change name

This commit is contained in:
Torsten Ruger 2017-09-27 15:35:55 +03:00
parent bf1b3e95bd
commit 6ca249118c
23 changed files with 93 additions and 96 deletions

1
.ruby-version Normal file
View File

@ -0,0 +1 @@
2.3.4

View File

@ -4,7 +4,5 @@ cache: bundler
script: script:
- CODECLIMATE_REPO_TOKEN=40ed7f464af09c892b27adc2cd171c36b24992d8d527428285bc55c46fe2f0e0 ruby test/test_all.rb - CODECLIMATE_REPO_TOKEN=40ed7f464af09c892b27adc2cd171c36b24992d8d527428285bc55c46fe2f0e0 ruby test/test_all.rb
rvm: rvm:
- 1.9.3 - 2.2.7
- 2.0.0 - 2.3.4
- 2.1.5
- 2.2.0

View File

@ -2,7 +2,7 @@ source "http://rubygems.org"
gem "rake" gem "rake"
gem "rubyx-object-file" , :path => "." gem "rx-file" , :path => "."
gem "codeclimate-test-reporter", require: nil gem "codeclimate-test-reporter", require: nil

View File

@ -1,22 +1,22 @@
PATH PATH
remote: . remote: .
specs: specs:
rubyx-object-file (0.3.0) rx-file (0.3.0)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
codeclimate-test-reporter (0.4.8) codeclimate-test-reporter (1.0.8)
simplecov (>= 0.7.1, < 1.0.0) simplecov (<= 0.13)
docile (1.1.5) docile (1.1.5)
json (1.8.3) json (2.1.0)
minitest (5.8.1) minitest (5.10.3)
rake (10.4.2) rake (12.1.0)
simplecov (0.10.0) simplecov (0.13.0)
docile (~> 1.1.0) docile (~> 1.1.0)
json (~> 1.8) json (>= 1.8, < 3)
simplecov-html (~> 0.10.0) simplecov-html (~> 0.10.0)
simplecov-html (0.10.0) simplecov-html (0.10.2)
PLATFORMS PLATFORMS
ruby ruby
@ -25,7 +25,7 @@ DEPENDENCIES
codeclimate-test-reporter codeclimate-test-reporter
minitest minitest
rake rake
rubyx-object-file! rx-file!
BUNDLED WITH BUNDLED WITH
1.14.6 1.15.4

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2015 A minimal oo vm that strives for simplicity and clarity Copyright (c) 2014-7 An object file format
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

View File

@ -1,11 +1,11 @@
[![Build Status](https://travis-ci.org/salama/salama-object-file.svg?branch=master)](https://travis-ci.org/salama/salama-object-file) [![Build Status](https://travis-ci.org/rubyx/rx-file.svg?branch=master)](https://travis-ci.org/rubyx/rx-file)
[![Gem Version](https://badge.fury.io/rb/salama-object-file.svg)](http://badge.fury.io/rb/salama-object-file) [![Gem Version](https://badge.fury.io/rb/rx-file.svg)](http://badge.fury.io/rb/rx-file)
[![Code Climate](https://codeclimate.com/github/salama/salama-object-file/badges/gpa.svg)](https://codeclimate.com/github/salama/salama-object-file) [![Code Climate](https://codeclimate.com/github/rubyx/rx-file/badges/gpa.svg)](https://codeclimate.com/github/rubyx/rx-file)
[![Test Coverage](https://codeclimate.com/github/salama/salama-object-file/badges/coverage.svg)](https://codeclimate.com/github/salama/salama-object-file) [![Test Coverage](https://codeclimate.com/github/rubyx/rx-file/badges/coverage.svg)](https://codeclimate.com/github/rubyx/rx-file)
### Reading the code ### Reading the code
Knowing what's going on while coding salama is not so easy: Hence the need to look at code dumps Knowing what's going on while coding rubyx is not so easy: Hence the need to look at code dumps
Hence the need for a code/object file format Hence the need for a code/object file format
(remember an oo program is just objects, some data, some code, all objects) (remember an oo program is just objects, some data, some code, all objects)
@ -19,7 +19,7 @@ But the "sort of" started to get to me, because
- 2) does not allow for (easy) ordering. - 2) does not allow for (easy) ordering.
- 3) has no concept of dumping only parts of an object - 3) has no concept of dumping only parts of an object
To fix this i started on Sof, with an eye to expand it. To fix this i started on RxFile, with an eye to expand it.
The main starting goal was quite like yaml, but with The main starting goal was quite like yaml, but with
@ -33,10 +33,10 @@ The main starting goal was quite like yaml, but with
The module's main useful api is The module's main useful api is
Sof::Writer.write(object_to_derialize) RxFile::Writer.write(object_to_derialize)
### Salama Object File ### Ruby X File
Ok, so we all heard about object files, it's the things compilers create so we don't have to have Ok, so we all heard about object files, it's the things compilers create so we don't have to have
huge compiles and can link them later. huge compiles and can link them later.
@ -60,13 +60,12 @@ And so this is a little start, just some outputter.
#### Direction #### Direction
The way this is meant to go (planned for 2020+) was a salama core with only a sof parser The way this is meant to go (planned for 2020+) was a rubyx core with only a rx-filw parser (as that is soo much simpler).
(as that is soo much simpler).
Then to_ruby for all the ast classes to be able to roundtrip ruby code. Then to_ruby for all the ast classes to be able to roundtrip ruby code.
Then go to storing sof in git, rather than ruby. Then go to storing rxf in git, rather than ruby.
Then write a python/java parser and respective runtime conversion. Extracting common features. Then write a python/java parser and respective runtime conversion. Extracting common features.
With the respective to_python on the ast's to roundtrip that too. With the respective to_python on the ast's to roundtrip that too.
Have to since by now we work on sof's. Etc . .. Have to since by now we work on rx-file's. Etc . ..

View File

@ -2,49 +2,49 @@
# if you want some attributes not written also check volotile # if you want some attributes not written also check volotile
require_relative "sof/util" require_relative "rx-file/util"
require_relative "sof/node" require_relative "rx-file/node"
require_relative "sof/simple_node" require_relative "rx-file/simple_node"
require_relative "sof/object_node" require_relative "rx-file/object_node"
require_relative "sof/members" require_relative "rx-file/members"
require_relative "sof/volotile" require_relative "rx-file/volotile"
require_relative "sof/writer" require_relative "rx-file/writer"
require_relative "sof/array_node" require_relative "rx-file/array_node"
require_relative "sof/hash_node" require_relative "rx-file/hash_node"
require_relative "sof/occurence" require_relative "rx-file/occurence"
Class.class_eval do Class.class_eval do
def to_sof def to_rxf
self.name self.name
end end
end end
Symbol.class_eval do Symbol.class_eval do
def to_sof() def to_rxf()
":#{to_s}" ":#{to_s}"
end end
end end
TrueClass.class_eval do TrueClass.class_eval do
def to_sof() def to_rxf()
"true" "true"
end end
end end
NilClass.class_eval do NilClass.class_eval do
def to_sof() def to_rxf()
"nil" "nil"
end end
end end
FalseClass.class_eval do FalseClass.class_eval do
def to_sof() def to_rxf()
"false" "false"
end end
end end
String.class_eval do String.class_eval do
def to_sof() def to_rxf()
"'" + self + "'" "'" + self + "'"
end end
end end
Fixnum.class_eval do Fixnum.class_eval do
def to_sof() def to_rxf()
to_s to_s
end end
end end

View File

@ -1,8 +1,8 @@
module Sof module RxFile
# A ArrayNode is a Node for an Array. See Node for when and how nodes are used in Sof. # A ArrayNode is a Node for an Array. See Node for when and how nodes are used in RxFile.
# A ArrayNode has a list of children that hold the value node representations for # A ArrayNode has a list of children that hold the value node representations for
# the arrays values. # the arrays values.
# #

View File

@ -1,5 +1,5 @@
module Sof module RxFile
# A HashNode is a Node for a Hash. See Node for when and how nodes are used in Sof. # A HashNode is a Node for a Hash. See Node for when and how nodes are used in RxFile.
# A HashNode has a list of children that hold the key/value node representations for # A HashNode has a list of children that hold the key/value node representations for
# the hashes keys and values. # the hashes keys and values.

View File

@ -1,4 +1,4 @@
module Sof module RxFile
# Members are members of the graph to be written # Members are members of the graph to be written
# The class collects all reachable objects into a hash for further transformation # The class collects all reachable objects into a hash for further transformation
@ -37,8 +37,8 @@ module Sof
unless occurence.referenced unless occurence.referenced
# puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 23 # puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 23
# puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 19 # puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 19
if object.respond_to? :sof_reference_name if object.respond_to? :rxf_reference_name
reference = object.sof_reference_name reference = object.rxf_reference_name
reference = reference.to_s.gsub(/\s|\W/ , "") #remove space and stuff reference = reference.to_s.gsub(/\s|\W/ , "") #remove space and stuff
if( @references.include?(reference) or reference.empty?) if( @references.include?(reference) or reference.empty?)
reference = "#{reference}-#{@counter}" reference = "#{reference}-#{@counter}"

View File

@ -1,6 +1,6 @@
# We transform objects into a tree of nodes # We transform objects into a tree of nodes
module Sof module RxFile
# Before writing the objects are transformed into a tree of nodes. # Before writing the objects are transformed into a tree of nodes.
# as the Members (all objects) are a graph (not tree) this is achieved by referencing # as the Members (all objects) are a graph (not tree) this is achieved by referencing

View File

@ -1,5 +1,5 @@
module Sof module RxFile
# ObjectNode means node with structure # ObjectNode means node with structure
# ie arrays and hashes get transformed into these too, as well as objects with attributes # ie arrays and hashes get transformed into these too, as well as objects with attributes

View File

@ -1,4 +1,4 @@
module Sof module RxFile
# simple struct like class to wrap an object and hold additionally # simple struct like class to wrap an object and hold additionally
# - the shallowest level at which it was seen # - the shallowest level at which it was seen

View File

@ -1,4 +1,4 @@
module Sof module RxFile
# What makes a node simple is that it has no further structure # What makes a node simple is that it has no further structure
# #

View File

@ -1,4 +1,4 @@
module Sof module RxFile
# module for a couple of helpers that are needed in Members and Writer # module for a couple of helpers that are needed in Members and Writer
@ -24,7 +24,7 @@ module Sof
# attributes may be supressed with Volotile # attributes may be supressed with Volotile
# TODO should be able to specify order too # TODO should be able to specify order too
def attributes_for object def attributes_for object
Sof::Util.attributes(object) RxFile::Util.attributes(object)
end end
# return a list of attributes for a given object # return a list of attributes for a given object

View File

@ -1,4 +1,4 @@
module Sof module RxFile
# Volotile module keeps track of attributes that are not menat to be written # Volotile module keeps track of attributes that are not menat to be written
# The idea being similar to private methods. So not every little detail is relevant # The idea being similar to private methods. So not every little detail is relevant
@ -9,7 +9,7 @@ module Sof
module Volotile module Volotile
@@mapping = { } @@mapping = { }
# Add attributes that are then ommited from the sof writing process # Add attributes that are then ommited from the rxf writing process
# The clazz is the real class object (eg String), and thus the # The clazz is the real class object (eg String), and thus the
# adding must happen after the class definition, often at the end of the file # adding must happen after the class definition, often at the end of the file
# attributes are an array of Symbols # attributes are an array of Symbols

View File

@ -1,6 +1,6 @@
module Sof module RxFile
# this function writes the object (and all reachable objects) out as sof # this function writes the object (and all reachable objects) out as rxf
# and returns a string # and returns a string
# For trees or graphs this works best by handing roots # For trees or graphs this works best by handing roots
# Internally this is done in three steps: # Internally this is done in three steps:
@ -23,9 +23,9 @@ module Sof
end end
# main function, creates nodes from the occurences and writes the nodes to a string # main function, creates nodes from the occurences and writes the nodes to a string
# returns the sof formatted string for all objects # returns the rxf formatted string for all objects
def write def write
node = to_sof_node(@members.root , 0) node = to_rxf_node(@members.root , 0)
io = StringIO.new io = StringIO.new
node.out( io , 0 ) node.out( io , 0 )
io.string io.string
@ -36,10 +36,10 @@ module Sof
# from the object we get the Occurence and decide wether a reference node is needed # from the object we get the Occurence and decide wether a reference node is needed
# simple objects (with more inner structure) become SimpleNodes # simple objects (with more inner structure) become SimpleNodes
# Any structured object becomes a ObjectNode # Any structured object becomes a ObjectNode
# Hash and Array create their own nodes via to_sof_node functions on the classes # Hash and Array create their own nodes via to_rxf_node functions on the classes
def to_sof_node(object , level) def to_rxf_node(object , level)
if is_value?(object) if is_value?(object)
return SimpleNode.new(object.to_sof()) return SimpleNode.new(object.to_rxf())
end end
occurence = @members.objects[object.object_id] occurence = @members.objects[object.object_id]
raise "no object #{object}" unless occurence raise "no object #{object}" unless occurence
@ -57,14 +57,14 @@ module Sof
ref = occurence.referenced ref = occurence.referenced
case object.class.name case object.class.name
when "Array" , "Parfait::List" when "Array" , "Parfait::List"
# If a class defines to_sof_node it tells the write that it will generate Nodes itself # If a class defines to_rxf_node it tells the write that it will generate Nodes itself
# this delegates to array_to_sof_node # this delegates to array_to_rxf_node
array_to_sof_node(object , level , ref ) array_to_rxf_node(object , level , ref )
when "Hash" , "Parfait::Dictionary" when "Hash" , "Parfait::Dictionary"
# and hash keys/values # and hash keys/values
hash_to_sof_node( object , level , ref) hash_to_rxf_node( object , level , ref)
else else
object_to_sof_node(object , level , ref) object_to_rxf_node(object , level , ref)
end end
end end
@ -76,41 +76,41 @@ module Sof
# #
# objects may be derived from array/hash. In that case the ObjectNode gets a super # objects may be derived from array/hash. In that case the ObjectNode gets a super
# (either ArrayNode or HashNode) # (either ArrayNode or HashNode)
def object_to_sof_node( object , level , ref) def object_to_rxf_node( object , level , ref)
node = ObjectNode.new(object.class.name , ref) node = ObjectNode.new(object.class.name , ref)
attributes_for(object).each() do |a| attributes_for(object).each() do |a|
val = get_value(object , a) val = get_value(object , a)
next if val.nil? next if val.nil?
node.add( a , to_sof_node( val , level + 1) ) node.add( a , to_rxf_node( val , level + 1) )
end end
#TODO get all superclsses here, but this covers 99% so . . moving on #TODO get all superclsses here, but this covers 99% so . . moving on
superclasses = [object.class.superclass.name] superclasses = [object.class.superclass.name]
if superclasses.include?( "Array") or superclasses.include?( "Parfait::List") if superclasses.include?( "Array") or superclasses.include?( "Parfait::List")
node.add_super( array_to_sof_node(object , level , ref ) ) node.add_super( array_to_rxf_node(object , level , ref ) )
end end
if superclasses.include?( "Hash") or superclasses.include?( "Parfait::Dictionary") if superclasses.include?( "Hash") or superclasses.include?( "Parfait::Dictionary")
node.add_super( hash_to_sof_node(object , level , ref ) ) node.add_super( hash_to_rxf_node(object , level , ref ) )
end end
node node
end end
# Creates a ArrayNode (see there) for the Array. # Creates a ArrayNode (see there) for the Array.
# This mainly involves creating nodes for the children # This mainly involves creating nodes for the children
def array_to_sof_node(array , level , ref ) def array_to_rxf_node(array , level , ref )
node = Sof::ArrayNode.new(ref) node = RxFile::ArrayNode.new(ref)
array.each do |object| array.each do |object|
node.add to_sof_node( object , level + 1) node.add to_rxf_node( object , level + 1)
end end
node node
end end
# Creates a HashNode (see there) for the Hash. # Creates a HashNode (see there) for the Hash.
# This mainly involves creating nodes for key value pairs # This mainly involves creating nodes for key value pairs
def hash_to_sof_node(hash , level , ref) def hash_to_rxf_node(hash , level , ref)
node = Sof::HashNode.new(ref) node = RxFile::HashNode.new(ref)
hash.each do |key , object| hash.each do |key , object|
k = to_sof_node( key ,level + 1) k = to_rxf_node( key ,level + 1)
v = to_sof_node( object ,level + 1) v = to_rxf_node( object ,level + 1)
node.add(k , v) node.add(k , v)
end end
node node

View File

@ -1,14 +1,14 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = 'rubyx-object-file' s.name = 'rx-file'
s.version = '0.3.0' s.version = '0.3.0'
s.authors = ['Torsten Ruger'] s.authors = ['Torsten Ruger']
s.email = 'torsten@villataika.fi' s.email = 'torsten@villataika.fi'
s.extra_rdoc_files = ['README.md'] s.extra_rdoc_files = ['README.md']
s.files = %w(README.md LICENSE Rakefile) + Dir.glob("lib/**/*") s.files = %w(README.md LICENSE Rakefile) + Dir.glob("lib/**/*")
s.homepage = 'https://github.com/ruby-x/rubyx-object-file' s.homepage = 'https://github.com/ruby-x/rx-file'
s.license = 'MIT' s.license = 'MIT'
s.require_paths = ['lib'] s.require_paths = ['lib']
s.summary = 'Rubyx object file is the object file format of rubyx. It is a sort of condensed yaml' s.summary = 'Rubyx object file is the object file format of rubyx. It is a sort of condensed yaml'

View File

@ -13,7 +13,7 @@ require 'rubyx-object-file'
module Checker module Checker
def check should def check should
out = Sof.write(@out) out = RxFile.write(@out)
same = (should == out) same = (should == out)
puts "Shouldda\n#{out}" unless same puts "Shouldda\n#{out}" unless same
assert_equal should , out assert_equal should , out
@ -28,4 +28,4 @@ class ObjectWithAttributes
attr_accessor :extra , :volotile attr_accessor :extra , :volotile
end end
OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)" OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)"
Sof::Volotile.add(ObjectWithAttributes , [:volotile]) RxFile::Volotile.add(ObjectWithAttributes , [:volotile])

View File

@ -1,6 +1,6 @@
require_relative "helper" require_relative "helper"
class BasicSof < MiniTest::Test class BasicRxFile < MiniTest::Test
include Checker include Checker
def test_true def test_true

View File

@ -9,17 +9,17 @@ class FailValue
end end
end end
class BasicValue < FailValue class BasicValue < FailValue
def to_sof def to_rxf
"'#{@name}'" "'#{@name}'"
end end
end end
class ObjectSof < MiniTest::Test class ObjectRxFile < MiniTest::Test
include Checker include Checker
def test_to_sof def test_to_rxf
assert_raises NoMethodError do assert_raises NoMethodError do
Sof::Writer.write(FailValue.new("name")) RxFile::Writer.write(FailValue.new("name"))
end end
end end

View File

@ -4,7 +4,7 @@ class NamedRef < ObjectWithAttributes
super() super()
@name = name @name = name
end end
def sof_reference_name def rxf_reference_name
@name.to_s @name.to_s
end end
end end

View File

@ -1,6 +1,6 @@
require_relative "helper" require_relative "helper"
class ObjectSof < MiniTest::Test class ObjectRxFile < MiniTest::Test
include Checker include Checker
def test_simple_object def test_simple_object