remove return_type

soon to be obsolete with multi returns
This commit is contained in:
Torsten Ruger 2015-10-28 12:19:10 +02:00
parent 142c36a374
commit 7e0778dc70
7 changed files with 24 additions and 38 deletions

View File

@ -13,7 +13,6 @@ module Register
# arguments: string address , integer # arguments: string address , integer
# def utoa context # def utoa context
# utoa_function = MethodSource.create_method(:Integer ,:utoa , [ :Integer ] ) # utoa_function = MethodSource.create_method(:Integer ,:utoa , [ :Integer ] )
# function.source.return_type = :Integer
# function.source.receiver = :Integer # function.source.receiver = :Integer
# return utoa_function # return utoa_function
# # str_addr = utoa_function.receiver # # str_addr = utoa_function.receiver
@ -32,8 +31,7 @@ module Register
# end # end
def putint context def putint context
putint_function = MethodSource.create_method(:Integer,:Integer,:putint , [] ) putint_function = MethodSource.create_method(:Integer,:putint , [] )
putint_function.source.set_return_type :Integer
putint_function.source.receiver = :Integer putint_function.source.receiver = :Integer
return putint_function return putint_function
# buffer = Parfait::Word.new(" ") # create a buffer # buffer = Parfait::Word.new(" ") # create a buffer
@ -61,11 +59,9 @@ module Register
# a hand coded version of the fibonachi numbers # 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 # not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
def fibo context def fibo context
fibo_function = MethodSource.create_method(:Integer,:Integer,:fibo , [] ) fibo_function = MethodSource.create_method(:Integer,:fibo , [] )
fibo_function.source.set_return_type :Integer
fibo_function.source.receiver = :Integer fibo_function.source.receiver = :Integer
return fibo_function return fibo_function
# result = fibo_function.return_type
# int = fibo_function.receiver # int = fibo_function.receiver
# #
# last = fibo_function.new_block("return") # last = fibo_function.new_block("return")

View File

@ -6,8 +6,7 @@ module Register
# it isn't really a function, ie it is jumped to (not called), exits and may not return # 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 # so it is responsible for initial setup
def __init__ context def __init__ context
function = MethodSource.create_method(:Kernel,:Integer,:__init__ , []) function = MethodSource.create_method(:Kernel,:__init__ , [])
function.source.set_return_type :Integer
# no method enter or return (automatically added), remove # no method enter or return (automatically added), remove
new_start = Label.new(function , "__init__" ) new_start = Label.new(function , "__init__" )
function.source.instructions = new_start function.source.instructions = new_start
@ -28,8 +27,7 @@ module Register
return function return function
end end
def exit context def exit context
function = MethodSource.create_method(:Kernel,:Integer,:exit , []) function = MethodSource.create_method(:Kernel,:exit , [])
function.source.set_return_type :Integer
return function return function
ret = RegisterMachine.instance.exit(function) ret = RegisterMachine.instance.exit(function)
function.set_return ret function.set_return ret
@ -53,7 +51,7 @@ module Register
def restore_message(function) def restore_message(function)
r8 = RegisterValue.new( :r8 , :Message) r8 = RegisterValue.new( :r8 , :Message)
return_tmp = Register.tmp_reg function.source.return_type return_tmp = Register.tmp_reg :Integer
# get the sys return out of the way # get the sys return out of the way
function.source.add_code RegisterTransfer.new(function, Register.message_reg , return_tmp ) function.source.add_code RegisterTransfer.new(function, Register.message_reg , return_tmp )
# load the stored message into the base RegisterMachine # load the stored message into the base RegisterMachine

View File

@ -6,7 +6,7 @@ module Register
# main entry point, ie __init__ calls this # main entry point, ie __init__ calls this
# defined here as empty, to be redefined # defined here as empty, to be redefined
def main context def main context
function = MethodSource.create_method(:Object, :Integer , :main , []) function = MethodSource.create_method(:Object , :main , [])
return function return function
end end

View File

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

View File

@ -3,17 +3,15 @@ module Register
# the static info of a method (with its compiled code, argument names etc ) is part of the # the static info of a method (with its compiled code, argument names etc ) is part of the
# runtime, ie found in Parfait::Method # runtime, ie found in Parfait::Method
# Code-wise Methods are made up from a list of Blocks, in a similar way blocks are made up of # Code-wise Methods are made up from a list of Instructions.
# Instructions. The function starts with one block, and that has a start and end (return)
# Blocks can be linked in two ways: # Instructions can be of three tyes:
# -linear: flow continues from one to the next as they are sequential both logically and # -linear: flow continues from one to the next as they are sequential both logically and
# "physically" use the block set_next for this. # "physically" use the set_next for this (or add_code).
# This "straight line", there must be a continuous sequence from body to return # This "straight line", there must be a continuous sequence from body to return
# Linear blocks may be created from an existing block with new_block # - branched: Any of the Branch instructions creates a fork. The else branch is the "next"
# - branched: You create new blocks using function.new_block which gets added "after" return # of a branch. The only valid branch targets are Labels.
# These (eg if/while) blocks may themselves have linear blocks ,but the last of these #
# MUST have an uncoditional branch. And remember, all roads lead to return.
class MethodSource class MethodSource
@ -22,13 +20,13 @@ module Register
# second, it creates MethodSource and attaches it to the method # second, it creates MethodSource and attaches it to the method
# #
# compile code then works with the method, but adds code tot the info # compile code then works with the method, but adds code tot the info
def self.create_method( class_name , return_type , method_name , args) def self.create_method( class_name , method_name , args)
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
clazz = Register.machine.space.get_class_by_name class_name clazz = Register.machine.space.get_class_by_name class_name
raise "No such class #{class_name}" unless clazz raise "No such class #{class_name}" unless clazz
create_method_for( clazz , return_type , method_name , args) create_method_for( clazz , method_name , args)
end end
def self.create_method_for clazz , return_type , method_name , args def self.create_method_for clazz , method_name , args
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol
arguments = [] arguments = []
args.each_with_index do | arg , index | args.each_with_index do | arg , index |
@ -38,16 +36,15 @@ module Register
arguments << arg arguments << arg
end end
method = clazz.create_instance_method( method_name , Register.new_list(arguments)) method = clazz.create_instance_method( method_name , Register.new_list(arguments))
method.source = MethodSource.new(method , return_type) method.source = MethodSource.new(method)
method method
end end
# just passing the method object in for Instructions to make decisions (later) # just passing the method object in for Instructions to make decisions (later)
def initialize method , return_type def initialize method
init( method , return_type) init( method )
end end
def init method , return_type = nil def init method
set_return_type( return_type )
@instructions = @current = Label.new(self, "#{method.for_class.name}_#{method.name}") @instructions = @current = Label.new(self, "#{method.for_class.name}_#{method.name}")
add_code enter = Register.save_return(self, :message , :return_address) add_code enter = Register.save_return(self, :message , :return_address)
add_code Label.new( method, "return") add_code Label.new( method, "return")
@ -60,14 +57,9 @@ module Register
@current = enter @current = enter
@constants = [] @constants = []
end end
attr_reader :constants , :return_type attr_reader :constants
attr_accessor :current , :receiver , :instructions attr_accessor :current , :receiver , :instructions
def set_return_type type
return if type.nil?
raise "not type #{type}" unless Register.machine.space.get_class_by_name type
@return_type = type
end
# add an instruction after the current (insertion point) # add an instruction after the current (insertion point)
# the added instruction will become the new insertion point # the added instruction will become the new insertion point
def add_code instruction def add_code instruction

View File

@ -50,7 +50,7 @@ module Soml
#puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a #puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a
raise "Method not implemented #{me.type}.#{name}" unless method raise "Method not implemented #{me.type}.#{name}" unless method
Register.issue_call( @method , method ) Register.issue_call( @method , method )
ret = use_reg( method.source.return_type ) ret = use_reg( :Integer )
# the effect of the method is that the NewMessage Return slot will be filled, return it # the effect of the method is that the NewMessage Return slot will be filled, return it
# but move it into a register too # but move it into a register too
add_code Register.get_slot(@method, :message , :return_value , ret ) add_code Register.get_slot(@method, :message , :return_value , ret )

View File

@ -30,7 +30,7 @@ module Soml
#TODO check args / type compatibility #TODO check args / type compatibility
@method.source.init @method @method.source.init @method
else else
@method = Register::MethodSource.create_method_for(@clazz, return_type, name , args ) @method = Register::MethodSource.create_method_for(@clazz, name , args )
@clazz.add_instance_method @method @clazz.add_instance_method @method
end end
@method.source.receiver = r @method.source.receiver = r