From 90935bfbbcd70ecfb5a4400942cbbffb234c7959 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 22 Mar 2020 15:58:19 +0200 Subject: [PATCH] risc is GREEN totally, man. Small fix in method missing fixed last block tests (why, i do not know) --- lib/risc/interpreter.rb | 2 +- lib/slot_machine/macro/method_missing.rb | 13 ++++++------- test/risc/interpreter/test_dynamic_call.rb | 2 +- .../instructions/test_resolve_method.rb | 14 +++++--------- test/slot_machine/macro/test_method_missing.rb | 17 ++++++++--------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index cbcf7b2b..08514477 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -266,7 +266,7 @@ module Risc set_instruction(nil) return false when :died - raise "Method #{@registers[std_reg(:syscall_2)]} not found for #{@registers[std_reg(:syscall_2)]}" + raise "Method #{@registers[:r1].to_string} not found for #{@registers[std_reg(:syscall_1)]}" else raise "un-implemented syscall #{name}" end diff --git a/lib/slot_machine/macro/method_missing.rb b/lib/slot_machine/macro/method_missing.rb index affc4cd3..b2d5dc14 100644 --- a/lib/slot_machine/macro/method_missing.rb +++ b/lib/slot_machine/macro/method_missing.rb @@ -1,19 +1,18 @@ module SlotMachine class MethodMissing < Macro - attr_reader :name + attr_reader :name_reg - def initialize( source , name ) + def initialize( source , name_reg ) super(source) - name = name.value if name.is_a?(Sol::SymbolConstant) - raise "No reg #{name.class}" unless name.class == Symbol - @name = name + name_reg = Risc::RegisterValue.new(name_reg , :Word) if name_reg.class == Symbol + raise "No reg #{name_reg.class}" unless name_reg.is_a? Risc::RegisterValue + @name_reg = name_reg end def to_risc(compiler) builder = compiler.builder(compiler.source_name) - from = compiler.load_object(Parfait.new_word_max(@name)) to = Risc::RegisterValue.new(:r1 , :Word) - builder.add_code Risc::Transfer.new(self , from , to) + builder.add_code Risc::Transfer.new(self , name_reg , to) builder.add_code Risc::Syscall.new(self, :died ) return compiler end diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index 6b6a6d07..e5c21fbb 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -16,7 +16,7 @@ module Risc SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #10 LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15 SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20 - OperatorInstruction, IsZero, RegToSlot, Branch, LoadConstant, #25 + OperatorInstruction, IsZero, RegToSlot, LoadConstant, Branch, #25 SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #30 RegToSlot, LoadConstant, SlotToReg, LoadConstant, SlotToReg, #35 RegToSlot, SlotToReg, DynamicJump, LoadConstant, LoadConstant, #40 diff --git a/test/slot_machine/instructions/test_resolve_method.rb b/test/slot_machine/instructions/test_resolve_method.rb index 905970c1..c34f6e25 100644 --- a/test/slot_machine/instructions/test_resolve_method.rb +++ b/test/slot_machine/instructions/test_resolve_method.rb @@ -10,7 +10,7 @@ module SlotMachine ResolveMethod.new( "method" , :name , cache_entry ) end def test_len - assert_equal 21 , all.length , all_str + assert_equal 20 , all.length , all_str end def test_load_name assert_load 1, Parfait::Word , "id_word_" @@ -58,21 +58,17 @@ module SlotMachine def test_goto_exit assert_label 15, "exit_label_" end - def test_load_name2 - assert_load 16, Parfait::Word , "id_word_" - assert_equal "name" , risc(1).constant.to_string - end def test_move_name - assert_transfer 17, "id_word_" , :r1 + assert_transfer 16, "id_word_" , :r1 end def test_sys - assert_syscall 18, :died + assert_syscall 17, :died end def test_label - assert_label 19, "ok_label_" + assert_label 18, "ok_label_" end def test_method - assert_reg_to_slot 20 , "id_cacheentry_.cached_type.methods" , "id_cacheentry_" , 2 + assert_reg_to_slot 19 , "id_cacheentry_.cached_type.methods" , "id_cacheentry_" , 2 end end end diff --git a/test/slot_machine/macro/test_method_missing.rb b/test/slot_machine/macro/test_method_missing.rb index 24e00af3..4e4de38e 100644 --- a/test/slot_machine/macro/test_method_missing.rb +++ b/test/slot_machine/macro/test_method_missing.rb @@ -14,19 +14,18 @@ module SlotMachine assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 15 , @method.to_risc.risc_instructions.length + assert_equal 14 , @method.to_risc.risc_instructions.length end def test_all - assert_load 1 , Parfait::Word , "id_word_" - assert_transfer 2 , "id_word_" , :r1 - assert_syscall 3 , :died - assert_slot_to_reg 4 , :message , 5 , "message.return_value" - assert_reg_to_slot 5 , "message.return_value" , :message , 5 - assert_branch 6 , "return_label" - assert_label 7 , "return_label" + assert_transfer 1 , :r1 , :r1 + assert_syscall 2 , :died + assert_slot_to_reg 3 , :message , 5 , "message.return_value" + assert_reg_to_slot 4 , "message.return_value" , :message , 5 + assert_branch 5 , "return_label" + assert_label 6 , "return_label" end def test_return - assert_return(7) + assert_return(6) end end end