fold last of the virtual into register

This commit is contained in:
Torsten Ruger
2015-10-22 18:16:29 +03:00
parent f658ecf425
commit dcbd3c7091
67 changed files with 161 additions and 227 deletions

View File

@ -4,9 +4,9 @@ The Builtin module contains functions that can not be coded in ruby.
It is the other side of the parfait coin, part of the runtime.
The functions are organized by their respective class and get loaded in boot_classes! ,
right at the start. (see virtual/boot.rb)
right at the start. (see register/boot.rb)
These functions return their code, ie a Parfait::Method with a Virtual::MethodSource object,
These functions return their code, ie a Parfait::Method with a MethodSource object,
which can then be called by ruby code as if it were a "normal" function.
A normal ruby function is one that is parsed and transformed to code. But not all functionality can

View File

@ -5,7 +5,7 @@ module Register
module ClassMethods
include AST::Sexp
def plus c
plus_function = Virtual::MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
plus_function = MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
plus_function.source.set_return_type :Integer
plus_function.source.receiver = :Integer
@ -15,7 +15,7 @@ module Register
me = Register.tmp_reg :Integer
plus_function.source.add_code Register.get_slot(plus_function , :message , :receiver , me )
add = Register::OperatorInstruction.new( plus_function, :add , me , tmp )
add = OperatorInstruction.new( plus_function, :add , me , tmp )
plus_function.source.add_code add
plus_function.source.add_code Register.set_slot(plus_function , me , :message , :return_value )
return plus_function
@ -28,14 +28,14 @@ module Register
# As we write before we recurse (save a push) we write the number backwards
# arguments: string address , integer
# def utoa context
# utoa_function = Virtual::MethodSource.create_method(:Integer ,:utoa , [ :Integer ] )
# utoa_function = MethodSource.create_method(:Integer ,:utoa , [ :Integer ] )
# function.source.return_type = :Integer
# function.source.receiver = :Integer
# return utoa_function
# # str_addr = utoa_function.receiver
# # number = utoa_function.args.first
# # remainder = utoa_function.new_local
# # Virtual::RegisterMachine.instance.div10( utoa_function , number , remainder )
# # RegisterMachine.instance.div10( utoa_function , number , remainder )
# # # make char out of digit (by using ascii encoding) 48 == "0"
# # utoa_function.instance_eval do
# # add( remainder , remainder , 48)
@ -48,7 +48,7 @@ module Register
# end
def putint context
putint_function = Virtual::MethodSource.create_method(:Integer,:Integer,:putint , [] )
putint_function = MethodSource.create_method(:Integer,:Integer,:putint , [] )
putint_function.source.set_return_type :Integer
putint_function.source.receiver = :Integer
return putint_function
@ -68,7 +68,7 @@ module Register
# add( int , buffer , nil ) # string to write to
# mov( moved_int , buffer.length )
# end
# Virtual::RegisterMachine.instance.write_stdout(putint_function)
# RegisterMachine.instance.write_stdout(putint_function)
# putint_function
end
@ -77,7 +77,7 @@ module 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::MethodSource.create_method(:Integer,:Integer,:fibo , [] )
fibo_function = MethodSource.create_method(:Integer,:Integer,:fibo , [] )
fibo_function.source.set_return_type :Integer
fibo_function.source.receiver = :Integer
return fibo_function

View File

@ -6,7 +6,7 @@ module Register
# 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
def __init__ context
function = Virtual::MethodSource.create_method(:Kernel,:Integer,:__init__ , [])
function = MethodSource.create_method(:Kernel,:Integer,:__init__ , [])
function.source.set_return_type :Integer
# no method enter or return (automatically added), remove
function.source.blocks.first.codes.pop # no Method enter
@ -21,20 +21,20 @@ module Register
# And store the space as the new self (so the call can move it back as self)
function.source.add_code Register.set_slot( function, space_reg , :new_message , :receiver)
# now we are set up to issue a call to the main
Register.issue_call( function , Virtual.machine.space.get_main)
Register.issue_call( function , Register.machine.space.get_main)
emit_syscall( function , :exit )
return function
end
def exit context
function = Virtual::MethodSource.create_method(:Kernel,:Integer,:exit , [])
function = MethodSource.create_method(:Kernel,:Integer,:exit , [])
function.source.set_return_type :Integer
return function
ret = Virtual::RegisterMachine.instance.exit(function)
ret = RegisterMachine.instance.exit(function)
function.set_return ret
function
end
def __send context
function = Virtual::MethodSource.create_method(:Kernel,:Integer ,:__send , [] )
function = MethodSource.create_method(:Kernel,:Integer ,:__send , [] )
function.source.set_return_type :Integer
return function
end

View File

@ -6,7 +6,7 @@ module Register
# main entry point, ie __init__ calls this
# defined here as empty, to be redefined
def main context
function = Virtual::MethodSource.create_method(:Object, :Integer , :main , [])
function = MethodSource.create_method(:Object, :Integer , :main , [])
return function
end
@ -18,13 +18,13 @@ module Register
# 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 = :Integer
get_function = Virtual::MethodSource.create_method(:Object,:Integer, :_get_instance_variable , [ ] )
get_function = MethodSource.create_method(:Object,:Integer, :_get_instance_variable , [ ] )
return get_function
# me = get_function.receiver
# var_name = get_function.args.first
# return_to = get_function.return_type
#
# index_function = ::Virtual.machine.space.get_class_by_name(:Object).resolve_method(:index_of)
# index_function = ::Register.machine.space.get_class_by_name(:Object).resolve_method(:index_of)
# # get_function.push( [me] )
# # index = get_function.call( index_function )
#
@ -39,7 +39,7 @@ module Register
end
def _set_instance_variable(context , name = :Integer , value = :Integer )
set_function = Virtual::MethodSource.create_method(:Object,:Integer,:_set_instance_variable ,[] )
set_function = MethodSource.create_method(:Object,:Integer,:_set_instance_variable ,[] )
return set_function
# receiver set_function
# me = set_function.receiver

View File

@ -3,7 +3,7 @@ module Register
module Word
module ClassMethods
def putstring context
function = Virtual::MethodSource.create_method(:Word,:Integer , :putstring , [] )
function = MethodSource.create_method(:Word,:Integer , :putstring , [] )
function.source.add_code Register.get_slot( function , :message , :receiver , :new_message )
Kernel.emit_syscall( function , :putstring )
function