Class: CodeReplaceNthPointInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/code/code_replace_nth_point.rb

Overview

was CODE.INSERT in Push3

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



27
28
29
# File 'lib/instructions/code/code_replace_nth_point.rb', line 27

def cleanup
  pushes :code, @result
end

#deriveObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/instructions/code/code_replace_nth_point.rb', line 11

def derive
  acceptor = NudgeProgram.new(@accept)
  raise InstructionMethodError,
    "#{self.class.to_nudgecode} cannot work with unparseable code" unless acceptor.parses?
  insertion = NudgeProgram.new(@insert)
  raise InstructionMethodError,
    "#{self.class.to_nudgecode} cannot work with unparseable code" unless insertion.parses?
  scale = acceptor.points
  which_pt = if @where < 1 || @where > scale
    (@where % acceptor.points) + 1
  else
    @where
  end
  new_tree = acceptor.replace_point(which_pt, insertion.linked_code).blueprint
  @result = ValuePoint.new("code", new_tree)
end

#preconditions?Boolean

Returns:

  • (Boolean)


2
3
4
5
# File 'lib/instructions/code/code_replace_nth_point.rb', line 2

def preconditions?
  needs :int, 1
  needs :code, 2
end

#setupObject



6
7
8
9
10
# File 'lib/instructions/code/code_replace_nth_point.rb', line 6

def setup
  @where = @context.pop_value(:int)
  @accept = @context.pop_value(:code)
  @insert = @context.pop_value(:code)
end