remove function statements

functions need to be defined a level up
This commit is contained in:
Torsten Ruger 2016-12-17 18:28:42 +02:00
parent 4875d3aea7
commit ffb69a2c55
5 changed files with 2 additions and 60 deletions

View File

@ -4,7 +4,7 @@ module Typed
CompilerModules = [ "assignment" , "basic_values" , "call_site", CompilerModules = [ "assignment" , "basic_values" , "call_site",
"class_statement" , "collections" , "field_access", "class_statement" , "collections" , "field_access",
"function_statement" , "if_statement" , "name_expression" , "if_statement" , "name_expression" ,
"operator_expression" , "return_statement", "statement_list", "operator_expression" , "return_statement", "statement_list",
"while_statement"] "while_statement"]

View File

@ -1,40 +0,0 @@
module Typed
module FunctionStatement
def on_FunctionStatement statement
# return_type , name , parameters, kids , receiver = *statement
raise "Already in method #{@method}" if @method
args = statement.parameters
class_method = handle_receiver( statement ) #nil for instance method
@method = @type.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(@type, statement.name , args ).init_method
end
@method.source = statement
process(statement.statements)
@type = class_method if class_method
@method = nil
# 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 = @type
@type = @type.object_class.meta.get_type
class_method
end
end
end

View File

@ -9,7 +9,7 @@ end
["while_statement", "if_statement" , "return_statement" , "statements", ["while_statement", "if_statement" , "return_statement" , "statements",
"operator_expression" , "field_access" , "call_site" , "basic_values", "operator_expression" , "field_access" , "call_site" , "basic_values",
"assignment" , "class_statement" , "function_statement" , "to_code"].each do |code| "assignment" , "class_statement" , "to_code"].each do |code|
require_relative "tree/" + code require_relative "tree/" + code
end end

View File

@ -1,7 +0,0 @@
module Typed
module Tree
class FunctionStatement < Statement
attr_accessor :return_type , :name , :parameters, :statements , :receiver
end
end
end

View File

@ -20,17 +20,6 @@ module Typed
w w
end end
def on_function statement
return_type , name , parameters, statements , receiver = *statement
w = Tree::FunctionStatement.new()
w.return_type = return_type
w.name = name.children.first
w.parameters = process parameters
w.statements = process(statements)
w.receiver = receiver
w
end
def on_parameters statement def on_parameters statement
params = {} params = {}
statement.children.each do |param , type , name| statement.children.each do |param , type , name|