removing the fake memory form object
just in word and list now
This commit is contained in:
parent
6214040888
commit
25f44949e4
@ -13,7 +13,11 @@ module Parfait
|
|||||||
module Indexed # marker module
|
module Indexed # marker module
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend(OffsetMethods)
|
base.extend(OffsetMethods)
|
||||||
base.attribute :indexed_length
|
end
|
||||||
|
|
||||||
|
def initialize( )
|
||||||
|
super()
|
||||||
|
@memory = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# include? means non nil index
|
# include? means non nil index
|
||||||
@ -165,6 +169,18 @@ module Parfait
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 1 -based index
|
||||||
|
def get_internal_word(index)
|
||||||
|
@memory[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
# 1 -based index
|
||||||
|
def set_internal_word(index , value)
|
||||||
|
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
||||||
|
@memory[index] = value
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
module OffsetMethods
|
module OffsetMethods
|
||||||
# generate all methods that depend on the (memory) offset
|
# generate all methods that depend on the (memory) offset
|
||||||
# These are get/set shrink_to/grow_to
|
# These are get/set shrink_to/grow_to
|
||||||
|
@ -17,6 +17,13 @@ module Parfait
|
|||||||
include Indexed
|
include Indexed
|
||||||
self.offset(1)
|
self.offset(1)
|
||||||
|
|
||||||
|
def self.attributes
|
||||||
|
[:indexed_length]
|
||||||
|
end
|
||||||
|
def indexed_length
|
||||||
|
get_length()
|
||||||
|
end
|
||||||
|
|
||||||
def initialize( )
|
def initialize( )
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
@ -21,7 +21,6 @@ module Parfait
|
|||||||
# At compile time we fake memory by using a global array for pages
|
# At compile time we fake memory by using a global array for pages
|
||||||
def self.new *args
|
def self.new *args
|
||||||
object = self.allocate
|
object = self.allocate
|
||||||
object.compile_time_init if object.respond_to?(:compile_time_init)
|
|
||||||
|
|
||||||
# have to grab the class, because we are in the ruby class not the parfait one
|
# have to grab the class, because we are in the ruby class not the parfait one
|
||||||
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym)
|
cl = Space.object_space.get_class_by_name( self.name.split("::").last.to_sym)
|
||||||
@ -36,33 +35,23 @@ module Parfait
|
|||||||
include Padding
|
include Padding
|
||||||
include Positioned
|
include Positioned
|
||||||
|
|
||||||
def compile_time_init
|
|
||||||
@memory = Array.new(16)
|
|
||||||
self # for chaining
|
|
||||||
end
|
|
||||||
|
|
||||||
# 1 -based index
|
# 1 -based index
|
||||||
def get_internal_word(index)
|
def get_internal_word(index)
|
||||||
@memory[index]
|
name = get_type().name_at(index)
|
||||||
|
return nil unless name
|
||||||
|
eval "@#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# 1 -based index
|
# 1 -based index
|
||||||
def set_internal_word(index , value)
|
def set_internal_word(index , value)
|
||||||
raise "failed init for #{self.class}" unless @memory
|
return set_type(value) if( index == 1)
|
||||||
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
|
raise "not type #{@type.class}" unless @type.is_a?(Type)
|
||||||
@memory[index] = value
|
name = @type.name_at(index)
|
||||||
|
raise "object type has no name at index #{index} " unless name
|
||||||
|
eval "@#{name} = value"
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.attributes names
|
|
||||||
names.each{|name| attribute(name) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.attribute name
|
|
||||||
define_method(name) { get_instance_variable(name) }
|
|
||||||
define_method("#{name}=".to_sym) { |value| set_instance_variable(name , value) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def == other
|
def == other
|
||||||
self.object_id == other.object_id
|
self.object_id == other.object_id
|
||||||
end
|
end
|
||||||
@ -81,20 +70,18 @@ module Parfait
|
|||||||
# private
|
# private
|
||||||
def set_type(type)
|
def set_type(type)
|
||||||
# puts "Type was set for #{self.class}"
|
# puts "Type was set for #{self.class}"
|
||||||
raise "Nil type" unless type
|
raise "not type #{type.class}" unless type.is_a?(Type)
|
||||||
set_internal_word(TYPE_INDEX , type)
|
@type = type
|
||||||
end
|
end
|
||||||
|
|
||||||
# so we can keep the raise in get_type
|
# so we can keep the raise in get_type
|
||||||
def has_type?
|
def has_type?
|
||||||
! get_internal_word(TYPE_INDEX).nil?
|
! @type.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_type()
|
def get_type()
|
||||||
l = get_internal_word(TYPE_INDEX)
|
raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless has_type?
|
||||||
#puts "get type for #{self.class} returns #{l.class}"
|
@type
|
||||||
raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless l
|
|
||||||
return l
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# return the metaclass
|
# return the metaclass
|
||||||
@ -103,28 +90,28 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_instance_variables
|
def get_instance_variables
|
||||||
get_type().instance_names
|
@type.names
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_instance_variable name
|
def get_instance_variable( name )
|
||||||
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_word(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_word(index , value)
|
return set_internal_word(index , value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_variable_defined name
|
def instance_variable_defined( name )
|
||||||
get_type().variable_index(name)
|
@type.variable_index(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def padded_length
|
def padded_length
|
||||||
padded_words( get_type().instance_length )
|
padded_words( @type.instance_length )
|
||||||
end
|
end
|
||||||
|
|
||||||
# parfait versions are deliberately called different, so we "relay"
|
# parfait versions are deliberately called different, so we "relay"
|
||||||
|
@ -13,7 +13,10 @@ module Parfait
|
|||||||
# Object length is measured in non-type cells though
|
# Object length is measured in non-type cells though
|
||||||
|
|
||||||
class Word < Object
|
class Word < Object
|
||||||
attribute :char_length
|
def self.attributes
|
||||||
|
[:char_length]
|
||||||
|
end
|
||||||
|
attr_reader :char_length
|
||||||
|
|
||||||
#semi "indexed" methods for interpreter
|
#semi "indexed" methods for interpreter
|
||||||
def self.get_length_index
|
def self.get_length_index
|
||||||
@ -27,13 +30,27 @@ module Parfait
|
|||||||
# Register provides methods to create Parfait objects from ruby
|
# Register provides methods to create Parfait objects from ruby
|
||||||
def initialize len
|
def initialize len
|
||||||
super()
|
super()
|
||||||
self.char_length = 0
|
@char_length = 0
|
||||||
|
@memory = []
|
||||||
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
|
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
|
||||||
raise "Must init with positive, not #{len}" if len < 0
|
raise "Must init with positive, not #{len}" if len < 0
|
||||||
set_length( len , 32 ) unless len == 0 #32 beeing ascii space
|
set_length( len , 32 ) unless len == 0 #32 beeing ascii space
|
||||||
#puts "type #{self.get_type} #{self.object_id.to_s(16)}"
|
#puts "type #{self.get_type} #{self.object_id.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 1 -based index
|
||||||
|
def get_internal_word(index)
|
||||||
|
@memory[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
# 1 -based index
|
||||||
|
def set_internal_word(index , value)
|
||||||
|
raise "Word[#{index}] = nil" if( value.nil? )
|
||||||
|
@memory[index] = value
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# return a copy of self
|
# return a copy of self
|
||||||
def copy
|
def copy
|
||||||
cop = Word.new( self.length )
|
cop = Word.new( self.length )
|
||||||
@ -47,7 +64,7 @@ module Parfait
|
|||||||
|
|
||||||
# return the number of characters
|
# return the number of characters
|
||||||
def length()
|
def length()
|
||||||
obj_len = self.char_length
|
obj_len = @char_length
|
||||||
return obj_len
|
return obj_len
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,9 +92,9 @@ module Parfait
|
|||||||
#
|
#
|
||||||
def set_length(len , fill_char)
|
def set_length(len , fill_char)
|
||||||
return if len <= 0
|
return if len <= 0
|
||||||
old = self.char_length
|
old = @char_length
|
||||||
return if old >= len
|
return if old >= len
|
||||||
self.char_length = len
|
@char_length = len
|
||||||
check_length
|
check_length
|
||||||
fill_from_with( old + 1 , fill_char )
|
fill_from_with( old + 1 , fill_char )
|
||||||
end
|
end
|
||||||
@ -168,7 +185,7 @@ module Parfait
|
|||||||
def to_string
|
def to_string
|
||||||
string = ""
|
string = ""
|
||||||
index = 1
|
index = 1
|
||||||
while( index <= self.char_length)
|
while( index <= @char_length)
|
||||||
char = get_char(index)
|
char = get_char(index)
|
||||||
string += char ? char.chr : "*"
|
string += char ? char.chr : "*"
|
||||||
index = index + 1
|
index = index + 1
|
||||||
@ -182,12 +199,12 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def padded_length
|
def padded_length
|
||||||
padded( 4 * get_type().instance_length + self.char_length )
|
padded( 4 * get_type().instance_length + @char_length )
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_length
|
def check_length
|
||||||
raise "Length out of bounds #{self.char_length}" if self.char_length > 1000
|
raise "Length out of bounds #{@char_length}" if @char_length > 1000
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user