diff --git a/lib/register/boot.rb b/lib/register/boot.rb index a86587d5..adfa7912 100644 --- a/lib/register/boot.rb +++ b/lib/register/boot.rb @@ -144,7 +144,7 @@ module Register # have to define some dummies, just for the other to compile # TODO go through the virtual parfait layer and adjust function names to what they really are obj = @space.get_class_by_name(:Object) - [:main ].each do |f| + [:main , :get_internal ].each do |f| obj.add_instance_method Builtin::Object.send(f , nil) end obj = @space.get_class_by_name(:Kernel) diff --git a/lib/register/builtin/object.rb b/lib/register/builtin/object.rb index 59d2b37b..ca939aa2 100644 --- a/lib/register/builtin/object.rb +++ b/lib/register/builtin/object.rb @@ -1,7 +1,10 @@ +require "ast/sexp" + module Register module Builtin class Object module ClassMethods + include AST::Sexp # main entry point, ie __init__ calls this # defined here as empty, to be redefined @@ -10,6 +13,24 @@ module Register return compiler.method end + # self[index] basically. Index is the first arg + # return is stored in return_value + # (this method returns a new method off course, like all builting) + def get_internal context + compiler = Soml::Compiler.new.create_method(:Object , :get_internal , []).init_method + source = "get_internal" + #Load self by "calling" on_name + me = compiler.process( s(:name , :self) ) + # Load the argument + index = compiler.use_reg :Integer + compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index ) + # reduce me to me[index] + compiler.add_code GetSlot.new( source , me , index , me) + # and put it back into the return value + compiler.add_code Register.set_slot( source , me , :message , :return_value) + return compiler.method + end + end extend ClassMethods end