From 4fe0edd1e3170edf9f4adfad3e9110615683bd95 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 30 Jul 2018 20:11:52 +0300 Subject: [PATCH] first risc level block test working assign was not executing yield baecause it was just testing for send, instead of callable --- lib/ruby/call_statement.rb | 2 +- lib/vool/assignment.rb | 2 +- lib/vool/yield_statement.rb | 2 +- .../blocks/test_block_assign_local.rb | 17 +++- test/support/risc_interpreter.rb | 2 +- test/vool/test_yield_statement.rb | 77 ++++++++++++++----- 6 files changed, 77 insertions(+), 25 deletions(-) diff --git a/lib/ruby/call_statement.rb b/lib/ruby/call_statement.rb index dba42549..5826ed17 100644 --- a/lib/ruby/call_statement.rb +++ b/lib/ruby/call_statement.rb @@ -23,7 +23,7 @@ module Ruby end def normalize_arg(arg , arguments , statements) - if arg.is_a?(Constant) and !arg.is_a?(SendStatement) + if arg.is_a?(Constant) and !arg.is_a?(CallStatement) arguments << arg.to_vool return end diff --git a/lib/vool/assignment.rb b/lib/vool/assignment.rb index 4a7677a9..0c29b35d 100644 --- a/lib/vool/assignment.rb +++ b/lib/vool/assignment.rb @@ -16,7 +16,7 @@ module Vool end def chain_assign(assign , compiler) - return assign unless @value.is_a?(SendStatement) + return assign unless @value.is_a?(CallStatement) @value.to_mom(compiler) << assign end end diff --git a/lib/vool/yield_statement.rb b/lib/vool/yield_statement.rb index 3aa8a0c6..ae6c6e8b 100644 --- a/lib/vool/yield_statement.rb +++ b/lib/vool/yield_statement.rb @@ -8,7 +8,7 @@ module Vool # On the way down to Mom, small differences become abvious, as the block that is # yielded to is an argument. Whereas in a send it is either statically known # or resolved and cached. Here it is dynamic, but sort of known dynamic. - # All we do before calling it is check that it is the right type. + # All we do before calling it is check that it is the right type. class YieldStatement < CallStatement # A Yield breaks down to 2 steps: diff --git a/test/risc/interpreter/blocks/test_block_assign_local.rb b/test/risc/interpreter/blocks/test_block_assign_local.rb index 3dc2ba2b..f1524515 100644 --- a/test/risc/interpreter/blocks/test_block_assign_local.rb +++ b/test/risc/interpreter/blocks/test_block_assign_local.rb @@ -19,8 +19,21 @@ module Risc RegToSlot, LoadConstant, Branch, SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, LoadConstant, SlotToReg, - RegToSlot, RegToSlot, SlotToReg, SlotToReg] - assert_equal 15 , get_return.class + RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, + SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + LoadConstant, SlotToReg, RegToSlot, SlotToReg, Branch, + SlotToReg, SlotToReg, DynamicJump, LoadConstant, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + RegToSlot, SlotToReg, Branch, SlotToReg, SlotToReg, + FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + Branch, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, + Transfer, SlotToReg, SlotToReg, Branch, Syscall, + NilClass] + assert_equal 15 , get_return end def est_call_main diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 30a8c085..6e9bb4de 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -42,7 +42,7 @@ module Risc end def get_return - #assert_equal Parfait::Message , @interpreter.get_register(:r8).class + assert_equal Parfait::Message , @interpreter.get_register(:r8).class @interpreter.get_register(:r0) end diff --git a/test/vool/test_yield_statement.rb b/test/vool/test_yield_statement.rb index e329803e..3bda6675 100644 --- a/test/vool/test_yield_statement.rb +++ b/test/vool/test_yield_statement.rb @@ -1,19 +1,8 @@ require_relative "helper" module Vool - class TestYieldArgsSendMom < MiniTest::Test - include MomCompile + module YieldBasics include Mom - - def setup - Parfait.boot! - @ins = compile_first_method( "yield(1)" ) - end - - def test_array - check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield] , - @ins - end def test_check_label assert_equal NotSameCheck, @ins.class assert @ins.false_jump.name.start_with?("method_ok_") @@ -37,23 +26,73 @@ module Vool assert_equal MessageSetup, @ins.next(2).class assert_equal 2, @ins.next(2).method_source end - def test_transfer - assert_equal ArgumentTransfer, @ins.next(3).class - assert_equal 1, @ins.next(3).arguments.length - end def test_receiver assert_equal :message , @ins.next(3).receiver.known_object assert_equal [:receiver] , @ins.next(3).receiver.slots end + def test_yield + assert_equal BlockYield, @ins.next(4).class + assert_equal 2, @ins.next(4).arg_index + end + def test_return_load + assert_equal SlotLoad, @ins.next(5).class + assert_equal :message, @ins.next(5).left.known_object + assert_equal :message, @ins.next(5).right.known_object + assert_equal :frame, @ins.next(5).left.slots.first + assert @ins.next(5).left.slots.last.to_s.start_with?("tmp_") + assert_equal [:return_value], @ins.next(5).right.slots + end + def test_return_load2 + assert_equal SlotLoad, @ins.next(6).class + assert_equal :message, @ins.next(6).left.known_object + assert_equal :message, @ins.next(6).right.known_object + assert_equal :return_value, @ins.next(6).left.slots.first + assert_equal :frame, @ins.next(6).right.slots.first + assert @ins.next(6).right.slots.last.to_s.start_with?("tmp_") + end + def test_return + assert_equal ReturnSequence, @ins.next(7).class + end + end + class TestYieldArgsSendMom < MiniTest::Test + include MomCompile + include YieldBasics + + def setup + Parfait.boot! + @ins = compile_first_method( "return yield(1)" ) + end + + def test_array + check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield , + SlotLoad, SlotLoad, ReturnSequence] , @ins + end + def test_transfer + assert_equal ArgumentTransfer, @ins.next(3).class + assert_equal 1, @ins.next(3).arguments.length + end def test_args_one_l left = @ins.next(3).arguments[0].left assert_equal Symbol, left.known_object.class assert_equal :message, left.known_object assert_equal [:next_message, :arguments, 1], left.slots end - def test_yield - assert_equal BlockYield, @ins.next(4).class - assert_equal 2, @ins.next(4).arg_index + end + class TestYieldNoArgsSendMom < MiniTest::Test + include MomCompile + include Mom + include YieldBasics + def setup + Parfait.boot! + @ins = compile_first_method( "return yield" ) + end + def test_array + check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield , + SlotLoad, SlotLoad, ReturnSequence] , @ins + end + def test_transfer + assert_equal ArgumentTransfer, @ins.next(3).class + assert_equal 0, @ins.next(3).arguments.length end end end