rename get/set internal
to _word , because _byte versions are coming
This commit is contained in:
parent
633c1e9a4a
commit
5369dc3d52
@ -141,7 +141,7 @@ module Register
|
|||||||
# have to define some dummies, just for the other to compile
|
# 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
|
# TODO go through the virtual parfait layer and adjust function names to what they really are
|
||||||
obj = @space.get_class_by_name(:Object)
|
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)
|
obj.add_instance_method Builtin::Object.send(f , nil)
|
||||||
end
|
end
|
||||||
obj = @space.get_class_by_name(:Kernel)
|
obj = @space.get_class_by_name(:Kernel)
|
||||||
|
@ -16,9 +16,9 @@ module Register
|
|||||||
# self[index] basically. Index is the first arg
|
# self[index] basically. Index is the first arg
|
||||||
# return is stored in return_value
|
# return is stored in return_value
|
||||||
# (this method returns a new method off course, like all builtin)
|
# (this method returns a new method off course, like all builtin)
|
||||||
def get_internal context
|
def get_internal_word context
|
||||||
compiler = Soml::Compiler.new.create_method(:Object , :get_internal , {:Integer => :index}).init_method
|
compiler = Soml::Compiler.new.create_method(:Object , :get_internal_word , {:Integer => :index}).init_method
|
||||||
source = "get_internal"
|
source = "get_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
me = compiler.process( s(:name , :self) )
|
me = compiler.process( s(:name , :self) )
|
||||||
# Load the argument
|
# Load the argument
|
||||||
@ -33,10 +33,10 @@ module Register
|
|||||||
|
|
||||||
# self[index] = val basically. Index is the first arg , vlaue the second
|
# self[index] = val basically. Index is the first arg , vlaue the second
|
||||||
# no return
|
# no return
|
||||||
def set_internal context
|
def set_internal_word context
|
||||||
compiler = Soml::Compiler.new.create_method(:Object , :set_internal ,
|
compiler = Soml::Compiler.new.create_method(:Object , :set_internal_word ,
|
||||||
{:Integer => :index, :Object => :value} ).init_method
|
{:Integer => :index, :Object => :value} ).init_method
|
||||||
source = "set_internal"
|
source = "set_internal_word"
|
||||||
#Load self by "calling" on_name
|
#Load self by "calling" on_name
|
||||||
me = compiler.process( s(:name , :self) )
|
me = compiler.process( s(:name , :self) )
|
||||||
# Load the index
|
# Load the index
|
||||||
|
@ -128,7 +128,7 @@ module Register
|
|||||||
raise "Unsupported action, must convert symbol to word:#{object}"
|
raise "Unsupported action, must convert symbol to word:#{object}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
value = object.get_internal( index )
|
value = object.get_internal_word( index )
|
||||||
end
|
end
|
||||||
#value = value.object_id unless value.is_a? Fixnum
|
#value = value.object_id unless value.is_a? Fixnum
|
||||||
set_register( @instruction.register , value )
|
set_register( @instruction.register , value )
|
||||||
@ -143,7 +143,7 @@ module Register
|
|||||||
else
|
else
|
||||||
index = get_register(@instruction.index)
|
index = get_register(@instruction.index)
|
||||||
end
|
end
|
||||||
object.set_internal( index , value )
|
object.set_internal_word( index , value )
|
||||||
trigger(:object_changed, @instruction.array , index)
|
trigger(:object_changed, @instruction.array , index)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
@ -161,7 +161,7 @@ module Register
|
|||||||
|
|
||||||
def execute_FunctionReturn
|
def execute_FunctionReturn
|
||||||
object = get_register( @instruction.register )
|
object = get_register( @instruction.register )
|
||||||
link = object.get_internal( @instruction.index )
|
link = object.get_internal_word( @instruction.index )
|
||||||
@instruction = link
|
@instruction = link
|
||||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
||||||
true
|
true
|
||||||
|
@ -154,7 +154,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
define_method :get_length do
|
define_method :get_length do
|
||||||
r = get_internal( offset ) #one for layout
|
r = get_internal_word( offset ) #one for layout
|
||||||
r.nil? ? 0 : r
|
r.nil? ? 0 : r
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ module Parfait
|
|||||||
grow_to(index)
|
grow_to(index)
|
||||||
end
|
end
|
||||||
# start one higher than offset, which is where the length is
|
# start one higher than offset, which is where the length is
|
||||||
set_internal( index + offset, value)
|
set_internal_word( index + offset, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
# set the value at index.
|
# set the value at index.
|
||||||
@ -176,7 +176,7 @@ module Parfait
|
|||||||
ret = nil
|
ret = nil
|
||||||
if(index <= self.get_length)
|
if(index <= self.get_length)
|
||||||
# start one higher than offset, which is where the length is
|
# start one higher than offset, which is where the length is
|
||||||
ret = get_internal(index + offset )
|
ret = get_internal_word(index + offset )
|
||||||
end
|
end
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
@ -187,14 +187,14 @@ module Parfait
|
|||||||
return if old_length >= len
|
return if old_length >= len
|
||||||
# raise "bounds error at #{len}" if( len + offset > 16 )
|
# raise "bounds error at #{len}" if( len + offset > 16 )
|
||||||
# be nice to use the indexed_length , but that relies on booted space
|
# 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
|
end
|
||||||
|
|
||||||
define_method :shrink_to do | len|
|
define_method :shrink_to do | len|
|
||||||
raise "Only positive lenths, #{len}" if len < 0
|
raise "Only positive lenths, #{len}" if len < 0
|
||||||
old_length = self.get_length
|
old_length = self.get_length
|
||||||
return if old_length <= len
|
return if old_length <= len
|
||||||
set_internal( offset , len)
|
set_internal_word( offset , len)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -74,8 +74,8 @@ module Parfait
|
|||||||
raise "Use variable_index instead"
|
raise "Use variable_index instead"
|
||||||
end
|
end
|
||||||
|
|
||||||
# index of the variable when using get_internal
|
# index of the variable when using get_internal_word
|
||||||
# (get_internal is 1 based and 1 is always the layout)
|
# (get_internal_word is 1 based and 1 is always the layout)
|
||||||
def variable_index name
|
def variable_index name
|
||||||
has = super_index(name)
|
has = super_index(name)
|
||||||
return nil unless has
|
return nil unless has
|
||||||
|
@ -41,11 +41,11 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
# 1 -based index
|
# 1 -based index
|
||||||
def get_internal(index)
|
def get_internal_word(index)
|
||||||
@memory[index]
|
@memory[index]
|
||||||
end
|
end
|
||||||
# 1 -based index
|
# 1 -based index
|
||||||
def set_internal(index , value)
|
def set_internal_word(index , value)
|
||||||
raise "failed init for #{self.class}" unless @memory
|
raise "failed init for #{self.class}" unless @memory
|
||||||
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
||||||
@memory[index] = value
|
@memory[index] = value
|
||||||
@ -80,16 +80,16 @@ module Parfait
|
|||||||
def set_layout(layout)
|
def set_layout(layout)
|
||||||
# puts "Layout was set for #{self.class}"
|
# puts "Layout was set for #{self.class}"
|
||||||
raise "Nil layout" unless layout
|
raise "Nil layout" unless layout
|
||||||
set_internal(LAYOUT_INDEX , layout)
|
set_internal_word(LAYOUT_INDEX , layout)
|
||||||
end
|
end
|
||||||
|
|
||||||
# so we can keep the raise in get_layout
|
# so we can keep the raise in get_layout
|
||||||
def has_layout?
|
def has_layout?
|
||||||
! get_internal(LAYOUT_INDEX).nil?
|
! get_internal_word(LAYOUT_INDEX).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_layout()
|
def get_layout()
|
||||||
l = get_internal(LAYOUT_INDEX)
|
l = get_internal_word(LAYOUT_INDEX)
|
||||||
#puts "get layout for #{self.class} returns #{l.class}"
|
#puts "get layout for #{self.class} returns #{l.class}"
|
||||||
raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
|
raise "No layout #{self.object_id.to_s(16)}:#{self.class} " unless l
|
||||||
return l
|
return l
|
||||||
@ -108,13 +108,13 @@ module Parfait
|
|||||||
index = instance_variable_defined(name)
|
index = instance_variable_defined(name)
|
||||||
#puts "getting #{name} at #{index}"
|
#puts "getting #{name} at #{index}"
|
||||||
return nil if index == nil
|
return nil if index == nil
|
||||||
return get_internal(index)
|
return get_internal_word(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_instance_variable name , value
|
def set_instance_variable name , value
|
||||||
index = instance_variable_defined(name)
|
index = instance_variable_defined(name)
|
||||||
return nil if index == nil
|
return nil if index == nil
|
||||||
return set_internal(index , value)
|
return set_internal_word(index , value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_variable_defined name
|
def instance_variable_defined name
|
||||||
|
@ -92,13 +92,13 @@ module Parfait
|
|||||||
word_index = (index - 1) / 4 + 1 + Word.get_length_index
|
word_index = (index - 1) / 4 + 1 + Word.get_length_index
|
||||||
rest = ((index - 1) % 4)
|
rest = ((index - 1) % 4)
|
||||||
shifted = char << (rest * 8)
|
shifted = char << (rest * 8)
|
||||||
was = get_internal( word_index )
|
was = get_internal_word( word_index )
|
||||||
was = 0 unless was.is_a?(Numeric)
|
was = 0 unless was.is_a?(Numeric)
|
||||||
mask = 0xFF << (rest * 8)
|
mask = 0xFF << (rest * 8)
|
||||||
mask = 0xFFFFFFFF - mask
|
mask = 0xFFFFFFFF - mask
|
||||||
masked = was & mask
|
masked = was & mask
|
||||||
put = masked + shifted
|
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 = "set index=#{index} word_index=#{word_index} rest=#{rest}= "
|
||||||
msg += "char=#{char.to_s(16)} shifted=#{shifted.to_s(16)} "
|
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)}"
|
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)
|
index = range_correct_index(at)
|
||||||
word_index = (index - 1 ) / 4 + 1 + Word.get_length_index
|
word_index = (index - 1 ) / 4 + 1 + Word.get_length_index
|
||||||
rest = ((index - 1) % 4)
|
rest = ((index - 1) % 4)
|
||||||
char = get_internal(word_index)
|
char = get_internal_word(word_index)
|
||||||
char = 0 unless char.is_a?(Numeric)
|
char = 0 unless char.is_a?(Numeric)
|
||||||
shifted = char >> (8 * rest)
|
shifted = char >> (8 * rest)
|
||||||
ret = shifted & 0xFF
|
ret = shifted & 0xFF
|
||||||
|
@ -6,7 +6,7 @@ class Word < Object
|
|||||||
word_index = word_index + 3
|
word_index = word_index + 3
|
||||||
int rest = index - 1
|
int rest = index - 1
|
||||||
rest = rest.mod4()
|
rest = rest.mod4()
|
||||||
int char = get_internal(word_index)
|
int char = get_internal_word(word_index)
|
||||||
int shifted = 8 * rest
|
int shifted = 8 * rest
|
||||||
shifted = char >> shifted
|
shifted = char >> shifted
|
||||||
int ret = shifted & 255
|
int ret = shifted & 255
|
||||||
@ -14,7 +14,7 @@ class Word < Object
|
|||||||
end
|
end
|
||||||
|
|
||||||
int set_length(int i)
|
int set_length(int i)
|
||||||
set_internal( 2 , i)
|
set_internal_word( 2 , i)
|
||||||
return i
|
return i
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class Word < Object
|
|||||||
int shifted = rest * 8
|
int shifted = rest * 8
|
||||||
shifted = char << shifted
|
shifted = char << shifted
|
||||||
|
|
||||||
int was = get_internal( word_index )
|
int was = get_internal_word( word_index )
|
||||||
int mask = rest * 8
|
int mask = rest * 8
|
||||||
int const = 255 << 8
|
int const = 255 << 8
|
||||||
const = const + 255
|
const = const + 255
|
||||||
@ -47,7 +47,7 @@ class Word < Object
|
|||||||
int masked = was & mask
|
int masked = was & mask
|
||||||
int put = masked + shifted
|
int put = masked + shifted
|
||||||
|
|
||||||
set_internal( word_index , put )
|
set_internal_word( word_index , put )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ HERE
|
|||||||
assert_equal Register::FunctionReturn , ret.class
|
assert_equal Register::FunctionReturn , ret.class
|
||||||
|
|
||||||
object = @interpreter.get_register( ret.register )
|
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
|
assert_equal Register::Label , link.class
|
||||||
end
|
end
|
||||||
|
@ -17,11 +17,11 @@ class TestLayout < MiniTest::Test
|
|||||||
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
|
||||||
index = @mess.get_layout.variable_index :next_message
|
index = @mess.get_layout.variable_index :next_message
|
||||||
assert_equal 2 , index
|
assert_equal 2 , index
|
||||||
assert_equal @mess.next_message , @mess.get_internal(index)
|
assert_equal @mess.next_message , @mess.get_internal_word(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_layout_index
|
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
|
end
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
@ -38,7 +38,7 @@ class TestLayout < MiniTest::Test
|
|||||||
|
|
||||||
def test_layout_length
|
def test_layout_length
|
||||||
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
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
|
end
|
||||||
|
|
||||||
def test_layout_length_index
|
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_layout.get_offset
|
||||||
assert_equal 4 , @mess.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.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
|
end
|
||||||
|
|
||||||
def test_layout_methods
|
def test_layout_methods
|
||||||
@ -116,7 +116,7 @@ class TestLayout < MiniTest::Test
|
|||||||
message_ind = Register.resolve_index( :message , :receiver )
|
message_ind = Register.resolve_index( :message , :receiver )
|
||||||
assert_equal 3 , message_ind
|
assert_equal 3 , message_ind
|
||||||
@mess.receiver = 55
|
@mess.receiver = 55
|
||||||
assert_equal 55 , @mess.get_internal(message_ind)
|
assert_equal 55 , @mess.get_internal_word(message_ind)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_layout
|
def test_object_layout
|
||||||
@ -125,6 +125,6 @@ class TestLayout < MiniTest::Test
|
|||||||
|
|
||||||
def test_remove_me
|
def test_remove_me
|
||||||
layout = @mess.get_layout
|
layout = @mess.get_layout
|
||||||
assert_equal layout , @mess.get_internal(1)
|
assert_equal layout , @mess.get_internal_word(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ class TestList < MiniTest::Test
|
|||||||
@list.push :one
|
@list.push :one
|
||||||
assert_equal 1 , @list.get_length
|
assert_equal 1 , @list.get_length
|
||||||
assert_equal 1 , @list.indexed_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
|
end
|
||||||
def test_list_inspect
|
def test_list_inspect
|
||||||
@list.set(1,1)
|
@list.set(1,1)
|
||||||
@ -71,7 +71,7 @@ class TestList < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_one_set1
|
def test_one_set1
|
||||||
assert_equal 2 , @list.set(1,2)
|
assert_equal 2 , @list.set(1,2)
|
||||||
assert_equal 1 , @list.get_internal(2)
|
assert_equal 1 , @list.get_internal_word(2)
|
||||||
end
|
end
|
||||||
def test_set1_len
|
def test_set1_len
|
||||||
@list.set(1,1)
|
@list.set(1,1)
|
||||||
|
@ -29,11 +29,11 @@ class TestMessage < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_push3
|
def test_push3
|
||||||
@mess.push :name
|
@mess.push :name
|
||||||
assert_equal 1 , @mess.get_internal(9)
|
assert_equal 1 , @mess.get_internal_word(9)
|
||||||
end
|
end
|
||||||
def test_get_internal
|
def test_get_internal_word
|
||||||
@mess.push :name
|
@mess.push :name
|
||||||
assert_equal :name , @mess.get_internal(10)
|
assert_equal :name , @mess.get_internal_word(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get
|
def test_get
|
||||||
|
@ -14,36 +14,36 @@ class TestObject < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_empty_object_doesnt_return
|
def test_empty_object_doesnt_return
|
||||||
assert_equal nil , @object.get_internal(3)
|
assert_equal nil , @object.get_internal_word(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_one_set1
|
def test_one_set1
|
||||||
assert_equal 1 , @object.set_internal(1,1)
|
assert_equal 1 , @object.set_internal_word(1,1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_one_set2
|
def test_one_set2
|
||||||
assert_equal :some , @object.set_internal(2,:some)
|
assert_equal :some , @object.set_internal_word(2,:some)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_two_sets
|
def test_two_sets
|
||||||
assert_equal 1 , @object.set_internal(1,1)
|
assert_equal 1 , @object.set_internal_word(1,1)
|
||||||
assert_equal :some , @object.set_internal(1,:some)
|
assert_equal :some , @object.set_internal_word(1,:some)
|
||||||
end
|
end
|
||||||
def test_one_get1
|
def test_one_get1
|
||||||
test_one_set1
|
test_one_set1
|
||||||
assert_equal 1 , @object.get_internal(1)
|
assert_equal 1 , @object.get_internal_word(1)
|
||||||
end
|
end
|
||||||
def test_one_get2
|
def test_one_get2
|
||||||
test_one_set2
|
test_one_set2
|
||||||
assert_equal :some , @object.get_internal(2)
|
assert_equal :some , @object.get_internal_word(2)
|
||||||
end
|
end
|
||||||
def test_many_get
|
def test_many_get
|
||||||
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
||||||
shouldda.each do |k,v|
|
shouldda.each do |k,v|
|
||||||
@object.set_internal(k,v)
|
@object.set_internal_word(k,v)
|
||||||
end
|
end
|
||||||
shouldda.each do |k,v|
|
shouldda.each do |k,v|
|
||||||
assert_equal v , @object.get_internal(k)
|
assert_equal v , @object.get_internal_word(k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user