adds message get and set instructions

This commit is contained in:
Torsten Ruger
2014-07-25 20:28:38 +03:00
parent 7df1490da8
commit 1a95835442
5 changed files with 39 additions and 10 deletions

View File

@ -51,7 +51,7 @@ Then a new Method receives the message, creates a Frame for local and temporary
The important thing here is that Messages and Frames are normal objects.
Anf interestingly we can partly use ruby to find the method, so in a way it is not just a top down transformation. but
And interestingly we can partly use ruby to find the method, so in a way it is not just a top down transformation. but
the sending goes back up and then down again.
The Message object is the second parameter to the compile method, the run-time part as it were.

View File

@ -103,12 +103,14 @@ module Virtual
class ImplicitBranch < Branch
end
# A note: future branch conditions include OverflowBranch and other non-c
class MessageGet < Instruction
include Named
end
class FrameGet < Instruction
include Named
end
class FrameSend < Instruction
class MessageSend < Instruction
def initialize name , args = [] , nex = nil
super(nex)
@name = name.to_sym
@ -132,6 +134,18 @@ module Virtual
end
end
class MessageSet < Instruction
def initialize name , val , nex = nil
super(nex)
@name = name.to_sym
@value = val
end
attr_reader :name , :value
def attributes
[:name , :value] + super
end
end
class LoadSelf < Instruction
def initialize val , nex = nil
super(nex)

View File

@ -36,19 +36,27 @@ module Virtual
end
#
def compile_get method , name
method.add FrameGet.new(name)
if method.has_arg(name)
method.add MessageGet.new(name)
else
method.add FrameGet.new(name)
end
method.get_var(name)
end
def compile_send method , name , me , with = []
method.add Virtual::LoadSelf.new(me)
method.add FrameSend.new(name , with )
method.add MessageSend.new(name , with )
Return.new( method.return_type )
end
def compile_set method , name , val
method.set_var(name,val)
method.add FrameSet.new(name , val )
if method.has_arg(name)
method.add MessageSet.new(name , val )
else
method.add FrameSet.new(name , val )
end
method.get_var(name)
end
end

View File

@ -49,6 +49,13 @@ module Virtual
var
end
# determine whether this method has an argument by the name
def has_arg name
name = name.to_sym
var = @args.find {|a| a.name == name }
var
end
def set_var name , var
v = has_var name
if( v )