starting to clear up slots
mostly docs
This commit is contained in:
parent
95bc824f9b
commit
eeaf2d97de
@ -1,7 +1,7 @@
|
|||||||
module Register
|
module Register
|
||||||
# load a constant into a register
|
# load a constant into a register
|
||||||
#
|
#
|
||||||
# first arguemnt is the register the constant is loaded into
|
# first argument is the register the constant is loaded into
|
||||||
# second is the actual constant
|
# second is the actual constant
|
||||||
|
|
||||||
class LoadConstant < Instruction
|
class LoadConstant < Instruction
|
||||||
|
@ -4,3 +4,7 @@ require_relative "assembler"
|
|||||||
require_relative "passes/set_implementation"
|
require_relative "passes/set_implementation"
|
||||||
require_relative "passes/return_implementation"
|
require_relative "passes/return_implementation"
|
||||||
require_relative "passes/call_implementation"
|
require_relative "passes/call_implementation"
|
||||||
|
|
||||||
|
# So the memory model of the machine allows for indexed access into an "object" .
|
||||||
|
# A fixed number of objects exist (ie garbage collection is reclaming, not destroying and
|
||||||
|
# recreating) although there may be a way to increase that number.
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
module Virtual
|
module Virtual
|
||||||
# The Virtual Machine is a value based virtual machine in which ruby is implemented.
|
# The Virtual Machine is a object based virtual machine in which ruby is implemented.
|
||||||
# While it is value based, it resembles oo in basic ways of object encapsulation and method
|
|
||||||
# invocation, it is a "closed" / static sytem in that all types are know and there is no
|
|
||||||
# dynamic dispatch (so we don't bite our tail here).
|
|
||||||
#
|
#
|
||||||
# It is minimal and realistic and low level
|
# It is minimal and realistic and low level
|
||||||
# - minimal means that if one thing can be implemented by another, it is left out. This is quite
|
# - minimal means that if one thing can be implemented by another, it is left out. This is quite
|
||||||
@ -10,17 +7,13 @@ module Virtual
|
|||||||
# - realistic means it is easy to implement on a 32 bit machine (arm) and possibly 64 bit.
|
# - realistic means it is easy to implement on a 32 bit machine (arm) and possibly 64 bit.
|
||||||
# Memory access,some registers of same size are the underlying hardware. (not ie byte machine)
|
# Memory access,some registers of same size are the underlying hardware. (not ie byte machine)
|
||||||
# - low level means it's basic instructions are realively easily implemented in a register machine.
|
# - low level means it's basic instructions are realively easily implemented in a register machine.
|
||||||
# ie send is not a an instruction but a function.
|
# Low level means low level in oo terms though, so basic instruction to implement oo
|
||||||
|
# #
|
||||||
|
# The ast is transformed to virtual-machine objects, some of which represent code, some data.
|
||||||
#
|
#
|
||||||
# So the memory model of the machine allows for indexed access into an "object" .
|
# The next step transforms to the register machine layer, which is quite close to what actually
|
||||||
# A fixed number of objects exist (ie garbage collection is reclaming, not destroying and
|
# executes. The step after transforms to Arm, which creates executables.
|
||||||
# recreating) although there may be a way to increase that number.
|
|
||||||
#
|
#
|
||||||
# The ast is transformed to virtaul-machine objects, some of which represent code, some data.
|
|
||||||
#
|
|
||||||
# The next step transforms to the register machine layer, which is what actually executes.
|
|
||||||
#
|
|
||||||
|
|
||||||
# More concretely, a virtual machine is a sort of oo turing machine, it has a current instruction,
|
# More concretely, a virtual machine is a sort of oo turing machine, it has a current instruction,
|
||||||
# executes the instructions, fetches the next one and so on.
|
# executes the instructions, fetches the next one and so on.
|
||||||
# Off course the instructions are not soo simple, but in oo terms quite so.
|
# Off course the instructions are not soo simple, but in oo terms quite so.
|
||||||
@ -28,16 +21,23 @@ module Virtual
|
|||||||
# The machine is virtual in the sense that it is completely modeled in software,
|
# The machine is virtual in the sense that it is completely modeled in software,
|
||||||
# it's complete state explicitly available (not implicitly by walking stacks or something)
|
# it's complete state explicitly available (not implicitly by walking stacks or something)
|
||||||
|
|
||||||
# The machine has a no register, but local variables, a scope at each point in time.
|
# The machine has a no register, but objects that represent it's state. There are four
|
||||||
# Scope changes with calls and blocks, but is saved at each level. In terms of lower level
|
# - message : the currently executing message (See Parfait::Message)
|
||||||
# implementation this means that the the model is such that what is a variable in ruby,
|
# - receiver : or self. This is actually an instance of Message, but "hoisted" out
|
||||||
# never ends up being just on the pysical stack.
|
# - frame : A pssible frame for temporary data. Also part of the message and "hoisted" out
|
||||||
|
# - next_message: A message object that the current activation wants to send.
|
||||||
#
|
#
|
||||||
|
# Messages form a linked list (not a stack) and the Space is responsible for storing
|
||||||
|
# and handing out empty messages
|
||||||
|
#
|
||||||
|
# The "machine" is not part of the run-time (Parfait)
|
||||||
|
|
||||||
class Machine
|
class Machine
|
||||||
|
|
||||||
|
FIRST_PASS = "Virtual::SendImplementation"
|
||||||
def initialize
|
def initialize
|
||||||
@parser = Parser::Salama.new
|
@parser = Parser::Salama.new
|
||||||
@passes = [ "Virtual::SendImplementation" ]
|
@passes = [ FIRST_PASS ]
|
||||||
@objects = []
|
@objects = []
|
||||||
@booted = false
|
@booted = false
|
||||||
end
|
end
|
||||||
@ -82,8 +82,8 @@ module Virtual
|
|||||||
# as before, run all passes that are registered
|
# as before, run all passes that are registered
|
||||||
# (but now finer control with before/after versions)
|
# (but now finer control with before/after versions)
|
||||||
def run_passes
|
def run_passes
|
||||||
run_before "Virtual::SendImplementation"
|
run_before FIRST_PASS
|
||||||
run_after "Virtual::SendImplementation"
|
run_after FIRST_PASS
|
||||||
end
|
end
|
||||||
|
|
||||||
# Objects are data and get assembled after functions
|
# Objects are data and get assembled after functions
|
||||||
|
12
lib/virtual/slots/frame_slot.rb
Normal file
12
lib/virtual/slots/frame_slot.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module Virtual
|
||||||
|
|
||||||
|
# Slots in the Frame a re represented by instances of FrameSlot
|
||||||
|
|
||||||
|
# Slots in the Frame are local or temporary varialbes in a message
|
||||||
|
class FrameSlot < Slot
|
||||||
|
def initialize index , type = Unknown, value = nil
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,5 +1,20 @@
|
|||||||
module Virtual
|
module Virtual
|
||||||
# The message that is being processed has a layout as per the constant above
|
|
||||||
|
MESSAGE_CALLER = 0
|
||||||
|
MESSAGE_RETURN_ADDRESS = 1
|
||||||
|
MESSAGE_EXCEPTION_ADDRESS = 2
|
||||||
|
MESSAGE_SELF = 3
|
||||||
|
MESSAGE_NAME = 4
|
||||||
|
MESSAGE_RETURN_VALUE = 5
|
||||||
|
MESSAGE_FRAME = 6
|
||||||
|
MESSAGE_PAYLOAD = 7
|
||||||
|
|
||||||
|
# The current Message is one of four objects the virtual machine knows
|
||||||
|
#
|
||||||
|
# Slots represent instance variables of objects, so MessageSlots
|
||||||
|
# represent instance variables of Message objects.
|
||||||
|
# The Message has a layout as per the constant above
|
||||||
|
|
||||||
class MessageSlot < Slot
|
class MessageSlot < Slot
|
||||||
def initialize index , type = Unknown , value = nil
|
def initialize index , type = Unknown , value = nil
|
||||||
super(index ,type , value )
|
super(index ,type , value )
|
||||||
|
21
lib/virtual/slots/self_slot.rb
Normal file
21
lib/virtual/slots/self_slot.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module Virtual
|
||||||
|
|
||||||
|
# Self (the receiver of the current message) is a Slot in the Message.
|
||||||
|
# The current self in the current message and if the current message
|
||||||
|
# want to send a message it puts the new self into the next_message.
|
||||||
|
#
|
||||||
|
# The slot in the Message is represented by instances of class Self
|
||||||
|
# (and slots in the next_message by instances of NewSelf)
|
||||||
|
#
|
||||||
|
# Additionally the current Self is represented as it's own top-level object.
|
||||||
|
# If self is an Object one can refer to it's instance variables as Slots in SelfSlot
|
||||||
|
#
|
||||||
|
# In Summary: class Self represents the self object and SelfSlot instances variables of
|
||||||
|
# that object
|
||||||
|
#
|
||||||
|
class SelfSlot < Slot
|
||||||
|
def initialize index , type = Unknown, value = nil
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,7 +2,7 @@ module Virtual
|
|||||||
# A slot is a slot in an object. It is the storage location for a value.
|
# A slot is a slot in an object. It is the storage location for a value.
|
||||||
# (Remember, values are typed)
|
# (Remember, values are typed)
|
||||||
# From a memory perspective a slot is an index into an array (the object)
|
# From a memory perspective a slot is an index into an array (the object)
|
||||||
# But we are not modelling the array here, but the index into it.
|
# We are not modelling the array here, but the index into it.
|
||||||
|
|
||||||
# Four known objects exist and those correspond to subclasses:
|
# Four known objects exist and those correspond to subclasses:
|
||||||
# - the message that has been received: MessageSlot
|
# - the message that has been received: MessageSlot
|
||||||
@ -21,15 +21,6 @@ module Virtual
|
|||||||
FRAME_REGISTER = :r2
|
FRAME_REGISTER = :r2
|
||||||
NEW_MESSAGE_REGISTER = :r3
|
NEW_MESSAGE_REGISTER = :r3
|
||||||
|
|
||||||
MESSAGE_CALLER = 0
|
|
||||||
MESSAGE_RETURN_ADDRESS = 1
|
|
||||||
MESSAGE_EXCEPTION_ADDRESS = 2
|
|
||||||
MESSAGE_SELF = 3
|
|
||||||
MESSAGE_NAME = 4
|
|
||||||
MESSAGE_RETURN_VALUE = 5
|
|
||||||
MESSAGE_FRAME = 6
|
|
||||||
MESSAGE_PAYLOAD = 7
|
|
||||||
|
|
||||||
attr_accessor :index , :type , :value
|
attr_accessor :index , :type , :value
|
||||||
|
|
||||||
private #abstract base class
|
private #abstract base class
|
||||||
@ -41,19 +32,9 @@ module Virtual
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FrameSlot < Slot
|
|
||||||
def initialize index , type = Unknown, value = nil
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class SelfSlot < Slot
|
|
||||||
def initialize index , type = Unknown, value = nil
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "message_slot"
|
require_relative "message_slot"
|
||||||
|
require_relative "self_slot"
|
||||||
|
require_relative "frame_slot"
|
||||||
require_relative "new_message_slot"
|
require_relative "new_message_slot"
|
||||||
|
Loading…
Reference in New Issue
Block a user