start a new ruby layer to do the to_vool conversion
the "normalization" is getting more and more complicated and is not tested And it seems i really don't like working with the untyped ast
This commit is contained in:
55
lib/ruby/statements.rb
Normal file
55
lib/ruby/statements.rb
Normal file
@ -0,0 +1,55 @@
|
||||
module Ruby
|
||||
class Statements < Statement
|
||||
attr_reader :statements
|
||||
def initialize(statements)
|
||||
@statements = statements
|
||||
end
|
||||
|
||||
def empty?
|
||||
@statements.empty?
|
||||
end
|
||||
def single?
|
||||
@statements.length == 1
|
||||
end
|
||||
def first
|
||||
@statements.first
|
||||
end
|
||||
def last
|
||||
@statements.last
|
||||
end
|
||||
def length
|
||||
@statements.length
|
||||
end
|
||||
def [](i)
|
||||
@statements[i]
|
||||
end
|
||||
def <<(o)
|
||||
@statements << o
|
||||
self
|
||||
end
|
||||
|
||||
# create mom instructions
|
||||
def to_mom( compiler )
|
||||
raise "Empty list ? #{statements.length}" if empty?
|
||||
stats = @statements.dup
|
||||
flat = stats.shift.to_mom(compiler)
|
||||
while( nekst = stats.shift )
|
||||
flat.append nekst.to_mom(compiler)
|
||||
end
|
||||
flat
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
block.call(self)
|
||||
@statements.each{|a| a.each(&block)}
|
||||
end
|
||||
|
||||
def to_s(depth = 0)
|
||||
at_depth(depth , *@statements.collect{|st| st.to_s(depth)})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ScopeStatement < Statements
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user