clean up function definition, now function statement

This commit is contained in:
Torsten Ruger 2016-12-09 14:12:41 +02:00
parent 059fb38f08
commit 037fd722df
2 changed files with 16 additions and 18 deletions

View File

@ -4,7 +4,7 @@ module Typed
CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" ,
"class_statement" , "collections" , "field_def" , "field_access",
"if_statement" , "name_expression"]
"function_statement" , "if_statement" , "name_expression"]
CompilerModules.each do |mod|
require_relative "compiler/" + mod
@ -190,7 +190,6 @@ module Typed
end
end
require_relative "compiler/function_definition"
require_relative "compiler/operator_value"
require_relative "compiler/return_statement"
require_relative "compiler/statement_list"

View File

@ -1,36 +1,25 @@
module Typed
Compiler.class_eval do
module FunctionStatement
def on_FunctionStatement statement
#puts statement.inspect
# return_type , name , parameters, kids , receiver = *statement
name = statement.name
# return_type , name , parameters, kids , receiver = *statement
raise "Already in method #{@method}" if @method
args = statement.parameters.collect do |p|
Parfait::Variable.new( *p )
end
class_method = nil
if(statement.receiver )
if( statement.receiver.first == :self) #class method
class_method = @clazz
@clazz = @clazz.meta
else
raise "Not covered #{statement.receiver}"
end
end
class_method = handle_receiver( statement ) #nil for instance method
@method = @clazz.get_instance_method( name )
@method = @clazz.get_instance_method( statement.name )
if(@method)
#puts "Warning, redefining method #{name}" unless name == :main
#TODO check args / type compatibility
init_method
else
create_method_for(@clazz, name , args ).init_method
create_method_for(@clazz, statement.name , args ).init_method
end
@method.source = statement
#puts "compile method #{@method.name}"
process(statement.statements)
@ -39,5 +28,15 @@ module Typed
# function definition is a statement, does not return any value
return nil
end
private
def handle_receiver( statement )
return nil unless statement.receiver
raise "Not covered #{statement.receiver}" unless ( statement.receiver.first == :self)
class_method = @clazz
@clazz = @clazz.meta
class_method
end
end
end