rename get/set internal

to _word , because _byte versions are coming
This commit is contained in:
Torsten Ruger 2015-11-18 15:36:43 +02:00
parent 633c1e9a4a
commit 5369dc3d52
13 changed files with 52 additions and 52 deletions

View File

@ -141,7 +141,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 , :get_internal , :set_internal ].each do |f|
[:main , :get_internal_word , :set_internal_word ].each do |f|
obj.add_instance_method Builtin::Object.send(f , nil)
end
obj = @space.get_class_by_name(:Kernel)

View File

@ -16,9 +16,9 @@ module Register
# self[index] basically. Index is the first arg
# return is stored in return_value
# (this method returns a new method off course, like all builtin)
def get_internal context
compiler = Soml::Compiler.new.create_method(:Object , :get_internal , {:Integer => :index}).init_method
source = "get_internal"
def get_internal_word context
compiler = Soml::Compiler.new.create_method(:Object , :get_internal_word , {:Integer => :index}).init_method
source = "get_internal_word"
#Load self by "calling" on_name
me = compiler.process( s(:name , :self) )
# Load the argument
@ -33,10 +33,10 @@ module Register
# self[index] = val basically. Index is the first arg , vlaue the second
# no return
def set_internal context
compiler = Soml::Compiler.new.create_method(:Object , :set_internal ,
def set_internal_word context
compiler = Soml::Compiler.new.create_method(:Object , :set_internal_word ,
{:Integer => :index, :Object => :value} ).init_method
source = "set_internal"
source = "set_internal_word"
#Load self by "calling" on_name
me = compiler.process( s(:name , :self) )
# Load the index

View File

@ -128,7 +128,7 @@ module Register
raise "Unsupported action, must convert symbol to word:#{object}"
end
else
value = object.get_internal( index )
value = object.get_internal_word( index )
end
#value = value.object_id unless value.is_a? Fixnum
set_register( @instruction.register , value )
@ -143,7 +143,7 @@ module Register
else
index = get_register(@instruction.index)
end
object.set_internal( index , value )
object.set_internal_word( index , value )
trigger(:object_changed, @instruction.array , index)
true
end
@ -161,7 +161,7 @@ module Register
def execute_FunctionReturn
object = get_register( @instruction.register )
link = object.get_internal( @instruction.index )
link = object.get_internal_word( @instruction.index )
@instruction = link
# we jump back to the call instruction. so it is as if the call never happened and we continue
true

View File

@ -154,7 +154,7 @@ module Parfait
end
define_method :get_length do
r = get_internal( offset ) #one for layout
r = get_internal_word( offset ) #one for layout
r.nil? ? 0 : r
end
@ -166,7 +166,7 @@ module Parfait
grow_to(index)
end
# start one higher than offset, which is where the length is
set_internal( index + offset, value)
set_internal_word( index + offset, value)
end
# set the value at index.
@ -176,7 +176,7 @@ module Parfait
ret = nil
if(index <= self.get_length)
# start one higher than offset, which is where the length is
ret = get_internal(index + offset )
ret = get_internal_word(index + offset )
end
ret
end
@ -187,14 +187,14 @@ module Parfait
return if old_length >= len
# raise "bounds error at #{len}" if( len + offset > 16 )
# be nice to use the indexed_length , but that relies on booted space
set_internal( offset , len) #one for layout
set_internal_word( offset , len) #one for layout
end
define_method :shrink_to do | len|
raise "Only positive lenths, #{len}" if len < 0
old_length = self.get_length
return if old_length <= len
set_internal( offset , len)
set_internal_word( offset , len)
end
end

View File

@ -74,8 +74,8 @@ module Parfait
raise "Use variable_index instead"
end
# index of the variable when using get_internal
# (get_internal is 1 based and 1 is always the layout)
# index of the variable when using get_internal_word
# (get_internal_word is 1 based and 1 is always the layout)
def variable_index name
has = super_index(name)
return nil unless has

View File

@ -41,11 +41,11 @@ module Parfait
end
# 1 -based index
def get_internal(index)
def get_internal_word(index)
@memory[index]
end
# 1 -based index
def set_internal(index , value)
def set_internal_word(index , value)
raise "failed init for #{self.class}" unless @memory
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
@memory[index] = value
@ -80,16 +80,16 @@ module Parfait
def set_layout(layout)
# puts "Layout was set for #{self.class}"
raise "Nil layout" unless layout
set_internal(LAYOUT_INDEX , layout)
set_internal_word(LAYOUT_INDEX , layout)
end
# so we can keep the raise in get_layout
def has_layout?
! get_internal(LAYOUT_INDEX).nil?
! get_internal_word(LAYOUT_INDEX).nil?
end
def get_layout()
l = get_internal(LAYOUT_INDEX)
l = get_internal_word(LAYOUT_INDEX)
#puts "get layout for #{self.class} returns #{l.class}"
raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
return l
@ -108,13 +108,13 @@ module Parfait
index = instance_variable_defined(name)
#puts "getting #{name} at #{index}"
return nil if index == nil
return get_internal(index)
return get_internal_word(index)
end
def set_instance_variable name , value
index = instance_variable_defined(name)
return nil if index == nil
return set_internal(index , value)
return set_internal_word(index , value)
end
def instance_variable_defined name

View File

@ -92,13 +92,13 @@ module Parfait
word_index = (index - 1) / 4 + 1 + Word.get_length_index
rest = ((index - 1) % 4)
shifted = char << (rest * 8)
was = get_internal( word_index )
was = get_internal_word( word_index )
was = 0 unless was.is_a?(Numeric)
mask = 0xFF << (rest * 8)
mask = 0xFFFFFFFF - mask
masked = was & mask
put = masked + shifted
set_internal( word_index , put )
set_internal_word( word_index , put )
msg = "set index=#{index} word_index=#{word_index} rest=#{rest}= "
msg += "char=#{char.to_s(16)} shifted=#{shifted.to_s(16)} "
msg += "was=#{was.to_s(16)} masked=#{masked.to_s(16)} put=#{put.to_s(16)}"
@ -114,7 +114,7 @@ module Parfait
index = range_correct_index(at)
word_index = (index - 1 ) / 4 + 1 + Word.get_length_index
rest = ((index - 1) % 4)
char = get_internal(word_index)
char = get_internal_word(word_index)
char = 0 unless char.is_a?(Numeric)
shifted = char >> (8 * rest)
ret = shifted & 0xFF

View File

@ -6,7 +6,7 @@ class Word < Object
word_index = word_index + 3
int rest = index - 1
rest = rest.mod4()
int char = get_internal(word_index)
int char = get_internal_word(word_index)
int shifted = 8 * rest
shifted = char >> shifted
int ret = shifted & 255
@ -14,7 +14,7 @@ class Word < Object
end
int set_length(int i)
set_internal( 2 , i)
set_internal_word( 2 , i)
return i
end
@ -32,7 +32,7 @@ class Word < Object
int shifted = rest * 8
shifted = char << shifted
int was = get_internal( word_index )
int was = get_internal_word( word_index )
int mask = rest * 8
int const = 255 << 8
const = const + 255
@ -47,7 +47,7 @@ class Word < Object
int masked = was & mask
int put = masked + shifted
set_internal( word_index , put )
set_internal_word( word_index , put )
return self
end

View File

@ -37,7 +37,7 @@ HERE
assert_equal Register::FunctionReturn , ret.class
object = @interpreter.get_register( ret.register )
link = object.get_internal( ret.index )
link = object.get_internal_word( ret.index )
assert_equal Register::Label , link.class
end

View File

@ -17,11 +17,11 @@ class TestLayout < MiniTest::Test
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
index = @mess.get_layout.variable_index :next_message
assert_equal 2 , index
assert_equal @mess.next_message , @mess.get_internal(index)
assert_equal @mess.next_message , @mess.get_internal_word(index)
end
def test_layout_index
assert_equal @mess.get_layout , @mess.get_internal(Parfait::LAYOUT_INDEX) , "mess"
assert_equal @mess.get_layout , @mess.get_internal_word(Parfait::LAYOUT_INDEX) , "mess"
end
def test_inspect
@ -38,7 +38,7 @@ class TestLayout < MiniTest::Test
def test_layout_length
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
assert_equal 18 , @mess.get_layout.get_internal(4)
assert_equal 18 , @mess.get_layout.get_internal_word(4)
end
def test_layout_length_index
@ -46,7 +46,7 @@ class TestLayout < MiniTest::Test
assert_equal 4 , @mess.get_layout.get_layout.get_offset
assert_equal 4 , @mess.get_layout.get_offset
assert_equal 8 , @mess.get_layout.get_layout.indexed_length
assert_equal 8 , @mess.get_layout.get_layout.get_internal(4)
assert_equal 8 , @mess.get_layout.get_layout.get_internal_word(4)
end
def test_layout_methods
@ -116,7 +116,7 @@ class TestLayout < MiniTest::Test
message_ind = Register.resolve_index( :message , :receiver )
assert_equal 3 , message_ind
@mess.receiver = 55
assert_equal 55 , @mess.get_internal(message_ind)
assert_equal 55 , @mess.get_internal_word(message_ind)
end
def test_object_layout
@ -125,6 +125,6 @@ class TestLayout < MiniTest::Test
def test_remove_me
layout = @mess.get_layout
assert_equal layout , @mess.get_internal(1)
assert_equal layout , @mess.get_internal_word(1)
end
end

View File

@ -48,7 +48,7 @@ class TestList < MiniTest::Test
@list.push :one
assert_equal 1 , @list.get_length
assert_equal 1 , @list.indexed_length
assert_equal 1 , @list.get_internal(Parfait::LAYOUT_INDEX + 1)
assert_equal 1 , @list.get_internal_word(Parfait::LAYOUT_INDEX + 1)
end
def test_list_inspect
@list.set(1,1)
@ -71,7 +71,7 @@ class TestList < MiniTest::Test
end
def test_one_set1
assert_equal 2 , @list.set(1,2)
assert_equal 1 , @list.get_internal(2)
assert_equal 1 , @list.get_internal_word(2)
end
def test_set1_len
@list.set(1,1)

View File

@ -29,11 +29,11 @@ class TestMessage < MiniTest::Test
end
def test_push3
@mess.push :name
assert_equal 1 , @mess.get_internal(9)
assert_equal 1 , @mess.get_internal_word(9)
end
def test_get_internal
def test_get_internal_word
@mess.push :name
assert_equal :name , @mess.get_internal(10)
assert_equal :name , @mess.get_internal_word(10)
end
def test_get

View File

@ -14,36 +14,36 @@ class TestObject < MiniTest::Test
end
def test_empty_object_doesnt_return
assert_equal nil , @object.get_internal(3)
assert_equal nil , @object.get_internal_word(3)
end
def test_one_set1
assert_equal 1 , @object.set_internal(1,1)
assert_equal 1 , @object.set_internal_word(1,1)
end
def test_one_set2
assert_equal :some , @object.set_internal(2,:some)
assert_equal :some , @object.set_internal_word(2,:some)
end
def test_two_sets
assert_equal 1 , @object.set_internal(1,1)
assert_equal :some , @object.set_internal(1,:some)
assert_equal 1 , @object.set_internal_word(1,1)
assert_equal :some , @object.set_internal_word(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 1 , @object.get_internal(1)
assert_equal 1 , @object.get_internal_word(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @object.get_internal(2)
assert_equal :some , @object.get_internal_word(2)
end
def test_many_get
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@object.set_internal(k,v)
@object.set_internal_word(k,v)
end
shouldda.each do |k,v|
assert_equal v , @object.get_internal(k)
assert_equal v , @object.get_internal_word(k)
end
end
end