2019-02-16 16:54:45 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-10-03 19:55:41 +02:00
|
|
|
class TestSendClassSlotMachine < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-02-16 16:54:45 +01:00
|
|
|
|
2019-09-30 16:09:13 +02:00
|
|
|
def class_main
|
|
|
|
<<-eos
|
|
|
|
class Space
|
|
|
|
def self.one_plus(one)
|
|
|
|
return 1 + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Space
|
|
|
|
def main(arg)
|
|
|
|
return Space.one_plus(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
eos
|
|
|
|
end
|
|
|
|
|
2019-09-18 21:07:58 +02:00
|
|
|
def setup
|
2019-09-30 16:09:13 +02:00
|
|
|
source = "class Integer < Data4;def +(other);X.int_operator(:+);end;end;" + class_main
|
2019-10-03 19:55:41 +02:00
|
|
|
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(source)
|
|
|
|
@ins = ret.compilers.find_compiler_name(:main).slot_instructions.next
|
2019-02-16 16:54:45 +01:00
|
|
|
end
|
2019-02-23 17:17:26 +01:00
|
|
|
|
2019-09-18 21:07:58 +02:00
|
|
|
def test_array
|
|
|
|
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,
|
|
|
|
ReturnJump,Label, ReturnSequence , Label] , @ins
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_compiles
|
|
|
|
assert_equal MessageSetup , @ins.class , @ins
|
|
|
|
end
|
2019-02-16 16:54:45 +01:00
|
|
|
def test_receiver
|
2020-02-11 10:19:52 +01:00
|
|
|
assert_equal Slot, @ins.next.receiver.class
|
2019-02-23 17:17:26 +01:00
|
|
|
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
|
|
|
|
assert_equal :Object , @ins.next.receiver.known_object.name
|
2019-02-16 16:54:45 +01:00
|
|
|
end
|
2019-09-18 21:07:58 +02:00
|
|
|
def test_receiver_move
|
2020-02-15 15:02:03 +01:00
|
|
|
assert_equal SlottedObject, @ins.next.receiver.class
|
2019-09-18 21:07:58 +02:00
|
|
|
end
|
|
|
|
def test_receiver
|
|
|
|
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
|
|
|
|
end
|
2019-02-16 16:54:45 +01:00
|
|
|
def test_arg_one
|
|
|
|
assert_equal SlotLoad, @ins.next(1).arguments[0].class
|
|
|
|
end
|
2019-09-18 21:07:58 +02:00
|
|
|
def test_receiver_move_class
|
|
|
|
assert_equal ArgumentTransfer, @ins.next(1).class
|
2019-02-16 16:54:45 +01:00
|
|
|
end
|
2019-09-18 21:07:58 +02:00
|
|
|
def test_call_is
|
|
|
|
assert_equal SimpleCall, @ins.next(2).class
|
2019-02-16 16:54:45 +01:00
|
|
|
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
|
2019-09-30 16:09:13 +02:00
|
|
|
assert_equal :one_plus, @ins.next(2).method.name
|
2019-02-16 16:54:45 +01:00
|
|
|
end
|
|
|
|
def test_call_has_right_receiver
|
2019-09-30 16:09:13 +02:00
|
|
|
assert_equal "Space.Single_Type", @ins.next(2).method.self_type.name
|
2019-02-16 16:54:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|