This commit is contained in:
Torsten Ruger 2015-06-29 20:55:45 +03:00
parent 54dd37cb4d
commit 218fafca05
5 changed files with 27 additions and 17 deletions

View File

@ -7,14 +7,14 @@ module Virtual
def self.compile_callsite expession , method
me = Compiler.compile( expession.receiver , method )
method.info.add_code NewMessage.new
method.info.add_code Set.new( me , NextSelf.new(me.type))
method.info.add_code Set.new( expession.name.to_sym , NextMessageName.new())
method.info.add_code Set.new( me , NewSelf.new(me.type))
method.info.add_code Set.new( expession.name.to_sym , NewMessageName.new())
compiled_args = []
expession.args.each_with_index do |arg , i|
#compile in the running method, ie before passing control
val = Compiler.compile( arg , method)
# move the compiled value to it's slot in the new message
to = NextMessageSlot.new(i ,val.type , val)
to = NewArgSlot.new(i ,val.type , val)
# (doing this immediately, not after the loop, so if it's a return it won't get overwritten)
method.info.add_code Set.new( val , to )
compiled_args << to

View File

@ -2,11 +2,11 @@ module Virtual
# The next Message is one of four objects the virtual machine knows
#
# Slots represent instance variables of objects, so NextMessageSlots
# represent instance variables of NextMessage objects.
# Slots represent instance variables of objects, so NewMessageSlots
# represent instance variables of NewMessage objects.
# The Message has a layout as per the constant above
class NextMessageSlot < Slot
class NewMessageSlot < Slot
def initialize type = Unknown, value = nil
super( type , value )
end
@ -14,24 +14,34 @@ module Virtual
# named classes exist for slots that often accessed
# NextReturn is the return of NextMessageSlot
class NextReturn < NextMessageSlot
# NewReturn is the return of NewMessageSlot
class NewReturn < NewMessageSlot
def initialize type = Unknown, value = nil
super( type , value )
end
end
# NextSelf is the self of NextMessageSlot
class NextSelf < NextMessageSlot
# NewSelf is the self of NewMessageSlot
class NewSelf < NewMessageSlot
def initialize type = Unknown, value = nil
super( type , value )
end
end
# NextMessageName of the next message
class NextMessageName < NextMessageSlot
# NewMessageName of the next message
class NewMessageName < NewMessageSlot
def initialize type = Unknown, value = nil
super( type , value )
end
end
# NewMessageName of the next message
class NewArgSlot < NewMessageSlot
def initialize index , type = Unknown, value = nil
@index = index
super( type , value )
end
attr_reader :index
end
end

View File

@ -5,7 +5,7 @@ module Virtual
# want to send a message it puts the new self into the next_message.
#
# The slot in the Message is represented by instances of class Self
# (and slots in the next_message by instances of NextSelf)
# (and slots in the next_message by instances of NewSelf)
#
# Additionally the current Self is represented as it's own top-level object.
# If self is an Object one can refer to it's instance variables as Slots in SelfSlot

View File

@ -9,7 +9,7 @@ module Virtual
# - the message that has been received: MessageSlot
# - the frame of the method that is executing (local variables): FrameSlot
# - self as an object: SelfSlot
# - a message that will be sent, NextMessageSlot
# - a message that will be sent, NewMessageSlot
# additionally frame, self and return are slots in Message and NewMessage

View File

@ -20,7 +20,7 @@ def foo()
end
foo()
HERE
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => *6)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :from &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* -Virtual::Set(:from => 'puts')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set(:from => 'Hello')*^* :to &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::Set()*^* :to &18 Virtual::NextMessageSlot(:index => 0, :type => &5 Virtual::Reference, :value => *16)*^* :from &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::MessageSend(:name => :puts)*^* :me &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :args [*18]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => *6)*^*-Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)"
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => *6)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :from &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* -Virtual::Set(:from => 'puts')*^* :to Virtual::NewMessageName(:index => 4, :type => *6)*^* -Virtual::Set(:from => 'Hello')*^* :to &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::Set()*^* :to &18 Virtual::NewMessageSlot(:index => 0, :type => &5 Virtual::Reference, :value => *16)*^* :from &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::MessageSend(:name => :puts)*^* :me &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :args [*18]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => *6)*^*-Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)"
check
end
@ -41,7 +41,7 @@ def foo(x)
2 + 5
end
HERE
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names [:x]*^* :locals ['abba']*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *6)*^* :from Virtual::FrameSlot(:index => 1, :type => &9 Virtual::Integer, :value => *16)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* :from &19 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &21 Virtual::NextMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *20)*^* :from &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* -Virtual::MessageSend(:name => :+)*^* :me &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :args [*21]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)"
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names [:x]*^* :locals ['abba']*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *6)*^* :from Virtual::FrameSlot(:index => 1, :type => &9 Virtual::Integer, :value => *16)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* :from &19 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &21 Virtual::NewMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *20)*^* :from &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* -Virtual::MessageSend(:name => :+)*^* :me &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :args [*21]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)"
check
end
@ -51,7 +51,7 @@ def foo()
2 + 5
end
HERE
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &19 Virtual::NextMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *18)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::MessageSend(:name => :+)*^* :me &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :args [*19]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)"
@output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &19 Virtual::NewMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *18)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::MessageSend(:name => :+)*^* :me &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :args [*19]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)"
check
end