abtrout / go-brainfuck-yourself

A Brainfuck interpreter that I wrote myself in Go
0 stars 0 forks source link

Accumulate list of commands executed rather than program to execute #3

Closed abtrout closed 10 months ago

abtrout commented 1 year ago

Read from stream, convert to internal Brainfuck bytecode and execute as we go. This allows for easier unit testing, and makes interactive/non-interactive execution use the same interface.

Loop construction should be similar from #2.

abtrout commented 1 year ago

This is in progress.

One complexity is dealing with loops: since we Eval commands one byte at a time, we could Eval an [ on a cell that has zero value. In this situation, the [ instruction tells us to jump to matching ] but we don't know that yet. Could handle this by keeping internal state that indicates if we're jumping out of a loop, probably requiring maintaining the index of the opening [ to deal with nested loops.

abtrout commented 11 months ago

We simply delay evaluation when there are partial loops. PR incoming!