rename the XX_slot classes to SlottedXX

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

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