move frame_impl to register
This commit is contained in:
parent
3fe35e34ec
commit
aafb179c61
@ -1,4 +1,4 @@
|
|||||||
module Virtual
|
module Register
|
||||||
# This implements the creation of new frame and message object
|
# This implements the creation of new frame and message object
|
||||||
|
|
||||||
# Frames and Message are very similar apart from the class name
|
# Frames and Message are very similar apart from the class name
|
||||||
@ -9,7 +9,7 @@ module Virtual
|
|||||||
# This is HARD coded to avoid any lookup
|
# 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
|
# 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
|
# and arguments + 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.
|
# variables as a result one of each is created for every single method call.
|
||||||
# A LOT, so make it fast luke
|
# A LOT, so make it fast luke
|
||||||
# Note: this is off course the reason for stack based implementations that just increment
|
# Note: this is off course the reason for stack based implementations that just increment
|
||||||
@ -17,36 +17,38 @@ module Virtual
|
|||||||
# and a few extra instructions don't hurt.
|
# and a few extra instructions don't hurt.
|
||||||
# After all, we are buying a big prize:oo, otherwise known as sanity.
|
# After all, we are buying a big prize:oo, otherwise known as sanity.
|
||||||
|
|
||||||
|
# TODO: This is too complicated, which means it should be ruby code and "inlined"
|
||||||
|
# then it would move to Virtual
|
||||||
class FrameImplementation
|
class FrameImplementation
|
||||||
def run block
|
def run block
|
||||||
block.codes.dup.each do |code|
|
block.codes.dup.each do |code|
|
||||||
if code.is_a?(NewFrame)
|
if code.is_a?(Virtual::NewFrame)
|
||||||
kind = :next_frame
|
kind = :next_frame
|
||||||
elsif code.is_a?(NewMessage)
|
elsif code.is_a?(Virtual::NewMessage)
|
||||||
kind = :next_message
|
kind = :next_message
|
||||||
else
|
else
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
# a place to store a reference to the space, we grab the next_frame from the space
|
# a place to store a reference to the space, we grab the next_frame from the space
|
||||||
space_tmp = Register::RegisterReference.tmp_reg
|
space_tmp = RegisterReference.tmp_reg
|
||||||
# a temporary place to store the new frame
|
# a temporary place to store the new frame
|
||||||
frame_tmp = space_tmp.next_reg_use
|
frame_tmp = space_tmp.next_reg_use
|
||||||
# move the spave to it's register (mov instruction gets the address of the object)
|
# move the spave to it's register (mov instruction gets the address of the object)
|
||||||
new_codes = [ Register::LoadConstant.new( space_tmp , Parfait::Space.object_space )]
|
new_codes = [ LoadConstant.new( space_tmp , Parfait::Space.object_space )]
|
||||||
# find index in the space where to grab frame/message
|
# find index in the space where to grab frame/message
|
||||||
ind = Parfait::Space.object_space.get_layout().index_of( kind )
|
ind = Parfait::Space.object_space.get_layout().index_of( kind )
|
||||||
raise "index not found for #{kind}.#{kind.class}" unless ind
|
raise "index not found for #{kind}.#{kind.class}" unless ind
|
||||||
# load the frame/message from space by index
|
# load the frame/message from space by index
|
||||||
new_codes << Register::GetSlot.new( frame_tmp , space_tmp , 5 )
|
new_codes << GetSlot.new( frame_tmp , space_tmp , 5 )
|
||||||
# save the frame in real frame register
|
# save the frame in real frame register
|
||||||
new_codes << Register::RegisterTransfer.new( Register::RegisterReference.frame_reg , frame_tmp )
|
new_codes << RegisterTransfer.new( RegisterReference.frame_reg , frame_tmp )
|
||||||
# get the next_frame
|
# get the next_frame
|
||||||
new_codes << Register::GetSlot.new( frame_tmp , frame_tmp , 2 ) # 2 index of next_frame
|
new_codes << GetSlot.new( frame_tmp , frame_tmp , 2 ) # 2 index of next_frame
|
||||||
# save next frame into space
|
# save next frame into space
|
||||||
new_codes << Register::SetSlot.new( frame_tmp , space_tmp , ind)
|
new_codes << SetSlot.new( frame_tmp , space_tmp , ind)
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Virtual.machine.add_pass "Virtual::FrameImplementation"
|
Virtual.machine.add_pass "Register::FrameImplementation"
|
||||||
end
|
end
|
@ -1,6 +1,7 @@
|
|||||||
require_relative "instruction"
|
require_relative "instruction"
|
||||||
require_relative "register_reference"
|
require_relative "register_reference"
|
||||||
require_relative "assembler"
|
require_relative "assembler"
|
||||||
|
require_relative "passes/frame_implementation"
|
||||||
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user