2017-04-01 20:28:57 +02:00
|
|
|
module Vool
|
|
|
|
class Statements < Statement
|
2018-03-15 16:10:21 +01:00
|
|
|
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
|
2017-04-12 10:52:23 +02:00
|
|
|
|
2018-03-16 08:03:11 +01:00
|
|
|
# create mom instructions
|
2018-07-05 13:02:38 +02:00
|
|
|
def to_mom( compiler )
|
2018-06-29 22:29:10 +02:00
|
|
|
raise "Empty list ? #{statements.length}" if empty?
|
2018-06-30 18:20:17 +02:00
|
|
|
stats = @statements.dup
|
2018-07-05 13:02:38 +02:00
|
|
|
flat = stats.shift.to_mom(compiler)
|
2018-06-30 18:20:17 +02:00
|
|
|
while( nekst = stats.shift )
|
2018-07-05 13:02:38 +02:00
|
|
|
flat.append nekst.to_mom(compiler)
|
2018-03-15 16:03:38 +01:00
|
|
|
end
|
|
|
|
flat
|
2017-04-08 11:10:42 +02:00
|
|
|
end
|
2017-04-09 09:14:28 +02:00
|
|
|
|
2018-03-15 12:52:56 +01:00
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
2018-03-15 16:10:21 +01:00
|
|
|
@statements.each{|a| a.each(&block)}
|
2018-03-15 12:52:56 +01:00
|
|
|
end
|
|
|
|
|
2018-03-15 17:24:03 +01:00
|
|
|
def normalize
|
2018-03-16 08:03:11 +01:00
|
|
|
if( single? )
|
|
|
|
first.normalize
|
|
|
|
else
|
|
|
|
Statements.new(@statements.collect{|s| s.normalize})
|
|
|
|
end
|
2018-03-15 17:24:03 +01:00
|
|
|
end
|
2018-07-03 21:18:19 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
at_depth(depth , *@statements.collect{|st| st.to_s(depth)})
|
|
|
|
end
|
|
|
|
|
2017-04-02 12:24:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class ScopeStatement < Statements
|
2018-03-15 17:24:03 +01:00
|
|
|
def normalize
|
2018-03-16 08:03:11 +01:00
|
|
|
if( single? )
|
|
|
|
first.normalize
|
|
|
|
else
|
|
|
|
ScopeStatement.new(@statements.collect{|s| s.normalize})
|
|
|
|
end
|
2018-03-15 17:24:03 +01:00
|
|
|
end
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
|
|
|
end
|