fix test result, but not test yet
This commit is contained in:
@ -170,5 +170,17 @@ module Interpreter
|
||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
||||
true
|
||||
end
|
||||
|
||||
def execute_OperatorInstruction
|
||||
case @instruction.operator
|
||||
when :add
|
||||
puts @instruction
|
||||
|
||||
else
|
||||
raise "unimplemented operator #{@instruction}"
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,9 +7,15 @@ module Register
|
||||
plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [:Integer] )
|
||||
plus_function.source.return_type = Virtual::Integer
|
||||
plus_function.source.receiver = Virtual::Integer
|
||||
plus_function.source.add_code Register::OperatorInstruction.new( plus_function, :add , 0 , 0 )
|
||||
|
||||
tmp = Register.tmp_reg
|
||||
index = Register.arg_index 1
|
||||
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
|
||||
add = Register::OperatorInstruction.new( plus_function, :add , tmp , Register.self_reg )
|
||||
plus_function.source.add_code add
|
||||
return plus_function
|
||||
end
|
||||
|
||||
# The conversion to base10 is quite a bit more complicated than i thought.
|
||||
# The bulk of it is in div10
|
||||
# We set up variables, do the devision and write the result to the string
|
||||
|
@ -7,7 +7,7 @@ module Register
|
||||
@left = left
|
||||
@right = right
|
||||
end
|
||||
attr_reader :left , :right
|
||||
attr_reader :operator, :left , :right
|
||||
|
||||
def to_s
|
||||
"OperatorInstruction: #{left} #{operator} #{right}"
|
||||
|
@ -126,4 +126,11 @@ module Register
|
||||
end
|
||||
return register
|
||||
end
|
||||
|
||||
# when knowing the index of the argument, return the index into the message
|
||||
# index passed is parfait, ie stats at 1
|
||||
def self.arg_index i
|
||||
last = resolve_index :message , :name
|
||||
return last + i
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user