bringing the locals into the ruby method
This commit is contained in:
parent
9ec9ccb9b6
commit
b242f9e223
@ -14,9 +14,12 @@ module Melon
|
|||||||
def on_def(statement)
|
def on_def(statement)
|
||||||
name , args , body = *statement
|
name , args , body = *statement
|
||||||
args_type = make_type(args)
|
args_type = make_type(args)
|
||||||
@methods << RubyMethod.new(name , args_type , body )
|
locals_type = make_locals(body)
|
||||||
|
@methods << RubyMethod.new(name , args_type , locals_type , body )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def make_type( statement )
|
def make_type( statement )
|
||||||
type = Parfait::Space.object_space.get_class_by_name(:Message ).instance_type
|
type = Parfait::Space.object_space.get_class_by_name(:Message ).instance_type
|
||||||
statement.children.each do |arg|
|
statement.children.each do |arg|
|
||||||
@ -25,5 +28,13 @@ module Melon
|
|||||||
type
|
type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_locals(body)
|
||||||
|
locals = LocalsCollector.new.collect(body)
|
||||||
|
type = Parfait::Space.object_space.get_class_by_name(:Frame ).instance_type
|
||||||
|
locals.each do |name , local_type |
|
||||||
|
type = type.add_instance_variable( name , local_type )
|
||||||
|
end
|
||||||
|
type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,10 +2,10 @@ module Melon
|
|||||||
|
|
||||||
class RubyMethod
|
class RubyMethod
|
||||||
|
|
||||||
attr_reader :name , :args_type , :body
|
attr_reader :name , :args_type , :locals_type , :body
|
||||||
|
|
||||||
def initialize(name , args_type , body )
|
def initialize(name , args_type , locals_type , body )
|
||||||
@name , @args_type , @body = name , args_type , body
|
@name , @args_type , @locals_type , @body = name , args_type, locals_type , body
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -23,10 +23,15 @@ module Melon
|
|||||||
assert method.args_type.variable_index(:arg1) , method.args_type.inspect
|
assert method.args_type.variable_index(:arg1) , method.args_type.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ivar_operator_assign
|
def test_three_args
|
||||||
method = parse_collect("def meth3(yksi,kaksi,kolme); 1;end").first
|
method = parse_collect("def meth3(yksi,kaksi,kolme); 1;end").first
|
||||||
assert method.args_type.variable_index(:kolme) , method.args_type.inspect
|
assert method.args_type.variable_index(:kolme) , method.args_type.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_one_local
|
||||||
|
method = parse_collect("def meth2(arg1); foo = 2 ;end").first
|
||||||
|
assert method.locals_type.variable_index(:foo) , method.locals_type.inspect
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user