getting the passes back and starting on send

This commit is contained in:
Torsten Ruger 2014-08-21 17:46:12 +03:00
parent b5792c155c
commit 2260c680b2
6 changed files with 53 additions and 17 deletions

View File

@ -5,7 +5,7 @@ module Ast
class IntegerExpression < Expression class IntegerExpression < Expression
# attr_reader :value # attr_reader :value
def compile method , message def compile method , message
to = Virtual::Return.new(Integer) to = Virtual::Return.new(Virtual::Integer)
method.add_code Virtual::Set.new( to , Virtual::IntegerConstant.new(value)) method.add_code Virtual::Set.new( to , Virtual::IntegerConstant.new(value))
to to
end end
@ -41,7 +41,7 @@ module Ast
message.compile_get(method , name ) message.compile_get(method , name )
else else
raise "Unimplemented" raise "Unimplemented"
message.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) ) message.compile_send( method , name , Virtual::Self.new( Virtual::Mystery ) )
end end
end end
end end
@ -99,7 +99,7 @@ module Ast
class VariableExpression < NameExpression class VariableExpression < NameExpression
def compile method , message def compile method , message
method.add_code Virtual::ObjectGet.new(name) method.add_code Virtual::ObjectGet.new(name)
Virtual::Return.new( Virtual::Mystery.new ) Virtual::Return.new( Virtual::Mystery )
end end
end end
end end

View File

@ -6,7 +6,8 @@ module Ast
def compile method , message def compile method , message
me = receiver.compile( method, message ) me = receiver.compile( method, message )
method.add_code Virtual::Set.new(Virtual::NewSelf.new, me) method.add_code Virtual::Set.new(Virtual::NewSelf.new(me.type), me)
method.add_code Virtual::Set.new(Virtual::NewName.new(), name)
args.each_with_index do |arg , i| args.each_with_index do |arg , i|
val = arg.compile( method, message) #compile in the running method, ie before passing control val = arg.compile( method, message) #compile in the running method, ie before passing control
method.add_code Virtual::Set.new(Virtual::NewMessageSlot.new(i ,val.type ) , val ) method.add_code Virtual::Set.new(Virtual::NewMessageSlot.new(i ,val.type ) , val )

13
lib/trickle/send.rb Normal file
View File

@ -0,0 +1,13 @@
module Trickle
# 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 reducing to Class and Module methods
class Send
def run block
block.codes.dup.each do |code|
next unless code.is_a? MessageSend
end
end
end
end

View File

@ -33,6 +33,14 @@ module Virtual
self self
end end
# replace a code with an array of new codes. This is what happens in passes all the time
def replace_with code , new_codes
index = @codes.index code
raise "Code not found #{code} in #{self}" unless index
@codes.delete_at(index)
@codes.insert(index , *new_codes)
end
# returns if this is a block that ends in a call (and thus needs local variable handling) # returns if this is a block that ends in a call (and thus needs local variable handling)
def call_block? def call_block?
return false unless codes.last.is_a?(CallInstruction) return false unless codes.last.is_a?(CallInstruction)

View File

@ -11,6 +11,9 @@ module Virtual
class Slot < Value class Slot < Value
RETURN = 0 RETURN = 0
SELF = 1 SELF = 1
FRAME = 2
NAME = 3
MESSAGE_PAYLOAD = 4
attr_accessor :index , :type attr_accessor :index , :type
private #abstract base class private #abstract base class
@ -22,7 +25,7 @@ module Virtual
class MessageSlot < Slot class MessageSlot < Slot
def initialize index , type = Mystery def initialize index , type = Mystery
super super(index + MESSAGE_PAYLOAD ,type)
end end
end end
class FrameSlot < Slot class FrameSlot < Slot
@ -37,28 +40,39 @@ module Virtual
end end
class NewMessageSlot < Slot class NewMessageSlot < Slot
def initialize index , type = Mystery def initialize index , type = Mystery
super super(index + MESSAGE_PAYLOAD , type)
end end
end end
class Return < MessageSlot class Return < MessageSlot
def initialize type = Mystery def initialize type = Mystery
super( RETURN , type ) super( RETURN - MESSAGE_PAYLOAD, type )
end
end
class NewReturn < NewMessageSlot
def initialize type = Mystery
super( RETURN , type )
end end
end end
class Self < MessageSlot class Self < MessageSlot
def initialize type = Mystery def initialize type = Mystery
super( SELF , type ) super( SELF - MESSAGE_PAYLOAD , type )
end
end
class Name < MessageSlot
def initialize type = Mystery
super( NAME - MESSAGE_PAYLOAD , type )
end
end
class NewReturn < NewMessageSlot
def initialize type = Mystery
super( RETURN - MESSAGE_PAYLOAD, type )
end end
end end
class NewSelf < NewMessageSlot class NewSelf < NewMessageSlot
def initialize type = Mystery def initialize type = Mystery
super( SELF , type ) super( SELF - MESSAGE_PAYLOAD , type )
end
end
class NewName < NewMessageSlot
def initialize type = Mystery
super( NAME - MESSAGE_PAYLOAD , type )
end end
end end

View File

@ -9,7 +9,7 @@ def foo(x)
5 5
end end
HERE HERE
@output = "---RETURN_MARKER- &1 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :fooRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER return_type: &2 !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Integer'RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *1RETURN_MARKER name: :fooRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: *2RETURN_MARKER from: !ruby/object:Virtual::IntegerConstantRETURN_MARKER integer: 5RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *1RETURN_MARKER name: :foo_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER" @output = "---RETURN_MARKER- &1 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :fooRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER return_type: &2 !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Integer'RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *1RETURN_MARKER name: :fooRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: *2RETURN_MARKER from: !ruby/object:Virtual::IntegerConstantRETURN_MARKER integer: 5RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *1RETURN_MARKER name: :foo_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER"
check check
end end
@ -20,7 +20,7 @@ def foo()
end end
foo() foo()
HERE HERE
@output = "---RETURN_MARKER- &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :fooRETURN_MARKER args: []RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: &1 !ruby/class 'Virtual::Mystery'RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :fooRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: !ruby/object:Virtual::NewSelfRETURN_MARKER index: 1RETURN_MARKER type: *1RETURN_MARKER from: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: *1RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: !ruby/object:Virtual::NewMessageSlotRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Reference'RETURN_MARKER from: !ruby/object:Virtual::StringConstantRETURN_MARKER string: HelloRETURN_MARKER - !ruby/object:Virtual::MessageSendRETURN_MARKER name: :putsRETURN_MARKER args: []RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :foo_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: *1RETURN_MARKER" @output = "---RETURN_MARKER- &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :fooRETURN_MARKER args: []RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: &1 !ruby/class 'Virtual::Mystery'RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :fooRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: !ruby/object:Virtual::NewSelfRETURN_MARKER index: 1RETURN_MARKER type: *1RETURN_MARKER from: !ruby/object:Virtual::SelfRETURN_MARKER index: 1RETURN_MARKER type: *1RETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: !ruby/object:Virtual::NewNameRETURN_MARKER index: 3RETURN_MARKER type: *1RETURN_MARKER from: :putsRETURN_MARKER - !ruby/object:Virtual::SetRETURN_MARKER to: !ruby/object:Virtual::NewMessageSlotRETURN_MARKER index: 4RETURN_MARKER type: !ruby/class 'Virtual::Reference'RETURN_MARKER from: !ruby/object:Virtual::StringConstantRETURN_MARKER string: HelloRETURN_MARKER - !ruby/object:Virtual::MessageSendRETURN_MARKER name: :putsRETURN_MARKER args: []RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :foo_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: *1RETURN_MARKER"
check check
end end
@ -30,7 +30,7 @@ def String.length(x)
@length @length
end end
HERE HERE
@output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/object:Virtual::Mystery {}RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::ObjectGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER" @output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::ObjectGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER"
check check
end end