rubyx/lib/virtual/frame.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2014-06-29 19:05:35 +03:00
module Virtual
# A frame, or activation frame, represents a function call during calling. So not the static definition of the function
# but the dynamic invokation of it.
#
# In a minimal c world this would be just the return address, but with exceptions and continuations things get more
# complicated. How much more we shall see
#
# The current list comprises
# - next normal instruction
# - next exception instruction
# - self (me)
# - argument mappings
2014-07-01 18:58:25 +03:00
# - local variable mapping, together with last called binding
2014-06-29 19:05:35 +03:00
class Frame
2014-07-01 18:58:25 +03:00
def initialize normal , exceptional , me
@next_normal = normal
@next_exception = exceptional
@me = me
# a binding represents the local variables at a point in the program.
# The amount of local variables is assumed to be relatively small, and so the
# storage is a linked list. Has the same api as a ha
@binding = List.new
2014-06-29 19:05:35 +03:00
end
2014-07-01 18:58:25 +03:00
attr_reader :next_normal, :next_exception, :me, :binding
2014-07-10 17:14:38 +03:00
# dummy for the eventual
def new_frame
self
end
2014-07-10 17:14:38 +03:00
#
2014-07-13 16:00:48 +03:00
def compile_get method , name
2014-07-10 17:14:38 +03:00
method.add FrameGet.new(name)
2014-07-15 10:35:29 +03:00
method.get_var(name)
2014-07-10 17:14:38 +03:00
end
2014-07-15 18:34:03 +03:00
def compile_send method , name , me , with = []
method.add Virtual::LoadSelf.new(me)
2014-07-13 16:00:48 +03:00
method.add FrameSend.new(name , with )
2014-07-15 10:35:29 +03:00
Return.new( method.return_type )
2014-07-10 17:14:38 +03:00
end
def compile_set method , name , val
2014-07-16 13:20:47 +03:00
method.set_var(name,val)
method.add FrameSet.new(name , val )
2014-07-15 10:35:29 +03:00
method.get_var(name)
end
2014-06-29 19:05:35 +03:00
end
end