diff --git a/lib/vm/block.rb b/lib/vm/block.rb index 1c551ca8..d2af8647 100644 --- a/lib/vm/block.rb +++ b/lib/vm/block.rb @@ -101,9 +101,10 @@ module Vm def method_missing(meth, *args, &block) if( meth.to_s[-1] == "=" && args.length == 1) l_val = @scope.eval meth.to_s[0 ... -1] - add_code l_val.asign(args[0]) + add_code l_val.assign(args[0]) + else + add_code CMachine.instance.send(meth , *args) end - add_code CMachine.instance.send(meth , *args) end end diff --git a/lib/vm/values.rb b/lib/vm/values.rb index f2c0724b..4bbb4637 100644 --- a/lib/vm/values.rb +++ b/lib/vm/values.rb @@ -70,6 +70,19 @@ module Vm class Integer < Word + # part of the dsl. + # Gets called with either fixnum/IntegerConstant or an Instruction (usually logic, iw add...) + # For instructions we flip, ie call the assign on the instruction + # but for constants we have to create instruction first (mov) + def assign other + other = Vm::IntegerConstant.new(other) if other.is_a? Fixnum + if other.is_a? Vm::IntegerConstant + class_for(MoveInstruction).new( self , other , :opcode => :mov) + else + other.assign(self) + end + end + def less_or_equal block , right CMachine.instance.integer_less_or_equal block , self , right end diff --git a/test/arm/test_small_program.rb b/test/arm/test_small_program.rb index 1e88099e..addbe479 100644 --- a/test/arm/test_small_program.rb +++ b/test/arm/test_small_program.rb @@ -17,7 +17,7 @@ class TestSmallProg < MiniTest::Test m = @program.main.scope binding r0 = Vm::Integer.new(0) m.r0 = 5 #1 - m.add_code start + m << start start.instance_eval do sub :r0, :r0, 1 , :update_status => 1 #2 bne start #3