diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index bffdd2fb..dd517e99 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -139,9 +139,8 @@ module Risc # for computationally building code (ie writing assembler) these short cuts # help to instantiate risc instructions and add them immediately - [:label, :reg_to_slot , :slot_to_reg , :load_constant, :load_data, - :function_return , :function_call, :op , - :transfer , :reg_to_slot , :byte_to_reg , :reg_to_byte].each do |method| + [ :slot_to_reg , :load_constant, :load_data, + :transfer ].each do |method| define_method("add_#{method}".to_sym) do |*args| if not @source_used args[0] = @source diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 75d851dc..cab77655 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -106,7 +106,7 @@ module Risc def add_receiver(builder) message = Risc.message_reg ret_type = builder.compiler.receiver_type - ret = builder.compiler.use_reg( ret_type ) + ret = builder.compiler.use_reg( ret_type ).set_builder(builder) builder.add_slot_to_reg(" load self" , message , :receiver , ret ) builder.add_slot_to_reg( "int -> fix" , ret , Parfait::Integer.integer_index , ret) return ret @@ -167,7 +167,7 @@ module Risc builder.add_code Risc.op( s , :+ , q , tmp ) builder.add_new_int(s,q , tmp) - builder.add_reg_to_slot( s , tmp , Risc.message_reg , :return_value) + builder.build{ message[:return_value] << tmp } compiler.add_mom( Mom::ReturnSequence.new) return compiler diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 04ed6e08..1479de59 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -70,11 +70,11 @@ module Risc end exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" ) - ret_tmp = compiler.use_reg(:Label) + ret_tmp = compiler.use_reg(:Label).set_builder(builder) builder.build do - add_load_constant("__init__ load return", exit_label , ret_tmp) - add_reg_to_slot("__init__ store return", ret_tmp , Risc.message_reg , :return_address) - add_function_call( "__init__ issue call" , Parfait.object_space.get_main) + ret_tmp << exit_label + message[:return_address] << ret_tmp + add_code Risc.function_call( "__init__ issue call" , Parfait.object_space.get_main) add_code exit_label end compiler.reset_regs diff --git a/lib/risc/register_value.rb b/lib/risc/register_value.rb index 58bdfdfc..e0dfcd5c 100644 --- a/lib/risc/register_value.rb +++ b/lib/risc/register_value.rb @@ -134,7 +134,7 @@ module Risc # - an RValue, resulting in an SlotToReg def <<( right ) case right - when Parfait::Object , Symbol + when Parfait::Object , Symbol , Label ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self) when Fixnum ins = Risc.load_data("#{right.class} to #{self.type}" , right , self) diff --git a/test/risc/test_register_value.rb b/test/risc/test_register_value.rb index 48556f94..abda7e2a 100644 --- a/test/risc/test_register_value.rb +++ b/test/risc/test_register_value.rb @@ -31,6 +31,11 @@ module Risc move = @r1 << :puts assert_equal LoadConstant , move.class end + def test_load_label + label = Risc::Label.new("HI","ho" , FakeAddress.new(0)) + move = @r1 << label + assert_equal LoadConstant , move.class + end def test_transfer transfer = @r0 << @r1 assert_equal Transfer , transfer.class