trying to get function calls to work (but will have to rework regeister handling)
This commit is contained in:
@ -56,6 +56,7 @@ module Vm
|
||||
|
||||
def assemble io
|
||||
@entry.assemble(io)
|
||||
raise @body.inspect
|
||||
@body.assemble(io)
|
||||
@exit.assemble(io)
|
||||
end
|
||||
|
@ -14,14 +14,14 @@ module Vm
|
||||
def assign_function context
|
||||
@function = context.program.get_function @name
|
||||
if @function
|
||||
raise "error #{self}" unless @function.arity != args.length
|
||||
raise "error #{self} , #{@function.args.length} != #{args.length}" if @function.arity != args.length
|
||||
else
|
||||
@function = context.program.get_or_create_function @name
|
||||
end
|
||||
end
|
||||
def load_args
|
||||
args.each_with_index do |arg , index|
|
||||
add_code arg.load(index)
|
||||
add_code arg.load("r#{index}".to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,14 +43,21 @@ module Vm
|
||||
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
||||
end
|
||||
|
||||
def add_function function
|
||||
raise "not a function #{function}" unless function.is_a? Function
|
||||
@functions << function
|
||||
end
|
||||
|
||||
def get_function name
|
||||
@functions.detect{ |f| (f.name == name) && (f.class == Function) }
|
||||
name = name.to_sym
|
||||
@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 = Function.new(name)
|
||||
block = Core::Kernel.send(name)
|
||||
fun.set_body block
|
||||
|
@ -24,6 +24,8 @@ module Vm
|
||||
def initialize value
|
||||
@value = value
|
||||
end
|
||||
attr_reader :value
|
||||
|
||||
#naming convention to infer types in kernel functions. Kernel types are basic types, ie see below
|
||||
#
|
||||
def self.type name
|
||||
@ -41,6 +43,9 @@ module Vm
|
||||
def load reg
|
||||
Machine.instance.word_load self , reg
|
||||
end
|
||||
def length
|
||||
4
|
||||
end
|
||||
end
|
||||
|
||||
class Unsigned < Word
|
||||
|
Reference in New Issue
Block a user