├── Makefile ├── README.md ├── bff.c └── samples ├── mandelbrot.b └── random.b /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS += -O3 -ansi -DNDEBUG -Wall 2 | 3 | all: bff 4 | strip bff 5 | 6 | bff: 7 | 8 | install: bff 9 | cp bff /usr/bin 10 | 11 | clean: 12 | rm bff 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bff 1.0.7 2 | ========= 3 | 4 | Moderately-optimizing brainfuck interpreter 5 | 6 | http://swapped.cc/bff 7 | 8 | = 9 | To build with GNU tools run 10 | make 11 | 12 | To install in /usr/bin (not sure why you'd be wanting this though) 13 | make install 14 | 15 | To clean up the build files 16 | make clean 17 | 18 | = 19 | 1.0.7 - Aug 09, 2018 20 | fixed an issue in preprocessing stage that caused it 21 | to ingest more bf code than there was if the bf code 22 | started with <<... or >>... sequence. This lead to a 23 | heap corruption with variable consequences. kudos to 24 | Alex Stefanov for reporting this. 25 | 26 | 1.0.6 - Apr 27, 2015 27 | added special handling for [-] and [+] 28 | 29 | 1.0.5 - Dec 10, 2012 30 | fixed grow() as per Mitch Schwartz note 31 | 32 | 1.0.4 - Aug 01, 2011 33 | fixed xalloc() to zero newly allocated blocks 34 | 35 | 1.0.3.1 - Aug 02, 2004 36 | fixed a bug where programs starting with < or > command 37 | were not handled properly 38 | 39 | 1.0.3 - Jul 29, 2004 40 | further optimized the main loop, now runs twice as fast 41 | 42 | 1.0.2 - Apr 27, 2004 43 | made it compilable under MSVC 44 | added -Wall to Makefile 45 | added missing string.h include 46 | 47 | 1.0.1 - Apr 27, 2004 48 | the cell array is now dynamically grown when exhausted; 49 | the input may be read from the file 50 | 51 | 1.0.0 - Apr 26, 2004 52 | an initial public release 53 | 54 | ========================================================================== 55 | Copyright (c) 2004-12, Alex Pankratov (ap@swapped.cc). All rights reserved. 56 | 57 | -------------------------------------------------------------------------------- /bff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Alex Pankratov. All rights reserved. 3 | * 4 | * Moderately-optimizing (tm) Brainfuck interpreter, 1.0.7 5 | * http://swapped.cc/bff 6 | */ 7 | 8 | /* 9 | * The program is distributed under terms of BSD license. 10 | * You can obtain the copy of the license by visiting: 11 | * 12 | * http://www.opensource.org/licenses/bsd-license.php 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /* 22 | * 23 | */ 24 | int chew(char * p, int j, int * v_off); 25 | void * xalloc(void * ptr, size_t sz); 26 | void * grow(int * v, int * j, int * jmax); 27 | int getc_ext(FILE * fh); 28 | 29 | void usage(); 30 | void die(const char * msg, ...); 31 | 32 | /* 33 | * 34 | */ 35 | struct bf_op 36 | { 37 | char op; 38 | int op_arg; 39 | int p_off, p_ofx; 40 | int v_off, v_ofx; 41 | }; 42 | 43 | int main(int argc, char ** argv) 44 | { 45 | FILE * fh = stdin; 46 | char buf[1024], * p; 47 | int i, k, l, b, n, jmax; 48 | int (* input)(FILE * fh); 49 | struct bf_op * x; 50 | 51 | /* main loop variables - keep 'em in registers */ 52 | register struct bf_op * z; 53 | register int j, v_off; 54 | register int * v; 55 | 56 | if ( (argc > 1 && argv[1][0] == '-') || 57 | (argc > 2 && argv[2][0] == '-') || 58 | (argc > 3) ) 59 | usage(); 60 | 61 | /* open and read the program file */ 62 | if (argc > 1 && ! (fh = fopen(argv[1], "r"))) 63 | die("cannot open program file (%s)\n", argv[1]); 64 | 65 | n = 0; 66 | p = 0; 67 | while (! feof(fh)) 68 | { 69 | b = fread(buf, 1, sizeof buf, fh); 70 | p = xalloc(p, (n += b) + 1); 71 | memcpy(p + n - b, buf, b); 72 | } 73 | fclose(fh); 74 | 75 | /* open data file */ 76 | if (argc > 2) 77 | { 78 | if (! (fh = fopen(argv[2], "r"))) 79 | die("cannot open input data file (%s)\n", argv[2]); 80 | input = getc_ext; 81 | } 82 | else 83 | { 84 | fh = stdin; 85 | input = getc; 86 | } 87 | 88 | /* strip the comments */ 89 | for (i=j=0; i+-,.", p[i])) 91 | p[j++] = p[i]; 92 | 93 | n = j++; 94 | p[n] = 0; /* 'end of program' */ 95 | 96 | /* skip leading < > */ 97 | for (i=0; i", p[i])) 99 | break; 100 | 101 | n -= i; 102 | memmove(p, p+i, n); 103 | p[n] = 0; 104 | 105 | /* preprocess */ 106 | x = xalloc(NULL, (n+1) * sizeof(*x)); 107 | 108 | for (i=0; i': 171 | /* chew() folds these into all other ops */ 172 | default: 173 | assert(0); 174 | break; 175 | } 176 | } 177 | 178 | /* exit */ 179 | x[i].op = 'x'; 180 | 181 | /* allocate cell array - start with the moderate size */ 182 | jmax = 256; 183 | v = xalloc(NULL, jmax * sizeof(int)); 184 | 185 | /* get busy */ 186 | j = jmax / 2; 187 | 188 | z = x; 189 | v_off = 0; 190 | for (;;) 191 | { 192 | if (v_off) 193 | { 194 | j += v_off; 195 | if (j < 0 || jmax <= j) 196 | { 197 | int _j = j, _m = jmax; 198 | v = grow(v, &_j, &_m); 199 | j = _j; jmax = _m; 200 | } 201 | } 202 | 203 | v_off = z->v_off; 204 | 205 | switch (z->op) 206 | { 207 | case '+': 208 | v[j] += z->op_arg; 209 | break; 210 | case '-': 211 | v[j] -= z->op_arg; 212 | break; 213 | case 'c': 214 | if (! v[j]) 215 | { 216 | v_off = z->v_ofx; 217 | z += z->p_ofx; 218 | continue; 219 | } 220 | break; 221 | case '.': 222 | for (k=0; kop_arg; k++) 223 | /* printf("%02x", v[j]); */ 224 | putchar(v[j]); 225 | 226 | break; 227 | case ',': 228 | for (k=0; kop_arg; k++) 229 | v[j] = input(fh); 230 | break; 231 | case 'z': 232 | v[j] = 0; 233 | break; 234 | case 'x': 235 | goto _break; 236 | 237 | default: 238 | assert(0); 239 | } 240 | 241 | z += z->p_off; 242 | } 243 | _break: 244 | return 0; 245 | } 246 | 247 | /* 248 | * miscellanea 249 | */ 250 | int chew(char * p, int j, int * v_off) 251 | { 252 | for ( ; p[j]; j++) 253 | switch (p[j]) 254 | { 255 | case '<': (*v_off)--; break; 256 | case '>': (*v_off)++; break; 257 | default: 258 | goto _break; 259 | } 260 | _break: 261 | return j; 262 | } 263 | 264 | void * xalloc(void * ptr, size_t sz) 265 | { 266 | ptr = ptr ? realloc(ptr, sz) : calloc(1, sz); 267 | if (! ptr) 268 | die("out of memory (%ld)\n", sz); 269 | return ptr; 270 | } 271 | 272 | void * grow(int * v, int * j, int * jmax) 273 | { 274 | int n = *jmax; 275 | int inc = n/2; /* grow at least by half */ 276 | int pos = *j; 277 | 278 | if (pos + inc < 0) /* underflow */ 279 | inc = 3 * (0 - pos) / 2; 280 | if (n + inc < pos) /* overflow */ 281 | inc = 3 * (pos - n) / 2; 282 | 283 | v = xalloc(v, (n+inc) * sizeof(int)); 284 | 285 | if (pos < 0) 286 | { 287 | /* underflow */ 288 | memmove(v + inc, v, n * sizeof(int)); 289 | memset(v, 0, inc * sizeof(int)); 290 | *j += inc; 291 | } 292 | else 293 | { 294 | /* overflow */ 295 | memset(v + n, 0, inc * sizeof(int)); 296 | } 297 | 298 | *jmax += inc; 299 | return v; 300 | } 301 | 302 | int getc_ext(FILE * fh) 303 | { 304 | return feof(fh) ? 0 : getc(fh); 305 | } 306 | 307 | /* 308 | * boring stuff 309 | */ 310 | void usage() 311 | { 312 | fprintf(stderr, 313 | "bff: moderately-opimizing Brainfuck interpreter, 1.0.7, " 314 | "http://swapped.cc/bff\n" 315 | "Usage: bff [ [++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ 3 | >>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ 4 | <<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>> 5 | >+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>> 6 | >>>>>[-]+<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+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< 145 | <<<<<]]>>>] 146 | -------------------------------------------------------------------------------- /samples/random.b: -------------------------------------------------------------------------------- 1 | >>>++[ 2 | <++++++++[ 3 | <[<++>-]>>[>>]+>>+[ 4 | -[->>+<<<[<[<<]<+>]>[>[>>]]] 5 | <[>>[-]]>[>[-<<]>[<+<]]+<< 6 | ]<[>+<-]>>- 7 | ]<.[-]>> 8 | ] 9 | "Random" byte generator using the Rule 30 automaton. 10 | Doesn't terminate; you will have to kill it. 11 | To get x bytes you need 32x+4 cells. 12 | Turn off any newline translation! 13 | Daniel B Cristofani (cristofdathevanetdotcom) 14 | http://www.hevanet.com/cristofd/brainfuck/ --------------------------------------------------------------------------------