rename the XX_slot classes to SlottedXX

move to slotted and slots (wip)
This commit is contained in:
Torsten Rüger 2020-02-15 21:02:03 +07:00
parent 8b29326957
commit b7df6f66f9
41 changed files with 96 additions and 58 deletions

View File

@ -26,7 +26,7 @@ module SlotLanguage
end
def to_slot(compiler)
SlotMachine::Slot.for(:message , name)
SlotMachine::Slotted.for(:message , name)
end
def to_s

View File

@ -31,8 +31,8 @@ module SlotMachine
def initialize(source , left , right, original_source = nil)
super(source)
@left , @right = left , right
@left = Slot.for(@left.shift , @left) if @left.is_a? Array
@right = Slot.for(@right.shift , @right) if @right.is_a? Array
@left = Slotted.for(@left.shift , @left) if @left.is_a? Array
@right = Slotted.for(@right.shift , @right) if @right.is_a? Array
raise "right not SlotMachine, #{@right.to_s}" unless @right.is_a?( Slot )
raise "left not SlotMachine, #{@left.to_s}" unless @left.is_a?( Slot )
@original_source = original_source || self

View File

@ -19,11 +19,11 @@ module SlotMachine
def self.for(object , slots)
case object
when :message
MessageSlot.new(slots)
SlottedMessage.new(slots)
when Constant
ConstantSlot.new(object , slots)
SlottedConstant.new(object , slots)
when Parfait::Object , Risc::Label
ObjectSlot.new(object , slots)
SlottedObject.new(object , slots)
else
raise "not supported type #{object}"
end

View File

@ -12,10 +12,11 @@
# Machine capabilities (instructions) for basic operations.
# Use of macros for higher level.
require_relative "slotted"
require_relative "slot"
require_relative "message_slot"
require_relative "constant_slot"
require_relative "object_slot"
require_relative "slotted_message"
require_relative "slotted_constant"
require_relative "slotted_object"
require_relative "instruction"
require_relative "slot_collection"
require_relative "callable_compiler"

View File

@ -0,0 +1,37 @@
module SlotMachine
class Slotted
def self.for(object , slots)
case object
when :message
SlottedMessage.new(slots)
when Constant
SlottedConstant.new(object , slots)
when Parfait::Object , Risc::Label
SlottedObject.new(object , slots)
else
raise "not supported type #{object}"
end
end
attr_reader :slots
# is an array of symbols, that specifies the first the object, and then the Slot.
# The first element is either a known type name (Capitalized symbol of the class name) ,
# or the symbol :message
# And subsequent symbols must be instance variables on the previous type.
# Examples: [:message , :receiver] or [:Space , :next_message]
def initialize( slots)
raise "No slots #{object}" unless slots
slots = [slots] unless slots.is_a?(Array)
@slots = slots
end
def to_s
names = [known_name] + @slots
"[#{names.join(', ')}]"
end
end
end

View File

@ -1,5 +1,5 @@
module SlotMachine
class ConstantSlot < Slot
class SlottedConstant < Slot
attr_reader :known_object

View File

@ -1,5 +1,5 @@
module SlotMachine
class MessageSlot < Slot
class SlottedMessage < Slot
def initialize(slots)
super(slots)
@ -8,7 +8,7 @@ module SlotMachine
def known_name
:message
end
alias :known_object :known_name
alias :known_object :known_name
# load the slots into a register
# the code is added to compiler

View File

@ -1,5 +1,5 @@
module SlotMachine
class ObjectSlot < Slot
class SlottedObject < Slot
attr_reader :known_object

View File

@ -32,7 +32,7 @@ module Sol
#
# Derived classes do not implement to_slot, only slot_position
def to_slot(compiler)
to = SlotMachine::Slot.for(:message , self.slot_position(compiler))
to = SlotMachine::Slotted.for(:message , self.slot_position(compiler))
from = @value.to_slot_definition(compiler)
assign = SlotMachine::SlotLoad.new(self,to,from)
return assign unless @value.is_a?(CallStatement)

View File

@ -10,7 +10,7 @@ module Sol
@value = value
end
def to_slot_definition(_)
return SlotMachine::Slot.for(SlotMachine::IntegerConstant.new(@value) , [])
return SlotMachine::Slotted.for(SlotMachine::IntegerConstant.new(@value) , [])
end
def ct_type
Parfait.object_space.get_type_by_class_name(:Integer)
@ -38,7 +38,7 @@ module Sol
Parfait.object_space.get_type_by_class_name(:True)
end
def to_slot_definition(_)
return SlotMachine::Slot.for(Parfait.object_space.true_object , [])
return SlotMachine::Slotted.for(Parfait.object_space.true_object , [])
end
def to_s(depth = 0)
"true"
@ -50,7 +50,7 @@ module Sol
Parfait.object_space.get_type_by_class_name(:False)
end
def to_slot_definition(_)
return SlotMachine::Slot.for(Parfait.object_space.false_object , [])
return SlotMachine::Slotted.for(Parfait.object_space.false_object , [])
end
def to_s(depth = 0)
"false"
@ -62,7 +62,7 @@ module Sol
Parfait.object_space.get_type_by_class_name(:Nil)
end
def to_slot_definition(_)
return SlotMachine::Slot.for(Parfait.object_space.nil_object , [])
return SlotMachine::Slotted.for(Parfait.object_space.nil_object , [])
end
def to_s(depth = 0)
"nil"
@ -77,7 +77,7 @@ module Sol
end
def to_slot_definition(compiler)
@my_type = compiler.receiver_type
SlotMachine::Slot.for(:message , [:receiver])
SlotMachine::Slotted.for(:message , [:receiver])
end
def ct_type
@my_type
@ -92,7 +92,7 @@ module Sol
@value = value
end
def to_slot_definition(_)
return SlotMachine::Slot.for(SlotMachine::StringConstant.new(@value),[])
return SlotMachine::Slotted.for(SlotMachine::StringConstant.new(@value),[])
end
def ct_type
Parfait.object_space.get_type_by_class_name(:Word)

View File

@ -11,7 +11,7 @@ module Sol
# When used as right hand side, this tells what data to move to get the result into
# a varaible. It is (off course) the return value of the message
def to_slot_definition(_)
SlotMachine::Slot.for(:message ,[ :return_value])
SlotMachine::Slotted.for(:message ,[ :return_value])
end
def to_s(depth = 0)

View File

@ -15,7 +15,7 @@ module Sol
# fact never called)
def to_slot_definition(compiler)
compile(compiler) unless @parfait_block
return SlotMachine::Slot.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) , [])
return SlotMachine::Slotted.for(SlotMachine::LambdaConstant.new(parfait_block(compiler)) , [])
end
# create a block, a compiler for it, compile the block and add the compiler(code)

View File

@ -15,7 +15,7 @@ module Sol
# When used as right hand side, this tells what data to move to get the result into
# a varaible. It is (off course) the return value of the message
def to_slot_definition(_)
SlotMachine::Slot.for(:message ,[ :return_value])
SlotMachine::Slotted.for(:message ,[ :return_value])
end
def to_s(depth = 0)

View File

@ -116,7 +116,7 @@ module Sol
defi
end
def build_condition(ok_label, compiler)
cached_type = SlotMachine::Slot.for(dynamic_call.cache_entry , [:cached_type])
cached_type = SlotMachine::Slotted.for(dynamic_call.cache_entry , [:cached_type])
current_type = receiver_type_definition(compiler)
SlotMachine::NotSameCheck.new(cached_type , current_type, ok_label)
end

View File

@ -12,7 +12,7 @@ module Sol
include Named
def to_slot_definition(compiler)
slot_def = compiler.slot_type_for(@name)
SlotMachine::Slot.for(:message , slot_def)
SlotMachine::Slotted.for(:message , slot_def)
end
def to_s(depth = 0)
name.to_s
@ -25,7 +25,7 @@ module Sol
class InstanceVariable < Expression
include Named
def to_slot_definition(_)
SlotMachine::Slot.for(:message , [ :receiver , @name] )
SlotMachine::Slotted.for(:message , [ :receiver , @name] )
end
# used to collect type information
def add_ivar( array )
@ -52,7 +52,7 @@ module Sol
get_named_class.single_class.instance_type
end
def to_slot_definition(_)
return SlotMachine::Slot.for( get_named_class, [])
return SlotMachine::Slotted.for( get_named_class, [])
end
def get_named_class
Parfait.object_space.get_class_by_name(self.name)

View File

@ -34,8 +34,8 @@ module Sol
# we brace ourselves with the check, and exit (later raise) if . . .
def method_check(compiler)
ok_label = SlotMachine::Label.new(self,"method_ok_#{self.object_id}")
compile_method = SlotMachine::Slot.for( compiler.get_method , [])
runtime_method = SlotMachine::Slot.for( :message , [ :method] )
compile_method = SlotMachine::Slotted.for( compiler.get_method , [])
runtime_method = SlotMachine::Slotted.for( :message , [ :method] )
check = SlotMachine::NotSameCheck.new(compile_method , runtime_method, ok_label)
# TODO? Maybe create slot instructions for this
#builder = compiler.builder("yield")

View File

@ -3,7 +3,7 @@ require_relative "helper"
module SlotMachine
class TestArgumentTransfer < SlotMachineInstructionTest
def instruction
receiver = MessageSlot.new( [:receiver])
receiver = SlottedMessage.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 = Slot.for(:message , :caller)
target = Slotted.for(:message , :caller)
NotSameCheck.new(target , target , Label.new("ok" , "target"))
end
def test_len

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ module SlotMachine
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = Slot.for(StringConstant.new("hi") , [])
@definition = Slotted.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 = Slot.for(StringConstant.new("hi") , [:type])
@definition = Slotted.for(StringConstant.new("hi") , [:type])
@register = @definition.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end

View File

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

View File

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

View File

@ -31,7 +31,7 @@ module Sol
def test_receiver
assert_equal SlotMachine::ArgumentTransfer, @ins.next(1).class
assert_equal 0, @ins.next(1).arguments.length
assert_equal ObjectSlot, @ins.next(1).receiver.class
assert_equal SlottedObject, @ins.next(1).receiver.class
assert_equal Parfait::Class, @ins.next(1).receiver.known_object.class
assert_equal :Space, @ins.next(1).receiver.known_object.name
end

View File

@ -39,7 +39,7 @@ module Sol
assert_equal :Object , @ins.next.receiver.known_object.name
end
def test_receiver_move
assert_equal ObjectSlot, @ins.next.receiver.class
assert_equal SlottedObject, @ins.next.receiver.class
end
def test_receiver
assert_equal Parfait::Class, @ins.next.receiver.known_object.class

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::MessageSlot , @ins.right.class , @ins
assert_equal SlotMachine::SlottedMessage , @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 MessageSlot , @ins.next(3).condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.next.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot, @ins.next.receiver.class
assert_equal SlottedMessage, @ins.next.receiver.class
end
def test_arg_one
assert_equal SlotLoad, @ins.next(1).arguments[0].class
@ -23,7 +23,7 @@ module Sol
assert_equal :get_internal_word, @ins.next(2).method.name
end
def test_receiver_move
assert_equal MessageSlot, @ins.next.receiver.class
assert_equal SlottedMessage, @ins.next.receiver.class
end
end

View File

@ -14,7 +14,7 @@ module Sol
assert_equal :div4, @ins.next(2).method.name
end
def test_receiver_move
assert_equal ConstantSlot, @ins.next.receiver.class
assert_equal SlottedConstant, @ins.next.receiver.class
end
end

View File

@ -24,7 +24,7 @@ module Sol
Label, ReturnSequence , Label] , @ins
end
def test_receiver_move
assert_equal ConstantSlot, @ins.next.receiver.class
assert_equal SlottedConstant, @ins.next.receiver.class
end
end

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::MessageSlot , @ins.right.class , @ins
assert_equal SlotMachine::SlottedMessage , @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 MessageSlot , @ins.next.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.next(3).condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.next.condition.class , @ins
assert_equal SlottedMessage , @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 MessageSlot , @ins.next(4).condition.class , @ins
assert_equal SlottedMessage , @ins.next(4).condition.class , @ins
end
def test_hoisetd
jump = @ins.next(8)

View File

@ -28,13 +28,13 @@ module Sol
assert_equal [:next_message, :arg1], left.slots
end
def test_check_left
assert_equal ObjectSlot, @ins.left.class
assert_equal SlottedObject, @ins.left.class
assert_equal Parfait::CallableMethod, @ins.left.known_object.class
assert_equal :main, @ins.left.known_object.name
assert @ins.left.slots.empty?
end
def test_check_right
assert_equal MessageSlot, @ins.right.class
assert_equal SlottedMessage, @ins.right.class
assert_equal :message, @ins.right.known_object
assert_equal [:method] , @ins.right.slots
end