2018-07-21 13:34:39 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-10-03 19:55:41 +02:00
|
|
|
class TestYieldArgsSendSlotMachine < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-08-16 20:43:54 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-12 12:10:31 +02:00
|
|
|
@compiler = compile_main( "return yield(1)" )
|
2019-10-03 19:55:41 +02:00
|
|
|
@ins = @compiler.slot_instructions.next
|
2019-08-16 20:43:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_array
|
|
|
|
check_array [NotSameCheck, Label, MessageSetup, ArgumentTransfer, BlockYield ,
|
|
|
|
SlotLoad, ReturnJump, Label, ReturnSequence , Label] , @ins
|
|
|
|
end
|
2018-07-24 10:35:49 +02:00
|
|
|
def test_check_label
|
|
|
|
assert_equal NotSameCheck, @ins.class
|
2020-02-18 20:16:44 +01:00
|
|
|
assert @ins.false_label.name.start_with?("method_ok_") , @ins.false_label.name
|
2019-08-16 20:43:54 +02:00
|
|
|
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
|
2020-02-27 17:19:27 +01:00
|
|
|
left = @ins.next(3).arguments[0]
|
|
|
|
assert_equal SlotMachine::IntegerConstant, left.known_object.class
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
|
|
|
def test_check_left
|
2020-02-15 15:02:03 +01:00
|
|
|
assert_equal SlottedObject, @ins.left.class
|
2018-07-24 10:35:49 +02:00
|
|
|
assert_equal Parfait::CallableMethod, @ins.left.known_object.class
|
|
|
|
assert_equal :main, @ins.left.known_object.name
|
2020-02-17 08:27:42 +01:00
|
|
|
assert !@ins.left.slots
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
|
|
|
def test_check_right
|
2020-02-15 15:02:03 +01:00
|
|
|
assert_equal SlottedMessage, @ins.right.class
|
2018-07-24 10:35:49 +02:00
|
|
|
assert_equal :message, @ins.right.known_object
|
2020-02-17 08:27:42 +01:00
|
|
|
assert_equal "message.method" , @ins.right.to_s
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
|
|
|
def test_label
|
|
|
|
assert_equal Label, @ins.next(1).class
|
|
|
|
assert @ins.next(1).name.start_with?("method_ok_")
|
2018-07-21 13:34:39 +02:00
|
|
|
end
|
2018-07-24 10:35:49 +02:00
|
|
|
def test_setup
|
|
|
|
assert_equal MessageSetup, @ins.next(2).class
|
2018-07-27 11:16:06 +02:00
|
|
|
assert_equal 2, @ins.next(2).method_source
|
2018-07-21 13:34:39 +02:00
|
|
|
end
|
2018-07-24 10:35:49 +02:00
|
|
|
def test_receiver
|
|
|
|
assert_equal :message , @ins.next(3).receiver.known_object
|
2020-02-17 08:27:42 +01:00
|
|
|
assert_equal :receiver , @ins.next(3).receiver.slots.name
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
2018-07-30 19:11:52 +02:00
|
|
|
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
|
2020-02-17 08:27:42 +01:00
|
|
|
assert_equal :return_value, @ins.next(5).left.slots.name
|
|
|
|
assert_equal :return_value, @ins.next(5).right.slots.name
|
2018-07-30 19:11:52 +02:00
|
|
|
end
|
|
|
|
def test_return
|
2019-08-16 20:43:54 +02:00
|
|
|
assert_equal ReturnJump, @ins.next(6).class
|
2018-07-30 19:11:52 +02:00
|
|
|
end
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
class TestYieldNoArgsSendSlotMachine < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2018-07-30 19:11:52 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-12 12:10:31 +02:00
|
|
|
@compiler = compile_main( "return yield(some.extra.calls)" )
|
2019-10-03 19:55:41 +02:00
|
|
|
@ins = @compiler.slot_instructions.next
|
2018-07-30 19:11:52 +02:00
|
|
|
end
|
2019-08-16 20:43:54 +02:00
|
|
|
def test_check_label
|
|
|
|
assert_equal NotSameCheck, @ins.class
|
2020-03-25 11:43:57 +01:00
|
|
|
assert @ins.false_label.name.start_with?("send_cache_some_ok_") , @ins.false_label.name
|
2018-07-30 19:11:52 +02:00
|
|
|
end
|
|
|
|
def test_array
|
2019-08-16 20:43:54 +02:00
|
|
|
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
|
2018-07-30 19:11:52 +02:00
|
|
|
end
|
|
|
|
def test_transfer
|
2019-08-16 20:43:54 +02:00
|
|
|
assert_equal ArgumentTransfer, @ins.next(5).class
|
|
|
|
assert_equal 0, @ins.next(5).arguments.length
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
2018-07-21 13:34:39 +02:00
|
|
|
end
|
|
|
|
end
|