move passes to own dir

This commit is contained in:
Torsten Ruger
2014-10-02 16:11:45 +03:00
parent cc08016a0f
commit 9923eb0b07
9 changed files with 7 additions and 7 deletions

View File

@ -0,0 +1,51 @@
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|
if code.is_a?(NewFrame)
kind = :next_frame
elsif code.is_a?(NewMessage)
kind = :next_message
else
next
end
space = BootSpace.space
machine = Register::RegisterMachine.instance
slot = Virtual::Slot
# a place to store a reference to the space, we grab the next_frame from the space
space_tmp = Register::RegisterReference.new(Virtual::Message::TMP_REG)
# a temporary place to store the new frame
frame_tmp = space_tmp.next_reg_use
# move the spave to it's register (mov instruction gets the address of the object)
new_codes = [ machine.mov( space_tmp , space )]
# find index in the space wehre to grab frame/message
ind = space.layout[:names].index(kind)
raise "index not found for :#{kind}" unless ind
# load the frame/message from space by index
new_codes << machine.ldr( frame_tmp , space_tmp , 5 )
# save the frame in real frame register
new_codes << machine.mov( Virtual::Message::FRAME_REG , frame_tmp )
# get the next_frame
new_codes << machine.ldr( frame_tmp , frame_tmp , 2 ) # 2 index of next_frame
# save next frame into space
new_codes << machine.str( frame_tmp , space_tmp , ind)
block.replace(code , new_codes )
end
end
end
Virtual::BootSpace.space.add_pass_after FrameImplementation , GetImplementation
end

View File

@ -0,0 +1,15 @@
module Virtual
# This implements instance variable get (not the opposite of Set, such a thing does not exists, their slots)
# Ivar get needs to acces the layout, find the index of the name, and shuffle the data to return register
# In short it's so complicated we implement it in ruby and stick the implementation here
class GetImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Virtual::InstanceGet
raise "Start coding"
end
end
end
Virtual::BootSpace.space.add_pass_after GetImplementation, SendImplementation
end

View File

@ -0,0 +1,41 @@
module Virtual
# This implements the send logic
# Send is so complicated that we actually code it in ruby and stick it in
# That off course opens up an endless loop possibility that we stop by
# implementing Class and Module methods
# Note: I find it slightly unsemetrical that the NewMessage object needs to be created before this instruction
# This is because all expressions create a (return) value and that return value is overwritten by the next
# expression unless saved. And since the message is the place to save it it needs to exist. qed
class SendImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? MessageSend
new_codes = [ ]
ref = code.me
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
if(ref.value)
me = ref.value
if( me.is_a? BootClass )
raise "unimplemented #{code}"
elsif( me.is_a? ObjectConstant )
# get the function from my class. easy peasy
method = me.clazz.get_instance_method(code.name)
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
new_codes << FunctionCall.new( method )
else
# note: this is the current view: call internal send, even the method name says else
# but send is "special" and accesses the internal method name and resolves.
kernel = Virtual::BootSpace.space.get_or_create_class(:Kernel)
method = kernel.get_instance_method(:__send)
new_codes << FunctionCall.new( method )
raise "unimplemented #{code}"
end
else
raise "not constant/ known object for send #{ref.inspect}"
end
block.replace(code , new_codes )
end
end
end
end