kernel functions are not fixed to be Object functions

This commit is contained in:
Torsten Ruger 2014-05-31 16:19:44 +03:00
parent a6f02d6be3
commit cdfc1ac891
3 changed files with 4 additions and 3 deletions

View File

@ -8,6 +8,7 @@ module Ast
end end
def compile context , into def compile context , into
params = args.collect{ |a| a.compile(context, into) } params = args.collect{ |a| a.compile(context, into) }
#TOOD, this needs dynamic resolution
function = context.current_class.get_or_create_function(name) function = context.current_class.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::CallSite.new( name , params , function) call = Vm::CallSite.new( name , params , function)

View File

@ -38,7 +38,7 @@ module Core
context.object_space.add_object buffer # and save it (function local variable: a no no) context.object_space.add_object buffer # and save it (function local variable: a no no)
int = putint_function.args.first int = putint_function.args.first
moved_int = putint_function.new_local moved_int = putint_function.new_local
utoa = context.current_class.get_or_create_function(:utoa) utoa = context.object_space.get_or_create_class(:Object).get_or_create_function(:utoa)
b = putint_function.body b = putint_function.body
b.mov( moved_int , int ) #move arg up b.mov( moved_int , int ) #move arg up
#b.a buffer => int # string to write to #b.a buffer => int # string to write to

View File

@ -46,12 +46,12 @@ class TestSmallProg < MiniTest::Test
# not my hand off course, found in the net from a basic introduction # not my hand off course, found in the net from a basic introduction
def test_fibo def test_fibo
int = Vm::Integer.new(1) int = Vm::Integer.new(1)
fibo = @object_space.context.current_class.get_or_create_function(:fibo) fibo = @object_space.get_or_create_class(:Object).get_or_create_function(:fibo)
main = @object_space.main.scope binding main = @object_space.main.scope binding
main.int = 10 main.int = 10
ret = main.call( fibo ) ret = main.call( fibo )
main.mov( :r1 , :r7 ) main.mov( :r1 , :r7 )
putint = @object_space.context.current_class.get_or_create_function(:putint) putint = @object_space.get_or_create_class(:Object).get_or_create_function(:putint)
@object_space.main.call( putint ) @object_space.main.call( putint )
@should = [0x0,0xb0,0xa0,0xe3,0xa,0x10,0xa0,0xe3,0x4,0x0,0x0,0xeb,0x7,0x10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0xef,0x0,0x70,0xa0,0xe1,0x0,0x40,0x2d,0xe9,0x1,0x0,0x51,0xe3,0x1,0x70,0xa0,0xd1,0xe,0xf0,0xa0,0xd1,0x1c,0x40,0x2d,0xe9,0x1,0x30,0xa0,0xe3,0x0,0x40,0xa0,0xe3,0x2,0x20,0x41,0xe2,0x4,0x30,0x83,0xe0,0x4,0x40,0x43,0xe0,0x1,0x20,0x52,0xe2,0xfb,0xff,0xff,0x5a,0x3,0x70,0xa0,0xe1,0x1c,0x80,0xbd,0xe8,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0xa,0x30,0x42,0xe2,0x22,0x21,0x42,0xe0,0x22,0x22,0x82,0xe0,0x22,0x24,0x82,0xe0,0x22,0x28,0x82,0xe0,0xa2,0x21,0xa0,0xe1,0x2,0x41,0x82,0xe0,0x84,0x30,0x53,0xe0,0x1,0x20,0x82,0x52,0xa,0x30,0x83,0x42,0x30,0x30,0x83,0xe2,0x0,0x30,0xc1,0xe5,0x1,0x10,0x41,0xe2,0x0,0x0,0x52,0xe3,0xef,0xff,0xff,0x1b,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x1,0x20,0xa0,0xe1,0x20,0x10,0x8f,0xe2,0x9,0x10,0x81,0xe2,0xe9,0xff,0xff,0xeb,0x14,0x10,0x8f,0xe2,0xc,0x20,0xa0,0xe3,0x1,0x0,0xa0,0xe3,0x4,0x70,0xa0,0xe3,0x0,0x0,0x0,0xef,0x0,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20]
write "fibo" write "fibo"