Class: Nydp::Cond
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
cons, list, literal?, pair?, sig, sym, sym?
Methods included from Converter
#n2r, #r2n
Constructor Details
#initialize(cond, when_true, when_false) ⇒ Cond
Returns a new instance of Cond.
31
32
33
|
# File 'lib/nydp/cond.rb', line 31
def initialize cond, when_true, when_false
@condition, @conditional = cond, cons(ExecuteConditionalInstruction.new(when_true, when_false))
end
|
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
29
30
31
|
# File 'lib/nydp/cond.rb', line 29
def condition
@condition
end
|
#conditional ⇒ Object
Returns the value of attribute conditional.
29
30
31
|
# File 'lib/nydp/cond.rb', line 29
def conditional
@conditional
end
|
Class Method Details
.build(expressions, bindings) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/nydp/cond.rb', line 52
def self.build expressions, bindings
if expressions.is_a? Nydp::Pair
cond = Compiler.compile expressions.car, bindings
when_true = Compiler.compile expressions.cdr.car, bindings
when_false = Compiler.compile expressions.cdr.cdr.car, bindings
csig = sig(cond)
case csig
when "LEX"
Cond_LEX.build(cond, when_true, when_false)
when "SYM"
Cond_SYM.new(cond, cons(when_true), cons(when_false))
else
new(cond, when_true, when_false)
end
else
raise "can't compile Cond: #{expressions.inspect}"
end
end
|
Instance Method Details
#execute(vm) ⇒ Object
39
40
41
42
|
# File 'lib/nydp/cond.rb', line 39
def execute vm
vm.push_ctx_instructions conditional
condition.execute vm
end
|
44
45
46
|
# File 'lib/nydp/cond.rb', line 44
def inspect
"cond:#{condition.inspect}:#{conditional.inspect}"
end
|
#lexical_reach(n) ⇒ Object
35
36
37
|
# File 'lib/nydp/cond.rb', line 35
def lexical_reach n
[@condition.lexical_reach(n), @conditional.car.lexical_reach(n)].max
end
|
48
49
50
|
# File 'lib/nydp/cond.rb', line 48
def to_s
"(cond #{condition.to_s} #{conditional.to_s})"
end
|