diff --git a/lib/parfait/behaviour.rb b/lib/parfait/behaviour.rb index 15029f79..4f979a0d 100644 --- a/lib/parfait/behaviour.rb +++ b/lib/parfait/behaviour.rb @@ -7,13 +7,13 @@ module Parfait def initialize super() - @instance_methods = List.new + instance_methods = List.new end def methods - m = @instance_methods + m = instance_methods return m if m - @instance_methods = List.new + instance_methods = List.new end def method_names @@ -45,7 +45,7 @@ module Parfait raise "resolve_method #{m_name}.#{m_name.class}" unless m_name.is_a?(Symbol) method = get_instance_method(m_name) return method if method - if( @super_class_name != :Object ) + if( super_class_name != :Object ) method = self.super_class.resolve_method(m_name) end method diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index 3c865d81..947d8638 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -7,7 +7,7 @@ module Parfait # and as the last code of each link is a jump to the next link. # class BinaryCode < Data16 - attr_reader :next + attr :type, :next_code def self.type_length 2 #type + next (could get from space, maybe later) @@ -27,35 +27,36 @@ module Parfait def initialize(total_size) super() + self.next_code = nil extend_to(total_size ) (0 ... data_length).each{ |index| set_word(index , 0) } set_last(0) end def extend_to(total_size) return if total_size < data_length - extend_one() unless @next - @next.extend_to(total_size - data_length) + extend_one() unless next_code + next_code.extend_to(total_size - data_length) end def extend_one() - @next = BinaryCode.new(1) + self.next_code = BinaryCode.new(1) Risc::Position.get(self).trigger_inserted if Risc::Position.set?(self) end def ensure_next - extend_one unless @next - @next + extend_one unless next_code + next_code end def last_code last = self - last = last.next while(last.next) + last = last.next_code while(last.next_code) last end def each_block( &block ) block.call( self ) - @next.each_block( &block ) if @next + next_code.each_block( &block ) if next_code end def to_s @@ -74,9 +75,9 @@ module Parfait def set_word(index , word) raise "invalid index #{index}" if index < 0 if index >= data_length - #raise "invalid index #{index}" unless @next + #raise "invalid index #{index}" unless next extend_to( index ) - @next.set_word( index - data_length , word) + next_code.set_word( index - data_length , word) else set_internal_word(index + BinaryCode.type_length , word) end @@ -90,15 +91,15 @@ module Parfait def get_word(index) raise "invalid index #{index}" if index < 0 if index >= data_length - raise "invalid index #{index}" unless @next - return @next.get_word( index - data_length) + raise "invalid index #{index}" unless next_code + return next_code.get_word( index - data_length) end get_internal_word(index + BinaryCode.type_length) end def set_char(index , char) if index >= byte_length - #puts "Pass it on #{index} for #{self.object_id}:#{@next.object_id}" - return @next.set_char( index - byte_length , char ) + #puts "Pass it on #{index} for #{self.object_id}:#{next_code.object_id}" + return next_code.set_char( index - byte_length , char ) end word_index = (index - 1) / 4 + 2 old = get_internal_word( word_index ) @@ -107,8 +108,8 @@ module Parfait end def total_byte_length(start = 0 ) start += self.byte_length - return start unless self.next - self.next.total_byte_length(start) + return start unless self.next_code + self.next_code.total_byte_length(start) end end end diff --git a/lib/parfait/block.rb b/lib/parfait/block.rb index 4c2a3a2d..dfcd8b7c 100644 --- a/lib/parfait/block.rb +++ b/lib/parfait/block.rb @@ -16,7 +16,7 @@ module Parfait end def inspect - "#{@self_type.object_class.name}(#{arguments_type.inspect})" + "#{self_type.object_class.name}(#{arguments_type.inspect})" end end end diff --git a/lib/parfait/cache_entry.rb b/lib/parfait/cache_entry.rb index 19c76bf8..b68acc6d 100644 --- a/lib/parfait/cache_entry.rb +++ b/lib/parfait/cache_entry.rb @@ -8,12 +8,11 @@ module Parfait class CacheEntry < Object - attr :cached_type - attr :cached_method + attr :type, :cached_type, :cached_method def initialize(type , method) - @cached_type = type - @cached_method = method + self.cached_type = type + self.cached_method = method end def to_s diff --git a/lib/parfait/callable.rb b/lib/parfait/callable.rb index 1bd039ef..95dbcc71 100644 --- a/lib/parfait/callable.rb +++ b/lib/parfait/callable.rb @@ -8,34 +8,39 @@ module Parfait # - frame_type: A type object describing the local variables that the method has # - binary: The binary (jumpable) code that instructions get assembled into # - blocks: linked list of blocks inside this method/block - # - next: next block/method at same level + # - next_callable: next block/method at same level # class Callable < Object - attr_reader :self_type , :arguments_type , :frame_type , :binary - attr_reader :blocks, :next , :name - + attr :type, :self_type , :arguments_type , :frame_type , :binary + attr :blocks , :name + attr :next_callable + + def self.type_length + 8 + end + def initialize( name , self_type , arguments_type , frame_type) super() raise "No class #{self}" unless self_type raise "For type, not class #{self_type}" unless self_type.is_a?(Type) raise "Mixup" unless name.is_a?(Symbol) - @name = name - @self_type = self_type + self.name = name + self.self_type = self_type init(arguments_type, frame_type) end def ==(other) - @self_type == other.self_type + self_type == other.self_type end # (re) init with given args and frame types def init(arguments_type, frame_type) raise "Wrong argument type, expect Type not #{arguments_type.class}" unless arguments_type.is_a? Type raise "Wrong frame type, expect Type not #{frame_type.class}" unless frame_type.is_a? Type - @arguments_type = arguments_type - @frame_type = frame_type - @binary = BinaryCode.new(0) + self.arguments_type = arguments_type + self.frame_type = frame_type + self.binary = BinaryCode.new(0) end # determine if method has a local variable or tmp (anonymous local) by given name @@ -47,19 +52,19 @@ module Parfait def add_local( name , type ) index = has_local( name ) return index if index - @frame_type = @frame_type.add_instance_variable(name,type) + self.frame_type = frame_type.add_instance_variable(name,type) end def each_binary( &block ) bin = binary while(bin) do block.call( bin ) - bin = bin.next + bin = bin.next_callable end end def set_next( method ) - @next = method + self.next_callable = method end end diff --git a/lib/parfait/callable_method.rb b/lib/parfait/callable_method.rb index 00d4cc1f..5d76d1bd 100644 --- a/lib/parfait/callable_method.rb +++ b/lib/parfait/callable_method.rb @@ -14,32 +14,32 @@ module Parfait def ==(other) return false unless other.is_a?(CallableMethod) - return false if @name != other.name + return false if name != other.name super end def rxf_reference_name - "Method: " + @name.to_s + "Method: " + name.to_s end def inspect - "#{@self_type.object_class.name}:#{name}(#{arguments_type.inspect})" + "#{self_type.object_class.name}:#{name}(#{arguments_type.inspect})" end def each_method( &block ) block.call( self ) - @next.each_method( &block ) if @next + next_callable.each_method( &block ) if next_callable end def create_block(args , frame) - block_name = "#{@name}_block".to_sym #TODO with id, to distinguish + block_name = "#{name}_block".to_sym #TODO with id, to distinguish add_block( Block.new(block_name , self_type , args , frame)) end def add_block(bl) - was = @blocks + was = blocks bl.set_next(was) if(was) - @blocks = bl + self.blocks = bl end def has_block(block) @@ -50,7 +50,7 @@ module Parfait blo = blocks while( blo ) yield(blo) - blo = blo.next + blo = blo.next_callable end end end diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 1aea5417..8a76c8e1 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -18,13 +18,17 @@ module Parfait class Class < Object include Behaviour - attr_reader :instance_type , :name , :instance_methods , :super_class_name + attr :type, :instance_type , :name , :instance_methods , :super_class_name + + def self.type_length + 5 + end def initialize( name , superclass , instance_type) super() - @name = name - @super_class_name = superclass - @instance_methods = List.new + self.name = name + self.super_class_name = superclass + self.instance_methods = List.new set_instance_type( instance_type ) end @@ -44,32 +48,32 @@ module Parfait def add_method(method) raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod - @instance_methods.push(method) + instance_methods.push(method) end def get_method(name) - @instance_methods.find{|m| m.name == name } + instance_methods.find{|m| m.name == name } end # adding an instance changes the instance_type to include that variable def add_instance_variable( name , type) - @instance_type = @instance_type.add_instance_variable( name , type ) + self.instance_type = instance_type.add_instance_variable( name , type ) end # setting the type generates all methods for this type # (or will do, once we store the methods code to do that) def set_instance_type( type ) raise "type must be type #{type}" unless type.is_a?(Type) - @instance_type = type + self.instance_type = type end # return the super class, but raise exception if either the super class name # or the super classs is nil. # Use only for non Object base class def super_class! - raise "No super_class for class #{@name}" unless @super_class_name + raise "No super_class for class #{name}" unless super_class_name s = super_class - raise "superclass not found for class #{@name} (#{@super_class_name})" unless s + raise "superclass not found for class #{name} (#{super_class_name})" unless s s end @@ -77,8 +81,8 @@ module Parfait # we only store the name, and so have to resolve. # Nil name means no superclass, and so nil is a valid return value def super_class - return nil unless @super_class_name - Parfait.object_space.get_class_by_name(@super_class_name) + return nil unless super_class_name + Parfait.object_space.get_class_by_name(super_class_name) end # ruby 2.1 list (just for reference, keep at bottom) diff --git a/lib/parfait/data_object.rb b/lib/parfait/data_object.rb index c497baf7..8c61c6a5 100644 --- a/lib/parfait/data_object.rb +++ b/lib/parfait/data_object.rb @@ -21,9 +21,7 @@ # A marker class module Parfait class DataObject < Object - def initialize - super - end + def self.integer_index type_length end diff --git a/lib/parfait/dictionary.rb b/lib/parfait/dictionary.rb index ab1c085e..4c874e7f 100644 --- a/lib/parfait/dictionary.rb +++ b/lib/parfait/dictionary.rb @@ -3,35 +3,41 @@ module Parfait class Dictionary < Object + attr :type, :i_keys , :i_values + + def self.type_length + 3 + end + # only empty initialization for now # # internally we store keys and values in lists, which means this does **not** scale well def initialize super() - @keys = List.new() - @values = List.new() + self.i_keys = List.new() + self.i_values = List.new() end def keys - @keys.dup + i_keys.dup end def values - @values.dup + i_values.dup end # are there any key/value items in the list def empty? - @keys.empty? + i_keys.empty? end # How many key/value pairs there are def length() - return @keys.get_length() + return i_keys.get_length() end def next_value(val) - return @values.next_value(val) + return i_values.next_value(val) end # get a value fot the given key @@ -40,7 +46,7 @@ module Parfait def get(key) index = key_index(key) if( index ) - @values.get(index) + i_values.get(index) else nil end @@ -53,17 +59,17 @@ module Parfait # private method def key_index(key) - @keys.index_of(key) + i_keys.index_of(key) end # set key with value, returns value def set(key , value) index = key_index(key) if( index ) - @values.set(index , value) + i_values.set(index , value) else - @keys.push(key) - @values.push(value) + i_keys.push(key) + i_values.push(value) end value end @@ -76,9 +82,9 @@ module Parfait # yield to each key value pair def each index = 0 - while index < @keys.get_length - key = @keys.get(index) - value = @values.get(index) + while index < i_keys.get_length + key = i_keys.get(index) + value = i_values.get(index) yield key , value index = index + 1 end diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 595c92c7..56b332c3 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -9,12 +9,13 @@ module Parfait class Integer < Data4 + attr :type, :next_integer + def initialize(value , next_i = nil) super() - @next_integer = next_i + self.next_integer = next_i set_internal_word(Integer.integer_index, value) end - attr_reader :next_integer def value get_internal_word(Integer.integer_index) @@ -28,7 +29,7 @@ module Parfait end def to_s - "Integer #{@value}" + "Integer #{value}" end # compile time method to set the actual value. # this should not really be part of parfait, as ints are immutable at runtime. @@ -38,12 +39,12 @@ module Parfait # :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, # :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, - # :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude, + # :singleton_method_added, :coerce, :i, :+, :-, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude, # :real?, :zero?, :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, # :rectangular, :rect, :polar, :conjugate, :conj, :>, :>=, :<, :<=, :between? # # Numeric - # :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude, + # :singleton_method_added, :coerce, :i, :+, :-, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude, # :to_int, :real?, :integer?, :zero?, :nonzero?, :floor, :ceil, :round, :truncate, :step, :numerator, :denominator, # :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj, # :>, :>=, :<, :<=, :between? diff --git a/lib/parfait/list.rb b/lib/parfait/list.rb index 9288a09a..0a692c76 100644 --- a/lib/parfait/list.rb +++ b/lib/parfait/list.rb @@ -7,29 +7,31 @@ module Parfait class List < Data16 - attr_reader :indexed_length , :next + attr :type, :indexed_length , :next_list def self.type_length 3 # 0 type , 1 length , 2 - next_list end - def self.get_length_index - 1 - end def self.data_length - self.memory_size - self.type_length - 1 #one for the jump + self.memory_size - self.type_length - 1 end + + def initialize + super + self.indexed_length = 0 + end + def data_length self.class.data_length end - def get_length - r = @indexed_length + r = indexed_length r.nil? ? 0 : r end def ensure_next - @next = List.new unless @next - @next + self.next_list = List.new unless next_list + self.next_list end # set the value at index. @@ -41,7 +43,7 @@ module Parfait end if index >= data_length ensure_next - @next.set( index - data_length , value) + next_list.set( index - data_length , value) else set_internal_word( index + self.class.type_length, value) end @@ -52,8 +54,8 @@ module Parfait def get( index ) raise "Only positive indexes, #{index}" if index < 0 if index >= data_length - return nil unless @next - return @next.get( index - data_length) + return nil unless next_list + return next_list.get( index - data_length) else ret = nil if(index < get_length) @@ -78,9 +80,9 @@ module Parfait internal_set_length( len) end - def indexed_length - get_length() - end + # def indexed_length + # get_length() + # end # include? means non nil index def include?( item ) @@ -262,7 +264,7 @@ module Parfait end private def internal_set_length( i ) - @indexed_length = i + self.indexed_length = i end end diff --git a/lib/parfait/message.rb b/lib/parfait/message.rb index 4ed82eea..33b98274 100644 --- a/lib/parfait/message.rb +++ b/lib/parfait/message.rb @@ -15,28 +15,35 @@ module Parfait # :return_address => :Integer, :return_value => :Integer, # :caller => :Message , :name => :Word , :arguments => :NamedList - attr_accessor :next_message - attr_reader :receiver , :frame - attr_reader :return_address, :return_value - attr_reader :caller , :method , :arguments + attr :type, :next_message + attr :receiver , :frame + attr :return_address, :return_value + attr :caller , :method , :arguments + + def self.type_length + 9 + end + def self.memory_size + 16 + end def initialize( next_m ) - @next_message = next_m - @frame = NamedList.new() - @arguments = NamedList.new() super() + self.next_message = next_m + self.frame = NamedList.new() + self.arguments = NamedList.new() end def set_receiver(rec) - @receiver = rec + self.receiver = rec end def set_caller(caller) - @caller = caller + caller = caller end def get_type_for(name) - index = @type.get_index(name) + index = type.get_index(name) get_at(index) end def to_s diff --git a/lib/parfait/named_list.rb b/lib/parfait/named_list.rb index ade4b17b..ad0bf936 100644 --- a/lib/parfait/named_list.rb +++ b/lib/parfait/named_list.rb @@ -23,6 +23,8 @@ module Parfait class NamedList < Object + attr :type + def to_s str = "NamedList len= #{get_length}" str += " at #{Risc::Position.get(self)}" if Risc::Position.set?(self) diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 9c3beba5..9c1b5c78 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -6,7 +6,7 @@ # word (instance of class Type). # Objects are arranged or layed out (in memory) according to their Type -# every object has a Type. Type objects are immutalbe and may be reused for a group/class +# every object has a Type. Type objects are immutable and may be reused for a group/class # of objects. # The Type of an object may change, but then a new Type is created # The Type also defines the class of the object @@ -16,8 +16,16 @@ module Parfait TYPE_INDEX = 0 class Object + attr :type - def self.new *args + def self.memory_size + 8 + end + def self.type_length + 1 + end + + def self.new( *args ) object = self.allocate # have to grab the class, because we are in the ruby class not the parfait one @@ -25,35 +33,16 @@ module Parfait # and have to set the type before we let the object do anything. otherwise boom object.set_type cl.instance_type - object.send :initialize , *args object end - # 0 -based index - def get_internal_word(index) - name = get_type().name_at(index) - return nil unless name - instance_variable_get("@#{name}".to_sym) - end - - # 0 -based index - def set_internal_word(index , value) - return set_type(value) if( index == TYPE_INDEX) - raise "not type #{@type.class}" unless @type.is_a?(Type) - name = @type.name_at(index) - #return value unless name - raise "object type (#{@type}) has no name at index #{index} " unless name - instance_variable_set("@#{name}".to_sym, value) - value - end - def == other self.object_id == other.object_id end - # This is the crux of the object system. The class of an object is stored in the objects - # memory (as opposed to an integer that has no memory and so always has the same class) + # This is the core of the object system. + # The class of an object is stored in the objects memory # # In RubyX we store the class in the Type, and so the Type is the only fixed # data that every object carries. @@ -64,20 +53,19 @@ module Parfait end # private - def set_type(type) - # puts "Type was set for #{self.class}" - raise "not type #{type.class} in #{self}" unless type.is_a?(Type) - @type = type + def set_type(typ) + raise "not type #{typ.class} in #{object_id.to_s(16)}" unless typ.is_a?(Type) + self.type = typ end # so we can keep the raise in get_type def has_type? - ! @type.nil? + ! type.nil? end def get_type() raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless has_type? - @type + type end # return the metaclass @@ -86,7 +74,7 @@ module Parfait end def get_instance_variables - @type.names + type.names end def get_instance_variable( name ) @@ -103,20 +91,20 @@ module Parfait end def instance_variable_defined( name ) - @type.variable_index(name) + type.variable_index(name) end def padded_length - Padding.padded_words( @type.instance_length ) + Padding.padded_words( type.instance_length ) end # parfait versions are deliberately called different, so we "relay" - # have to put the "@" on the names for rfx to take them off again + # have to put the "" on the names for rfx to take them off again def instance_variables - get_instance_variables.to_a.collect{ |n| "@#{n}".to_sym } + get_instance_variables.to_a.collect{ |n| "#{n}".to_sym } end - # name comes in as a ruby @var name + # name comes in as a ruby var name def instance_variable_ged name var = get_instance_variable name.to_s[1 .. -1].to_sym #puts "getting #{name} #{var}" diff --git a/lib/parfait/page.rb b/lib/parfait/page.rb index db319b59..aedda2c8 100644 --- a/lib/parfait/page.rb +++ b/lib/parfait/page.rb @@ -10,6 +10,6 @@ module Parfait class Page < Object - + attr :type end end diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 995b2a55..20bf3c94 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -11,12 +11,12 @@ module Parfait # Make the object space globally available def self.object_space - @@object_space + @object_space end # TODO Must get rid of the setter (move the boot process ?) def self.set_object_space( space ) - @@object_space = space + @object_space = space end # The Space contains all objects for a program. In functional terms it is a program, but in oo @@ -31,51 +31,58 @@ module Parfait class Space < Object + attr :type, :classes , :types , :next_message , :next_integer , :next_address + attr :messages, :integers , :addresses + attr :true_object , :false_object , :nil_object + def initialize( classes ) - @classes = classes - @types = Dictionary.new - @classes.each do |name , cl| + self.classes = classes + self.types = Dictionary.new + classes.each do |name , cl| add_type(cl.instance_type) end - 101.times { @integers = Integer.new(0,@integers) } - 400.times { @addresses = ReturnAddress.new(0,@addresses) } + 101.times { self.integers = Integer.new(0,self.integers) } + 400.times { self.addresses = ReturnAddress.new(0,self.addresses) } message = Message.new(nil) 50.times do - @messages = Message.new message - message.set_caller @messages - message = @messages + self.messages = Message.new( message ) + message.set_caller( self.messages ) + message = self.messages end - @next_message = @messages - @next_integer = @integers - @next_address = @addresses - @true_object = Parfait::TrueClass.new - @false_object = Parfait::FalseClass.new - @nil_object = Parfait::NilClass.new + self.next_message = self.messages + self.next_integer = self.integers + self.next_address = self.addresses + self.true_object = Parfait::TrueClass.new + self.false_object = Parfait::FalseClass.new + self.nil_object = Parfait::NilClass.new end - attr_reader :classes , :types , :next_message , :next_integer , :next_address - attr_reader :messages, :integers , :addresses - attr_reader :true_object , :false_object , :nil_object + def self.type_length + 12 + end + def self.memory_size + 16 + end # hand out one of the preallocated ints for use as constant # the same code is hardcoded as risc instructions for "normal" use, to # avoid the method call at runtime. But at compile time we want to keep # the number of integers known (fixed). def get_integer - int = @next_integer - @next_integer = @next_integer.next_integer + int = self.next_integer + self.next_integer = next_integer.next_integer int end # hand out a return address for use as constant the address is added def get_address - addr = @next_address - @next_address = @next_address.next_integer + addr = next_address + next_address = next_address.next_integer addr end def each_type - @types.values.each do |type| + types.values.each do |type| yield(type) end end @@ -83,13 +90,13 @@ module Parfait def add_type( type ) hash = type.hash raise "upps #{hash} #{hash.class}" unless hash.is_a?(Fixnum) - was = @types[hash] + was = types[hash] return was if was - @types[hash] = type + types[hash] = type end def get_type_for( hash ) - @types[hash] + types[hash] end # all methods form all types @@ -124,8 +131,8 @@ module Parfait # return nili if no such class. Use bang version if create should be implicit def get_class_by_name( name ) raise "get_class_by_name #{name}.#{name.class}" unless name.is_a?(Symbol) - c = @classes[name] - #puts "MISS, no class #{name} #{name.class}" unless c # " #{@classes}" + c = classes[name] + #puts "MISS, no class #{name} #{name.class}" unless c # " #{classes}" #puts "CLAZZ, #{name} #{c.get_type.get_length}" if c c end @@ -146,7 +153,7 @@ module Parfait raise "create_class #{superclass.class}" unless superclass.is_a? Symbol type = get_type_by_class_name(superclass) c = Class.new(name , superclass , type ) - @classes[name] = c + classes[name] = c end def rxf_reference_name diff --git a/lib/parfait/type.rb b/lib/parfait/type.rb index 88dc46de..95186cc8 100644 --- a/lib/parfait/type.rb +++ b/lib/parfait/type.rb @@ -36,7 +36,11 @@ module Parfait class Type < Object - attr_reader :object_class , :names , :types , :methods + attr :type, :object_class , :names , :types , :methods + + def self.type_length + 5 + end def self.for_hash( object_class , hash) hash = {type: object_class.name }.merge(hash) unless hash[:type] @@ -53,9 +57,9 @@ module Parfait # this part of the init is seperate because at boot time we can not use normal new # new is overloaded to grab the type from space, and before boot, that is not set up def init_lists(hash) - @methods = nil - @names = List.new - @types = List.new + self.methods = nil + self.names = List.new + self.types = List.new raise "No type Type in #{hash}" unless hash[:type] private_add_instance_variable(:type , hash[:type]) #first hash.each do |name , type| @@ -64,13 +68,13 @@ module Parfait end def class_name - @object_class.name + object_class.name end def to_s str = "#{class_name}-[" first = false - @names.each do |name| + names.each do |name| unless(first) first = true str += ":#{name}" @@ -83,8 +87,8 @@ module Parfait def method_names names = List.new - return names unless @methods - @methods.each_method do |method| + return names unless methods + methods.each_method do |method| names.push method.name end names @@ -114,19 +118,19 @@ module Parfait if get_method( method.name ) remove_method(method.name) end - method.set_next( @methods ) - @methods = method + method.set_next( methods ) + self.methods = method #puts "#{self.name} add #{method.name}" method end def remove_method( method_name ) - raise "No such method #{method_name} in #{self.name}" unless @methods - if( @methods.name == method_name) - @methods = @methods.next + raise "No such method #{method_name} in #{self.name}" unless methods + if( methods.name == method_name) + self.methods = methods.next return true end - method = @methods + method = methods while(method && method.next) if( method.next.name == method_name) method.set_next( method.next.next ) @@ -140,8 +144,8 @@ module Parfait def get_method( fname ) raise "get_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol) - return nil unless @methods - @methods.each_method do |m| + return nil unless methods + methods.each_method do |m| return m if(m.name == fname ) end nil @@ -163,9 +167,9 @@ module Parfait end def methods_length - return 0 unless @methods + return 0 unless methods len = 0 - @methods.each_method { len += 1} + methods.each_method { len += 1} return len end @@ -181,38 +185,38 @@ module Parfait raise "No nil type" unless type hash = to_hash hash[name] = type - return Type.for_hash( @object_class , hash) + return Type.for_hash( object_class , hash) end def set_object_class(oc) raise "object class should be a class, not #{oc.class}" unless oc.is_a?(Class) - @object_class = oc + self.object_class = oc end def instance_length - @names.get_length() + names.get_length() end # index of the variable when using get_internal_word # (get_internal_word is 0 based and 0 is always the type) def variable_index( name ) - has = @names.index_of(name) + has = names.index_of(name) return nil unless has raise "internal error #{name}:#{has}" if has < 0 has end def get_length() - @names.get_length() + names.get_length() end def name_at( index ) - raise "No names #{index}" unless @names - @names.get(index) + raise "No names #{index}" unless names + names.get(index) end def type_at( index ) - @types.get(index) + types.get(index) end def type_for( name ) @@ -226,7 +230,7 @@ module Parfait end def rxf_reference_name - "#{@object_class.name}_Type" + "#{object_class.name}_Type" end alias :name :rxf_reference_name @@ -239,8 +243,8 @@ module Parfait end def each_method(&block) - return unless @methods - @methods.each_method(&block) + return unless methods + methods.each_method(&block) end def to_hash hash = {} @@ -254,7 +258,7 @@ module Parfait def hash index = 1 - hash_code = Type.str_hash( @object_class.name ) + hash_code = Type.str_hash( object_class.name ) each do |name , type| item_hash = Type.str_hash(name) + Type.str_hash(type) hash_code += item_hash + (item_hash / 256 ) * index @@ -280,8 +284,8 @@ module Parfait def private_add_instance_variable( name , type) raise "Name shouldn't be nil" unless name raise "Value Type shouldn't be nil" unless type - @names.push(name) - @types.push(type) + names.push(name) + types.push(type) end end diff --git a/lib/parfait/vool_method.rb b/lib/parfait/vool_method.rb index b7201a03..ef154105 100644 --- a/lib/parfait/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -12,10 +12,13 @@ module Parfait # class VoolMethod < Object - attr_reader :name , :args_type , :frame_type , :source + attr :type, :name , :args_type , :frame_type , :source def initialize(name , args_type , frame_type , source ) - @name , @args_type , @frame_type , @source = name , args_type, frame_type , source + self.name = name + self.args_type = args_type + self.frame_type = frame_type + self.source = source raise "Name must be symbol" unless name.is_a?(Symbol) raise "args_type must be type" unless args_type.is_a?(Parfait::Type) raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type) @@ -25,7 +28,7 @@ module Parfait def create_callable_method( type ) raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type - type.create_method( @name , @args_type , @frame_type) + type.create_method( name , args_type , frame_type) end def compiler_for(self_type) diff --git a/lib/parfait/word.rb b/lib/parfait/word.rb index de0aaab7..29bfa234 100644 --- a/lib/parfait/word.rb +++ b/lib/parfait/word.rb @@ -13,7 +13,7 @@ module Parfait # Object length is measured in non-type cells though class Word < Data8 - attr_reader :char_length + attr :type, :char_length def self.type_length 2 # 0 type , 1 char_length @@ -26,7 +26,7 @@ module Parfait # Risc provides methods to create Parfait objects from ruby def initialize( len ) super() - @char_length = 0 + self.char_length = 0 raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum raise "Must init with positive, not #{len}" if len < 0 set_length( len , 32 ) unless len == 0 #32 being ascii space @@ -47,7 +47,7 @@ module Parfait # return the number of characters def length() - obj_len = @char_length + obj_len = char_length return obj_len end @@ -75,9 +75,9 @@ module Parfait # def set_length(len , fill_char) return if len <= 0 - old = @char_length + old = char_length return if old >= len - @char_length = len + self.char_length = len check_length fill_from_with( old + 1 , fill_char ) end @@ -169,7 +169,7 @@ module Parfait def to_string string = "" index = 0 - while( index < @char_length) + while( index < char_length) char = get_char(index) string += char ? char.chr : "*" index = index + 1 @@ -183,12 +183,12 @@ module Parfait end def padded_length - Padding.padded( 4 * get_type().instance_length + @char_length ) + Padding.padded( 4 * get_type().instance_length + char_length ) end private def check_length - raise "Length out of bounds #{@char_length}" if @char_length > 1000 + raise "Length out of bounds #{char_length}" if char_length > 1000 end end