fix method seperation
Since Compiled method split into Method and CompiledMethodInfo (parfait/vm) lots of call syntax changes
This commit is contained in:
@ -2,15 +2,15 @@ module Builtin
|
||||
class Array
|
||||
module ClassMethods
|
||||
def get context , index = Virtual::Integer
|
||||
get_function = Virtual::CompiledMethod.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
get_function = Virtual::CompiledMethodInfo.create_method(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
return get_function
|
||||
end
|
||||
def set context , index = Virtual::Integer , object = Virtual::Reference
|
||||
set_function = Virtual::CompiledMethod.new(:set , [Virtual::Integer, Virtual::Reference] )
|
||||
set_function = Virtual::CompiledMethodInfo.create_method(:set , [Virtual::Integer, Virtual::Reference] )
|
||||
return set_function
|
||||
end
|
||||
def push context , object = Virtual::Reference
|
||||
push_function = Virtual::CompiledMethod.new(:push , [Virtual::Reference] )
|
||||
push_function = Virtual::CompiledMethodInfo.create_method(:push , [Virtual::Reference] )
|
||||
return push_function
|
||||
end
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -4,38 +4,42 @@ module Builtin
|
||||
# main entry point, ie __init__ calls this
|
||||
# defined here as empty, to be redefined
|
||||
def main context
|
||||
function = Virtual::CompiledMethod.new(:main , [] , Virtual::Integer)
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","main" , [])
|
||||
function.info.return_type = Virtual::Integer
|
||||
return function
|
||||
end
|
||||
# this is the really really first place the machine starts.
|
||||
# it isn't really a function, ie it is jumped to (not called), exits and may not return
|
||||
# so it is responsible for initial setup (and relocation)
|
||||
def __init__ context
|
||||
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
|
||||
clazz = Virtual::Machine.instance.space.get_class_by_name "Kernel"
|
||||
method = clazz.resolve_method :main
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
|
||||
function.info.return_type = Virtual::Integer
|
||||
clazz = Virtual::Machine.instance.class_mappings["Kernel"]
|
||||
method = clazz.resolve_method Virtual::new_word "main"
|
||||
me = Virtual::Self.new(Virtual::Reference)
|
||||
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
||||
function.add_code(code)
|
||||
function.add_code Virtual::MethodCall.new(method)
|
||||
function.info.add_code(code)
|
||||
function.info.add_code Virtual::MethodCall.new(method)
|
||||
return function
|
||||
end
|
||||
def putstring context
|
||||
function = Virtual::CompiledMethod.new(:putstring , [] )
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel" , "putstring" , [] )
|
||||
return function
|
||||
ret = Virtual::RegisterMachine.instance.write_stdout(function)
|
||||
function.set_return ret
|
||||
function
|
||||
end
|
||||
def exit context
|
||||
function = Virtual::CompiledMethod.new(:exit , [] , Virtual::Integer)
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","exit" , [])
|
||||
function.info.return_type = Virtual::Integer
|
||||
return function
|
||||
ret = Virtual::RegisterMachine.instance.exit(function)
|
||||
function.set_return ret
|
||||
function
|
||||
end
|
||||
def __send context
|
||||
function = Virtual::CompiledMethod.new(:__send , [] , Virtual::Integer)
|
||||
function = Virtual::CompiledMethodInfo.create_method("Kernel" ,"__send" , [] )
|
||||
function.info.return_type = Virtual::Integer
|
||||
return function
|
||||
end
|
||||
end
|
||||
|
@ -6,7 +6,8 @@ module Builtin
|
||||
# set/get instance variable use it.
|
||||
# This is just a placeholder, as we code this in ruby, but the instance methods need the definition before.
|
||||
def index_of context , name = Virtual::Integer
|
||||
index_function = Virtual::CompiledMethod.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
|
||||
index_function = Virtual::CompiledMethodInfo.create_method("Object" , "index_of" , [Virtual::Reference] )
|
||||
index_function.info.return_type = Virtual::Integer
|
||||
return index_function
|
||||
end
|
||||
|
||||
@ -23,7 +24,7 @@ module Builtin
|
||||
# end
|
||||
# The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
|
||||
def _get_instance_variable context , name = Virtual::Integer
|
||||
get_function = Virtual::CompiledMethod.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery )
|
||||
get_function = Virtual::CompiledMethodInfo.create_method("Object","_get_instance_variable" , [ Virtual::Reference ] )
|
||||
return get_function
|
||||
me = get_function.receiver
|
||||
var_name = get_function.args.first
|
||||
@ -44,7 +45,7 @@ module Builtin
|
||||
end
|
||||
|
||||
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
|
||||
set_function = Virtual::CompiledMethod.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery )
|
||||
set_function = Virtual::CompiledMethodInfo.create_method("Object","_set_instance_variable" ,[Virtual::Reference ,Virtual::Reference] )
|
||||
return set_function
|
||||
receiver set_function
|
||||
me = set_function.receiver
|
||||
|
@ -1,18 +1,6 @@
|
||||
module Builtin
|
||||
class Word
|
||||
module ClassMethods
|
||||
def get context , index = Virtual::Integer
|
||||
get_function = Virtual::CompiledMethod.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
return get_function
|
||||
end
|
||||
def set context , index = Virtual::Integer , char = Virtual::Integer
|
||||
set_function = Virtual::CompiledMethod.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
|
||||
return set_function
|
||||
end
|
||||
def puts context
|
||||
puts_function = Virtual::CompiledMethod.new(:puts , [] )
|
||||
return puts_function
|
||||
end
|
||||
end
|
||||
extend ClassMethods
|
||||
end
|
||||
|
Reference in New Issue
Block a user