redid get_set internal byte with builder

trying to change style, get rid of some of builders functions
This commit is contained in:
Torsten Ruger 2018-08-09 20:15:52 +03:00
parent 0d52b620ed
commit 7002956e81
2 changed files with 18 additions and 13 deletions

View File

@ -137,6 +137,7 @@ module Parfait
def range_correct_index( at )
index = at
# index = self.length + at if at < 0
raise "index not integer #{at.class}" unless at.is_a?(Fixnum)
raise "index must be positive , not #{at}" if (index < 0)
raise "index too large #{at} > #{self.length}" if (index >= self.length )
return index + 11

View File

@ -9,13 +9,14 @@ module Risc
# (this method returns a new method off course, like all builtin)
def get_internal_word( context )
compiler = compiler_for(:Object , :get_internal_word ,{at: :Integer})
builder = compiler.compiler_builder(compiler.source)
source = "get_internal_word"
me , index = builder.self_and_int_arg(source)
# reduce me to me[index]
builder.add_slot_to_reg( source , me , index , me)
# and put it back into the return value
builder.add_reg_to_slot( source , me , Risc.message_reg , :return_value)
compiler.compiler_builder(compiler.source).build do
object << message[:receiver]
integer << message[:arguments]
integer << integer_reg[1]
integer.reduce_int
object << object[integer]
message[:return_value] << object
end
compiler.add_mom( Mom::ReturnSequence.new)
return compiler
end
@ -24,12 +25,15 @@ module Risc
# no return
def set_internal_word( context )
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
source = "set_internal_word"
builder = compiler.compiler_builder(compiler.source)
me , index = builder.self_and_int_arg(source)
value = builder.load_int_arg_at(source , 1)
# do the set
builder.add_reg_to_slot( source , value , me , index)
compiler.compiler_builder(compiler.source).build do
object << message[:receiver]
integer << message[:arguments]
object_reg << integer[ 2]
integer << integer[ 1]
integer.reduce_int
object[integer] << object_reg
message[:return_value] << object_reg
end
compiler.add_mom( Mom::ReturnSequence.new)
return compiler
end