2019-08-12 12:16:15 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
module SlotMachine
|
2019-08-12 12:16:15 +02:00
|
|
|
module Builtin
|
|
|
|
class TestWordPutRisc < BootTest
|
|
|
|
def setup
|
2019-09-13 09:41:13 +02:00
|
|
|
@method = get_compiler("Word",:put)
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot_length
|
2019-09-13 09:41:13 +02:00
|
|
|
assert_equal :putstring , @method.callable.name
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal 7 , @method.slot_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
def test_compile
|
|
|
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
|
|
|
end
|
|
|
|
def test_risc_length
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_equal 44 , @method.to_risc.risc_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
2020-03-06 17:09:56 +01:00
|
|
|
def test_allocate
|
|
|
|
assert_allocate
|
|
|
|
end
|
|
|
|
def test_all
|
2020-03-11 21:31:16 +01:00
|
|
|
s = Risc.allocate_length
|
|
|
|
assert_reg_to_slot s + 1 , "id_factory_.next_object" , :message , 5
|
|
|
|
assert_slot_to_reg s + 2 ,:message , 2 , "message.receiver"
|
|
|
|
assert_slot_to_reg s + 3 ,"message.receiver" , 1 , "id_factory_.next_object"
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_transfer s + 4 , :"message.receiver" , :syscall_1
|
|
|
|
assert_transfer s + 5 , "id_factory_.next_object" , :syscall_2
|
|
|
|
assert_transfer s + 6 , :message , :saved_message
|
|
|
|
assert_syscall s + 7 , :putstring
|
2020-03-22 13:30:03 +01:00
|
|
|
assert_transfer s + 8 , :syscall_1 , :restore_integer_return
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_transfer s + 9 , :saved_message , :message
|
2020-03-11 21:31:16 +01:00
|
|
|
assert_slot_to_reg s + 10 ,:message , 5 , "message.return_value"
|
2020-03-22 13:30:03 +01:00
|
|
|
assert_reg_to_slot s + 11 , :restore_integer_return , "message.return_value" , 2
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_slot_to_reg s + 12 ,:message , 5 , "message.return_value"
|
|
|
|
assert_reg_to_slot s + 13 , "message.return_value" , :message , 5
|
|
|
|
assert_branch s + 14 , "return_label"
|
|
|
|
assert_label s + 15 , "return_label"
|
2020-03-06 17:09:56 +01:00
|
|
|
end
|
|
|
|
def test_return
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_return(36)
|
2020-03-06 17:09:56 +01:00
|
|
|
end
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|