2016-12-15 18:20:54 +01:00
|
|
|
require_relative "compile_helper"
|
2015-11-07 16:36:28 +01:00
|
|
|
|
2015-06-29 20:03:58 +02:00
|
|
|
module Register
|
|
|
|
module Builtin
|
|
|
|
class Object
|
|
|
|
module ClassMethods
|
2016-12-15 18:20:54 +01:00
|
|
|
include CompileHelper
|
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-15 18:31:39 +01:00
|
|
|
compiler = compiler_for(:Object , :get_internal_word )
|
2015-11-18 14:36:43 +01:00
|
|
|
source = "get_internal_word"
|
2016-12-21 21:35:36 +01:00
|
|
|
me , index = self_and_int_arg(compiler,source)
|
2015-11-07 16:36:28 +01:00
|
|
|
# reduce me to me[index]
|
2016-12-25 17:05:39 +01:00
|
|
|
compiler.add_code SlotToReg.new( source , me , index , me)
|
2015-11-07 16:36:28 +01:00
|
|
|
# and put it back into the return value
|
2016-12-25 17:02:39 +01:00
|
|
|
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
|
2015-11-07 16:36:28 +01:00
|
|
|
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-15 18:31:39 +01:00
|
|
|
compiler = compiler_for(:Object , :set_internal_word , {:value => :Object} )
|
2015-11-18 14:36:43 +01:00
|
|
|
source = "set_internal_word"
|
2016-12-21 21:35:36 +01:00
|
|
|
me , index = self_and_int_arg(compiler,source)
|
2016-12-27 19:34:11 +01:00
|
|
|
value = load_int_arg_at(compiler,source , 2)
|
2016-12-15 18:20:54 +01:00
|
|
|
|
2015-11-08 16:10:36 +01:00
|
|
|
# do the set
|
2016-12-25 17:02:39 +01:00
|
|
|
compiler.add_code RegToSlot.new( source , value , me , index)
|
2015-11-08 16:10:36 +01:00
|
|
|
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
|