https://github.com/stepainpy/brainfuck
https://github.com/stepainpy/brainfuck
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stepainpy/brainfuck
- Owner: Stepainpy
- License: mit
- Created: 2025-07-12T16:48:45.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-07-20T18:58:35.000Z (8 months ago)
- Last Synced: 2025-07-20T20:30:05.300Z (8 months ago)
- Language: C
- Size: 243 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Brainfuck virtual machine
## Overview
Little Brainfuck virtual machine. Brainfuck source code convert to optimized byte-code for machine.
Support interruption via breakpoints (see [bf source](./bf.c)).
## Usage
### As standalone code
``` console
$ bf [-A] []
```
### As external part
1. compile library.
2. copy `bfconf.h`, `brainfuck.h` and library file to your project.
3. use API functions `bfa_compile`, `bfa_execute` and etc.
Minimal code example:
```c
#include
#include
#include "brainfuck.h"
const char* source = // print "brainfuck"
">++++[>++++++<-]>-[[<+++++>>+<-]>-]<<[<]>>>>-"
"-.<<<-.>>>-.<.<.>---.<<+++.>>>++.<<---.[>]<<.";
static void read(void* file, bft_cell* cell) {
int ch = fgetc(file);
*cell = ch != EOF ? ch : 0;
}
static void write(void* file, bft_cell cell) {
fputc(cell, file);
}
int main(void) {
bft_error rc = BFE_OK;
bft_program program = {0};
bft_env env = { stdin, stdout, read, write };
rc = bfa_compile(&program, source, strlen(source));
if (rc) { // error handling
fprintf(stderr, "bfa_compile(): %s\n", bfa_strerror(rc));
return 1;
}
rc = bfa_execute(&program, &env, NULL); // no breakpoints
if (rc) { // error handling
bfa_destroy(&program);
fprintf(stderr, "bfa_execute(): %s\n", bfa_strerror(rc));
return 1;
}
bfa_destroy(&program);
return 0;
}
```
## Prefix cheatsheet
| Prefix | Full name |
| :----: | :---------- |
| `t` | type |
| `a` | API |
| `d` | debug |
| `s` | stack |
| `c` | code |
| `p` | parse |
| `u` | utility |
| `i` | instruction |
| `I` | instruction |
| `E` | error |
| `M` | mask |
| `C` | constant |
| `K` | kind |
| `D` | define |