Class: Nydp::ExecuteConditionalInstruction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

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

Constructor Details

#initialize(when_true, when_false) ⇒ ExecuteConditionalInstruction

Returns a new instance of ExecuteConditionalInstruction.



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

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

Instance Attribute Details

#when_falseObject (readonly)

Returns the value of attribute when_false.



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

def when_false
  @when_false
end

#when_trueObject (readonly)

Returns the value of attribute when_true.



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

def when_true
  @when_true
end

Instance Method Details

#execute(vm) ⇒ Object



10
11
12
13
14
# File 'lib/nydp/cond.rb', line 10

def execute vm
  arg = vm.pop_arg
  truth = !Nydp.NIL.is?(arg)
  vm.push_instructions (truth ? when_true : when_false), vm.peek_context
end

#inspectObject



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

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

#to_sObject



19
20
21
# File 'lib/nydp/cond.rb', line 19

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