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)
|
2019-08-16 19:39:08 +02:00
|
|
|
case statements
|
|
|
|
when nil
|
|
|
|
@statements = []
|
|
|
|
when Array
|
|
|
|
@statements = statements
|
|
|
|
when Statement
|
|
|
|
@statements = statements.statements
|
|
|
|
when Statement
|
|
|
|
@statements = [statements]
|
|
|
|
else
|
|
|
|
raise "Invalid class, must be Statement or Array, not #{statements.class}"
|
|
|
|
end
|
2018-03-15 16:10:21 +01:00
|
|
|
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)
|
2019-08-16 19:39:08 +02:00
|
|
|
if(o.is_a?(Statements))
|
2019-08-19 10:33:12 +02:00
|
|
|
o.statements.each do |s|
|
|
|
|
raise "not a statement #{s}" unless s.is_a?(Statement)
|
|
|
|
@statements << s
|
|
|
|
end
|
2019-08-16 19:39:08 +02:00
|
|
|
else
|
2019-08-19 10:33:12 +02:00
|
|
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
2019-08-16 19:39:08 +02:00
|
|
|
@statements << o
|
|
|
|
end
|
2018-03-15 16:10:21 +01:00
|
|
|
self
|
|
|
|
end
|
2018-07-20 19:06:14 +02:00
|
|
|
def prepend(o)
|
2019-08-19 10:33:12 +02:00
|
|
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
2018-07-20 19:06:14 +02:00
|
|
|
@statements = [o] + @statements
|
|
|
|
end
|
2019-08-15 20:30:36 +02:00
|
|
|
def shift
|
|
|
|
@statements.shift
|
|
|
|
end
|
2019-08-16 13:09:56 +02:00
|
|
|
def pop
|
|
|
|
@statements.pop
|
|
|
|
end
|
2017-04-12 10:52:23 +02:00
|
|
|
|
2019-09-24 14:44:33 +02:00
|
|
|
# apply for all statements , return collection (for testing)
|
|
|
|
def to_parfait
|
|
|
|
@statements.collect{|s| s.to_parfait}
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
# to_slot all the statements. Append subsequent ones to the first, and return the
|
2018-11-03 01:27:46 +01:00
|
|
|
# first.
|
|
|
|
#
|
2019-10-03 19:55:41 +02:00
|
|
|
# For ClassStatements this creates and returns a SlotMachineCompiler
|
2018-11-03 01:27:46 +01:00
|
|
|
#
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot( 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
|
2019-10-03 19:55:41 +02:00
|
|
|
first = stats.shift.to_slot(compiler)
|
2018-06-30 18:20:17 +02:00
|
|
|
while( nekst = stats.shift )
|
2019-10-03 19:55:41 +02:00
|
|
|
next_mom = nekst.to_slot(compiler)
|
2019-09-30 16:09:13 +02:00
|
|
|
first.append next_mom
|
2018-03-15 16:03:38 +01:00
|
|
|
end
|
2018-11-03 01:27:46 +01:00
|
|
|
first
|
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-07-03 21:18:19 +02:00
|
|
|
def to_s(depth = 0)
|
2019-09-19 19:48:21 +02:00
|
|
|
at_depth(depth , @statements.collect{|st| st.to_s(depth)}.join("\n"))
|
2018-07-03 21:18:19 +02:00
|
|
|
end
|
|
|
|
|
2017-04-02 12:24:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class ScopeStatement < Statements
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
|
|
|
end
|