rename function_call to call_site in all levels to avoid confusion

This commit is contained in:
Torsten Ruger
2014-05-13 21:15:02 +03:00
parent 04af367bc0
commit 46ea1df51e
17 changed files with 73 additions and 70 deletions

View File

@ -54,7 +54,7 @@ module Arm
end
def function_call into , call
raise "Not FunctionCall #{call.inspect}" unless call.is_a? Vm::FunctionCall
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
raise "Not linked #{call.inspect}" unless call.function
into.add_code bl( :left => call.function )
call.function.return_type

View File

@ -0,0 +1,31 @@
module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
attr_reader :name, :args
def initialize name, args
@name , @args = name.to_sym , args
end
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
function = context.program.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::CallSite.new( name , params , function)
call.load_args into
call.do_call into
call
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") +"] )"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes
[:name , :args]
end
end
end

View File

@ -38,3 +38,4 @@ require_relative "conditional_expression"
require_relative "while_expression"
require_relative "function_expression"
require_relative "operator_expressions"
require_relative "call_site_expression"

View File

@ -1,34 +1,5 @@
module Ast
# assignment, like operators are really function calls
class FuncallExpression < Expression
attr_reader :name, :args
def initialize name, args
@name , @args = name.to_sym , args
end
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
function = context.program.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::FunctionCall.new( name , params , function)
call.load_args into
call.do_call into
call
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") +"] )"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes
[:name , :args]
end
end
class OperatorExpression < Expression
attr_reader :operator, :left, :right

View File

@ -1,5 +1,5 @@
module Parser
module FunctionCall
module CallSite
include Parslet
rule(:argument_list) {
@ -9,7 +9,7 @@ module Parser
space? >> right_parenthesis
}
rule(:function_call) { name.as(:function_call) >> argument_list }
rule(:call_site) { name.as(:call_site) >> argument_list }
end

View File

@ -4,7 +4,7 @@ require_relative "tokens"
require_relative "keywords"
require_relative "control"
require_relative "expression"
require_relative "function_call"
require_relative "call_site"
require_relative "function_definition"
require_relative "operators"
@ -25,10 +25,10 @@ module Parser
include Keywords
include Control
include Expression
include FunctionCall
include CallSite
include FunctionDefinition
include Operators
rule(:root){ (function_definition | expression | operator_expression | function_call).repeat }
rule(:root){ (function_definition | expression | operator_expression | call_site).repeat }
end
end

View File

@ -2,9 +2,9 @@ module Parser
module Expression
include Parslet
rule(:value_expression) { function_call | basic_type }
rule(:value_expression) { call_site | basic_type }
rule(:expression) { (while_do | conditional | operator_expression | function_call ) >> newline }
rule(:expression) { (while_do | conditional | operator_expression | call_site ) >> newline }
def delimited_expressions( delimit )
( (delimit.absent? >> expression).repeat(1)).as(:expressions) >> delimit

View File

@ -19,9 +19,9 @@ module Parser
rule(:argument => simple(:argument)) { argument }
rule(:argument_list => sequence(:argument_list)) { argument_list }
rule( :function_call => simple(:function_call),
rule( :call_site => simple(:call_site),
:argument_list => sequence(:argument_list)) do
Ast::FuncallExpression.new(function_call.name, argument_list)
Ast::CallSiteExpression.new(call_site.name, argument_list)
end
rule(:if => simple(:if), :conditional => simple(:conditional),

View File

@ -2,7 +2,7 @@ module Vm
# name and args , return
class FunctionCall < Value
class CallSite < Value
def initialize(name , args , function )
@name = name

View File

@ -1,5 +1,5 @@
require_relative "function"
require_relative "function_call"
require_relative "call_site"
require "arm/arm_machine"
module Vm