fix method seperation

Since Compiled method split into Method and
CompiledMethodInfo (parfait/vm) lots of call
syntax changes
This commit is contained in:
Torsten Ruger
2015-05-24 13:31:33 +03:00
parent 1d9ef6d5c8
commit 1a499a1de9
11 changed files with 71 additions and 85 deletions

View File

@ -8,7 +8,9 @@ module Builtin
# As we write before we recurse (save a push) we write the number backwards
# arguments: string address , integer
def utoa context
utoa_function = Virtual::CompiledMethod.new(:utoa , [ Virtual::Integer ] , Virtual::Integer ,Virtual::Integer )
utoa_function = Virtual::CompiledMethodInfo.create_method("Integer" ,"utoa" , [ Virtual::Integer ] )
function.info.return_type = Virtual::Integer
function.info.receiver = Virtual::Integer
return utoa_function
str_addr = utoa_function.receiver
number = utoa_function.args.first
@ -17,8 +19,8 @@ module Builtin
# make char out of digit (by using ascii encoding) 48 == "0"
utoa_function.instance_eval do
add( remainder , remainder , 48)
strb( remainder, str_addr )
sub( str_addr, str_addr , 1 )
strb( remainder, str_addr )
sub( str_addr, str_addr , 1 )
cmp( number , 0 )
callne( utoa_function )
end
@ -26,7 +28,9 @@ module Builtin
end
def putint context
putint_function = Virtual::CompiledMethod.new(:putint , [] , Virtual::Integer ,Virtual::Integer )
putint_function = Virtual::CompiledMethodInfo.create_method("Integer","putint" , [] )
putint_function.info.return_type = Virtual::Integer
putint_function.info.receiver = Virtual::Integer
return putint_function
buffer = Parfait::Word.new(" ") # create a buffer
context.object_space.add_object buffer # and save it (function local variable: a no no)
@ -48,21 +52,23 @@ module Builtin
putint_function
end
# testing method, hand coded fibo, expects arg in receiver_register
# testing method, hand coded fibo, expects arg in receiver_register
# result comes in return_register
# a hand coded version of the fibonachi numbers
# not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
def fibo context
fibo_function = Virtual::CompiledMethod.new(:fibo , [] , Virtual::Integer ,Virtual::Integer )
fibo_function = Virtual::CompiledMethodInfo.create_method("Integer","fibo" , [] )
fibo_function.info.return_type = Virtual::Integer
fibo_function.info.receiver = Virtual::Integer
return fibo_function
result = fibo_function.return_type
int = fibo_function.receiver
last = fibo_function.new_block("return")
f1 = fibo_function.new_local
f2 = fibo_function.new_local
fibo_function.instance_eval do
cmp int , 1
mov( result, int , condition_code: :le)
@ -73,8 +79,8 @@ module Builtin
loop = fibo_function.new_block("loop")
fibo_function.insert_at loop
fibo_function.instance_eval do #loop through
fibo_function.instance_eval do #loop through
add f1 , f1 , f2 # f1 = f1 + f2
sub f2 , f1 , f2 # f2 = f1 -f2
sub int , int , 1 # todo: set.. should do below cmp, but doesn't , set_update_status: 1
@ -82,10 +88,10 @@ module Builtin
bne( loop )
mov( result , f1 )
end
fibo_function
end
end
extend ClassMethods
extend ClassMethods
end
end
end