From c0a7f1d284eadb6e014240eabd41606e66c6df59 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 19 Mar 2018 13:19:42 +0530 Subject: [PATCH] fix insertion and add assign send must implement send conversion before this makes sense --- lib/risc/method_compiler.rb | 8 ++++-- ...signment.rb => test_assign_local_const.rb} | 2 +- test/mom/test_assign_local_send.rb | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) rename test/mom/{test_local_assignment.rb => test_assign_local_const.rb} (91%) create mode 100644 test/mom/test_assign_local_send.rb diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 65f0e74f..785aada8 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -93,11 +93,12 @@ module Risc # continue down the instruction chain unti depleted # (adding moves the insertion point so the whole mom chain is added as a risc chain) def add_mom( instruction ) - raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction) while( instruction ) - #puts "adding #{instruction.to_s}:#{instruction.next.to_s}" + raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction) + #puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}" risc = instruction.to_risc( self ) add_code(risc) + #puts "adding risc #{risc.to_s}:#{risc.next.to_s}" instruction = instruction.next end end @@ -106,8 +107,9 @@ module Risc def add_code( instruction ) raise "Not an instruction:#{instruction.to_s}" unless instruction.is_a?(Risc::Instruction) raise instruction.to_s if( instruction.class.name.split("::").first == "Arm") + new_current = instruction.last #after insertion this point is lost @current.insert(instruction) #insert after current - @current = instruction.last + @current = new_current self end diff --git a/test/mom/test_local_assignment.rb b/test/mom/test_assign_local_const.rb similarity index 91% rename from test/mom/test_local_assignment.rb rename to test/mom/test_assign_local_const.rb index d9107845..ad80251a 100644 --- a/test/mom/test_local_assignment.rb +++ b/test/mom/test_assign_local_const.rb @@ -1,7 +1,7 @@ require_relative 'helper' module Risc - class TestLocalAssign < MiniTest::Test + class TestAssignLocalConst < MiniTest::Test include Statements def setup diff --git a/test/mom/test_assign_local_send.rb b/test/mom/test_assign_local_send.rb new file mode 100644 index 00000000..210b14fc --- /dev/null +++ b/test/mom/test_assign_local_send.rb @@ -0,0 +1,28 @@ +require_relative 'helper' + +module Risc + class TestAssignLocalSend < MiniTest::Test + include Statements + + def setup + super + @input = "r = 5.mod4" + @expect = [Label, LoadConstant, RegToSlot, Label, Label, SlotToReg , + RegToSlot] + end + def test_local_assign_instructions + assert_nil msg = check_nil , msg + end + + def ttest_constant_load + produced = produce_body + assert_equal 5 , produced.constant.known_object.value + end + + def ttest_slot_move + produced = produce_body + assert_equal produced.next.register , produced.register + end + + end +end