creates methods from method statement

This commit is contained in:
Torsten Ruger 2017-04-08 17:22:53 +03:00
parent b0e3978b15
commit f8b3fa1877
4 changed files with 68 additions and 7 deletions

View File

@ -36,6 +36,10 @@ module Vool
# used to collect frame information
def add_local( array )
end
# used for method creation
def set_class( clazz )
end
end
end

View File

@ -22,9 +22,8 @@ module Vool
# ivar_hash = Passes::TypeCollector.new.collect(body)
# @clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
end
body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects
# methods = create_methods(clazz , body)
# compile_methods(clazz,methods)
end
end

View File

@ -1,16 +1,69 @@
module Vool
class MethodStatement
attr_reader :name, :args , :body
class MethodStatement < Statement
attr_reader :name, :args , :body , :clazz
def initialize( name , args , body)
@name , @args , @body = name , args , (body || [])
end
def collect(arr)
@args.collect(arr)
@args.each{ |arg| arg.collect(arr)}
@body.collect(arr)
super
end
def set_class(clazz)
@clazz = clazz
end
def create_objects
args_type = make_type
locals_type = make_locals
method = Rubyx::RubyMethod.new(name , args_type , locals_type , body )
@clazz.add_method( method )
# compile_methods(clazz,methods)
end
private
def make_type( )
type_hash = {}
@args.each do |arg|
puts "ARG #{arg}"
type_hash[arg.children[0]] = :Object
end
Parfait::NamedList.type_for( type_hash )
end
def make_locals
type_hash = {}
vars = []
@body.collect([]).each do |node|
node.add_local(vars)
end
vars.each do |var|
type_hash[var] = :Object
end
Parfait::NamedList.type_for( type_hash )
end
def create_methods(clazz , body)
methods = Passes::MethodCollector.new.collect(body)
methods.each do |method|
clazz.add_method( method )
normalizer = Passes::Normalizer.new(method)
method.normalize_source { |sourc| normalizer.process( sourc ) }
end
methods
end
def compile_methods(clazz , methods)
methods.each do |method|
code = Passes::MethodCompiler.new(method).get_code
typed_method = method.create_vm_method(clazz.instance_type)
Vm::MethodCompiler.new( typed_method ).init_method.process( code )
end
end
end
end

View File

@ -14,7 +14,12 @@ module Vool
test.get_method(:meth)
end
def pest_creates_method_in_class
def test_method_statement_has_class
clazz = VoolCompiler.compile in_Test("def meth; @ivar ;end")
assert_equal Parfait::Class , clazz.body.clazz.class
end
def test_creates_method_in_class
method = create_method
assert method , "No method created"
end