Skip to content

Commit

Permalink
Prefer absolute index in MindFreak optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Jan 1, 2024
1 parent daa499f commit 96a1f09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MindFreak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def bytecode(program)

def optimize(bytecode, blank_tape = false)
# Dead code elimination
bytecode.shift(bytecode[0][-1]+1) if blank_tape and bytecode[0][0] == JUMP and not bytecode[1][0] == INCREMENT && bytecode[2][0] == JUMPBACK
bytecode.shift(bytecode[0][1]+1) if blank_tape and bytecode[0][0] == JUMP and not bytecode[1][0] == INCREMENT && bytecode[2][0] == JUMPBACK
clear = [INCREMENT, 0, nil, true]
memory = Hash.new(0)
i = -1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ The bytecode generated is an Array of Arrays and differ from the basic to the op

The basic bytecode is described by the tuple ``[instruction, argument]``, in which:
- **instruction** corresponds to the byte value of each instruction char used in BrainFuck;
- **argument** corresponds to the amount of times this instruction is used or the index to jump in case of <kbd>[</kbd> or <kbd>]</kbd>.
- **argument** corresponds to the amount of times this instruction is used or the jump index in case of <kbd>[</kbd> or <kbd>]</kbd>.

The extended bytecode adds a multiply instruction, defined by <kbd>*</kbd>, and more information to each bytecode.
It is described by the tuple ``[instruction, argument, offset, assign, multiplier]``, in which:
Expand Down

0 comments on commit 96a1f09

Please sign in to comment.