and another one, and another one....
This commit is contained in:
parent
ae21863245
commit
c1f475070b
@ -35,9 +35,9 @@ module Ast
|
|||||||
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
||||||
def compile frame , method
|
def compile frame , method
|
||||||
if method.has_var(name)
|
if method.has_var(name)
|
||||||
frame.compile_get(name , method )
|
frame.compile_get(method , name )
|
||||||
else
|
else
|
||||||
frame.compile_send( name , method )
|
frame.compile_send( method , name )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,11 @@ module Ast
|
|||||||
# attr_reader :name, :args , :receiver
|
# attr_reader :name, :args , :receiver
|
||||||
@@counter = 0
|
@@counter = 0
|
||||||
def compile frame , method
|
def compile frame , method
|
||||||
|
with = args.collect{|a| a.compile(frame , method)}
|
||||||
|
frame.compile_send( method , @name , with )
|
||||||
|
end
|
||||||
|
|
||||||
|
def scratch
|
||||||
into = context.function
|
into = context.function
|
||||||
params = args.collect{ |a| a.compile(context) }
|
params = args.collect{ |a| a.compile(context) }
|
||||||
puts "compiling receiver #{receiver} (call #{name})"
|
puts "compiling receiver #{receiver} (call #{name})"
|
||||||
|
@ -24,12 +24,12 @@ module Virtual
|
|||||||
attr_reader :next_normal, :next_exception, :me, :binding
|
attr_reader :next_normal, :next_exception, :me, :binding
|
||||||
|
|
||||||
#
|
#
|
||||||
def compile_get name , method
|
def compile_get method , name
|
||||||
method.add FrameGet.new(name)
|
method.add FrameGet.new(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_send name , method
|
def compile_send method , name , with = []
|
||||||
method.add FrameSend.new(name)
|
method.add FrameSend.new(name , with )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,16 +36,17 @@ module Virtual
|
|||||||
|
|
||||||
class FrameSend < Instruction
|
class FrameSend < Instruction
|
||||||
|
|
||||||
def initialize name
|
def initialize name , args = []
|
||||||
@name = name.to_sym
|
@name = name.to_sym
|
||||||
|
@args = args
|
||||||
end
|
end
|
||||||
attr_reader :name
|
attr_reader :name , :args
|
||||||
|
|
||||||
def == other
|
def == other
|
||||||
self.class == other.class && self.name == other.name
|
self.class == other.class && self.name == other.name
|
||||||
end
|
end
|
||||||
def inspect
|
def inspect
|
||||||
self.class.name + ".new(:#{@name})"
|
self.class.name + ".new(:#{@name} , [ " + args.collect{|a| a.inspect}.join(",")+ "])"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ class TestBasic < MiniTest::Test
|
|||||||
|
|
||||||
def test_instance_variable
|
def test_instance_variable
|
||||||
@string_input = '@foo_bar '
|
@string_input = '@foo_bar '
|
||||||
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
|
@output = [Virtual::FrameSend.new(:_get_instance_variable , [ Virtual::StringConstant.new('foo_bar')])]
|
||||||
@output = Ast::VariableExpression.new(:foo_bar)
|
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user