implement adding in interpreter

This commit is contained in:
Torsten Ruger 2015-08-09 00:52:27 +03:00
parent 5d838056fa
commit db31ff7021

View File

@ -31,7 +31,7 @@ module Interpreter
@stdout = "" @stdout = ""
@registers = {} @registers = {}
@clock = 0 @clock = 0
(0...16).each do |r| (0...12).each do |r|
set_register "r#{r}".to_sym , "r#{r}:unknown" set_register "r#{r}".to_sym , "r#{r}:unknown"
end end
end end
@ -103,7 +103,8 @@ module Interpreter
def execute_LoadConstant def execute_LoadConstant
to = @instruction.register to = @instruction.register
value = @instruction.constant.object_id value = @instruction.constant
value = value.object_id unless value.is_a?(Fixnum)
set_register( to , value ) set_register( to , value )
true true
end end
@ -174,8 +175,12 @@ module Interpreter
def execute_OperatorInstruction def execute_OperatorInstruction
case @instruction.operator case @instruction.operator
when :add when :add
puts @instruction left = get_register(@instruction.left)
rr = @instruction.right
right = get_register(rr)
result = left + right
puts "#{@instruction} == #{result}"
right = set_register(rr , result)
else else
raise "unimplemented operator #{@instruction}" raise "unimplemented operator #{@instruction}"
end end