Fix first Slot instruction that uses builder
now without method_missing and names but still with instance_eval, hmm. Tried without, makes code much less readable
This commit is contained in:
parent
4888b3b6db
commit
4b303977a7
@ -142,6 +142,9 @@ module Risc
|
||||
return ins
|
||||
end
|
||||
|
||||
def load_object(object)
|
||||
@compiler.load_object(object)
|
||||
end
|
||||
# for some methods that return an integer it is beneficial to pre allocate the
|
||||
# integer and store it in the return value. That is what this function does.
|
||||
#
|
||||
|
@ -96,6 +96,7 @@ module Risc
|
||||
def load_object( object )
|
||||
raise "must be Parfait, not #{object.class}" unless object.is_a?(Parfait::Object)
|
||||
ins = Risc.load_constant("load to #{object.type}" , object)
|
||||
ins.register.set_compiler(self)
|
||||
add_code ins
|
||||
# todo for constants (not objects)
|
||||
# add_constant(right) if compiler
|
||||
|
@ -20,13 +20,13 @@ module SlotMachine
|
||||
|
||||
def to_risc(compiler)
|
||||
false_label = @false_label.risc_label(compiler)
|
||||
builder = compiler.builder("TruthCheck")
|
||||
condition_reg = @condition.to_register(compiler,self)
|
||||
builder.build do
|
||||
object! << Parfait.object_space.false_object
|
||||
|
||||
compiler.build(self.to_s) do
|
||||
object = load_object Parfait.object_space.false_object
|
||||
object.op :- , condition_reg
|
||||
if_zero false_label
|
||||
object << Parfait.object_space.nil_object
|
||||
object = load_object Parfait.object_space.nil_object
|
||||
object.op :- , condition_reg
|
||||
if_zero false_label
|
||||
end
|
||||
|
@ -7,18 +7,19 @@ module SlotMachine
|
||||
TruthCheck.new(target , Label.new("ok" , "target"))
|
||||
end
|
||||
def test_len
|
||||
assert_equal 8 , all.length , all_str
|
||||
assert_equal 8 , all.length
|
||||
assert_equal Risc::Label , all.first.class
|
||||
end
|
||||
def test_1_slot
|
||||
assert_slot_to_reg risc(1) ,:r0 , 6 , :r2
|
||||
assert_slot_to_reg risc(1) ,:message , 6 , :"message.caller"
|
||||
end
|
||||
def test_2_load
|
||||
assert_load risc(2) , Parfait::FalseClass , :r3
|
||||
assert_load risc(2) , Parfait::FalseClass
|
||||
end
|
||||
def test_3_op
|
||||
assert_equal Risc::OperatorInstruction , risc(3).class
|
||||
assert_equal :r3 , risc(3).left.symbol
|
||||
assert_equal :r2 , risc(3).right.symbol
|
||||
assert risc(3).left.is_object?
|
||||
assert_equal :"message.caller" , risc(3).right.symbol
|
||||
assert_equal :- , risc(3).operator
|
||||
end
|
||||
def test_4_zero
|
||||
@ -26,12 +27,12 @@ module SlotMachine
|
||||
assert_label risc(4).label , "target"
|
||||
end
|
||||
def test_5_load
|
||||
assert_load risc(5) , Parfait::NilClass , :r3
|
||||
assert_load risc(5) , Parfait::NilClass
|
||||
end
|
||||
def test_6_op
|
||||
assert_equal Risc::OperatorInstruction , risc(6).class
|
||||
assert_equal :r3 , risc(6).left.symbol
|
||||
assert_equal :r2 , risc(6).right.symbol
|
||||
assert risc(6).left.is_object?
|
||||
assert_equal :"message.caller" , risc(6).right.symbol
|
||||
assert_equal :- , risc(6).operator
|
||||
end
|
||||
def test_7_zero
|
||||
|
@ -18,7 +18,11 @@ module Minitest
|
||||
def assert_load(load , clazz = nil , register = nil)
|
||||
assert_equal Risc::LoadConstant , load.class
|
||||
assert_equal( clazz , load.constant.class) if clazz
|
||||
assert_equal( register , load.register.symbol, "wrong destination register") if register
|
||||
if register
|
||||
assert_equal( register , load.register.symbol, "wrong destination register") if register
|
||||
else
|
||||
assert load.register.is_object? , "reg #{load.register.symbol} is not object (ie no id_xx)"
|
||||
end
|
||||
end
|
||||
def assert_transfer( transfer , from , to)
|
||||
assert_equal Risc::Transfer , transfer.class
|
||||
|
Loading…
Reference in New Issue
Block a user