class NScript::WhileNode
Public Class Methods
new(condition, body)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 695 def initialize(condition, body) @condition, @body = condition, body end
Public Instance Methods
compile_node(o)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 699 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