├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README-TESTING.txt ├── README.md ├── bf.vim ├── bf2any ├── .gitignore ├── GNUmakefile ├── Makefile ├── bf2ada.c ├── bf2any.c ├── bf2any.h ├── bf2any_ex.h ├── bf2asmjs.c ├── bf2awk.c ├── bf2b.c ├── bf2bas.c ├── bf2bc.c ├── bf2bcd.c ├── bf2bf.c ├── bf2bn.c ├── bf2cgmp.c ├── bf2cmd.c ├── bf2cobol.c ├── bf2const.c ├── bf2crun.c ├── bf2cs.c ├── bf2csh.c ├── bf2d.c ├── bf2dc.c ├── bf2dump.c ├── bf2elf.c ├── bf2f95.c ├── bf2gas.c ├── bf2go.c ├── bf2java.c ├── bf2jit.x86.dasc ├── bf2julia.c ├── bf2ksh.c ├── bf2ksh88.c ├── bf2loop.c ├── bf2lua.c ├── bf2nav.c ├── bf2neko.c ├── bf2nickle.c ├── bf2oldsh.c ├── bf2pas.c ├── bf2perl.c ├── bf2perl6.c ├── bf2php.c ├── bf2ps1.c ├── bf2py.c ├── bf2rb.c ├── bf2rc.c ├── bf2run.c ├── bf2sh.c ├── bf2slang.c ├── bf2swift.c ├── bf2tcl.c ├── bf2tomm.c ├── bf2tsql.c ├── bf2vala.c ├── bf2whitespace.c ├── move_opt.h ├── ov_int.h └── usemktemp.c ├── bitwidth.b ├── extras ├── .gitignore ├── GNUmakefile ├── Makefile ├── README.md ├── bf.pl ├── bf.rb ├── bf.sed ├── bf2bash.sh ├── bf2c-plain.sed ├── bf2c.awk ├── bf2c.py ├── bf2c.rb ├── bf2c.sed ├── bf2c_v1.b ├── bf2c_v2.b ├── bf2lua.lua ├── bfopt.c ├── byte2byte.c ├── c-sizes.c ├── cdowhile.c ├── deadbeef.c ├── easy.c ├── hellbox-103.b ├── hydrogen.c ├── lightning.c ├── md5.gw.b ├── md5.hw.b ├── microbf.c ├── neutron.c ├── neutron.txt ├── ook.l ├── ov_int.h ├── profilebf.c ├── proton.c ├── trixy.c ├── trixy_if.c ├── txtbf.b ├── txtbf.c └── txtbf.rb ├── testing ├── Beer.b ├── Beer.out ├── Bench.b ├── Bench.out ├── BusyBeaver.b ├── BusyBeaverOverflow.b ├── Cellsize.b ├── Cellsize2.b ├── Cellsize3.b ├── Cellsize4.b ├── Cellsize5.b ├── Collatz.b ├── Collatz.in ├── Collatz.out ├── Copyrights ├── Counter.b ├── Counter.out ├── EasyOpt.b ├── Endtest.b ├── Endtest.in ├── Euler1-orig.b ├── Euler1.b ├── Euler1.out ├── Euler5-orig.b ├── Euler5.b ├── Euler5.out ├── Factor.b ├── Factor.in ├── Factor.out ├── Golden.b ├── Golden.out ├── Hanoi.b ├── Hanoi.out ├── Hello.b ├── Hello.out ├── Hello2.b ├── Hello2.out ├── Impeccable.b ├── Impeccable.out ├── Kiloseconds.b ├── Life.b ├── Life.in ├── Life.out ├── Long.b ├── Long.out ├── LostKng.b ├── LostKng.in ├── LostKng.out ├── Mandelbrot-extreme.b ├── Mandelbrot-extreme.png ├── Mandelbrot-extreme.sh ├── Mandelbrot-r64.b ├── Mandelbrot-tiny.b ├── Mandelbrot.b ├── Mandelbrot.out ├── OptimTease.b ├── OptimTease.in ├── OptimTease.out ├── OptimTease2.in ├── PIdigits-as.b ├── PIdigits-cp.b ├── PIdigits-orig.b ├── PIdigits.b ├── PIdigits.in ├── PIdigits.out ├── PIdigits2.in ├── Precalc.b ├── PrecalcBreak.b ├── Prime-multi.b ├── Prime-orig.b ├── Prime.b ├── Prime.in ├── Prime.out ├── Prime2.b ├── Prime2.in ├── Prime2.out ├── Prime8.b ├── Prime8.in ├── Prime8.out ├── Prttab.b ├── SelfInt.b ├── SelfInt.in ├── SelfInt.out ├── Skiploop.b ├── Sorry-needs-16.b ├── Sorry-needs-32.b ├── Tribit.b ├── Zozotez.b ├── Zozotez.in ├── Zozotez.out ├── al-count-0.b ├── al-count-1.b ├── al-count-2.b ├── al-count-3.b ├── awib-0.4.b ├── awib-0.4.in ├── awib-0.4.out ├── cell-max.b ├── cell-type.b ├── cells100k.b ├── cells30k.b ├── chess.b ├── cristofd-30000.b ├── cristofd-close.b ├── cristofd-endtest.b ├── cristofd-endtest.in ├── cristofd-leftmargin.b ├── cristofd-misctest.b ├── cristofd-open.b ├── cristofd-rightmargin.b ├── cristofd-tests.txt ├── fibint.b ├── fibint.out ├── numwarp.b ├── numwarp.in ├── numwarp.out ├── oobrain.b ├── oobrain.out ├── squaresums.b ├── squaresums.out ├── too-slow.b ├── too-slow.out ├── utm.b └── utm.in ├── tools ├── README ├── dynasm │ ├── .gitignore │ ├── README │ ├── bitops.lua │ ├── dasm_arm.h │ ├── dasm_arm.lua │ ├── dasm_mips.h │ ├── dasm_mips.lua │ ├── dasm_ppc.h │ ├── dasm_ppc.lua │ ├── dasm_proto.h │ ├── dasm_x64.lua │ ├── dasm_x86.h │ ├── dasm_x86.lua │ ├── dynasm │ ├── dynasm.lua │ └── minilua.c ├── fgmp-1.0b5 │ ├── Index.txt │ ├── Makefile │ ├── gmp.c │ ├── gmp.h │ └── notes ├── lightning.h └── lightning │ ├── asm-common.h │ ├── core-common.h │ ├── fp-common.h │ ├── funcs-common.h │ ├── i386 │ ├── asm.h │ ├── core.h │ ├── fp.h │ └── funcs.h │ ├── ppc │ ├── asm.h │ ├── core.h │ ├── fp.h │ └── funcs.h │ └── sparc │ ├── asm.h │ ├── core.h │ ├── fp.h │ └── funcs.h ├── tritium ├── .gitattributes ├── .gitignore ├── GNUmakefile ├── Makefile ├── README.md ├── bfi.be.def ├── bfi.bf.c ├── bfi.bf.h ├── bfi.c ├── bfi.ccode.c ├── bfi.ccode.h ├── bfi.cpp.c ├── bfi.cpp.h ├── bfi.dasm.h ├── bfi.dasm.x86.dasc ├── bfi.dd.c ├── bfi.dd.h ├── bfi.execloop.h ├── bfi.gmp.c ├── bfi.gmp.h ├── bfi.gnulit.c ├── bfi.gnulit.h ├── bfi.nasm.c ├── bfi.nasm.h ├── bfi.run.h ├── bfi.runarray.c ├── bfi.runarray.h ├── bfi.tree.h ├── bfi.version.c ├── big_int.h ├── clock.c ├── clock.h ├── gmp.c ├── gmp.h ├── hashmem.c ├── hashmem.h ├── md5.c ├── md5.h ├── opt_bfbasic.c ├── opt_runner.c ├── opt_runner.h ├── ov_int.h ├── ov_long.h ├── taperam.c └── version.sh ├── trivial_substitutions ├── Hello_world.bewbs ├── README.md ├── bbf2bfrle.c ├── blub.pl ├── heartf2bf.rb ├── k-on-fuck.pl ├── malbrain.sed ├── ook.pl ├── petooh.rb ├── pikalang.rb ├── pogaack.pl ├── spoon.rb ├── xqt-abcd.rb ├── xqt-alphuck.rb ├── xqt-assfuck.rb ├── xqt-baby.rb ├── xqt-bf.pl ├── xqt-bf.rb ├── xqt-bf2.rb ├── xqt-bfl.rb ├── xqt-bfwide.rb ├── xqt-blub.rb ├── xqt-bwee.rb ├── xqt-cga.rb ├── xqt-chris.rb ├── xqt-compbf.rb ├── xqt-cupid.rb ├── xqt-developers.rb ├── xqt-df.rb ├── xqt-dotty.rb ├── xqt-excon.rb ├── xqt-flufflepuff.rb ├── xqt-h.rb ├── xqt-heartf.rb ├── xqt-iuab.rb ├── xqt-jr.rb ├── xqt-la-wea.rb ├── xqt-meep.rb ├── xqt-mini.rb ├── xqt-minimal.rb ├── xqt-newbiefuck.rb ├── xqt-nice.rb ├── xqt-nonima.rb ├── xqt-omam.rb ├── xqt-ook.rb ├── xqt-penis.rb ├── xqt-pikalang.rb ├── xqt-pluso.rb ├── xqt-pogaack.rb ├── xqt-qqq.rb ├── xqt-rev9.rb ├── xqt-shish.rb ├── xqt-tapelang.rb ├── xqt-ternary.rb ├── xqt-tick.rb ├── xqt-tmcc.rb ├── xqt-train.rb ├── xqt-wooloo.rb ├── xqt-yo.rb ├── xqt-zzz.rb └── zero.rb └── umueller ├── README ├── bfc ├── bfc.asm ├── bfi ├── bfi.c └── src ├── atoi.b ├── div10.b ├── hello.b ├── mul10.b ├── prime.b └── varia.b /.gitattributes: -------------------------------------------------------------------------------- 1 | # Attributes for github's "Linguist" stats 2 | *.awk linguist-language=awk 3 | tools/** linguist-vendored 4 | testing/*.b linguist-vendored 5 | testing/*.out linguist-generated 6 | 7 | testing/Cellsize.b -linguist-vendored 8 | testing/Cellsize2.b -linguist-vendored 9 | testing/Cellsize3.b -linguist-vendored 10 | testing/Cellsize4.b -linguist-vendored 11 | testing/Cellsize5.b -linguist-vendored 12 | testing/Counter.b -linguist-vendored 13 | testing/EasyOpt.b -linguist-vendored 14 | testing/Endtest.b -linguist-vendored 15 | testing/Hello.b -linguist-vendored 16 | testing/Hello2.b -linguist-vendored 17 | testing/Precalc.b -linguist-vendored 18 | testing/PrecalcBreak.b -linguist-vendored 19 | testing/Prttab.b -linguist-vendored 20 | testing/Skiploop.b -linguist-vendored 21 | testing/Tribit.b -linguist-vendored 22 | testing/al-count-1.b -linguist-vendored 23 | testing/al-count-2.b -linguist-vendored 24 | testing/cells100k.b -linguist-vendored 25 | testing/cells30k.b -linguist-vendored 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # https://travis-ci.org/rdebath/Brainfuck/builds 2 | language: c 3 | 4 | # Select Trusty 5 | # dist: trusty 6 | # sudo: false 7 | group: beta 8 | 9 | arch: 10 | - amd64 11 | - s390x 12 | - ppc64le 13 | - arm64 14 | 15 | # addons: 16 | # apt: 17 | # packages: 18 | # - lua5.1 19 | # - liblua5.1-bitop0 20 | # - g++-multilib 21 | 22 | install: 23 | - "if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y g++-multilib ||: ; fi" 24 | - "if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y liblua5.3-bitop0 lua5.3 ||: ; fi" 25 | - "if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y liblua5.2-bitop0 lua5.2 ||: ; fi" 26 | - "if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -y liblua5.1-bitop0 lua5.1 ||: ; fi" 27 | 28 | os: 29 | - linux 30 | - osx 31 | 32 | compiler: 33 | - gcc 34 | - clang 35 | 36 | env: 37 | - 38 | - TARGET_ARCH=-m32 39 | - TARGET_ARCH=-mx32 40 | 41 | jobs: 42 | exclude: 43 | - 44 | os: linux 45 | compiler: clang 46 | env: TARGET_ARCH=-mx32 47 | - 48 | os: osx 49 | env: TARGET_ARCH=-m32 50 | - 51 | os: osx 52 | env: TARGET_ARCH=-mx32 53 | - 54 | arch: s390x 55 | os: osx 56 | - 57 | arch: s390x 58 | env: TARGET_ARCH=-m32 59 | - 60 | arch: s390x 61 | env: TARGET_ARCH=-mx32 62 | - 63 | arch: ppc64le 64 | os: osx 65 | - 66 | arch: ppc64le 67 | env: TARGET_ARCH=-m32 68 | - 69 | arch: ppc64le 70 | env: TARGET_ARCH=-mx32 71 | - 72 | arch: arm64 73 | os: osx 74 | - 75 | arch: arm64 76 | env: TARGET_ARCH=-m32 77 | - 78 | arch: arm64 79 | env: TARGET_ARCH=-mx32 80 | 81 | # Only run the tests if the exe was built. 82 | script: 83 | - make CC="$CC" -C tritium 84 | - make CC="$CC" HAVE_TCL_H= -C bf2any 85 | - make CC="$CC" -C extras 86 | - test ! -x tritium/bfi.out || tritium/bfi.out -v bitwidth.b 87 | - test ! -x tritium/bfi.out || tritium/bfi.out -v -rc bitwidth.b 88 | - test ! -x bf2any/bf2jit || bf2any/bf2jit bitwidth.b 89 | - test ! -x bf2any/bf2crun || bf2any/bf2crun -v bitwidth.b 90 | - test ! -x bf2any/bf2run || bf2any/bf2run bitwidth.b 91 | - test ! -x tritium/bfi.out || tritium/bfi.out testing/Mandelbrot.b 92 | - test ! -x tritium/bfi.out || tritium/bfi.out testing/Prime.b < testing/Prime.in 93 | - test ! -x tritium/bfi.out || tritium/bfi.out -h || true 94 | - test ! -x extras/c-sizes || extras/c-sizes 95 | 96 | # - "\"$CC\" -dM -E -x c - 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 39 | #define UNUSED __attribute__ ((__unused__)) 40 | 41 | #ifdef _POSIX_VERSION 42 | #if (_XOPEN_VERSION+0) < 500 && _POSIX_VERSION < 200809L 43 | #if !defined(strdup) 44 | #define strdup(str) \ 45 | ({char*_s=(str);int _l=strlen(_s)+1;void*_t=malloc(_l);if(_t)memcpy(_t,_s,_l);_t;}) 46 | #endif 47 | #endif 48 | #endif 49 | 50 | #else 51 | #define UNUSED 52 | #ifndef __attribute__ 53 | #define __attribute__(__ignored__) 54 | #endif 55 | #endif 56 | -------------------------------------------------------------------------------- /bf2any/bf2any_ex.h: -------------------------------------------------------------------------------- 1 | #include "bf2any.h" 2 | #include "ov_int.h" 3 | 4 | void outopt(int ch, int count); 5 | void outcmd(int ch, int count); 6 | void add_string(int ch); 7 | void flush_string(void); 8 | 9 | struct mem { struct mem *p, *n; int is_set; int v; int cleaned, cleaned_val;}; 10 | extern struct mem *tape; 11 | 12 | extern int disable_init_optim; 13 | extern int tape_is_all_blank; 14 | void outtxn(int ch, int count); 15 | 16 | extern struct be_interface_s be_interface; 17 | -------------------------------------------------------------------------------- /bf2any/bf2b.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "bf2any.h" 6 | 7 | /* 8 | * B translation from BF, runs at about 640,000,000 instructions per second. 9 | * 10 | * Compiled using ABC -- https://github.com/aap/abc 11 | */ 12 | 13 | static int ind = 1; 14 | #define prv(s,v) printf("%*s" s "\n", ind*4, "", (v)) 15 | #define pr(s) printf("%*s" s "\n", ind*4, "") 16 | 17 | static gen_code_t gen_code; 18 | struct be_interface_s be_interface = {.gen_code=gen_code}; 19 | 20 | static void print_string(char * str); 21 | 22 | static void 23 | gen_code(int ch, int count, char * strn) 24 | { 25 | switch(ch) { 26 | case '!': 27 | printf( "%s%d%s", 28 | "t[",tapesz,"];\n" 29 | "main()\n{\n" 30 | " extrn t;\n" 31 | " auto v;\n" 32 | ); 33 | if (tapeinit) 34 | printf( "%s%d%s", " t =+ ",tapeinit,";\n"); 35 | break; 36 | case '~': 37 | pr("return(0);"); 38 | printf("}\n"); 39 | break; 40 | 41 | case 'X': 42 | /* Note: FD2 is Unix specific (works with ABC's brt.s ) */ 43 | pr("write(2, \"Infinite Loop*n\", 14);"); 44 | pr("return(1);"); 45 | break; 46 | 47 | case '=': prv("*t = %d;", count); break; 48 | case 'B': 49 | if(bytecell) pr("*t =& 0377;"); 50 | pr("v = *t;"); 51 | break; 52 | case 'M': prv("*t =+ v * %d;", count); break; 53 | case 'N': prv("*t =- v * %d;", count); break; 54 | case 'S': pr("*t =+ v;"); break; 55 | case 'T': pr("*t =- v;"); break; 56 | case '*': pr("*t =* v;"); break; 57 | case '/': pr("*t =/ v;"); break; 58 | case '%': pr("*t =%% v;"); break; 59 | 60 | case 'C': prv("*t = v * %d;", count); break; 61 | case 'D': prv("*t = -v * %d;", count); break; 62 | case 'V': pr("*t = v;"); break; 63 | case 'W': pr("*t = -v;"); break; 64 | 65 | case '+': prv("*t =+ %d;", count); break; 66 | case '-': prv("*t =- %d;", count); break; 67 | case '>': prv("t =+ %d;", count); break; 68 | case '<': prv("t =- %d;", count); break; 69 | case '.': pr("putchar(*t & 0377);"); break; 70 | case ',': 71 | pr("*t = getchar();"); 72 | break; 73 | case '"': print_string(strn); break; 74 | 75 | case '[': 76 | if(bytecell) pr("*t =& 0377;"); 77 | pr("while( *t != 0 ) {"); 78 | ind++; 79 | break; 80 | case ']': 81 | if(bytecell) pr("*t =& 0377;"); 82 | ind--; 83 | pr("}"); 84 | break; 85 | 86 | case 'I': 87 | if(bytecell) pr("*t =& 0377;"); 88 | pr("if( *t != 0 ) {"); 89 | ind++; 90 | break; 91 | case 'E': 92 | ind--; 93 | pr("}"); 94 | break; 95 | } 96 | } 97 | 98 | static void 99 | print_string(char * str) 100 | { 101 | char buf[256]; 102 | int badchar = 0; 103 | size_t outlen = 0; 104 | 105 | if (!str) return; 106 | 107 | for(;; str++) { 108 | if (outlen && (*str == 0 || badchar || outlen > sizeof(buf)-8)) 109 | { 110 | buf[outlen] = 0; 111 | prv("putstr(\"%s\");", buf); 112 | outlen = 0; 113 | } 114 | if (badchar) { 115 | prv("putchar(%d);", badchar); 116 | badchar = 0; 117 | } 118 | if (!*str) break; 119 | 120 | if (*str >= ' ' && *str <= '~' && *str != '\'' && *str != '\"' && *str != '*') { 121 | buf[outlen++] = *str; 122 | } else if (*str == '\'' || *str == '\"' || *str == '*') { 123 | buf[outlen++] = '*'; 124 | buf[outlen++] = *str; 125 | } else if (*str == '\n') { 126 | buf[outlen++] = '*'; 127 | buf[outlen++] = 'n'; 128 | } else if (*str == '\t') { 129 | buf[outlen++] = '*'; 130 | buf[outlen++] = 't'; 131 | } else { 132 | badchar = (*str & 0xFF); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /bf2any/move_opt.h: -------------------------------------------------------------------------------- 1 | 2 | static inline void 3 | move_opt(int *pch, int *pcount, int *pmov) 4 | { 5 | if (enable_optim) { 6 | static struct ostack { struct ostack *p; int d; } *sp; 7 | static int imov = 0; 8 | int ch = *pch; 9 | 10 | if (ch == '>') { 11 | imov += *pcount; 12 | *pch = 0; 13 | return; 14 | } else if (ch == '<') { 15 | imov -= *pcount; 16 | *pch = 0; 17 | return; 18 | } 19 | 20 | *pmov = imov; 21 | 22 | if (ch == '[' || ch == 'I') { 23 | struct ostack * np = malloc(sizeof(struct ostack)); 24 | np->p = sp; 25 | np->d = imov; 26 | sp = np; 27 | } else if (ch == ']' || ch == 'E') { 28 | struct ostack * np = sp; 29 | sp = sp->p; 30 | *pcount = imov - np->d; 31 | *pmov = imov = np->d; 32 | free(np); 33 | } else if (ch == '~') { 34 | *pcount = imov; 35 | *pmov = imov = 0; 36 | } 37 | } else { 38 | if (*pch == ']') *pcount = 0; 39 | *pmov = 0; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /bf2any/usemktemp.c: -------------------------------------------------------------------------------- 1 | /* These functions will never be used on a modern system, they only 2 | * exist for compatibility with "old crap". 3 | */ 4 | 5 | #define DISABLE_OPENMEMSTREAM 6 | #warning open_memstream not used; _POSIX_VERSION is not set high enough. 7 | #warning Beware: the replacement routine uses mktemp(). 8 | 9 | FILE * 10 | open_tempfile(void) 11 | { 12 | static char tempf[] = "/tmp/badtemp.XXXXXX"; 13 | FILE * ofd; 14 | 15 | if ( !*mktemp(tempf) ) return 0; 16 | 17 | if ( (ofd = fopen(tempf, "w+")) == 0) return 0; 18 | 19 | unlink(tempf); 20 | return ofd; 21 | } 22 | 23 | void 24 | reload_tempfile(FILE * ofd, char **ptr, size_t * sizeloc) 25 | { 26 | char *membuf = 0; 27 | int ch; 28 | size_t maxp=0, p=0; 29 | 30 | rewind(ofd); 31 | 32 | while ((ch = getc(ofd)) != EOF) { 33 | while (p + 2 > maxp) { 34 | membuf = realloc(membuf, maxp += BUFSIZ); 35 | if (!membuf) { 36 | perror("realloc"); 37 | exit(1); 38 | } 39 | } 40 | membuf[p++] = ch; 41 | } 42 | membuf[p] = 0; 43 | 44 | fclose(ofd); 45 | *ptr = membuf; 46 | *sizeloc = p; 47 | } 48 | -------------------------------------------------------------------------------- /extras/.gitignore: -------------------------------------------------------------------------------- 1 | *.tmp.* 2 | bbf2bfrle 3 | bf0k 4 | bf1k 5 | bfas 6 | bfopt 7 | byte2byte 8 | c-sizes 9 | cdowhile 10 | deadbeef 11 | easy 12 | hydrogen 13 | hydrogen0k 14 | hydrogen16 15 | hydrogen1k 16 | hydrogen32 17 | hydrogen3k 18 | hydrogen64 19 | hydrogen8 20 | hydrogenasc 21 | lightning 22 | microbf 23 | neutron 24 | ook 25 | profilebf 26 | proton 27 | qtable.h 28 | trixy 29 | txtbf 30 | -------------------------------------------------------------------------------- /extras/Makefile: -------------------------------------------------------------------------------- 1 | # The real makefile is VERY GNU make specific, so here's a POSIX makefile 2 | # to forward the basic requests. 3 | # But don't actually label it because that will break a really old make. 4 | 5 | all: 6 | gmake $@ 7 | install: 8 | gmake $@ 9 | clean: 10 | gmake $@ 11 | -------------------------------------------------------------------------------- /extras/README.md: -------------------------------------------------------------------------------- 1 | 2 | This is a collection of other BF interpreters, compilers, tools and components. 3 | 4 | The files bf2c_v1.b and bf2c_v2.b are simple BF to C converters the second does RLE (strangely). The other bf2c*.* are also converters from BF to C written in their respective languages. 5 | 6 | Many of the C programs are interpreters, mostly components that were merged into one of my major interpreters or attempts on the theme of "small but tidy". 7 | 8 | The files bf2bash.sh, bf2lua.lua and also bf.pl are interpreters that convert to the host language then use an "eval" command. 9 | 10 | The txtbf.c program takes a text input and generates a brainfuck program to output that text, in default mode it's quick and effective. In "-max" mode it's very slow and thorough. 11 | 12 | File | Description 13 | -----|------------ 14 | profilebf.c | A counting brainfuck interpreter, counts and classifies your brainfuck code. 15 | deadbeef.c | Brainfuck interpreter with TWO instruction lookahead, rather quick. 16 | trixy.c | 'Compile' brainfuck to various trivial languages and other tricksy things. 17 | txtbf.c | Encode text as a brainfuck program 18 | bf.sed | Brainfuck interpreter in SED, no input. 19 | bfopt.c | Brainfuck to brainfuck optimiser 20 | bf2c.awk | Convert Brainfuck to C, then compile and run *optimises* 21 | ook.l | Brainfuck interpreter for various trivial brainfuck substitutions including many I've never heard of. 22 | | | 23 | bf2bash.sh | Convert Brainfuck to bash and "eval" it 24 | bf2c-plain.sed | Very plain brainfuck to C in sed 25 | bf2c.py | Convert Brainfuck to plain C 26 | bf2c.sed | Lightly optimising brainfuck to C 27 | bf2c_v1.b | Unoptimised brainfuck to C in brainfuck 28 | bf2c_v2.b | Slightly optimising brainfuck to C in brainfuck 29 | bf2lua.lua | Lightly optimising brainfuck to Lua in Lua, including Lostkng.b 30 | bfdowhile.c | Brainfuck variant that seems (surprisingly) to be Turing complete 31 | bf.pl | Golfed brainfuck to Perl and eval 32 | bf.rb | Golfed brainfuck to Ruby and eval 33 | bf-trace.c | Simple brainfuck interpreter with *full* trace. 34 | byte2byte.c | Encode text as two cell brainfuck. 35 | cdowhile.c | Turing complete brainfuck variant to C and run. 36 | easy.c | [Easy](http://esolangs.org/wiki/Easy) interpreter and 16bit brainfuck. 37 | hellbox-103.b | _Pretty_ Hello world in brainfuck. 38 | hydrogen.c | Early component for tritium. 39 | lightning.c | Brainfuck interpreter using just the GNU-Lightning library (only RLE _optimisation_) 40 | md5.gw.b | Brainfuck program with same md5 hash as md5.hw.b but different output. 41 | md5.hw.b | Brainfuck program with same md5 hash as md5.gw.b but different output. 42 | microbf.c | Nice tiny brainfuck interpreter 43 | neutron.c | Testbed interpreter for brainfuck smart parser. 44 | proton.c | A simple testbed brainfuck interpreter. 45 | txtbf.b | Encode text as a brainfuck program 46 | txtbf.rb | Encode text as a brainfuck program (in one line) 47 | -------------------------------------------------------------------------------- /extras/bf.pl: -------------------------------------------------------------------------------- 1 | %c=qw(> $p++ < $p-- + D++ - D-- [ D&=255;while(D){ ] D&=255;} . print+chrD , D=ord(getc)); 2 | $/=$,;$_=<>;s/./$c{$&};/g;s[D]'$b[$p]'g;eval 3 | 4 | # http://codegolf.stackexchange.com/users/199/j-b 5 | # http://codegolf.stackexchange.com/questions/84/interpret-brainfuck?rq=1 6 | -------------------------------------------------------------------------------- /extras/bf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read. 3 | gsub(/[^\[\]+,-.<>]/,''). 4 | gsub(/\[\-\]\+*|\++|-+|>+|<+|./, Hash.new{|_, k| 5 | (k[0] == '+') ? "m[p]+="+k.length.to_s+";\n" : 6 | (k[0] == '-') ? "m[p]-="+k.length.to_s+";\n" : 7 | (k[0] == '>') ? "p+="+k.length.to_s+";\n" : 8 | (k[0] == '<') ? "p-="+k.length.to_s+";\n" : 9 | (k[0..3] == '[-]+') ? "m[p]="+(k.length-3).to_s+";\n" : "#{k}\n" 10 | }.merge({ 11 | '>' => 'p+=1;', 12 | '<' => 'p-=1;', 13 | '+' => 'm[p]+=1;', 14 | '-' => 'm[p]-=1;', 15 | '[' => '(', 16 | ']' => ')while((m[p]&=255)!=0);', 17 | '.' => 'putc m[p];', 18 | ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 19 | '[-]' => 'm[p]=0;', 20 | '#' => 'print "(p=",p,",m=",m,")\n";' 21 | })); 22 | -------------------------------------------------------------------------------- /extras/bf2c-plain.sed: -------------------------------------------------------------------------------- 1 | 1i\ 2 | #include\ 3 | char M[90000],*m=M;int main(){ 4 | s/[^]<>+,-.[]//g 5 | s/+/++*m;/g 6 | s/-/--*m;/g 7 | s/>/++m;/g 8 | s/':'++p;', 7 | '<':'--p;', 8 | '+':'++*p;', 9 | '-':'--*p;', 10 | '.':'putchar(*p);', 11 | ',':'*p=getchar();', 12 | '[':'while(*p){', 13 | ']':'}' 14 | } 15 | 16 | def translate(c): 17 | try: 18 | return b2c[c] 19 | except KeyError: 20 | return '' 21 | 22 | print('#include\n#include\n' + 23 | 'int main(){unsigned char* p=calloc(sizeof(unsigned char), 8388608);\n' + 24 | '\n'.join(translate(c) for c in open(sys.argv[1]).read()) + '\nreturn 0;}') 25 | -------------------------------------------------------------------------------- /extras/bf2c.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | # This is a slightly optimising BF to C translation. The generated C is then 3 | # compiled, loaded as a shared library and executed. 4 | require "inline" 5 | class BFCode 6 | inline do |builder| 7 | h = Hash.new{|_, k| 8 | (k[0] == "+") ? "m[p]+="+k.length.to_s+";\n" : 9 | (k[0] == "-") ? "m[p]-="+k.length.to_s+";\n" : 10 | (k[0] == ">") ? "p+="+k.length.to_s+";\n" : 11 | (k[0] == "<") ? "p-="+k.length.to_s+";\n" : 12 | (k[0..3] == "[-]+") ? "m[p]="+(k.length-3).to_s+";\n" : 13 | "#{k}\n" }.merge({ 14 | '[-]' => "m[p]=0;\n", 15 | '>' => "p++;\n", 16 | '<' => "p--;\n", 17 | '+' => "m[p]++;\n", 18 | '-' => "m[p]--;\n", 19 | '[' => "while(m[p]!=0){\n", 20 | ']' => "}\n", 21 | '.' => "putchar(m[p]);\n", 22 | ',' => "m[p]=getchar();\n"}) 23 | 24 | bfcode ="void bfprog() {\n" + 25 | "static unsigned char m[100000];\n" + 26 | "register int p=0;\n" + 27 | "setbuf(stdout, 0);\n" + 28 | ARGF.read. 29 | gsub(/[^\[\]+,-.<>]/,''). 30 | gsub(/\[\-\]\+*|\++|-+|>+|<+|./,h) + 31 | "}\n"; 32 | 33 | builder.include "" 34 | # Beware, I've put a hash of the generated code into the "prefix" 35 | # because the main argument to the "c" method is NOT part of the 36 | # cache key. 37 | builder.prefix "/*#{ Digest::MD5.hexdigest(bfcode) }*/" 38 | builder.c bfcode 39 | end 40 | end 41 | 42 | BFCode.new().bfprog(); 43 | -------------------------------------------------------------------------------- /extras/bf2c.sed: -------------------------------------------------------------------------------- 1 | #!/bin/sed -f 2 | 1i\ 3 | #include\ 4 | #define r ;m+=1\ 5 | #define l ;m-=1\ 6 | #define u ;*m+=1\ 7 | #define d ;*m-=1\ 8 | #define o ;write(1,m,1)\ 9 | #define i ;read(0,m,1)\ 10 | #define b ;while(*m){\ 11 | #define e ;}\ 12 | #define _ +1\ 13 | #define s ;*m=0\ 14 | #define z ;return 0;}\ 15 | char mem[30000];int main(){register char*m=mem; 16 | :slurp 17 | $ !{ 18 | N 19 | b slurp 20 | } 21 | s/[^]<>+,-.[]//g 22 | y/]<>+,-.[/elruidob/ 23 | s/\([lrud]\)\1/\1_f\1/g 24 | s/bde/sfu/g 25 | s/f\([lrud]\)\1/_/g 26 | s/f.//g 27 | s/$/z/ 28 | s/\(.\)/\1 /g 29 | s/[^\n]\{74\}/&\n/g 30 | s/ *\(\n\|$\)/\1/g 31 | -------------------------------------------------------------------------------- /extras/bf2c_v1.b: -------------------------------------------------------------------------------- 1 | ++++++++++++[->+++++>+++++++++>++++>+++>++++++++>+++++++++<<<<<<]>>>>-.< 2 | <---.+++++.>>>+++.>.+++++++++.<+.+.<<<<.>>>>>.<<<<.-----.>>>>--.+.<-.<<- 3 | -.<-.<++.<++++++++++.>>>>>-.<<<.>>>--.>--.<<---.<<+++++.>>>------.<<++++ 4 | +.---....>>++.<<<<---.<.>>----.+++++.++++++.>>.>>-----.<++++.>----.+++++ 5 | .<<++++++++.<<++.>>>>+.------.<+++.<+.<<+++++.<<.>>---------.>>>+.++.>.< 6 | <<<+.+.>>>--.<<<--.>>---------.>--.>-.<--.<<<.>------.>.<<--.<++.>---.<- 7 | -.<.>>>>+++.>+++.+.+.>+.<<<<+.>>>-.<---.>----.<.<+..-.<++.<.<.>>>>+++.>+ 8 | ++.+.+.>.+++++.<-.<---.>--.<.<+++..---.<.<.<.>>>>+++.>+.+.+.+++.>.<----. 9 | <---.>+.<.<+..<.<.<.>>>>+++.>--.+.+.+++.>.<----.<---.>.<.<++..<.<.<.>>>> 10 | +++.>-.+.+.+++.>.<----.<---.>++.<.<<+++++++.>>>+.+.+++.-------.<<-----.+ 11 | +.>>>++.<<<-.>.<<++++.<<.>>>>+++.>-.+.+.+++.>--.<----.<---.>+++.<.<<++.< 12 | <.>>>>+++.>----.+.+.+++.>.<----.<---.>-.<.<<------.-----.>>>+++++.<<<++. 13 | >>>----.<<-.+++++++++.-----.<----.>.+++++.--------.<<.<.>>>>+++.>-.+.+.+ 14 | ++.>.<----.<---.>---.<.<<++.>>>+++.----.+++.<<-.++++++++.----.<--.>.++++ 15 | +.--------.<<.<.>>>>+++.>.+.+.+++.>.<----.<---.>------.<.<<++.>>>++++++. 16 | <<<++.+.---.----.>>.<+++++++.<<.>+++++++++++++++.<<.>[-]>[-]>----------> 17 | >----<<[-<+<+>>]<<[->>+<<]>>>>>[-]>>>>+[-<<[-]-,+[->+>+>[-]++++++[-<<<-- 18 | ----->>>]<<<-[-<+>[-<+>[-<+>[--------------<+>[--<+>[<+>>>>[-]+++++[-<<< 19 | ----->>>]<<<----[--<+>[<[-]>>->>[-]+++++++++[-<<<++++++++++>>>]<<<[-]]]] 20 | ]]]]]>[-<<<<[->+>+<<]>[-<+>]>.[-]+<<<<<-[>>.>>>-<<<<<[->>>>+<<<<]]>>>>[- 21 | <<<<+>>>>]>[-<<<<<<<.>>>[-<+<+>>]<<[->>+<<]>>>>>>]>>]<]>>]<<<<<--.<<<<<. 22 | -------------------------------------------------------------------------------- /extras/bf2c_v2.b: -------------------------------------------------------------------------------- 1 | ++++++++++++[->++++++++++>+++>++++++++>+++++++++>++++>+++++<<<<<<]>>-.>> 2 | ---.+++++.<+++.>--.<<<---.>>+.+.>>>.<<<<<.>>>++.<++++.<<--.+.>>-----.>>- 3 | -.<<++++.>>>++.<<<<<<++++++++++.>>.>----.+.+.+++.>.<----.<---.<--.>.>>>> 4 | ---.<<-.>---.>++.<++++++.<<<<<.>>+++.>-.+.+.+++.>+.<----.<---.>>--.<<.>> 5 | >>--.<<+.>----.>++.<++++.<<<<<.>>+++.>-.+.+.+++.>+.<----.<---.<+++.>.>>> 6 | >--.<-------.<-.>+.>++.<++++++.<<<<<.>>+++.>-.+.+.+++.>+.<----.<---.>-.< 7 | .>>>>--.<-------.<-.>+++.>++.<++++.<<<<<.>>+++.>.+.+.+++.>+.<----.<---.> 8 | >+.<<.>>>>--.<<<<<++.-----.>>++++.<<++.>>----.<++++++++.>>>.-----.<--.>. 9 | +++++.<<<+.<<.>>------.>-.+.+.+++.>+.<----.<---.>++++.<.>>>>.<<++++.<--- 10 | -.----.+++.<++++++++.>>>-.----.<-----.>.+++++.<<<+.<<.>>------.>.+.+.+++ 11 | .>+.<----.<---.>---.<.>>>>.<<<<<+++.>>++++++.+.+++.-------.<++++++++.++. 12 | >>-.<<-.<++++.<.>>------.>-.+.+.+++.>+.<----.<---.>.<.>>>>.<<<<<++.<.>>+ 13 | ++.>-.+.+.+++.>.<----.<---.<-----.>.>>>------.++++++.<<<<<.>>+++.>-.+.+. 14 | +++.>.<----.<---.>------.<.>>>>.<<++++.<++++++.>++.+.---.----.<<.>>>-.>. 15 | <<<<<+++++.<.>>>--.+++++.-------.>++++.<<.>>-----.<++++.>.<----------.>> 16 | +++.---....<<++.>>>.<<----.+++++.++++++.<<.>>-------.<++++.>----.+++++.> 17 | --------.+.<<<<--.>>>++++.<++++.++.++.>+.+.<----.>--.<<.>--.+++++.------ 18 | -.>.>+.<-----.>>++.<<.<++++.>.>>--.<<<<<<.>[-]++++++++++++>[-]>[-]>[-]>[ 19 | -]>[-]<<<<<[->+++>++++++++<<]>++>+<[->>+>+<<<<+>]>>[-<<+>>]<<<------>>>> 20 | >>>>>>>>>>+[-<<<<[-]-,+[->>+>+>+<<<<<[-]++++[-<<+++++>>]++++++[->------- 21 | <]>-[--<<<----------------->>>[---------------<<<++++++++>>>[--<<<++++++ 22 | >>>[>>-<<<[-]++++<<--->>[->++++<]>[++<<<------>>>[<[-]++++++<<------->>[ 23 | ->-------<]>-----[--<<<+++>>>[>>>-<<<<[-]+++++++++<<[-]>>[->++++++++++<] 24 | >[-]]]]]]]]]>>>[-<<<<<<<[-]<[-]>>>>>>[-<<<<<-<+>>>>>>]>[<<<<<<<[->>>>>>+ 25 | <<<<<<]>>[-<+<+>>]<<[->>+<<]>[[-]>>>>>[-]>-<<<<<[->>>>+<<<<<<+>>]<<[->>+ 26 | <<]>]>>>>>>[-<<<[-]++++<<[-]>>[-<<+++++>>]<<+++>>>>>]]<<<<<<[-]<[-]<<<[- 27 | >>>+>>+<<<<<]>>>[-<<<+>>>]>>.[-]+<<<-[<<<<.>>>>>>>-<<<[->+<]]>[-<+>]>>[- 28 | <<<<<<<<.>>[->>+>+<<<]>>[-<<+>>]>>>>]>>>>>>]<<<]>>>>]<<<<<<<<<<<<--.<<<. 29 | -------------------------------------------------------------------------------- /extras/bf2lua.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | --[[ 3 | This is a self-contained BF interpreter for lua or luajit. 4 | 5 | Tape cells are set to eight bits and the interpreter uses run length encoding 6 | and re-encoding of [-] to a single token. The lua interpreter has a limit on 7 | the size of while loops, this means that a plain translation fails for very 8 | large programs; the method used by this interpreter works with all known BF 9 | programs. 10 | 11 | ]] 12 | local code = assert(io.open(assert(({...})[1],"filename argument needed"),"r")):read("*all") 13 | local ft = {} 14 | 15 | -- Head of the script we will run 16 | ft[#ft+1] = [[ 17 | -- Brainfuck code 18 | local p = 0 19 | local m = setmetatable({},{__index=function() return 0 end}) 20 | 21 | function o() io.write(string.char(m[p]%256)) io.flush() end 22 | function i() local c=io.read(1) if c then m[p] = string.byte(c) end end 23 | ]] 24 | 25 | local wt = {} 26 | local wtc = {} 27 | local sp = 0 28 | local fno = 1 29 | local tt = {} 30 | local ttc = 0 31 | 32 | -- Filter out non-command characters. 33 | code = code:gsub('[^%<%>%+%-%.%,%[%]]','') 34 | 35 | -- foreach substring ... 36 | local l = string.len( code ) 37 | local i = 0 38 | while i < l do 39 | i = i + 1 40 | local c = string.sub( code, i, i ) 41 | local m = 1 42 | while c == string.sub( code, i+m, i+m ) do m=m+1 end 43 | if ( c == "+" ) then 44 | tt[#tt+1] = "m[p]=(m[p]+"..m..")%256" 45 | i = i + m-1 46 | elseif ( c == "-" ) then 47 | tt[#tt+1] = "m[p]=(m[p]-"..m..")%256" 48 | i = i + m-1 49 | elseif ( c == ">" ) then 50 | tt[#tt+1] = "p=p+"..m 51 | i = i + m-1 52 | elseif ( c == "<" ) then 53 | tt[#tt+1] = "p=p-"..m 54 | i = i + m-1 55 | elseif ( c == "." ) then tt[#tt+1]="o()" 56 | elseif ( c == "," ) then tt[#tt+1]="i()" 57 | elseif ( c == "[" ) then 58 | sp = sp + 1 59 | wt[sp] = table.concat(tt,"\n") 60 | wtc[sp] = ttc + #tt 61 | tt = {} 62 | ttc = 0 63 | elseif ( c == "]" ) then 64 | local body = table.concat(tt,"\n") 65 | local bodyc = #tt + ttc 66 | tt = {} 67 | ttc = 0 68 | if wt[sp] ~= "" then 69 | tt[#tt+1]= wt[sp] 70 | ttc = ttc + wtc[sp] 71 | end 72 | if body == "m[p]=(m[p]-1)%256" or body == "m[p]=(m[p]+1)%256" then 73 | -- Tiny optimisation; [-] is set to zero. 74 | tt[#tt+1]= "m[p]=0" 75 | elseif bodyc < 5120 then 76 | -- Not too large loops are done directly. 77 | tt[#tt+1]= "while m[p]~=0 do" 78 | tt[#tt+1]= body 79 | ttc = ttc + bodyc 80 | tt[#tt+1]= "end" 81 | else 82 | -- When the BF code gets larger we run into lua limitations. 83 | -- Specifically the body of a while loop has a maximum size, 84 | -- fortunatly the same limit does not apply to the body of a 85 | -- function. 86 | tt[#tt+1]= "while m[p]~=0 do" 87 | tt[#tt+1]= "f"..fno.."()" 88 | tt[#tt+1]= "end" 89 | 90 | ft[#ft+1]= "function f"..fno.."()" 91 | ft[#ft+1]= body 92 | ft[#ft+1]= "end" 93 | 94 | fno = fno + 1 95 | end 96 | wt[sp] = nil 97 | sp = sp -1 98 | else 99 | -- Comment char 100 | end 101 | end 102 | 103 | local ccode = table.concat(ft,"\n").."\n--\n"..table.concat(tt,"\n") 104 | assert(loadstring(ccode))() 105 | -------------------------------------------------------------------------------- /extras/easy.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Easy Interpreter. 3 | 4 | This is not exactly as in the 'specification'. I have improved 5 | compatibility with Brainfuck by switching the the input and output 6 | characters back to 'normal' and altered the ':' command so that it 7 | ignores any non-command character. 8 | 9 | If a file is specified on the command line the program will therefor 10 | execute this as a normal brainfuck program. If no file is specified 11 | easy commands (and data) will be read from the standard input. 12 | 13 | Because of the brainfuck compatibility newlines will not terminate the 14 | program; instead you must give the ':' command an EOF indication. 15 | (or abort the program with too many ']' commands) 16 | 17 | Errors are indicated with the command return status as normal. 18 | 19 | As a brainfuck interpreter this implementation has a limited tape of 20 | 65536 cells each of which is 16bits, both cells and tape wrap. 21 | EOF uses the read() convention. This interpreter is slow. 22 | 23 | This input is "Hello World!" 24 | 25 | ++++++++++[>+++++++>++++++++++>+++>+<<<<-] 26 | >++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. 27 | 28 | As is this: 29 | 30 | ,H[.[-],e]llo World! 31 | 32 | *****************************************************************************/ 33 | #include 34 | #include 35 | 36 | FILE *f; 37 | char pgm[4000000]; 38 | unsigned short m, mem[65536]; 39 | 40 | char * bf(char * p, int r) { 41 | char * s; 42 | for(;;) { 43 | switch(*p) { 44 | case ':': {int c;if((c = getc(f)) == EOF) exit(r); *p=c;}p[1]=':'; continue; 45 | case '+': mem[m]++; break; 46 | case '-': mem[m]--; break; 47 | case '>': m++; break; 48 | case '<': m--; break; 49 | case '.': putchar(mem[m]); break; 50 | case ',': {int a=getchar(); if(a!=EOF) mem[m]=a;} break; 51 | case ']': return p; 52 | case '[': 53 | s=p+1; 54 | if(mem[m]) do p=bf(s,1); while(mem[m]); 55 | else { 56 | int b=0, c; 57 | for(p++;*p!=']'||b;) { 58 | if (*p!=':') { b += (*p=='[')-(*p==']'); p++; } 59 | else if((c = getc(f)) != EOF) *p=c,p[1]=':'; else exit(2); 60 | } 61 | } 62 | break; 63 | } 64 | if (!r) *(p=pgm)=':'; else p++; 65 | } 66 | } 67 | 68 | int main(int argc, char**argv) 69 | { 70 | if(argc==1) f=stdin; else if(!(f=fopen(argv[1],"r"))) exit(4); 71 | setbuf(stdout, 0); *pgm=':'; bf(pgm,0); exit(3); 72 | } 73 | -------------------------------------------------------------------------------- /extras/hellbox-103.b: -------------------------------------------------------------------------------- 1 | 1 []>[-]<-[>]<[+]><[][[]>[-]<-[>]<[+]><[]][]>[-]<-[>]<[+]><[] 2 | 2 []>+>+>++>++[>[->++++<<+++>]<<]>----.>->+.+++++++..+++.<+[] 3 | 3 [ This is hellbox, a 103 command Hello World ] 4 | 4 [ >+>+>++>++[>[->++++<<+++>]<<]>----.>>+.+++++++..+++ ] 5 | 5 [ .>.<<<+++++++++++++++.>>.+++.------.--------.>+.>++. ] 6 | 6 [ -- Robert de Bath -- 2014 ] 7 | 7 []>>.<<<+++++++++++++++.>+>.+++.------.--------.>+.+>++.>[] 8 | 8 []>[-]<-[>]<[+]><[][[]>[-]<-[>]<[+]><[]][]>[-]<-[>]<[+]><[] 9 | -------------------------------------------------------------------------------- /extras/md5.gw.b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdebath/Brainfuck/525d346c006ea30dfc847ae3b32ed44d44fa9925/extras/md5.gw.b -------------------------------------------------------------------------------- /extras/md5.hw.b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdebath/Brainfuck/525d346c006ea30dfc847ae3b32ed44d44fa9925/extras/md5.hw.b -------------------------------------------------------------------------------- /extras/microbf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main (int argc, char *argv[]) { 4 | unsigned short m=0; int i=0, n=0, s=0, g=0, c; 5 | char *b = calloc(s=1024,1), *p, t[65536]={0}; 6 | FILE *fp=argc>1?fopen(argv[1], "r"):stdin; 7 | while (fp && (c=getc(fp)) != EOF && (c!='!' || argc>1 || !g)) { 8 | if (n+2>s && !(b = realloc(b, s += 1024))) break; 9 | if (c) g |= ((b[n++] = c) == ','); b[n] = 0; 10 | } 11 | if(!fp || !b) { perror(argv[1]); return 1;} 12 | for(p=b;*p;p++)switch(*p) { 13 | case '>': m++;break; 14 | case '<': m--;break; 15 | case '+': t[m]++;break; 16 | case '-': t[m]--;break; 17 | case '.': putchar(t[m]);break; 18 | case ',': if((c=getchar())!=EOF)t[m]=c;break; 19 | case '[': if(t[m]==0)while((i+=(*p=='[')-(*p==']'))&&p[1])p++;break; 20 | case ']': if(t[m]!=0)while((i+=(*p==']')-(*p=='['))&&p>b)p--;break; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /extras/neutron.c: -------------------------------------------------------------------------------- 1 | /* This is the Neutron brainfuck interpreter. 2 | * It's rather small and dense, but still readable, more or less. 3 | * 4 | * Tape size: limited by RAM. 5 | * Cell size: 8bit with wraparound. 6 | * EOF processing: leave as is. 7 | * 8 | * Robert de Bath (c) 2013 GPL v2 or later. 9 | */ 10 | #include 11 | #include 12 | #include 13 | 14 | struct bfi { char cmd; struct bfi *next, *jmp; }; 15 | struct mem { unsigned char val; struct mem *next, *prev; }; 16 | 17 | int main(int argc, char **argv) 18 | { 19 | FILE * ifd; 20 | int ch; 21 | struct bfi *p=0, *n=0, *j=0, *pgm = 0; 22 | struct mem *m = calloc(1,sizeof*m); 23 | setbuf(stdout, NULL); 24 | 25 | /* Open the file from the command line or stdin */ 26 | if (argc < 2 || strcmp(argv[1], "-") == 0) ifd = stdin; 27 | else if ((ifd = fopen(argv[1], "r")) == 0) { perror(argv[1]); exit(1); } 28 | 29 | /* 30 | * For each character, if it's a valid BF command add it onto the 31 | * end of the program. If the input is stdin use the '!' character 32 | * to mark the end of the program and the start of the data, but 33 | * only if we have a complete program. The 'j' variable points 34 | * at the list of currently open '[' commands, one is matched off 35 | * by each ']'. A ']' without a matching '[' is not a legal BF 36 | * command and so is ignored. If there are any '[' commands left 37 | * over at the end they are not valid BF commands and so are ignored. 38 | */ 39 | while((ch = getc(ifd)) != EOF && (ifd!=stdin || ch != '!' || j || !pgm)) { 40 | if (ch == '<' || ch == '>' || ch == '+' || ch == '-' || 41 | ch == ',' || ch == '.' || ch == '[' || (ch == ']' && j)) { 42 | if ((n = calloc(1, sizeof*n)) == 0) { 43 | perror(argv[0]); exit(1); 44 | } 45 | if (p) p->next = n; else pgm = n; 46 | n->cmd = ch; p = n; 47 | if (n->cmd == '[') { n->jmp=j; j = n; } 48 | else if (n->cmd == ']') { 49 | n->jmp = j; j = j->jmp; n->jmp->jmp = n; 50 | } 51 | } 52 | } 53 | 54 | /* Ignore any left over '[' commands */ 55 | while(j) { p = j; j = j->jmp; p->jmp = 0; p->cmd = ' '; } 56 | 57 | if (ifd!=stdin) fclose(ifd); 58 | 59 | /* Execute the loaded BF program */ 60 | for(n=pgm; n; n=n->next) 61 | switch(n->cmd) 62 | { 63 | case '+': m->val++; break; 64 | case '-': m->val--; break; 65 | case '.': putchar(m->val); break; 66 | case ',': if((ch=getchar())!=EOF) m->val=ch; break; 67 | case '[': if (m->val == 0) n=n->jmp; break; 68 | case ']': if (m->val != 0) n=n->jmp; break; 69 | case '<': 70 | if (!(m=m->prev)) { 71 | fprintf(stderr, "%s: Hit start of tape\n", argv[0]); 72 | exit(1); 73 | } 74 | break; 75 | case '>': 76 | if (m->next == 0) { 77 | if ((m->next = calloc(1,sizeof*m)) == 0) { 78 | perror(argv[0]); exit(1); 79 | } 80 | m->next->prev = m; 81 | } 82 | m=m->next; 83 | break; 84 | } 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /extras/neutron.txt: -------------------------------------------------------------------------------- 1 | This is the Neutron brainfuck interpreter. 2 | It's rather small and dense, but still readable. 3 | 4 | It's a wrapping 8 bit interpreter, the type of the 'val' field controls 5 | this and you can change it simply by changing that type. 6 | 7 | The size of the program, tape and number of nested loops are limited only 8 | by available memory. In practice this means about 250,000,000 cells if 9 | compiled as a 32bit application. Compiling as 64bit will use twice the 10 | RAM per cell so you need at least 6Gb of FREE ram before this is likely 11 | to allow more cells. 12 | 13 | The program does not optimise the BF in any way. (It's a bit slow!) 14 | 15 | Newline processing is inherited from the C stdio library. 16 | Input leaves the current cell unchanged on EOF. 17 | The "stdout" stream is unbuffered. 18 | 19 | If the program specified on the command line there are no special controls. 20 | If the program is read from "stdin" a "!" character marks the end of the 21 | program and the start of the data. 22 | 23 | Robert de Bath 24 | 25 | -------------------------------------------------------------------------------- /extras/trixy_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NO_INTERFACE_EXT 6 | #define be_interface (*(interfaces[be_id].be)) 7 | #include "bf2any.h" 8 | 9 | #define TAPELEN 30000 10 | 11 | extern struct be_interface_s 12 | int_bf2bf, 13 | int_bf2gas, 14 | int_bf2elf, 15 | int_bf2oldsh, 16 | int_bf2rc; 17 | 18 | static struct interface_s { 19 | const char * name; 20 | struct be_interface_s *be; 21 | const char * desc; 22 | } interfaces[] = { 23 | { "bf2bf", &int_bf2bf, "Backend with various small translations" }, 24 | { "bf2gas", &int_bf2gas, "Backend to translate to assembler" }, 25 | { "bf2elf", &int_bf2elf, "Backend to translate to an ELF executable" }, 26 | { "bf2oldsh", &int_bf2oldsh, "Backend for simple Bourne shell" }, 27 | { "bf2rc", &int_bf2rc, "Backend for the Plan9 rc shell" }, 28 | { 0, 0, 0 } 29 | }; 30 | 31 | static int be_id = -1; 32 | 33 | int 34 | be_option(const char * arg) 35 | { 36 | if (strcmp(arg, "-h") == 0) { 37 | int i; 38 | fprintf(stderr, "\n"); 39 | for(i=0; interfaces[i].be; i++) { 40 | if (interfaces[i].be->gen_code == 0) continue; 41 | 42 | fprintf(stderr, " -%-11s %s\n", 43 | interfaces[i].name, 44 | interfaces[i].desc); 45 | if (interfaces[i].be->check_arg) { 46 | if ((*interfaces[i].be->check_arg)(arg)) 47 | fprintf(stderr, "\n"); 48 | } 49 | } 50 | return 1; 51 | } 52 | 53 | if (be_id < 0 || interfaces[be_id].be->gen_code == 0) { 54 | int i; 55 | if (arg[0] != '-') return 0; 56 | 57 | for(i=0; interfaces[i].be; i++) { 58 | if (strcmp(arg+1, interfaces[i].name) == 0) { 59 | be_id = i; 60 | interfaces[be_id].be->tape_len = TAPELEN; 61 | interfaces[be_id].be->fe_enable_optim = 1; 62 | return 1; 63 | } 64 | } 65 | return 0; 66 | } 67 | 68 | if (be_id < 0) return 0; 69 | 70 | if (strncmp(arg, "-M", 2) == 0 && arg[2] != 0) { 71 | int tapelen = strtoul(arg+2, 0, 10); 72 | if (tapelen < 1) tapelen = TAPELEN; 73 | tapesz = tapelen + tapeinit; 74 | return 1; 75 | } 76 | 77 | if (interfaces[be_id].be->check_arg == 0) return 0; 78 | return (*interfaces[be_id].be->check_arg)(arg); 79 | } 80 | 81 | static void 82 | outcmd(int ch, int count) 83 | { 84 | if (be_id < 0 || interfaces[be_id].be->gen_code == 0) return; 85 | 86 | (*interfaces[be_id].be->gen_code)(ch, count, 0); 87 | } 88 | 89 | void be_outcmd(int mov, int cmd, int arg) 90 | { 91 | if (mov > 0 ) 92 | outcmd('>', mov); 93 | else if (mov < 0) 94 | outcmd('<', -mov); 95 | 96 | if (cmd == 0) { 97 | be_option("+init"); 98 | outcmd('!', 0); 99 | return; 100 | } 101 | else if (cmd == '[' || cmd == ']') 102 | outcmd(cmd, 0); 103 | else if (cmd == '!') { 104 | outcmd('[', 0); 105 | outcmd('X', 1); 106 | outcmd(']', 0); 107 | } 108 | else if (cmd == '.' || cmd == ',') 109 | outcmd(cmd, 0); 110 | else if (cmd == '+' && arg < 0) 111 | outcmd('-', -arg); 112 | else if (cmd == '>' && arg < 0) 113 | outcmd('<', -arg); 114 | else 115 | outcmd(cmd, arg); 116 | } 117 | -------------------------------------------------------------------------------- /extras/txtbf.b: -------------------------------------------------------------------------------- 1 | +++++++++[>++++++++++>+++++>>+<<<<-]>+>>>+<,[<<.>.--<++.-->>[-<.>]<+++.->>.<,] 2 | -------------------------------------------------------------------------------- /extras/txtbf.rb: -------------------------------------------------------------------------------- 1 | print ARGF.read.split('').map{|i|'+'*(i.ord/10)+'[>'+'+'*10+'<-]>'+'+'*(i.ord%10)+".[-]<\n"}.join 2 | -------------------------------------------------------------------------------- /testing/Beer.b: -------------------------------------------------------------------------------- 1 | [ 99 bottles in 1752 brainfuck instructions ] 2 | [ by jim crawford (http://www.goombas.org/) ] 3 | >++++++++++[<++++++++++>-]<->>>>>+++[>+++>+++<<-]<<<<+<[>[>+ 4 | >+<<-]>>[-<<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]>> 5 | >>>>[[-]<++++++++++<->>]<-[>+>+<<-]>[<+>-]+>[[-]<->]<<<<<<<< 6 | <->>]<[>+>+<<-]>>[-<<+>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<< 7 | <[>>+>+<<<-]>>>[-<<<+>>>]++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]< 8 | <[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<<[>>+>+<<<-]>>>[-<<<+>>>]+ 9 | +++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[< 10 | <+>>[-]]<<[[-]>>>++++++++[>>++++++<<-]>[<++++++++[>++++++<-] 11 | >.<++++++++[>------<-]>[<<+>>-]]>.<<++++++++[>>------<<-]<[- 12 | >>+<<]<++++++++[<++++>-]<.>+++++++[>+++++++++<-]>+++.<+++++[ 13 | >+++++++++<-]>.+++++..--------.-------.++++++++++++++>>[>>>+ 14 | >+<<<<-]>>>>[-<<<<+>>>>]>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<< 15 | [>>>+>+<<<<-]>>>>[-<<<<+>>>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+> 16 | >]<<<[>>+<<[-]]>[>+<[-]]++>>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]< 17 | +<[[-]>-<]>[<<<<<<<.>>>>>>>[-]]<<<<<<<<<.>>----.---------.<< 18 | .>>----.+++..+++++++++++++.[-]<<[-]]<[>+>+<<-]>>[-<<+>>]+>+< 19 | [-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+>+<<<-]>>>[-<<<+>>>]++++ 20 | >+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+> 21 | >[-]]<<[[-]>++++++++[<++++>-]<.>++++++++++[>+++++++++++<-]>+ 22 | .-.<<.>>++++++.------------.---.<<.>++++++[>+++<-]>.<++++++[ 23 | >----<-]>++.+++++++++++..[-]<<[-]++++++++++.[-]]<[>+>+<<-]>> 24 | [-<<+>>]+++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++. 25 | >+++++++++[>+++++++++<-]>+++.+++++++++++++.++++++++++.------ 26 | .<++++++++[>>++++<<-]>>.<++++++++++.-.---------.>.<-.+++++++ 27 | ++++.++++++++.---------.>.<-------------.+++++++++++++.----- 28 | -----.>.<++++++++++++.---------------.<+++[>++++++<-]>..>.<- 29 | ---------.+++++++++++.>.<<+++[>------<-]>-.+++++++++++++++++ 30 | .---.++++++.-------.----------.[-]>[-]<<<.[-]]<[>+>+<<-]>>[- 31 | <<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++.[ 32 | -]<[-]>]<+<] 33 | 34 | -------------------------------------------------------------------------------- /testing/Bench.b: -------------------------------------------------------------------------------- 1 | Commands executed on 8bit: 268436272 2 | Commands executed on 16bit: 4503599627371312 3 | Commands executed on 32bit: 1267650600228229401496703206192 4 | 5 | ++++++++[->-[->-[->-[-]<]<]<] 6 | >++++++++[<++++++++++>-]<[>+>+<<-]>-.>-----.> 7 | -------------------------------------------------------------------------------- /testing/Bench.out: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /testing/BusyBeaver.b: -------------------------------------------------------------------------------- 1 | [ https://sites.google.com/site/res0001/surpassing-graham-s-number ] 2 | >+>+>+>+>+>+>+[->[>]+[->[>]+>+>+[<]+<]+<]+++++++[>+++++++++++>+<<-]>+.----.>++. 3 | -------------------------------------------------------------------------------- /testing/Cellsize.b: -------------------------------------------------------------------------------- 1 | 2 | // Calculate (16*16*16*16)^128 AKA 2^2048 3 | ++[>++++++++<-]>[>++++++++<-]>[<< 4 | +>>[-<< 5 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 6 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 7 | >>]]<+< 8 | 9 | // If that's not zero we have a bignum; probably 10 | [ 11 | // Calculate 2^112 this is too large for any floating point type 12 | // to treat as an integer 13 | [-]>[-]>[-]+++++++<< 14 | +>>[-<< 15 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 16 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 17 | >>]<< 18 | 19 | // If X and X minus one are the same we have a float type 20 | [->+>+<<] >>- [-<->] +< 21 | 22 | [[-]> 23 | 24 | // Unknown or huge cell size 25 | >>>>>[-]<[-]<[-]<[-]<[-]<[-]>++++++[<++++>-]<[>+++++>++++>+>++>+ 26 | ++<<<<<-]>>>>>.<<<<---.>+++++++.--.>++++++++.<<------.+++.>>.<<- 27 | ---.+.-.>>>---.<<---.+++++++.<.>--------.<++++.+++++++.>>.<++.++ 28 | .<-------------..+++++++.>>.<+.<----.++++++.-------.>--.>>+.>[-] 29 | <[-]<[-]<[-]<[-]< 30 | 31 | <] 32 | >[ 33 | 34 | // Floating point cells found 35 | >>>>[-]<[-]<[-]<[-]<[-]>++++[<++++>-]<[>++++>+++++++>++++++>++<< 36 | <<-]>++++++.>----.+++.>+.<+++++.>++++++++.+++++.-------.>.<<---- 37 | .-.>++.<-.++++++.>>.<------.++.+++++++..<-.>>.<------.<----.++++ 38 | ++.-------.>--.>++++++++++++++.[-]<[-]<[-]<[-]< 39 | 40 | ]< 41 | 42 | // Check for a compile problem 43 | >[-]+++++[<++++++>-]<++ >+<[->[->++<]>[-<+>]<<] 44 | # 45 | >>+<[[-]>-<]>[ 46 | >[-]<[-]>++++++++[<++++>-]<.>++++++[<++++++>-]<+.+++++++++++ 47 | ++..---.+++.[-] 48 | ]<< 49 | # 50 | <[-]] 51 | >[> 52 | // The cell is a binary type less than 2^2048; find exactly how 53 | // many bits it is 54 | >+[ [->++<]>[-<+>]<<+> ]< 55 | 56 | // and print it 57 | >>++++[<++++>-]<+[>++++++>+++++++>++>+++++<<<<-]>>>>-.<<<++.+.>- 58 | ---.>--.<<.+++++.>+.<---------.>--.--.++.<.>++.<.>--.>.<<+++.--- 59 | ----.>+.>.>[-]<[-]<[-]<[-]<< 60 | 61 | >[-]>[-]>[-]>[-]>[-]>[-]+>[-]+>[-]+>[-]+<<<<<<<<<[->>+>+<<<]>>>[ 62 | -<<<+>>>]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]+++++++++<[>>>[-]+<<[>+> 63 | [-]<<-]>[<+>-]>[<<++++++++++>>-]<<-<-]+++++++++>[<->-]<[>+<-]<[> 64 | +<-]<[>+<-]>>>[<<<+>>>-]>>>[-]<<<+++++++++<[>>>[-]+<<[>+>[-]<<-] 65 | >[<+>-]>[<<++++++++++>>>+<-]<<-<-]>>>>[<<<<+>>>>-]<<<[-]<<+>]<[> 66 | [-]<[>+<-]+++++++[<+++++++>-]<-.[-]>>[<<+>>-]<<-]< 67 | 68 | >>>[-]<[-]<[-]<[-]>++++[<++++>-]<[>++++++>+++++++>++<<<-]>++.+++ 69 | ++++.>++++.>.<<------.++.+++++++..>-.>++++++++++++++.[-]<[-]<[-] 70 | < 71 | 72 | <[-]]< 73 | 74 | [-]++++++++++.[-] 75 | -------------------------------------------------------------------------------- /testing/Cellsize3.b: -------------------------------------------------------------------------------- 1 | [ This contains a VERY simple check for the three common bit sizes. 2 | It's the original version for the Bitwidth.b test program. 3 | 4 | In addition a check has been added on the start to check 5 | for really large, or non-binary, cells. 6 | ] 7 | 8 | [-]>[-] 9 | ++++ [<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>-] 10 | <[>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<-] 11 | >[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>-] 12 | <[>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<-] 13 | >[<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>+<-] 14 | +< [>>[-<< 15 | ---------------------------------------------------------------- 16 | >>]<< 17 | 18 | [-]>[-]+++++++++++++[<++++++>-]<.>++++++++[<++++>-]<+.-.>++++++++[<----- 19 | --->-]<-.>+++++++++[<++++++>-]<-.+++++++.+++++.-------------.>++++[<++++ 20 | >-]<+.+++++++.[-]++++++++[>++++<-]>.<++++++++++[>++++++++<-]>-.+++.[-]++ 21 | ++++++[<++++>-]<.>+++++++++[<++++++++>-]<.+++++++++++++.--------------.- 22 | -.[-]++++++++[>++++<-]>.<+++++++++++[>++++++<-]>+.++.+++++++..+++++++.<+ 23 | +++++++++[>-------<-]>+.[-]++++++++++.[-]< 24 | 25 | ]>[[-]>[-]< 26 | 27 | // Calculate the value 256 and test if it's zero 28 | ++++++++[>++++++++<-]>[<++++>-] 29 | +<[>-< 30 | // Not zero so multiply by 256 again to get 65536 31 | [>++++<-]>[<++++++++>-]<[>++++++++<-] 32 | +>[> 33 | // Print "32" 34 | ++++++++++[>+++++<-]>+.-.[-]< 35 | <[-]<->] <[>> 36 | // Print "16" 37 | +++++++[>+++++++<-]>.+++++.[-]< 38 | <<[-]]] >[> 39 | // Print "8" 40 | ++++++++[>+++++++<-]>.[-]< 41 | <[-]]< 42 | // Print " bit cells\n" 43 | +++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<. 44 | >>.++.+++++++..<-.>>- 45 | Clean up used cells. 46 | [-]<[-]<[-]<[-]< 47 | ] 48 | -------------------------------------------------------------------------------- /testing/Cellsize5.b: -------------------------------------------------------------------------------- 1 | [ 2 | This cell size checker only finds binary cells. 3 | It works upto a million bits per cell. 4 | ] 5 | 6 | // Calculate (16^16)^(4*16^3) AKA 2^1048576 7 | >>++++>>+++[-<<[->++++<]>[-<++++>]>] << 8 | [<< 9 | +>>[-<< 10 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 11 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 12 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 13 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 14 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 15 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 16 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 17 | [->++++++++++++++++<]>[-<++++++++++++++++>]< 18 | >>]]<+< 19 | // If that's not zero we have a bignum; probably 20 | [> 21 | 22 | >[-]<[-]++++++[->+++++++++++++<]>.----[--<+++>]<.+.-----------.- 23 | -[--->+<]>.[---<+>]<-.[-] 24 | 25 | <[-]] 26 | >[> 27 | 28 | 29 | // "This interpreter has" 30 | [-]>[-]>[-]>[-]>[-]<<<++++[<++++>-]<+[>++++++>+++++++>++>+++++<<<<-]>>>> 31 | -.<<<++.+.>----.>--.<<.+++++.>+.<---------.>--.--.++.<.>++.<.>--.>.<<+++ 32 | .-------.>+.>>[-]<[-]<[-]<[-]< 33 | 34 | // find the number 35 | >+[ [->++<]>[-<+>]<<+> ]< 36 | 37 | // Space 38 | >> [-]>[-]++++++++[<++++>-]<.[-] << 39 | 40 | // print the number 41 | >[-]>[-]>[-]>[-]>[-]>[-]+>[-]+>[-]+>[-]+<<<<<<<<<[->>+>+<<<]>>>[ 42 | -<<<+>>>]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]+++++++++<[>>>[-]+<<[>+> 43 | [-]<<-]>[<+>-]>[<<++++++++++>>-]<<-<-]+++++++++>[<->-]<[>+<-]<[> 44 | +<-]<[>+<-]>>>[<<<+>>>-]>>>[-]<<<+++++++++<[>>>[-]+<<[>+>[-]<<-] 45 | >[<+>-]>[<<++++++++++>>>+<-]<<-<-]>>>>[<<<<+>>>>-]<<<[-]<<+>]<[> 46 | [-]<[>+<-]+++++++[<+++++++>-]<-.[-]>>[<<+>>-]<<-]< 47 | 48 | // " bit cells" 49 | >[-]<[-]++++[->++++++++<]>.[-<+++>]<++.+++++++.+++++++++++.[--- 50 | ->+<]>+++.+[-<+++>]<.++.+++++++..+++++++.[----->++<]>.[-]++++++ 51 | ++++.[-]< 52 | 53 | 54 | <[-]]< 55 | 56 | -------------------------------------------------------------------------------- /testing/Collatz.b: -------------------------------------------------------------------------------- 1 | >,[ 2 | [ 3 | ----------[ 4 | >>>[>>>>]+[[-]+<[->>>>++>>>>+[>>>>]++[->+<<<<<]]<<<] 5 | ++++++[>------<-]>--[>>[->>>>]+>+[<<<<]>-],< 6 | ]> 7 | ]>>>++>+>>[ 8 | <<[>>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<<]]<[>+<-]>] 9 | >[>[>>>>]+[[-]<[+[->>>>]>+<]>[<+>[<<<<]]+<<<<]>>>[->>>>]+>+[<<<<]] 10 | >[[>+>>[<<<<+>>>>-]>]<<<<[-]>[-<<<<]]>>>>>>> 11 | ]>>+[[-]++++++>>>>]<<<<[[<++++++++>-]<.[-]<[-]<[-]<]<, 12 | ] 13 | 14 | [The Collatz problem or 3n+1 problem is as follows. Take a natural number n. 15 | If it's even, halve it; if odd, triple it and add one. Repeat the process with 16 | the resulting number, and continue indefinitely. If n is 0, the resulting 17 | sequence is 0, 0, 0, 0... It is conjectured but not proven that for any 18 | positive integer n, the resulting sequence will end in 1, 4, 2, 1... 19 | See also http://www.research.att.com/projects/OEIS?Anum=A006577 20 | 21 | This program takes a series of decimal numbers, followed by linefeeds (10). 22 | The entire series is terminated by an EOF (0 or "no change"). For each number 23 | input, the program outputs, in decimal, the number of steps from that number 24 | to zero or one, when following the rule above. It's quite fast; on a Sun 25 | machine, it took three seconds for a random 640-digit number. 26 | 27 | One more note. This program was originally written for Tristan Parker's 28 | Brainfuck Texas Holdem contest, and won by default (it was the only entry); 29 | the version I submitted before the contest deadline is at 30 | http://www.hevanet.com/cristofd/brainfuck/oldcollatz.b 31 | 32 | Daniel B Cristofani (cristofdathevanetdotcom) 33 | http://www.hevanet.com/cristofd/brainfuck/] 34 | -------------------------------------------------------------------------------- /testing/Collatz.in: -------------------------------------------------------------------------------- 1 | 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227967823547816360093417216412199245863150302861829745557067498385054945885869269956909272107975093029553211653449872027559602364806654991198818347977535663698074265425278625518184175746728909777727938000816470600161452491921732172147723501414419735685481613611573525521334757418494684385233239073941433345477624168625189835694855620992192221842725502542568876717904946016534668049886272327917860857843838279679766814541009538837863609506800642251252051173929848960841284886269456042419652850222106611863067442786220391949450471237137869609563643719172874677646575739624138908658326459958133904780275900 2 | -------------------------------------------------------------------------------- /testing/Collatz.out: -------------------------------------------------------------------------------- 1 | 47733 2 | -------------------------------------------------------------------------------- /testing/Copyrights: -------------------------------------------------------------------------------- 1 | The programs listed below are written by me (rdebath) and so are officially 2 | relased as public domain or CC0. The other BF programs are either written 3 | by third parties or mechanical translations of such and so not covered by 4 | this note. However, unless noted within the original file, you have a good 5 | faith expectation that nobody cares, so they are public domain by default. 6 | 7 | Cellsize.b Cellsize2.b Cellsize3.b Cellsize4.b Cellsize5.b Counter.b 8 | EasyOpt.b Endtest.b Hello.b Hello2.b Precalc.b PrecalcBreak.b 9 | Prime2.b Prttab.b Skiploop.b Sorry-needs-16.b Sorry-needs-32.b 10 | Tribit.b al-count-0.b al-count-1.b al-count-2.b al-count-3.b 11 | cells30k.b cells100k.b cell-max.b cell-type.b too-slow.b 12 | 13 | -------------------------------------------------------------------------------- /testing/Counter.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2014 2 | Length is 116 instructions executed in 5368712635 ticks 3 | It needs 62 cells of at least 7 bits each 4 | Very difficult to optimise 5 | Prints "OK" on completion 6 | 7 | +>>+++++++++++++++++++++++++++++<<[>>>[>>]<[[>>+<<-]>>-[<<]]>+<<[-<<]<]> 8 | +>>[-<<]<+++++++++[>++++++++>+<<-]>-.----.>. 9 | -------------------------------------------------------------------------------- /testing/Counter.out: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /testing/EasyOpt.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2016 2 | Length is 179 instructions executed in 5814292411 ticks 3 | It needs 9 cells of at least 8 bits each 4 | Very easy to optimise 5 | Prints "OK" on completion 6 | 7 | >+>++>+>+<[>[-<+++++>]<<]> 8 | 9 | [->+>+<<]> 10 | 11 | [- >[->+>+>+<<<]>>>[-<<<+>>>]<< 12 | [- >[->+>+>+<<<]>>>[-<<<+>>>]<< 13 | 14 | [->[-]< [->+>+<<]>>[-<<+>>] <<] 15 | 16 | <<]>[-]< 17 | <<]>[-]< 18 | 19 | <<++++++++++[>++++++++>+<<-]>-.----.>. 20 | -------------------------------------------------------------------------------- /testing/Endtest.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2014 2 | This program needs 6 cells 3 | When given a newline and EOF it describes the characters it received 4 | 5 | >>,----------[[-]>>[-]>[-]+++++++++++++[<++++++>-]<.--.-------------.>++ 6 | ++++[<----->-]<-.[-]<<]>>[-]>[-]++++++++++[<++++++>-]<.>++++++[<+++>-]<. 7 | --.--------------.[-]++++++++++.[-]<<+,+[>+>]<[<<]>>-[>[-]>[-]++++[<++++ 8 | ++++>-]<[<++++++++>-]<+[<+++>[-]]]<<+>[-[-[-[--------[++++++++++[>+<-]<- 9 | >>>[-]>[-]++++++++++++[<+++++++>-]<+.>+++++[<+++++>-]<.---.+++.+.+++++++ 10 | +.---------.[-]<<]<[->>>[-]>[-]+++++++++++++[<++++++>-]<.>++++++[<++++>- 11 | ]<-.>++++++[<+++>-]<.-----------.---.+++++.---------.[-]<<<]>]<[->>>[-]> 12 | [-]++++++++++[<+++++++>-]<-.++++++++++.---------.[-]<<<]>]<[->>>[-]>[-]+ 13 | ++++++++++[<+++++++>-]<-.>+++++[<+++++>-]<.----.>+++++++[<+++>-]<.>++++[ 14 | <---->-]<-.[-]<<<]>]<[->>>[-]>[-]++++++++++[<+++++++++>-]<.+++++++++++.+ 15 | ++++++++++++.---.[-]<<<]>]<[->>>[-]>[-]++++++++[<++++++>-]<.>+++++++++[< 16 | ++++++++>-]<.>++++++++++[<----->-]<..[-]<<<]>>>[-]++++++++++.[-]<<<< 17 | -------------------------------------------------------------------------------- /testing/Endtest.in: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testing/Euler1-orig.b: -------------------------------------------------------------------------------- 1 | [/////////////////////////////////////////////////////////////////////////////// 2 | 3 | Project Euler Problem 1: Solution by: James Stanley 4 | https://github.com/jes/bnbf 5 | zLib license 6 | 7 | $ bcci-wrap Euler1.b 8 | Project Euler .net Problem 1 9 | 10 | Multiples of 3 and 5 11 | If we list all the natural numbers below 10 that are multiples of 3 or 5, 12 | we get 3, 5, 6 and 9. The sum of these multiples is 23. 13 | 14 | Find the sum of all the multiples of 3 or 5 below 1000. 15 | ... 16 | 17 | 233168 18 | $ 19 | 20 | ///////////////////////////////////////////////////////////////////////////////] 21 | Project Euler Problem 1 by James Stanley 22 | 23 | Generate 1000 24 | ++++++++++[>++++++++++[>++++++++++<-]<-]>> 25 | Take it down to 995 26 | ----- 27 | 28 | Memory now: === 0 0 (995) result=0 === 29 | 30 | repeatedly add the number at 995 to our result and then take 5 off 995 31 | 32 | [[->+>+<<] >>[-<<+>>]<< -----] 33 | 34 | Move back to address 0 35 | << 36 | 37 | Memory now: === (0) 0 0 result=99500 === 38 | 39 | Generate 1000 40 | ++++++++++[>++++++++++[>++++++++++<-]<-]>> 41 | Take it down to 999 42 | - 43 | 44 | Memory now: === 0 0 (999) result=99500 === 45 | 46 | for 3's we do the same as the loop above for 5's but remember to ignore the 47 | ones that were counted for 5 and basically unroll the loop and only count it on 48 | the ones that aren't divisible by 15 49 | also we quit looping when the outer loop should end 50 | 51 | [ 52 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 53 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 54 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 55 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [> --- < [-]] > 56 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 57 | ] 58 | 59 | Memory now: === 0 0 (0) result=233168 0 === 60 | 61 | Print overall result 62 | >. 63 | -------------------------------------------------------------------------------- /testing/Euler1.b: -------------------------------------------------------------------------------- 1 | // The first chunk is just something to print the heading text 2 | ++++++++++[>+++++++++++>++++++++++>+++>++++++++++++>+++++>+>++++++++>+++ 3 | +>+++++++>++++++<<<<<<<<<<-]>>>>>>>.<<<<<<++++.---.-----.>+.--.>>----.<+ 4 | +.>>>>>>-.<<<<<+.<<<++.>++.<++++++.>>.>>----.<<<<----.>.>>-.<.>>>>.<<<<< 5 | <++++.---.>---.<---.>+++.<+.>>.>>+++.>..>---.<<<+.<<<-.>>>-.<<<---.+++++ 6 | ++.----.>.>>-.<.<<+++.>+.>.>>++.<<.<-----.<-.>+++.>.>>++.>.>>>++++.<<<<< 7 | <<++.>.>++++.<<-.>.<<--.---.>>>----.+.<.<----.<+++..>>.>.<<+++++++.---.> 8 | .<<++.>----.>>.+.<<<++++.>.<------.>>.<<++.>>>.<<<-.>+.+++.<+++++.>>>--. 9 | <.<---.+++.<------.+++.>>>++++.<.>>----.-.<<.>---.<<+++.-------.>>.<.<.< 10 | +++.>++++.>.<<-----.>>>+.<<<-.>>>-.<<<---.+++++++.----.>.>>-.<.<<+++.>+. 11 | >.>>+++.<<.<<.+++.>>.>>++.>>>++++.<<.<<++++.<<-.>.<++.--.>>---.<.>>--.>> 12 | >.<<<<<.>>++.>>>.<<<<<.>>+.<<.<----.<----.>+++.>.>>>>>>>---.<<<<<------- 13 | -.<<.>>>>+++++++.<<<<<++++.---.>.>-.++.<<<-.>>.<<++.>+.>.>-.<<++.---.>>- 14 | .<<.>.<<--.>>>++.<<<-.>>>-.<<<---.+++++++.----.>.>>-.<.<<---.>>>.<.>>+++ 15 | +.+.-----.>..>>>---.<<<<<<<<.+++++.>-.>.>+.<<++++.---.>.>-.++.<<<-.>>.<< 16 | ++.>+.>.<-----.<---..>>.>-.<<+++++++.---.>.<<+.>>>+.<<<-.>>>-.<<<---.+++ 17 | ++++.----.>.>>-.<.<<+++.>+.>.>>+++++.<<.<<.+++.>>.>>++.<<.<----.+++.<--- 18 | ---.+++.>>>++++.<.>>----.-...--.>.<...>..>>>>[-]<[-]<[-]<[-]<[-]<[-]<[-] 19 | <[-]<[-]<[-]< 20 | 21 | Project Euler Problem 1 by James Stanley 22 | 23 | Generate 1000 24 | ++++++++++[>++++++++++[>++++++++++<-]<-]>> 25 | Take it down to 995 26 | ----- 27 | 28 | Memory now: === 0 0 (995) result=0 === 29 | 30 | repeatedly add the number at 995 to our result and then take 5 off 995 31 | 32 | [[->+>+<<] >>[-<<+>>]<< -----] 33 | 34 | Move back to address 0 35 | << 36 | 37 | Memory now: === (0) 0 0 result=99500 === 38 | 39 | Generate 1000 40 | ++++++++++[>++++++++++[>++++++++++<-]<-]>> 41 | Take it down to 999 42 | - 43 | 44 | Memory now: === 0 0 (999) result=99500 === 45 | 46 | for 3's we do the same as the loop above for 5's but remember to ignore the 47 | ones that were counted for 5 and basically unroll the loop and only count it on 48 | the ones that aren't divisible by 15 49 | also we quit looping when the outer loop should end 50 | 51 | [ 52 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 53 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 54 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 55 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [> --- < [-]] > 56 | <[-]<[-]>> [-<+<+>>] <<[->>+<<]>> < [[->>+>+<<<] >>>[-<<<+>>>]<< --- < [-]] > 57 | ] 58 | 59 | Memory now: === 0 0 (0) result=233168 0 === 60 | 61 | [ 62 | Print overall result 63 | >. 64 | ] 65 | 66 | //////////////////////////////////////////////////////////////////////////////// 67 | 68 | > Move to result cell and print as a number 69 | >[-]>[-]>[-]>[-]>[-]>[-]+>[-]+>[-]+>[-]+<<<<<<<<<[->>+>+<<<]>>>[-<<<+>>> 70 | ]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]+++++++++<[>>>[-]+<<[>+>[-]<<-]>[<+>-]>[ 71 | <<++++++++++>>-]<<-<-]+++++++++>[<->-]<[>+<-]<[>+<-]<[>+<-]>>>[<<<+>>>-] 72 | >>>[-]<<<+++++++++<[>>>[-]+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++>>>+<-]<<-< 73 | -]>>>>[<<<<+>>>>-]<<<[-]<<+>]<[>[-]<[>+<-]+++++++[<+++++++>-]<-.[-]>>[<< 74 | +>>-]<<-]< 75 | 76 | <++++++++++. 77 | -------------------------------------------------------------------------------- /testing/Euler1.out: -------------------------------------------------------------------------------- 1 | Project Euler .net Problem 1 2 | 3 | Multiples of 3 and 5 4 | If we list all the natural numbers below 10 that are multiples of 3 or 5, 5 | we get 3, 5, 6 and 9. The sum of these multiples is 23. 6 | 7 | Find the sum of all the multiples of 3 or 5 below 1000. 8 | ... 9 | 10 | 233168 11 | -------------------------------------------------------------------------------- /testing/Euler5.out: -------------------------------------------------------------------------------- 1 | Project Euler .net Problem 5 2 | Smallest multiple 3 | 4 | 2520 is the smallest number that can be divided by each of the numbers 5 | from 1 to 10 without any remainder. 6 | 7 | What is the smallest positive number that is evenly divisible by all of 8 | the numbers from 1 to 20? 9 | 10 | ... 11 | 232792560 12 | -------------------------------------------------------------------------------- /testing/Factor.in: -------------------------------------------------------------------------------- 1 | 123456789123456789 2 | -------------------------------------------------------------------------------- /testing/Factor.out: -------------------------------------------------------------------------------- 1 | 123456789123456789: 3 3 7 11 13 19 3607 3803 52579 2 | -------------------------------------------------------------------------------- /testing/Golden.b: -------------------------------------------------------------------------------- 1 | ++++++[>++++++++<-]>+.---.>>>+>>+>++>+>+>+>>+>+++>+>>+>+>+>>+>>>>+>>>>+>++>>>>+>+<>-----[+++++<[>>>]<<<[>>>>>>>>>+<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]<-<<<]>>>>>>+>>>+[<<<]<<<<<[>>>+<<[>>>+<<<-]<-<<<]>>>+<<<<<<<<[<<]>>>>[->[<<<+>>>>[>>]>+<<<[<<]>-]<<<-[>>>+<<<-]+>>>>[>>]+>[-[-[-<->>>>>>[[>>>]>>]<<<<<[>+<-<<<]<<[<<<]>>>[->>>[>>>]>>[>>>]+[<<<]<<[<<<]+>>>]>>>[<[-]+>->>>]<[>>>]<<<[>+++++++++<<<<]<<[<<<]>>>[->[<<+>+>-]<[>+<-]>[>>[>>>]>>>>[>>>]<-<<[<<<]<<<<[<<<]>-]>>[>>>]>>>>[>>>]+[<<<]<<<<[<<<]<[>>+<<-]>+>>>]>>>>[->>>]<<[>>>]<<<[>[-[-[-[-[-[-[-[-[-<->[<+>[-]>+<]]]]]]]]]]<[[>>[<<<+>>>-]<[-]<-<<<]>>>]<<<]>+>[-<-<<<[[<<<]<<]<<<[<<]+>>->>[>>]>>>>>>>-<[[>>>]>>]<]<[-<<<[[<<<]<<]<<<[<<]+[<<]>>->>[>>]>>>>>>[[>>>]>>]<<]<<<[[<<<]<<]]<[->>>>>>>+[<<+>+>-]<-[>+<-]+<[-[-[-[-[-[-[-[-[-[->>-<<<<<<<<<[<<]+>>>>>>>>->>[>>]>>>>>]]]]]]]]]]<<<<<]>]<[->>>>>>>[<<<+>+>>-]<<[>>+<<-]+<[>-<[>>[>>>]>>[>>>]>>[>>>]<<<[-<<<]<<[<<<]<<[<<<]>>>[->[<<+>+>-]<[>+<-]<[>>>>[>>>]>>[>>>]>>[>>>]>++<<<<[<<<]<<[<<<]<<[<<<]<-]>>>>[>>>]>>[>>>]>>[>>>]+[<<<]<<[<<<]<<[<<<]+>>>]<<<[<<<]>-]>>[>>>]>>[>>>]>>[->[<+>>+<-]<[[<+>>+<-]<[>+<-]>->-[<->-[<->-[<->-[<->-[<->-[<->-[<->-[<->-[<->[-]>---------->[-]+>+<<<]]]]]]]]]<]+>>[<+>-]>]<<<[[<<<]<<]>>>>>>[<<+>>>+<-]>[<+>-]<<<[>[[>>>]>>]<+<<<<[[<<<]<<]>>>>-]>[[>>>]>>]>+<<-[>+<-]>[>+++<-[>+++++<-[>--->>+>+<<<<-[>->>>+<<<<-[>+>>>+<<<<-[>+++>>>+<<<<-[>----->>>++<<<<-[>--->>>++<<<<-]]]]]]]]+[[<<<]<<]>>>]>[->[[>>>]>>]+>>>>>+[[<<<]<<]>>>>]<<<<<]>]<[->>>>>>[[>>>]>>]<<<<<[<<<]>>>[-<<<[<<<]<<[<<<]>>[>>>]+>[>>>]>>[>>>]>[<<<<[<<<]<<[<<<]>>[>>>]<<<+>[>>>]>>[>>>]>-]<+>>>]<<<[-<<<]<<[<<<]>>[->>>]<<[<<<]>>>[++++++++<[>-<-]>[>+<-]+>>>]<<<[<<<]>>>>+<[->[<<+>+>-]<[-[-[-[-[-[-[-[-[-[<---------->>>>[-]+>+<<<<[-]]]]]]]]]]]<[>>+<<-]>+>>>]<<[-<]<<[<<<]>>>->[<<+>>-]>>[>>>]<<<[>>+<[>-<<[<<<]>]>[-<<-<]<<]+<[>>+<<-]>[[<<<]<<]<]<<[<<]+>>]>+>[>+++++[>++>++<<-]<-]>>>>>[<<<+>+>+>-]<-[>+<-]+<<[<[<+>-]<<[>>+<<-]>[<+>-]>>-]<<<[-]>>[<+>>>-<<-]++++++[>++++++++<-]>>[<+>--]<.[-]>>[>>>]>>>-----] 2 | 3 | -------------------------------------------------------------------------------- /testing/Golden.out: -------------------------------------------------------------------------------- 1 | 1.618033988749894848204586834365638117 -------------------------------------------------------------------------------- /testing/Hello.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath 2 | Length is 140 instructions 3 | It needs 7 cells 4 | It checks for a number of mistakes commonly made in simple interpreters 5 | 6 | >++++++++[-<+++++++++>]<.>>+>-[+]++ 7 | >++>+++[>[->+++<<+++>]<<]>-----.>-> 8 | +++..+++.>-.<<+[>[+>+]>>]<--------- 9 | -----.>>.+++.------.--------.>+.>+. 10 | -------------------------------------------------------------------------------- /testing/Hello.out: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /testing/Hello2.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2017 2 | Length is 105 instructions 3 | It needs 14 cells 4 | It checks for a many mistakes commonly made in simple interpreters 5 | 6 | +[>[<->+[>+++>[+++++++++++>][]-[<]> 7 | -]]++++++++++<]>>>>>>----.<<+++.<-. 8 | .+++.<-.>>>.<<.+++.------.>-.<<+.<. 9 | -------------------------------------------------------------------------------- /testing/Hello2.out: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /testing/Impeccable.b: -------------------------------------------------------------------------------- 1 | [impeccable.b -- compute impeccable numbers 2 | (c) 2016 Daniel B. Cristofani 3 | http://brainfuck.org/] 4 | 5 | [ This is Daniel's original code 6 | 7 | >>>->+[ 8 | [ 9 | [<<+>+>-]++++++[<<++++++++>>-]<<-.[-]< 10 | ]++++++++++.[-]>>>++<[ 11 | [-[[>>>]<<<-[+>>>]<<<[<<<]+>]<-[+>++++++++++>>]>]>>> 12 | [[>+<-]>>>]<<[-[<++>-[<++>-[<++>-[<++>-[<[-]>-[<++>-]>>[<+<]>[->]<++<<]]]]]<+<<] 13 | > 14 | ]>[>>>]<<< 15 | ] 16 | 17 | This program outputs sequence (http://oeis.org/A014221). Although this sequence 18 | is technically nonterminating, computing its eighth term would require more 19 | storage than can exist in this universe, so you may as well kill this program 20 | after the seventh term. 21 | 22 | ] 23 | 24 | Print out the zero that's supposed to start the sequence 25 | ++++++[->++++++++<]>.[----<+>]<--. 26 | 27 | Only print six more to avoid the end of the universe 28 | [-]++++++[->> 29 | >>>++<[ 30 | [-[[>>>]<<<-[+>>>]<<<[<<<]+>]<-[+>++++++++++>>]>]>>> 31 | [[>+<-]>>>]<<[-[<++>-[<++>-[<++>-[<++>-[<[-]>-[<++>-]>>[<+<]>[->]<++<<]]]]]<+<<] 32 | > 33 | ]>[>>>]<<< 34 | 35 | Print the number we've found 36 | [ 37 | [<<+>+>-]++++++[<<++++++++>>-]<<-.[-]< 38 | ]++++++++++.[-] 39 | 40 | <<] 41 | 42 | >[-]<[-]++++++[->+++++++++++<]>+.-[---<+++++>]<+.--.+++.+++++.-.>+++++[< 43 | ---->-]<+.->+++++[<++++>-]<.-----------.++++++.-.--[--->+<]>----.+++++[- 44 | <+++>]<.---------.[--->+<]>--.---[-<++++>]<.------------.---.--[--->+<]> 45 | -.+[-<+++>]<++.++++.--.+.++++++++++++.------------.--[--->+<]>--.+++[-<+ 46 | ++>]<.++++.+++.-----------.--..--.+.++++++++++.-------.--[--->+<]>-.++++ 47 | [-<+++>]<++.+++++++.--------.-----------.+++.+++++++++++++.[--->+<]>---- 48 | --.[-<+++>]<+.+.+++++++++++++.+++.++.---------------.-.-[--->+<]>-.+[-<+ 49 | ++>]<+.+>++++[<++++>-]<.>++++[<---->-]<.--[--->+<]>-.---[-<++++>]<.----- 50 | .[--->+<]>-----.---[-<++++>]<.------------.---.--[--->+<]>-.+++[-<+++>]< 51 | .++++..----.+++++.---------.+++++++++.++++++.[---->+<]>+++.+[-<+++>]<++. 52 | +++++++++.----------.-[--->+<]>-.+++++[-<+++>]<.---------.[--->+<]>--.-- 53 | -[-<++++>]<.------------.---.--[--->+<]>-.---[-<++++>]<+.-------.-----.+ 54 | ++++++++++++.>++++[<---->-]<-.+++++++++++++.+.--------------.-[-->+<]>-- 55 | --.[-]++++++++++.[-]< 56 | 57 | -------------------------------------------------------------------------------- /testing/Kiloseconds.b: -------------------------------------------------------------------------------- 1 | [ https://github.com/bavardage/Kiloseconds/blob/master/brainfuck/ks.bf ] 2 | [ Usage: date +"%H%M%S"|somebfinterpreter ks.bf ] 3 | ++++++++++> 4 | >>++++[<++++++++<++++++++>>-] 5 | ++[<+++++++>-] 6 | >+++++++++[<++++++++>-]<+ 7 | >>>>>>>>>>>>++++++++++[<++++++++++>-] 8 | <[<<<<<<<<<<+>+>+>+>+>+>+>+>+>+>-] 9 | <<<<<<<<<<->>+>+++++>+++++++>++++++++ 10 | >>>>>+++++++++++++[<<<<+>+>+>+>-]<<<<--->-->++>+++ 11 | >,>,>,>,>,>,>>++++++[<++++++++>-]<[<<<<<<->->->->->->-] 12 | <[>+<-]<[>+<-]<[>>++++++<<-]<[>>++++++<<-] 13 | <[>>+++>++++++<<<-]<[>>+++>++++++<<<-] 14 | >>>>>[>>+>+<<<-]>>> 15 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 16 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 17 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 18 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 19 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 20 | [-[-[-[-[-[-[-[-[-[-<----------<<<+>>>> 21 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 22 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 23 | <[<<+>>-] 24 | <<<[>>>+>+<<<<-]>>>> 25 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 26 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 27 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 28 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 29 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 30 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 31 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 32 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 33 | [-[-[-[-[-[-[-[-[-[-<----------<<<<+>>>>> 34 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 35 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 36 | ]]]]]]]]]] 37 | <[<<<+>>>-] 38 | <<<<[>>>>+>+<<<<<-]>>>>> 39 | [-[-[-[-[-[-[-[-[-[-<----------<<<<<+>>>>>> 40 | [-[-[-[-[-[-[-[-[-[-<----------<<<<<+>>>>>> 41 | [-[-[-[-[-[-[-[-[-[-<----------<<<<<+>>>>>> 42 | [-[-[-[-[-[-[-[-[-[-<----------<<<<<+>>>>>> 43 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 44 | <[<<<<+>>>>-] 45 | >++++++[<++++++++>-]<[<<<<<+>+>+>+>+>-] 46 | <<<<<<<<<<<<<<<<<<.>>>>>>>>>>.<<<<<<<<<<<<.>>>>>>.>>>>>.<<<<<<<<<<<. 47 | >>>>>>>>>>>>>>>.>.<<<<<<<<<<<<<<< . >>>>>>>>>>>>>>>>.>.>. 48 | <<<<<<<<<<<<<<<<<<<.>>>>>>>.<.>>.>>.>.<<<<<<.>>>>>.<.<<<<<.>>>>>>>. 49 | <<<<<<<<<<<<. 50 | -------------------------------------------------------------------------------- /testing/Life.in: -------------------------------------------------------------------------------- 1 | cc 2 | cd 3 | ce 4 | dc 5 | dd 6 | de 7 | ec 8 | ed 9 | ee 10 | ff 11 | fg 12 | fh 13 | gf 14 | gg 15 | gh 16 | hf 17 | hg 18 | hh 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | q 28 | -------------------------------------------------------------------------------- /testing/Long.b: -------------------------------------------------------------------------------- 1 | >+>+>+>+>++<[>[<+++>- 2 | 3 | >>>>> 4 | >+>+>+>+>++<[>[<+++>- 5 | 6 | >>>>> 7 | >+>+>+>+>++<[>[<+++>- 8 | 9 | >>>>> 10 | >+>+>+>+>++<[>[<+++>- 11 | 12 | >>>>> 13 | +++[->+++++<]>[-]< 14 | <<<<< 15 | 16 | ]<<]>[-] 17 | <<<<< 18 | 19 | ]<<]>[-] 20 | <<<<< 21 | 22 | ]<<]>[-] 23 | <<<<< 24 | 25 | ]<<]>. 26 | -------------------------------------------------------------------------------- /testing/Long.out: -------------------------------------------------------------------------------- 1 | � -------------------------------------------------------------------------------- /testing/LostKng.in: -------------------------------------------------------------------------------- 1 | Y 2 | n 3 | t1 4 | s 5 | t2 6 | e 7 | s 8 | s 9 | t3 10 | n 11 | n 12 | t4 13 | e 14 | t0 15 | i 16 | p 17 | q 18 | y 19 | n 20 | 21 | -------------------------------------------------------------------------------- /testing/Mandelbrot-extreme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdebath/Brainfuck/525d346c006ea30dfc847ae3b32ed44d44fa9925/testing/Mandelbrot-extreme.png -------------------------------------------------------------------------------- /testing/Mandelbrot-extreme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | bf testing/Mandelbrot-extreme.b | 4 | { 5 | echo 'P5' 6 | echo '1024 768' 7 | echo '255' 8 | sed 's/......//' | tr ' ' '@' | tr -d '\012' 9 | } | ppmnorm | pnmtopng > mandelbrot-extreme.png 10 | -------------------------------------------------------------------------------- /testing/OptimTease.in: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /testing/OptimTease.out: -------------------------------------------------------------------------------- 1 | #################### 2 | #################### 3 | #################### 4 | #### #### ###### ###### #################### 5 | #### #### #### #### #################### 6 | #### #### #### #### #################### 7 | #### #### #### #### #################### 8 | #### #### ############ #### #### ############ #################### 9 | #### #### #### #### #### #### #### #### #################### 10 | ################ #### #### #### #### #### #### ###### ######## 11 | #### #### ################ #### #### #### #### #### ## ###### 12 | #### #### #### #### #### #### #### ## ###### #### 13 | #### #### #### #### #### #### #### ## ###### #### 14 | #### #### #### #### #### #### #### #### ## ###### 15 | #### #### #### #### #### #### #### #### ###### ######## 16 | #### #### ############ ######## ######## ############ #################### 17 | #################### 18 | #################### 19 | #################### 20 | #################### 21 | -------------------------------------------------------------------------------- /testing/OptimTease2.in: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /testing/PIdigits-orig.b: -------------------------------------------------------------------------------- 1 | [ yet another pi calculation program in bf 2 | 3 | Just like for pi16.b the accuracy of the result depends on the cellsize: 4 | 5 | - using 8 bit cells causes an overflow after 4 digits 6 | - using 16 bit cells causes an overflow after 537 digits 7 | - using 32 bit cells causes an overflow after several millions of digits 8 | 9 | It's about ~38 times shorter than pi16.b, ~364 times faster and works with 10 | not-wrapping (bignum) implementations. 11 | 12 | by Felix Nawothnig (felix.nawothnig@t-online.de) ] 13 | 14 | > Put the number of digits you want in this cell 15 | ++++ 16 | 17 | [<+>>>>>>>>++++++++++<<<<<<<-]>+++++[<+++++++++>-]+>>>>>>+[<<+++[>>[-<]<[>]<-]>> 18 | [>+>]<[<]>]>[[->>>>+<<<<]>>>+++>-]<[<<<<]<<<<<<<<+[->>>>>>>>>>>>[<+[->>>>+<<<<]> 19 | >>>>]<<<<[>>>>>[<<<<+>>>>-]<<<<<-[<<++++++++++>>-]>>>[<<[<+<<+>>>-]<[>+<-]<++<<+ 20 | >>>>>>-]<<[-]<<-<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+<<<-[>>+<<-]<]<<<<+>>>>>>> 21 | >[-]>[<<<+>>>-]<<++++++++++<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+>[<<+<+>>>-]<<< 22 | <+<+>>[-[-[-[-[-[-[-[-[-<->[-<+<->>]]]]]]]]]]<[+++++[<<<++++++++<++++++++>>>>-]< 23 | <<<+<->>>>[>+<<<+++++++++<->>>-]<<<<<[>>+<<-]+<[->-<]>[>>.<<<<[+.[-]]>>-]>[>>.<< 24 | -]>[-]>[-]>>>[>>[<<<<<<<<+>>>>>>>>-]<<-]]>>[-]<<<[-]<<<<<<<<]++++++++++. 25 | -------------------------------------------------------------------------------- /testing/PIdigits.b: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | =========================== OUTPUT STRING ============================== 3 | ======================================================================== 4 | 5 | > 6 | How many digits do you want? 7 | 8 | >++++++++[<+++++++++>-]<.>++++++[<++++++>-]<+++.++++++++.[-]>+++++[<++++ 9 | ++>-]<++.>++++++++[<+++++++++>-]<+++++.------------.+++++++++++++.++++++ 10 | +++++.[-]>+++++[<++++++>-]<++.>++++++++[<++++++++>-]<++++.+++++.--.++.++ 11 | +++++++++.-.[-]>+++++[<++++++>-]<++.>++++++++[<++++++++>-]<++++.++++++++ 12 | +++.[-]>+++++[<++++++>-]<++.>+++++++++[<+++++++++>-]<++++++++.---------- 13 | .++++++.[-]>+++++[<++++++>-]<++.>+++++++++[<+++++++++>-]<++++++.>++++[<- 14 | ---->-]<--.+++++++++++++.++++++.>+++++++[<------->-]<----.>+++++[<------ 15 | >-]<-. [-] 16 | 17 | ======================================================================== 18 | =========================== INPUT NUMBER ============================== 19 | ======================================================================== 20 | 21 | +[->,----------[<+>-------------------------------------->[>+>+<<-]>>[<< 22 | +>>-]<>>>+++++++++[<<<[>+>+<<-]>>[<<+>>-]<[<<+>>-]>>-]<<<[-]<<[>+<-]]<]> 23 | >[<<+>>-]<< 24 | 25 | <[-] 26 | ======================================================================== 27 | ============================== PROCESS ================================= 28 | ======================================================================== 29 | 30 | [ yet another pi calculation program in bf 31 | 32 | Just like for pi16.b the accuracy of the result depends on the cellsize: 33 | 34 | - using 8 bit cells causes an overflow after 4 digits 35 | - using 16 bit cells causes an overflow after 537 digits 36 | - using 32 bit cells causes an overflow after several millions of digits 37 | 38 | It's about ~38 times shorter than pi16.b, ~364 times faster and works with 39 | not-wrapping (bignum) implementations. 40 | 41 | by Felix Nawothnig (felix.nawothnig@t-online.de) ] 42 | 43 | > Put the number of digits you want in this cell 44 | 45 | [<+>>>>>>>>++++++++++<<<<<<<-]>+++++[<+++++++++>-]+>>>>>>+[<<+++[>>[-<]<[>]<-]>> 46 | [>+>]<[<]>]>[[->>>>+<<<<]>>>+++>-]<[<<<<]<<<<<<<<+[->>>>>>>>>>>>[<+[->>>>+<<<<]> 47 | >>>>]<<<<[>>>>>[<<<<+>>>>-]<<<<<-[<<++++++++++>>-]>>>[<<[<+<<+>>>-]<[>+<-]<++<<+ 48 | >>>>>>-]<<[-]<<-<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+<<<-[>>+<<-]<]<<<<+>>>>>>> 49 | >[-]>[<<<+>>>-]<<++++++++++<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+>[<<+<+>>>-]<<< 50 | <+<+>>[-[-[-[-[-[-[-[-[-<->[-<+<->>]]]]]]]]]]<[+++++[<<<++++++++<++++++++>>>>-]< 51 | <<<+<->>>>[>+<<<+++++++++<->>>-]<<<<<[>>+<<-]+<[->-<]>[>>.<<<<[+.[-]]>>-]>[>>.<< 52 | -]>[-]>[-]>>>[>>[<<<<<<<<+>>>>>>>>-]<<-]]>>[-]<<<[-]<<<<<<<<]++++++++++. 53 | 54 | -------------------------------------------------------------------------------- /testing/PIdigits.in: -------------------------------------------------------------------------------- 1 | 200 2 | -------------------------------------------------------------------------------- /testing/PIdigits.out: -------------------------------------------------------------------------------- 1 | How many digits do you want? 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819 2 | -------------------------------------------------------------------------------- /testing/PIdigits2.in: -------------------------------------------------------------------------------- 1 | 50 2 | -------------------------------------------------------------------------------- /testing/Precalc.b: -------------------------------------------------------------------------------- 1 | 2 | : '[' 3 | # Several heavily optimising interpreters make mistakes when calculating 4 | # optimisation of operations that exceed the cell size by doing those 5 | # calculation with incorrectly wrapped variables. 6 | # 7 | # This does a basic check for this sort of issue. 8 | # 9 | # Robert de Bath 2016 10 | 11 | for b in 8 16 32 12 | do echo "Esotope $b:" "$( tcc -run <( esotope-bfc -s$b $0 ) | cat -vt )" 13 | done 14 | echo "libbf char: $(libbf --compile-execute-char $0)" 15 | 16 | echo 17 | for b in 8 16 32 18 | do echo "Tritium $b: $(bfi -b$b $0)" 19 | done 20 | 21 | exit 0 22 | <<\END 23 | : ']' 24 | 25 | >[-]<[-]++++++++[>++++++++<-]>[<++++>-]<[ 26 | >+[>]<-< 27 | [[-] 28 | 29 | // Original code 30 | [-]>[-]>[-]>[-]>[-]>[-]<++++[>++++<-]>[<++<+++++<++++++<+++++++> 31 | >>>-]<<-.<<++.---------.--.++.+++++.>+.<--.>>>.<------------.<<+ 32 | ++.>+++.+.<<++++++++++.>>>>[-]<[-]<[-]<[-]<[-] 33 | 34 | [-]]] 35 | 36 | >[-]<[-]++++++++[>++++++++<-]>[<++++>-]+<[>-<[-]]>[> 37 | // Large byte doubled code 38 | >>>>[-]<[-]<[-]<[-]<[-]>++++++[<+++>-]<+[>++++>++++++>+++++>++<< 39 | <<-]>.>>++.<.>++++++.--.>------.<---.<+++++++.-----.>+++.>.<-.<- 40 | ----.++++++.>--.<---------.>+++.-.>.<-.<+++.>+.+.<<<++++++++++.> 41 | >>>[-]<[-]<[-]<[-]<[-] 42 | 43 | <[-]]< 44 | 45 | 46 | >[-]<[-]++++++++[>++++++++<-]>[<++++>-]<[[-] 47 | +>+>>[-]++++[-<<[->++++<]>[-<+>]>]<+<[>-<[-]]>[- 48 | // Message for esotope bfc 49 | >>>>[-]<[-]<[-]<[-]<[-]>++++[<++++>-]<[>++++>++>+++++++>+++++++< 50 | <<<-]>+++.>>-.--.>.<----.+++.-------.<.<++.>>>++..---.+++.<<<--- 51 | --------.>.>++++.>+.<<.>>+.<-.+.>-.<<.>----.>.----.+++++.-----.+ 52 | .<.<+++++++++++++.>---.++++.---.<-------------.<+++++.<+++++++++ 53 | +.>>>>[-]<[-]<[-]<[-]<[-] 54 | ]<< 55 | [-]] 56 | 57 | END 58 | -------------------------------------------------------------------------------- /testing/PrecalcBreak.b: -------------------------------------------------------------------------------- 1 | : '[' 2 | # This regression test triggers bugs in the esotope-bfc, libbf 3 | # and bfdb compilers. 4 | # 5 | # Robert de Bath 2019 6 | 7 | for b in 8 16 32 8 | do echo "Esotope $b:" "$( tcc -w -run <( esotope-bfc -s$b $0 ) )" 9 | done 10 | 11 | echo "libbf char: $(libbf --compile-execute-char $0 2>/dev/null)" 12 | echo "libbf short: $(libbf --compile-execute-short $0 2>/dev/null)" 13 | echo "libbf int: $(libbf --compile-execute-int $0 2>/dev/null)" 14 | 15 | echo "bfdb int: $(ulimit -t 3; bfdb -n -u $0 2>/dev/null)" 16 | 17 | for b in 8 16 32 ; do echo "Tritium $b: $(bfi -b$b $0)" ; done 18 | 19 | exit 0 20 | <<\END 21 | : ']' 22 | 23 | // This code runs on byte sized cells 24 | [-]>[-]++++++++[<++++++++>-]<[>++++<-]+>[<->[-]]<[[-] 25 | +++++++++[->+++++++++<]>++.+[---<++++>]<-.+++..+++++++.-[---->+<]>++.--- 26 | [-<++++>]<.------------.+.++++++++++.+[---->+<]>+++.[--<+++++++>]<.++.-- 27 | -.--------.+++++++++++.>++++[<---->-]<-.++++++++++++.-[--->+<]>----.++++ 28 | [-<+++>]<++.---------..-.+++++++++++++++.+[---->+<]>+++.[-<+++>]<+.-[--- 29 | >+<]>.++++[-<+++>]<.-----------.+>++++[<++++>-]<.-----------.--.++++++++ 30 | +++++.[--->+<]>------.+[-<+++>]<.++.+++++++..[--->+<]>----.---[-<++++>]< 31 | -.----------.+>++++[<++++>-]<.>+++++++[<--->-]<.[-]++++++++++. 32 | [-]] 33 | 34 | // This generates 256 to check for larger than byte cells 35 | >[-]<[-]++++++++[>++++++++<-]>[<++++>-]<[[-] 36 | // Check that the cells size is okay 37 | +>++++[-<[->>++<<]>>[-<<++>>]<]+<[>-<[-]]>[ [-]+++++++. [><]]< 38 | 39 | // The payload code: 40 | ++++++++[->+++++++++<]>.----[--<+++>]<-.+++++++..+++.[--->+<]>-----.---[ 41 | -<+++>]<.---[--->++++<]>-.+++.------.--------.-[---<+>]<.[--->+<]>-.[-]< 42 | // to here 43 | 44 | [-]] 45 | -------------------------------------------------------------------------------- /testing/Prime.in: -------------------------------------------------------------------------------- 1 | 1030 2 | -------------------------------------------------------------------------------- /testing/Prime.out: -------------------------------------------------------------------------------- 1 | Primes up to: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 2 | -------------------------------------------------------------------------------- /testing/Prime2.in: -------------------------------------------------------------------------------- 1 | 5000 2 | -------------------------------------------------------------------------------- /testing/Prime2.out: -------------------------------------------------------------------------------- 1 | Primes up to: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 2 | -------------------------------------------------------------------------------- /testing/Prime8.b: -------------------------------------------------------------------------------- 1 | Prime.b -------------------------------------------------------------------------------- /testing/Prime8.in: -------------------------------------------------------------------------------- 1 | 255 2 | -------------------------------------------------------------------------------- /testing/Prime8.out: -------------------------------------------------------------------------------- 1 | Primes up to: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 2 | -------------------------------------------------------------------------------- /testing/Prttab.b: -------------------------------------------------------------------------------- 1 | // Print out ASCII and high byte values in both forms suitable for 2 | // easy optimisation to printed strings and difficult to optimise 3 | // character by character output 4 | // 5 | // Note the "high bytes" are printed both as greater than 128 and 6 | // as negative values 7 | // 8 | // Robert de bath 2015 9 | 10 | // This title is very easy to optimise and includes an ESC character 11 | >>>>>>[-]<[-]<[-]<[-]<[-]<[-]<[-]++++++++++++++++[>+++>++++>+++++++>++++ 12 | ++>++>+<<<<<<-]>>>>>...<<<<.+.+.+.+.+.+.+.+.+.>+.+.+.+.+.+.<---------.+. 13 | +.+.+.+.+.+.+.+.>-----.+.+.+.+.+.<---------.+.+.+.+.+.+.+.+.+.>-----.+.+ 14 | .+.+.+.<---------.+.+.+.+.+.+.+.+.+.>-----.+.+.+.+.+.>>>>------.<-----.< 15 | -----.<<<--------.>>---.<---.>++++++++.---..>++++++++++.<----.++++++.>>+ 16 | ++++.<--.+++++.-------.<--.>.++.<++.>++.<--.>>.<<+.>.<+.>>-----.<------- 17 | ---.<-------.>>>.[-]<[-]<[-]<[-]<[-]<[-]< 18 | 19 | // This first should be very easy to optimise so with luck we get 20 | // a literal string with all the characters in the generated code 21 | >>>>[-]<[-]<[-]<[-]<[-]++++++++++++++++[>+++>++++++++>++>++<<<<-]>.+++++ 22 | +++++.>----.>.................................+.+.+.+.+.+.+.+.+.+.+.+.+. 23 | +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.<.<<++++++++++.>---------.>>-----.<. 24 | >++++++.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+. 25 | +.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.>.<<.<<.>>>> 26 | [-]<[-]<[-]<[-]<[-] 27 | 28 | // This is the same again but it is rather more difficult to optimise 29 | +++++++++++[>+++>>+++++++++++>++++>+++++>+<<<<<<-]>->>+++>++++.>+++.>-<< 30 | <.<<[-<+>>+<]<[->+>.<<]>[-<+>>.+<]>>.>>>.<<+.>.<<.<<<[->+>.+<<]>-[-<+>>. 31 | +<]<+.>>>.>>>.[-]<[-]<[-]<[-]<[-]<<[-] 32 | 33 | // Next the high bytes above 128 34 | ++++++++++.+[>+++>>+++++++++++>++++>+++++>+<<<<<<-]>->>+++>++++++.>+++.> 35 | -<<<.<<[-<+>>+<]<[->+>.<<]>[-<+>>++++<]<[->+>.+<<]>>>.>>>.<<+.>.<<.<-<[- 36 | <+>>+.<]<[->+>+.<<]>>>.>>>.[-]<[-]<[-]<[-]<[-]<[-]< 37 | 38 | // Last the negative byte values 39 | ++++++++++.+[>+++>>+++++++++++>++++>+++++>+<<<<<<-]>->>+++>++++++.>+++.> 40 | -<<<.<<[-<+>>+<]<[->+>.<<]>[-<+>>----<]<[->+>.+<<]>>>.>>>.<<+.>.<<.<<[-< 41 | +>>.+<]<[->+>.+<<]>>+>.>>>.[-]<[-]<[-]<[-]<[-]<[-]< 42 | 43 | -------------------------------------------------------------------------------- /testing/SelfInt.b: -------------------------------------------------------------------------------- 1 | >>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[ 2 | ->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<< 3 | ]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[> 4 | +<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>- 5 | [<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[ 6 | >->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<] 7 | [input a brainfuck program and its input, separated by an exclamation point. 8 | Daniel B Cristofani (cristofdathevanetdotcom) 9 | http://www.hevanet.com/cristofd/brainfuck/] 10 | -------------------------------------------------------------------------------- /testing/SelfInt.in: -------------------------------------------------------------------------------- 1 | >>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[> 2 | ++>++++++<<-]+>>>,<++[[>[->>]<[>>]<<-]<[<]<+>>[>]>[<+ 3 | >-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<]<] 4 | < 5 | [[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<] 6 | +<<[+>+<<-[>-->+<<-[>+<[>>+<<-]]]>[<+>-]<]++>>-->[>]> 7 | >[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-[<->[<< 8 | +>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>> 9 | >]<<[>.>>>>>>>]<<[>->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]!>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-] 10 | <.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.! 11 | -------------------------------------------------------------------------------- /testing/SelfInt.out: -------------------------------------------------------------------------------- 1 | Hello World! -------------------------------------------------------------------------------- /testing/Sorry-needs-16.b: -------------------------------------------------------------------------------- 1 | [-]>[-]+++++++++[-<+++++++++>]<++.+[--->++++<]>-.+++..+++++++.-[----<+>] 2 | <++.---[->++++<]>.------------.+.++++++++++.+[----<+>]<+++.[-->+++++++<] 3 | >.++.---.--------.+++++++++++.<++++[>----<-]>-.++++++++++++.-[---<+>]<-- 4 | --.++++[->+++<]>++.---------..-.+++++++++++++++.+[----<+>]<+++.[->+++<]> 5 | +.+++++++++++++.--[---<+>]<----.[-->+++<]>+.+++++.-----[-<++>]<.+++++++. 6 | +++++++++++.[---->+<]>+++.+++[-<+++>]<.+++++.++++++.---------------.++++ 7 | +++++++++.--.++.-------------.+++++++++++++++.---------------.++++++++++ 8 | +++.[-]++++++++++.[-] 9 | -------------------------------------------------------------------------------- /testing/Sorry-needs-32.b: -------------------------------------------------------------------------------- 1 | [-]>[-]+++++++++[-<+++++++++>]<++.+[--->++++<]>-.+++..+++++++.-[----<+>] 2 | <++.---[->++++<]>.------------.+.++++++++++.+[----<+>]<+++.[-->+++++++<] 3 | >.++.---.--------.+++++++++++.<++++[>----<-]>-.++++++++++++.-[---<+>]<-- 4 | --.++++[->+++<]>++.---------..-.+++++++++++++++.+[----<+>]<+++.[->+++<]> 5 | +.+++++++++++++.--[---<+>]<----.++[-->+++<]>.-.-[-<++>]<.+++++++.+++++++ 6 | ++++.[---->+<]>+++.+++[-<+++>]<.+++++.++++++.---------------.+++++++++++ 7 | ++.--.++.-------------.+++++++++++++++.---------------.+++++++++++++.[-] 8 | ++++++++++.[-] 9 | -------------------------------------------------------------------------------- /testing/Tribit.b: -------------------------------------------------------------------------------- 1 | [ This is a VERY simple check for the three common bit sizes. 2 | It's the original version for the Bitwidth.b test program. 3 | 4 | Robert de Bath 2013 5 | ] 6 | 7 | // Calculate the value 256 and test if it's zero 8 | // If the interpreter errors on overflow this is where it'll happen 9 | ++++++++[>++++++++<-]>[<++++>-] 10 | +<[>-< 11 | // Not zero so multiply by 256 again to get 65536 12 | [>++++<-]>[<++++++++>-]<[>++++++++<-] 13 | +>[> 14 | // Print "32" 15 | ++++++++++[>+++++<-]>+.-.[-]< 16 | <[-]<->] <[>> 17 | // Print "16" 18 | +++++++[>+++++++<-]>.+++++.[-]< 19 | <<-]] >[> 20 | // Print "8" 21 | ++++++++[>+++++++<-]>.[-]< 22 | <-]< 23 | // Print " bit cells\n" 24 | +++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<. 25 | >>.++.+++++++..<-.>>- 26 | Clean up used cells. 27 | [[-]<] 28 | -------------------------------------------------------------------------------- /testing/Zozotez.in: -------------------------------------------------------------------------------- 1 | ((\ 2 | (set quote lambda cons car cdr if eq atom flambda print read eval au-revoir 3 | REPL list setq and) 4 | (print '(Bonjour to Zozotez REPL classic |LISP1.| (au-revoir) to |exit.|) NIL) 5 | (REPL)) 6 | : " \ c a d ? = s ~ p r e ; builtins 7 | (\ () 'au-revoir) ; exit-function 8 | (\ () ; REPL 9 | (print 'Zozotez-moi~>()) 10 | (if (eq (print(eval(read))) 'au-revoir) () (REPL))) 11 | (\ q q) ; list 12 | (~ ($s $o) (list set (list quote $s) $o)) ; setq 13 | (~ ($s . $o) (if $o (list if $s (cons and $o)) $s))) 14 | ((\ (fibonacci + - 0 1 num) 15 | (fibonacci num 0 1)) 16 | (\ (n a1 a2) (? n (fibonacci (- n 1) a2 (+ a1 a2)) a1)) 17 | (\ (x y) (? x (c (a x) (+ (d x) y)) y)) 18 | (\ (x y) (? y (- (d x) (d y)) x)) 19 | () '(1) '(1 2 3 4 5 6 7 8)) 20 | ; 21 | (au-revoir) 22 | 23 | -------------------------------------------------------------------------------- /testing/Zozotez.out: -------------------------------------------------------------------------------- 1 | Bonjour to Zozotez REPL classic LISP1. (au-revoir) to exit. 2 | Zozotez-moi~>(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 3 | Zozotez-moi~>au-revoir 4 | -------------------------------------------------------------------------------- /testing/al-count-0.b: -------------------------------------------------------------------------------- 1 | +++++++++[>+++++++>+++>+<<<-]>+>-[-<+.>]>+. 2 | -------------------------------------------------------------------------------- /testing/al-count-1.b: -------------------------------------------------------------------------------- 1 | [ This is a binary counter benchmark program, it runs ] 2 | [ 671106031 instructions and is mostly unoptimisable. ] 3 | [ As it runs it prints the letters of the alphabet with ] 4 | [ a delay that doubles between each letter. ] 5 | [ Robert de Bath 2015, 2020 ] 6 | 7 | >++++++++[>+++>>>++++++++<<<<-]>++<< 8 | +[> // The loop flag 9 | >>[>>] // Find first zero 10 | <[ // Check for the term flag 11 | [->>+<<] // if found move it up one 12 | >> 13 | >+.[->>+<<]< 14 | 15 | -[<<] // Decrement and finish on zero 16 | ]> // Back to the zero 17 | + // Make the zero a one 18 | <<[-<<] // Remove all the carried ones 19 | <] // and loop 20 | >+>>>>[[-]<<]< // Clean up 21 | +++++++++.[-] // NL 22 | -------------------------------------------------------------------------------- /testing/al-count-2.b: -------------------------------------------------------------------------------- 1 | [ This is a binary counter benchmark program, it runs ] 2 | [ 1.1259e+16 instructions and is mostly unoptimisable. ] 3 | [ As it runs it prints the letters of the alphabet with ] 4 | [ a delay that quadruples between each letter. ] 5 | [ Robert de Bath 2015, 2020 ] 6 | 7 | >++++++++[>++++++>>>++++++++<<<<-]>++<< 8 | +[> // The loop flag 9 | >>[>>] // Find first zero 10 | <[ // Check for the term flag 11 | [->>+<<] // if found move it up one 12 | >> 13 | >[+.[->>>>+<<<<]]< 14 | 15 | -[<<] // Decrement and finish on zero 16 | ]> // Back to the zero 17 | + // Make the zero a one 18 | <<[-<<] // Remove all the carried ones 19 | <] // and loop 20 | ++++++++++.[-] // NL 21 | -------------------------------------------------------------------------------- /testing/al-count-3.b: -------------------------------------------------------------------------------- 1 | [ This is a binary counter benchmark program, it runs ] 2 | [ 5368726554 instructions and is mostly unoptimisable. ] 3 | [ As it runs it prints the letters of the alphabet with ] 4 | [ a delay that doubles between each letter. ] 5 | [ Robert de Bath 2015, 2020 ] 6 | 7 | + >>>>>> 8 | >++++++++[>+++>>>++++++++<<<<-]>+ [+<-] 9 | +[> // The loop flag 10 | >>[>>] // Find first zero 11 | <[ // Check for the term flag 12 | [->>+<<] // if found move it up one 13 | >> 14 | >+.[->>+<<]< 15 | 16 | -[<<] // Decrement and finish on zero 17 | ]> // Back to the zero 18 | + // Make the zero a one 19 | <<[-<<] // Remove all the carried ones 20 | <] // and loop 21 | >+>>>>[[-]<<]< // Clean up 22 | +++++++++.[-] // NL 23 | -------------------------------------------------------------------------------- /testing/awib-0.4.in: -------------------------------------------------------------------------------- 1 | awib-0.4.b -------------------------------------------------------------------------------- /testing/cell-max.b: -------------------------------------------------------------------------------- 1 | >[-]++++[<++++>-]<[->>+<<]>>[-<<+>>>>>+<<<]>>>++[-<<<<<[->>+<<]> 2 | >[-<<+>>>>+<<]>>[-<<<<[->>+<<]>>[-<<+>>>+<]>[-<<<[->>+<<]>>[-<<+ 3 | >+>]<[->>>>>>+<+[>-]>[-<-<[-]<[-]<[-]<<[-]<[-]>>>>>>>>]<<<<<<<]> 4 | >]>]>]<<<<+>>>>>[-<<<+<+>>>>]<<<<+>[-<->>>>+<<<]+<[[-]>-<]>[[-]< 5 | <<[-]>>>]<<< 6 | 7 | [>>>>>>>>>>[-]>[-]+++++++[<+++++++++++>-]<-.-----------.>++++[<+ 8 | +++>-]<+.-----------.--.[-]++++++++++.[-]<<<<<<<<<[-]<[-]]>[[-]< 9 | 10 | >>>>>>[>+<-]>[[>+>+<<-]>>[<<+>>-]+++++++++<[>>>+<<[>+>[-]<<-]>[< 11 | +>-]>[<<++++++++++>>-]<<-<-]+++++++++>[<->-]<[>+<-]<[>+<-]<[>+<- 12 | ]>>>[<<<+>>>-]+++++++++<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++> 13 | >>+<-]<<-<-]>>>>[<<<<+>>>>-]<<<[-]<<+>]<[[>+<-]+++++++[<+++++++> 14 | -]<-.[-]>>[<<+>>-]<<-]++++++++++.[-]<<<<<< 15 | 16 | >[-]]< 17 | -------------------------------------------------------------------------------- /testing/cell-type.b: -------------------------------------------------------------------------------- 1 | // This generates 65536 to check for larger than 16bit cells 2 | [-]>[-]++[<++++++++>-]<[>++++++++<-]>[<++++++++>-]<[>++++++++<-]>[<+++++ 3 | +++>-]<[[-] 4 | 5 | [-]>[-]+++++[<++++++++++>-]<+.-. 6 | 7 | [-]] 8 | 9 | // This section is cell doubling for 16bit cells 10 | >[-]>[-]<<[-]++++++++[>++++++++<-]>[<++++>-]<[->+>+<<]>[<++++++++>-]<[>+ 11 | +++++++<-]>[<++++>-]>[<+>[-]]<<[>[-]<[-]]>[-<+>]<[[-] 12 | 13 | [-]>[-]+++++++[<+++++++>-]<.+++++. 14 | 15 | [-]] 16 | 17 | // This section is cell quadrupling for 8bit cells 18 | [-]>[-]++++++++[<++++++++>-]<[>++++<-]+>[<->[-]]<[[-] 19 | 20 | [-]>[-]+++++++[<++++++++>-]<. 21 | 22 | [-]] 23 | 24 | [-]>[-]++++[-<++++++++>]<.[->+++<]>++.+++++++.+++++++++++.[----<+>]<+++. 25 | +[->+++<]>.++.+++++++..+++++++.[-]++++++++++.[-]< 26 | -------------------------------------------------------------------------------- /testing/cells100k.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2016 2 | Length is 219 instructions executed in 21034372 ticks 3 | It needs 100000 cells of at least 7 bits each 4 | It does check that the tape does not wrap within those 100000 cells 5 | Prints "OK" on completion 6 | 7 | ++++++++++>>>>>+++++[<+++++>-]<++++[>+>+>+<<<-]>-------->[->[>+<-]>[<+<<+ 8 | >>>-]<<<[->>[>+<-]>[<+<<<+>>>>-]<<<<[-[>>>>+<<<<-]>[>>>>+<<<<-]>[>>>>+<<< 9 | <-]>[>>>>+<<<<-]+<+<+<+>>>>]>]>]>[-]<<<<[-<]<<<[>++++++++>+<<-]>-.----.>. 10 | -------------------------------------------------------------------------------- /testing/cells30k.b: -------------------------------------------------------------------------------- 1 | Brainfuck test program written by Robert de Bath in 2015 2 | Length is 153 instructions executed in 18340571 ticks 3 | It needs 30000 cells of at least 7 bits each 4 | It does check that the tape does not wrap within those 30000 cells 5 | Prints "OK" on completion 6 | 7 | >+++++++++[-<+++++++++++>]<[->+>+<<]>>++<[->[->>+<< 8 | ]>>[-<<+<<+>>>>]<<<<[->[->>>+<<<]>[->>>+<<<]<<[->>> 9 | +<<<]+>+>+>]>]<<+++++++++[->++++++++>+<<]>-.----.>. 10 | -------------------------------------------------------------------------------- /testing/cristofd-30000.b: -------------------------------------------------------------------------------- 1 | ++++[>++++++<-]>[>+++++>+++++++<<-]>>++++<[[>[[>>+<<-]<]>>>-]>-[>+>+<<-]>] 2 | +++++[>+++++++<<++>-]>.<<. 3 | -------------------------------------------------------------------------------- /testing/cristofd-close.b: -------------------------------------------------------------------------------- 1 | +++++[>+++++++>++<<-]>.>.][ 2 | -------------------------------------------------------------------------------- /testing/cristofd-endtest.b: -------------------------------------------------------------------------------- 1 | >,>+++++++++,>+++++++++++[<++++++<++++++<+>>>-]<<.>.<<-.>.>.<<. 2 | -------------------------------------------------------------------------------- /testing/cristofd-endtest.in: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /testing/cristofd-leftmargin.b: -------------------------------------------------------------------------------- 1 | +[<+++++++++++++++++++++++++++++++++.] 2 | -------------------------------------------------------------------------------- /testing/cristofd-misctest.b: -------------------------------------------------------------------------------- 1 | []++++++++++[>>+>+>++++++[<<+<+++>>>-]<<<<-] 2 | "A*$";?@![#>>+<<]>[>>]<<<<[>++<[-]]>.>. 3 | -------------------------------------------------------------------------------- /testing/cristofd-open.b: -------------------------------------------------------------------------------- 1 | +++++[>+++++++>++<<-]>.>.[ 2 | -------------------------------------------------------------------------------- /testing/cristofd-rightmargin.b: -------------------------------------------------------------------------------- 1 | +[>+++++++++++++++++++++++++++++++++.] 2 | -------------------------------------------------------------------------------- /testing/cristofd-tests.txt: -------------------------------------------------------------------------------- 1 | Here are some little programs for testing brainfuck implementations. 2 | 3 | 4 | >,>+++++++++,>+++++++++++[<++++++<++++++<+>>>-]<<.>.<<-.>.>.<<. 5 | This is for testing i/o; give it a return followed by an EOF. (Try it both 6 | with file input--a file consisting only of one blank line--and with 7 | keyboard input, i.e. hit return and then ctrl-d (Unix) or ctrl-z 8 | (Windows).) 9 | It should give two lines of output; the two lines should be identical, and 10 | should be lined up one over the other. If that doesn't happen, ten is not 11 | coming through as newline on output. 12 | The content of the lines tells how input is being processed; each line 13 | should be two uppercase letters. 14 | Anything with O in it means newline is not coming through as ten on input. 15 | LK means newline input is working fine, and EOF leaves the cell unchanged 16 | (which I recommend). 17 | LB means newline input is working fine, and EOF translates as 0. 18 | LA means newline input is working fine, and EOF translates as -1. 19 | Anything else is fairly unexpected. 20 | 21 | 22 | ++++[>++++++<-]>[>+++++>+++++++<<-]>>++++<[[>[[>>+<<-]<]>>>-]>-[>+>+<<-]>] 23 | +++++[>+++++++<<++>-]>.<<. 24 | Goes to cell 30000 and reports from there with a #. (Verifies that the 25 | array is big enough.) 26 | 27 | 28 | These next two test the array bounds checking. Bounds checking is not 29 | essential, and in a high-level implementation it is likely to introduce 30 | extra overhead. In a low-level implementation you can get bounds checking 31 | for free by using the OS's own memory protections; this is the best 32 | solution, which may require making the array size a multiple of the page 33 | size. 34 | Anyway. These two programs measure the "real" size of the array, in some 35 | sense, in cells left and right of the initial cell respectively. They 36 | output the result in unary; the easiest thing is to direct them to a file 37 | and measure its size, or (on Unix) pipe the output to wc. If bounds 38 | checking is present and working, the left should measure 0 and the right 39 | should be the array size minus one. 40 | +[<+++++++++++++++++++++++++++++++++.] 41 | 42 | +[>+++++++++++++++++++++++++++++++++.] 43 | 44 | 45 | []++++++++++[>>+>+>++++++[<<+<+++>>>-]<<<<-] 46 | "A*$";?@![#>>+<<]>[>>]<<<<[>++<[-]]>.>. 47 | Tests for several obscure problems. Should output an H. 48 | 49 | 50 | +++++[>+++++++>++<<-]>.>.[ 51 | Should ideally give error message "unmatched [" or the like, and not give 52 | any output. Not essential. 53 | 54 | +++++[>+++++++>++<<-]>.>.][ 55 | Should ideally give error message "unmatched ]" or the like, and not give 56 | any output. Not essential. 57 | 58 | 59 | My pathological program rot13.b is good for testing the response to deep 60 | brackets; the input "~mlk zyx" should produce the output "~zyx mlk". 61 | 62 | 63 | For an overall stress test, and also to check whether the output is 64 | monospaced as it ideally should be, I would run numwarp.b. 65 | 66 | 67 | Daniel B Cristofani (cristofdathevanetdotcom) 68 | http://www.hevanet.com/cristofd/brainfuck/ 69 | -------------------------------------------------------------------------------- /testing/fibint.out: -------------------------------------------------------------------------------- 1 | 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073 -------------------------------------------------------------------------------- /testing/numwarp.b: -------------------------------------------------------------------------------- 1 | >>>>+>+++>+++>>>>>+++[ 2 | >,+>++++[>++++<-]>[<<[-[->]]>[<]>-]<<[ 3 | >+>+>>+>+[<<<<]<+>>[+<]<[>]>+[[>>>]>>+[<<<<]>-]+<+>>>-[ 4 | <<+[>]>>+<<<+<+<--------[ 5 | <<-<<+[>]>+<<-<<-[ 6 | <<<+<-[>>]<-<-<<<-<----[ 7 | <<<->>>>+<-[ 8 | <<<+[>]>+<<+<-<-[ 9 | <<+<-<+[>>]<+<<<<+<-[ 10 | <<-[>]>>-<<<-<-<-[ 11 | <<<+<-[>>]<+<<<+<+<-[ 12 | <<<<+[>]<-<<-[ 13 | <<+[>]>>-<<<<-<-[ 14 | >>>>>+<-<<<+<-[ 15 | >>+<<-[ 16 | <<-<-[>]>+<<-<-<-[ 17 | <<+<+[>]<+<+<-[ 18 | >>-<-<-[ 19 | <<-[>]<+<++++[<-------->-]++<[ 20 | <<+[>]>>-<-<<<<-[ 21 | <<-<<->>>>-[ 22 | <<<<+[>]>+<<<<-[ 23 | <<+<<-[>>]<+<<<<<-[ 24 | >>>>-<<<-<- 25 | ]]]]]]]]]]]]]]]]]]]]]]>[>[[[<<<<]>+>>[>>>>>]<-]<]>>>+>>>>>>>+>]< 26 | ]<[-]<<<<<<<++<+++<+++[ 27 | [>]>>>>>>++++++++[<<++++>++++++>-]<-<<[-[<+>>.<-]]<<<<[ 28 | -[-[>+<-]>]>>>>>[.[>]]<<[<+>-]>>>[<<++[<+>--]>>-] 29 | <<[->+<[<++>-]]<<<[<+>-]<<<< 30 | ]>>+>>>--[<+>---]<.>>[[-]<<]< 31 | ] 32 | [Enter a number using ()-./0123456789abcdef and space, and hit return. 33 | Daniel B Cristofani (cristofdathevanetdotcom) 34 | http://www.hevanet.com/cristofd/brainfuck/] 35 | -------------------------------------------------------------------------------- /testing/numwarp.in: -------------------------------------------------------------------------------- 1 | 0123456789 abcdef ()-./ 2 | -------------------------------------------------------------------------------- /testing/numwarp.out: -------------------------------------------------------------------------------- 1 | \ 2 | / 3 | \ 4 | 5 | / 6 | / 7 | /\ 8 | \ 9 | / / 10 | \ 11 | \/ 12 | 13 | / 14 | \/ 15 | /\ \ 16 | \/ 17 | \ \/ 18 | /\ 19 | \/ 20 | / 21 | \/ 22 | \/\ 23 | /\ \/ 24 | /\ 25 | \/ 26 | 27 | /\ 28 | \/\ 29 | /\ 30 | \/\ 31 | /\ \/ 32 | \ 33 | / 34 | \/\ 35 | / \/ 36 | \/\ 37 | \ / 38 | \/\ 39 | /\ 40 | /\ 41 | /\ / 42 | / 43 | \ \/ 44 | \ 45 | /\ 46 | \ \ 47 | \/ 48 | -------------------------------------------------------------------------------- /testing/oobrain.out: -------------------------------------------------------------------------------- 1 | DRAWING A CIRCLE AT:(15,25), RADIUS 8 2 | DRAWING A RECTANGLE AT:(10,20), WIDTH 5, HEIGHT 6 3 | DRAWING A CIRCLE AT:(115,125), RADIUS 8 4 | DRAWING A RECTANGLE AT:(110,120), WIDTH 5, HEIGHT 6 5 | DRAWING A RECTANGLE AT:(0,0), WIDTH 30, HEIGHT 15 6 | -------------------------------------------------------------------------------- /testing/squaresums.b: -------------------------------------------------------------------------------- 1 | Justice Suh 2 | 3 | cell #0 = 100 4 | ++++++++++[>++++++++++<-]>[<+>-]< 5 | 6 | cell #2 = sum of 1 to 100 7 | [[>+>+<<-]>>[<<+>>-]<[>>+<<-]<-]>>>[<+>-]< 8 | 9 | cell #3 = cell #2 10 | [>+>+<<-]>>[<<+>>-]< 11 | 12 | cell #0 = cell #2 * cell #3 13 | [<[<+<+>>-]<[>+<-]>>-]<[-] 14 | 15 | cell #2 = 100 16 | ++++++++++[>++++++++++<-]>[<+>-]< 17 | 18 | loop until cell #2 = 0 19 | [ 20 | cell #4 = cell #3 = cell #2 21 | [>+>+>+<<<-]>>>[<<<+>>>-]<< 22 | 23 | add cell #3 * cell #4 to cell #1 24 | [>[>+<<<<+>>>-]>[<+>-]<<-]>[-]< 25 | 26 | <- 27 | ] 28 | 29 | cell #0 = cell #0 minus cell #1 30 | <[<->-]< 31 | 32 | cell #2 = cell #0 33 | [>>+>+<<<-]>>>[<<<+>>>-]<<+> 34 | 35 | loop while value exists 36 | [<->[ 37 | divide by ten 38 | >++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-] 39 | 40 | ascii offset 41 | ++++++++[<++++++>-] 42 | 43 | store remainder 44 | >[<<+>>-]>[<<+>>-]<< 45 | ]>] 46 | 47 | make zero 48 | <[->>++++++++[<++++++>-]] 49 | 50 | output in reverse order 51 | <[.[-]<]++++++++++.[-]< 52 | -------------------------------------------------------------------------------- /testing/squaresums.out: -------------------------------------------------------------------------------- 1 | 25164150 2 | -------------------------------------------------------------------------------- /testing/too-slow.b: -------------------------------------------------------------------------------- 1 | [-]>[-]+++++++[-<++++++++++++>]<. T 2 | +++++++++++++. a 3 | >++++++[<+++>-]<. s 4 | --------. k 5 | --[--->+<]>---. SP 6 | [-<+++>]<+. a 7 | +. b 8 | +++++++++++++. o 9 | +++. r 10 | ++. t 11 | ---------------. e 12 | -. d 13 | -[--->+<]>-. SP 14 | +[-<+++>]<+. d 15 | +>++++[<++++>-]<. u 16 | >++++[<---->-]<. e 17 | --[--->+<]>-. SP 18 | ---[-<++++>]<. t 19 | -----. o 20 | [--->+<]>-----. SP 21 | ---[-<++++>]<. t 22 | ------------. h 23 | ---. e 24 | --[--->+<]>-. SP 25 | +++[-<+++>]<. i 26 | ++++. m 27 | . m 28 | ----. i 29 | +++++. n 30 | ---------. e 31 | +++++++++. n 32 | ++++++. t 33 | [---->+<]>+++. SP 34 | +[-<+++>]<++. e 35 | +++++++++. n 36 | ----------. d 37 | -[--->+<]>-. SP 38 | +++++[-<+++>]<. o 39 | ---------. f 40 | [--->+<]>--. SP 41 | ---[-<++++>]<. t 42 | ------------. h 43 | ---. e 44 | --[--->+<]>-. SP 45 | ---[-<++++>]<+. u 46 | -------. n 47 | -----. i 48 | +++++++++++++. v 49 | >++++[<---->-]<-. e 50 | +++++++++++++. r 51 | +. s 52 | --------------. e 53 | -[-->+<]>----. dot 54 | [-]++++++++++. NL 55 | [-]< 56 | -------------------------------------------------------------------------------- /testing/too-slow.out: -------------------------------------------------------------------------------- 1 | Task aborted due to the imminent end of the universe. 2 | -------------------------------------------------------------------------------- /testing/utm.in: -------------------------------------------------------------------------------- 1 | b1b11111111111111111bbb1b1bb11111111111111111bb111111b1b111111111111111111111bb1bb11111111111bb11111111111111111bb1111111111111111b11111111111c1c1 2 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | DynASM 2 | Dynamic assembler from LuaJIT 2.0.2 3 | Project Homepage: http://luajit.org/ 4 | 5 | Tested and runs correctly on x86 and x86_x64. 6 | 7 | lightning-1.2.tar.gz 8 | GNU Lightning v1.2 for i686, PowerPC and sparc 9 | 10 | Minor modifications so it will work without autoconf and fail 11 | softly on other processors. 12 | 13 | fgmp-1.0b5 14 | A very small version of GMP 1.0 it's a lot slower than the real 15 | thing but much smaller and Public Domain. 16 | -------------------------------------------------------------------------------- /tools/dynasm/.gitignore: -------------------------------------------------------------------------------- 1 | minilua 2 | -------------------------------------------------------------------------------- /tools/dynasm/README: -------------------------------------------------------------------------------- 1 | This is the dynamic assembler from the LuaJIT project, see link below 2 | for more details. 3 | 4 | 5 | README for LuaJIT 2.0.2 6 | ----------------------- 7 | 8 | LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. 9 | 10 | Project Homepage: http://luajit.org/ 11 | 12 | LuaJIT is Copyright (C) 2005-2013 Mike Pall. 13 | LuaJIT is free software, released under the MIT license. 14 | See full Copyright Notice in the COPYRIGHT file or in luajit.h. 15 | 16 | Documentation for LuaJIT is available in HTML format. 17 | Please point your favorite browser to: 18 | 19 | doc/luajit.html 20 | 21 | -------------------------------------------------------------------------------- /tools/dynasm/dasm_proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** DynASM encoding engine prototypes. 3 | ** Copyright (C) 2005-2014 Mike Pall. All rights reserved. 4 | ** Released under the MIT license. See dynasm.lua for full copyright notice. 5 | */ 6 | 7 | #ifndef _DASM_PROTO_H 8 | #define _DASM_PROTO_H 9 | 10 | #include 11 | #include 12 | 13 | #define DASM_IDENT "DynASM 1.3.0" 14 | #define DASM_VERSION 10300 /* 1.3.0 */ 15 | 16 | #ifndef Dst_DECL 17 | #define Dst_DECL dasm_State **Dst 18 | #endif 19 | 20 | #ifndef Dst_REF 21 | #define Dst_REF (*Dst) 22 | #endif 23 | 24 | #ifndef DASM_FDEF 25 | #define DASM_FDEF extern 26 | #endif 27 | 28 | #ifndef DASM_M_GROW 29 | #define DASM_M_GROW(ctx, t, p, sz, need) \ 30 | do { \ 31 | size_t _sz = (sz), _need = (need); \ 32 | if (_sz < _need) { \ 33 | if (_sz < 16) _sz = 16; \ 34 | while (_sz < _need) _sz += _sz; \ 35 | (p) = (t *)realloc((p), _sz); \ 36 | if ((p) == NULL) exit(1); \ 37 | (sz) = _sz; \ 38 | } \ 39 | } while(0) 40 | #endif 41 | 42 | #ifndef DASM_M_FREE 43 | #define DASM_M_FREE(ctx, p, sz) free(p) 44 | #endif 45 | 46 | /* Internal DynASM encoder state. */ 47 | typedef struct dasm_State dasm_State; 48 | 49 | 50 | /* Initialize and free DynASM state. */ 51 | DASM_FDEF void dasm_init(Dst_DECL, int maxsection); 52 | DASM_FDEF void dasm_free(Dst_DECL); 53 | 54 | /* Setup global array. Must be called before dasm_setup(). */ 55 | DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl); 56 | 57 | /* Grow PC label array. Can be called after dasm_setup(), too. */ 58 | DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc); 59 | 60 | /* Setup encoder. */ 61 | DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist); 62 | 63 | /* Feed encoder with actions. Calls are generated by pre-processor. */ 64 | DASM_FDEF void dasm_put(Dst_DECL, int start, ...); 65 | 66 | /* Link sections and return the resulting size. */ 67 | DASM_FDEF int dasm_link(Dst_DECL, size_t *szp); 68 | 69 | /* Encode sections into buffer. */ 70 | DASM_FDEF int dasm_encode(Dst_DECL, void *buffer); 71 | 72 | /* Get PC label offset. */ 73 | DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc); 74 | 75 | #ifdef DASM_CHECKS 76 | /* Optional sanity checker to call between isolated encoding steps. */ 77 | DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch); 78 | #else 79 | #define dasm_checkstep(a, b) 0 80 | #endif 81 | 82 | 83 | #endif /* _DASM_PROTO_H */ 84 | -------------------------------------------------------------------------------- /tools/dynasm/dasm_x64.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- DynASM x64 module. 3 | -- 4 | -- Copyright (C) 2005-2014 Mike Pall. All rights reserved. 5 | -- See dynasm.lua for full copyright notice. 6 | ------------------------------------------------------------------------------ 7 | -- This module just sets 64 bit mode for the combined x86/x64 module. 8 | -- All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | x64 = true -- Using a global is an ugly, but effective solution. 12 | return require("dasm_x86") 13 | -------------------------------------------------------------------------------- /tools/dynasm/dynasm: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | 3 | PGM=$(readlink -f "$0") 4 | # If readlink is missing, try directly 5 | [ "$PGM" = "" ] && PGM="$0" 6 | 7 | LUA=/usr/bin/luajit 8 | [ -x "$LUA" ] || LUA="`which luajit`" 9 | [ -x "$LUA" ] || LUA=/usr/bin/lua 10 | [ -x "$LUA" ] || LUA=lua 11 | 12 | $LUA $PGM.lua -A x86 >/dev/null 2>&1 || { 13 | # No useful lua try the mini. 14 | dir="`dirname \"$PGM\"`" 15 | [ -f "$dir/minilua.c" -a ! -x "$dir/minilua" ] && { 16 | echo A suitable real lua was not found, building minilua ... 17 | CC=`( which gcc clang pcc ; echo cc ) | head -1 | sed 's:.*/::'` 18 | $CC -o "$dir/minilua" "$dir/minilua.c" -lm 19 | } 20 | 21 | LUA="$dir/minilua" 22 | 23 | $LUA $PGM.lua -A x86 >/dev/null 2>&1 || { 24 | echo Unable to find a suitable lua to run DynASM 25 | exit 1 26 | } 27 | } 28 | 29 | exec $LUA $PGM.lua "$@" 30 | -------------------------------------------------------------------------------- /tools/fgmp-1.0b5/Index.txt: -------------------------------------------------------------------------------- 1 | Index of /afs/sipb/project/stk/src/STk-2.2.0/Mp/fgmp-1.0b5 2 | 3 | This content is being served through the [1]AFS server 4 | ronald-ann.mit.edu in the [2]sipb.mit.edu AFS cell. If you have any 5 | questions about this content, please contact the administrator of this 6 | directory, who made it publicly available. The administrators of the 7 | stuff.mit.edu AFS gateway are not responsible for this content and have 8 | no ability to remove it. 9 | 10 | The administrator of this directory is jhawk of sipb.mit.edu. 11 | 12 | [ICO] Name Last modified Size 13 | __________________________________________________________________ 14 | [ ] Makefile 1993-12-09 07:43 142 15 | [TXT] gmp.c 1993-12-09 06:35 38K 16 | [TXT] gmp.h 1993-12-09 06:35 4.1K 17 | [ ] notes 1993-12-09 06:35 3.5K 18 | __________________________________________________________________ 19 | 20 | Apache/2.4.7 (Ubuntu) Server at stuff.mit.edu Port 443 21 | 22 | References 23 | 24 | 1. http://en.wikipedia.org/wiki/Andrew_File_System 25 | 2. https://stuff.mit.edu/afs/sipb.mit.edu/ 26 | -------------------------------------------------------------------------------- /tools/fgmp-1.0b5/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Free MP 3 | # 4 | CC=gcc 5 | CFLAGS=-O 6 | 7 | libfgmp.a: gmp.o 8 | ar cq libfgmp.a gmp.o 9 | ranlib libfgmp.a 10 | 11 | clean: 12 | rm -f gmp.o libfgmp.a core *~ 13 | -------------------------------------------------------------------------------- /tools/lightning.h: -------------------------------------------------------------------------------- 1 | /******************************** -*- C -*- **************************** 2 | * 3 | * lightning main include file 4 | * 5 | ***********************************************************************/ 6 | 7 | 8 | /*********************************************************************** 9 | * 10 | * Copyright 2000 Free Software Foundation, Inc. 11 | * Written by Paolo Bonzini. 12 | * 13 | * This file is part of GNU lightning. 14 | * 15 | * GNU lightning is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU Lesser General Public License as published 17 | * by the Free Software Foundation; either version 2.1, or (at your option) 18 | * any later version. 19 | * 20 | * GNU lightning is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | * License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public License 26 | * along with GNU lightning; see the file COPYING.LESSER; if not, write to the 27 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, 28 | * MA 02111-1307, USA. 29 | * 30 | ***********************************************************************/ 31 | 32 | #ifndef __lightning_h 33 | #define __lightning_h 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #if defined(__i386__) || defined(__i386) || defined(_M_IX86) 40 | #include 41 | 42 | #ifndef LIGHTNING_DEBUG 43 | #include 44 | #endif 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #endif 53 | 54 | #if (defined(__powerpc__) || defined(__PPC__)) && defined(__BIG_ENDIAN__) && !defined(__PPC64__) 55 | #include 56 | 57 | #ifndef LIGHTNING_DEBUG 58 | #include 59 | #endif 60 | 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #endif 68 | 69 | #if defined(__sparc__) 70 | #include 71 | 72 | #ifndef LIGHTNING_DEBUG 73 | #include 74 | #endif 75 | 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #endif 83 | 84 | #if !defined(JIT_R0) 85 | #include 86 | 87 | #ifndef LIGHTNING_DEBUG 88 | #include 89 | #endif 90 | 91 | #include 92 | #include 93 | #include 94 | #include 95 | #include 96 | #include 97 | 98 | #ifndef JIT_R0 99 | #error GNU lightning does not support the current target 100 | #endif 101 | #endif 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __lightning_h */ 108 | -------------------------------------------------------------------------------- /tools/lightning/funcs-common.h: -------------------------------------------------------------------------------- 1 | /******************************** -*- C -*- **************************** 2 | * 3 | * Platform-independent layer inline functions (common part) 4 | * 5 | ***********************************************************************/ 6 | 7 | 8 | /*********************************************************************** 9 | * 10 | * Copyright 2000, 2001, 2002 Free Software Foundation, Inc. 11 | * Written by Paolo Bonzini. 12 | * 13 | * This file is part of GNU lightning. 14 | * 15 | * GNU lightning is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU Lesser General Public License as published 17 | * by the Free Software Foundation; either version 2.1, or (at your option) 18 | * any later version. 19 | * 20 | * GNU lightning is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | * License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public License 26 | * along with GNU lightning; see the file COPYING.LESSER; if not, write to the 27 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, 28 | * MA 02111-1307, USA. 29 | * 30 | ***********************************************************************/ 31 | 32 | #ifndef __lightning_funcs_common_h 33 | #define __lightning_funcs_common_h 34 | 35 | #include 36 | #include 37 | 38 | static int jit_fail(const char *, const char*, int, const char *) JIT_UNUSED; 39 | 40 | int 41 | jit_fail(const char *msg, const char *file, int line, const char *function) 42 | { 43 | fprintf(stderr, "%s: In function `%s':\n", file, function); 44 | fprintf(stderr, "%s:%d: %s\n", file, line, msg); 45 | abort(); 46 | } 47 | 48 | 49 | #ifndef jit_start_pfx 50 | #define jit_start_pfx() ( (jit_insn*)0x4) 51 | #define jit_end_pfx() ( (jit_insn*)0x0) 52 | #endif 53 | 54 | #endif /* __lightning_funcs_common_h */ 55 | -------------------------------------------------------------------------------- /tools/lightning/sparc/funcs.h: -------------------------------------------------------------------------------- 1 | /******************************** -*- C -*- **************************** 2 | * 3 | * Platform-independent layer inline functions (Sparc) 4 | * 5 | ***********************************************************************/ 6 | 7 | 8 | /*********************************************************************** 9 | * 10 | * Copyright 2000, 2001, 2002 Free Software Foundation, Inc. 11 | * Written by Paolo Bonzini. 12 | * 13 | * This file is part of GNU lightning. 14 | * 15 | * GNU lightning is free software; you can redistribute it and/or modify it 16 | * under the terms of the GNU Lesser General Public License as published 17 | * by the Free Software Foundation; either version 2.1, or (at your option) 18 | * any later version. 19 | * 20 | * GNU lightning is distributed in the hope that it will be useful, but 21 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | * License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public License 26 | * along with GNU lightning; see the file COPYING.LESSER; if not, write to the 27 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, 28 | * MA 02111-1307, USA. 29 | * 30 | ***********************************************************************/ 31 | 32 | 33 | 34 | #ifndef __lightning_funcs_h 35 | #define __lightning_funcs_h 36 | 37 | #if !defined(__GNUC__) && !defined(__GNUG__) 38 | #error Go get GNU C, I do not know how to flush the cache 39 | #error with this compiler. 40 | #else 41 | /* Why doesn't this compile?!? 42 | * static void 43 | * jit_flush_code(start, end) 44 | * void *start; 45 | * void *end; 46 | */ 47 | 48 | static void 49 | jit_flush_code(void* start, void* end) 50 | { 51 | #ifndef LIGHTNING_CROSS 52 | register char *dest; 53 | 54 | __asm__ __volatile__ ("stbar"); 55 | for (dest = (char *)start; dest <= (char *)end; dest += 4) { 56 | __asm__ __volatile__ ("flush %0"::"r"(dest)); 57 | } 58 | 59 | /* [SPARC Architecture Manual v8, page 139, implementation note #5] */ 60 | __asm__ __volatile__ ("nop; nop; nop; nop; nop"); 61 | #endif 62 | } 63 | #endif 64 | 65 | #endif /* __lightning_core_h */ 66 | -------------------------------------------------------------------------------- /tritium/.gitattributes: -------------------------------------------------------------------------------- 1 | version.sh export-subst 2 | -------------------------------------------------------------------------------- /tritium/.gitignore: -------------------------------------------------------------------------------- 1 | bfi 2 | bfi.out 3 | bfi.version.h 4 | tmp.* 5 | .build-opts.* 6 | -------------------------------------------------------------------------------- /tritium/Makefile: -------------------------------------------------------------------------------- 1 | # The real makefile is VERY GNU make specific, so here's a POSIX makefile 2 | # to forward the basic requests. 3 | # But don't actually label it because that will break a really old make. 4 | 5 | # If you don't have GNU make you can compile with a simple command: 6 | # cc -O -o bfi *.c 7 | # 8 | # but without any of the big options. 9 | # 10 | # To do a more complex manual build you need: 11 | # 12 | # cc -DCNF -DVERSION='VS_S(Manual Build)' -o bfi *.c 13 | # 14 | # Plus maybe one or more of these 15 | # -DDISABLE_DYNASM 16 | # -DDISABLE_TCCLIB 17 | # -DDISABLE_GNULIGHTNING 18 | # -DDISABLE_DLOPEN 19 | # 20 | # For example: 21 | # 22 | # cc -DCNF -DVERSION='VS_S(Manual Build)' -DDISABLE_DYNASM -o bfi *.c -llightning -ltcc -ldl 23 | # 24 | # The DynASM is the most complex to build manually; see the GNU Makefile. 25 | # The other options should work fine given the necessary libraries, 26 | # which will have to be added to the command line. 27 | # 28 | # Note GNU Lightning V1 needs to be flagged with -DGNULIGHTv1 29 | # 30 | 31 | all install clean pristine: 32 | +@gmake $@ 33 | -------------------------------------------------------------------------------- /tritium/README.md: -------------------------------------------------------------------------------- 1 | Tritium 2 | ======= 3 | 4 | This is the fastest brainfuck interpreter around, it's official name is Ρ‴ but as most people won't pronounce that right it's working name is Tritium. 5 | 6 | It's optimisations include: 7 | 8 | * Run length encoding. 9 | * Change '[-]' and '[+]' to value set instructions. 10 | * Change "Move or ADD" ( MADD ) loops to value set instructions. 11 | * Change more complex loops if the initial states are known 12 | * Preserve known values through loops. 13 | * Downgrade loops to conditionals. 14 | * Eliminate redundant writes. 15 | * Eliminate redundant reads. 16 | * Convert known Print instructions into constant prints and eliminate the related tape write. 17 | 18 | It has multiple backends. 19 | * JIT compile using GUN Lightning. 20 | * JIT compile using luajit's dynasm. 21 | * Two JIT C compiles, one using libtcc the other using gcc and dlopen(). 22 | * A 'Tree' interpreter for debugging, profiling and tracing. 23 | * An array interpreter as a reasonably fast fallback for the JIT. 24 | * Generate C code for later compiling. 25 | * Generate macro calls for translation to Ruby, Perl, PHP, Awk etc. 26 | * Generate NASM assembler to directly create an ELF32 executable (for example a 116 byte Hello World). 27 | * Generate NASM or gas (intel) assembler to link with libc. 28 | * Generate a program for the unix dc(1) command. 29 | 30 | And finally there is the 'cheat' option '-Orun', this runs the syntax tree as far as it can with the 'Tree' interpreter before running a code generator. If the BF program has no input (',') commands this will run the program to completion (or hang) and convert it into a 'Hello World'. However, as this currently is done using the tree interpreter it runs at less than a tenth the speed of the JIT runners. 31 | 32 | Though even without "-Orun" it'll convert a standard 'Hello world!' and several other 'benchmark' programs into C code like this: 33 |
34 | #include <stdio.h>
35 | 
36 | int main(void)
37 | {
38 |   puts("Hello World!");
39 |   return 0;
40 | }
41 | 
42 | -------------------------------------------------------------------------------- /tritium/bfi.be.def: -------------------------------------------------------------------------------- 1 | /* 2 | Preprocessor abuse; all the modifications to the main bfi.c for adding 3 | backends are brought here in one place. To add another backend just add 4 | it to the list and fill in it's entry. 5 | */ 6 | 7 | #ifdef NO_EXT_BE 8 | #undef XX 9 | #else 10 | 11 | #define Nothing_Here /* TCC-0.9.27 needs a something in a argument of a 12 | * preprocessor macro, as this seems like a likely 13 | * bug for other compilers I've added a macro that 14 | * is something but compiles to nothing. */ 15 | #if XX == 1 16 | /* The enum */ 17 | #define X(a,b,c,d,e,f) c_ ## a, 18 | #elif XX == 2 19 | /* Help text */ 20 | #define X(a,b,c,d,e,f) c 21 | #elif XX == 3 22 | /* Option flags */ 23 | #define X(a,b,c,d,e,f) d 24 | #elif XX == 4 25 | /* Defaults */ 26 | #define X(a,b,c,d,e,f) 27 | #elif XX == 5 28 | /* Print code */ 29 | #define X(a,b,c,d,e,f) e 30 | #elif XX == 6 31 | /* Last Option Limits */ 32 | #define X(a,b,c,d,e,f) 33 | #elif XX == 7 34 | /* Run directly */ 35 | #define X(a,b,c,d,e,f) f 36 | #elif XX == 8 37 | /* Comma strings */ 38 | #define X(a,b,c,d,e,f) ,#a 39 | #elif XX == 9 40 | /* Call option func. */ 41 | #define X(a,b,c,d,e,f) 42 | #else 43 | #define X(a,b,c,d,e,f) 44 | #endif 45 | 46 | /****************************************************************************/ 47 | 48 | #include "bfi.dasm.h" 49 | #include "bfi.gnulit.h" 50 | #include "bfi.ccode.h" 51 | #include "bfi.gmp.h" 52 | 53 | #include "bfi.dd.h" 54 | #include "bfi.nasm.h" 55 | #include "bfi.bf.h" 56 | #include "bfi.cpp.h" 57 | 58 | /****************************************************************************/ 59 | 60 | #undef X 61 | #undef Nothing_Here 62 | #undef XX 63 | #endif /*NO_EXT_BE*/ 64 | -------------------------------------------------------------------------------- /tritium/bfi.bf.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "bfi.tree.h" 8 | #include "bfi.bf.h" 9 | 10 | static int col = 0; 11 | 12 | static void 13 | pc(int ch) { if (col>=72) { putchar('\n'); col=0; } col++; putchar(ch); } 14 | 15 | static void 16 | ps(const char * p) { 17 | if (!p || col+strlen(p) >= 72) {putchar('\n'); col = 0;} 18 | while(p&&*p) pc(*p++); 19 | } 20 | 21 | static void 22 | pr(char ch, int r) { 23 | while(r-->0) pc(ch); 24 | } 25 | 26 | /* 27 | * Regenerate some BF code. 28 | * 29 | * Most optimised tokens cannot be generated because the code would need 30 | * temp cells on the tape, but the information as to which temps were used 31 | * has been discarded. However, we could use any cell who's value is known. 32 | * 33 | * You may have to reduce the optimisation to -O1 34 | */ 35 | void 36 | print_bf(void) 37 | { 38 | struct bfi *n = bfprog; 39 | int i, last_offset = 0; 40 | 41 | if (!noheader) 42 | printf("[ BF regenerated from %s ]\n", bfname); 43 | 44 | while(n) 45 | { 46 | if (n->type == T_MOV) { 47 | last_offset -= n->count; 48 | n = n->next; 49 | continue; 50 | } 51 | 52 | if(n->offset>last_offset) 53 | pr('>', n->offset-last_offset); 54 | if(n->offsetoffset); 56 | last_offset = n->offset; 57 | 58 | switch(n->type) 59 | { 60 | case T_SET: 61 | ps("[-]"); 62 | i = n->count; 63 | if(i>0) pr('+', i); 64 | if(i<0) pr('-', -i); 65 | break; 66 | 67 | case T_ADD: 68 | i = n->count; 69 | if(i>0) pr('+', i); 70 | if(i<0) pr('-', -i); 71 | break; 72 | 73 | case T_PRT: 74 | pc('.'); 75 | break; 76 | 77 | case T_INP: 78 | pc(','); 79 | break; 80 | 81 | case T_MULT: case T_CMULT: 82 | case T_IF: 83 | case T_WHL: 84 | pc('['); 85 | break; 86 | 87 | case T_END: 88 | pc(']'); 89 | break; 90 | 91 | case T_STOP: 92 | ps("[-]+[]"); 93 | break; 94 | 95 | case T_DUMP: 96 | pc('#'); 97 | break; 98 | 99 | case T_NOP: 100 | break; 101 | 102 | default: 103 | fprintf(stderr, "Error on code generation:\n" 104 | "Bad node: %s ptr+%d, cnt=%d.\n", 105 | tokennames[n->type], n->offset, n->count); 106 | fprintf(stderr, "Optimisation level probably too high for BF output\n"); 107 | exit(1); 108 | } 109 | n=n->next; 110 | } 111 | ps(0); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /tritium/bfi.bf.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFI_BF_H 2 | #define _BFI_BF_H 3 | 4 | void print_bf(void); 5 | #define BE_BF 6 | #endif 7 | 8 | #ifdef XX 9 | X(bf,BF, 10 | printf(" -F Attempt to regenerate BF code. (This disables a lot of optimisations.)\n");, 11 | case 'F': do_codestyle = c_bf; break; , 12 | case c_bf: print_bf(); break; , 13 | Nothing_Here ) 14 | #if XX == 4 15 | if (do_codestyle == c_bf) { 16 | opt_no_calc = opt_no_endif = opt_no_litprt = 1; 17 | opt_regen_mov = 0; 18 | hard_left_limit = 0; 19 | 20 | if (iostyle > 0) { 21 | fprintf(stderr, "The -F option only supports binary I/O.\n"); 22 | exit(255); 23 | } 24 | iostyle = 0; 25 | } 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /tritium/bfi.ccode.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFI_CCODE_H 2 | #define _BFI_CCODE_H 3 | #define BE_CCODE 4 | 5 | void run_ccode(void); 6 | void print_ccode(FILE * ofd); 7 | int checkarg_ccode(char * opt, char * arg); 8 | #endif 9 | 10 | #ifdef XX 11 | #if !defined(DISABLE_TCCLIB) || !defined(DISABLE_DLOPEN) 12 | X(ccode,CCODE, 13 | printf(" -c Create C code. If combined with -r the code is loaded and run.\n"); , 14 | case 'c': do_codestyle = c_ccode; break; , 15 | case c_ccode: print_ccode(stdout); break; , 16 | case c_ccode: run_ccode(); break; ) 17 | 18 | #if (XX == 4) && !defined(DISABLE_RUNC) 19 | if (do_run <= 0 && do_codestyle == c_default && verbose<3 20 | && (cell_length <= UINTBIG_BIT)) { 21 | do_run = (do_run != 0); 22 | do_codestyle = c_ccode; 23 | } 24 | #endif 25 | #else 26 | X(ccode,CCODE, 27 | printf(" -c Create C code.\n"); , 28 | case 'c': do_codestyle = c_ccode; break; , 29 | case c_ccode: print_ccode(stdout); break; , 30 | Nothing_Here ) 31 | #endif 32 | 33 | #if XX == 4 34 | if (do_codestyle == c_ccode && 35 | cell_length>UINTBIG_BIT && cell_length != INT_MAX) { 36 | fprintf(stderr, "The C generator does not support that cell size\n"); 37 | exit(255); 38 | } 39 | if (do_codestyle == c_ccode) special_eof = 1; 40 | #endif 41 | #if XX == 9 42 | { int f = checkarg_ccode(opt, arg); 43 | if (f) return f; 44 | } 45 | #endif 46 | #endif 47 | -------------------------------------------------------------------------------- /tritium/bfi.cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFI_CPP_H 2 | #define _BFI_CPP_H 3 | 4 | void print_cpp(void); 5 | #define BE_CPP 6 | #endif 7 | 8 | #ifdef XX 9 | X(cpp,CPP, 10 | printf(" -C Code for C or C++ with Boost cpp_int\n");, 11 | case 'C': case 'A': do_codestyle = c_cpp; break; , 12 | case c_cpp: print_cpp(); break; , 13 | Nothing_Here ) 14 | 15 | #if XX == 4 16 | if (do_codestyle == c_cpp) { 17 | if (iostyle == 3) { 18 | fprintf(stderr, "The -C option does not support -fintio\n"); 19 | exit(255); 20 | } 21 | } 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /tritium/bfi.dasm.h: -------------------------------------------------------------------------------- 1 | #ifndef DISABLE_DYNASM 2 | #ifndef _BFI_DYNASM_H 3 | #define _BFI_DYNASM_H 4 | 5 | void run_dynasm(void); 6 | int checkarg_dynasm(char * opt, char * arg); 7 | extern int dynasm_ok; 8 | #define BE_DYNASM 9 | #endif 10 | 11 | #ifdef XX 12 | X(dynasm,DYNASM, 13 | printf(" -q Run using the Dynasm interpreter/assembler.\n"); , 14 | case 'q': do_codestyle = c_dynasm; break; , 15 | /* Cannot do print_dynasm() */ , 16 | case c_dynasm: run_dynasm(); break; ) 17 | #if XX == 4 18 | if (do_run == -1 && do_codestyle == c_default && 19 | (cell_length==0 || cell_size>0) && 20 | verbose<3 && !enable_trace && !debug_mode && dynasm_ok) { 21 | do_run = 1; 22 | do_codestyle = c_dynasm; 23 | } 24 | if (do_codestyle == c_dynasm && do_run == -1) do_run = 1; 25 | if (do_codestyle == c_dynasm && cell_length>0 && cell_size == 0) { 26 | fprintf(stderr, "The DynASM generator does not support that cell size\n"); 27 | exit(255); 28 | } 29 | #endif 30 | #if XX == 6 31 | if (cell_size == 0 && do_codestyle == c_dynasm) set_cell_size(-1); 32 | #endif 33 | #if XX == 9 34 | { int f = checkarg_dynasm(opt, arg); 35 | if (f) return f; 36 | } 37 | #endif 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /tritium/bfi.dd.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFI_DD_H 2 | #define _BFI_DD_H 3 | 4 | void print_dd(void); 5 | int checkarg_dd(char * opt, char * arg); 6 | #define BE_DD 7 | #endif 8 | 9 | #ifdef XX 10 | X(dd,DD, 11 | printf(" -d Code for be-pipe of bf2any\n"); 12 | printf(" -bfrle Generate an RLE variant of BF\n");, 13 | case 'd': do_codestyle = c_dd; break; , 14 | case c_dd: print_dd(); break; , 15 | Nothing_Here ) 16 | 17 | #if XX == 4 18 | if (do_codestyle == c_dd) { 19 | opt_no_lessthan = 1; 20 | if (opt_regen_mov < 0) opt_regen_mov = 1; 21 | 22 | if (iostyle == 3) { 23 | fprintf(stderr, "The -d option does not support -fintio\n"); 24 | exit(255); 25 | } 26 | } 27 | #endif 28 | #if XX == 9 29 | if (do_codestyle == c_default) { 30 | if (!strcmp(opt, "-bfrle")) { 31 | (void) checkarg_dd(opt, arg); 32 | do_codestyle = c_dd; 33 | opt_no_calc = opt_no_endif = opt_no_litprt = 1; 34 | return 1; 35 | } 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tritium/bfi.gmp.h: -------------------------------------------------------------------------------- 1 | #if !defined(DISABLE_GMP) 2 | 3 | #ifndef _BFI_GMP_H 4 | #define _BFI_GMP_H 5 | 6 | void run_gmparray(void); 7 | #endif 8 | 9 | #ifdef XX 10 | X(gmp,LIBGMP, 11 | printf(" -fgmp Run using libgmp bignums (cell size unlimited)\n"); , 12 | /* No short option */ , 13 | /* No code dump */ , 14 | case c_gmp: run_gmparray(); break; ) 15 | #if XX == 4 16 | if (do_run && do_codestyle == c_default && 17 | (cell_length > UINTBIG_BIT || 18 | (cell_length>32 && iostyle == 3)) && 19 | verbose<3 && !enable_trace && !debug_mode) { 20 | do_run = 1; 21 | do_codestyle = c_gmp; 22 | } 23 | if (do_codestyle == c_gmp && do_run == -1) do_run = 1; 24 | if (do_codestyle == c_gmp && cell_length == 0) set_cell_size(INT_MAX); 25 | #endif 26 | #if XX == 9 27 | if (!strcmp(opt, "-fgmp")) { 28 | do_codestyle = c_gmp; 29 | return 1; 30 | } 31 | #endif 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /tritium/bfi.gnulit.h: -------------------------------------------------------------------------------- 1 | #ifndef DISABLE_GNULIGHTNING 2 | 3 | #ifndef _BFI_GNULIGHTNING_H 4 | #define _BFI_GNULIGHTNING_H 5 | 6 | void run_gnulightning(void); 7 | extern int gnulightning_ok; 8 | #define BE_GNULIGHTNING 9 | #endif 10 | 11 | #ifdef XX 12 | X(gnulightning,GNULIGHTNING, 13 | printf(" -j Run using the GNU lightning interpreter/assembler.\n"); , 14 | case 'j': do_codestyle = c_gnulightning; break; , 15 | /* Cannot do print_gnulightning() */ , 16 | case c_gnulightning: run_gnulightning(); break; ) 17 | #if XX == 4 18 | if (do_run == -1 && do_codestyle == c_default && 19 | (cell_length==0 || cell_size>0) && 20 | verbose<3 && !enable_trace && !debug_mode && gnulightning_ok) { 21 | do_run = 1; 22 | do_codestyle = c_gnulightning; 23 | } 24 | if (do_codestyle == c_gnulightning && do_run == -1) do_run = 1; 25 | if (do_codestyle == c_gnulightning && cell_length>0 && cell_size == 0) { 26 | fprintf(stderr, "The GNU Lightning generator does not support that cell size\n"); 27 | exit(255); 28 | } 29 | #endif 30 | #if XX == 6 31 | if (cell_size == 0 && do_codestyle == c_gnulightning) set_cell_size(-1); 32 | #endif 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /tritium/bfi.nasm.h: -------------------------------------------------------------------------------- 1 | #ifndef _BFI_NASM_H 2 | #define _BFI_NASM_H 3 | 4 | void print_nasm(void); 5 | int checkarg_nasm(char * opt, char * arg); 6 | #define BE_NASM 7 | #endif 8 | 9 | #ifdef XX 10 | X(nasm,NASM, 11 | printf(" -s Create i386 Linux ELF NASM code.\n"); , 12 | case 's': do_codestyle = c_nasm; break; , 13 | case c_nasm: print_nasm(); break; , 14 | Nothing_Here ) 15 | #if XX == 4 16 | if (do_codestyle == c_nasm) 17 | { 18 | if (cell_length && cell_size != 8) { 19 | fprintf(stderr, "The 'nasm' generator only supports 8 bit cells.\n"); 20 | exit(255); 21 | } 22 | set_cell_size(8); 23 | if (iostyle > 0) { 24 | fprintf(stderr, "The 'nasm' generator only supports binary I/O.\n"); 25 | exit(255); 26 | } 27 | iostyle = 0; 28 | } 29 | #endif 30 | #if XX == 6 31 | if (cell_size == 0 && do_codestyle == c_nasm) set_cell_size(-1); 32 | #endif 33 | #if XX == 9 34 | { int f = checkarg_nasm(opt, arg); 35 | if (f) return f; 36 | } 37 | #endif 38 | #endif 39 | -------------------------------------------------------------------------------- /tritium/bfi.run.h: -------------------------------------------------------------------------------- 1 | 2 | extern int verbose; 3 | extern int do_run; 4 | 5 | extern double run_time, io_time; 6 | 7 | extern int huge_ram_available; 8 | 9 | void run_tree(void); 10 | void * map_hugeram(void); 11 | void unmap_hugeram(void); 12 | void delete_tree(void); 13 | void * tcalloc(size_t nmemb, size_t size); 14 | 15 | int getch(int oldch); 16 | int getint(int oldch); 17 | void putch(int ch); 18 | void putint(unsigned int ch); 19 | -------------------------------------------------------------------------------- /tritium/bfi.runarray.h: -------------------------------------------------------------------------------- 1 | 2 | void run_tree_as_array(void); 3 | int * convert_tree_to_runarray(int merge_mov); 4 | -------------------------------------------------------------------------------- /tritium/bfi.tree.h: -------------------------------------------------------------------------------- 1 | #ifndef CNF 2 | #define DISABLE_GNULIGHTNING 3 | #define DISABLE_TCCLIB 4 | #define DISABLE_DLOPEN 5 | #define DISABLE_DYNASM 6 | #define DISABLE_SSL 7 | #define DISABLE_GMP 8 | #endif 9 | 10 | #if defined(__GNUC__) \ 11 | && (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 12 | #define UNUSED __attribute__ ((__unused__)) 13 | 14 | #if (_XOPEN_VERSION+0) < 500 && _POSIX_VERSION < 200809L 15 | #if !defined(strdup) && !defined(_WIN32) 16 | #define strdup(str) \ 17 | ({char*_s=(str);int _l=strlen(_s)+1;void*_t=malloc(_l);if(_t)memcpy(_t,_s,_l);_t;}) 18 | #endif 19 | #endif 20 | 21 | #else 22 | #define UNUSED 23 | #ifndef __attribute__ 24 | #define __attribute__(__ignored__) 25 | #endif 26 | #endif 27 | 28 | #ifndef __has_builtin // Optional of course. 29 | #define __has_builtin(x) 0 // Compatibility with non-clang compilers. 30 | #endif 31 | 32 | extern const char * bfname; 33 | extern int noheader, enable_trace, hard_left_limit, memsize, most_neg_maad_loop; 34 | extern int min_pointer, max_pointer; 35 | extern int min_safe_mem, max_safe_mem; 36 | extern int opt_level; 37 | extern int iostyle, eofcell; 38 | extern char * input_string; 39 | extern int opt_regen_mov; 40 | extern int only_uses_putch; 41 | 42 | extern unsigned cell_length; 43 | extern int cell_size; 44 | extern int cell_mask; 45 | extern int cell_smask; 46 | 47 | #define UM(vx) ((vx) & cell_mask) 48 | #define SM(vx) ((UM(vx) ^ cell_smask) - cell_smask) 49 | #define XM(vx) (cell_size<=8?UM(vx):SM(vx)) 50 | 51 | #define TOKEN_LIST(Mac) \ 52 | Mac(MOV) Mac(ADD) Mac(PRT) Mac(INP) Mac(WHL) Mac(END) \ 53 | Mac(SET) Mac(CALC) Mac(CALCMULT) Mac(CHR) Mac(STR) \ 54 | Mac(IF) Mac(ENDIF) Mac(MULT) Mac(CMULT) \ 55 | Mac(ZFIND) Mac(MFIND) Mac(ADDWZ) Mac(LT) Mac(DIV) \ 56 | Mac(CALC2) Mac(CALC3) Mac(CALC4) Mac(CALC5) \ 57 | Mac(PRTI) Mac(INPI) Mac(STOP) Mac(FINI) Mac(DUMP) \ 58 | Mac(NOP) Mac(DEAD) Mac(CALL) Mac(SUSP) 59 | 60 | #define GEN_TOK_ENUM(NAME) T_ ## NAME, 61 | enum token { TOKEN_LIST(GEN_TOK_ENUM) TCOUNT}; 62 | 63 | struct string { int length; int maxlen; char buf[0]; }; 64 | 65 | struct bfi 66 | { 67 | struct bfi *next; 68 | unsigned char type; 69 | unsigned char orgtype; 70 | 71 | int count; 72 | int offset; 73 | struct bfi *jmp; 74 | 75 | int count2; 76 | int offset2; 77 | int count3; 78 | int offset3; 79 | 80 | int line, col; 81 | int inum; 82 | int iprof; 83 | 84 | struct bfi *prev; 85 | struct string *str; 86 | }; 87 | 88 | extern struct bfi *bfprog; 89 | extern const char* tokennames[]; 90 | extern int node_type_counts[TCOUNT+1]; 91 | extern int total_nodes; 92 | extern int max_indent; 93 | 94 | /* How far to search for constants. */ 95 | #define SEARCHDEPTH 16 96 | #define SEARCHRANGE 1000 97 | 98 | void print_banner(FILE * fd, char const * program); 99 | void calculate_stats(void); 100 | void printtreecell(FILE * efd, int indent, struct bfi * n); 101 | void delete_tree(void); 102 | struct bfi * add_node_after(struct bfi * p); 103 | void bf_basic_hack(void); 104 | 105 | void 106 | find_known_value(struct bfi * n, int v_offset, struct bfi ** n_found, 107 | int * const_found_p, int * known_value_p, int * unsafe_p); 108 | 109 | -------------------------------------------------------------------------------- /tritium/bfi.version.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #ifdef CNF 5 | #ifndef VERSION 6 | #include "bfi.version.h" 7 | #endif 8 | #else 9 | #define VERSION "Manual build" 10 | #endif 11 | 12 | #define VS_Q(x) #x 13 | #define VS_S(x) VS_Q(x) 14 | #ifndef VERSION 15 | #define VS(x) VS_S(VERSION_ ## x) 16 | #ifdef GITHASH 17 | #ifdef GITDECO 18 | #ifdef GITTIME 19 | #define VERSION VS_S(GITDECO) " " VS_S(GITHASH) " " VS_S(GITTIME) 20 | #else 21 | #define VERSION VS_S(GITDECO) " " VS_S(GITHASH) 22 | #endif 23 | #else 24 | #define VERSION VS(MAJOR) "." VS(MINOR) "." VS(BUILD) "? " \ 25 | VS_S(GITHASH) " " VS_S(GITTIME) 26 | #endif 27 | #else 28 | #define VERSION "v" VS(MAJOR) "." VS(MINOR) "." VS(BUILD) VERSION_SUFFIX 29 | #endif 30 | #endif 31 | 32 | /* This list of Operating systems is all those I've actually tried it on. */ 33 | #ifdef __linux__ 34 | #define OSNAME "Linux" 35 | #elif defined(_WIN32) 36 | #define OSNAME "Windows" 37 | #elif defined(__FreeBSD__) 38 | #define OSNAME "FreeBSD" 39 | #elif defined(__OpenBSD__) 40 | #define OSNAME "OpenBSD" 41 | #elif defined(__NetBSD__) 42 | #define OSNAME "NetBSD" 43 | #elif defined(__hpux__) 44 | #define OSNAME "HP-UX" 45 | #elif defined(__osf__) 46 | #define OSNAME "DEC OSF/1" 47 | #elif defined(__APPLE__) 48 | #define OSNAME "Apple" 49 | #elif defined(__EMSCRIPTEN__) 50 | #define OSNAME "Emscripten" 51 | #elif defined(__ultrix__) 52 | #define OSNAME "Ultrix" 53 | #elif defined(__unix__) 54 | #define OSNAME "Unix" 55 | #else 56 | #define OSNAME "an unknown OS" 57 | #endif 58 | 59 | /* And here's the CPUs those OSs were running on */ 60 | #if defined(__x86_64__) || defined(__amd64__) || defined(_M_AMD64) 61 | #ifndef __ILP32__ 62 | #define PROCESSOR "x86_64" 63 | #else 64 | #define PROCESSOR "x86_32" 65 | #endif 66 | #if defined(__ELF__) || defined(_WIN32) || defined(__APPLE__) 67 | #define BFI_FOUND_CPU_X86_64 68 | #endif 69 | #elif defined(__i386__) || defined(_M_IX86) 70 | #define PROCESSOR "i386" 71 | #if defined(__ELF__) || defined(__APPLE__) 72 | #define BFI_FOUND_CPU_X86_32 73 | #endif 74 | #if defined(_WIN32) 75 | #define BFI_FOUND_CPU_X86_32_WINDOWS 76 | #endif 77 | #elif defined(__PPC64__) 78 | #define PROCESSOR "PPC64" 79 | #elif (defined(__powerpc__) || defined(__PPC__)) && defined(__BIG_ENDIAN__) 80 | #define PROCESSOR "PPC" 81 | #ifdef __ELF__ 82 | #define BFI_FOUND_CPU_PPC 83 | #endif 84 | #elif defined(__powerpc__) || defined(__PPC__) 85 | #define PROCESSOR "PPC" 86 | #elif defined(__sparc__) 87 | #define PROCESSOR "Sparc" 88 | #ifdef __ELF__ 89 | #define BFI_FOUND_CPU_SPARC 90 | #endif 91 | #elif defined(__arm__) 92 | #ifdef __thumb2__ 93 | #define PROCESSOR "ARMv7" /* Approx, actually ARMv6t2 */ 94 | #elif __thumb__ 95 | #define PROCESSOR "ARMv6" /* Approx, actually ARMv5t */ 96 | #else 97 | #define PROCESSOR "ARM" 98 | #endif 99 | #elif defined(__AARCH64EL__) 100 | #define PROCESSOR "ARM64" 101 | #elif defined(__MIPSEL__) || defined(__MIPSEB__) 102 | #define PROCESSOR "MIPS" 103 | #elif defined(__SH4__) 104 | #define PROCESSOR "SuperH-4" 105 | #elif defined(__ia64__) 106 | #define PROCESSOR "ia64" 107 | #elif defined(__alpha__) || defined(__alpha) 108 | #define PROCESSOR "DEC Alpha" 109 | #elif defined(__vax__) 110 | #define PROCESSOR "VAX" 111 | #elif defined(__s390x__) 112 | #define PROCESSOR "s390x" 113 | #elif defined(__asmjs__) 114 | #define PROCESSOR "using asm.js" 115 | #else 116 | #define PROCESSOR "?" 117 | #endif 118 | 119 | /* This is what I've spotted this time. */ 120 | #define HOST OSNAME " " PROCESSOR 121 | 122 | void 123 | print_banner(FILE * fd, char const * program) 124 | { 125 | fprintf(fd, "%s: Version "VERSION" on "HOST"\n", program); 126 | } 127 | -------------------------------------------------------------------------------- /tritium/big_int.h: -------------------------------------------------------------------------------- 1 | #ifdef __STDC__ 2 | #include 3 | /* LLONG_MAX came in after inttypes.h, limits.h is very old. */ 4 | #if _POSIX_VERSION >= 199506L || defined(LLONG_MAX) 5 | #include 6 | #endif 7 | #endif 8 | 9 | #ifndef uintbig_t 10 | #ifdef __SIZEOF_INT128__ 11 | #define uintbig_t unsigned __int128 12 | #else 13 | #ifdef _UINT128_T 14 | #define uintbig_t __uint128_t 15 | #else 16 | #if defined(ULLONG_MAX) || defined(__LONG_LONG_MAX__) 17 | #define uintbig_t unsigned long long 18 | #else 19 | #if defined(UINTMAX_MAX) 20 | #define uintbig_t uintmax_t 21 | #else 22 | #define uintbig_t unsigned long 23 | #endif 24 | #endif 25 | #endif 26 | #endif 27 | #endif 28 | 29 | #define UINTBIG_BIT ((int)(CHAR_BIT*sizeof(uintbig_t))) 30 | -------------------------------------------------------------------------------- /tritium/clock.h: -------------------------------------------------------------------------------- 1 | 2 | void start_runclock(void); 3 | void finish_runclock(double * prun_time, double *pwait_time); 4 | void pause_runclock(void); 5 | void unpause_runclock(void); 6 | -------------------------------------------------------------------------------- /tritium/hashmem.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * To use create a variable 'htab' for the first argument. 4 | * 5 | * struct hashtab * htab[1] = {0}; 6 | * 7 | * The string pointed to be 'name' argument is copied into the table so 8 | * it can be a temp buffer. But only the pointer to the 'value' entity 9 | * is stored in the table so the entity must be permanent. 10 | * 11 | * The recommended way to delete the table is: 12 | * 13 | * foreach_entry(htab, delete_htab_entry); 14 | * void delete_htab_entry(word, value) { 15 | * set_entry(htab, word, 0); 16 | * clear(value); 17 | * free(value); 18 | * } 19 | * 20 | */ 21 | 22 | struct hashtab; 23 | typedef void (*hashfunc_p)(char * word, void * value); 24 | char * set_entry(struct hashtab ** hashtab, char * name, void * value); 25 | void * find_entry(struct hashtab ** hashtab, char * name); 26 | void foreach_entry(struct hashtab ** hashtab, hashfunc_p func); 27 | 28 | void hash_stats(struct hashtab ** phashtab, int * size, int * words); 29 | 30 | #ifdef TEST 31 | /* Quick and dirty integer varients */ 32 | void * find_ientry(struct hashtab ** phashtab, int keyval); 33 | char * set_ientry(struct hashtab ** phashtab, int keyval, void * value); 34 | #endif 35 | -------------------------------------------------------------------------------- /tritium/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************** 3 | ** md5.h -- Header file for implementation of MD5 ** 4 | ** RSA Data Security, Inc. MD5 Message Digest Algorithm ** 5 | ** Created: 2/17/90 RLR ** 6 | ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version ** 7 | ** Revised (for MD5): RLR 4/27/91 ** 8 | ** -- G modified to have y&~z instead of y&z ** 9 | ** -- FF, GG, HH modified to add in last register done ** 10 | ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 ** 11 | ** -- distinct additive constant for each step ** 12 | ** -- round 4 added, working mod 7 ** 13 | ********************************************************************** 14 | */ 15 | 16 | /* 17 | ********************************************************************** 18 | ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** 19 | ** ** 20 | ** License to copy and use this software is granted provided that ** 21 | ** it is identified as the "RSA Data Security, Inc. MD5 Message ** 22 | ** Digest Algorithm" in all material mentioning or referencing this ** 23 | ** software or this function. ** 24 | ** ** 25 | ** License is also granted to make and use derivative works ** 26 | ** provided that such works are identified as "derived from the RSA ** 27 | ** Data Security, Inc. MD5 Message Digest Algorithm" in all ** 28 | ** material mentioning or referencing the derived work. ** 29 | ** ** 30 | ** RSA Data Security, Inc. makes no representations concerning ** 31 | ** either the merchantability of this software or the suitability ** 32 | ** of this software for any particular purpose. It is provided "as ** 33 | ** is" without express or implied warranty of any kind. ** 34 | ** ** 35 | ** These notices must be retained in any copies of any part of this ** 36 | ** documentation and/or software. ** 37 | ********************************************************************** 38 | */ 39 | 40 | /* typedef a 32 bit type */ 41 | typedef unsigned int UINT4; 42 | enum { UINT4_must_be_4_bytes=1/(4==sizeof(UINT4)) }; 43 | 44 | /* Data structure for MD5 (Message Digest) computation */ 45 | typedef struct { 46 | UINT4 i[2]; /* number of _bits_ handled mod 2^64 */ 47 | UINT4 buf[4]; /* scratch buffer */ 48 | unsigned char in[64]; /* input buffer */ 49 | unsigned char digest[16]; /* actual digest after MD5Final call */ 50 | } MD5_CTX; 51 | 52 | void MD5Init (); 53 | void MD5Update (); 54 | void MD5Final (); 55 | 56 | /* 57 | ********************************************************************** 58 | ** End of md5.h ** 59 | ******************************* (cut) ******************************** 60 | */ 61 | -------------------------------------------------------------------------------- /tritium/opt_bfbasic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "bfi.tree.h" 7 | 8 | void 9 | bf_basic_hack() 10 | { 11 | struct bfi *n = bfprog; 12 | int indent = 0, i; 13 | 14 | while(n) 15 | { 16 | /* This is something that's always true for BF Basic generated 17 | * code. The 'while-switch' loop takes the first few cells and 18 | * next seven are temps that will always be left at zero. This 19 | * fragment explicitly zeros those cells so the optimiser can 20 | * easily see this is true. 21 | * 22 | * QGT0123456 23 | * @_Q 0 = quit (end), 1 = otherwise 24 | * @_G 0 = performing a jump (goto), 1 = otherwise 25 | */ 26 | 27 | switch(n->type) 28 | { 29 | case T_END: 30 | case T_ENDIF: 31 | /* if (indent == 2 && n->offset == 2) 32 | ; * These loops are always T_IF loops. */ 33 | 34 | indent--; 35 | break; 36 | 37 | case T_MULT: case T_CMULT: 38 | case T_IF: 39 | case T_WHL: 40 | indent++; 41 | 42 | /* The outer loop is on "G", the second is on "T" */ 43 | if (indent != 2 || n->offset != 2) 44 | break; 45 | 46 | /* These explicitly set the value that should already 47 | * exist at this location */ 48 | 49 | n = add_node_after(n); 50 | n->type = T_SET; 51 | n->count = 1; 52 | n->offset = 2; 53 | 54 | for(i=3; i<10; i++) { 55 | n = add_node_after(n); 56 | n->type = T_SET; 57 | n->count = 0; 58 | n->offset = i; 59 | } 60 | break; 61 | } 62 | n=n->next; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tritium/opt_runner.h: -------------------------------------------------------------------------------- 1 | /* Trial run. */ 2 | void try_opt_runner(void); 3 | extern int opt_no_litprt; 4 | -------------------------------------------------------------------------------- /tritium/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # We only need a POSIX shell, but if bash is available it's more likely to be good. 3 | if [ ! -n "$BASH_VERSION" ];then if [ "`which 2>/dev/null bash`" != "" ];then exec bash "$0" "$@"; fi ; fi 4 | 5 | MAJOR=1 6 | MINOR=1 7 | SUFFIX="# Unknown @ `date -R 2>/dev/null || date`" 8 | BUILD= 9 | 10 | # This is expanded by git archive 11 | GITARCHVERSION= 12 | GITHASH=525d346 13 | GITTIME="Wed Jan 31 21:48:48 2024 +0000" 14 | GITDECO=" (HEAD -> master)" 15 | 16 | [ "$GITTIME" != "" ] && SUFFIX="$GITTIME" 17 | [ "$GITDECO" != "" ] && { 18 | GITDECO=`echo "$GITDECO" | 19 | sed \ 20 | -e 's/[ (),][ (),]*/ /g' \ 21 | -e 's/HEAD//' \ 22 | -e 's/master//' \ 23 | -e 's/ *$//' \ 24 | -e 's/^ *//' 25 | ` 26 | } 27 | 28 | # Override from the Makefile. 29 | [ ".$2" != "." -a "$3" != "." ] && { 30 | [ "$GITHASH" = "" ] && 31 | GITHASH="`git log -1 --format=%h 2>/dev/null`" 32 | GITTIME="$GITHASH" 33 | GITDECO="$2" 34 | GITHASH="$3" 35 | } 36 | 37 | git_describe() { 38 | # Get more detail than just git describe --tags 39 | # tag + commits to branch from upstream + local commits + local mods. 40 | 41 | # What's upstream -- "--verify -q" is NOT silent despite the docs, sigh 42 | UPSTREAM=`git rev-parse --verify -q @{u} 2>/dev/null` 43 | 44 | [ "$UPSTREAM" = "" ] && 45 | UPSTREAM=`git rev-parse --verify -q master@{u} 2>/dev/null` 46 | 47 | [ "$UPSTREAM" = "" ] && UPSTREAM=HEAD 48 | 49 | # Find the merge base between this and the upstream. 50 | ORIGIN=`git merge-base $UPSTREAM HEAD` 51 | 52 | # Find the most recent tag. 53 | TAG=`git describe --tags --match='v[0-9]*.[0-9]*' --abbrev=0 $ORIGIN` 54 | [ "$TAG" = "" ] && return 55 | 56 | MAJOR=`echo $TAG | sed "s/^v\([0-9]*\).*/\1/"` 57 | MINOR=`echo $TAG | sed "s/^v[0-9]*\.\([0-9]*\)/\1/"` 58 | 59 | # Commits between the tag and the merge base and from there to HEAD 60 | VER=`git rev-list HEAD ${TAG:+^$TAG} . | wc -l` 61 | DIFF=`git rev-list $ORIGIN..HEAD . | wc -l` 62 | VER=$((VER-DIFF)) 63 | 64 | # Number of modified files. 65 | MOD=`git status --porc . | grep "^ M" | wc -l` 66 | 67 | # Commentary. 68 | echo Origin ver: $MAJOR.$MINOR.$VER, Local commits: $DIFF, Local edits: $MOD 1>&2 69 | 70 | SUFFIX= 71 | [ "$DIFF" -ne 0 ] && SUFFIX="$SUFFIX+$DIFF" 72 | [ "$MOD" -ne 0 -a "$DIFF" -eq 0 ] && SUFFIX="${SUFFIX}+0" 73 | [ "$MOD" -ne 0 ] && SUFFIX="${SUFFIX}.${MOD}" 74 | 75 | [ "$TAG" = "" ] && SUFFIX="$SUFFIX-pre" 76 | 77 | # Add the start of the hash on the end. 78 | SUFFIX="$SUFFIX `git rev-list HEAD -n 1 . | cut -c 1-8`" 79 | BUILD="$VER" 80 | } 81 | 82 | ( (type git && git status ) >/dev/null 2>&1) && git_describe 83 | 84 | if [ -n "$1" ] 85 | then TMPFILE="$1".tmp 86 | else TMPFILE=/dev/stdout 87 | fi 88 | 89 | { 90 | echo "#define VERSION_MAJOR $MAJOR" 91 | echo "#define VERSION_MINOR $MINOR" 92 | echo "#define VERSION_BUILD $BUILD" 93 | echo "#define VERSION_SUFFIX \"$SUFFIX\"" 94 | [ "$GITHASH" != "" ] && echo "#define GITHASH $GITHASH" 95 | [ "$GITTIME" != "" ] && echo "#define GITTIME $GITTIME" 96 | [ "$GITDECO" != "" ] && echo "#define GITDECO $GITDECO" 97 | } > "$TMPFILE" 98 | 99 | [ -n "$1" ] && { 100 | if ! cmp -s "$TMPFILE" "$1" 101 | then 102 | mv "$TMPFILE" "$1" 103 | else rm -f "$TMPFILE" 104 | fi 105 | } 106 | 107 | exit 0 108 | -------------------------------------------------------------------------------- /trivial_substitutions/Hello_world.bewbs: -------------------------------------------------------------------------------- 1 | %c=qw(XX $p++ XZ $p-- XY D++ YX D-- ZY D&=255;while(D){ YZ D&=255;} YY print+chrD ZZ D=ord(getc) ZX print+join(",",@b),"\n"); 2 | $/=$,;$_=<>;s/[XYZ]//g;s/\(\.\)/X/g;s/\[\.\]/Y/g;s/{\.}/Z/g;s/[^XYZ]//g;s/../$c{$&}; /g;s[D]'$b[$p]'g;eval; 3 | =begin comment 4 | 5 | /* From: https://gist.github.com/ELLIOTTCABLE/402586 */ 6 | /* I wrote “Hello, world!” for whatever mad, mad genius wrote this version of Brainfuck: 7 | http://pastie.org/private/siw6uoan1cd6shuao7r8hw (dead link) 8 | */ 9 | 10 | (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] {.}[.] (.)(.) (.)[.] (.)[.] (.)[.] (.)[.] 11 | (.)[.] (.)[.] (.)[.] (.)(.) (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)(.) (.)[.] 12 | (.)[.] (.)[.] (.)(.) (.)[.] (.){.} (.){.} (.){.} (.){.} [.](.) [.]{.} (.)(.) (.)[.] (.)[.] [.][.] (.)(.) (.)[.] 13 | [.][.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] [.][.] [.][.] (.)[.] (.)[.] (.)[.] [.][.] (.)(.) (.)[.] 14 | (.)[.] [.][.] (.){.} (.){.} (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] (.)[.] 15 | (.)[.] (.)[.] (.)[.] [.][.] (.)(.) [.][.] (.)[.] (.)[.] (.)[.] [.][.] [.](.) [.](.) [.](.) [.](.) [.](.) [.](.) 16 | [.][.] [.](.) [.](.) [.](.) [.](.) [.](.) [.](.) [.](.) [.](.) [.][.] (.)(.) (.)[.] [.][.] (.)(.) [.][.] 17 | 18 | #{.}[.][.](.)[.]{.}{.}[.] 19 | 20 | # (.)(.) move memory pointer one right 21 | # (.){.} move memory pointer one left 22 | # (.)[.] increase the current cell 23 | # [.](.) decrease the current cell 24 | # [.][.] output the current cell as character 25 | # {.}{.} input a byte to current cell 26 | # [.]{.} jump back to the corresponding start loop 27 | # {.}[.] if the current cell is zero, jump past the corresponding end loop, otherwise continue 28 | 29 | # {.}(.) output the current state of the storage tape 30 | 31 | #[.]{.} 32 | 33 | # See also: http://codegolf.stackexchange.com/questions/84/interpret-brainfuck#answer-933 34 | -------------------------------------------------------------------------------- /trivial_substitutions/README.md: -------------------------------------------------------------------------------- 1 | 2 | This is a collection of tools and interpreters for brainfuck variants, mostly trivial brainfuck substitutions. 3 | 4 | The Ruby "xqt" scripts execute mostly languages from https://esolangs.org/ 5 | 6 | File | Description 7 | -----|------------ 8 | bbf2bfrle.c | Convert base2 BF-RLE to BF-RLE 9 | blub.pl | [Blub](http://esolangs.org/wiki/Blub) interpreter. 10 | Hello_world.bewbs | Another brainfuck variant (Perl eval) 11 | k-on-fuck.pl | Another brainfuck variant (Perl eval) 12 | malbrain.sed | [Malbrain](http://esolangs.org/wiki/Malbrain) conversion to C in sed. 13 | ook.pl | [Ook](http://esolangs.org/wiki/Ook) interpreter. 14 | petooh.rb | [Petooh](https://github.com/Ky6uk/PETOOH) "eval" interpreter (brainfuck variant) 15 | pikalang.rb | Trivial brainfuck substitution interpreter using the eval from regex and hashtable pattern. 16 | pogaack.pl | [POHAACK](http://esolangs.org/wiki/POGAACK) interpreter (brainfuck variant with RLE) 17 | spoon.rb | Trivial brainfuck substitution interpreter using the eval from regex and hashtable pattern. 18 | zero.rb | Trivial brainfuck substitution interpreter using the eval from regex and hashtable pattern. 19 | 20 | -------------------------------------------------------------------------------- /trivial_substitutions/bbf2bfrle.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | >* Right in binary > is 1, * is 0 4 | <* Left in binary < is 1, * is 0 5 | +* Up in binary + is 1, * is 0 6 | -* Down in binary - is 1, * is 0 7 | 8 | [ Begin 9 | ] End 10 | , Input 11 | . Output 12 | 13 | = Set current cell to zero. 14 | 15 | { ??? } Nested comments in braces. 16 | \n\s\r... Whitespace is ignored. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | void do_file(FILE *fd); 23 | 24 | int 25 | main(int argc, char** argv) 26 | { 27 | int ar; 28 | if (argc == 1) 29 | do_file(stdin); 30 | else for(ar=1; ar 0) { 58 | if (pcnt > 1) 59 | col += printf("%.0f%c", pcnt, pch); 60 | else { 61 | col++; putchar(pch); 62 | } 63 | pch = pcnt = 0; 64 | if (col > 70) {col=0; putchar('\n');} 65 | } 66 | if (ch == EOF) break; 67 | if (ch == '>' || ch == '<' || ch == '+' || ch == '-') { 68 | pcnt = pcnt*2 + 1; 69 | pch = ch; 70 | continue; 71 | } 72 | if (ch == '.' || ch == ',' || ch == '[' || ch == ']') 73 | { 74 | putchar(ch); 75 | if (++col > 70) {col=0; putchar('\n');} 76 | continue; 77 | } 78 | if (ch == '=') { 79 | putchar('='); 80 | if (++col > 70) {col=0; putchar('\n');} 81 | continue; 82 | } 83 | fprintf(stderr, "Illegal character '%c' (%d)\n", 84 | ch>' '&&ch<='~'?ch:' ', ch); 85 | exit(1); 86 | } 87 | if (col) {col=0; putchar('\n');} 88 | } 89 | -------------------------------------------------------------------------------- /trivial_substitutions/blub.pl: -------------------------------------------------------------------------------- 1 | %c=qw(AC $p++ CA $p-- AA D++ BB D-- BC D&=255;while(D){ CB D&=255;} BA print+chrD AB D=ord(getc)); 2 | $/=$,;$_=<>;s/[ABC]//g;s/Blub\./A/gi;s/Blub!/B/gi;s/Blub\?/C/gi;s/[^ABC]//g;s/../$c{$&};/g;s[D]'$b[$p]'g;eval 3 | -------------------------------------------------------------------------------- /trivial_substitutions/heartf2bf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | '💗' => '>', 4 | '💜' => '<', 5 | '💖' => '+', 6 | '❤' => '-', 7 | '💌' => '.', 8 | '❣️' => ',', 9 | '💛' => '[', 10 | '💙' => ']' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | print 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | 16 | -------------------------------------------------------------------------------- /trivial_substitutions/k-on-fuck.pl: -------------------------------------------------------------------------------- 1 | %c=qw(AAA $p++ AAB $p-- ABA D++ ABB D-- BBA D&=255;while(D){ BBB D&=255;} BAA print+chrD BAB D=ord(getc)); 2 | $/=$,;$_=<>;s/[AB]//g;s/うん/A/g;s/たん/B/g;s/[^AB]//g;s/.../$c{$&};/g;s[D]'$b[$p]'g;eval 3 | -------------------------------------------------------------------------------- /trivial_substitutions/malbrain.sed: -------------------------------------------------------------------------------- 1 | 1i\ 2 | #include\ 3 | #define b while(*m) {\ 4 | #define i read(0,m,1);\ 5 | #define o write(1,m,1);\ 6 | #define d --*m;\ 7 | #define u ++*m;\ 8 | #define l m-=1;\ 9 | #define r m+=1;\ 10 | #define e }\ 11 | #define _ return 0;}\ 12 | char mem[30000];int main(){register char*m=mem; 13 | $a\ 14 | _ 15 | s/[^>.]//g 16 | y/>./NE/ 17 | H 18 | g 19 | s/\n//g 20 | s/^N/l/ 21 | s/^E/rE/ 22 | t nxtl 23 | :nxtl 24 | s/^rN/l/ 25 | s/^lN/u/ 26 | s/^uN/d/ 27 | s/^dN/o/ 28 | s/^oN/i/ 29 | s/^iN/b/ 30 | s/^bN/e/ 31 | s/^eN/r/ 32 | t nxtl 33 | h 34 | s/^\(.\)E.*/\1/ 35 | t prti 36 | b dele 37 | :prti 38 | p 39 | g 40 | s/^\(.\)E/\1/ 41 | t nxtl 42 | :dele 43 | d 44 | -------------------------------------------------------------------------------- /trivial_substitutions/ook.pl: -------------------------------------------------------------------------------- 1 | %c=qw(AC $p++ CA $p-- AA D++ BB D-- BC D&=255;while(D){ CB D&=255;} BA print+chrD AB D=ord(getc)); 2 | $/=$,;$_=<>;$_=lc$_;s/\bb?ook([.!?])[\t\n ]*b?ook([.!?])/O\1 O\2/g; 3 | s/O\./A/g;s/O!/B/g;s/O\?/C/g;s/[^ABC]//g;s/../$c{$&};/g;s[D]'$b[$p]'g;eval 4 | -------------------------------------------------------------------------------- /trivial_substitutions/petooh.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[^adehkKoOru]/,'').gsub( 3 | /(kO|Ko|[Kk]u(dah|karek|d))/, 4 | 'Kudah' => 'p+=1;', 5 | 'kudah' => 'p-=1;', 6 | 'Ko' => 'm[p]+=1;', 7 | 'kO' => 'm[p]-=1;', 8 | 'Kud' => '(', 9 | 'kud' => ')while((m[p]&=255)!=0);', 10 | 'Kukarek' => 'putc m[p];', 11 | 'kukarek' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/pikalang.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /([A-Za-z_][A-Za-z0-9_]*)|./, 4 | 'pipi' => 'p+=1;', 5 | 'pichu' => 'p-=1;', 6 | 'pi' => 'm[p]+=1;', 7 | 'ka' => 'm[p]-=1;', 8 | 'pika' => '(', 9 | 'chu' => ')while((m[p]&=255)!=0);', 10 | 'pikachu' => 'putc m[p];', 11 | 'pikapi' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/pogaack.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | %c=qw(r ;$p+=1 l ;$p-=1 u ;D+=1 d ;D-=1 b ;D&=255;while(D){ e ;D&=255;} o ;print+chrD i ;D=ord(getc) x +1); 3 | $/=$,; 4 | $_=<>; 5 | $_=uc$_; 6 | s/POGACK!/r/g; 7 | s/POGAACK!/l/g; 8 | s/POGAAACK!/u/g; 9 | s/POOCK!/d/g; 10 | s/POGAAACK\?/o/g; 11 | s/POOCK\?/i/g; 12 | s/POGACK\?/b/g; 13 | s/POGAACK\?/e/g; 14 | s/POCK!/x/g; 15 | s/[^rludiobex]//g; 16 | s/./$c{$&}/g;s[D]'$b[$p]'g; 17 | eval 18 | -------------------------------------------------------------------------------- /trivial_substitutions/spoon.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[^01]/,'').gsub( 3 | /1|000|01.|0011|00101111|00101*0/, 4 | '1' => 'm[p]+=1;', 5 | '000' => 'm[p]-=1;', 6 | '010' => 'p+=1;', 7 | '011' => 'p-=1;', 8 | '0011' => ')while(m[p]!=0);', 9 | '00100' => '(', 10 | '001010' => 'putc m[p];', 11 | '0010110' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 12 | '00101110' => 'print "(p=",p,",m=",m,")\n";', 13 | '00101111' => 'exit;' 14 | ) 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-abcd.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'c=0;'+ARGF.read.gsub(/./, 3 | 'A' => 'c+=1;', 4 | 'B' => 'c-=1;', 5 | 'C' => 'c=STDIN.getbyte if !STDIN.eof;', 6 | 'D' => 'putc c;') 7 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-alphuck.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/./, 3 | 'a' => 'p+=1;', 4 | 'c' => 'p-=1;', 5 | 'e' => 'm[p]+=1;', 6 | 'i' => 'm[p]-=1;', 7 | 'j' => 'putc m[p];', 8 | 'o' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'p' => '(', 10 | 's' => ')while((m[p]&=255)!=0);') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-assfuck.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[Aa][Ss][Ss]|./, 3 | 'asS' => 'p-=1;', 4 | 'aSs' => 'p+=1;', 5 | 'Ass' => 'm[p]-=1;', 6 | 'ass' => 'm[p]+=1;', 7 | 'AsS' => '(', 8 | 'ASS' => ')while((m[p]&=255)!=0);', 9 | 'ASs' => 'putc m[p];', 10 | 'aSS' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-baby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub( 3 | /[a-z][a-z0-9]*|./, 4 | 'gaga' => 'p+=1;', 5 | 'gugu' => 'p-=1;', 6 | 'aaag' => 'm[p]+=1;', 7 | 'uuug' => 'm[p]-=1;', 8 | 'unga' => 'm[p]=0;', 9 | 'guuu' => 'putc m[p];', 10 | 'gaaa' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 11 | 'gagu' => '(', 12 | 'guga' => ')while((m[p]&=255)!=0);') 13 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bf.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | %c=qw( 3 | > $p++; 4 | < $p--; 5 | + $b[$p]++; 6 | - $b[$p]--; 7 | . print+chr$b[$p]; 8 | , $b[$p]=ord(getc); 9 | [ $b[$p]&=255;while($b[$p]){ 10 | ] $b[$p]&=255;} ); 11 | $/=$,;$_=<>;s/./$c{$&}/g;eval 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read. 3 | gsub(/[^\[\]+,-.<>]/,''). 4 | gsub(/\[\-\]\+*|\++|-+|>+|<+|./, Hash.new{|_, k| 5 | (k[0] == '+') ? "m[p]+="+k.length.to_s+";\n" : 6 | (k[0] == '-') ? "m[p]-="+k.length.to_s+";\n" : 7 | (k[0] == '>') ? "p+="+k.length.to_s+";\n" : 8 | (k[0] == '<') ? "p-="+k.length.to_s+";\n" : 9 | (k[0..3] == '[-]+') ? "m[p]="+(k.length-3).to_s+";\n" : "#{k}\n" 10 | }.merge({ 11 | '>' => 'p+=1;', 12 | '<' => 'p-=1;', 13 | '+' => 'm[p]+=1;', 14 | '-' => 'm[p]-=1;', 15 | '[' => '(', 16 | ']' => ')while((m[p]&=255)!=0);', 17 | '.' => 'putc m[p];', 18 | ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 19 | '[-]' => 'm[p]=0;', 20 | '#' => 'print "(p=",p,",m=",m,")\n";' 21 | })); 22 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bf2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /./, 4 | '>'=>'p+=1;', 5 | '<'=>'p-=1;', 6 | '+'=>'m[p]+=1;', 7 | '-'=>'m[p]-=1;', 8 | '['=>'(', 9 | ']'=>')while((m[p]&=255)!=0);', 10 | '.'=>'putc m[p];', 11 | ','=>'m[p]=STDIN.getbyte if !STDIN.eof;') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bfl.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+Integer(ARGF.read.gsub(/[^0-9a-zA-Z]/,"")).to_s(8).gsub(/./, 3 | '1' => 'p+=1;', 4 | '2' => 'p-=1;', 5 | '3' => 'm[p]+=1;', 6 | '4' => 'm[p]-=1;', 7 | '5' => 'putc m[p];', 8 | '6' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | '7' => '(', 10 | '0' => ')while((m[p]&=255)!=0);') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bfwide.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/./, 3 | '>' => 'p+=1;', 4 | '<' => 'p-=1;', 5 | '+' => 'm[p]+=1;', 6 | '-' => 'm[p]-=1;', 7 | '[' => '(', 8 | ']' => ')while((m[p]&=255)!=0);', 9 | '.' => 'putc m[p];', 10 | ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-blub.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | print 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub(/[0-9]/,'_'). 3 | gsub(/([!-~]*)/, ' \1 ').gsub(/[\n\t ]+/,' '). 4 | gsub(/ blub/,' 3').gsub(/\./,'0').gsub(/\!/,'1').gsub(/\?/,'2'). 5 | gsub(/3([0-2]) 3([0-2])/, '3\1\2'); 6 | gsub(/[!-~]*/, 7 | '302' => 'p+=1;', 8 | '320' => 'p-=1;', 9 | '300' => 'm[p]+=1;', 10 | '311' => 'm[p]-=1;', 11 | '312' => '(', 12 | '321' => ')while((m[p]&=255)!=0);', 13 | '310' => 'putc m[p];', 14 | '301' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-bwee.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[!-~]+|./, 4 | 'BWEE' => 'p+=1;', 5 | 'BWEEE' => 'p-=1;', 6 | 'BWEEEE' => 'm[p]+=1;', 7 | 'BWEEEEE' => 'm[p]-=1;', 8 | 'BWEEEEEE' => 'putc m[p];', 9 | 'BWEEEEEEE' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'BWEEEEEEEE' => '(', 11 | 'BWEEEEEEEEE' => ')while((m[p]&=255)!=0);') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-cga.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | h = { 4 | '文明' => 'p+=1;', 5 | '和谐' => 'p-=1;', 6 | '爱国' => 'm[p]+=1;', 7 | '自由' => 'm[p]-=1;', 8 | '诚信' => 'putc m[p];', 9 | '友善' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | '富强' => '(', 11 | '民主' => ')while((m[p]&=255)!=0);', 12 | '敬业' => 'm[p]+=5;', 13 | '平等' => 'm[p]-=5;' 14 | } 15 | 16 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 17 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(r,h); 18 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-chris.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = Hash.new{|_, k| 3 | if k =~ /^lol(ol)*$/ then "m[p]+="+((k.length-1)/2).to_s+";" 4 | elsif k =~ /^rii*p$/ then "m[p]-="+(k.length-2).to_s+";" 5 | elsif k[0..5] == "shift " then "p+="+k[5..-1]+";" 6 | end }; 7 | 8 | h.merge!({ 9 | 'chris' => 'p+=1;', 10 | 'lee' => 'p-=1;', 11 | 'lol' => 'm[p]+=1;', 12 | 'rip' => 'm[p]-=1;', 13 | 'chris?' => '(', 14 | 'lee?' => ')while((m[p]&=255)!=0);', 15 | 'ok' => 'putc m[p];', 16 | 'pls' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 17 | 'rekt' => 'm[p]=0;', 18 | 'gg' => 'exit;', 19 | 'troll' => 'print (m[p]&255).to_s;', 20 | }); 21 | 22 | eval 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub(/[\n\t ]+/," ") 23 | .gsub(/shift -?[0-9]+|[!-~]+|./, h); 24 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-compbf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | print ARGF.read.gsub(/[^\[\]<>+,-.]/,'').gsub(/(.{1,72})/, "\\1\n"); 3 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-cupid.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[-><][-><]|./, 4 | '->' => 'p+=1;', 5 | '<-' => 'p-=1;', 6 | '><' => 'm[p]+=1;', 7 | '<>' => 'm[p]-=1;', 8 | '<<' => 'putc m[p];', 9 | '>>' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | '-<' => '(', 11 | '>-' => ')while((m[p]&=255)!=0);', 12 | '--' => 'print p,",",m,"\n";') 13 | 14 | # >> input a byte to current cell 15 | # << output the current cell as character 16 | # -> move memory pointer one right 17 | # <- move memory pointer one left 18 | # >< increase the current cell 19 | # <> decrease the current cell 20 | # -< if the current cell is zero, jump to the corresponding >-, otherwise continue 21 | # >- jump back to the corresponding -< 22 | # -- output the current state of the storage tape 23 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-developers.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read 3 | .gsub(/Developer[sz]|./i,Hash.new{|_, k| (k.length>1)?k[-1]:' '; }) 4 | .gsub(/[sz]+|./, 5 | 's' => 'm[p]+=1;', 6 | 'ss' => 'm[p]-=1;', 7 | 'sss' => 'p+=1;', 8 | 'ssss' => 'p-=1;', 9 | 'sssss' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'ssssss' => 'putc m[p];', 11 | 'sssssss' => '(', 12 | 'ssssssss' => ')while((m[p]&=255)!=0);', 13 | 'z' => 'sleep(1);', 14 | 'zz' => 'print "\033[H\033[J";', 15 | 'zzz' => 'm[p]=(rand() * 256).to_i;', 16 | ) 17 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-df.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/8=+D|./, 3 | '8=D' => 'p+=1;', 4 | '8==D' => 'p-=1;', 5 | '8===D' => 'm[p]+=1;', 6 | '8====D' => 'm[p]-=1;', 7 | '8=====D' => 'putc m[p];', 8 | '-' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | '8======D' => '(', 10 | '8=======D' => ')while((m[p]&=255)!=0);' 11 | ); 12 | 13 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-dotty.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | '..' => 'p+=1;', 4 | '::' => 'p-=1;', 5 | '.:.' => 'm[p]+=1;', 6 | '.::' => 'm[p]-=1;', 7 | ':.::' => 'putc m[p];', 8 | ':...' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | ':.:.' => '(', 10 | ':..:' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[^.:]/,'').gsub(r,h); 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-excon.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'p=0;f=1;'+ARGF.read.gsub(/./, 3 | ':' => 'p=0;f=1;', 4 | '^' => 'p^=f;', 5 | '<' => 'f*=2;', 6 | '!' => 'putc p;') 7 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-flufflepuff.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'b' => 'p+=1;', 4 | 't' => 'p-=1;', 5 | 'pf' => 'm[p]+=1;', 6 | 'bl' => 'm[p]-=1;', 7 | '!' => 'putc m[p];', 8 | '?' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | '*gasp*' => '(', 10 | '*pomf*' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-h.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'h' => 'p+=1;', 4 | 'hh' => 'p-=1;', 5 | 'hhh' => 'm[p]+=1;', 6 | 'hhhh' => 'm[p]-=1;', 7 | 'hhhhh' => 'putc m[p];', 8 | 'hhhhhh' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'hhhhhhh' => '(', 10 | 'hhhhhhhh' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-heartf.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | '💗' => 'p+=1;', 4 | '💜' => 'p-=1;', 5 | '💖' => 'm[p]+=1;', 6 | '❤' => 'm[p]-=1;', 7 | '💌' => 'putc m[p];', 8 | '❣' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | '💛' => '(', 10 | '💙' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | 16 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-iuab.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = Hash.new{|_, k| '##'; }.merge({ 3 | 'i' => 'p+=1;', 4 | 'use' => 'p-=1;', 5 | 'arch' => 'm[p]+=1;', 6 | 'linux' => 'm[p]-=1;', 7 | 'btw' => 'putc m[p];', 8 | 'by' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'the' => '(', 10 | 'way' => ')while((m[p]&=255)!=0);', 11 | 'gentoo' => 'print "\n",m,"\n";', 12 | ' ' => '' 13 | }); 14 | 15 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 16 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/;.*$/,'').gsub(/[\n\t ]+/," ").gsub(r,h).gsub(/.*##.*/,'STDERR.puts "Error in translation\n";'); 17 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-jr.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/./, 3 | '[' => 'm[p]-=1;', 4 | ']' => 'm[p]+=1;', 5 | ';' => 'm[p]*=m[p];', 6 | '.' => 'print m[p].to_s;', 7 | ',' => 'putc m[p];', 8 | '@' => 'm[p]=0;', 9 | '~' => 'print "\033[2J\033[H";', 10 | '>' => 'p+=1;', 11 | '<' => 'p-=1;', 12 | '!' => 'print "the source of your program";', 13 | ) 14 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-la-wea.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'puta' => 'p+=1;', 4 | 'chucha' => 'p-=1;', 5 | 'weón' => 'm[p]+=1;', 6 | 'aweonao' => 'm[p]+=2;', 7 | 'maricón' => 'm[p]-=1;', 8 | 'maraco' => 'm[p]-=2;', 9 | 'maraca' => 'm[p]=0;', 10 | 'ctm' => 'putc m[p];', 11 | 'quéweá' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 12 | 'pichula' => '(', 13 | 'tula' => ')while(m[p]!=0);', 14 | 'pico' => 'break;', 15 | 'chúpala' => 'print m[p].to_s;', 16 | 'brígido' => 'm[p] = Integer(gets) rescue 0;', 17 | 'mierda' => 'exit;', 18 | 'perkin' => 'if pf then pf=false; m[p]=v; else pf=true; v=m[p]; end;' 19 | } 20 | 21 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 22 | eval 'm=Hash.new(p=0);pf=false;'+ARGF.read.downcase.gsub(/[\n\t ]+/," ").gsub(r,h); 23 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-meep.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[!-~]+|./, 4 | 'meeP' => 'p+=1;', 5 | 'Meep' => 'p-=1;', 6 | 'mEEp' => 'm[p]+=1;', 7 | 'MeeP' => 'm[p]-=1;', 8 | 'MEEP' => 'putc m[p];', 9 | 'meep' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'mEEP' => '(', 11 | 'MEEp' => ')while((m[p]&=255)!=0);') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-mini.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/./, 3 | 'r' => 'p+=1;', 4 | 'l' => 'p-=1;', 5 | 'u' => 'm[p]+=1;', 6 | 'd' => 'm[p]-=1;', 7 | 'o' => 'putc m[p];', 8 | 'i' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'b' => '(', 10 | 'e' => ')while((m[p]&=255)!=0);') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-minimal.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /./, 4 | '>'=>'p+=1;', 5 | '<'=>'p-=1;', 6 | '+'=>'m[p]+=1;', 7 | '-'=>'m[p]-=1;', 8 | '/'=>'if (m[p]&=255)!=0) ', 9 | '.'=>'putc m[p];', 10 | ','=>'m[p]=STDIN.getbyte if !STDIN.eof;') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-newbiefuck.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/./, 3 | '>' => 'p+=1;', 4 | '<' => 'p-=1;', 5 | '+' => 'm[p]+=1;', 6 | '-' => 'm[p]-=1;', 7 | '.' => 'putc m[p] if m[p]!=0;', 8 | ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | '[' => 'loop do;', 10 | ']' => 'break if ((m[p]&=255)==0);end;') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-nice.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub( 3 | /[a-z][a-z0-9]*|./, 4 | 'right' => 'p+=1;', 5 | 'left' => 'p-=1;', 6 | 'up' => 'm[p]+=1;', 7 | 'down' => 'm[p]-=1;', 8 | 'out' => 'putc m[p];', 9 | 'in' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'begin' => '(', 11 | 'end' => ')while((m[p]&=255)!=0);') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-nonima.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | # Language 'nonimatulaelcebe' 3 | eval 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub( 4 | /ma|la|tu|ni|be|ce|no|el|./, 5 | 'ma' => 'p+=1;', 6 | 'la' => 'p-=1;', 7 | 'tu' => 'm[p]+=1;', 8 | 'ni' => 'm[p]-=1;', 9 | 'be' => 'putc m[p];', 10 | 'ce' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 11 | 'no' => '(', 12 | 'el' => ')while((m[p]&=255)!=0);') 13 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-omam.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'hold your horses now' => 'p+=1;', 4 | 'sleep until the sun goes down' => 'p-=1;', 5 | 'through the woods we ran' => 'm[p]+=1;', 6 | 'deep into the mountain sound' => 'm[p]-=1;', 7 | "don't listen to a word i say" => 'putc m[p];', 8 | 'the screams all sound the same' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'though the truth may vary' => '(', 10 | 'this ship will carry' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-ook.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | print 'm=Hash.new(p=0);'+ARGF.read.downcase.gsub(/[0-9]/,'_'). 3 | gsub(/([!-~]*)/, ' \1 ').gsub(/[\n\t ]+/,' '). 4 | gsub(/ ook/,' 3').gsub(/\./,'0').gsub(/\!/,'1').gsub(/\?/,'2'). 5 | gsub(/3([0-2]) 3([0-2])/, '3\1\2'); 6 | gsub(/[!-~]*/, 7 | '302' => 'p+=1;', 8 | '320' => 'p-=1;', 9 | '300' => 'm[p]+=1;', 10 | '311' => 'm[p]-=1;', 11 | '312' => '(', 12 | '321' => ')while((m[p]&=255)!=0);', 13 | '310' => 'putc m[p];', 14 | '301' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-penis.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /8=+D|./, 4 | '8=D'=>'p+=1;', 5 | '8==D'=>'p-=1;', 6 | '8===D'=>'m[p]+=1;', 7 | '8====D'=>'m[p]-=1;', 8 | '8=====D'=>'putc m[p];', 9 | '8======D'=>'m[p]=STDIN.getbyte if !STDIN.eof;', 10 | '8=======D'=>'(', 11 | '8========D'=>')while((m[p]&=255)!=0);') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-pikalang.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /([A-Za-z_][A-Za-z0-9_]*)|./, 4 | 'pipi' => 'p+=1;', 5 | 'pichu' => 'p-=1;', 6 | 'pi' => 'm[p]+=1;', 7 | 'ka' => 'm[p]-=1;', 8 | 'pika' => '(', 9 | 'chu' => ')while((m[p]&=255)!=0);', 10 | 'pikachu' => 'putc m[p];', 11 | 'pikapi' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-pluso.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval'c=1;'+ARGF.read.gsub(/./,'p'=>'c=(c+1)%27;','o'=>'putc c!=0?c+64:32;')+'puts' 3 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-pogaack.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.upcase. 3 | gsub(/PO[GOC][ACK][A-Z]*[!\?]/, 4 | 'POGACK!' => 'r', 5 | 'POGAACK!' => 'l', 6 | 'POGAAACK!' => 'u', 7 | 'POOCK!' => 'd', 8 | 'POGAAACK?' => 'o', 9 | 'POOCK?' => 'i', 10 | 'POGACK?' => 'b', 11 | 'POGAACK?' => 'e', 12 | 'POCK!' => 'x'). 13 | gsub(/[^rludoibex]/,''). 14 | gsub(/[rlud]x*|./, 15 | Hash.new{|_, k| 16 | (k[0] == 'u') ? "m[p]+="+k.length.to_s+";\n" : 17 | (k[0] == 'd') ? "m[p]-="+k.length.to_s+";\n" : 18 | (k[0] == 'r') ? "p+="+k.length.to_s+";\n" : 19 | (k[0] == 'l') ? "p-="+k.length.to_s+";\n" : 20 | "#{k}\n" 21 | }.merge({ 22 | 'r' => 'p+=1;', 23 | 'l' => 'p-=1;', 24 | 'u' => 'm[p]+=1;', 25 | 'd' => 'm[p]-=1;', 26 | 'b' => '(', 27 | 'e' => ')while((m[p]&=255)!=0);', 28 | 'o' => 'putc m[p];', 29 | 'i' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 30 | })); 31 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-qqq.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | s = 0; 4 | h = Hash.new{|_, k| 5 | if k == "'" then s=1-s ; "" 6 | elsif k == '"' && s==0 then "(" 7 | elsif k == '"' && s!=0 then ")while((m[p]&=255)!=0);" 8 | else "" 9 | end }; 10 | h[';'] = "p+=1;" 11 | h['-'] = "p-=1;" 12 | h['.'] = "m[p]+=1;" 13 | h[','] = "m[p]-=1;" 14 | h['!'] = 'putc m[p];' 15 | h['?'] = 'm[p]=STDIN.getbyte if !STDIN.eof;' 16 | 17 | eval 'm=Hash.new(p=0);' + ARGF.read.gsub(/./,h) 18 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-rev9.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | "It's alright" => 'p-=1;', 4 | 'turn me on, dead man' => 'p+=1;', 5 | 'Number 9' => 'm[p]+=1;', 6 | 'if you become naked' => 'm[p]-=1;', 7 | 'The Beatles' => 'putc m[p];', 8 | 'Paul is dead' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'Revolution 1' => '(', 10 | 'Revolution 9' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-shish.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | h = { 4 | 'praytoshishkirka' => 'm[p]+=1;', 5 | 'praytopolinka' => 'm[p]-=1;', 6 | 'praytoshshkrkX10' => 'm[p]+=10;', 7 | 'praytoplnkX10' => 'm[p]-=10;', 8 | '<-' => 'p-=1;', 9 | '->' => 'p+=1;', 10 | 'shishpol' => 'print m[p].to_s;', 11 | 'shishkirism' => 'putc m[p];', 12 | 'shishkirkapolinka' => 'm[p]=0;', 13 | 'shshclr' => 'print "\033[38;5;" + m[p].to_s + "m";', 14 | 'plnk!' => 'sleep(m[p]/1000.0);', 15 | 'shshkrkplnk' => 'p=0;', 16 | 'shshpofck' => 'raise "666";', 17 | 'polshsh' => 'print "\n";', 18 | 19 | # '' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 20 | # '' => '(', 21 | # '' => ')while((m[p]&=255)!=0);', 22 | } 23 | 24 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 25 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(r,h); 26 | 27 | ## praytoshishkirka accumulator + 1 28 | ## praytopolinka accumulator - 1 29 | ## praytoshshkrkX10 accumulator + 10 30 | ## praytoplnkX10 accumulator - 10 31 | ## <- pointer move left 32 | ## -> pointer move right 33 | ## shishpol displays the value of the variable 34 | ## shishkirism displays the value of the variable symbol 35 | ## shishkirkapolinka reset accumulator 36 | ## shshclr changes the color of the console text by changing the cell value 37 | ## plnk! creates a delay in the program due to the value of the variable in milliseconds 38 | ## shshkrkplnk reset cell 39 | ## shshpofck generates a program error with code 666 40 | ## polshsh creates a new line 41 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-tapelang.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/#[^\n]*\n|./, 3 | '<' => 'p-=1;', 4 | '>' => 'p+=1;', 5 | '-' => 'm[p]-=1;', 6 | '+' => 'm[p]+=1;', 7 | '[' => '(', 8 | ']' => ')while((m[p]&=255)!=0);', 9 | 'o' => 'putc m[p];', 10 | 'i' => 'm[p]=STDIN.getbyte if !STDIN.eof;') 11 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-ternary.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[012][012]|./, 4 | '01' => 'p+=1;', 5 | '00' => 'p-=1;', 6 | '11' => 'm[p]+=1;', 7 | '10' => 'm[p]-=1;', 8 | '20' => 'putc m[p];', 9 | '21' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | '02' => '(', 11 | '12' => ')while((m[p]&=255)!=0);', 12 | '22' => 'print p,",",m,"\n";') 13 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-tick.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /./, 4 | '>' => 'p+=1;', 5 | '<' => 'p-=1;', 6 | '+' => 'm[p]+=1;', 7 | '*' => 'putc m[p];') 8 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-tmcc.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'しの' => 'p+=1;', 4 | 'さばにき' => 'p-=1;', 5 | 'SMD' => 'm[p]+=1;', 6 | 'にゃんこ' => 'm[p]-=1;', 7 | 'ゲェジ' => 'putc m[p];', 8 | 'がりん' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'NEMO' => '(', 10 | 'キュゥ' => ')while((m[p]&=255)!=0);' 11 | } 12 | 13 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 14 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[\n\t ]+/," ").gsub(r,h); 15 | 16 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-train.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = Hash.new{|_, k| 3 | if k[0] == "+" then "m[p]+="+k[1..-1]+';' 4 | elsif k[0] == "-" then "m[p]-="+k[1..-1]+';' 5 | elsif k[0] == ">" then "p+="+k[1..-1]+';' 6 | elsif k[0] == "<" then "p-="+k[1..-1]+';' 7 | end }; 8 | 9 | h.merge!({ 10 | '>' => 'p+=1;', 11 | '<' => 'p-=1;', 12 | '+' => 'm[p]+=1;', 13 | '-' => 'm[p]-=1;', 14 | '[' => '(', 15 | ']' => ')while((m[p]&=255)!=0);', 16 | '.' => 'putc m[p];', 17 | ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 18 | '=' => 'm[p]=0;', 19 | '@' => 'p=0;', 20 | '!' => 'exit;', 21 | ':' => 'print (m[p]&255).to_s;', 22 | }); 23 | 24 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(/[-+><][0-9]+|./, h); 25 | 26 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-wooloo.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[wlWL][oO][oO]|./, 4 | 'woo' => 'p+=1;', 5 | 'loo' => 'p-=1;', 6 | 'Woo' => 'm[p]+=1;', 7 | 'Loo' => 'm[p]-=1;', 8 | 'wOO' => 'putc m[p];', 9 | 'lOO' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'WOO' => '(', 11 | 'LOO' => ')while((m[p]&=255)!=0);') 12 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-yo.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[Yy][oO][!?]?|./, 4 | 'yo' => 'p+=1;', 5 | 'YO' => 'p-=1;', 6 | 'Yo!' => 'm[p]+=1;', 7 | 'Yo?' => 'm[p]-=1;', 8 | 'YO!' => 'putc m[p];', 9 | 'yo?' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 10 | 'yo!' => '(', 11 | 'YO?' => ')while((m[p]&=255)!=0);') 12 | 13 | # yo increment the data pointer (to point to the next cell to the right). 14 | # YO decrement the data pointer (to point to the next cell to the left). 15 | # Yo! increment (increase by one) the byte at the data pointer. 16 | # Yo? decrement (decrease by one) the byte at the data pointer. 17 | # YO! output the byte at the data pointer. 18 | # yo? accept one byte of input, storing its value in the byte at the data pointer. 19 | # yo! if the byte at the data pointer is zero, then instead of moving 20 | # the instruction pointer forward to the next command, jump it 21 | # forward to the command after the matching YO? command. 22 | # YO? if the byte at the data pointer is nonzero, then instead of 23 | # moving the instruction pointer forward to the next command, 24 | # jump it back to the command after the matching yo! command. 25 | -------------------------------------------------------------------------------- /trivial_substitutions/xqt-zzz.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | h = { 3 | 'zz' => 'p+=1;', 4 | '-zz' => 'p-=1;', 5 | 'z' => 'm[p]+=1;', 6 | '-z' => 'm[p]-=1;', 7 | 'zzz' => 'putc m[p];', 8 | '-zzz' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 9 | 'z+z' => '(', 10 | 'z-z' => ')while((m[p]&=255)!=0);', 11 | 12 | 'ZZ' => 'p+=1;', 13 | '-ZZ' => 'p-=1;', 14 | 'Z' => 'm[p]+=1;', 15 | '-Z' => 'm[p]-=1;', 16 | 'ZZZ' => 'putc m[p];', 17 | '-ZZZ' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 18 | 'Z+Z' => '(', 19 | 'Z-Z' => ')while((m[p]&=255)!=0);', 20 | 21 | } 22 | r = Regexp.union(Regexp.union(h.keys.sort{|a,b|b.length<=>a.length}),/./); 23 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub(r,h); 24 | -------------------------------------------------------------------------------- /trivial_substitutions/zero.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | eval 'm=Hash.new(p=0);'+ARGF.read.gsub( 3 | /[!-~]+/, 4 | '0+' => 'p+=1;', 5 | '0-' => 'p-=1;', 6 | '0++' => 'm[p]+=1;', 7 | '0--' => 'm[p]-=1;', 8 | '0/' => '(', 9 | '/0' => ')while(m[p]!=0);', 10 | '0.' => 'putc m[p];', 11 | '0?' => 'm[p]=STDIN.getbyte if !STDIN.eof;', 12 | '0,' => 'print m[p].to_s;', 13 | '0;' => 'm[p]=STDIN.gets.to_i if !STDIN.eof;', 14 | ) 15 | -------------------------------------------------------------------------------- /umueller/README: -------------------------------------------------------------------------------- 1 | This archive contains the following programs: 2 | 3 | bfc The compiler for the 'brainfuck' language (240 bytes!) 4 | bfc.asm Source for the compiler 5 | bfi The interpreter for the 'brainfuck' language 6 | bfi.c Source for the interpreter (portable) 7 | src/ Some example programs in 'brainfuck' 8 | src/atoi.b Reads a number from stdin 9 | src/div10.b Divides the number under the pointer by 10 10 | src/hello.b The ubiquitous "Hello World!" 11 | src/mul10.b Multiplies the number under the pointer by 10 12 | src/prime.b Computes the primes up the a variable limit 13 | src/varia.b Small program elements like SWAP, DUP etc. 14 | 15 | 16 | WHATS NEW 17 | ========= 18 | 19 | Yes, I squeezed another ridiculous 56 bytes out of the compiler. They have 20 | their price, though: The new compiler requires OS 2.0, operates on a byte 21 | array instead of longwords, and generates executables that are always 64K 22 | in size. Apart from that the language hasn't changed. Again: 23 | *** OS 2.0 *required* for the compiler and the compiled programs *** 24 | The interpreter works fine under any OS version. And yes, thanks to Chris 25 | Schneider for his ideas how to make the compiler shorter. 26 | 27 | 28 | THE LANGUAGE 29 | ============ 30 | 31 | The language 'brainfuck' knows the following commands: 32 | 33 | Cmd Effect Equivalent in C 34 | --- ------ --------------- 35 | + Increases element under pointer array[p]++; 36 | - Decrases element under pointer array[p]--; 37 | > Increases pointer p++; 38 | < Decreases pointer p--; 39 | [ Starts loop, counter under pointer while(array[p]) { 40 | ] Indicates end of loop } 41 | . Outputs ASCII code under pointer putchar(array[p]); 42 | , Reads char and stores ASCII under ptr array[p]=getchar(); 43 | 44 | All other characters are ignored. The 30000 array elements and p are being 45 | initialized to zero at the beginning. Now while this seems to be a pretty 46 | useless language, it can be proven that it can compute every solvable 47 | mathematical problem (if we ignore the array size limit and the executable 48 | size limit). 49 | 50 | 51 | THE COMPILER 52 | ============ 53 | 54 | The compiler does not check for balanced brackets; they better be. It reads 55 | the source from stdin and writes the executable to stdout. Note that the 56 | executable is always 65536 bytes long, and usually won't be executable if 57 | brackets aren't balanced. OS 2.0 required for the compiler and the compiled 58 | program. 59 | 60 | 61 | THE INTERPRETER 62 | =============== 63 | 64 | For debugging, there's also an interpreter. It expects the name of the 65 | program to interpret on the command line and accepts an additional command: 66 | Whenever a '#' is met in the source and a second argument was passwd to 67 | the interpreter, the first few elements of the array are written to stdout 68 | as numbers 69 | 70 | 71 | Enjoy 72 | 73 | -Urban Mueller 74 | -------------------------------------------------------------------------------- /umueller/bfc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdebath/Brainfuck/525d346c006ea30dfc847ae3b32ed44d44fa9925/umueller/bfc -------------------------------------------------------------------------------- /umueller/bfc.asm: -------------------------------------------------------------------------------- 1 | EXEOBJ 2 | OUTPUT bfc 3 | 4 | OBJSIZE EQU 65536 5 | CODSIZE EQU 32000 6 | 7 | read EQU -$2a 8 | write EQU -$30 9 | input EQU -$36 10 | output EQU -$3c 11 | closlib EQU -$19e 12 | 13 | ; d0 14 | ; d1 len 15 | ; d2 16 | ; d3 1 17 | ; d4 byte 18 | ; d5 offset 19 | ; d6 20 | ; d7 21 | 22 | ; a0 23 | ; a1 24 | ; a2 stack 25 | ; a3 cdptr 26 | ; a4 4 27 | ; a5 code 28 | ; a6 29 | 30 | 31 | initcode: 32 | dc.l $3f3,0,1,0,0,OBJSIZE/4-9,$3e9,OBJSIZE/4-9 33 | 34 | lea (CODSIZE,pc),a5 35 | moveq #4,d0 36 | move.l d0,a4 37 | move.l (a4),a6 38 | jsr -810(a6) 39 | move.l d0,a6 40 | moveq #1,d3 41 | initcode2: 42 | 43 | 44 | 45 | clrmem 46 | move.l a5,a2 47 | moveq #-1,d5 48 | .. clr.b (a2)+ 49 | dbra d5,.. 50 | move.w #$3f2,-(a2) 51 | move.l a5,a2 52 | 53 | 54 | 55 | move.b d3,(a5) 56 | mainloop 57 | move.b (a5),d4 58 | lea (code,pc),a3 59 | 60 | .. move.b (a3)+,d5 61 | move.b (a3)+,d1 62 | cmp.b (a3)+,d4 63 | blo.b .. 64 | bne.b advance 65 | add.l d5,a3 66 | 67 | copy move.b (a3)+,(a5)+ 68 | subq.b #1,d1 69 | bne.b copy 70 | 71 | addq.b #8,d5 72 | bcc.s noloop 73 | move.l a5,-(a2) 74 | noloop 75 | 76 | addq.b #3,d5 77 | bne.s noendl 78 | move.l (a2)+,a0 79 | move.l a0,d0 80 | sub.l a5,d0 81 | move.w d0,(a5)+ 82 | neg.w d0 83 | subq.w #4,d0 84 | move.w d0,-(a0) 85 | noendl 86 | 87 | 88 | advance 89 | clr.b (a5) 90 | readbyte 91 | jsr input(a6) 92 | move.l d0,d1 93 | move.l a5,d2 94 | jsr read(a6) 95 | readbyte2 96 | 97 | tst.b d4 98 | bne.s mainloop 99 | 100 | move.l a2,a5 101 | swap d3 102 | writebyte 103 | jsr output(a6) 104 | move.l d0,d1 105 | move.l a5,d2 106 | jsr write(a6) 107 | writebyte2 108 | 109 | cleanup 110 | move.l a6,a1 111 | move.l (a4),a6 112 | jsr closlib(a6) 113 | moveq #0,d0 114 | rts 115 | cleanup2 116 | 117 | rightcode: 118 | addq.l #1,a5 119 | leftcode: 120 | subq.l #1,a5 121 | 122 | endwcode 123 | addcode: 124 | addq.b #1,(a5) 125 | subcode: 126 | subq.b #1,(a5) 127 | dc.w $6600 128 | endwcode2 129 | 130 | whilecode: 131 | dc.w $6000 132 | whilecode2 133 | 134 | code: 135 | endw: dc.b endwcode-endw-3,6,']' 136 | while: dc.b whilecode-while-3,4,'[' 137 | right: dc.b rightcode-right-3,2,'>' 138 | left: dc.b leftcode-left-3,2,'<' 139 | 140 | out: dc.b writebyte-out-3,writebyte2-writebyte,'.' 141 | sub: dc.b subcode-sub-3,2,'-' 142 | in: dc.b readbyte-in-3,readbyte2-readbyte,',' 143 | add: dc.b addcode-add-3,2,'+' 144 | 145 | beg: dc.b (initcode-beg-3)&$FF,initcode2-initcode,1 146 | end: dc.b cleanup-end-3,cleanup2-cleanup,0 147 | 148 | dx.b OBJSIZE+CODSIZE 149 | 150 | END 151 | -------------------------------------------------------------------------------- /umueller/bfi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdebath/Brainfuck/525d346c006ea30dfc847ae3b32ed44d44fa9925/umueller/bfi -------------------------------------------------------------------------------- /umueller/bfi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int p, r, q; 4 | char a[5000], f[5000], b, o, *s=f; 5 | 6 | void interpret(char *c) 7 | { 8 | char *d; 9 | 10 | r++; 11 | while( *c ) { 12 | //if(strchr("<>+-,.[]\n",*c))printf("%c",*c); 13 | switch(o=1,*c++) { 14 | case '<': p--; break; 15 | case '>': p++; break; 16 | case '+': a[p]++; break; 17 | case '-': a[p]--; break; 18 | case '.': putchar(a[p]); fflush(stdout); break; 19 | case ',': a[p]=getchar();fflush(stdout); break; 20 | case '[': 21 | for( b=1,d=c; b && *c; c++ ) 22 | b+=*c=='[', b-=*c==']'; 23 | if(!b) { 24 | c[-1]=0; 25 | while( a[p] ) 26 | interpret(d); 27 | c[-1]=']'; 28 | break; 29 | } 30 | case ']': 31 | puts("UNBALANCED BRACKETS"), exit(0); 32 | case '#': 33 | if(q>2) 34 | printf("%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n%*s\n", 35 | *a,a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],3*p+2,"^"); 36 | break; 37 | default: o=0; 38 | } 39 | if( p<0 || p>100) 40 | puts("RANGE ERROR"), exit(0); 41 | } 42 | r--; 43 | chkabort(); 44 | } 45 | 46 | main(int argc,char *argv[]) 47 | { 48 | FILE *z; 49 | 50 | q=argc; 51 | 52 | if(z=fopen(argv[1],"r")) { 53 | while( (b=getc(z))>0 ) 54 | *s++=b; 55 | *s=0; 56 | interpret(f); 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /umueller/src/atoi.b: -------------------------------------------------------------------------------- 1 | ==== ==== ==== 2 | cont digi num 3 | ==== ==== ==== 4 | 5 | + 6 | [ 7 | - cont=0 8 | >, 9 | ======SUB10====== 10 | ---------- 11 | 12 | [ not 10 13 | <+> cont=1 14 | =====SUB38====== 15 | ---------- 16 | ---------- 17 | ---------- 18 | -------- 19 | 20 | > 21 | =====MUL10======= 22 | [>+>+<<-]>>[<<+>>-]< dup 23 | 24 | >>>+++++++++ 25 | [ 26 | <<< 27 | [>+>+<<-]>>[<<+>>-]< dup 28 | [<<+>>-] 29 | >>- 30 | ] 31 | <<<[-]< 32 | ======RMOVE1====== 33 | < 34 | [>+<-] 35 | ] 36 | < 37 | ] 38 | >>[<<+>>-]<< 39 | # 40 | -------------------------------------------------------------------------------- /umueller/src/div10.b: -------------------------------------------------------------------------------- 1 | ==== ==== ==== ==== ==== 2 | num ten tmp bool div 3 | ==== ==== ==== ==== ==== 4 | 5 | >+++++++++< 6 | [ 7 | >>>+<< bool= 1 8 | [>+>[-]<<-] bool= ten==0 9 | >[<+>-] ten = tmp 10 | >[<<++++++++++>>>+<-] if ten=0 ten=10 inc div 11 | <<- dec ten 12 | <- dec num 13 | ] 14 | >>>>[<<<<+>>>>-]<<<< copy div to num 15 | >[-]< clear ten 16 | 17 | -------------------------------------------------------------------------------- /umueller/src/hello.b: -------------------------------------------------------------------------------- 1 | >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] 2 | <.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[ 3 | <++++>-]<+.[-]++++++++++. 4 | 5 | -------------------------------------------------------------------------------- /umueller/src/mul10.b: -------------------------------------------------------------------------------- 1 | =====MUL10======= 2 | [>+<-]> ; move num one right ie num2=num 3 | >>++++++++++ ; load 10 into fourth element 4 | [ 5 | <<[<+>>+<-] ; add num2 to first and third element 6 | >[<+>-]> ; num2=third element 7 | - ; loop ten times 8 | ] 9 | <<[-]< ; clear num2 10 | # 11 | -------------------------------------------------------------------------------- /umueller/src/varia.b: -------------------------------------------------------------------------------- 1 | [ 2 | most of these require the the numbers to the right of the pointer to be 0 3 | 4 | CLR = [-] 5 | ADD = [<+>-]< 6 | DUP = [>+>+<<-]>>[<<+>>-] 7 | SWAP = [>+<-]<[>+<-]>>[<<+>>-]< 8 | MUL = >[-]>[-]<< <[>[>+>+<<-] >[<+>-] <-] >>>[<<<+>>>-]<<< 9 | IF = >[-]<[>[-]+<-]> (your program here) < 10 | 11 | ] 12 | --------------------------------------------------------------------------------