Fix all but one test

Riples upon riples. The one left looks like the genuine article
This commit is contained in:
Torsten Rüger 2019-08-16 21:43:54 +03:00
parent 7c91a08d5b
commit d3f3c91ae5
23 changed files with 223 additions and 179 deletions

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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