first steps to defining specialised slot classes

getting rid of the mess in SlotDefinition (wip)
This commit is contained in:
2020-02-10 18:12:39 +07:00
parent df4fd409c1
commit 24d7fe25da
35 changed files with 104 additions and 62 deletions

View File

@ -3,7 +3,7 @@ require_relative "helper"
module SlotMachine
class TestArgumentTransfer < SlotMachineInstructionTest
def instruction
receiver = SlotDefinition.new(:message , [:receiver])
receiver = MessageDefinition.new( [:receiver])
arg = SlotLoad.new("test", [:message, :caller] , [:message,:type] )
ArgumentTransfer.new("" , receiver ,[arg])
end

View File

@ -3,7 +3,7 @@ require_relative "helper"
module SlotMachine
class TestNotSameCheck < SlotMachineInstructionTest
def instruction
target = SlotDefinition.new(:message , :caller)
target = SlotDefinition.for(:message , :caller)
NotSameCheck.new(target , target , Label.new("ok" , "target"))
end
def test_len

View File

@ -4,7 +4,7 @@ module SlotMachine
class TestSlotDefinitionBasics < MiniTest::Test
def slot(slot = :caller)
SlotDefinition.new(:message , slot)
MessageDefinition.new(slot)
end
def test_create_ok1
assert_equal :message , slot.known_object

View File

@ -6,7 +6,7 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = SlotDefinition.new(StringConstant.new("hi") , [])
@definition = SlotDefinition.for(StringConstant.new("hi") , [])
@register = @definition.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end
@ -27,7 +27,7 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = SlotDefinition.new(StringConstant.new("hi") , [:type])
@definition = SlotDefinition.for(StringConstant.new("hi") , [:type])
@register = @definition.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end

View File

@ -5,7 +5,7 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = SlotDefinition.new(:message , :caller)
@definition = MessageDefinition.new( :caller)
@register = @definition.to_register(@compiler , "fake source")
@instruction = @compiler.instructions.first
end

View File

@ -5,7 +5,7 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = SlotDefinition.new(:message , [:caller , :type])
@definition = MessageDefinition.new( [:caller , :type])
@register = @definition.to_register(@compiler , InstructionMock.new)
end
def test_def_next_class

View File

@ -3,7 +3,7 @@ require_relative "helper"
module SlotMachine
class TestSameCheck < SlotMachineInstructionTest
def instruction
target = SlotDefinition.new(:message , :caller)
target = MessageDefinition.new( :caller)
TruthCheck.new(target , Label.new("ok" , "target"))
end
def test_len

View File

@ -53,11 +53,11 @@ module Sol
assert_equal SlotLoad, @ins.class
end
def test_left
assert_equal SlotDefinition , @ins.left.class
assert_equal MessageDefinition , @ins.left.class
assert_equal [:return_value] , @ins.left.slots
end
def test_right
assert_equal SlotDefinition , @ins.right.class
assert_equal MessageDefinition , @ins.right.class
assert_equal [:receiver , :inst] , @ins.right.slots
end
end

View File

@ -73,7 +73,7 @@ module SolBlocks
def test_assigns_move
@ins = compile_main_block( "@a = arg")
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::SlotDefinition , @ins.right.class , @ins
assert_equal SlotMachine::MessageDefinition , @ins.right.class , @ins
end
end

View File

@ -12,7 +12,7 @@ module SolBlocks
assert_equal TruthCheck , @ins.next(3).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
assert_equal MessageDefinition , @ins.next(3).condition.class , @ins
end
def test_simple_call
assert_equal SimpleCall , @ins.next(2).class

View File

@ -15,7 +15,7 @@ module SolBlocks
assert_equal TruthCheck , @ins.next.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next.condition.class , @ins
assert_equal MessageDefinition , @ins.next.condition.class , @ins
end
def test_array
check_array [Label, TruthCheck, SlotLoad, Jump, Label,

View File

@ -8,7 +8,7 @@ module Sol
"self.get_internal_word(0);return"
end
def test_receiver
assert_equal SlotDefinition, @ins.next.receiver.class
assert_equal MessageDefinition, @ins.next.receiver.class
end
def test_arg_one
assert_equal SlotLoad, @ins.next(1).arguments[0].class
@ -22,6 +22,10 @@ module Sol
def test_call_has_right_method
assert_equal :get_internal_word, @ins.next(2).method.name
end
def test_receiver_move
assert_equal MessageDefinition, @ins.next.receiver.class
end
end
class TestSendSelfImplicitSlotMachine < TestSendSelfSlotMachine

View File

@ -79,7 +79,7 @@ module Sol
@compiler = compile_main( "@a = arg;return")
@ins = @compiler.slot_instructions.next
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::SlotDefinition , @ins.right.class , @ins
assert_equal SlotMachine::MessageDefinition , @ins.right.class , @ins
end
end

View File

@ -18,7 +18,7 @@ module Sol
assert_equal TruthCheck , @ins.next.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next.condition.class , @ins
assert_equal MessageDefinition , @ins.next.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next(2).class , @ins

View File

@ -14,7 +14,7 @@ module Sol
assert_equal TruthCheck , @ins.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.condition.class , @ins
assert_equal MessageDefinition , @ins.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next.class , @ins

View File

@ -14,7 +14,7 @@ module Sol
assert_equal TruthCheck , @ins.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.condition.class , @ins
assert_equal MessageDefinition , @ins.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next.class , @ins

View File

@ -14,7 +14,7 @@ module Sol
assert_equal TruthCheck , @ins.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.condition.class , @ins
assert_equal MessageDefinition , @ins.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next.class , @ins

View File

@ -13,7 +13,7 @@ module Sol
assert_equal TruthCheck , @ins.next(3).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(3).condition.class , @ins
assert_equal MessageDefinition , @ins.next(3).condition.class , @ins
end
def test_hoisted_call
assert_equal SimpleCall , @ins.next(2).class

View File

@ -16,7 +16,7 @@ module Sol
assert_equal TruthCheck , @ins.next.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next.condition.class , @ins
assert_equal MessageDefinition , @ins.next.condition.class , @ins
end
def test_array
check_array [Label, TruthCheck, SlotLoad, Jump, Label ,

View File

@ -14,7 +14,7 @@ module Sol
assert_equal TruthCheck , @ins.next(4).class
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next(4).condition.class , @ins
assert_equal MessageDefinition , @ins.next(4).condition.class , @ins
end
def test_hoisetd
jump = @ins.next(8)

View File

@ -34,7 +34,7 @@ module Sol
assert @ins.left.slots.empty?
end
def test_check_right
assert_equal SlotDefinition, @ins.right.class
assert_equal MessageDefinition, @ins.right.class
assert_equal :message, @ins.right.known_object
assert_equal [:method] , @ins.right.slots
end