2014-09-24 17:15:08 +02:00
|
|
|
module Virtual
|
|
|
|
# This implements the creation of new frame and message object
|
|
|
|
|
|
|
|
# Frames and Message are very similar apart from the class name
|
|
|
|
# - All existing instances are stored in the space for both
|
|
|
|
# - Size is currently 2, ie 16 words (TODO a little flexibility here would not hurt, but the mountain is big)
|
|
|
|
# - Unused instances for a linked list with their first instance variable. This is HARD coded to avoid any lookup
|
|
|
|
|
|
|
|
# Just as a reminder: a message object is created before a send and holds return address/message and arguemnts + self
|
|
|
|
# frames are created upon entering a method and hold local and temporary variables
|
|
|
|
# as a result one of each is created for every single method call. A LOT, so make it fast luke
|
|
|
|
# Note: this is off course the reason for stack based implementations that just increment a known pointer/register or
|
|
|
|
# something. But i think most programs are memory bound and a few extra instructions don't hurt.
|
|
|
|
# After all, we are buying a big prize:oo, otherwise known as sanity.
|
|
|
|
|
|
|
|
class FrameImplementation
|
|
|
|
def run block
|
|
|
|
block.codes.dup.each do |code|
|
2014-09-27 13:59:16 +02:00
|
|
|
if code.is_a?(NewFrame)
|
|
|
|
kind = :next_frame
|
|
|
|
elsif code.is_a?(NewMessage)
|
|
|
|
kind = :next_message
|
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
|
|
|
space = BootSpace.space
|
|
|
|
slot = Virtual::Slot
|
2014-09-28 10:18:24 +02:00
|
|
|
# a place to store a reference to the space, we grab the next_frame from the space
|
2014-09-27 13:59:16 +02:00
|
|
|
space_tmp = Register::RegisterReference.new(Virtual::Message::TMP_REG)
|
2014-09-28 10:18:24 +02:00
|
|
|
# a temporary place to store the new frame
|
2014-09-27 13:59:16 +02:00
|
|
|
frame_tmp = space_tmp.next_reg_use
|
2014-09-28 10:18:24 +02:00
|
|
|
# move the spave to it's register (mov instruction gets the address of the object)
|
2014-10-04 16:22:23 +02:00
|
|
|
new_codes = [ Register::RegisterTransfer.new( space_tmp , space )]
|
2014-09-28 10:18:24 +02:00
|
|
|
# find index in the space wehre to grab frame/message
|
2014-09-27 13:59:16 +02:00
|
|
|
ind = space.layout[:names].index(kind)
|
2014-09-28 10:18:24 +02:00
|
|
|
raise "index not found for :#{kind}" unless ind
|
|
|
|
# load the frame/message from space by index
|
2014-10-04 16:22:23 +02:00
|
|
|
new_codes << Register::GetSlot.new( frame_tmp , space_tmp , 5 )
|
2014-09-28 10:18:24 +02:00
|
|
|
# save the frame in real frame register
|
2014-10-04 16:22:23 +02:00
|
|
|
new_codes << Register::RegisterTransfer.new( Virtual::Message::FRAME_REG , frame_tmp )
|
2014-09-28 10:18:24 +02:00
|
|
|
# get the next_frame
|
2014-10-04 16:22:23 +02:00
|
|
|
new_codes << Register::GetSlot.new( frame_tmp , frame_tmp , 2 ) # 2 index of next_frame
|
2014-09-28 10:18:24 +02:00
|
|
|
# save next frame into space
|
2014-10-04 16:22:23 +02:00
|
|
|
new_codes << Register::SetSlot.new( frame_tmp , space_tmp , ind)
|
2014-09-24 17:15:08 +02:00
|
|
|
block.replace(code , new_codes )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-03 13:52:47 +02:00
|
|
|
Virtual::BootSpace.space.add_pass_after "Virtual::FrameImplementation" , "Virtual::GetImplementation"
|
2014-09-24 17:15:08 +02:00
|
|
|
end
|