2015-06-21 16:23:15 +02:00
|
|
|
module Register
|
2014-09-24 17:15:08 +02:00
|
|
|
# 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
|
2015-05-30 11:20:39 +02:00
|
|
|
# - 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
|
2015-05-24 12:55:05 +02:00
|
|
|
|
2015-05-30 11:20:39 +02:00
|
|
|
# Just as a reminder: a message object is created before a send and holds return address/message
|
2015-06-21 16:23:15 +02:00
|
|
|
# and arguments + self frames are created upon entering a method and hold local and temporary
|
2015-05-30 11:20:39 +02:00
|
|
|
# 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.
|
2014-09-24 17:15:08 +02:00
|
|
|
# After all, we are buying a big prize:oo, otherwise known as sanity.
|
|
|
|
|
2015-06-21 16:23:15 +02:00
|
|
|
# TODO: This is too complicated, which means it should be ruby code and "inlined"
|
|
|
|
# then it would move to Virtual
|
2014-09-24 17:15:08 +02:00
|
|
|
class FrameImplementation
|
|
|
|
def run block
|
|
|
|
block.codes.dup.each do |code|
|
2015-06-21 16:23:15 +02:00
|
|
|
if code.is_a?(Virtual::NewFrame)
|
2015-06-01 07:33:23 +02:00
|
|
|
kind = :next_frame
|
2015-06-21 16:23:15 +02:00
|
|
|
elsif code.is_a?(Virtual::NewMessage)
|
2015-06-01 07:33:23 +02:00
|
|
|
kind = :next_message
|
2014-09-27 13:59:16 +02:00
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
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
|
2015-06-21 16:23:15 +02:00
|
|
|
space_tmp = RegisterReference.tmp_reg
|
2014-09-28 10:18:24 +02:00
|
|
|
# move the spave to it's register (mov instruction gets the address of the object)
|
2015-06-25 15:31:09 +02:00
|
|
|
new_codes = [ LoadConstant.new( Parfait::Space.object_space , space_tmp )]
|
2015-05-24 14:31:30 +02:00
|
|
|
# find index in the space where to grab frame/message
|
2015-06-28 21:02:07 +02:00
|
|
|
space_index = Parfait::Space.object_space.get_layout().index_of( kind )
|
|
|
|
raise "index not found for #{kind}.#{kind.class}" unless space_index
|
2014-09-28 10:18:24 +02:00
|
|
|
# load the frame/message from space by index
|
2015-06-28 21:02:07 +02:00
|
|
|
new_codes << GetSlot.new( space_tmp , space_index , RegisterReference.frame_reg )
|
2015-06-28 09:52:02 +02:00
|
|
|
# a temporary place to store the new frame
|
|
|
|
frame_tmp = space_tmp.next_reg_use
|
2014-09-28 10:18:24 +02:00
|
|
|
# get the next_frame
|
2015-06-28 21:02:07 +02:00
|
|
|
from = Parfait::Space.object_space.send( kind )
|
|
|
|
kind_index = from.get_layout().index_of( kind )
|
|
|
|
raise "index not found for #{kind}.#{kind.class}" unless kind_index
|
|
|
|
new_codes << GetSlot.new( RegisterReference.frame_reg , kind_index , frame_tmp) # 2 index of next_frame
|
2014-09-28 10:18:24 +02:00
|
|
|
# save next frame into space
|
2015-06-28 21:02:07 +02:00
|
|
|
new_codes << SetSlot.new( frame_tmp , space_tmp , space_index)
|
2014-09-24 17:15:08 +02:00
|
|
|
block.replace(code , new_codes )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-21 16:23:15 +02:00
|
|
|
Virtual.machine.add_pass "Register::FrameImplementation"
|
2014-09-24 17:15:08 +02:00
|
|
|
end
|