From 253d2fead817eb5b5434b4fa79d696ed58e62739 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 19 Aug 2018 13:18:25 +0300 Subject: [PATCH] change all to_risc functions to add directly still #11 test not working yet --- lib/mom/instruction/argument_transfer.rb | 2 +- lib/mom/instruction/jump.rb | 3 ++- lib/mom/instruction/message_setup.rb | 3 +-- lib/mom/instruction/not_same_check.rb | 9 ++++----- lib/mom/instruction/resolve_method.rb | 3 +-- lib/mom/instruction/return_jump.rb | 2 +- lib/mom/instruction/return_sequence.rb | 3 +-- lib/mom/instruction/truth_check.rb | 12 +++++------- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/mom/instruction/argument_transfer.rb b/lib/mom/instruction/argument_transfer.rb index 3f632ef8..d93a9cd0 100644 --- a/lib/mom/instruction/argument_transfer.rb +++ b/lib/mom/instruction/argument_transfer.rb @@ -35,7 +35,7 @@ module Mom transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver, self).to_risc(compiler) compiler.reset_regs @arguments.each do |arg| - transfer << arg.to_risc(compiler) + arg.to_risc(compiler) compiler.reset_regs end transfer diff --git a/lib/mom/instruction/jump.rb b/lib/mom/instruction/jump.rb index 8ec76f61..470aac2d 100644 --- a/lib/mom/instruction/jump.rb +++ b/lib/mom/instruction/jump.rb @@ -12,7 +12,8 @@ module Mom @label = label end def to_risc(compiler) - Risc::Branch.new(self , @label.to_risc(compiler)) + label = @label.to_risc(compiler) + compiler.add_code Risc::Branch.new(self , label) end end diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index a3407922..294655ec 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -27,8 +27,7 @@ module Mom # Move method name, frame and arguemnt types from the method to the next_message # Get the message from Space and link it. def to_risc(compiler) - builder = compiler.code_builder(self) - build_with(builder) + build_with(compiler.builder(self)) end # directly called by to_risc diff --git a/lib/mom/instruction/not_same_check.rb b/lib/mom/instruction/not_same_check.rb index f790b22e..67034c4a 100644 --- a/lib/mom/instruction/not_same_check.rb +++ b/lib/mom/instruction/not_same_check.rb @@ -23,11 +23,10 @@ module Mom # basically move both left and right values into register # subtract them and see if IsZero comparison def to_risc(compiler) - l_val = left.to_register(compiler, self) - r_val = right.to_register(compiler, self) - check = Risc.op( self , :- , l_val.register , r_val.register) - check << Risc::IsZero.new( self, false_jump.to_risc(compiler)) - l_val << r_val << check + l_reg = left.to_register(compiler, self) + r_reg = right.to_register(compiler, self) + compiler.add_code Risc.op( self , :- , l_reg , r_reg) + compiler.add_code Risc::IsZero.new( self, false_jump.to_risc(compiler)) end end end diff --git a/lib/mom/instruction/resolve_method.rb b/lib/mom/instruction/resolve_method.rb index 6c69ed77..ada02460 100644 --- a/lib/mom/instruction/resolve_method.rb +++ b/lib/mom/instruction/resolve_method.rb @@ -35,7 +35,7 @@ module Mom def to_risc( compiler ) name_ = @name cache_entry_ = @cache_entry - builder = compiler.code_builder(self) + builder = compiler.builder(self) builder.build do word! << name_ cache_entry! << cache_entry_ @@ -64,7 +64,6 @@ module Mom add_code ok_label cache_entry[:cached_method] << callable_method end - return builder.built end end diff --git a/lib/mom/instruction/return_jump.rb b/lib/mom/instruction/return_jump.rb index d5de1131..ceb1f6ae 100644 --- a/lib/mom/instruction/return_jump.rb +++ b/lib/mom/instruction/return_jump.rb @@ -8,7 +8,7 @@ module Mom class ReturnJump < Instruction def to_risc(compiler) - Risc::Branch.new(self , compiler.return_label) + compiler.add_code Risc::Branch.new(self , compiler.return_label) end end diff --git a/lib/mom/instruction/return_sequence.rb b/lib/mom/instruction/return_sequence.rb index 08d2c492..fb48ac94 100644 --- a/lib/mom/instruction/return_sequence.rb +++ b/lib/mom/instruction/return_sequence.rb @@ -21,7 +21,7 @@ module Mom class ReturnSequence < Instruction def to_risc(compiler) compiler.reset_regs - builder = compiler.code_builder(self) + builder = compiler.builder(self) builder.build do object! << message[:return_value] caller_reg! << message[:caller] @@ -38,7 +38,6 @@ module Mom message << message[:caller] return_address.function_return end - builder.built end def to_s diff --git a/lib/mom/instruction/truth_check.rb b/lib/mom/instruction/truth_check.rb index 8f5af60d..94fb37fd 100644 --- a/lib/mom/instruction/truth_check.rb +++ b/lib/mom/instruction/truth_check.rb @@ -20,18 +20,16 @@ module Mom def to_risc(compiler) false_label = @false_jump.to_risc(compiler) - builder = compiler.code_builder("TruthCheck") - condition_code = @condition.to_register(compiler,self) - condition = condition_code.register#.set_builder(builder) - built = builder.build do + builder = compiler.builder("TruthCheck") + condition_reg = @condition.to_register(compiler,self) + builder.build do object! << Parfait.object_space.false_object - object.op :- , condition + object.op :- , condition_reg if_zero false_label object << Parfait.object_space.nil_object - object.op :- , condition + object.op :- , condition_reg if_zero false_label end - condition_code << built end end