Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: brainfuck interpreter #5

Merged
merged 30 commits into from
Nov 6, 2024
Merged

feat: brainfuck interpreter #5

merged 30 commits into from
Nov 6, 2024

Conversation

zmalatrax
Copy link
Collaborator

@zmalatrax zmalatrax commented Oct 31, 2024

Closes #2

Initialization of the rust project (virtual workspace with two crates, one for the interpreter, to compile and generate the execution trace of a given Brainfuck program (i.e. run the program) and one for the prover, which will generate the STARK proof of the program execution with stwo)

This PR implements the Brainfuck interpreter. It has been adapted from work by @rkdud007:

  • Refactor Machine.execute() to run program with a single instruction
  • Refactor IO of Machine to take generic Read/Write rather than Stdin/Stdout - Useful for non-CLI context (testing, CI...)
  • Add unit and integration tests
  • Use of M31 for the memory values and related casting
  • Use of clap for handling args on the CLI (program filename, trace printing...)
  • Flag to print the trace or not
  • Up the memory capacity from 100 to 30,000

I've included a few Brainfuck programs found on the web, some from examples of the Esolang page, and others written by Daniel B Cristofani. The collatz program has been modified to take only one input, return the corresponding number of steps to reach 1 and terminate.

There are four different programs which outputs "Hello World!", I haven't included two others as they don't run on the interpreter.

Some key aspects to consider:

  • The memory is bounded to 30,000 cells
    It might be better to have an unbounded size (more complex) or make it configurable (preferred imo)

Memory should consist of at least 30000 cells, some existing brainfuck programs do need more so this should be configurable or unbounded.

  • Brainfuck dialect working over M31 prime finite field: values are taken in $[0..2^{31} - 1)$
    Some Brainfuck programs relying on u8 wrapping might not be working

@zmalatrax zmalatrax self-assigned this Oct 31, 2024
.trunk/trunk.yaml Outdated Show resolved Hide resolved
@zmalatrax zmalatrax merged commit 53fb010 into main Nov 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Generate Execution Trace
2 participants