premature start on the salama object files, just for reading the compiled code
This commit is contained in:
parent
200228a33d
commit
90cbeddc0a
30
lib/sof/README.md
Normal file
30
lib/sof/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
### 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
|
||||||
|
can link them later.
|
||||||
|
|
||||||
|
Much few know what they include, and that is not because they are not very useful, but rather very complicated.
|
||||||
|
|
||||||
|
An object machine must off course have it's own object files, because:
|
||||||
|
|
||||||
|
- otherwise we'd have to express the object machine in c (nischt gut)
|
||||||
|
- we would be forced to read the source every time (slow)
|
||||||
|
- 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
|
||||||
|
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!!
|
||||||
|
|
||||||
|
And so this is a little start, just some outputter.
|
||||||
|
|
||||||
|
#### Direction
|
||||||
|
|
||||||
|
The way this is meant to go (planned for 2020+) was a salama core with only a sof parser (as that is soo much simpler).
|
||||||
|
|
||||||
|
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 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. Have to since by now we work on sof's. Etc . ..
|
3
lib/sof/all.rb
Normal file
3
lib/sof/all.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require_relative "members"
|
||||||
|
require_relative "array"
|
||||||
|
require_relative "occurence"
|
8
lib/sof/array.rb
Normal file
8
lib/sof/array.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Array.class_eval do
|
||||||
|
def attributes
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
def to_sof
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
53
lib/sof/members.rb
Normal file
53
lib/sof/members.rb
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
module Sof
|
||||||
|
|
||||||
|
class Members
|
||||||
|
def initialize root
|
||||||
|
@root = root
|
||||||
|
@counter = 1
|
||||||
|
@objects = {}
|
||||||
|
add(root ,0 )
|
||||||
|
end
|
||||||
|
|
||||||
|
def add object , level
|
||||||
|
if( @objects.has_key?(object) )
|
||||||
|
occurence = @objects.get(object)
|
||||||
|
occurence.level = level if occurence.level > level
|
||||||
|
else
|
||||||
|
o = Occurence.new( object , @counter , level )
|
||||||
|
@objects[object] = o
|
||||||
|
c = @counter
|
||||||
|
@counter = @counter + 1
|
||||||
|
object.attributes.each do a
|
||||||
|
val = object.send a
|
||||||
|
add(val , level + 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def write
|
||||||
|
string = ""
|
||||||
|
output string , @root
|
||||||
|
end
|
||||||
|
|
||||||
|
def output string , object
|
||||||
|
occurence = @objects[object]
|
||||||
|
indent = " " * occurence.level
|
||||||
|
string += indent
|
||||||
|
if(object.respond_to? :to_sof)
|
||||||
|
string += object.to_sof + "\n"
|
||||||
|
else
|
||||||
|
string += "!" + object.class.name + "\n"
|
||||||
|
indent += " "
|
||||||
|
object.attributes.each do a
|
||||||
|
val = object.send a
|
||||||
|
output( string , val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.write object
|
||||||
|
members = Members.new object
|
||||||
|
members.write
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
lib/sof/occurence.rb
Normal file
13
lib/sof/occurence.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module Sof
|
||||||
|
|
||||||
|
class Occurence
|
||||||
|
def initialize object , level , number
|
||||||
|
@number = number
|
||||||
|
@object = object
|
||||||
|
@level = level
|
||||||
|
end
|
||||||
|
attr_reader :object , :number
|
||||||
|
attr_accessor :level
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user