class NScript::RangeNode
Public Class Methods
new(from, to, exclusive=false)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 384 def initialize(from, to, exclusive=false) @from, @to, @exclusive = from, to, exclusive end
Public Instance Methods
compile_array(o)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 410 def compile_array(o) body = Expressions.wrap(LiteralNode.wrap('i')) arr = Expressions.wrap(ForNode.new(body, {:source => ValueNode.new(self)}, Value.new('i'))) ParentheticalNode.new(CallNode.new(CodeNode.new([], arr))).compile(o) end
compile_node(o)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 399 def compile_node(o) return compile_array(o) unless o[:index] idx, step = o.delete(:index), o.delete(:step) vars = "#{idx}=#{@from_var}" step = step ? step.compile(o) : '1' equals = @exclusive ? '' : '=' compare = "(#{@from_var} <= #{@to_var} ? #{idx} <#{equals} #{@to_var} : #{idx} >#{equals} #{@to_var})" incr = "(#{@from_var} <= #{@to_var} ? #{idx} += #{step} : #{idx} -= #{step})" write("#{vars}; #{compare}; #{incr}") end
compile_variables(o)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 392 def compile_variables(o) @indent = o[:indent] @from_var, @to_var = o[:scope].free_variable, o[:scope].free_variable from_val, to_val = @from.compile(o), @to.compile(o) write("#{@from_var} = #{from_val}; #{@to_var} = #{to_val};\n#{idt}") end
exclusive?()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 388 def exclusive? @exclusive end