2015-11-07 16:36:28 +01:00
|
|
|
require "ast/sexp"
|
|
|
|
|
2015-06-29 20:03:58 +02:00
|
|
|
module Register
|
|
|
|
module Builtin
|
|
|
|
class Object
|
|
|
|
module ClassMethods
|
2015-11-07 16:36:28 +01:00
|
|
|
include AST::Sexp
|
2015-05-04 22:03:52 +02:00
|
|
|
|
2015-11-07 16:36:28 +01:00
|
|
|
# self[index] basically. Index is the first arg
|
|
|
|
# return is stored in return_value
|
2015-11-08 16:10:36 +01:00
|
|
|
# (this method returns a new method off course, like all builtin)
|
2015-11-18 14:36:43 +01:00
|
|
|
def get_internal_word context
|
2016-12-08 14:25:20 +01:00
|
|
|
compiler = Typed::Compiler.new.create_method(:Object , :get_internal_word , {:index => :Integer}).init_method
|
2015-11-18 14:36:43 +01:00
|
|
|
source = "get_internal_word"
|
2015-11-07 16:36:28 +01:00
|
|
|
#Load self by "calling" on_name
|
2016-03-07 10:55:28 +01:00
|
|
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
2015-11-07 16:36:28 +01:00
|
|
|
# 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
|
|
|
|
|
2016-12-06 10:38:09 +01:00
|
|
|
# self[index] = val basically. Index is the first arg , value the second
|
2015-11-08 16:10:36 +01:00
|
|
|
# no return
|
2015-11-18 14:36:43 +01:00
|
|
|
def set_internal_word context
|
2016-12-08 14:25:20 +01:00
|
|
|
compiler = Typed::Compiler.new.create_method(:Object , :set_internal_word ,
|
2015-11-19 09:10:13 +01:00
|
|
|
{:index => :Integer, :value => :Object} ).init_method
|
2015-11-18 14:36:43 +01:00
|
|
|
source = "set_internal_word"
|
2015-11-08 16:10:36 +01:00
|
|
|
#Load self by "calling" on_name
|
2016-03-07 10:55:28 +01:00
|
|
|
me = compiler.process( Soml::NameExpression.new( :self) )
|
2015-11-08 16:10:36 +01:00
|
|
|
# Load the index
|
|
|
|
index = compiler.use_reg :Integer
|
|
|
|
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(1), index )
|
|
|
|
# Load the value
|
|
|
|
value = compiler.use_reg :Integer
|
|
|
|
compiler.add_code Register.get_slot(source , :message , Parfait::Message.get_indexed(2), value )
|
|
|
|
# do the set
|
|
|
|
compiler.add_code SetSlot.new( source , value , me , index)
|
|
|
|
return compiler.method
|
|
|
|
end
|
|
|
|
|
2014-06-03 13:49:02 +02:00
|
|
|
end
|
2015-06-29 20:03:58 +02:00
|
|
|
extend ClassMethods
|
2014-06-03 13:49:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|