coming together, more and more each day

This commit is contained in:
Torsten Ruger
2014-05-13 21:06:12 +03:00
parent f6711ea49c
commit 04af367bc0
8 changed files with 45 additions and 28 deletions

View File

@ -29,6 +29,7 @@ module Vm
branch_body
end
attr_reader :args , :entry , :exit , :body , :name
attr_accessor :return_type
def arity
@args.length

View File

@ -4,22 +4,22 @@ module Vm
class FunctionCall < Value
def initialize(name , args)
def initialize(name , args , function )
@name = name
@args = args
@function = nil
@function = function
end
attr_reader :function , :args , :name
def load_args into
args.each_with_index do |arg , index|
puts "load " + arg.inspect
into.add_code arg.move("r#{index}".to_sym)
arg.load( into , index )
end
end
def do_call into
into.add_code Machine.instance.function_call self
into.add_code CMachine.instance.function_call into , self
end
end
end

View File

@ -45,20 +45,21 @@ module Vm
def add_function function
raise "not a function #{function}" unless function.is_a? Function
raise "syserr " unless function.name.is_a? Symbol
@functions << function
end
def get_function name
name = name.to_sym
@functions.detect{ |f| (f.name == name) }
@functions.detect{ |f| f.name == name }
end
# preferred way of creating new functions (also forward declarations, will flag unresolved later)
def get_or_create_function name
fun = get_function name
unless fun
puts @functions.inspect
fun = Core::Kernel.send(name)
raise "no such function '#{name}'" if fun == nil
@functions << fun
end
fun