diff --git a/lib/parfait/message.rb b/lib/parfait/message.rb index 611019d1..ac9ac0e6 100644 --- a/lib/parfait/message.rb +++ b/lib/parfait/message.rb @@ -29,35 +29,35 @@ module Parfait get_at(index) end - def __send - typ = get_type_for( :receiver ) - # TODO: this will obviously be recoded as case, once that is done :-) - # depending on value type get method - if( typ == Integer ) - method = Integer.get_method @method_name - else - if( typ != ObjectReference ) - raise "unimplemented case" - else - method = @receiver.get_singeton_method @method_name - # Find the method for the given object (receiver) according to ruby dispatch rules: - # - see if the receiver object has a (singleton) method by the name - # - get receivers class and look for instance methods of the name - # - go up inheritance tree - # - start over with method_missing instead - # -> guaranteed to end at object.method_missing - unless method - cl = @receiver.layout.object_class - method = cl.get_instance_or_super_method @method_name - end - end - end - unless method - message = Message.new( @receiver , :method_missing , [@method_name] + @args) - message.send - else - method.call - end - end + # def __send + # typ = get_type_for( :receiver ) + # # TODO: this will obviously be recoded as case, once that is done :-) + # # depending on value type get method + # if( typ == Integer ) + # method = Integer.get_method @method_name + # else + # if( typ != ObjectReference ) + # raise "unimplemented case" + # else + # method = @receiver.get_singeton_method @method_name + # # Find the method for the given object (receiver) according to ruby dispatch rules: + # # - see if the receiver object has a (singleton) method by the name + # # - get receivers class and look for instance methods of the name + # # - go up inheritance tree + # # - start over with method_missing instead + # # -> guaranteed to end at object.method_missing + # unless method + # cl = @receiver.layout.object_class + # method = cl.get_instance_or_super_method @method_name + # end + # end + # end + # unless method + # message = Message.new( @receiver , :method_missing , [@method_name] + @args) + # message.send + # else + # method.call + # end + # end end end diff --git a/lib/parfait/meta_class.rb b/lib/parfait/meta_class.rb index 070b7c01..d5814ca9 100644 --- a/lib/parfait/meta_class.rb +++ b/lib/parfait/meta_class.rb @@ -16,43 +16,43 @@ module Parfait class MetaClass < Object # no name, nor nothing. as this is just the object really - def initialize(object) - super() - self.functions = [] - self.me_self = object - end + # def initialize(object) + # super() + # self.functions = [] + # self.me_self = object + # end # in a non-booting version this should map to _add_singleton_method - def add_function function - raise "not a function #{function}" unless function.is_a? Virtual::Function - raise "syserr " unless function.name.is_a? Symbol - self.functions << function - end + # def add_function function + # raise "not a function #{function}" unless function.is_a? Virtual::Function + # raise "syserr " unless function.name.is_a? Symbol + # self.functions << function + # end - def get_function name - name = name.to_sym - f = self.functions.detect{ |f| f.name == name } - return f if f - if( self.me_self == "Object" ) - puts "no function for :#{name} in Meta #{self.me_self.inspect}" - return nil - else #recurse up class hierachy unless we're at Object - return self.me_self.context.object_space.get_class_by_name(self.me_self.super_class).get_function name - end - end + # def get_function name + # name = name.to_sym + # f = self.functions.detect{ |f| f.name == name } + # return f if f + # if( self.me_self == "Object" ) + # puts "no function for :#{name} in Meta #{self.me_self.inspect}" + # return nil + # else #recurse up class hierachy unless we're at Object + # return self.me_self.context.object_space.get_class_by_name(self.me_self.super_class).get_function name + # end + # end # get the function and if not found, try superclasses. raise error if not found - def resolve_method name - fun = get_function name - # TODO THE BOOK says is class A derives from B , then the metaclass of - # A derives from the metaclass of B - # just get to it ! (and stop whimpering) - raise "Method not found #{name} , for #{inspect}" unless fun - fun - end + # def resolve_method name + # fun = get_function name + # # TODO THE BOOK says is class A derives from B , then the metaclass of + # # A derives from the metaclass of B + # # just get to it ! (and stop whimpering) + # raise "Method not found #{name} , for #{inspect}" unless fun + # fun + # end - def to_s - "#{inspect} on #{self.me_self}, #{self.functions.length} functions" - end + # def to_s + # "#{inspect} on #{self.me_self}, #{self.functions.length} functions" + # end end end diff --git a/lib/register/builtin/integer.rb b/lib/register/builtin/integer.rb index adb57afe..ff9f2de3 100644 --- a/lib/register/builtin/integer.rb +++ b/lib/register/builtin/integer.rb @@ -14,19 +14,19 @@ module Register function.source.return_type = Virtual::Integer function.source.receiver = Virtual::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 ) - # 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 ) - cmp( number , 0 ) - callne( utoa_function ) - end - 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 ) + # # 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 ) + # cmp( number , 0 ) + # callne( utoa_function ) + # end + # return utoa_function end def putint context @@ -34,24 +34,24 @@ module Register putint_function.source.return_type = Virtual::Integer putint_function.source.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) - int = putint_function.receiver - moved_int = putint_function.new_local - utoa = context.object_space.get_class_by_name(:Object).resolve_method(:utoa) - putint_function.instance_eval do - mov( moved_int , int ) # move arg up - add( int , buffer ,nil ) # string to write to (add string address to pc) - add( int , int , buffer.length - 3) # 3 for good measure , ahem. - call( utoa ) - after = new_block("after_call") - insert_at after - # And now we "just" have to print it, using the write_stdout - add( int , buffer , nil ) # string to write to - mov( moved_int , buffer.length ) - end - Virtual::RegisterMachine.instance.write_stdout(putint_function) - putint_function + # buffer = Parfait::Word.new(" ") # create a buffer + # context.object_space.add_object buffer # and save it (function local variable: a no no) + # int = putint_function.receiver + # moved_int = putint_function.new_local + # utoa = context.object_space.get_class_by_name(:Object).resolve_method(:utoa) + # putint_function.instance_eval do + # mov( moved_int , int ) # move arg up + # add( int , buffer ,nil ) # string to write to (add string address to pc) + # add( int , int , buffer.length - 3) # 3 for good measure , ahem. + # call( utoa ) + # after = new_block("after_call") + # insert_at after + # # And now we "just" have to print it, using the write_stdout + # add( int , buffer , nil ) # string to write to + # mov( moved_int , buffer.length ) + # end + # Virtual::RegisterMachine.instance.write_stdout(putint_function) + # putint_function end # testing method, hand coded fibo, expects arg in receiver_register @@ -63,35 +63,35 @@ module Register fibo_function.source.return_type = Virtual::Integer fibo_function.source.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) - ble( last ) #branch to return, rather than return (as the original) - mov f1 , 1 #set up initial values - mov f2 , 0 - end - - loop = fibo_function.new_block("loop") - fibo_function.insert_at loop - - 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 - cmp int , 1 - bne( loop ) - mov( result , f1 ) - end - - 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) + # ble( last ) #branch to return, rather than return (as the original) + # mov f1 , 1 #set up initial values + # mov f2 , 0 + # end + # + # loop = fibo_function.new_block("loop") + # fibo_function.insert_at loop + # + # 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 + # cmp int , 1 + # bne( loop ) + # mov( result , f1 ) + # end + # + # fibo_function end end extend ClassMethods