Little Brainfuck virtual machine. Brainfuck source code convert to optimized byte-code for machine. Support interruption via breakpoints (see bf source).
$ bf <code.bf> [-A] [<inputfile>]- compile library.
- copy
bfconf.h,brainfuck.hand library file to your project. - use API functions
bfa_compile,bfa_executeand etc.
Minimal code example:
#include <stdio.h>
#include <string.h>
#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 | 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 |