From db31ff7021fd57e0360cb5dfc0c55397c3e45a60 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 9 Aug 2015 00:52:27 +0300 Subject: [PATCH] implement adding in interpreter --- lib/interpreter/interpreter.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/interpreter/interpreter.rb b/lib/interpreter/interpreter.rb index 950e4598..5575d7b2 100644 --- a/lib/interpreter/interpreter.rb +++ b/lib/interpreter/interpreter.rb @@ -31,7 +31,7 @@ module Interpreter @stdout = "" @registers = {} @clock = 0 - (0...16).each do |r| + (0...12).each do |r| set_register "r#{r}".to_sym , "r#{r}:unknown" end end @@ -103,7 +103,8 @@ module Interpreter def execute_LoadConstant to = @instruction.register - value = @instruction.constant.object_id + value = @instruction.constant + value = value.object_id unless value.is_a?(Fixnum) set_register( to , value ) true end @@ -174,8 +175,12 @@ module Interpreter def execute_OperatorInstruction case @instruction.operator 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 raise "unimplemented operator #{@instruction}" end