Class: Nydp::Cond_LEX
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CondBase
#initialize, #inspect, #to_s
Methods included from Helper
#cons, #list, #literal?, #pair?, #sig, #sym, #sym?
Methods included from Converter
#n2r, #r2n
Constructor Details
This class inherits a constructor from Nydp::CondBase
Class Method Details
.build(cond, when_true, when_false) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/nydp/cond.rb', line 105
def self.build cond, when_true, when_false
tsig = sig(when_true)
fsig = sig(when_false)
cond_sig = "#{tsig}_#{fsig}"
if (cond == when_true) && (fsig == "LIT")
OR_LEX_LIT.new cond, nil, when_false
elsif (cond == when_true) && (fsig == "LEX")
OR_LEX_LEX.new cond, nil, when_false
else
case cond_sig
when "LIT_LIT"
Nydp::Cond_LEX_LIT_LIT.new(cond, when_true.expression, when_false.expression)
when "LEX_LIT"
Nydp::Cond_LEX_LEX_LIT.new(cond, when_true, when_false.expression)
when "CND_LIT"
Nydp::Cond_LEX_CND_LIT.new(cond, when_true, when_false.expression)
else
Nydp::Cond_LEX.new(cond, cons(when_true), cons(when_false))
end
end
end
|
Instance Method Details
#execute(vm) ⇒ Object
92
93
94
95
|
# File 'lib/nydp/cond.rb', line 92
def execute vm
truth = !Nydp::NIL.is?(@condition.value vm.current_context)
vm.push_ctx_instructions (truth ? @when_true : @when_false)
end
|
#lexical_reach(n) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/nydp/cond.rb', line 97
def lexical_reach n
cr = @condition.lexical_reach(n)
ct = @when_true.car.lexical_reach(n)
cf = @when_false.car.lexical_reach(n)
[cr, ct, cf].max
end
|