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