diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index f082a52a..65217bf0 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -144,13 +144,13 @@ module Risc null = load_object Parfait.object_space.nil_object int = nil build do - int = factory[:next_object].to_reg + int = factory[:next_object].to_reg.known_type(:Integer) null.op :- , int if_not_zero cont_label factory[:next_object] << factory[:reserve] call_get_more add_code cont_label - factory[:next_object] << factory[:next_object][:next_integer] + factory[:next_object] << int[:next_integer] end int end diff --git a/lib/slot_machine/slotted_message.rb b/lib/slot_machine/slotted_message.rb index 553dab64..61f3e670 100644 --- a/lib/slot_machine/slotted_message.rb +++ b/lib/slot_machine/slotted_message.rb @@ -14,8 +14,8 @@ module SlotMachine # the code is added to compiler # the register returned def to_register(compiler, source) - slots = @slots left = Risc.message_named_reg + slots = @slots while( slots ) left = left.resolve_and_add( slots.name , compiler) slots = slots.next_slot @@ -30,7 +30,6 @@ module SlotMachine # They are very similar (apart from the final reg_to_slot here) and should # most likely be united def reduce_and_load(const_reg , compiler , original_source ) - raise "Not Message #{object}" unless known_object == :message left = Risc.message_named_reg slot = slots while( slot.next_slot ) diff --git a/test/risc/test_builder1.rb b/test/risc/test_builder1.rb index fcc93101..77ba406e 100644 --- a/test/risc/test_builder1.rb +++ b/test/risc/test_builder1.rb @@ -3,6 +3,8 @@ require_relative "../helper" module Risc class TestCompilerBuilder < MiniTest::Test include Parfait::MethodHelper + include HasCompiler + def setup Parfait.boot!(Parfait.default_test_options) @method = SlotMachine::SlotCollection.compiler_for( :Space , :main,{},{}).callable @@ -18,7 +20,11 @@ module Risc end def test_allocate_len int = @builder.allocate_int - assert_equal 23 , @builder.compiler.risc_instructions.length + assert_equal 22 , @builder.compiler.risc_instructions.length + end + def test_allocate + int = @builder.allocate_int + assert_allocate end end end diff --git a/test/slot_machine/macro/helper.rb b/test/slot_machine/macro/helper.rb index 88180195..97efa4fd 100644 --- a/test/slot_machine/macro/helper.rb +++ b/test/slot_machine/macro/helper.rb @@ -18,41 +18,6 @@ module SlotMachine @risc_i.next( at ) end - def assert_return(at) - assert_label at , "return_label" - assert_slot_to_reg at + 1 , :message , 6 , "message.caller" - assert_slot_to_reg at + 2 , "message" , 5 , "message.return_value" - assert_reg_to_slot at + 3 ,"message.return_value" , "message.caller" , 5 - assert_slot_to_reg at + 4 , :message , 4 , "message.return_address" - assert_slot_to_reg at + 5 , :message , 6 , :message - assert_equal Risc::FunctionReturn , risc(at + 6).class - assert_label at + 7 , "unreachable" - end - def assert_allocate - assert_load 1 , Parfait::Factory , "id_factory_" - assert_load 2 , Parfait::NilClass , "id_nilclass_" - assert_slot_to_reg 3 , "id_factory_" , 2 , "id_factory_.next_object" - assert_operator 4 , :- , "id_nilclass_" , "id_factory_.next_object" - assert_not_zero 5 , "cont_label" - assert_slot_to_reg 6 , "id_factory_" , 2 , "id_factory_.next_object" - assert_reg_to_slot 7 , "id_factory_.next_object" , "id_factory_" , 2 - assert_load 8 , Parfait::Factory , "id_factory_" - assert_load 9 , Parfait::CallableMethod , "id_callablemethod" - assert_slot_to_reg 10 , :message , 1 , "message.next_message" - assert_reg_to_slot 11 , "id_callablemethod_" , "message.next_message" , 7 - assert_reg_to_slot 12 , "id_factory_" , :message , 2 - assert_load 13 , Risc::Label , "id_label" - assert_slot_to_reg 14 , :message , 1 , "message.next_message" - assert_reg_to_slot 15 , "id_label" , "message.next_message" , 4 - assert_slot_to_reg 16 ,:message , 1 , :message - assert_equal Risc::FunctionCall, risc(17).class - assert_equal :main, risc(17).method.name - assert_label 18 , "after_main_" - assert_label 19 , "cont_label" - assert_slot_to_reg 20 , "id_factory_" , 2 , "id_factory_.next_object" - assert_slot_to_reg 21 , "id_factory_" , 2 , "id_factory_.next_object" - assert_reg_to_slot 22 , "id_factory_.next_object" , "id_factory_" , 2 - end end end end diff --git a/test/support/risc_assert.rb b/test/support/risc_assert.rb index 9f64dacd..cbf6a51c 100644 --- a/test/support/risc_assert.rb +++ b/test/support/risc_assert.rb @@ -136,5 +136,43 @@ module Minitest assert_equal Risc::LoadData , ins.class, "Class at:#{ins_i}" assert_equal data , ins.constant , "Data at:#{ins_i}" end + + def assert_return(at) + assert_label at , "return_label" + assert_slot_to_reg at + 1 , :message , 6 , "message.caller" + assert_slot_to_reg at + 2 , "message" , 5 , "message.return_value" + assert_reg_to_slot at + 3 ,"message.return_value" , "message.caller" , 5 + assert_slot_to_reg at + 4 , :message , 4 , "message.return_address" + assert_slot_to_reg at + 5 , :message , 6 , :message + assert_equal Risc::FunctionReturn , risc(at + 6).class + assert_label at + 7 , "unreachable" + end + def assert_allocate + assert_load 1 , Parfait::Factory , "id_factory_" + assert_load 2 , Parfait::NilClass , "id_nilclass_" + assert_slot_to_reg 3 , "id_factory_" , 2 , "id_factory_.next_object" + assert_operator 4 , :- , "id_nilclass_" , "id_factory_.next_object" + assert_not_zero 5 , "cont_label" + assert_slot_to_reg 6 , "id_factory_" , 3 , "id_factory_.reserve" + assert_reg_to_slot 7 , "id_factory_.reserve" , "id_factory_" , 2 + assert_load 8 , Parfait::Factory , "id_factory_" + assert_load 9 , Parfait::CallableMethod , "id_callablemethod" + assert_slot_to_reg 10 , :message , 1 , "message.next_message" + assert_reg_to_slot 11 , "id_callablemethod_" , "message.next_message" , 7 + assert_reg_to_slot 12 , "id_factory_" , :message , 2 + assert_load 13 , Risc::Label , "id_label" + assert_slot_to_reg 14 , :message , 1 , "message.next_message" + assert_reg_to_slot 15 , "id_label" , "message.next_message" , 4 + assert_slot_to_reg 16 ,:message , 1 , :message + assert_equal Risc::FunctionCall, risc(17).class + assert_equal :main, risc(17).method.name + assert_label 18 , "after_main_" + assert_label 19 , "cont_label" + assert_slot_to_reg 20 , "id_factory_.next_object" , 1 , "id_factory_.next_object.next_integer" + assert_reg_to_slot 21 , "id_factory_.next_object.next_integer" , "id_factory_" , 2 + end end end +def Risc.allocate_length + 21 +end