2018-04-19 18:47:35 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2019-10-03 20:07:55 +02:00
|
|
|
module SlotMachine
|
2018-04-19 18:47:35 +02:00
|
|
|
module Builtin
|
2019-08-11 13:31:00 +02:00
|
|
|
class BootTest < MiniTest::Test
|
2019-09-13 09:41:13 +02:00
|
|
|
include Preloader
|
2019-08-22 16:52:19 +02:00
|
|
|
|
2019-09-13 09:41:13 +02:00
|
|
|
def get_compiler(clazz , name)
|
|
|
|
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
2019-10-03 20:07:55 +02:00
|
|
|
coll = compiler.ruby_to_slot( get_preload("Space.main;#{clazz}.#{name}") )
|
2019-09-28 11:41:38 +02:00
|
|
|
@method = coll.method_compilers.last_compiler
|
2019-09-13 09:41:13 +02:00
|
|
|
@method
|
2019-08-11 13:31:00 +02:00
|
|
|
end
|
2019-09-13 09:41:13 +02:00
|
|
|
|
2020-03-06 17:09:56 +01:00
|
|
|
def risc(at)
|
|
|
|
@risc_i = @method.to_risc.risc_instructions unless @risc_i
|
|
|
|
return @risc_i if at == 0
|
|
|
|
@risc_i.next( at )
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_return(at)
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_label at , "return_label"
|
|
|
|
assert_slot_to_reg at + 1 , :message , 6 , "message.caller"
|
|
|
|
assert_slot_to_reg at + 2 , "message.caller" , 5 , "message.caller.return_value"
|
|
|
|
assert_reg_to_slot at + 3 ,"message.caller.return_value" , "message.caller" , 5
|
|
|
|
assert_slot_to_reg at + 4 , :message , 4 , "message.return_address"
|
|
|
|
assert_slot_to_reg at + 5 , :message , 6 , :message
|
|
|
|
assert_equal Risc::FunctionReturn , risc(at + 6).class
|
|
|
|
assert_label at + 7 , "unreachable"
|
2020-03-06 17:09:56 +01:00
|
|
|
end
|
|
|
|
def assert_allocate
|
2020-03-07 18:23:19 +01:00
|
|
|
assert_load 1 , Parfait::Factory , "id_factory_"
|
|
|
|
assert_load 2 , Parfait::NilClass , "id_nilclass_"
|
|
|
|
assert_slot_to_reg 3 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
|
|
assert_operator 4 , :- , "id_nilclass_" , "id_factory_.next_object"
|
|
|
|
assert_zero 5 , "cont_label"
|
|
|
|
assert_slot_to_reg 6 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
|
|
assert_reg_to_slot 7 , "id_factory_.next_object" , "id_factory_" , 2
|
|
|
|
assert_load 8 , Parfait::Factory , "id_factory_"
|
|
|
|
assert_load 9 , Parfait::CallableMethod , "id_callablemethod"
|
|
|
|
assert_slot_to_reg 10 , :message , 1 , "message.next_message"
|
|
|
|
assert_reg_to_slot 11 , "id_callablemethod_" , "message.next_message" , 7
|
|
|
|
assert_reg_to_slot 12 , "id_factory_" , :message , 2
|
|
|
|
assert_load 13 , Risc::Label , "id_label"
|
|
|
|
assert_slot_to_reg 14 , :message , 1 , "message.next_message"
|
|
|
|
assert_reg_to_slot 15 , "id_label" , "message.next_message" , 4
|
|
|
|
assert_slot_to_reg 16 ,:message , 1 , :message
|
2020-03-06 17:09:56 +01:00
|
|
|
assert_equal Risc::FunctionCall, risc(17).class
|
|
|
|
assert_equal :main, risc(17).method.name
|
2020-03-07 18:23:19 +01:00
|
|
|
assert_label 18 , "after_main_"
|
|
|
|
assert_label 19 , "cont_label"
|
|
|
|
assert_slot_to_reg 20 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
|
|
assert_slot_to_reg 21 , "id_factory_" , 2 , "id_factory_.next_object"
|
|
|
|
assert_reg_to_slot 22 , "id_factory_.next_object" , "id_factory_" , 2
|
2020-03-06 17:09:56 +01:00
|
|
|
end
|
2019-08-11 13:31:00 +02:00
|
|
|
end
|
2018-04-19 18:47:35 +02:00
|
|
|
end
|
|
|
|
end
|