sunjay / brain-debug

The brain language debugger and visualizer
MIT License
2 stars 1 forks source link

Instruction Display and Expanded View #6

Open sunjay opened 7 years ago

sunjay commented 7 years ago

Instruction Display

The instruction display shows the currently loaded program. We currently have a very simple implementation of this that does not really do much at all.

When the interpreter is running, it can be useful to highlight the current instruction that is running while the program runs.

Something like this:

,[.>+++<]

Notice that the + instruction is bolded. (A highlight would be better but this is just an example.) That signifies that the instruction was the last one to run. This can be updated as the program goes so the user can see the effect of each instruction as well as where the interpreter is inside the program.

This is taken a step further with the expanded view.

Expanded View

Brainfuck programs are hard to read because they are extremely terse. The expanded view makes it really easy to understand the program loaded into the debugger.

The user can choose to toggle expanded view on and off. Off is the default.

An example of the expanded view:

# Explanation
1 , Read into the current cell
2 [ Jump to #9 if the current cell is zero
3 . Output the current cell
4 > Move one cell to the right
5 + Increment the current cell
6 + Increment the current cell
7 + Increment the current cell
8 < Move one cell to the left
9 ] Jump to #2 if the current cell is non-zero

Note: The #9 and #2 links are links. They are formatted as code here to get around GFM.

The #n links should scroll to and highlight instruction n. The highlight should be a different color than the highlight for the last run instruction. The last run instruction highlight should be the only highlight if both are applied to a row.

Notice that #5 is highlighted since that was the last run instruction.

During time travel debugging, the highlighted row updates to reflect the last run instruction.