Class: StyleScript::UntilNode
Overview
A until loop, the only sort of low-level loop exposed by StyleScript. From it, all other loops can be manufactured.
Constant Summary
Constants inherited from Node
Instance Method Summary collapse
- #compile_node(o) ⇒ Object
-
#initialize(condition, body) ⇒ UntilNode
constructor
A new instance of UntilNode.
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write
Constructor Details
#initialize(condition, body) ⇒ UntilNode
Returns a new instance of UntilNode.
820 821 822 |
# File 'lib/style_script/nodes.rb', line 820 def initialize(condition, body) @condition, @body = condition, body end |
Instance Method Details
#compile_node(o) ⇒ Object
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
# File 'lib/style_script/nodes.rb', line 824 def compile_node(o) returns = o.delete(:return) top = o.delete(:top) && !returns o[:indent] = idt(1) o[:top] = true cond = @condition.compile(o) set = '' if !top rvar = o[:scope].free_variable set = "#{idt}#{rvar} = [];\n" @body = PushNode.wrap(rvar, @body) end post = returns ? "\n#{idt}return #{rvar};" : '' return write("#{set}#{idt}while (!(#{cond})) null;#{post}") if @body.nil? write("#{set}#{idt}while (!(#{cond})) {\n#{@body.compile(o)}\n#{idt}}#{post}") end |