Class: Brainfuck::AST::FwdNode

Inherits:
Object
  • Object
show all
Defined in:
lib/brainfuck/ast.rb

Instance Method Summary collapse

Instance Method Details

#bytecode(g) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/brainfuck/ast.rb', line 4

def bytecode(g)
  g.push_local 1
  g.meta_push_1
  g.meta_send_op_plus 0
  g.set_local 1

  # Check the contents of the new cell
  g.push_local 0   
  g.swap_stack
  g.send :[], 1, false

  fin = g.new_label
  g.git fin
  g.pop

  # If the cell is nil set it to 0
  g.push_local 0
  g.push_local 1
  g.meta_push_0
  g.send :[]=, 2, false

  # Otherwise, do nothing
  fin.set!
end