moved slots to own directory

This commit is contained in:
Torsten Ruger
2015-05-06 08:38:29 +03:00
parent cdea4915f9
commit 4f1508ca61
11 changed files with 130 additions and 107 deletions

View File

@ -13,7 +13,7 @@ module Compiler
# attr_reader :value
def self.compile_integer expession , method , message
int = Virtual::IntegerConstant.new(expession.value)
to = Virtual::NewReturn.new(Virtual::Integer , int)
to = Virtual::Return.new(Virtual::Integer , int)
method.add_code Virtual::Set.new( to , int)
to
end
@ -81,6 +81,6 @@ module Compiler
def self.compile_variable expession, method , message
method.add_code Virtual::InstanceGet.new(expession.name)
Virtual::NewReturn.new( Virtual::Mystery )
Virtual::Return.new( Virtual::Mystery )
end
end

View File

@ -21,6 +21,6 @@ module Compiler
method.add_code Virtual::MessageSend.new(expession.name , me , compiled_args) #and pass control
# the effect of the method is that the NewMessage Return slot will be filled, return it
# (this is what is moved _inside_ above loop for such expressions that are calls (or constants))
Virtual::NewReturn.new( method.return_type )
Virtual::Return.new( method.return_type )
end
end

View File

@ -70,7 +70,7 @@ require_relative "instruction"
require_relative "compiled_method"
require_relative "frame"
require_relative "message"
require_relative "slot"
require_relative "slots/slot"
require_relative "type"
require_relative "object"
require_relative "constants"

View File

@ -1,88 +0,0 @@
module Virtual
# Slots are named, or rather indexed, storage locations that are typed.
# Four of those locations exist and those correspond to subclasses:
# - the message that has been received: MessageSlot
# - the frame of the method that is executing (local variables): FrameSlot
# - self as an object: SelfSlot
# - a message that will be sent, NewMessageSlot
# additionally frame, self and return are slots in Message and NewMessage
class Slot < Object
MESSAGE_REGISTER = :r0
SELF_REGISTER = :r1
FRAME_REGISTER = :r2
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
private #abstract base class
def initialize index , type , value
@index = index
@type = type
@value = value
end
end
class MessageSlot < Slot
def initialize index , type = Mystery , value = nil
super(index ,type , value )
end
end
class FrameSlot < Slot
def initialize index , type = Mystery, value = nil
super
end
end
class SelfSlot < Slot
def initialize index , type = Mystery, value = nil
super
end
end
class NewMessageSlot < Slot
def initialize index , type = Mystery, value = nil
super(index , type , value )
end
end
class Return < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_RETURN_VALUE , type , value )
end
end
class Self < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_SELF , type , value )
end
end
class Name < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_NAME , type , value )
end
end
class NewReturn < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_RETURN_VALUE, type , value )
end
end
class NewSelf < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_SELF , type , value )
end
end
class NewName < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_NAME, type , value )
end
end
end

View File

@ -0,0 +1,27 @@
module Virtual
# The message that is being processed has a layout as per the constant above
class MessageSlot < Slot
def initialize index , type = Mystery , value = nil
super(index ,type , value )
end
end
class Return < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_RETURN_VALUE , type , value )
end
end
class Self < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_SELF , type , value )
end
end
# Name of the current message
class Name < MessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_NAME , type , value )
end
end
end

View File

@ -0,0 +1,25 @@
module Virtual
class NewMessageSlot < Slot
def initialize index , type = Mystery, value = nil
super(index , type , value )
end
end
class NewReturn < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_RETURN_VALUE, type , value )
end
end
class NewSelf < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_SELF , type , value )
end
end
class NewName < NewMessageSlot
def initialize type = Mystery, value = nil
super( MESSAGE_NAME, type , value )
end
end
end

59
lib/virtual/slots/slot.rb Normal file
View File

@ -0,0 +1,59 @@
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)
# But we are not modelling the array here, but the index into it.
# 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
# - self as an object: SelfSlot
# - a message that will be sent, NewMessageSlot
# 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
MESSAGE_REGISTER = :r0
SELF_REGISTER = :r1
FRAME_REGISTER = :r2
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
private #abstract base class
def initialize index , type , value
@index = index
@type = type
@value = value
end
end
class FrameSlot < Slot
def initialize index , type = Mystery, value = nil
super
end
end
class SelfSlot < Slot
def initialize index , type = Mystery, value = nil
super
end
end
end
require_relative "message_slot"
require_relative "new_message_slot"