2015-05-06 07:38:29 +02:00
|
|
|
module Virtual
|
|
|
|
# A slot is a slot in an object. It is the storage location for a value.
|
|
|
|
# (Remember, values are typed)
|
|
|
|
# From a memory perspective a slot is an index into an array (the object)
|
2015-06-29 09:55:22 +02:00
|
|
|
# The mapping into arrays is a straightforward matter, but happens in the
|
|
|
|
# next level down, the register machine.
|
2015-05-06 07:38:29 +02:00
|
|
|
|
|
|
|
# Four known objects exist and those correspond to subclasses:
|
|
|
|
# - the message that has been received: MessageSlot
|
|
|
|
# - the frame of the method that is executing (local variables): FrameSlot
|
2015-10-07 09:04:00 +02:00
|
|
|
# - self as an object: SelfsSlot
|
2015-06-29 19:55:45 +02:00
|
|
|
# - a message that will be sent, NewMessageSlot
|
2015-05-06 07:38:29 +02:00
|
|
|
|
|
|
|
# additionally frame, self and return are slots in Message and NewMessage
|
|
|
|
|
|
|
|
# Slot has a lot of small subclasses
|
|
|
|
# Names for the slots avoid indexes
|
|
|
|
|
|
|
|
class Slot < Object
|
|
|
|
|
2015-06-30 08:39:45 +02:00
|
|
|
# the name of the object of a slot is a symbol that represents what the class name describes
|
|
|
|
# ie it is one of :message , :self , :frame , :new_message
|
2015-07-01 20:45:21 +02:00
|
|
|
# one of the objects the machine works on.
|
2015-06-30 08:39:45 +02:00
|
|
|
def object_name
|
|
|
|
raise "abstract called #{self}"
|
|
|
|
end
|
|
|
|
|
2015-06-29 09:55:22 +02:00
|
|
|
attr_accessor :type , :value
|
2015-05-06 07:38:29 +02:00
|
|
|
|
2015-08-04 20:46:33 +02:00
|
|
|
def to_s
|
|
|
|
"#{self.class.name}.new(#{type}, #{value})"
|
|
|
|
end
|
2015-05-06 07:38:29 +02:00
|
|
|
private #abstract base class
|
|
|
|
|
2015-06-29 09:55:22 +02:00
|
|
|
def initialize type , value
|
2015-05-06 07:38:29 +02:00
|
|
|
@type = type
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
require_relative "message_slot"
|
2015-10-07 09:04:00 +02:00
|
|
|
require_relative "selfs_slot"
|
2015-06-20 22:49:30 +02:00
|
|
|
require_relative "frame_slot"
|
2015-07-01 20:45:21 +02:00
|
|
|
require_relative "new_message_slot"
|