From 7e0778dc70b9aaf3ca9864476f6ce95215cfd947 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 28 Oct 2015 12:19:10 +0200 Subject: [PATCH] remove return_type soon to be obsolete with multi returns --- lib/register/builtin/integer.rb | 8 ++---- lib/register/builtin/kernel.rb | 10 +++---- lib/register/builtin/object.rb | 2 +- lib/register/builtin/word.rb | 2 +- lib/register/method_source.rb | 36 +++++++++--------------- lib/soml/compiler/call_site.rb | 2 +- lib/soml/compiler/function_definition.rb | 2 +- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/register/builtin/integer.rb b/lib/register/builtin/integer.rb index ccb8ba70..a7ff327a 100644 --- a/lib/register/builtin/integer.rb +++ b/lib/register/builtin/integer.rb @@ -13,7 +13,6 @@ module Register # arguments: string address , integer # def utoa context # 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 @@ -32,8 +31,7 @@ module Register # end def putint context - putint_function = MethodSource.create_method(:Integer,:Integer,:putint , [] ) - putint_function.source.set_return_type :Integer + putint_function = MethodSource.create_method(:Integer,:putint , [] ) putint_function.source.receiver = :Integer return putint_function # buffer = Parfait::Word.new(" ") # create a buffer @@ -61,11 +59,9 @@ 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 = MethodSource.create_method(:Integer,:Integer,:fibo , [] ) - fibo_function.source.set_return_type :Integer + fibo_function = MethodSource.create_method(:Integer,:fibo , [] ) fibo_function.source.receiver = :Integer return fibo_function - # result = fibo_function.return_type # int = fibo_function.receiver # # last = fibo_function.new_block("return") diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index 30454c8b..40c54bc8 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -6,13 +6,12 @@ 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 = MethodSource.create_method(:Kernel,:Integer,:__init__ , []) - function.source.set_return_type :Integer + function = MethodSource.create_method(:Kernel,:__init__ , []) # no method enter or return (automatically added), remove new_start = Label.new(function , "__init__" ) function.source.instructions = new_start function.source.current = new_start - + #Set up the Space as self upon init space = Parfait::Space.object_space space_reg = Register.tmp_reg(:Space) @@ -28,8 +27,7 @@ module Register return function end def exit context - function = MethodSource.create_method(:Kernel,:Integer,:exit , []) - function.source.set_return_type :Integer + function = MethodSource.create_method(:Kernel,:exit , []) return function ret = RegisterMachine.instance.exit(function) function.set_return ret @@ -53,7 +51,7 @@ module Register def restore_message(function) 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 function.source.add_code RegisterTransfer.new(function, Register.message_reg , return_tmp ) # load the stored message into the base RegisterMachine diff --git a/lib/register/builtin/object.rb b/lib/register/builtin/object.rb index b03e3cff..e44dfdee 100644 --- a/lib/register/builtin/object.rb +++ b/lib/register/builtin/object.rb @@ -6,7 +6,7 @@ module Register # main entry point, ie __init__ calls this # defined here as empty, to be redefined def main context - function = MethodSource.create_method(:Object, :Integer , :main , []) + function = MethodSource.create_method(:Object , :main , []) return function end diff --git a/lib/register/builtin/word.rb b/lib/register/builtin/word.rb index 635c1590..28dc49dd 100644 --- a/lib/register/builtin/word.rb +++ b/lib/register/builtin/word.rb @@ -3,7 +3,7 @@ module Register module Word module ClassMethods 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 ) Kernel.emit_syscall( function , :putstring ) function diff --git a/lib/register/method_source.rb b/lib/register/method_source.rb index 8ab9dc55..4e7459dd 100644 --- a/lib/register/method_source.rb +++ b/lib/register/method_source.rb @@ -3,17 +3,15 @@ module Register # the static info of a method (with its compiled code, argument names etc ) is part of the # 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 - # Instructions. The function starts with one block, and that has a start and end (return) + # Code-wise Methods are made up from a list of Instructions. - # 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 - # "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 - # Linear blocks may be created from an existing block with new_block - # - branched: You create new blocks using function.new_block which gets added "after" return - # 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. + # - branched: Any of the Branch instructions creates a fork. The else branch is the "next" + # of a branch. The only valid branch targets are Labels. + # class MethodSource @@ -22,13 +20,13 @@ module Register # second, it creates MethodSource and attaches it to the method # # 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 clazz = Register.machine.space.get_class_by_name class_name 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 - 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 arguments = [] args.each_with_index do | arg , index | @@ -38,16 +36,15 @@ module Register arguments << arg end method = clazz.create_instance_method( method_name , Register.new_list(arguments)) - method.source = MethodSource.new(method , return_type) + method.source = MethodSource.new(method) method end # just passing the method object in for Instructions to make decisions (later) - def initialize method , return_type - init( method , return_type) + def initialize method + init( method ) end - def init method , return_type = nil - set_return_type( return_type ) + def init method @instructions = @current = Label.new(self, "#{method.for_class.name}_#{method.name}") add_code enter = Register.save_return(self, :message , :return_address) add_code Label.new( method, "return") @@ -60,14 +57,9 @@ module Register @current = enter @constants = [] end - attr_reader :constants , :return_type + attr_reader :constants 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) # the added instruction will become the new insertion point def add_code instruction diff --git a/lib/soml/compiler/call_site.rb b/lib/soml/compiler/call_site.rb index 873dd523..0e7c0f66 100644 --- a/lib/soml/compiler/call_site.rb +++ b/lib/soml/compiler/call_site.rb @@ -50,7 +50,7 @@ module Soml #puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a raise "Method not implemented #{me.type}.#{name}" unless 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 # but move it into a register too add_code Register.get_slot(@method, :message , :return_value , ret ) diff --git a/lib/soml/compiler/function_definition.rb b/lib/soml/compiler/function_definition.rb index 9649ab95..b59745a1 100644 --- a/lib/soml/compiler/function_definition.rb +++ b/lib/soml/compiler/function_definition.rb @@ -30,7 +30,7 @@ module Soml #TODO check args / type compatibility @method.source.init @method 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 end @method.source.receiver = r