fix test and remove hack for -

This commit is contained in:
Torsten Ruger 2014-05-21 12:42:54 +03:00
parent 9d873d3cba
commit 53cfeb72a4
2 changed files with 7 additions and 8 deletions

View File

@ -21,9 +21,6 @@ module Vm
# just a base class for data. not sure how this will be usefull (may just have read too much llvm)
class Value < Code
def class_for clazz
CMachine.instance.class_for(clazz)
end
# part of the dsl, ie serves to make code like value.is a + b work
# ie we save the receier as the result into the instruction and pass that back
def is instruction
@ -76,11 +73,11 @@ module Vm
# 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)
if other.is_a?(Vm::IntegerConstant) or other.is_a?(Vm::Integer)
class_for(MoveInstruction).new( self , other , :opcode => :mov)
elsif other.is_a?(Vm::StringConstant) # pc relative addressing
class_for(LogicInstruction).new(self , other , nil , opcode: :add)
else
else
other.assign(self)
end
end
@ -88,12 +85,14 @@ module Vm
def less_or_equal block , right
CMachine.instance.integer_less_or_equal block , self , right
end
def == other
code = class_for(CompareInstruction).new(self , other , opcode: :cmp)
end
def + other
class_for(LogicInstruction).new(nil , self , other , opcode: :add)
end
def - other
class_for(LogicInstruction).new(nil , self , other , opcode: :sub , update_status: 1 )
class_for(LogicInstruction).new(nil , self , other , opcode: :sub )#, update_status: 1 )
end
def plus block , first , right
CMachine.instance.integer_plus block , self , first , right

View File

@ -18,7 +18,7 @@ class TestSmallProg < MiniTest::Test
r0 = Vm::Integer.new(0)
m.r0 = 5 #1
m << s
s.r0 = r0 - 1 #2
s.r0 = (r0 - 1).set_update_status #2
s.bne s #3
@should = [0,176,160,227,5,0,160,227,1,0,80,226,253,255,255,26,1,112,160,227,0,0,0,239]
write "loop"