moving know_object out of the base class
object is only common to constant and object slots (which should be unified) On the way to making the array recursive
This commit is contained in:
parent
6aa6b32c50
commit
8b29326957
@ -1,22 +1,15 @@
|
||||
module SlotMachine
|
||||
class ConstantSlot < Slot
|
||||
# get the right definition, depending on the object
|
||||
def self.for(object , slots)
|
||||
case object
|
||||
when :message
|
||||
MessageSlot.new(slots)
|
||||
when Constant
|
||||
ConstantSlot.new(object , slots)
|
||||
else
|
||||
Slot.new(object,slots)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
attr_reader :known_object
|
||||
|
||||
def initialize( object , slots)
|
||||
super(object, slots)
|
||||
super(slots)
|
||||
@known_object = object
|
||||
raise "Not known #{slots}" unless object
|
||||
end
|
||||
|
||||
|
||||
def known_name
|
||||
known_object.class.short_name
|
||||
end
|
||||
@ -31,18 +24,15 @@ module SlotMachine
|
||||
type = :Object
|
||||
end
|
||||
right = compiler.use_reg( type )
|
||||
case known_object
|
||||
when Constant
|
||||
parfait = known_object.to_parfait(compiler)
|
||||
const = Risc.load_constant(source, parfait , right)
|
||||
compiler.add_code const
|
||||
if slots.length == 1
|
||||
raise "only type allowed for constants, not #{slots[0]}" unless slots[0] == :type
|
||||
compiler.add_code Risc::SlotToReg.new( source , right , Parfait::TYPE_INDEX, right)
|
||||
end
|
||||
raise "Can't have slots into Constants #{slots}" if slots.length > 1
|
||||
parfait = known_object.to_parfait(compiler)
|
||||
const = Risc.load_constant(source, parfait , right)
|
||||
compiler.add_code const
|
||||
if slots.length == 1
|
||||
raise "only type allowed for constants, not #{slots[0]}" unless slots[0] == :type
|
||||
compiler.add_code Risc::SlotToReg.new( source , right , Parfait::TYPE_INDEX, right)
|
||||
end
|
||||
return const.register
|
||||
raise "Can't have slots into Constants #{slots}" if slots.length > 1
|
||||
return const.register
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,12 +2,13 @@ module SlotMachine
|
||||
class MessageSlot < Slot
|
||||
|
||||
def initialize(slots)
|
||||
super(:message , slots)
|
||||
super(slots)
|
||||
end
|
||||
|
||||
def known_name
|
||||
:message
|
||||
end
|
||||
alias :known_object :known_name
|
||||
|
||||
# load the slots into a register
|
||||
# the code is added to compiler
|
||||
|
@ -1,8 +1,12 @@
|
||||
module SlotMachine
|
||||
class ObjectSlot < Slot
|
||||
|
||||
attr_reader :known_object
|
||||
|
||||
def initialize( object , slots)
|
||||
super(object , slots )
|
||||
super(slots)
|
||||
@known_object = object
|
||||
raise "Not known #{slots}" unless object
|
||||
end
|
||||
|
||||
def known_name
|
||||
|
@ -29,17 +29,16 @@ module SlotMachine
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :known_object , :slots
|
||||
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( object , slots)
|
||||
def initialize( slots)
|
||||
raise "No slots #{object}" unless slots
|
||||
slots = [slots] unless slots.is_a?(Array)
|
||||
@known_object , @slots = object , slots
|
||||
raise "Not known #{slots}" unless object
|
||||
@slots = slots
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -1 +1,9 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module SlotMachine
|
||||
class InstructionMock < Instruction
|
||||
def initialize
|
||||
super("mocking")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,6 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module SlotMachine
|
||||
class InstructionMock < Instruction
|
||||
def initialize
|
||||
super("mocking")
|
||||
end
|
||||
end
|
||||
|
||||
# Most SlotMachineInstructionTests test the risc instructions of the slot instruction
|
||||
# quite carefully, ie every instruction, every register.
|
||||
|
Loading…
x
Reference in New Issue
Block a user