finally change List to derive from data object
can’t derive from data16 as some lists are longer have to get the delegation to work first
This commit is contained in:
parent
f9a89db10c
commit
8ef1a471a4
@ -30,8 +30,8 @@ module Parfait
|
||||
def data_length
|
||||
raise "called #{self}"
|
||||
end
|
||||
def data_start
|
||||
return get_type.get_length
|
||||
def self.type_length
|
||||
raise "called #{self}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -69,4 +69,9 @@ module Parfait
|
||||
16 * 4
|
||||
end
|
||||
end
|
||||
class Data32 < DataObject
|
||||
def self.memory_size
|
||||
32
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,22 +12,18 @@
|
||||
# so all incoming/outgoing indexes have to be shifted one up/down
|
||||
|
||||
module Parfait
|
||||
class List < Object
|
||||
class List < Data32
|
||||
attr_reader :indexed_length
|
||||
|
||||
def self.type_length
|
||||
2 # 0 type , 1 length
|
||||
end
|
||||
def self.get_length_index
|
||||
return 2
|
||||
end
|
||||
def self.get_indexed(index)
|
||||
return index + 2
|
||||
end
|
||||
def length_index
|
||||
1
|
||||
end
|
||||
def get_offset
|
||||
return 2
|
||||
type_length - 1
|
||||
end
|
||||
|
||||
def get_length
|
||||
r = get_internal_word( length_index ) #one for type
|
||||
r = @indexed_length
|
||||
r.nil? ? 0 : r
|
||||
end
|
||||
|
||||
@ -39,7 +35,7 @@ module Parfait
|
||||
grow_to(index + 1)
|
||||
end
|
||||
# start one higher than offset, which is where the length is
|
||||
set_internal_word( index + get_offset, value)
|
||||
set_internal_word( index + self.class.type_length, value)
|
||||
end
|
||||
|
||||
# set the value at index.
|
||||
@ -49,36 +45,30 @@ module Parfait
|
||||
ret = nil
|
||||
if(index < get_length)
|
||||
# start one higher than offset, which is where the length is
|
||||
ret = get_internal_word(index + get_offset )
|
||||
ret = get_internal_word(index + self.class.type_length )
|
||||
end
|
||||
ret
|
||||
end
|
||||
alias :[] :get
|
||||
|
||||
def grow_to( len )
|
||||
raise "Only positive lenths, #{len}" if len < 0
|
||||
old_length = get_length
|
||||
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_word( length_index , len) #one for type
|
||||
internal_set_length( len)
|
||||
end
|
||||
|
||||
def shrink_to( len )
|
||||
raise "Only positive lenths, #{len}" if len < 0
|
||||
old_length = get_length
|
||||
return if old_length <= len
|
||||
set_internal_word( length_index , len)
|
||||
internal_set_length( len)
|
||||
end
|
||||
|
||||
def indexed_length
|
||||
get_length()
|
||||
end
|
||||
|
||||
def initialize( )
|
||||
super()
|
||||
@memory = []
|
||||
end
|
||||
|
||||
# include? means non nil index
|
||||
def include?( item )
|
||||
return index_of(item) != nil
|
||||
@ -236,20 +226,6 @@ module Parfait
|
||||
ret
|
||||
end
|
||||
|
||||
# 0 -based index
|
||||
def get_internal_word(index)
|
||||
@memory[index]
|
||||
end
|
||||
|
||||
# 0 -based index
|
||||
def set_internal_word(index , value)
|
||||
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
||||
@memory[index] = value
|
||||
value
|
||||
end
|
||||
|
||||
alias :[] :get
|
||||
|
||||
def to_rxf_node(writer , level , ref )
|
||||
Sof.array_to_rxf_node(self , writer , level , ref )
|
||||
end
|
||||
@ -271,6 +247,10 @@ module Parfait
|
||||
end
|
||||
array
|
||||
end
|
||||
private
|
||||
def internal_set_length( i )
|
||||
@indexed_length = i
|
||||
end
|
||||
end
|
||||
|
||||
# new list from ruby array to be precise
|
||||
@ -284,5 +264,4 @@ module Parfait
|
||||
end
|
||||
list
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -192,6 +192,7 @@ module Parfait
|
||||
end
|
||||
|
||||
def name_at( index )
|
||||
raise "No names #{index}" unless @names
|
||||
@names.get(index)
|
||||
end
|
||||
|
||||
|
@ -15,15 +15,11 @@ module Parfait
|
||||
class Word < Data8
|
||||
attr_reader :char_length
|
||||
|
||||
#semi "indexed" methods for interpreter
|
||||
def self.get_length_index
|
||||
2 # 2 is the amount of attributes, type and char_length. the offset after which chars start
|
||||
end
|
||||
def self.type_length
|
||||
2 # 0 type , 1 char_length
|
||||
end
|
||||
def self.get_indexed( i )
|
||||
i + get_length_index * 4
|
||||
def self.get_length_index
|
||||
type_length - 1
|
||||
end
|
||||
# initialize with length. For now we try to keep all non-parfait (including String) out
|
||||
# String will contain spaces for non-zero length
|
||||
|
@ -119,7 +119,7 @@ module Risc
|
||||
def super_class_names
|
||||
{ Data4: :DataObject , Data8: :DataObject ,Data16: :DataObject ,
|
||||
BinaryCode: :Data16 , Integer: :Data4, Word: :Data8 ,
|
||||
Object: :BasicObject}
|
||||
Object: :BasicObject , List: :Data16}
|
||||
end
|
||||
|
||||
# the function really just returns a constant (just avoiding the constant)
|
||||
|
@ -11,14 +11,14 @@ module Parfait
|
||||
|
||||
# 0 -based index
|
||||
def get_internal_word(index)
|
||||
return super if index < data_start
|
||||
return super if index < self.class.type_length
|
||||
@memory[index]
|
||||
end
|
||||
|
||||
# 1 -based index
|
||||
def set_internal_word(index , value)
|
||||
return super if index < data_start
|
||||
raise "Word[#{index}] = nil" if( value.nil? )
|
||||
return super if index < self.class.type_length
|
||||
raise "Word[#{index}] = nil" if( value.nil? and self.class != List)
|
||||
@memory[index] = value
|
||||
value
|
||||
end
|
||||
|
@ -29,7 +29,7 @@ module Parfait
|
||||
assert_equal 0, @list.indexed_length
|
||||
end
|
||||
def test_offset
|
||||
assert_equal 2 , @list.get_offset
|
||||
assert_equal 2 , @list.class.type_length
|
||||
end
|
||||
def test_indexed_index
|
||||
# 0 type , 1 indexed_length
|
||||
|
Loading…
Reference in New Issue
Block a user