cleanup
This commit is contained in:
parent
9f292ba618
commit
99e0c0db18
@ -1,28 +1,30 @@
|
|||||||
### Reading the code
|
### Reading the code
|
||||||
|
|
||||||
Knowing what's going on while coding salama is not so easy: Hnce the need to look at code dumps
|
Knowing what's going on while coding salama is not so easy: Hence the need to look at code dumps
|
||||||
|
|
||||||
Hence the need for a code/object file format (remeber an oo program is just objects, some data, some code, all objects)
|
Hence the need for a code/object file format (remember an oo program is just objects, some data, some code, all objects)
|
||||||
|
|
||||||
I started with yaml, which is nice in that it has a solid implementation, reads and writes, handles arbitrary objects,
|
I started with yaml, which is nice in that it has a solid implementation, reads and writes, handles arbitrary objects, handles graphs and is a sort of readable text format.
|
||||||
handles graphs and is a sort of readable text format.
|
|
||||||
|
|
||||||
But the sort of started to get to me, because 1) it's way to verbose and 2) does not allow for (easy) ordering.
|
But the sort of started to get to me, because
|
||||||
|
1) it's way to verbose (long files, object groups over many pages) and
|
||||||
|
2) does not allow for (easy) ordering.
|
||||||
Also it was placing references in weird (first seen) places.
|
Also it was placing references in weird (first seen) places.
|
||||||
|
|
||||||
To fix this i started on Sof, with an eye to expand it.
|
To fix this i started on Sof, 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
|
||||||
|
|
||||||
- more text per line, specifically objects with simle attributes to have a constructor like syntax
|
- more text per line, specifically objects with simple attributes to have a constructor like syntax
|
||||||
|
- also short versions of arrays and hashes
|
||||||
- Shorter class names (no ruby/object or even ruby/struct stuff)
|
- Shorter class names (no ruby/object or even ruby/struct stuff)
|
||||||
- references at the most shallow level
|
- references at the most shallow level
|
||||||
- a possibility to order attributes and specify attributes that should not be serialized
|
- a possibility to order attributes and specify attributes that should not be serialized
|
||||||
|
|
||||||
### Salama Object File
|
### Salama Object File
|
||||||
|
|
||||||
Ok, so we all heard about object files, it's the things compilers create so we don't have to have huge compiles and
|
Ok, so we all heard about object files, it's the things compilers create so we don't have to have
|
||||||
can link them later.
|
huge compiles and can link them later.
|
||||||
|
|
||||||
Much fewer know what they include, and that is not because they are not very useful, but rather very complicated.
|
Much fewer know what they include, and that is not because they are not very useful, but rather very complicated.
|
||||||
|
|
||||||
@ -32,8 +34,9 @@ An object machine must off course have it's own object files, because:
|
|||||||
- we would be forced to read the source every time (slow)
|
- we would be forced to read the source every time (slow)
|
||||||
- we would have no language independant format
|
- we would have no language independant format
|
||||||
|
|
||||||
And i was going to get there, juust not now. I mean i think it's a great idea to have many languages compile and run
|
And i was going to get there, juust not now. I mean i think it's a great idea to have many languages
|
||||||
on the same object machine. Not neccessarily my idea, but i haven't seen it pulled off. Not that i will.
|
compile and run on the same object machine.
|
||||||
|
Not neccessarily my idea, but i haven't seen it pulled off. Not that i will.
|
||||||
|
|
||||||
I just want to be able to read my compiled code!!
|
I just want to be able to read my compiled code!!
|
||||||
|
|
||||||
|
@ -7,3 +7,27 @@ Array.class_eval do
|
|||||||
node
|
node
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
module Sof
|
||||||
|
class ArrayNode < Node
|
||||||
|
def initialize
|
||||||
|
@children = []
|
||||||
|
end
|
||||||
|
attr_reader :children
|
||||||
|
def add c
|
||||||
|
@children << c
|
||||||
|
end
|
||||||
|
def out io , level = 0
|
||||||
|
long_out(io , level)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def long_out io , level
|
||||||
|
indent = " " * level
|
||||||
|
@children.each_with_index do |child , i|
|
||||||
|
io.write "\n#{indent}" unless i == 0
|
||||||
|
io.write "-"
|
||||||
|
child.out(io , level + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,3 +1,26 @@
|
|||||||
|
module Sof
|
||||||
|
class HashNode < Node
|
||||||
|
def initialize
|
||||||
|
@children = []
|
||||||
|
end
|
||||||
|
attr_reader :children
|
||||||
|
def add key , val
|
||||||
|
@children << [key,val]
|
||||||
|
end
|
||||||
|
def out io , level = 0
|
||||||
|
indent = " " * level
|
||||||
|
@children.each_with_index do |child , i|
|
||||||
|
key , val = child
|
||||||
|
io.write "\n#{indent}" unless i == 0
|
||||||
|
io.write "-"
|
||||||
|
key.out(io , level + 1)
|
||||||
|
io.write ": "
|
||||||
|
val.out(io , level + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Hash.class_eval do
|
Hash.class_eval do
|
||||||
def to_sof_node(writer , level)
|
def to_sof_node(writer , level)
|
||||||
node = Sof::HashNode.new()
|
node = Sof::HashNode.new()
|
||||||
@ -9,3 +32,4 @@ Hash.class_eval do
|
|||||||
node
|
node
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
module Sof
|
module Sof
|
||||||
#abstract base class for nodes in the tree
|
#abstract base class for nodes in the tree
|
||||||
class Node
|
class Node
|
||||||
|
include Util
|
||||||
# must be able to output to a stream
|
# must be able to output to a stream
|
||||||
def out io ,level
|
def out io ,level
|
||||||
raise "abstract #{self}"
|
raise "abstract #{self}"
|
||||||
@ -13,36 +14,18 @@ module Sof
|
|||||||
def initialize data
|
def initialize data
|
||||||
@data = data
|
@data = data
|
||||||
end
|
end
|
||||||
attr_accessor :data
|
attr_reader :data
|
||||||
def out io , level
|
def out io , level
|
||||||
io.write(data)
|
io.write(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ArrayNode < Node
|
|
||||||
def initialize
|
|
||||||
@children = []
|
|
||||||
end
|
|
||||||
attr_reader :children
|
|
||||||
def add c
|
|
||||||
@children << c
|
|
||||||
end
|
|
||||||
def out io , level = 0
|
|
||||||
indent = " " * level
|
|
||||||
@children.each_with_index do |child , i|
|
|
||||||
io.write "\n#{indent}" unless i == 0
|
|
||||||
io.write "-"
|
|
||||||
child.out(io , level + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class ObjectNode < Node
|
class ObjectNode < Node
|
||||||
def initialize data
|
def initialize data
|
||||||
@data = data
|
@data = data
|
||||||
@children = []
|
@children = []
|
||||||
end
|
end
|
||||||
attr_reader :children
|
attr_reader :children , :data
|
||||||
attr_accessor :data
|
|
||||||
def add k , v
|
def add k , v
|
||||||
@children << [k,v]
|
@children << [k,v]
|
||||||
end
|
end
|
||||||
@ -58,24 +41,4 @@ module Sof
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class HashNode < Node
|
|
||||||
def initialize
|
|
||||||
@children = []
|
|
||||||
end
|
|
||||||
attr_reader :children
|
|
||||||
def add key , val
|
|
||||||
@children << [key,val]
|
|
||||||
end
|
|
||||||
def out io , level = 0
|
|
||||||
indent = " " * level
|
|
||||||
@children.each_with_index do |child , i|
|
|
||||||
key , val = child
|
|
||||||
io.write "\n#{indent}" unless i == 0
|
|
||||||
io.write "-"
|
|
||||||
key.out(io , level + 1)
|
|
||||||
io.write ": "
|
|
||||||
val.out(io , level + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user