From d3f3c91ae5cbe15745116c558d326ee865be51ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Fri, 16 Aug 2019 21:43:54 +0300 Subject: [PATCH] Fix all but one test Riples upon riples. The one left looks like the genuine article --- lib/ruby/call_statement.rb | 2 +- test/mom/test_return_call.rb | 11 ++- test/mom/test_while_cmp.rb | 27 +++--- .../interpreter/blocks/test_assign_outer.rb | 17 ++-- .../interpreter/blocks/test_block_return.rb | 17 ++-- test/risc/interpreter/calling/test_alloc.rb | 13 ++- test/risc/interpreter/calling/test_div10.rb | 15 ++-- .../risc/interpreter/calling/test_get_byte.rb | 11 ++- test/risc/interpreter/calling/test_minus.rb | 13 ++- test/risc/interpreter/calling/test_mod.rb | 13 ++- test/risc/interpreter/calling/test_mult.rb | 11 ++- test/risc/interpreter/calling/test_plus.rb | 14 +-- test/risc/interpreter/calling/test_puts.rb | 12 +-- .../risc/interpreter/calling/test_set_byte.rb | 9 +- test/risc/interpreter/test_dynamic_call.rb | 13 ++- test/ruby/test_yield_statement.rb | 28 +++--- test/rubyx/parfait/README.md | 25 ++++++ test/rubyx/parfait/helper.rb | 13 +++ test/rubyx/parfait/test_object.rb | 25 ++++++ test/vool/blocks/test_if_condition.rb | 10 +-- test/vool/send/test_send_cached_simple.rb | 9 +- test/vool/test_return.rb | 6 +- test/vool/test_yield_statement.rb | 88 +++++++++---------- 23 files changed, 223 insertions(+), 179 deletions(-) create mode 100644 test/rubyx/parfait/README.md create mode 100644 test/rubyx/parfait/helper.rb create mode 100644 test/rubyx/parfait/test_object.rb diff --git a/lib/ruby/call_statement.rb b/lib/ruby/call_statement.rb index 3cb7d8ac..d94118ac 100644 --- a/lib/ruby/call_statement.rb +++ b/lib/ruby/call_statement.rb @@ -39,7 +39,7 @@ module Ruby # rather than using a stack to do that at runtime def normalize_arg(arg , statements) vool_arg = arg.to_vool - if arg.is_a?(Constant) + if arg.is_a?(Variable) || arg.is_a?(Constant) return vool_arg end if( vool_arg.is_a?(Vool::Statements)) diff --git a/test/mom/test_return_call.rb b/test/mom/test_return_call.rb index 2f1f5f02..27b4ec27 100644 --- a/test/mom/test_return_call.rb +++ b/test/mom/test_return_call.rb @@ -7,18 +7,17 @@ module Risc def setup super @input = "return 5.div4" - @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, - RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, - RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, - FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot, - SlotToReg, SlotToReg, RegToSlot, Branch] + @expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #4 + RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, #9 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #14 + FunctionCall, Label, SlotToReg, RegToSlot, Branch] #19 end def test_return_instructions assert_nil msg = check_nil , msg end def test_function_return - produced = produce_body.next(23) + produced = produce_body.next(19) assert_equal Branch , produced.class assert_equal "return_label" , produced.label.name end diff --git a/test/mom/test_while_cmp.rb b/test/mom/test_while_cmp.rb index 4c0f7d8b..092df33f 100644 --- a/test/mom/test_while_cmp.rb +++ b/test/mom/test_while_cmp.rb @@ -7,14 +7,13 @@ module Risc def setup super @input = "while(5 > 0) ; @a = true; end" - @expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, - RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, - SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, - RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, - FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot, - SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, - LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, - RegToSlot, Branch, Label] + @expect = [Label, LoadConstant, LoadConstant, SlotToReg, SlotToReg, #4 + RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, #9 + SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #14 + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #19 + FunctionCall, Label, SlotToReg, LoadConstant, OperatorInstruction, #24 + IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #29 + SlotToReg, RegToSlot, Branch, Label] #34 end def test_while_instructions @@ -39,19 +38,19 @@ module Risc end def test_false_check produced = produce_body - assert_equal Risc::IsZero , produced.next(29).class - assert produced.next(29).label.name.start_with?("merge_label") , produced.next(29).label.name + assert_equal Risc::IsZero , produced.next(25).class + assert produced.next(25).label.name.start_with?("merge_label") , produced.next(25).label.name end def test_nil_load produced = produce_body - assert_equal Risc::LoadConstant , produced.next(30).class - assert_equal Parfait::NilClass , produced.next(30).constant.class + assert_equal Risc::LoadConstant , produced.next(29).class + assert_equal Parfait::TrueClass , produced.next(29).constant.class end def test_back_jump # should jump back to condition label produced = produce_body - assert_equal Risc::Branch , produced.next(36).class - assert_equal produced , produced.next(36).label + assert_equal Risc::Branch , produced.next(32).class + assert_equal produced.name , produced.next(32).label.name end end diff --git a/test/risc/interpreter/blocks/test_assign_outer.rb b/test/risc/interpreter/blocks/test_assign_outer.rb index 9c6614d2..afdfeb4d 100644 --- a/test/risc/interpreter/blocks/test_assign_outer.rb +++ b/test/risc/interpreter/blocks/test_assign_outer.rb @@ -10,7 +10,7 @@ module Risc end def test_chain - #show_main_ticks # get output of what is + # show_main_ticks # get output of what is check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 10 RegToSlot, RegToSlot, RegToSlot, Branch, RegToSlot, @@ -25,15 +25,14 @@ module Risc SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, # 60 Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, # 70 - SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, - RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 80 + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, + Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 80 + SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, + SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, # 90 Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, - SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 90 - Branch, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, - RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 100 - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, - Branch, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 110 - SlotToReg, SlotToReg, Syscall, NilClass, ] + SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, # 100 + SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, + SlotToReg, Syscall, NilClass, ] assert_equal 10 , get_return end diff --git a/test/risc/interpreter/blocks/test_block_return.rb b/test/risc/interpreter/blocks/test_block_return.rb index f0fcf80e..ea60bd7b 100644 --- a/test/risc/interpreter/blocks/test_block_return.rb +++ b/test/risc/interpreter/blocks/test_block_return.rb @@ -24,15 +24,14 @@ module Risc RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 60 SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg, - SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 70 - RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 80 - SlotToReg, Branch, SlotToReg, FunctionReturn, SlotToReg, - SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg, # 90 - RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 100 - Branch, SlotToReg, SlotToReg, FunctionReturn, Transfer, - SlotToReg, SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 70 + LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, # 80 + Branch, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 90 + SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, + SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 100 + SlotToReg, Syscall, NilClass, ] assert_equal 15 , get_return end diff --git a/test/risc/interpreter/calling/test_alloc.rb b/test/risc/interpreter/calling/test_alloc.rb index f59bb47a..f20caf07 100644 --- a/test/risc/interpreter/calling/test_alloc.rb +++ b/test/risc/interpreter/calling/test_alloc.rb @@ -11,8 +11,8 @@ module Risc end def test_chain - #show_base_ticks # get output of what is - check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + # show_main_ticks # get output of what is + check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20 @@ -22,11 +22,10 @@ module Risc RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40 LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, - Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 60 - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 70 - SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, + Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60 + SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, + SlotToReg, SlotToReg, Syscall, NilClass, ] assert_equal 10 , get_return end def base_ticks(num) diff --git a/test/risc/interpreter/calling/test_div10.rb b/test/risc/interpreter/calling/test_div10.rb index f79ecead..ebcd54b1 100644 --- a/test/risc/interpreter/calling/test_div10.rb +++ b/test/risc/interpreter/calling/test_div10.rb @@ -10,8 +10,8 @@ module Risc end def test_chain - #show_main_ticks # get output of what is - check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + # show_main_ticks # get output of what is + check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg, LoadConstant, # 20 @@ -26,11 +26,10 @@ module Risc RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, RegToSlot, # 70 SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 80 - Branch, SlotToReg, SlotToReg, RegToSlot, Branch, - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 90 - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, - SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 80 + LoadConstant, SlotToReg, RegToSlot, RegToSlot, Branch, + SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 90 + SlotToReg, SlotToReg, Syscall, NilClass, ] assert_equal 2 , get_return end @@ -44,7 +43,7 @@ module Risc assert_load load_ins, Parfait::Factory end def test_return_class - ret = main_ticks(93) + ret = main_ticks(89) assert_equal FunctionReturn , ret.class link = @interpreter.get_register( ret.register ) assert_equal ::Integer , link.class diff --git a/test/risc/interpreter/calling/test_get_byte.rb b/test/risc/interpreter/calling/test_get_byte.rb index 4f0f6a98..e1bc3c8d 100644 --- a/test/risc/interpreter/calling/test_get_byte.rb +++ b/test/risc/interpreter/calling/test_get_byte.rb @@ -19,12 +19,11 @@ module Risc SlotToReg, SlotToReg, SlotToReg, ByteToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 40 SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, # 50 - RegToSlot, SlotToReg, SlotToReg, RegToSlot, Branch, - Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 60 - SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, - SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg, # 70 - Syscall, NilClass, ] + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, # 50 + Branch, SlotToReg, SlotToReg, RegToSlot, Branch, + LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 60 + SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, + SlotToReg, Syscall, NilClass, ] assert_equal "H".ord , get_return end def test_byte_to_reg diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index 304ca87c..1b4388f8 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -21,11 +21,10 @@ module Risc RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40 LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, - Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 60 - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 70 - SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, + Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60 + SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, + SlotToReg, SlotToReg, Syscall, NilClass, ] assert_equal 1 , get_return end def test_op @@ -38,10 +37,10 @@ module Risc assert_equal 5 , @interpreter.get_register(:r3) end def test_return - ret = main_ticks(68) + ret = main_ticks(64) assert_equal FunctionReturn , ret.class assert_equal :r1 , ret.register.symbol - assert_equal 23196 , @interpreter.get_register(ret.register) + assert_equal 23004 , @interpreter.get_register(ret.register) end end end diff --git a/test/risc/interpreter/calling/test_mod.rb b/test/risc/interpreter/calling/test_mod.rb index 1f931684..3e1e49f2 100644 --- a/test/risc/interpreter/calling/test_mod.rb +++ b/test/risc/interpreter/calling/test_mod.rb @@ -10,7 +10,7 @@ module Risc end def test_chain - #show_main_ticks # get output of what is + # show_main_ticks # get output of what is check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, @@ -19,12 +19,11 @@ module Risc Branch, SlotToReg, LoadData, OperatorInstruction, RegToSlot, # 30 RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, # 40 - SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, - RegToSlot, SlotToReg, SlotToReg, RegToSlot, Branch, # 50 - SlotToReg, SlotToReg, RegToSlot, Branch, LoadConstant, - SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 60 - SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg, - Syscall, NilClass, ] + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, RegToSlot, + Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, # 50 + SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, + SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 60 + SlotToReg, Syscall, NilClass, ] assert_equal 2 , get_return end diff --git a/test/risc/interpreter/calling/test_mult.rb b/test/risc/interpreter/calling/test_mult.rb index d44cd5a0..e76ce604 100644 --- a/test/risc/interpreter/calling/test_mult.rb +++ b/test/risc/interpreter/calling/test_mult.rb @@ -11,7 +11,7 @@ module Risc def test_mult #show_main_ticks # get output of what is - check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20 @@ -21,11 +21,10 @@ module Risc RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40 LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, - Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 60 - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 70 - SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, + Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60 + SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, + SlotToReg, SlotToReg, Syscall, NilClass, ] assert_equal 0 , get_return end def test_zero diff --git a/test/risc/interpreter/calling/test_plus.rb b/test/risc/interpreter/calling/test_plus.rb index fea24498..191a3486 100644 --- a/test/risc/interpreter/calling/test_plus.rb +++ b/test/risc/interpreter/calling/test_plus.rb @@ -10,8 +10,8 @@ module Risc end def test_chain - #show_base_ticks # get output of what is - check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + # show_main_ticks # get output of what is + check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20 @@ -21,11 +21,11 @@ module Risc RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, # 40 LoadConstant, SlotToReg, RegToSlot, Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, # 50 - SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, - Branch, Branch, SlotToReg, SlotToReg, RegToSlot, # 60 - LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, - SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, # 70 - SlotToReg, Syscall, NilClass, ] + RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, + Branch, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60 + SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, + SlotToReg, SlotToReg, Syscall, NilClass, ] + assert_equal 10 , get_return end def base_ticks(num) diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index 68337854..a6af4c58 100644 --- a/test/risc/interpreter/calling/test_puts.rb +++ b/test/risc/interpreter/calling/test_puts.rb @@ -20,11 +20,11 @@ module Risc Transfer, Transfer, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, # 40 RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg, - FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 50 - SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, - RegToSlot, Branch, LoadConstant, SlotToReg, RegToSlot, # 60 - RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, - Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ] # 70 + FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, # 50 + SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, Branch, SlotToReg, SlotToReg, SlotToReg, # 60 + FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, + NilClass, ] assert_equal "Hello again" , @interpreter.stdout assert_equal 11 , get_return #bytes written end @@ -57,7 +57,7 @@ module Risc assert_reg_to_slot( sl , :r1 ,:r2 , 5) end def test_return - done = main_ticks(65) + done = main_ticks(61) assert_equal FunctionReturn , done.class end diff --git a/test/risc/interpreter/calling/test_set_byte.rb b/test/risc/interpreter/calling/test_set_byte.rb index 6e89a70e..1fcd00f1 100644 --- a/test/risc/interpreter/calling/test_set_byte.rb +++ b/test/risc/interpreter/calling/test_set_byte.rb @@ -11,7 +11,7 @@ module Risc def test_chain #show_main_ticks # get output of what is - check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, + check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10 RegToSlot, LoadConstant, SlotToReg, Branch, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 20 @@ -20,10 +20,9 @@ module Risc SlotToReg, SlotToReg, RegToByte, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, # 40 RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, - SlotToReg, SlotToReg, Branch, RegToSlot, SlotToReg, # 50 - SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, - RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, # 60 - SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn, + SlotToReg, RegToSlot, Branch, Branch, SlotToReg, # 50 + SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 60 Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ] assert_equal "K".ord , get_return end diff --git a/test/risc/interpreter/test_dynamic_call.rb b/test/risc/interpreter/test_dynamic_call.rb index 1cdb44bc..becbcec7 100644 --- a/test/risc/interpreter/test_dynamic_call.rb +++ b/test/risc/interpreter/test_dynamic_call.rb @@ -35,11 +35,10 @@ module Risc OperatorInstruction, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 110 RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn, # 120 - SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, - RegToSlot, Branch, SlotToReg, SlotToReg, Branch, # 130 - RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot, - SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 140 - SlotToReg, SlotToReg, Syscall, NilClass, ] + SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, Branch, # 130 + RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, + Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]# 140 assert_equal ::Integer , get_return.class assert_equal 1 , get_return end @@ -60,13 +59,13 @@ module Risc assert_equal DynamicJump , cal.class end def test_return - ret = main_ticks(139) + ret = main_ticks(135) assert_equal FunctionReturn , ret.class link = @interpreter.get_register( ret.register ) assert_equal ::Integer , link.class end def test_sys - sys = main_ticks(143) + sys = main_ticks(139) assert_equal Syscall , sys.class end end diff --git a/test/ruby/test_yield_statement.rb b/test/ruby/test_yield_statement.rb index 11664447..66dfe800 100644 --- a/test/ruby/test_yield_statement.rb +++ b/test/ruby/test_yield_statement.rb @@ -1,20 +1,6 @@ require_relative "helper" module Ruby - class TestYieldStatementVool < MiniTest::Test - include RubyTests - - def setup() - input = "yield(0)" - @lst = compile( input ).to_vool - end - def test_block - assert_equal Vool::YieldStatement , @lst.class - end - def test_block_args - assert_equal Vool::IntegerConstant , @lst.arguments.first.class - end - end class TestYieldStatement < MiniTest::Test include RubyTests @@ -32,4 +18,18 @@ module Ruby assert_equal "yield(0)" , @lst.to_s end end + class TestYieldStatementVool < MiniTest::Test + include RubyTests + + def setup() + input = "yield(0)" + @lst = compile( input ).to_vool + end + def test_block + assert_equal Vool::YieldStatement , @lst.class + end + def test_block_args + assert_equal Vool::IntegerConstant , @lst.arguments.first.class + end + end end diff --git a/test/rubyx/parfait/README.md b/test/rubyx/parfait/README.md new file mode 100644 index 00000000..2adb8080 --- /dev/null +++ b/test/rubyx/parfait/README.md @@ -0,0 +1,25 @@ +# Test Parfait compilation + +Parfait has tests in tests/parfait which test it using mri. + +## Parsing and compiling Parfait + +Since we need Parfait in the runtime, we need to parse it and compile it. +And since it is early days, we expect errors at every level during this process, which +means testing every layer for every file. + +Rather than create parfait tests for every layer (ie in the vool/mom/risc directories) +we have one file per parfait file here. Each file tests all layers. + +The usual workflow is to start with a new file and create tests for vool, mom, risc,binary +in that order. Possibly fixing the compiler on the way. Then adding the file to +the RubyXCompiler parfait load list. + +## Testing compiled Parfait + +The next step is to test the compiled parfait. Since we have tests, the best way would +be to parse and execute the tests. This would involve creating a mini MiniTest and some +fancy footwork in the compilation. But it should be possible to create one executable / +interpreted test for each of the exising Parfait test. + +Alas, this is for another day. diff --git a/test/rubyx/parfait/helper.rb b/test/rubyx/parfait/helper.rb new file mode 100644 index 00000000..7ca6d99d --- /dev/null +++ b/test/rubyx/parfait/helper.rb @@ -0,0 +1,13 @@ +require_relative "../helper" + +module RubyX + module ParfaitHelper + + def load_parfait(file) + File.read File.expand_path("../../../../lib/parfait/#{file}.rb",__FILE__) + end + def compiler + RubyXCompiler.new(RubyX.default_test_options) + end + end +end diff --git a/test/rubyx/parfait/test_object.rb b/test/rubyx/parfait/test_object.rb new file mode 100644 index 00000000..197a04ba --- /dev/null +++ b/test/rubyx/parfait/test_object.rb @@ -0,0 +1,25 @@ +require_relative "helper" + +module RubyX + + class TestObjecCompile < MiniTest::Test + include ParfaitHelper + def source + load_parfait(:object2) + end + def test_load + assert source.include?("class Object") + assert source.length > 2000 + end + def est_vool + vool = compiler.ruby_to_vool source + assert_equal Vool::ClassStatement , vool.class + assert_equal :Object , vool.name + end + def est_mom + vool = compiler.ruby_to_mom source + assert_equal Vool::ClassStatement , vool.class + assert_equal :Object , vool.name + end + end +end diff --git a/test/vool/blocks/test_if_condition.rb b/test/vool/blocks/test_if_condition.rb index 052cc3a5..3bd7666c 100644 --- a/test/vool/blocks/test_if_condition.rb +++ b/test/vool/blocks/test_if_condition.rb @@ -11,18 +11,18 @@ module VoolBlocks end def test_condition - assert_equal TruthCheck , @ins.next(4).class + assert_equal TruthCheck , @ins.next(3).class end def test_condition_is_slot - assert_equal SlotDefinition , @ins.next(4).condition.class , @ins + assert_equal SlotDefinition , @ins.next(3).condition.class , @ins end - def test_hoisted_dynamic_call + def test_simple_call assert_equal SimpleCall , @ins.next(2).class assert_equal :div4 , @ins.next(2).method.name end def test_array - check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, TruthCheck, Label , - SlotLoad, Jump, Label, SlotLoad, Label, + check_array [MessageSetup, ArgumentTransfer, SimpleCall, TruthCheck, Label , + SlotLoad, Jump, Label, SlotLoad, Label , Label, ReturnSequence, Label] , @ins end diff --git a/test/vool/send/test_send_cached_simple.rb b/test/vool/send/test_send_cached_simple.rb index 7e9f4318..0e2989fc 100644 --- a/test/vool/send/test_send_cached_simple.rb +++ b/test/vool/send/test_send_cached_simple.rb @@ -5,12 +5,11 @@ module Vool include VoolCompile def setup - Parfait.boot!(Parfait.default_test_options) @compiler = compile_first_method( "a = 5; a.div4") @ins = @compiler.mom_instructions.next end def test_check_type - assert_equal NotSameCheck , @ins.next.class , @ins + assert_equal NotSameCheck , @ins.next(1).class , @ins end def test_type_update load = @ins.next(2) @@ -27,9 +26,9 @@ module Vool end def test_array - check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup , - ArgumentTransfer, DynamicCall, Label, ReturnSequence , - Label] , @ins + check_array [SlotLoad, NotSameCheck, SlotLoad, ResolveMethod , + Label, MessageSetup, ArgumentTransfer, DynamicCall, Label , + ReturnSequence, Label] , @ins end end diff --git a/test/vool/test_return.rb b/test/vool/test_return.rb index 8b15a158..49cf292a 100644 --- a/test/vool/test_return.rb +++ b/test/vool/test_return.rb @@ -48,11 +48,11 @@ module Vool end def test_return_is_last - assert_equal ReturnJump , @ins.next(5).class + assert_equal ReturnJump , @ins.next(4).class end def test_array - check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad, - SlotLoad,ReturnJump, Label, ReturnSequence, Label] , @ins + check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, ReturnJump , + Label, ReturnSequence, Label] , @ins end end end diff --git a/test/vool/test_yield_statement.rb b/test/vool/test_yield_statement.rb index 17fb22e2..1dbd59ad 100644 --- a/test/vool/test_yield_statement.rb +++ b/test/vool/test_yield_statement.rb @@ -1,11 +1,32 @@ require_relative "helper" module Vool - module YieldBasics - include Mom + class TestYieldArgsSendMom < MiniTest::Test + include VoolCompile + + def setup + Parfait.boot!(Parfait.default_test_options) + @compiler = compile_first_method( "return yield(1)" ) + @ins = @compiler.mom_instructions.next + end + + def test_array + check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield , + SlotLoad, ReturnJump, Label, ReturnSequence , Label] , @ins + end def test_check_label assert_equal NotSameCheck, @ins.class - assert @ins.false_jump.name.start_with?("method_ok_") + assert @ins.false_jump.name.start_with?("method_ok_") , @ins.false_jump.name + 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_check_left assert_equal SlotDefinition, @ins.left.class @@ -38,64 +59,37 @@ module Vool 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).left.slots 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 ReturnJump, @ins.next(7).class - end - end - class TestYieldArgsSendMom < MiniTest::Test - include VoolCompile - include YieldBasics - - def setup - Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "return yield(1)" ) - @ins = @compiler.mom_instructions.next - end - - def test_array - check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield , - SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence , - Label] , @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 + assert_equal ReturnJump, @ins.next(6).class end end class TestYieldNoArgsSendMom < MiniTest::Test include VoolCompile - include YieldBasics + def setup Parfait.boot!(Parfait.default_test_options) - @compiler = compile_first_method( "return yield" ) + @compiler = compile_first_method( "return yield(some.extra.calls)" ) @ins = @compiler.mom_instructions.next end + def test_check_label + assert_equal NotSameCheck, @ins.class + assert @ins.false_jump.name.start_with?("cache_ok_") , @ins.false_jump.name + end def test_array - check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield , - SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence , - Label] , @ins + check_array [NotSameCheck, SlotLoad, ResolveMethod, Label, MessageSetup , + ArgumentTransfer, DynamicCall, SlotLoad, NotSameCheck, SlotLoad , + ResolveMethod, Label, MessageSetup, ArgumentTransfer, DynamicCall , + SlotLoad, NotSameCheck, SlotLoad, ResolveMethod, Label , + MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, NotSameCheck , + Label, MessageSetup, ArgumentTransfer, BlockYield, SlotLoad , + ReturnJump, Label, ReturnSequence, Label] , @ins end def test_transfer - assert_equal ArgumentTransfer, @ins.next(3).class - assert_equal 0, @ins.next(3).arguments.length + assert_equal ArgumentTransfer, @ins.next(5).class + assert_equal 0, @ins.next(5).arguments.length end end end