bit more method collector/creation testing

This commit is contained in:
Torsten Ruger 2017-01-13 22:16:06 +02:00
parent 3f6c1bc3a3
commit 75c7ca950e
5 changed files with 31 additions and 16 deletions

View File

@ -17,7 +17,7 @@ module Melon
def add_local(statement)
var = statement.children[0]
@locals[var] = :Object #guess, can maybe guess better
@locals[var] = :Object #not really used right now
end
end

View File

@ -21,20 +21,16 @@ module Melon
private
def make_type( statement )
type = Parfait.object_space.get_class_by_name(:Message ).instance_type
type_hash = {}
statement.children.each do |arg|
type = type.add_instance_variable( arg.children[0] , :Object )
type_hash[arg.children[0]] = :Object
end
type
Parfait::NamedList.type_for( type_hash )
end
def make_locals(body)
locals = LocalsCollector.new.collect(body)
type = Parfait.object_space.get_class_by_name(:NamedList ).instance_type
locals.each do |name , local_type |
type = type.add_instance_variable( name , local_type )
end
type
type_hash = LocalsCollector.new.collect(body)
Parfait::NamedList.type_for( type_hash )
end
end
end

View File

@ -2,10 +2,10 @@ module Melon
class RubyMethod
attr_reader :name , :args_type , :locals_type , :body
attr_reader :name , :args_type , :locals_type , :source
def initialize(name , args_type , locals_type , body )
@name , @args_type , @locals_type , @body = name , args_type, locals_type , body
def initialize(name , args_type , locals_type , source )
@name , @args_type , @locals_type , @source = name , args_type, locals_type , source
end
end

View File

@ -20,7 +20,7 @@ module Melon
def test_one_arg
method = parse_collect("def meth2(arg1); 1;end").first
assert method.name == :meth2
assert method.args_type.variable_index(:arg1) , method.args_type.inspect
assert_equal 2 , method.args_type.variable_index(:arg1) , method.args_type.inspect
end
def test_three_args

View File

@ -8,12 +8,31 @@ module Melon
Register.machine.boot
end
def test_creates_method_in_class
def create_method
Compiler.compile in_Space("def meth; @ivar;end")
space = Parfait.object_space.get_class
method = space.get_method(:meth)
space.get_method(:meth)
end
def test_creates_method_in_class
method = create_method
assert method , "No method created"
end
def test_method_has_source
method = create_method
assert_equal "(ivar :@ivar)", method.source.to_s
end
def test_method_has_no_args
method = create_method
assert_equal 1 , method.args_type.instance_length
end
def test_method_has_no_locals
method = create_method
assert_equal 1 , method.locals_type.instance_length
end
end
end