From 278d71b56cd06e88ea55858da2b5043e7c025c74 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 25 Feb 2016 12:03:11 -0800 Subject: [PATCH] fix docs for rename --- CodeStyle.md | 2 +- Gemfile.lock | 4 ++-- lib/register/assembler.rb | 2 +- lib/register/boot.rb | 6 +++--- lib/register/parfait/class.rb | 18 ++++++++++-------- lib/register/parfait/frame.rb | 9 ++++++--- lib/register/parfait/list.rb | 6 +++--- lib/register/parfait/object.rb | 28 +++++++++++++++------------- lib/register/parfait/type.rb | 23 +++++++++++++---------- lib/register/parfait/value.rb | 28 ++-------------------------- lib/register/parfait/word.rb | 2 +- lib/soml/compiler/field_access.rb | 2 +- test/melon/collector.rb | 27 ++++++++++++++++++++------- test/register/parfait/test_list.rb | 2 +- test/register/parfait/test_type.rb | 2 +- 15 files changed, 80 insertions(+), 81 deletions(-) diff --git a/CodeStyle.md b/CodeStyle.md index cc910f3c..f9152e8d 100644 --- a/CodeStyle.md +++ b/CodeStyle.md @@ -32,6 +32,6 @@ But often one finds a little massaging of the incoming data is better, while kee out of the Instructions classes. In such cases Module functions are again quite nice. Example: Instead of GetSlot.new( register, index , register) we use Register.get_slot( name , name , name). -All names are resolved to registers, or index via Layout. More readable code less repetition. +All names are resolved to registers, or index via Type. More readable code less repetition. As the example shows, in this case the module function name should be the instruction class name. diff --git a/Gemfile.lock b/Gemfile.lock index 15d5bba8..246ace93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,7 @@ GEM method_source (~> 0.8.1) slop (~> 3.4) win32console (~> 1.3) - rake (10.4.2) + rake (10.5.0) rb-fsevent (0.9.6) rb-inotify (0.9.5) ffi (>= 0.5.0) @@ -133,4 +133,4 @@ DEPENDENCIES salama-reader! BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index 3e653f57..28dba7de 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -132,7 +132,7 @@ module Register obj.position end - # write type and type of the instance, and the variables that are passed + # write type of the instance, and the variables that are passed # variables ar values, ie int or refs. For refs the object needs to save the object first def write_object( object ) log.debug "Write object #{object.class} #{object.inspect}" diff --git a/lib/register/boot.rb b/lib/register/boot.rb index 9d0b9e4e..4624991b 100644 --- a/lib/register/boot.rb +++ b/lib/register/boot.rb @@ -11,8 +11,8 @@ module Register # And so we have a chicken and egg problem. At the end of the boot function we want to have a # working Space object # But that has instance variables (List and Dictionary) and off course a class. - # Or more precisely in salama, a Layout, that points to a class. - # So we need a Layout, but that has Layout and Class too. hmmm + # Or more precisely in salama, a Type, that points to a class. + # So we need a Type, but that has Type and Class too. hmmm # # The way out is to build empty shell objects and stuff the neccessary data into them # (not use the normal initialize way) @@ -86,7 +86,7 @@ module Register end end - # helper to create a Layout, name is the parfait name, ie :Type + # helper to create a Type, name is the parfait name, ie :Type def type_for( name , ivars ) l = Parfait::Type.allocate.fake_init l.add_instance_variable :type , :Type diff --git a/lib/register/parfait/class.rb b/lib/register/parfait/class.rb index 42b03220..4c46a41d 100644 --- a/lib/register/parfait/class.rb +++ b/lib/register/parfait/class.rb @@ -1,17 +1,19 @@ -# Class is mainly a list of methods with a name (for now) -# The memory type of object is seperated into Layout - # A class describes the capabilities of a group of objects, ie what data it has # and functions it responds to. -# -# So it is essential that the class (the object defining the class) + +# Class is mainly a list of methods with a name. (Note that methods may have many functions) +# The memory layout of an object is determined by the Type (see there). +# The class carries the "current" type, ie the type an object would be if you created an instance +# of the class. Note that this changes over time and so many types share the same class. + +# It is essential that the class (the object defining the class) # can carry methods. It does so as instance variables. -# In fact this property is implemented in the Layout, as methods +# In fact this property is implemented in the Type, as methods # may be added to any object at run-time # An Object carries the data for the instance variables it has -# The Layout lists the names of the instance variables +# The Type lists the names of the instance variables # The class keeps a list of instance methods, these have a name and code module Parfait @@ -24,7 +26,7 @@ module Parfait self.name = name self.super_class_name = superclass # the type for this class (class = object of type Class) carries the class - # as an instance. The relation is from an object through the Layout to it's class + # as an instance. The relation is from an object through the Type to it's class # TODO the object type should copy the stuff from superclass self.object_type = Type.new(self) end diff --git a/lib/register/parfait/frame.rb b/lib/register/parfait/frame.rb index f26d8598..19804bc9 100644 --- a/lib/register/parfait/frame.rb +++ b/lib/register/parfait/frame.rb @@ -8,13 +8,16 @@ # A Message (see details there) is created by the caller and control is transferred # A Frame is created by the receiver # PS: it turns out that both messages and frames are created at compile, not run-time, and -# just constantly reused. Each message has a frame object ready and ist also linked +# just constantly reused. Each message has a frame object ready and is also linked # to the next message. # The better way to say above is that a message is *used* by the caller, and a frame by the callee. -# Also at runtime Messages and Frames remain completely "normal" objects. Ie have types and so on. +# Also at runtime Messages and Frames remain completely "normal" objects. +# Ie they have have type and instances and so on.* # Which resolves the dichotomy of objects on the stack or heap. Sama sama. - +# +# *Alas the type for each call instance is unique. +# module Parfait class Frame < Object attribute :next_frame diff --git a/lib/register/parfait/list.rb b/lib/register/parfait/list.rb index 0b1bcb76..cdbb9d33 100644 --- a/lib/register/parfait/list.rb +++ b/lib/register/parfait/list.rb @@ -4,12 +4,12 @@ require_relative "indexed" # For a programmer this may be a little strange as this new start goes with trying to break old # bad habits. A List would be an array in some languages, but list is a better name, closer to # common language. -# Another habit is to start a list from 0. This is "just" programmers lazyness, as it goes +# Another bad habit is to start a list from 0. This is "just" programmers lazyness, as it goes # with the standard c implementation. But it bends the mind, and in oo we aim not to. -# If you have a list of three items, you they will be first, second and third, ie 1,2,3 +# If you have a list of three items, they will be first, second and third, ie 1,2,3 # # For the implementation we use Objects memory which is index addressable -# But, objects are also lists where indexes start with 1, except 1 is taken for the Layout +# But, objects are also lists where indexes start with 1, except 1 is taken for the Type # so all incoming/outgoing indexes have to be shifted one up/down module Parfait diff --git a/lib/register/parfait/object.rb b/lib/register/parfait/object.rb index bb759905..244b9869 100644 --- a/lib/register/parfait/object.rb +++ b/lib/register/parfait/object.rb @@ -1,17 +1,19 @@ -# to be precise, this should be an ObjectReference, as the Reference is a Value -# but we don't want to make that distinction all the time , so we don't. +# From a programmers perspective an object has hash like data (with instance variables as keys) +# and functions to work on that data. +# Only the object may access it's data directly. -# that does lead to the fact that we have Reference functions on the Object though +# From an implementation perspective it is a chunk of memory with an type as the first +# word. -# Objects are arranged or layed out (in memory) according to their Layout -# every object has a Layout. Layout objects are immutalbe and may be resued for a group/class +# 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 # off objects. -# The Layout of an object may change, but then a new Layout is created -# The Layout also defines the class of the object -# The Layout is **always** the first entry (index 1) in an object, but the type word is index 0 +# The Type of an object may change, but then a new Type is created +# The Type also defines the class of the object +# The Type is **always** the first entry (index 1) in an object module Parfait - LAYOUT_INDEX = 1 + TYPE_INDEX = 1 class Object < Value @@ -68,7 +70,7 @@ module Parfait # 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) # - # In Salama we store the class in the Layout, and so the Layout is the only fixed + # In Salama we store the class in the Type, and so the Type is the only fixed # data that every object carries. def get_class() l = get_type() @@ -80,16 +82,16 @@ module Parfait def set_type(type) # puts "Type was set for #{self.class}" raise "Nil type" unless type - set_internal_word(LAYOUT_INDEX , type) + set_internal_word(TYPE_INDEX , type) end # so we can keep the raise in get_type def has_type? - ! get_internal_word(LAYOUT_INDEX).nil? + ! get_internal_word(TYPE_INDEX).nil? end def get_type() - l = get_internal_word(LAYOUT_INDEX) + l = get_internal_word(TYPE_INDEX) #puts "get type for #{self.class} returns #{l.class}" raise "No type #{self.object_id.to_s(16)}:#{self.class} " unless l return l diff --git a/lib/register/parfait/type.rb b/lib/register/parfait/type.rb index 020c20eb..8d3acaf2 100644 --- a/lib/register/parfait/type.rb +++ b/lib/register/parfait/type.rb @@ -1,26 +1,29 @@ # An Object is really a hash like structure. It is dynamic and # you want to store values by name (instance variable names). # -# One could (like mri), store the names in each object, but that is wasteful +# One could (like mri), store the names in each object, but that is wasteful in both time and space. # Instead we store only the values, and access them by index. -# The Layout allows the mapping of names to index. +# The Type allows the mapping of names to index. -# The Layout of an object describes the memory type of the object -# The Layout is a simple list of the names of instance variables. +# The Type of an object describes the memory layout of the object. In a c analogy, it is the +# information defined in a struct. +# The Type is a list of the names of instance variables, and their value types (int etc). # -# As every object has a Layout to describe it, the name "type" is the -# first name in the list for every Layout. +# Every object has a Type to describe it, so it's *first* instance variable is **always** +# "type". This means the name "type" is the first name in the list +# for every Type instance. -# But as we want every Object to have a class, the Layout carries that class. +# But, as we want every Object to have a class, the Type carries that class. # So the type of type has an entry "object_class" # But Objects must also be able to carry methods themselves (ruby calls singleton_methods) -# and those too are stored in the Layout (both type and class include behaviour) +# and those too are stored in the Type (both type and class include behaviour) -# In other words, the Layout is a list of names that describe +# In other words, the Type is a list of names and value types that describe # the values stored in an actual object. # The object is an List of values of length n and -# the Layout is an List of names of length n , plus class reference and methods reference +# the Type is an List of names and value tpyes of length n , +# plus class reference and methods reference # Together they turn the object into a hash like structure module Parfait diff --git a/lib/register/parfait/value.rb b/lib/register/parfait/value.rb index f8371e26..cb614ef9 100644 --- a/lib/register/parfait/value.rb +++ b/lib/register/parfait/value.rb @@ -1,39 +1,15 @@ -# this is not a "normal" ruby file, ie it is not required by salama -# instead it is parsed by salama to define part of the program that runs - # Values are _not_ objects. Specifically they have the following properties not found in objects: # - they are immutable # - equality implies identity == is === # - they have type, not class -# To make them useful in an oo system, we assign a class to each basic type +# To make them useful in an oo system, we assign a class to each value type # This makes them look more like objects, but they are not. # Value is an abstract class that unifies the "has a type" concept -# Types are not "objectified", but are represented as integer constants +# Types are not "objectified", but are represented as symbol constants module Parfait class Value - - # to make the machine work, the constants need - # - to start at 0 - # - be unique - # - be smaller enough to fit into the 2-4 bits available - INTEGER_VALUE = 0 - OBJECT_VALUE = 1 - - # the type is what identifies the value - def get_type() - raise "abstract clalled on #{self}" - end - - # Get class works on the type. The value's type is stored by the machine. - # So this function is not overriden in derived classes, because it is used - # to espablish what class a value has! (it's that "fake" oo i mentioned) - # def get_class() - # type = self.get_type() - # return Integer if( type == INTEGER_VALUE ) - # raise "invalid type" - # end end end diff --git a/lib/register/parfait/word.rb b/lib/register/parfait/word.rb index 87efde0e..021088a8 100644 --- a/lib/register/parfait/word.rb +++ b/lib/register/parfait/word.rb @@ -8,7 +8,7 @@ module Parfait # Words are constant, maybe like js strings, ruby symbols # Words are short, but may have spaces - # Words are objects, that means they carry Layout as index 0 + # Words are objects, that means they carry Type as index 0 # So all indexes are offset by one in the implementation # Object length is measured in non-type cells though diff --git a/lib/soml/compiler/field_access.rb b/lib/soml/compiler/field_access.rb index 00541983..475e74da 100644 --- a/lib/soml/compiler/field_access.rb +++ b/lib/soml/compiler/field_access.rb @@ -4,7 +4,7 @@ module Soml def on_field_access statement receiver_ast , field_ast = *statement receiver = process(receiver_ast) - + clazz = Register.machine.space.get_class_by_name receiver.type field_name = field_ast.first_from(:name) diff --git a/test/melon/collector.rb b/test/melon/collector.rb index 29945fe6..b9eb5774 100644 --- a/test/melon/collector.rb +++ b/test/melon/collector.rb @@ -16,9 +16,20 @@ class Walker < AST::Processor if method == :require_relative @collector.load File.dirname(@collector.current) + "/" + file_node.children[0] + ".rb" end + if method.to_s.include?("eval") + @collector.evals << method + end handler_missing(node) end + def on_class node + @collector.class_defs << node.children[0].children[1] + handler_missing(node) + end + def on_const node + @collector.const_uses[node.children[1]] += 1 + handler_missing(node) + end def handler_missing node type = node.type @collector.types[type] += 1 @@ -33,15 +44,16 @@ class Collector def initialize @parser = Parser::Ruby22 @paths = Bundler.load.specs.collect { |s| s.gem_dir + "/lib/" } - @class_defs = Hash.new([]) - @class_uses = Hash.new([]) + @class_defs = [] + @const_uses = Hash.new(0) @types = Hash.new(0) @not_found = [] @walker = Walker.new(self) @files = [] + @evals = [] @current = nil end - attr_reader :class_defs , :class_uses , :types , :current + attr_reader :class_defs , :const_uses , :types , :current , :evals def file_content file_name return nil if @files.include? file_name @@ -70,11 +82,12 @@ class Collector @current = was end def print + @class_defs.uniq! + @files.uniq! puts "Class defs #{@class_defs.length}" - puts "Class uses #{@class_uses.length}" - #puts "Types #{@types.to_yaml}" - #puts "files #{@files.to_yaml}" - #puts "Not found #{@not_found.length} #{@not_found.join(' ')}" + puts "Types #{@types.to_yaml}" + puts "evals=#{@evals.length} #{@evals.uniq}" + #puts "Not found #{@not_found.length} #{@not_found}" end end diff --git a/test/register/parfait/test_list.rb b/test/register/parfait/test_list.rb index 0081caf4..43caf234 100644 --- a/test/register/parfait/test_list.rb +++ b/test/register/parfait/test_list.rb @@ -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_word(Parfait::LAYOUT_INDEX + 1) + assert_equal 1 , @list.get_internal_word(Parfait::TYPE_INDEX + 1) end def test_list_inspect @list.set(1,1) diff --git a/test/register/parfait/test_type.rb b/test/register/parfait/test_type.rb index 95cb8ab7..1cf7a7d5 100644 --- a/test/register/parfait/test_type.rb +++ b/test/register/parfait/test_type.rb @@ -21,7 +21,7 @@ class TestType < MiniTest::Test end def test_type_index - assert_equal @mess.get_type , @mess.get_internal_word(Parfait::LAYOUT_INDEX) , "mess" + assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess" end def test_inspect