Class: ExecSInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/exec/exec_s.rb

Overview

Implements the S Combinator on the :exec stack: if the top three items on the stack are A, B, C (in top-to-bottom order), this pushes

  1. a CodeBlock containing B and C (in that order)

  2. C

  3. A

needs: 3 :exec items

pushes: 3 :exec items

Instance Attribute Summary

Attributes inherited from Instruction

#context

Instance Method Summary collapse

Methods inherited from Instruction

all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode

Constructor Details

This class inherits a constructor from Instruction

Instance Method Details

#cleanupObject



24
25
26
27
28
# File 'lib/instructions/exec/exec_s.rb', line 24

def cleanup
  pushes :exec, @s_result
  pushes :exec, @argC
  pushes :exec, @argA
end

#deriveObject



21
22
23
# File 'lib/instructions/exec/exec_s.rb', line 21

def derive  
  @s_result = CodeblockPoint.new([@argB,@argC])
end

#preconditions?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/instructions/exec/exec_s.rb', line 13

def preconditions?
  needs :exec, 3
end

#setupObject



16
17
18
19
20
# File 'lib/instructions/exec/exec_s.rb', line 16

def setup
  @argA = @context.pop(:exec)
  @argB = @context.pop(:exec)
  @argC = @context.pop(:exec)
end