using new macro approach for builtin, testing first

This commit is contained in:
2019-08-26 09:24:06 +03:00
parent b9bdc55059
commit 160d860db2
5 changed files with 92 additions and 2 deletions

View File

@ -1,6 +1,6 @@
module Mom
module Builtin
class Operator < ::Mom::Instruction
class Operator < Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@ -14,7 +14,7 @@ module Mom
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arg1] #"other"
integer_reg! << message[:arg1] #"other"
integer_reg.reduce_int
integer.op operator , integer_reg
integer_tmp[Parfait::Integer.integer_index] << integer
@ -23,5 +23,29 @@ module Mom
return compiler
end
end
end
class IntOperator < Instruction
attr_reader :operator
def initialize(name , operator)
super(name)
@operator = operator
end
def to_risc(compiler)
builder = compiler.builder(compiler.source)
integer_tmp = builder.allocate_int
operator = @operator # make accessible in block
builder.build do
integer! << message[:receiver]
integer.reduce_int
integer_reg! << message[:arg1] #"other"
integer_reg.reduce_int
integer.op operator , integer_reg
integer_tmp[Parfait::Integer.integer_index] << integer
message[:return_value] << integer_tmp
end
return compiler
end
end
end