class Nydp::Cond
Attributes
condition[R]
conditional[R]
Public Class Methods
build(expressions, bindings, ns)
click to toggle source
# File lib/nydp/cond.rb, line 47 def self.build expressions, bindings, ns if expressions.is_a? Nydp::Pair cond = Compiler.compile expressions.car, bindings, ns when_true = Compiler.compile expressions.cdr.car, bindings, ns when_false = Compiler.compile expressions.cdr.cdr.car, bindings, ns csig = sig(cond) xsig = "#{sig(cond)}_#{sig(when_true)}_#{sig(when_false)}" # case csig # when "LEX" # Cond_LEX.build(cond, when_true, when_false) # when "SYM" # Cond_SYM.new(cond, when_true, when_false) # else # new(cond, when_true, when_false) # end new(cond, when_true, when_false) else raise "can't compile Cond: #{expressions._nydp_inspect}" end end
new(cond, when_true, when_false)
click to toggle source
# File lib/nydp/cond.rb, line 7 def initialize cond, when_true, when_false @condition, @when_true, @when_false = cond, when_true, when_false end
Public Instance Methods
compile_to_ruby(indent, srcs, opts=nil)
click to toggle source
# File lib/nydp/cond.rb, line 23 def compile_to_ruby indent, srcs, opts=nil if (!@when_false) || (@when_false.is_a?(Nydp::Literal) && !@when_false.expression) "#{indent}##> #{inspect.split(/\n/).join('\n')} #{indent}if (#{@condition.compile_to_ruby "", srcs}) #{@when_true.compile_to_ruby(indent + " ", srcs, cando: true)} #{indent}end" else "#{indent}##> #{inspect.split(/\n/).join('\n')} #{indent}if (#{@condition.compile_to_ruby "", srcs}) #{@when_true.compile_to_ruby(indent + " ", srcs, cando: true)} #{indent}else #{@when_false.compile_to_ruby(indent + " ", srcs, cando: true)} #{indent}end" end end
execute(vm)
click to toggle source
# File lib/nydp/cond.rb, line 15 def execute vm if (@condition.execute(vm)) @when_true.execute(vm) else @when_false.execute(vm) end end
inspect()
click to toggle source
# File lib/nydp/cond.rb, line 39 def inspect "(cond #{condition._nydp_inspect} #{@when_true._nydp_inspect} #{@when_false._nydp_inspect})" end
lexical_reach(n)
click to toggle source
# File lib/nydp/cond.rb, line 11 def lexical_reach n [@condition.lexical_reach(n), @when_true.lexical_reach(n), @when_false.lexical_reach(n)].max end
to_s()
click to toggle source
# File lib/nydp/cond.rb, line 43 def to_s "(cond #{condition.to_s} #{@when_true.to_s} #{@when_false.to_s})" end