Unify instruction namings also dirs

Was getting confused myself, where it was instruction or instructions, when if the base class was inside or out of dir.
Now dirs are plural, and base class is inside.
This commit is contained in:
2020-03-02 17:58:13 +02:00
parent f3d299208e
commit db5a59f735
36 changed files with 34 additions and 34 deletions

View File

@@ -0,0 +1,40 @@
require_relative '../helper'
module SlotMachine
# Most SlotMachineInstructionTests test the risc instructions of the slot instruction
# quite carefully, ie every instruction, every register.
#
# This is done with the assert methods in risc_assert
#
# Most tests go through instructions from top to bottom.
# For working code, one can get a list of those instructions by using the all_str as message
# Most tests will test for length and give the all_str as message to see where it went wrong
# like: assert_equal 8 , all.length , all_str
class SlotMachineInstructionTest < MiniTest::Test
include Output
def setup
Parfait.boot!(Parfait.default_test_options)
@instruction = instruction
@compiler = Risc::MethodCompiler.new(Risc::FakeCallable.new , Label.new("source","start"))
@instruction.to_risc(@compiler)
@risc = @compiler.risc_instructions
end
def risc(at)
return @risc if at == 0
@risc.next( at )
end
def all
ret = []
@risc.each {|i| ret << i}
ret
end
def all_str
class_list(all.collect{|i|i.class})
end
end
end

View File

@@ -0,0 +1,35 @@
require_relative "helper"
module SlotMachine
class TestArgumentTransfer < SlotMachineInstructionTest
def instruction
receiver = SlottedMessage.new( [:arg1])
arg = SlottedMessage.new( [:receiver , :type])
ArgumentTransfer.new("" , receiver ,[arg])
end
def test_len
assert_equal 8 , all.length , all_str
end
def test_1_slot
assert_slot_to_reg risc(1) ,:message , 9 , :"message.arg1"
end
def test_2_slot
assert_slot_to_reg risc(2) ,:message , 1 , :"message.next_message"
end
def test_3_reg
assert_reg_to_slot risc(3) , :"message.arg1" , :"message.next_message" , 2
end
def test_4_slot
assert_slot_to_reg risc(4) ,:message , 2 , :"message.receiver"
end
def test_5
assert_slot_to_reg risc(5) ,:"message.receiver" , 0 , :"message.receiver.type"
end
def test_6
assert_slot_to_reg risc(6) ,:message , 1 , :"message.next_message"
end
def test_7
assert_reg_to_slot risc(7) , :"message.receiver.type" , :"message.next_message" , 9
end
end
end

View File

@@ -0,0 +1,35 @@
require_relative "helper"
module SlotMachine
class TesBlockYield < SlotMachineInstructionTest
def instruction
BlockYield.new("source",1)
end
def test_len
assert_equal 8 , all.length , all_str
end
def test_1_slot
assert_slot_to_reg risc(1) ,:r0 , 1 , :r1
end
def test_2_load
assert_load risc(2) , Risc::Label , :r2
assert_label risc(2).constant , "continue_"
end
def test_3_reg
assert_reg_to_slot risc(3) , :r2 , :r1 , 4
end
def test_4_slot
assert_slot_to_reg risc(4) ,:r0 , 9 , :r3
end
def test_5_slot
assert_slot_to_reg risc(5) ,:r0 , 1 , :r0
end
def test_6_jump
assert_equal Risc::DynamicJump , risc(6).class
assert_equal :r3 , risc(6).register.symbol
end
def test_7_label
assert_label risc(7) , "continue_"
end
end
end

View File

@@ -0,0 +1,37 @@
require_relative "helper"
module SlotMachine
class TestDynamicCall < SlotMachineInstructionTest
def instruction
DynamicCall.new(nil,nil)
end
def test_len
assert_equal 9 , all.length , all_str
end
def test_1_load
assert_load risc(1) , Risc::Label , :r1
assert_label risc(1).constant , "continue_"
end
def test_2_slot
assert_slot_to_reg risc(2) ,:r0 , 1 , :r2
end
def test_3_reg
assert_reg_to_slot risc(3) , :r1 , :r2 , 4
end
def test_4_slot
assert_slot_to_reg risc(4) ,:r0 , 1 , :r0
end
def test_5_load
assert_load risc(5) , Parfait::CacheEntry , :r3
end
def test_6_slot
assert_slot_to_reg risc(6) ,:r3 , 2 , :r3
end
def test_7_jump
assert_equal Risc::DynamicJump , risc(7).class
end
def test_8_label
assert_label risc(8) , "continue_"
end
end
end

View File

@@ -0,0 +1,15 @@
require_relative "helper"
module SlotMachine
class TestJump < SlotMachineInstructionTest
def instruction
Jump.new( Label.new("ok" , "target"))
end
def test_len
assert_equal 2 , all.length , all_str
end
def test_1_slot
assert_branch risc(1) , "target"
end
end
end

View File

@@ -0,0 +1,46 @@
require_relative "helper"
module SlotMachine
class TestMessageSetupInt < SlotMachineInstructionTest
def instruction
MessageSetup.new( 1 )
end
def test_len
assert_equal 4 , all.length , all_str
end
def test_1_slot
assert_slot_to_reg risc(1) ,:message , 9 , :"message.arg1"
end
def test_2_slot
assert_slot_to_reg risc(2) ,:message , 1 , :"message.next_message"
end
def test_3_reg
assert_reg_to_slot risc(3) , :"message.arg1" , :"message.next_message" , 7
end
end
class TestMessageSetupCache < SlotMachineInstructionTest
include Parfait::MethodHelper
def instruction
method = make_method
cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
MessageSetup.new( cache_entry )
end
def test_len
assert_equal 5 , all.length , all_str
end
def test_1_load
assert_load risc(1) , Parfait::CacheEntry , "id_"
end
def test_2_slot
assert_slot_to_reg risc(2) ,"id_" , 2 , "id_.cached_method"
end
def test_3_slot
assert_slot_to_reg risc(3) ,:message , 1 , :"message.next_message"
end
def test_4_reg
assert_reg_to_slot risc(4) , "id_.cached_method" , :"message.next_message" , 7
end
end
end

View File

@@ -0,0 +1,26 @@
require_relative "helper"
module SlotMachine
class TestNotSameCheck < SlotMachineInstructionTest
def instruction
target = Slotted.for(:message , [:caller])
target2 = Slotted.for(:message , [:next_message])
NotSameCheck.new(target , target2 , Label.new("ok" , "target"))
end
def test_len
assert_equal 5 , all.length , all_str
end
def test_1_slot
assert_slot_to_reg risc(1) ,:message , 6 , :"message.caller"
end
def test_2_slot
assert_slot_to_reg risc(2) ,:message , 1 , :"message.next_message"
end
def test_3_op
assert_operator risc(3) , :-, :"message.caller" , :"message.next_message"
end
def test_4_zero
assert_zero risc(4) , "target"
end
end
end

View File

@@ -0,0 +1,72 @@
require_relative "helper"
module SlotMachine
class TestResolveMethod < SlotMachineInstructionTest
include Parfait::MethodHelper
def instruction
method = make_method
cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
ResolveMethod.new( "method" , :name , cache_entry )
end
def test_len
assert_equal 19 , all.length , all_str
end
def test_1_load_name
assert_load risc(1) , Symbol , :r1
assert_equal :name , risc(1).constant
end
def test_2_load_cache
assert_load risc(2) , Parfait::CacheEntry , :r2
end
def test_3_get_cache_type
assert_slot_to_reg risc(3) ,:r2 , 1 , :r3
end
def test_4_get_type_methods
assert_slot_to_reg risc(4) ,:r3 , 4 , :r4
end
def test_5_start_label
assert_label risc(5) , "while_start_"
end
def test_6_load_nil
assert_load risc(6) , Parfait::NilClass , :r5
end
def test_7_check_nil
assert_operator risc(7) , :- , :r5 , :r4
end
def test_8_nil_branch
assert_zero risc(8) , "exit_label_"
end
def test_9_get_method_name
assert_slot_to_reg risc(9) ,:r4 , 6 , :r6
end
# Syscall, Label, RegToSlot,] #20
def test_10_check_name
assert_operator risc(10) , :- , :r6 , :r1
end
def test_11_nil_branch
assert_zero risc(11) , "ok_label_"
end
def test_12_get_next_method
assert_slot_to_reg risc(12) ,:r4 , 2 , :r4
end
def test_13_continue_while
assert_branch risc(13) , "while_start_"
end
def test_14_goto_exit
assert_label risc(14) , "exit_label_"
end
def test_15_move_name
assert_transfer( risc(15) , :r1 , :r1)
end
def test_16_die
assert_syscall risc(16) , :died
end
def test_17_label
assert_label risc(17) , "ok_label_"
end
def test_18_load_method
assert_reg_to_slot risc(18) , :r4 , :r2 , 2
end
end
end

View File

@@ -0,0 +1,15 @@
require_relative "helper"
module SlotMachine
class TestReturnJump < SlotMachineInstructionTest
def instruction
ReturnJump.new("source",Label.new("ok" , "return"))
end
def test_len
assert_equal 2 , all.length , all_str
end
def test_2_branch
assert_branch risc(1) ,"return"
end
end
end

View File

@@ -0,0 +1,34 @@
require_relative "helper"
module SlotMachine
class TestReturnSequence < SlotMachineInstructionTest
def instruction
ReturnSequence.new("source")
end
def test_len
assert_equal 8 , all.length , all_str
end
def test_1_load_return_value
assert_slot_to_reg risc(1) ,:r0 , 5 , :r1
end
def test_2_load_caller
assert_slot_to_reg risc(2) ,:r0 , 6 , :r2
end
def test_3_store_return_in_caller
assert_reg_to_slot risc(3) , :r1 , :r2 , 5
end
def test_4_load_return_address
assert_slot_to_reg risc(4) ,:r0 , 4 , :r3
end
def test_5_get_int_for_address
assert_slot_to_reg risc(5) ,:r3 , 2 , :r3
end
def test_6_swap_messages
assert_slot_to_reg risc(6) ,:r0 , 6 , :r0
end
def test_7_do_return
assert_equal Risc::FunctionReturn , risc(7).class
assert_equal :r3 , risc(7).register.symbol
end
end
end

View File

@@ -0,0 +1,35 @@
require_relative "helper"
module SlotMachine
class TestSimpleCall < SlotMachineInstructionTest
include Parfait::MethodHelper
def instruction
SimpleCall.new( make_method )
end
def est_len
assert_equal 7 , all.length , all_str
end
def test_1_load_return_label
assert_load risc(1) , Risc::Label , "id_"
assert_label risc(1).constant , "continue_"
end
def test_2_load_next_message
assert_slot_to_reg risc(2) ,:message , 1 , :"message.next_message"
end
def test_3_store_return_address
assert_reg_to_slot risc(3) , "id_" , :"message.next_message" , 4
end
def test_4_swap_messages
assert_slot_to_reg risc(4) ,:message , 1 , :message
end
def test_5_call
assert_equal Risc::FunctionCall , risc(5).class
assert_equal :meth , risc(5).method.name
end
def test_6_label
assert_equal Risc::Label , risc(6).class
assert_label risc(6) , "continue_"
end
end
end

View File

@@ -0,0 +1,24 @@
require_relative "helper"
module SlotMachine
class TestSlotLoadBasics < MiniTest::Test
def setup
Parfait.boot!({})
end
def test_ins_ok
assert SlotLoad.new("test", [:message, :caller] , [:message , :receiver,:type] )
end
def test_ins_fail1
assert_raises {SlotLoad.new( "test",[:message, :caller] , nil )}
end
def pest_fail_on_right
load = SlotLoad.new( "test",[:message, :caller] , [:message ,:receiver,:type] )
assert_raises {load.to_risc(Risc.test_compiler)}
end
def pest_fail_on_left_long
load = SlotLoad.new("test", [:message, :caller , :type , :type] , [:message,:type] )
assert_raises {load.to_risc(Risc.test_compiler)}
end
end
end

View File

@@ -0,0 +1,39 @@
require_relative "helper"
module SlotMachine
class TestSlotLoad1 < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
load = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
compiler = Risc.test_compiler
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_class
assert_equal Risc::SlotToReg , @instructions.class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions.next.class
end
def test_ins_arr
assert_equal :message , @instructions.array.symbol
end
def test_ins_reg
assert_equal :"message.type" , @instructions.register.symbol
end
def test_ins_index
assert_equal 0 , @instructions.index
end
def test_ins_next_reg
assert_equal :"message.type" , @instructions.next.register.symbol
end
def test_ins_next_arr
assert_equal :message , @instructions.next.array.symbol
end
def test_ins_next_index
assert_equal 6 , @instructions.next.index
end
end
end

View File

@@ -0,0 +1,36 @@
require_relative "helper"
module SlotMachine
class TestSlotLoad2 < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
compiler = Risc.test_compiler
load = SlotLoad.new( "test",[:message, :caller, :type] , [:message, :caller , :type] )
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_classes
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::SlotToReg , @instructions.next.class
assert_equal Risc::SlotToReg , @instructions.next(2).class
end
def test_ins_next_next_class
assert_equal Risc::RegToSlot , @instructions.next(3).class
assert_equal NilClass , @instructions.next(4).class
end
def test_ins
assert_slot_to_reg @instructions ,:message , 6 , "message.caller"
end
def test_ins_next
assert_slot_to_reg @instructions.next ,"message.caller" , 0 , "message.caller.type"
end
def test_ins_next_2
assert_slot_to_reg @instructions.next(2) , :message , 6 , "message.caller"
end
def test_ins_next_3
assert_reg_to_slot @instructions.next(3) ,"message.caller.type" , "message.caller" , 0
end
end
end

View File

@@ -0,0 +1,35 @@
require_relative "helper"
module SlotMachine
class TestSlotLoad3 < MiniTest::Test
include Parfait::MethodHelper
def setup
Parfait.boot!(Parfait.default_test_options)
method = make_method
compiler = Risc.test_compiler
@cache_entry = Parfait::CacheEntry.new(method.frame_type, method)
load = SlotLoad.new("test", [@cache_entry , :cached_type] , [:message, :type] )
load.to_risc(compiler)
@instructions = compiler.risc_instructions.next
end
def test_ins_next_class
assert_equal Risc::SlotToReg , @instructions.class
assert_equal Risc::LoadConstant, @instructions.next.class
end
def test_ins_next_class
assert_equal Risc::RegToSlot , @instructions.next(2).class
assert_equal NilClass , @instructions.next(3).class
end
def test_ins
assert_slot_to_reg @instructions , :message , 0 , "message.type"
end
def test_ins_next
assert_load @instructions.next , Parfait::CacheEntry , "id_"
end
def test_ins_next_2
assert_reg_to_slot @instructions.next(2) , :"message.type" , "id_", 1
end
end
end

View File

@@ -0,0 +1,37 @@
require_relative "helper"
module SlotMachine
class TestSameCheck < SlotMachineInstructionTest
def instruction
target = SlottedMessage.new( [:caller])
TruthCheck.new(target , Label.new("ok" , "target"))
end
def test_len
assert_equal 8 , all.length
assert_equal Risc::Label , all.first.class
end
def test_1_slot
assert_slot_to_reg risc(1) ,:message , 6 , :"message.caller"
end
def test_2_load
assert_load risc(2) , Parfait::FalseClass, "id_"
end
def test_3_op
assert_operator risc(3) , :- , "id_" , "message.caller"
end
def test_4_zero
assert_equal Risc::IsZero , risc(4).class
assert_label risc(4).label , "target"
end
def test_5_load
assert_load risc(5) , Parfait::NilClass , "id_"
end
def test_6_op
assert_operator risc(6), :- , "id_", "message.caller"
end
def test_7_zero
assert_equal Risc::IsZero , risc(7).class
assert_label risc(7).label , "target"
end
end
end