phase one, assignment for constants (moves) work

This commit is contained in:
Torsten Ruger 2014-05-20 11:14:18 +03:00
parent 7056f6f05c
commit c3c6928dc8
3 changed files with 17 additions and 3 deletions

View File

@ -101,10 +101,11 @@ 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])
end
add_code l_val.assign(args[0])
else
add_code CMachine.instance.send(meth , *args)
end
end
end

View File

@ -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

View File

@ -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