Class: Nydp::ExecuteConditionalInstruction

Inherits:
Object
  • Object
show all
Extended by:
Helper
Defined in:
lib/nydp/cond.rb

Instance Method Summary collapse

Methods included from Helper

cons, list, literal?, pair?, sig, sym, sym?

Methods included from Converter

#n2r, #r2n

Constructor Details

#initialize(when_true, when_false) ⇒ ExecuteConditionalInstruction

Returns a new instance of ExecuteConditionalInstruction.



5
6
7
# File 'lib/nydp/cond.rb', line 5

def initialize when_true, when_false
  @when_true, @when_false = when_true, when_false
end

Instance Method Details

#execute(vm) ⇒ Object



13
14
15
# File 'lib/nydp/cond.rb', line 13

def execute vm
  (Nydp::NIL.is?(vm.args.pop) ? @when_false : @when_true).execute vm
end

#inspectObject



17
18
19
# File 'lib/nydp/cond.rb', line 17

def inspect
  "when_true:#{@when_true.inspect}:when_false:#{@when_false.inspect}"
end

#lexical_reach(n) ⇒ Object



9
10
11
# File 'lib/nydp/cond.rb', line 9

def lexical_reach n
  [@when_true.lexical_reach(n), @when_false.lexical_reach(n)].max
end

#to_sObject



21
22
23
# File 'lib/nydp/cond.rb', line 21

def to_s
  "#{@when_true.to_s} #{@when_false.to_s}"
end