Redoing ruby block conversion

Since the block is actually a constant, it does not need assignment or special hoisting
Just use the send and stick the lambda in as last arg
This commit is contained in:
2019-08-19 14:23:55 +03:00
parent f87526f86f
commit 3ddf2e3837
7 changed files with 37 additions and 72 deletions

View File

@ -33,24 +33,17 @@ module Ruby
@lst = compile( input ).to_vool
end
def test_block
assert_equal Vool::Statements , @lst.class
assert_equal Vool::SendStatement , @lst.class
end
def test_first
assert_equal Vool::LocalAssignment , @lst.first.class
assert @lst.first.name.to_s.start_with?("implicit_block_")
assert_equal Vool::LambdaExpression , @lst.first.value.class
end
def test_last_send
assert_equal 2 , @lst.length
assert_equal Vool::SendStatement , @lst.last.class
assert_equal :plus_one , @lst.last.name
def test_send_name
assert_equal :plus_one , @lst.name
end
def test_send_block_arg
assert_equal 1 , @lst.last.arguments.length
assert @lst.last.arguments.first.name.to_s.start_with?("implicit_block_")
assert_equal 1 , @lst.arguments.length
assert_equal Vool::LambdaExpression , @lst.arguments.first.class
end
def test_block_args
assert_equal [:arg1] , @lst.first.value.args
assert_equal [:arg1] , @lst.arguments.first.args
end
end
end

View File

@ -33,26 +33,19 @@ module Ruby
def test_scope
assert_equal Vool::ScopeStatement , @lst.class
end
def test_first
assert_equal Vool::Statements , @lst.first.class
def test_assign
assert_equal Vool::LocalAssignment , @lst.first.class
assert_equal :a , @lst.first.name
end
def test_block_assign
assert_equal Vool::LocalAssignment , @lst.first.first.class
assert @lst.first.first.name.to_s.start_with?("implicit_block")
def test_send
assert_equal Vool::SendStatement , @lst.first.value.class
assert_equal :plus_one , @lst.first.value.name
end
def test_block_assign_right
assert_equal Vool::LambdaExpression , @lst.first.first.value.class
end
def test_a_assign
assert_equal Vool::LocalAssignment , @lst.first.last.class
assert_equal :a , @lst.first.last.name
end
def test_a_assign_val
assert_equal Vool::SendStatement , @lst.first.last.value.class
assert_equal :plus_one , @lst.first.last.value.name
def test_block_arg
assert_equal Vool::LambdaExpression , @lst.first.value.arguments.first.class
end
def test_ret
assert_equal Vool::ReturnStatement , @lst.last.class
assert_equal Vool::ReturnStatement , @lst[1].class
end
end
end

View File

@ -39,13 +39,14 @@ module Ruby
end
class TestSendSuperVool < MiniTest::Test
include RubyTests
def test_super0_receiver
lst = compile( "super").to_vool
assert_equal Vool::SuperExpression , lst.receiver.class
end
def test_super0
lst = compile( "super").to_vool
assert_equal Vool::SendStatement , lst.class
assert_equal Vool::Statements , lst.class
assert_equal Vool::SendStatement , lst.last.class
end
def test_super0_receiver
lst = compile( "super").to_vool
assert_equal Vool::SuperExpression , lst.first.value.class
end
end
class TestSendSuperArgsVool < MiniTest::Test
@ -54,13 +55,14 @@ module Ruby
@lst = compile( "super(1)").to_vool
end
def test_super_class
assert_equal Vool::SendStatement , @lst.class
assert_equal Vool::Statements , @lst.class
assert_equal Vool::SendStatement , @lst.last.class
end
def test_super_receiver
assert_equal Vool::SuperExpression , @lst.receiver.class
assert_equal Vool::SuperExpression , @lst.first.value.class
end
def test_super_name #is nil
assert_nil @lst.name
def test_super_name
assert @lst.first.name.to_s.start_with?("tmp")
end
end
class TestSendReceiverTypeVool < MiniTest::Test