├── tests ├── automated │ ├── turt2.expected │ ├── strn-A.expected │ ├── iterate-exit.expected │ ├── iterate-jump.expected │ ├── multi-file.expected │ ├── refc-force-resize.expected │ ├── s-nowrap.expected │ ├── split-in-iterate.expected │ ├── strn-F.expected │ ├── bool-test.expected │ ├── iterate-space.expected │ ├── sigfpe.expected │ ├── strn-G.expected │ ├── sysinfo-pick.expected │ ├── iterate-iterate2.expected │ ├── iterate-fetchchar.b98 │ ├── iterate-fetchchar.expected │ ├── subr-test.expected │ ├── strn-A.b98 │ ├── iterate-zero.expected │ ├── strn-F.b98 │ ├── perl.expected │ ├── test-formfeed.expected │ ├── concurrent-issues.expected │ ├── refc-invalid-deref.expected │ ├── wrap.expected │ ├── iterate-iterate.expected │ ├── toys-errors.expected │ ├── dirf-errors.expected │ ├── sysinfo-pick.b98 │ ├── bounds.expected │ ├── frth-test.expected │ ├── iterate-iterate2.b109 │ ├── refc-force-resize.b98 │ ├── bool-test.b98 │ ├── s-nowrap.b98 │ ├── turt2.b98 │ ├── io-errors.expected │ ├── split-in-iterate.b98 │ ├── sysexec.expected │ ├── iterate-exit.b98 │ ├── turt.expected │ ├── iterate-space.b109 │ ├── test-formfeed.b98 │ ├── iterate-zero.b98 │ ├── subr-test.b98 │ ├── iterate-jump.b109 │ ├── strn-G.b98 │ ├── file-errors.expected │ ├── multi-file.b98 │ ├── bounds.b98 │ ├── iterate-iterate.b109 │ ├── perl.b98 │ ├── sigfpe.b98 │ ├── dirf-errors.b98 │ ├── toys-errors.b98 │ ├── turt2.TURT.expected │ ├── refc-invalid-deref.b98 │ ├── io-errors.b98 │ ├── turt.TURT.expected │ ├── concurrent-issues.b98 │ ├── frth-test.b98 │ ├── sysexec.b98 │ ├── wrap.b98 │ ├── CMakeLists.txt │ ├── file-errors.b98 │ └── turt.b98 ├── manual │ ├── text-output.b98 │ ├── jumpwrap.b98 │ ├── sysinfo-multi-stack-sizes.b98 │ └── fixp-nan.b98 ├── mycology │ ├── mycology_runner.sh │ ├── mycouser.expected │ ├── cfunge_TURT.svg │ ├── mycology.TURT.expected │ ├── mycology_output_filter.sh │ └── CMakeLists.txt └── CMakeLists.txt ├── examples ├── hello.bf ├── hello-concurrent2.b98 ├── fib.bf ├── hello-concurrent1.b98 ├── count.b98 ├── roman.b98 ├── prng.b98 ├── prime.bf ├── pi2.bf ├── robot.b93 ├── README ├── dladv.bf ├── life.bf └── wumpus.bf ├── src ├── instructions │ ├── README │ ├── sysinfo-misc │ │ ├── gen_safeenv_hash.sh │ │ └── safe_env.gperf │ ├── execute.h │ ├── sysinfo.h │ ├── safe_env.h │ ├── io.h │ ├── iterate.h │ └── execute.c ├── fingerprints │ ├── REFC.spec │ ├── DIRF.spec │ ├── JSTR.spec │ ├── SCKE.spec │ ├── FING.spec │ ├── MODU.spec │ ├── BOOL.spec │ ├── HRTI.spec │ ├── REXP.spec │ ├── ROMA.spec │ ├── SUBR.spec │ ├── PERL.spec │ ├── CPLI.spec │ ├── INDV.spec │ ├── FRTH.spec │ ├── BASE.spec │ ├── TIME.spec │ ├── TERM.spec │ ├── FIXP.spec │ ├── ORTH.spec │ ├── SOCK.spec │ ├── FILE.spec │ ├── DATE.spec │ ├── FPSP.spec │ ├── FPDP.spec │ ├── STRN.spec │ ├── NCRS.spec │ ├── NULL.spec │ ├── 3DSP.spec │ ├── TURT.spec │ ├── 3DSP │ │ └── 3DSP.h │ ├── BOOL │ │ ├── BOOL.h │ │ └── BOOL.c │ ├── CPLI │ │ └── CPLI.h │ ├── DATE │ │ └── DATE.h │ ├── DIRF │ │ ├── DIRF.h │ │ └── DIRF.c │ ├── FILE │ │ └── FILE.h │ ├── FING │ │ └── FING.h │ ├── FRTH │ │ └── FRTH.h │ ├── HRTI │ │ └── HRTI.h │ ├── INDV │ │ ├── INDV.h │ │ └── INDV.c │ ├── JSTR │ │ ├── JSTR.h │ │ └── JSTR.c │ ├── MODU │ │ ├── MODU.h │ │ └── MODU.c │ ├── NULL │ │ ├── NULL.h │ │ └── NULL.c │ ├── ORTH │ │ └── ORTH.h │ ├── PERL │ │ └── PERL.h │ ├── REFC │ │ ├── REFC.h │ │ └── REFC.c │ ├── REXP │ │ └── REXP.h │ ├── ROMA │ │ ├── ROMA.h │ │ └── ROMA.c │ ├── SCKE │ │ └── SCKE.h │ ├── STRN │ │ └── STRN.h │ ├── SUBR │ │ └── SUBR.h │ ├── TIME │ │ └── TIME.h │ ├── TOYS │ │ └── TOYS.h │ ├── BASE │ │ └── BASE.h │ ├── FIXP │ │ └── FIXP.h │ ├── FPDP │ │ └── FPDP.h │ ├── FPSP │ │ └── FPSP.h │ ├── TURT │ │ └── TURT.h │ ├── NCRS │ │ └── NCRS.h │ ├── SOCK │ │ └── SOCK.h │ ├── TERM │ │ └── TERM.h │ └── TOYS.spec ├── settings.c ├── rect.h ├── vector.c ├── prng.h ├── main.h ├── vector.h ├── division.h ├── diagnostic.c ├── settings.h ├── input.h └── interpreter.h ├── .gitmodules ├── .codecov.yml ├── .gitignore ├── etc ├── README ├── example.gdbinit └── _cfunge ├── lib ├── libghthash │ ├── README │ └── hash_table.c └── fungestring │ ├── funge_strlen.c │ ├── funge_strchr.c │ ├── funge_memchr.c │ └── funge_string.h ├── tools └── astyle.sh ├── TODO ├── cmake └── modules │ ├── MacroAddLinkFlags.cmake │ ├── CfungeRequireInclude.cmake │ ├── CfungeRequireFunction.cmake │ ├── CfungeCheckCflag.cmake │ ├── CfungeCheckFunction.cmake │ ├── CfungeRequireMultipleIncludes.cmake │ ├── CfungeSetBuildInfoFlags.cmake │ ├── CfungeCheckLinkerFlag.cmake │ └── CfungeCheckLibraryFunction.cmake ├── doc ├── Defines ├── cfunge-man.in ├── API_CHANGES ├── cfunge-man-fingerprints.in └── fingerprintspecformat.txt ├── pkgs └── arch │ └── PKGBUILD ├── .github └── workflows │ └── ci.yml └── CREDITS /tests/automated/turt2.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/automated/strn-A.expected: -------------------------------------------------------------------------------- 1 | fedcba -------------------------------------------------------------------------------- /tests/automated/iterate-exit.expected: -------------------------------------------------------------------------------- 1 | C 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-jump.expected: -------------------------------------------------------------------------------- 1 | C 2 | -------------------------------------------------------------------------------- /tests/automated/multi-file.expected: -------------------------------------------------------------------------------- 1 | OK 2 | -------------------------------------------------------------------------------- /tests/automated/refc-force-resize.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/automated/s-nowrap.expected: -------------------------------------------------------------------------------- 1 | GOOD 2 | -------------------------------------------------------------------------------- /tests/automated/split-in-iterate.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/automated/strn-F.expected: -------------------------------------------------------------------------------- 1 | cdef 2 | -------------------------------------------------------------------------------- /examples/hello.bf: -------------------------------------------------------------------------------- 1 | 91+"!dlrow olleH">:#,_@ 2 | -------------------------------------------------------------------------------- /tests/automated/bool-test.expected: -------------------------------------------------------------------------------- 1 | 4 -6 7 3 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-space.expected: -------------------------------------------------------------------------------- 1 | C 2 | -------------------------------------------------------------------------------- /tests/automated/sigfpe.expected: -------------------------------------------------------------------------------- 1 | Finished 2 | -------------------------------------------------------------------------------- /tests/automated/strn-G.expected: -------------------------------------------------------------------------------- 1 | 120 0 64 0 2 | -------------------------------------------------------------------------------- /tests/automated/sysinfo-pick.expected: -------------------------------------------------------------------------------- 1 | 2 3 1 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-iterate2.expected: -------------------------------------------------------------------------------- 1 | GOOD 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-fetchchar.b98: -------------------------------------------------------------------------------- 1 | 4k'abcd .,,,,a,@ 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-fetchchar.expected: -------------------------------------------------------------------------------- 1 | 13 cba' 2 | -------------------------------------------------------------------------------- /tests/automated/subr-test.expected: -------------------------------------------------------------------------------- 1 | C: OK 2 | R: OK 3 | -------------------------------------------------------------------------------- /tests/automated/strn-A.b98: -------------------------------------------------------------------------------- 1 | "NRTS"4( 0"abc"0"def"A >:#,_@ 2 | -------------------------------------------------------------------------------- /tests/automated/iterate-zero.expected: -------------------------------------------------------------------------------- 1 | GOOD: 0kvv 2 | GOOD: 0k vv 3 | -------------------------------------------------------------------------------- /tests/automated/strn-F.b98: -------------------------------------------------------------------------------- 1 | "NRTS"4($$ 0"dc" 0"fedcba" F >:#,_ a, @ -------------------------------------------------------------------------------- /tests/automated/perl.expected: -------------------------------------------------------------------------------- 1 | Hello world! 2 | hi6 3 | 1 4 | 5934 5 | -------------------------------------------------------------------------------- /tests/automated/test-formfeed.expected: -------------------------------------------------------------------------------- 1 | GOOD: Raw form feed ignored. 2 | -------------------------------------------------------------------------------- /examples/hello-concurrent2.b98: -------------------------------------------------------------------------------- 1 | #vt"drwolH">:#,_@ 2 | >"lo le">:#,_a,@ 3 | -------------------------------------------------------------------------------- /examples/fib.bf: -------------------------------------------------------------------------------- 1 | >#v1&#:<-1<-1\0\_.a,@ 2 | >2-!#v_:2\^fibre^-< 3 | ^:_ >$1>\#+:#$!_1^ 4 | -------------------------------------------------------------------------------- /examples/hello-concurrent1.b98: -------------------------------------------------------------------------------- 1 | #vtf2*2+"olleH">:#,_'>11p><"dlrow">:#,_'>fb+0p@ 3 | -------------------------------------------------------------------------------- /tests/automated/concurrent-issues.expected: -------------------------------------------------------------------------------- 1 | 1: GOOD 2 | 2: GOOD 3 | 3: GOOD 4 | 4: GOOD 5 | -------------------------------------------------------------------------------- /tests/automated/refc-invalid-deref.expected: -------------------------------------------------------------------------------- 1 | 1 GOOD 2 | 2 GOOD 3 | 3 GOOD 4 | 4 GOOD 5 | 6 | -------------------------------------------------------------------------------- /examples/count.b98: -------------------------------------------------------------------------------- 1 | " :rebmun a retnE">:#,_v 2 | v_v#`g00:+1:. ^@ 4 | -------------------------------------------------------------------------------- /examples/roman.b98: -------------------------------------------------------------------------------- 1 | " raey eht ni nettirw saw elpmaxe sihT" >:#,_ "AMOR"4#@(MM+IIX\-\-+.)a,@ 2 | -------------------------------------------------------------------------------- /tests/automated/wrap.expected: -------------------------------------------------------------------------------- 1 | GOOD: > 2 | GOOD: < 3 | GOOD: v 4 | GOOD: ^ 5 | GOOD: Flying worked 6 | -------------------------------------------------------------------------------- /tests/automated/iterate-iterate.expected: -------------------------------------------------------------------------------- 1 | 5 5 5 5 5 5 5 5 2 | Correct output is: 3 | 5 5 5 5 5 5 5 5 4 | -------------------------------------------------------------------------------- /tests/automated/toys-errors.expected: -------------------------------------------------------------------------------- 1 | GOOD: A 2 | GOOD: C 3 | GOOD: K 4 | GOOD: M 5 | GOOD: S 6 | GOOD: V 7 | -------------------------------------------------------------------------------- /tests/automated/dirf-errors.expected: -------------------------------------------------------------------------------- 1 | GOOD: C 2 | GOOD: M (1) 3 | GOOD: M (2) 4 | GOOD: R (1) 5 | GOOD: R (2) 6 | -------------------------------------------------------------------------------- /tests/automated/sysinfo-pick.b98: -------------------------------------------------------------------------------- 1 | 0yf8+y2+02pn987654321 02gy. 02g1+y. 02g1-y. a, @ 2 | Should output: 2 3 1 3 | -------------------------------------------------------------------------------- /tests/automated/bounds.expected: -------------------------------------------------------------------------------- 1 | GOOD: Value at (50625,50625) read correctly. 2 | GOOD: Space at (50625,50625). 3 | -------------------------------------------------------------------------------- /src/instructions/README: -------------------------------------------------------------------------------- 1 | This directory only contains huge instructions that would be painful to put in interpreter.c 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests/mycology/src"] 2 | path = tests/mycology/src 3 | url = https://github.com/Deewiant/Mycology 4 | -------------------------------------------------------------------------------- /tests/automated/frth-test.expected: -------------------------------------------------------------------------------- 1 | Will test L with large negative argument. 2 | Reflected. 3 | Top two items on stack: 1 0 4 | -------------------------------------------------------------------------------- /tests/automated/iterate-iterate2.b109: -------------------------------------------------------------------------------- 1 | 432kkv 2 | zz 3 | z>0"DAB">:#,_a,@ 4 | >0"DOOG">:#,_a,@ 5 | " 6 | _a,@ >"DAB YREV">:#, 7 | -------------------------------------------------------------------------------- /tests/automated/refc-force-resize.b98: -------------------------------------------------------------------------------- 1 | "CFER"4(v ; Forces cfunge to realloc the REFC list three times. Should not crash. ; 2 | > fkR @ 3 | -------------------------------------------------------------------------------- /tests/automated/bool-test.b98: -------------------------------------------------------------------------------- 1 | "LOOB"4#v(v 2 | Tests 3 | v; A;> 56A. 4 | v>; N; 5N. 5 | v>; O; 56O. 6 | v>; X; 56X. 7 | > a,@ 8 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | range: 60..100 3 | round: down 4 | precision: 5 5 | 6 | ignore: 7 | # Ignore external libraries 8 | - "lib/genx" 9 | -------------------------------------------------------------------------------- /tests/automated/s-nowrap.b98: -------------------------------------------------------------------------------- 1 | 'v10p f s 2 | >ff+0gf-#v_>na"DOOG" >:#,_@ 3 | >na"DAB" ^ 4 | 5 | Check that s doesn't wrap. 6 | -------------------------------------------------------------------------------- /tests/automated/turt2.b98: -------------------------------------------------------------------------------- 1 | "TRUT"4(n0H1Pf1+:*::**1-Naa*F0PaF1PI@ 2 | 3 | This (contributed by the CCBI author) should print a horizontal line followed by 4 | a dot. 5 | -------------------------------------------------------------------------------- /tests/manual/text-output.b98: -------------------------------------------------------------------------------- 1 | v @,,,,,,,,,,"Reflected"a < 2 | > a a 0 3 1 0"txt.tset"#^o @ 3 | 4 | This is s 5 | 6 | 7 | blah blah 8 | -------------------------------------------------------------------------------- /tests/automated/io-errors.expected: -------------------------------------------------------------------------------- 1 | GOOD: i reflected on zero length filename 2 | GOOD: o reflected on zero length filename 3 | GOOD: o reflected on trying to write to /etc/befunge-test 4 | -------------------------------------------------------------------------------- /tests/automated/split-in-iterate.b98: -------------------------------------------------------------------------------- 1 | 7#vkt @ 2 | @ 3 | 4 | This program test splitting in iterate. Should not crash or make valgrind complain. 5 | The issue was found using fuzz testing. 6 | -------------------------------------------------------------------------------- /tests/automated/sysexec.expected: -------------------------------------------------------------------------------- 1 | Hi there: 2 | Second command 3 | Will run: exit 2 4 | 5 | Retval (should be 0): 0 6 | 7 | Retval (should be 2): 2 8 | GOOD: = pushed -2 on zero length string. 9 | -------------------------------------------------------------------------------- /examples/prng.b98: -------------------------------------------------------------------------------- 1 | 4v >0v >$'@*\88+*+\4*++, 2 | >#v?1>\1-:!#^_ 3 | >2^ 4 | > 3^ 5 | 6 | Generate an infinite stream 7 | of random binary data. 8 | Thanks to Deewiant for this 9 | file. 10 | -------------------------------------------------------------------------------- /tests/automated/iterate-exit.b98: -------------------------------------------------------------------------------- 1 | #vt zzzzzzzzzzz 'C,a,@ 2 | > 5k@'W,a,q 3 | 4 | This should print "C" (without quotes) followed by a newline. 5 | Tests that we don't crash or continue after iterating over @. 6 | -------------------------------------------------------------------------------- /tests/automated/turt.expected: -------------------------------------------------------------------------------- 1 | UNDEF: Pen is 0 2 | UNDEF: Position is x=0 y=0 3 | UNDEF: Heading is 0 degrees 4 | UNDEF: Bounds are (163839998 163839998 ) (-163839998 -163839998 ) 5 | DONE, now check image 6 | -------------------------------------------------------------------------------- /tests/automated/iterate-space.b109: -------------------------------------------------------------------------------- 1 | v 2 | > 'W,a,@ 3 | >221k * 4w 'C,a,@ 4 | > 'W,a,@ 5 | 6 | Note that Funge98 is undef here but Funge109 needs it to work in the 7 | way that produce C as output. 8 | -------------------------------------------------------------------------------- /tests/automated/test-formfeed.b98: -------------------------------------------------------------------------------- 1 | v 1 2 | >v 3 | >10g c w na".derongi ton deef mrof waR :DAB">:#,_@ 4 | v << >v 5 | > 10g '1 w na".derongi deef mrof waR :DOOG">:#,_@ 6 | v << 7 | > na".x detnemercni deef mrof waR :DAB">:#,_@ 8 | -------------------------------------------------------------------------------- /tests/automated/iterate-zero.b98: -------------------------------------------------------------------------------- 1 | 0kvv 2 | >>> v 3 | v < > 0a"vvk0 :DAB" >:#,_@ 4 | > 0a"vvk0 :DOOG" >:#,_v 5 | 6 | 0k vv > 7 | >>>>>> v 8 | v < > 0a"vv k0 :DAB" >:#,_@ 9 | > 0a"vv k0 :DOOG" >:#,_@ 10 | 11 | 12 | 13 | 14 | This tests 0k 15 | -------------------------------------------------------------------------------- /tests/automated/subr-test.b98: -------------------------------------------------------------------------------- 1 | "RBUS"4#v(v 2 | > n a"detroppus ton RBUS">:#,_@ 3 | > aa0C 0a"KO :R">:#,_@ 4 | 5 | @@@@@@@@@@@@@@@@ 6 | @ Should print @ 7 | @ C: OK @ 8 | @ R: OK @ 9 | @@@@@@@@@@@@@@@@ 10 | 11 | >0a"KO :C">:#,_R 12 | -------------------------------------------------------------------------------- /tests/automated/iterate-jump.b109: -------------------------------------------------------------------------------- 1 | v 2 | > 'W,a,@ 3 | >221k; ; ; * 4w 'C,a,@ 4 | > 'W,a,@ 5 | 6 | Note that Funge98 is undef here but Funge108 needs it to work in the 7 | way that produce C as output. Yes they are unmatched to also test wrapping around. 8 | -------------------------------------------------------------------------------- /src/instructions/sysinfo-misc/gen_safeenv_hash.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! hash gperf; then 4 | echo "Please install gperf to run this script." 5 | fi 6 | gperf safe_env.gperf | sed '/#line/d' > ../safe_env.c 7 | 8 | echo "Please do the post processing changes to fix inline statements." 9 | -------------------------------------------------------------------------------- /src/fingerprints/REFC.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:REFC 3 | %url:http://catseye.tc/projects/funge98/library/REFC.html 4 | %desc:Referenced Cells Extension 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | D dereference dereference cell 9 | R reference reference cell 10 | %end 11 | -------------------------------------------------------------------------------- /src/fingerprints/DIRF.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:DIRF 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Directory functions extension 5 | %safe:false 6 | %begin-instrs 7 | #I name desc 8 | C chdir change directory 9 | M mkdir make directory 10 | R rmdir remove directory 11 | %end 12 | -------------------------------------------------------------------------------- /src/fingerprints/JSTR.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:JSTR 3 | %url:http://www.imaginaryrobots.net/projects/funge/myexts.txt 4 | %desc:Read and write strings in Funge-Space 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | G push_n Read with delta 9 | P pop_n Write with delta 10 | %end 11 | -------------------------------------------------------------------------------- /src/fingerprints/SCKE.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:SCKE 3 | %url:http://glfunge98.sourceforge.net/ 4 | %desc:TCP/IP async socket and dns resolving extension 5 | %safe:false 6 | %begin-instrs 7 | #I name desc 8 | H gethostbyname Get address by hostname 9 | P peek Peek for incoming data 10 | %end 11 | -------------------------------------------------------------------------------- /src/fingerprints/FING.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:FING 3 | %url:http://rcfunge98.com/rcsfingers.html#FING 4 | %desc:Operate on single fingerprint semantics 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | X swap Swap two semantics 9 | Y drop Drop semantic 10 | Z push Push source semantic onto dst 11 | %end 12 | -------------------------------------------------------------------------------- /src/fingerprints/MODU.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:MODU 3 | %url:http://catseye.tc/projects/funge98/library/MODU.html 4 | %desc:Modulo Arithmetic 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | M signed_result Signed result 9 | R remainder C style reminder. 10 | U unsigned_result Unsigned result 11 | %end 12 | -------------------------------------------------------------------------------- /tests/manual/jumpwrap.b98: -------------------------------------------------------------------------------- 1 | 0a5+-jvvvvvvvvv 2 | 123456789 3 | @,a.<<<<<<<<< 4 | ;;;;;;;;;;;;;;; 5 | This tests 6 | negative 7 | wrapping with 8 | j. 9 | 10 | That is also 11 | the reaon for 12 | the short 13 | lines here. 14 | 15 | It is not 16 | clear to me 17 | if it should 18 | hit 1 or 9. 19 | ;;;;;;;;;;;;;;; 20 | -------------------------------------------------------------------------------- /src/fingerprints/BOOL.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:BOOL 3 | %url:http://rcfunge98.com/rcsfingers.html#BOOL 4 | %desc:Logic Functions 5 | %safe:true 6 | %begin-instrs 7 | #I Name Desc 8 | A and and 9 | N not not 10 | O or or 11 | X xor xor 12 | %end 13 | -------------------------------------------------------------------------------- /src/fingerprints/HRTI.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:HRTI 3 | %url:http://catseye.tc/projects/funge98/library/HRTI.html 4 | %desc:High-Resolution Timer Interface 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | E erase_mark Erase Mark 9 | G granularity Granularity 10 | M mark Mark 11 | S second Second 12 | T timer Timer 13 | %end 14 | -------------------------------------------------------------------------------- /src/fingerprints/REXP.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:REXP 3 | %url:http://rcfunge98.com/rcsfingers.html#REXP 4 | %desc:Regular Expression Matching 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | C compile Compile a regular expression 9 | E execute Execute regular expression on string 10 | F free Free compiled regex buffer 11 | %end 12 | -------------------------------------------------------------------------------- /tests/automated/strn-G.b98: -------------------------------------------------------------------------------- 1 | "NRTS"4($$ 'x00p 010p '@ v 2 | v < 3 | 4 | At this point, there should be the string "x" with the 5 | terminating \0 at (0,0), and a marker value 64 on stack. 6 | 7 | If I now use STRN:G to get the string, the stack should 8 | contain (from top) 120, 0, 64. 9 | 10 | > 00G .... a, @ 11 | -------------------------------------------------------------------------------- /examples/prime.bf: -------------------------------------------------------------------------------- 1 | 222p35*89+*11p>133p >33g1+33p 22g33g- v>22g33g%#v_v 2 | o >| 3 | 2 v,,,,, ,,,,,.g22"is prime."< 4 | 1 > v^ < 5 | ^_@#-g11g22p22+1g22,*25<,,,,,,,,,,,,,.g22"is not prime."< 6 | -------------------------------------------------------------------------------- /src/fingerprints/ROMA.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:ROMA 3 | %url:http://catseye.tc/projects/funge98/library/ROMA.html 4 | %desc:Roman Numerals 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | C pushC Push 100 9 | D pushD Push 500 10 | I pushI Push 1 11 | L pushL Push 50 12 | M pushM Push 1000 13 | V pushV Push 5 14 | X pushX Push 10 15 | %end 16 | -------------------------------------------------------------------------------- /src/fingerprints/SUBR.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:SUBR 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Subroutine extension 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | A absolute Change to absolute addressing 9 | C call Call 10 | J jump Jump 11 | O relative Change to relative addressing 12 | R return Return from call 13 | %end 14 | -------------------------------------------------------------------------------- /src/fingerprints/PERL.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:PERL 3 | %url:http://catseye.tc/projects/funge98/library/PERL.html 4 | %desc:Generic Interface to the Perl Language 5 | %safe:false 6 | %begin-instrs 7 | #I name desc 8 | E eval Evaluate 0gnirts 9 | I int_eval As E but cast to integer. 10 | S shelled Is Perl loaded? Or will it be shelled? 11 | %end 12 | -------------------------------------------------------------------------------- /src/fingerprints/CPLI.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:CPLI 3 | %url:http://rcfunge98.com/rcsfingers.html#CPLI 4 | %desc:Complex Integer extension 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A add add 10 | D div divide 11 | M mul multiply 12 | O out output 13 | S sub subtract 14 | V abs absolute value 15 | %end 16 | -------------------------------------------------------------------------------- /src/fingerprints/INDV.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:INDV 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Pointer functions 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | G get_num Get value using indirect vector 9 | P put_num Put value using indirect vector 10 | V get_vec Get vector using indirect vector 11 | W put_vec Write vector using indirect vector 12 | %end 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.code-workspace 2 | *.gcda 3 | *.gcno 4 | *.gcov 5 | *.log 6 | *.orig 7 | *.sublime-project 8 | *.sublime-workspace 9 | *.tmp 10 | *.user 11 | *~ 12 | .tags 13 | .tags_sorted_by_file 14 | /*.svg 15 | /.gdbinit 16 | /.idea 17 | /.vscode 18 | /CMakeCache.txt 19 | /CMakeFiles 20 | /build 21 | /dist 22 | /doxygen-docs 23 | /install_manifest.txt 24 | /other 25 | Makefile 26 | tags 27 | -------------------------------------------------------------------------------- /etc/README: -------------------------------------------------------------------------------- 1 | This directory contains some useful files for when working with cfunge: 2 | 3 | * _cfunge 4 | Argument completion definition for the zsh shell. 5 | * example.gdbinit 6 | Copy this to the top source directory and call it just .gdbinit, then it 7 | will add some new commands to allow breaking at specific position in 8 | funge-space and such. See file for details on what commands. 9 | -------------------------------------------------------------------------------- /src/fingerprints/FRTH.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:FRTH 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Some common forth commands 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | D stack_size Push depth of stack to tos 9 | L forth_roll Forth Roll command 10 | O forth_over Forth Over command 11 | P forth_pick Forth Pick command 12 | R forth_rot Forth Rot command 13 | %end 14 | -------------------------------------------------------------------------------- /src/fingerprints/BASE.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:BASE 3 | %url:http://rcfunge98.com/rcsfingers.html#BASE 4 | %desc:I/O for numbers in other bases 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | B output_binary Output in binary 10 | H output_hex Output in hex 11 | I input_base Input in base 12 | N output_base Output in base 13 | O output_octal Output in octal 14 | %end 15 | -------------------------------------------------------------------------------- /lib/libghthash/README: -------------------------------------------------------------------------------- 1 | This directory contains part of libghthash-0.6.2 from 2 | http://www.ipd.bth.se/ska/sim_home/libghthash.html 3 | Only the parts cfunge use are included. See website for more information on the 4 | library. 5 | 6 | It has been changed to: 7 | * Use C99 stuff when possible. 8 | * Not be generic, but use the exact data types we handle. 9 | * Hard code stuff in to avoid function pointers. 10 | * Possibly some other stuff. 11 | -------------------------------------------------------------------------------- /tests/automated/file-errors.expected: -------------------------------------------------------------------------------- 1 | GOOD: C (invalid handle) 2 | GOOD: G (invalid handle) 3 | GOOD: L (invalid handle) 4 | GOOD: P (invalid handle) 5 | GOOD: R (invalid handle) 6 | GOOD: S (invalid handle) 7 | GOOD: W (invalid handle) 8 | GOOD: G (write only) 9 | GOOD: R (write only) 10 | GOOD: S (1) 11 | GOOD: G (read only) 12 | GOOD: R (negative count) 13 | GOOD: P (read only) 14 | GOOD: W (read only) 15 | GOOD: D (1) 16 | GOOD: D (nosuch file) 17 | -------------------------------------------------------------------------------- /tests/automated/multi-file.b98: -------------------------------------------------------------------------------- 1 | v > 0"dedaol ton ELIF">:#,_a,@ 2 | >"ELIF"4#^( aa5 0"pmt.0tset" #vO 11x> 3 | aa5 0"pmt.1tset" #vO 11x> 4 | aa5 0"pmt.2tset" #vO 11x> 5 | aa5 0"pmt.3tset" #vO 11x> 6 | aa5 0"pmt.4tset" #vO 11x> 7 | aa5 0"pmt.5tset" #vO 11x> 8 | aa5 0"pmt.6tset" #vO 11x> 9 | aa5 0"pmt.7tset" #vO 11x> 10 | CCCCCCCC a"KO",,,@ > 11 | @,,,,"Bad"a < 12 | -------------------------------------------------------------------------------- /src/fingerprints/TIME.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:TIME 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Time and Date functions 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | D day Get day of month. 9 | F day_of_year Get day of year. 10 | G use_gmt Set to use UTC. 11 | H hour Get hour. 12 | L use_local Set to use local time. 13 | M minute Get minute. 14 | O month Get month. 15 | S second Get second. 16 | W day_of_week Get day of week. 17 | Y year Get year. 18 | %end 19 | -------------------------------------------------------------------------------- /tests/automated/bounds.b98: -------------------------------------------------------------------------------- 1 | v >v 2 | > a0f-0f-p affff***:p ffff***:g a w v 3 | v << 4 | na".yltcerroc daer )52605,52605( ta eulaV :DOOG">:#,_v > 5 | >na".tcerrocni )52605,52605( ta eulaV :DAB">:#,_@ 6 | ^ << > v 7 | ' ffff***:p ffff***:g ' wna".)52605,52605( ta ecapS :DOOG">:#,_v > 8 | ^< 9 | ^ :***ffff p00x' p:***ffff@' p:***ffffj' < 10 | -------------------------------------------------------------------------------- /tests/automated/iterate-iterate.b109: -------------------------------------------------------------------------------- 1 | 32kk5 >:#._a, v 2 | v"Correct output is:"a"5 5 5 5 5 5 5 5"< 3 | >:#,_a,@ 4 | 5 | This tests k on k... 6 | Output should be: 7 | 5 5 5 5 5 5 5 5 8 | Correct output is: 9 | 5 5 5 5 5 5 5 5 10 | 11 | Here is how the stack should look after the different steps, spaces for clarity: 12 | First iteration of inner k: 555 13 | Next itereation where inner k pops a 5: 55 14 | Now it pushed five 5s: 55 55555 15 | Finally the code resumes at the 5: 55 55555 5 16 | -------------------------------------------------------------------------------- /src/fingerprints/TERM.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.3 2 | %fprint:TERM 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:Terminal control functions 5 | %condition:defined(HAVE_NCURSES) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | C clear_screen Clear screen 10 | D go_down Move cursor down n lines 11 | G goto_xy Goto cursor position x,y (home is 0,0) 12 | H go_home Move cursor to home 13 | L clear_to_eol Clear from cursor to end of line 14 | S clear_to_eos Clear from cursor to end of screen 15 | U go_up Move cursor up n lines 16 | %end 17 | -------------------------------------------------------------------------------- /tests/automated/perl.b98: -------------------------------------------------------------------------------- 1 | > #v "LREP"4(v 2 | v < 3 | > > 0a"detcelfeR" >:#,_@ 4 | > 0 '" "ih" '" #^ E >:#,_ v 5 | v < 6 | > ^ 7 | > 0 "5+1"#^I. a, >:#,_ v 8 | > v 9 | 10 | v "$x=" "' "Hello world!\n" "' "; print $x"0< 11 | > a"detcelfeR" >:#,_@ 12 | > #^ E >:#,_ a, v 13 | v "'"x""'" x 5934"n< 14 | > #v E a2*3+y1-.a, @ 15 | > na".detcelfer E :DAB">:#,_@ 16 | 17 | This program should print: 18 | hi6 19 | Hello world! 20 | 1 21 | 5934 22 | -------------------------------------------------------------------------------- /tests/automated/sigfpe.b98: -------------------------------------------------------------------------------- 1 | v ; This file test for potential floating point exceptions. ; 2 | ; It does not show where it is, use a debugger if you run into issues ; 3 | 4 | > 00/ 00% v ; Core instructions ; 5 | v < 6 | >na"PXIF oN">:#,_v ; Just tells it couldn't test FIXP ; 7 | > #^ "PXIF"4( 0D 0U 0T 01 0J v 8 | v < < 9 | 10 | >na"ILPC oN">:#,_v ; Just tells it couldn't test CPLI ; 11 | > #^ "ILPC"4( nD v 12 | v < 13 | 14 | > na"dehsiniF">:#,_@ 15 | -------------------------------------------------------------------------------- /tests/automated/dirf-errors.b98: -------------------------------------------------------------------------------- 1 | "FRID"4(v ; Test error handling for DIRF ; 2 | > n #vC na"C :DAB" >:#,_v 3 | v > na"C :DOOG" >:#,_> 4 | 5 | > n #vM na")1( M :DAB" >:#,_v 6 | v > na")1( M :DOOG" >:#,_> 7 | 8 | > "b/a" #vM na")2( M :DAB" >:#,_v 9 | v > na")2( M :DOOG" >:#,_> 10 | 11 | > n #vR na")1( R :DAB" >:#,_v 12 | v > na")1( R :DOOG" >:#,_> 13 | 14 | > "hcuson" #vR na")2( R :DAB" >:#,_v 15 | v > na")2( R :DOOG" >:#,_> 16 | @ -------------------------------------------------------------------------------- /tests/manual/sysinfo-multi-stack-sizes.b98: -------------------------------------------------------------------------------- 1 | 120{1230{aaaaaa0y2a*1+k$....a,@ 2 | ; This should print: ; 3 | ; 3 4 5 6 ; 4 | ; or ; 5 | : 3 6 5 4 ; 6 | ; I'm not clear on what one is correct. Please tell me ; 7 | ; if you find out ; 8 | ; Based on code from Matti Niemenmaa (mycology author) ; 9 | ; Then modified to test more than two stacks ; 10 | -------------------------------------------------------------------------------- /etc/example.gdbinit: -------------------------------------------------------------------------------- 1 | define tr9 2 | set variable setting_trace_level=9 3 | end 4 | 5 | document tr9 6 | Set funge trace level to 9 7 | end 8 | 9 | 10 | define brkcell 11 | break execute_instruction if (ip->position.x == $arg0) && (ip->position.y == $arg1) 12 | end 13 | 14 | document brkcell 15 | Break when any IP reach that specific cell. 16 | brkcell x y 17 | end 18 | 19 | 20 | define brkinst 21 | break execute_instruction if (opcode == $arg0) 22 | end 23 | 24 | document brkinst 25 | Break when the given instruction is executed. 26 | brkinst 'char' 27 | end 28 | -------------------------------------------------------------------------------- /tests/mycology/mycology_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Runner for mycology 3 | # $1 Path to Python 4 | # $2 Path to python runner 5 | # $3 Path to cfunge 6 | # $4 Path to mycology directory (where this file resides) 7 | 8 | PYTHON="$1" 9 | RUNNER="$2" 10 | CFUNGE="$3" 11 | MYCOLOGY="$4" 12 | 13 | cp "$MYCOLOGY"/src/*.b98 "$MYCOLOGY"/src/*.bf "$MYCOLOGY"/*.expected . 14 | 15 | "$PYTHON" "$RUNNER" "$CFUNGE" mycology.b98 "$MYCOLOGY/mycology_output_filter.sh" --exit-code 15 || exit 1 16 | 17 | echo -e "1\nx\n7\n16\nabc\n" | "$PYTHON" "$RUNNER" "$CFUNGE" mycouser.b98 || exit 1 18 | -------------------------------------------------------------------------------- /src/fingerprints/FIXP.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:FIXP 3 | %url:http://rcfunge98.com/rcsfingers.html#FIXP 4 | %desc:Some useful math functions 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A and bitwise and 10 | B acos arccos 11 | C cos cos 12 | D rand random number 13 | I sin sin 14 | J asin arcsin 15 | N neg negate 16 | O or bitwise or 17 | P mulpi multiply by pi 18 | Q sqrt square root 19 | R pow pow 20 | S signbit signbit 21 | T tan tan 22 | U atan arctan 23 | V abs absolute value 24 | X xor bitwise xor 25 | %end 26 | -------------------------------------------------------------------------------- /src/fingerprints/ORTH.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:ORTH 3 | %url:http://catseye.tc/projects/funge98/library/ORTH.html 4 | %desc:Orthogonal Easement Library 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | A bit_and bitwise and 9 | E bit_xor bitwise xor 10 | G get Get cell (ortho style) 11 | O bit_or bitwise or 12 | P put Put cell (ortho style) 13 | S output_string Output string 14 | V change_dx Change delta x 15 | W change_dy Change delta y 16 | X change_x Change x position 17 | Y change_y Change y position 18 | Z ramp_if_zero Act like trampoline if 0 19 | %end 20 | -------------------------------------------------------------------------------- /src/fingerprints/SOCK.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:SOCK 3 | %url:http://rcfunge98.com/rcsfingers.html#SOCK 4 | %desc:TCP/IP socket extension 5 | %safe:false 6 | %begin-instrs 7 | #I name desc 8 | A accept Accept a connection 9 | B bind Bind a socket 10 | C open Open a connection 11 | I fromascii Convert an ASCII IP address to a 32 bit address 12 | K kill Kill a connection 13 | L listen Set a socket to listening mode (n=backlog size) 14 | O setopt Set socket option 15 | R receive Receive from a socket 16 | S create Create a socket 17 | W write Write to a socket 18 | %end 19 | -------------------------------------------------------------------------------- /src/fingerprints/FILE.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:FILE 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:File I/O functions 5 | %safe:false 6 | %begin-instrs 7 | #I name desc 8 | C fclose Close a file 9 | D delete Delete specified file 10 | G fgets Get string from file (like c fgets) 11 | L ftell Get current location in file 12 | O fopen Open a file (Va = i/o buffer vector) 13 | P fputs Put string to file (like c fputs) 14 | R fread Read n bytes from file to i/o buffer 15 | S fseek Seek to position in file 16 | W fwrite Write n bytes from i/o buffer to file 17 | %end 18 | -------------------------------------------------------------------------------- /tools/astyle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is used to format files in cfunge as needed. You need to install astyle to use this: 3 | # http://astyle.sourceforge.net/ 4 | # I use astyle 2.01. No idea if it will work with previous versions. 5 | 6 | args=( 7 | --indent-preprocessor 8 | --indent-namespaces 9 | --indent-labels 10 | --keep-one-line-statements 11 | --keep-one-line-blocks 12 | --indent=tab=4 13 | --max-instatement-indent=40 14 | --min-conditional-indent=1 15 | --unpad-paren 16 | --indent-switches 17 | --pad-header 18 | --pad-oper 19 | ) 20 | 21 | astyle "${args[@]}" "$@" 22 | -------------------------------------------------------------------------------- /src/fingerprints/DATE.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:DATE 3 | %url:http://rcfunge98.com/rcsfingers.html#DATE 4 | %desc:Date Functions 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I Name Desc 9 | A add_days Add days to date 10 | C jdn_to_ymd Convert Julian day to calendar date 11 | D day_diff Days between dates 12 | J ymd_to_jdn Calendar date to Julian day 13 | T year_day_to_full Year/day-of-year to full date 14 | W week_day Day of week (0=Monday) 15 | Y year_day Day of year (0=Jan 1) 16 | %end 17 | -------------------------------------------------------------------------------- /tests/automated/toys-errors.b98: -------------------------------------------------------------------------------- 1 | "SYOT"4(v ; Test error handling for TOYS ; 2 | > 02- #vA na"A :DAB" >:#,_v 3 | v > na"A :DOOG" >:#,_> 4 | 5 | > 0001-01-00 #vC na"C :DAB" >:#,_v 6 | v > na"C :DOOG" >:#,_> 7 | 8 | > 0001-01-00 #vK na"K :DAB" >:#,_v 9 | v > na"K :DOOG" >:#,_> 10 | 11 | > 0001-01-00 #vM na"M :DAB" >:#,_v 12 | v > na"M :DOOG" >:#,_> 13 | 14 | > 0001-01-00 #vS na"S :DAB" >:#,_v 15 | v > na"S :DOOG" >:#,_> 16 | 17 | > 0001-01-00 #vV na"V :DAB" >:#,_v 18 | v > na"V :DOOG" >:#,_> 19 | 20 | @ -------------------------------------------------------------------------------- /tests/mycology/mycouser.expected: -------------------------------------------------------------------------------- 1 | GOOD: 9 / 2 = 4 2 | GOOD: 9 % 2 = 1 3 | About to test division by zero... 4 | GOOD: 1 / 0 = 0 5 | GOOD: 1 % 0 = 0 6 | Please input a number: UNDEF: got 1 which is hopefully correct. 7 | Please input a character: UNDEF: got 120 'x' which is hopefully correct. 8 | All done checking the following instructions: / % & ~ 9 | 10 | Loaded BASE fingerprint: testing I instruction. 11 | Assuming Befunge-98 instructions work... 12 | Which base to read input in? Selected base 7 13 | Input a number in that base: UNDEF: got 13 which is hopefully correct. 14 | 15 | Loaded STRN: testing I. Please input: UNDEF: got "abc" 16 | -------------------------------------------------------------------------------- /tests/mycology/cfunge_TURT.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/mycology/mycology.TURT.expected: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/automated/turt2.TURT.expected: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | This file details current status of the Befunge93/98/109 interpreter cfunge. 2 | 3 | Before next release 4 | ------------------- 5 | * Test 6 | * For i: Check that binary mode works. 7 | * Free if too large gap and test the IP code after the change to avoid 8 | realloc() every time. 9 | 10 | Future 11 | ------ 12 | * Several more fingerprints 13 | * Better hash library. 14 | * Rewrite TURT to use events, to handle lines on top of dots. 15 | * Handle Funge-109 fingerprint URIs. 16 | 17 | Ideas for future 18 | ---------------- 19 | * Make trace interface better, possibly make it interface with some sort of 20 | debugger (like the one of CCBI but better). 21 | -------------------------------------------------------------------------------- /cmake/modules/MacroAddLinkFlags.cmake: -------------------------------------------------------------------------------- 1 | # - MACRO_ADD_LINK_FLAGS(<_target> "flags...") 2 | 3 | # Copyright (c) 2006, Oswald Buddenhagen, 4 | # 5 | # Redistribution and use is allowed according to the terms of the BSD license. 6 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 7 | 8 | MACRO (MACRO_ADD_LINK_FLAGS _target _flg) 9 | 10 | GET_TARGET_PROPERTY(_flags ${_target} LINK_FLAGS) 11 | if (_flags) 12 | set(_flags "${_flags} ${_flg}") 13 | else (_flags) 14 | set(_flags "${_flg}") 15 | endif (_flags) 16 | SET_TARGET_PROPERTIES(${_target} PROPERTIES LINK_FLAGS "${_flags}") 17 | 18 | ENDMACRO (MACRO_ADD_LINK_FLAGS) 19 | -------------------------------------------------------------------------------- /tests/automated/refc-invalid-deref.b98: -------------------------------------------------------------------------------- 1 | v >0a"CFER oN" >:#,_@ ; This program tests invalid D in REFC ; 2 | >#^"CFER"4(nv 3 | v < 4 | >1. #v 0D "DAB" >:#,_ @ ; Derefence 0 ; 5 | >a"DOOG">:#,_v 6 | v < 7 | 8 | 9 | >2. #v 01-D "DAB" >:#,_ @ ; Derefence negative ; 10 | >a"DOOG">:#,_v 11 | v < 12 | 13 | 14 | >3. 45+ #v D "DAB" >:#,_ @ ; Derefence postive ; 15 | >a"DOOG">:#,_v 16 | v < 17 | 18 | 19 | >4. #v nD "DAB" >:#,_ @ ; Derefence on empty stack ; 20 | >a"DOOG">:#,_v 21 | v < 22 | 23 | a ; That's all ; 24 | , 25 | @ 26 | -------------------------------------------------------------------------------- /src/fingerprints/FPSP.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:FPSP 3 | %url:http://rcfunge98.com/rcsfingers.html#FPSP 4 | %desc:Single precision floating point 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A add add 10 | B sin sin 11 | C cos cos 12 | D div divide 13 | E asin arcsin 14 | F fromint create float from integer 15 | G atan arctan 16 | H acos arcsin 17 | I toint create integer from float 18 | K ln natural logarithm 19 | L log10 10 logarithm 20 | M mul multiply 21 | N neg negate 22 | P print output number 23 | Q sqrt square root 24 | R fromascii create float from ascii 25 | S sub subtract 26 | T tan tan 27 | V abs absolute value 28 | X exp exp 29 | Y pow pow 30 | %end -------------------------------------------------------------------------------- /src/fingerprints/FPDP.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:FPDP 3 | %url:http://rcfunge98.com/rcsfingers.html#FPDP 4 | %desc:Double precision floating point 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A add add 10 | B sin sin 11 | C cos cos 12 | D div divide 13 | E asin arcsin 14 | F fromint create double from integer 15 | G atan arctan 16 | H acos arcsin 17 | I toint create integer from double 18 | K ln natural logarithm 19 | L log10 10 logarithm 20 | M mul multiply 21 | N neg negate 22 | P print output number 23 | Q sqrt square root 24 | R fromascii create double from ascii 25 | S sub substract 26 | T tan tan 27 | V abs absolute value 28 | X exp exp 29 | Y pow pow 30 | %end 31 | -------------------------------------------------------------------------------- /src/fingerprints/STRN.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:STRN 3 | %url:http://rcfunge98.com/rcsfingers.html 4 | %desc:String functions 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | A append Append bottom string to upper string 9 | C compare Compare strings 10 | D display Display a string 11 | F search Search for bottom string in upper string 12 | G get Get string from specified position 13 | I input Input a string 14 | L left Leftmost n characters of string 15 | M slice n characters starting at position s 16 | N length Get length of string 17 | P put Put string at specified position 18 | R right Rightmost n characters of string 19 | S itoa String representation of a number 20 | V atoi Retrieve value from string 21 | %end 22 | -------------------------------------------------------------------------------- /tests/automated/io-errors.b98: -------------------------------------------------------------------------------- 1 | aa*aa* 0 0 #vi na".emanelif htgnel orez no tcelfer t'ndid i :DAB">:#,_@ 2 | v >na"emanelif htgnel orez no detcelfer i :DOOG">:#,_ 3 | >aa*aa* aa*aa* 0 0 #vo na".emanelif htgnel orez no tcelfer t'ndid o :DAB">:#,_@ 4 | v >na"emanelif htgnel orez no detcelfer o :DOOG">:#,_ 5 | >aa*aa* aa*aa* 0 0"tset-egnufeb/cte/" #vo v 6 | v < 7 | v < 8 | >na"tset-egnufeb/cte/ no tcelfer t'ndid o :DAB">:#,_@ 9 | >na"tset-egnufeb/cte/ ot etirw ot gniyrt no detcelfer o :DOOG">:#,_@ 10 | 11 | This program tests: 12 | * i and o with zero length filenames 13 | * o to readonly files (assumes you can't write to /etc/befunge-test 14 | -------------------------------------------------------------------------------- /examples/pi2.bf: -------------------------------------------------------------------------------- 1 | aa* v +------------------------+ 2 | vp*9920p*9930< | Pi generator in Bef-97 | 3 | >:09a*pa*3/1+19a*p09a*g:09b*v | | 4 | v_@# g*b90 p*b910 < p< | 7/2/1997, Kevin Vigor | 5 | >19a*g:+1-29b*p19a*g::09v +------------------------+ 6 | v*a90g*b90*g*b91: _v#p*9< 7 | >g-#v_ 2a*+\$ v :$ 8 | >\1-aa*ga*+v p 9 | v1:/g*b92p*991:< * 10 | >9b*p29b*g*199*g\v9 11 | v*b92p*aa-1g*990-<9 12 | >g2-29b*p099*g1-:0^ 13 | v -9p*b92:%ag*991 < 14 | >#v_ 299*g1+299*p> ^ 15 | >09b*g:#v_$v 16 | v93p*b90-1< 17 | >9*g199*ga/+.v 18 | v:g*992 09b*g:#v_v 1 21 | vp*b90-1 < $ g 22 | >199*g9`#v_'9,v * 23 | >'0, >' ,299^ 24 | -------------------------------------------------------------------------------- /src/fingerprints/NCRS.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.3 2 | %fprint:NCRS 3 | %url:http://www.imaginaryrobots.net/projects/funge/myexts.txt 4 | %desc:ncurses extension 5 | %condition:defined(HAVE_NCURSES) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | B beep Beep 10 | C clear Clear all or part of the screen 11 | E toggle_echo Set echo mode 12 | G get Get character 13 | I init Initialise and end curses mode 14 | K toggle_keypad Set keypad mode 15 | M goto_xy Move cursor to x,y 16 | N toggle_input Toggle input mode 17 | P put Put the character at cursor 18 | R refresh Refresh window 19 | S write Write string at cursor 20 | U unget Unget character 21 | %end 22 | -------------------------------------------------------------------------------- /etc/_cfunge: -------------------------------------------------------------------------------- 1 | #compdef cfunge 2 | 3 | # ZSH argument completion 4 | 5 | declare -a args 6 | args=( 7 | '-b[Use fully buffered output (default is system default for stdout).]' 8 | '-E[Show non-fatal error messages, fatal ones are always shown.]' 9 | '-F[Disable all fingerprints.]' 10 | '-f[Show list of features and fingerprints supported in this binary.]' 11 | '(-)-h[Show this help and exit.]' 12 | '-S[Enable sandbox mode (see README for details).]' 13 | '-V[Show version and copyright info and exit.]' 14 | '(-)-v[Show version and build info and exit.]' 15 | '-W[Show warnings.]' 16 | '-s+[Use the given standard.]:standard:(93 98 109)' 17 | '-t+[Use given trace level. Default 0.]:level:(0 1 2 3 4 5 6 7 8 9)' 18 | '*:files:_files' 19 | ) 20 | _arguments $args 21 | -------------------------------------------------------------------------------- /tests/automated/turt.TURT.expected: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/manual/fixp-nan.b98: -------------------------------------------------------------------------------- 1 | "PXIF"4#v(v 2 | > na".detroppus ton PXIF">:#,_@ 3 | v >aaaaa**** 4 | v>#vB0{" :dehsup dna tcelfer t'ndid tnemugra egnar fo tuo htiw B">:#,_n}.a, 5 | v >na".detcelfer tnemugra egnar fo tuo htiw B">:#,_ 6 | >n1-#vQ0{" :dehsup dna tcelfer t'ndid tnemugra evitagen htiw Q">:#,_n}.a,nv 7 | >na".detcelfer tnemugra evitagen htiw Q">:#,_ @ 8 | 9 | What correct behaviour is here I don't know. The fingerprint is underspecified. 10 | Common behaviours (in all cases same for both of the tests) include: 11 | cfunge (32 bit cells) and RC/Funge-98 pushes -2147483648. 12 | cfunge (64 bit cells) pushes -9223372036854775808. 13 | efunge and CCBI pushes 0. 14 | PyFunge reflects. 15 | By the way: -2147483648 seems to be NaN (as represented in "long double" on 16 | x86/x86_64) cast to 32-bit signed integer. 17 | -------------------------------------------------------------------------------- /src/fingerprints/NULL.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:NULL 3 | # Note this file can NOT be used to generate the fingerprint 4 | # itself 5 | %url:http://catseye.tc/projects/funge98/library/NULL.html 6 | %desc:Null Fingerprint 7 | %safe:true 8 | %begin-instrs 9 | #I name desc 10 | A reverse reverse 11 | B reverse reverse 12 | C reverse reverse 13 | D reverse reverse 14 | E reverse reverse 15 | F reverse reverse 16 | G reverse reverse 17 | H reverse reverse 18 | I reverse reverse 19 | J reverse reverse 20 | K reverse reverse 21 | L reverse reverse 22 | M reverse reverse 23 | N reverse reverse 24 | O reverse reverse 25 | P reverse reverse 26 | Q reverse reverse 27 | R reverse reverse 28 | S reverse reverse 29 | T reverse reverse 30 | U reverse reverse 31 | V reverse reverse 32 | W reverse reverse 33 | X reverse reverse 34 | Y reverse reverse 35 | Z reverse reverse 36 | %end 37 | -------------------------------------------------------------------------------- /src/fingerprints/3DSP.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:3DSP 3 | %url:http://rcfunge98.com/rcsfingers.html#3DSP 4 | %desc:3D space manipulation extension 5 | %condition:!defined(CFUN_NO_FLOATS) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A add Add two 3D vectors 10 | B sub Subtract two 3D vectors 11 | C cross Cross product of two vectors 12 | D dot Dot product of two vector 13 | L length Length of vector 14 | M mul Multiply two 3D vectors 15 | N normalise Normalize vector (sets length to 1) 16 | P matrix_copy Copy a matrix 17 | R matrix_rotate Generate a rotation matrix 18 | S matrix_scale Generate a scale matrix 19 | T matrix_translate Generate a translation matrix 20 | U duplicate Duplicate vector on top of stack 21 | V map Map 3D point to 2D view 22 | X transform Transform a vector using transformation matrix 23 | Y matrix_mul Multiply two matrices 24 | Z scale Scale a vector 25 | %end 26 | -------------------------------------------------------------------------------- /examples/robot.b93: -------------------------------------------------------------------------------- 1 | vv_v#:"*********"*25< 01 = x coord 2 | 8,: > ^ 02 = y coord 3 | 0>^ ^"* * *"*25< 4 | 1 > ^ 5 | p ^"* *** * *"*25< 6 | 2 > ^ 7 | 0 ^"* * *"*25< 8 | 2 > ^ 9 | p ^"* * * *"*25< 10 | " > ^ 11 | O ^"* ***** *"*25< >,v 12 | " > ^ |:<"You hit a wall! Game over!"0< 13 | 0 ^"* * *"*25< >25*,@ |-*84gg20g10< 14 | 1 > ^v ,*62 pg20g10"O"< < 15 | g ^"* * *"*25< >00g"w"-| 16 | 0 > ^ >00g"e"-| >01g1-01p^ 17 | 2 ^"*********"*250< >00g"s"-| >01g1+01p ^ 18 | g > " "01g02gp "?",~~$:00p"n"-| >02g2+02p ^ 19 | >p 62*, ^ >02g2-02p ^ 20 | -------------------------------------------------------------------------------- /src/instructions/sysinfo-misc/safe_env.gperf: -------------------------------------------------------------------------------- 1 | %language=ANSI-C 2 | %define hash-function-name safe_env_hash 3 | %define lookup-function-name safe_in_word_set 4 | %compare-lengths 5 | %compare-strncmp 6 | %readonly-tables 7 | %{ 8 | #include 9 | #include 10 | #include "safe_env.h" 11 | %} 12 | %% 13 | COLORTERM 14 | COLUMNS 15 | DISPLAY 16 | EDITOR 17 | GROUP 18 | HOME 19 | HOST 20 | LANG 21 | LC_ADDRESS 22 | LC_ALL 23 | LC_COLLATE 24 | LC_CTYPE 25 | LC_IDENTIFICATION 26 | LC_MEASUREMENT 27 | LC_MESSAGES 28 | LC_MONETARY 29 | LC_NAME 30 | LC_NUMERIC 31 | LC_PAPER 32 | LC_TELEPHONE 33 | LC_TIME 34 | MACHTYPE 35 | OSTYPE 36 | PAGER 37 | PATH 38 | PS1 39 | PWD 40 | SHELL 41 | TERM 42 | TZ 43 | USER 44 | VISUAL 45 | %% 46 | 47 | FUNGE_ATTR_FAST FUNGE_ATTR_PURE 48 | bool check_env_is_safe(const char *envvar) { 49 | const char * p; 50 | 51 | p = strchr(envvar, '='); 52 | if (!p) 53 | return false; 54 | else 55 | return (safe_in_word_set(envvar, p - envvar) != NULL); 56 | } 57 | -------------------------------------------------------------------------------- /tests/automated/concurrent-issues.b98: -------------------------------------------------------------------------------- 1 | v ; This file tests concurrency, in places where there has been previous ; 2 | ; problems in cfunge. ; 3 | 4 | > #vta"DOOG :1" >:#,_ v 5 | > zzz@ 6 | v < 7 | 8 | > #vtzza"DOOG :2" >:#,_ v 9 | >#vtzz@ 10 | >@ 11 | v < 12 | 13 | > #vt >< v 14 | >#vta"DOOG :3">:#,_ a '>9cp@ 15 | > zzz@ 16 | v < 17 | z 18 | >zz#vt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzv 19 | >#vtzzz@ z 20 | >a"DOOG :4">:#,_@ z 21 | vzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz< 22 | 23 | ; Just testing threading, in certain versions this cause an assertion ; 24 | >zzzzzzzz@ 25 | > #^tz#vt v 26 | >zzzz@ 27 | v < 28 | 29 | 30 | 31 | 32 | @ 33 | -------------------------------------------------------------------------------- /tests/mycology/mycology_output_filter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Filter for mycology output. Removes random and date dependent things. 3 | 4 | exec \ 5 | sed '/That the day of the month is/s/[0-9][0-9]*/#/' | \ 6 | sed '/That the month is/s/[0-9][0-9]*/#/' | \ 7 | sed '/That the year is/s/[0-9][0-9]*/#/' | \ 8 | sed '/That the time is/s/[0-9][0-9]*/#/g' | \ 9 | sed "/That the interpreter's version is /s/[0-9][0-9]*/#/g" | \ 10 | sed '/The directions were generated in the order/s/[^]/#/g' | \ 11 | sed '/? was met/s/[0-9][0-9]*/#/' | \ 12 | sed '/UNDEF: S pushed [0-9]/s/[0-9][0-9]*/#/' | \ 13 | sed '/UNDEF: T after M pushed /s/[0-9][0-9]*/#/g' | \ 14 | sed '/UNDEF: called 3D 9 times and got /s/[0-9] /# /g' | \ 15 | sed '/UNDEF: A pushed address /s/[0-9][0-9]*/#/g' | \ 16 | sed '/UNDEF: YODHMS claim that the /s/[0-9][0-9]*/#/g' | \ 17 | sed '/UNDEF: F claims that it is the/s/[0-9][0-9]*/#/g' | \ 18 | sed '/UNDEF: W claims that it is the/s/[0-9][0-9]*/#/g' | \ 19 | sed '/UNDEF: G gives clock granularity as /s/[0-9][0-9]*/#/g' 20 | -------------------------------------------------------------------------------- /tests/automated/frth-test.b98: -------------------------------------------------------------------------------- 1 | "HTRF"4#v(v 2 | >n a".detroppus ton HTRF">:#,_@ 3 | v >na".tnemugra evitagen egral htiw L tset lliW">:#,_ 4 | v >1 0aaaaa****- #v L 0{0a".tcelfer ton diD">:#,_ 5 | v >0{0a".detcelfeR">:#,_ 6 | > 0" :kcats no smeti owt poT">:#,_0}..a,@ 7 | 8 | This program pushes a 1 before. The program may print several things. Known 9 | examples are included below (indentation added for clarity). The behaviour is 10 | undefined. 11 | 12 | cfunge: 13 | Will test L with large negative argument. 14 | Reflected. 15 | Top two items on stack: 1 0 16 | CCBI: 17 | Will test L with large negative argument. 18 | Did not reflect. 19 | Top two items on stack: 0 1 20 | RC/Funge 1: 21 | Will test L with large negative argument. 22 | Segmentation fault 23 | RC/Funge 2: 24 | Will test L with large negative argument. 25 | Did not reflect. 26 | Top two items on stack: 0 0 27 | PyFunge: 28 | Will test L with large negative argument. 29 | Did not reflect. 30 | Top two items on stack: 0 0 31 | -------------------------------------------------------------------------------- /src/fingerprints/TURT.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.4 2 | %fprint:TURT 3 | %url:http://catseye.tc/projects/funge98/library/TURT.html 4 | %desc:Simple Turtle Graphics Library 5 | %condition:!defined(CFUN_NO_FLOATS) && !defined(CFUN_NO_TURT) 6 | %safe:true 7 | %begin-instrs 8 | #I name desc 9 | A query_heading Query Position (x, y coordinates) 10 | B back Back (distance in pixles) 11 | C pen_colour Pen Colour (24-bit RGB) 12 | D show_display Show Display (0 = no, 1 = yes) 13 | E query_pen Query Pen (0 = up, 1 = down) 14 | F forward Forward (distance in pixels) 15 | H set_heading Set Heading (angle in degrees, relative to 0deg, east) 16 | I print_drawing Print current Drawing (if possible) 17 | L turn_left Turn Left (angle in degrees) 18 | N clear_paper Clear Paper with Colour (24-bit RGB) 19 | P pen_position Pen Position (0 = up, 1 = down) 20 | Q query_position Query Position (x, y coordinates) 21 | R turn_right Turn Right (angle in degrees) 22 | T teleport Teleport (x, y coords relative to origin; 00T = home) 23 | U query_bounds Query Bounds (two pairs of x, y coordinates) 24 | %end 25 | -------------------------------------------------------------------------------- /tests/automated/sysexec.b98: -------------------------------------------------------------------------------- 1 | < v ,a = v# "echo 'Hi there:'; echo 'Second command'" 0 2 | > 0a"detcelfer =" >:#,_@ 3 | > 0" :)0 eb dluohs( lavteR" >:#,_ $ . a, v 4 | 5 | v ,a = "echo 'Will run: exit 2'; exit 2" 0 < 6 | > 0" :)2 eb dluohs( lavteR" >:#,_ $ . a,v 7 | v < 8 | >n #v=v 9 | > na".gnirts htgnel orez no detcelfer = :DAB">:#,_@ 10 | >v 11 | >02-w na".gnirts htgnel orez no 2- dehsup = :DOOG">:#,_@ 12 | >> na"gnirts htgnel orez no 2- hsup t'ndid = :DAB">:#,_@ 13 | 14 | This program should ouput (on a POSIX system): 15 | Hi there (and now a ls): 16 | 17 | 18 | Retval (should be 0): 0 19 | Will run: exit 2 20 | 21 | Retval (should be 2): 2 22 | GOOD: = pushed -2 on zero length string. 23 | There should be no indention in the output. (It was done here for clarity.) 24 | The blank lines should match. 25 | 26 | The last test (value on zero length string) is implementation defined, but 27 | cfunge is supposed to push -2. Other implementations may push other values 28 | (even 0). 29 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 2 | # Copyright (C) 2017 Arvid Norlander 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at the proxy's option) any later version. Arvid Norlander is a 8 | # proxy who can decide which future versions of the GNU General Public 9 | # License can be used. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | find_package(Python3 COMPONENTS Interpreter) 20 | 21 | if (NOT ${Python3_Interpreter_FOUND}) 22 | message(WARNING "Tests disabled as Python 3 was not found") 23 | return() 24 | endif () 25 | 26 | add_subdirectory(automated) 27 | add_subdirectory(mycology) -------------------------------------------------------------------------------- /src/fingerprints/3DSP/3DSP.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_3DSP_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_3DSP_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_3DSP_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/BOOL/BOOL.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_BOOL_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_BOOL_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_BOOL_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/CPLI/CPLI.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_CPLI_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_CPLI_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_CPLI_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/DATE/DATE.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_DATE_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_DATE_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_DATE_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/DIRF/DIRF.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_DIRF_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_DIRF_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_DIRF_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/FILE/FILE.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FILE_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FILE_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_FILE_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/FING/FING.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FING_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FING_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_FING_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/FRTH/FRTH.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FRTH_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FRTH_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_FRTH_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/HRTI/HRTI.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_HRTI_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_HRTI_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_HRTI_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/INDV/INDV.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_INDV_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_INDV_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_INDV_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/JSTR/JSTR.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_JSTR_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_JSTR_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_JSTR_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/MODU/MODU.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_MODU_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_MODU_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_MODU_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/NULL/NULL.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_NULL_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_NULL_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_NULL_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/ORTH/ORTH.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_ORTH_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_ORTH_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_ORTH_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/PERL/PERL.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_PERL_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_PERL_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_PERL_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/REFC/REFC.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_REFC_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_REFC_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_REFC_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/REXP/REXP.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_REXP_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_REXP_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_REXP_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/ROMA/ROMA.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_ROMA_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_ROMA_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_ROMA_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/SCKE/SCKE.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_SCKE_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_SCKE_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_SCKE_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/STRN/STRN.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_STRN_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_STRN_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_STRN_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/SUBR/SUBR.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_SUBR_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_SUBR_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_SUBR_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/TIME/TIME.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_TIME_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_TIME_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_TIME_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/fingerprints/TOYS/TOYS.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_TOYS_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_TOYS_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_TOYS_load(instructionPointer * ip); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /doc/Defines: -------------------------------------------------------------------------------- 1 | For development purposes there are some specialised defines. These should 2 | not be used unless you are doing development on cfunge. If you don't know 3 | that you want one of these, then you don't. 4 | 5 | None of these is accessible as simple options in cmake. Some of these 6 | requires customised built systems to work (such as the klee ones). 7 | 8 | Apart from these there are several that can be enabled using the normal 9 | build system. In general those are documented in CMakeLists.txt. 10 | 11 | 12 | Testing & Debugging 13 | ------------------- 14 | CFUN_KLEE_TEST Define if you are going to test cfunge using klee. 15 | CFUN_KLEE_TEST_PROGRAM Define to test random programs using klee. 16 | CFUN_PARANOIA Enable extra asserts. Note that CFUN_KLEE_TEST 17 | implies this. 18 | FUZZ_TESTING Has to be defined to use tools/fuzz-test.sh. 19 | Note that this breaks Funge standard conformance 20 | in multiple ways. 21 | 22 | Support for IFFI 23 | ---------------- 24 | CFUN_IS_IFFI Disables most part of main.c. 25 | FUNGE_EXTERNAL_LIBRARY Enables the fungespace_load_string() prototype. 26 | FUNGE_NEW_HANDPRINT Override 109 handprint. Normally defined in global.h 27 | FUNGE_OLD_HANDPRINT Override 98 handprint. Normally defined in global.h 28 | -------------------------------------------------------------------------------- /pkgs/arch/PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Arvid Norlander 2 | pkgname=cfunge-git 3 | pkgver=1,0.r0.80188c4 4 | pkgrel=1 5 | pkgdesc="A fast Befunge interpreter in C" 6 | arch=('x86_64' 'i686' 'arm7h' 'aarch64') 7 | url="https://github.com/VorpalBlade/cfunge" 8 | license=('GPL3') 9 | depends=('libbsd') 10 | makedepends=('git' 'cmake' 'ninja') 11 | provides=("${pkgname%-git}") 12 | conflicts=("${pkgname%-git}") 13 | source=('cfunge::git+https://github.com/VorpalBlade/cfunge' 14 | 'mycology::git+https://github.com/Deewiant/Mycology') 15 | md5sums=('SKIP' 16 | 'SKIP') 17 | 18 | pkgver() { 19 | cd "$srcdir/${pkgname%-git}" 20 | printf "%s" "$(git describe --long --tags | sed 's/\([^-]*-\)g/r\1/;s/-/./g')" 21 | } 22 | 23 | prepare() { 24 | cd "$srcdir/${pkgname%-git}" 25 | # There isn't a sane way to deal with submodules apparently in PKGBUILDs. 26 | git submodule init 27 | git config submodule.tests/mycology/src.url "$srcdir/mycology" 28 | git -c protocol.file.allow=always submodule update 29 | } 30 | 31 | build() { 32 | mkdir -p "$srcdir/build" 33 | cd "$srcdir/build" 34 | cmake -GNinja "$srcdir/${pkgname%-git}" -DCMAKE_INSTALL_PREFIX=/usr 35 | ninja 36 | } 37 | 38 | check() { 39 | cd "$srcdir/build" 40 | ninja -k0 test 41 | } 42 | 43 | package() { 44 | cd "$srcdir/build" 45 | DESTDIR="$pkgdir/" ninja install 46 | } 47 | -------------------------------------------------------------------------------- /lib/fungestring/funge_strlen.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "../../src/global.h" 23 | #include "funge_string.h" 24 | 25 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 26 | size_t funge_strlen(const funge_cell *s) 27 | { 28 | const funge_cell *p = s; 29 | while (*p != '\0') p++; 30 | return (size_t)(p - s); 31 | } 32 | -------------------------------------------------------------------------------- /src/fingerprints/BASE/BASE.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_BASE_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_BASE_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if !defined(CFUN_NO_FLOATS) 29 | 30 | bool finger_BASE_load(instructionPointer * ip); 31 | 32 | #endif /* !defined(CFUN_NO_FLOATS) */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/fingerprints/FIXP/FIXP.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FIXP_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FIXP_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if !defined(CFUN_NO_FLOATS) 29 | 30 | bool finger_FIXP_load(instructionPointer * ip); 31 | 32 | #endif /* !defined(CFUN_NO_FLOATS) */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/fingerprints/FPDP/FPDP.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FPDP_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FPDP_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if !defined(CFUN_NO_FLOATS) 29 | 30 | bool finger_FPDP_load(instructionPointer * ip); 31 | 32 | #endif /* !defined(CFUN_NO_FLOATS) */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/fingerprints/FPSP/FPSP.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FPSP_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_FPSP_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if !defined(CFUN_NO_FLOATS) 29 | 30 | bool finger_FPSP_load(instructionPointer * ip); 31 | 32 | #endif /* !defined(CFUN_NO_FLOATS) */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/fingerprints/NULL/NULL.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "NULL.h" 23 | 24 | static void finger_NULL_reverse(instructionPointer * ip) 25 | { 26 | ip_reverse(ip); 27 | } 28 | 29 | bool finger_NULL_load(instructionPointer * ip) 30 | { 31 | for (unsigned char c = 'A'; c < 'Z'; c++) 32 | if (!opcode_stack_push(ip, c, &finger_NULL_reverse)) 33 | return false; 34 | return true; 35 | } 36 | -------------------------------------------------------------------------------- /doc/cfunge-man.in: -------------------------------------------------------------------------------- 1 | [SANDBOX MODE] 2 | Sandbox mode prevents Funge programs from doing "harmful" things, this includes, 3 | but is not limited to: 4 | .TP 5 | Any file or filesystem IO is forbidden. 6 | .TP 7 | The list of environment variables the program can see in y are restricted. 8 | .TP 9 | Non-safe fingerprints can not be loaded (this includes network and file system access as well as other things). 10 | 11 | [IMPLEMENTATION DEFINED BEHAVIOUR] 12 | The Befunge98 standard leaves some things undefined, here is what cfunge do for some of those cases: 13 | .TP 14 | y pushes time in UTC not local time. 15 | .TP 16 | k with a negative argument reflects. 17 | .TP 18 | # across edge of Funge-Space may or may not skip first char after wrapping depending on exact situation. 19 | .TP 20 | ( and ) with a negative count reflects and doesn't pop any fingerprint. 21 | .TP 22 | Loaded fingerprints are inherited to child IPs at split (t). 23 | .TP 24 | Standard output is flushed at the end of the program and just before any instruction reading standard input. However it is of course possible that the operating system decides to flush anyway. 25 | .TP 26 | Standard input is read one line at a time and buffered internally. Those instructions reading chars fetch one char from this buffer, leaving the rest (if any) including any ending newline. Instructions reading an integer will leave anything after the integer in the buffer with one exception: if the next char is a newline it will be discarded. 27 | -------------------------------------------------------------------------------- /src/fingerprints/TURT/TURT.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_TURT_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_TURT_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if !defined(CFUN_NO_FLOATS) && !defined(CFUN_NO_TURT) 29 | 30 | bool finger_TURT_load(instructionPointer * ip); 31 | 32 | #endif /* !defined(CFUN_NO_FLOATS) && !defined(CFUN_NO_TURT) */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/settings.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "global.h" 23 | 24 | #include "settings.h" 25 | 26 | // This file is just for some global variables. 27 | 28 | standardVersion setting_current_standard = stdver98; 29 | 30 | uint_fast16_t setting_trace_level = 0; 31 | bool setting_enable_warnings = false; 32 | bool setting_enable_errors = false; 33 | bool setting_disable_fingerprints = false; 34 | bool setting_enable_sandbox = false; 35 | -------------------------------------------------------------------------------- /lib/fungestring/funge_strchr.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "../../src/global.h" 23 | #include "funge_string.h" 24 | 25 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 26 | funge_cell *funge_strchr(const funge_cell *s, 27 | const funge_cell c) 28 | { 29 | while (*s != '\0') { 30 | FUNGE_WARNING_IGNORE("-Wcast-qual") 31 | if (*s == c) 32 | return (funge_cell *)s; 33 | FUNGE_WARNING_RESTORE() 34 | s++; 35 | } 36 | return NULL; 37 | } 38 | -------------------------------------------------------------------------------- /src/rect.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Definition of a rectangle in Funge-Space. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_RECT_H 28 | #define FUNGE_HAD_SRC_RECT_H 29 | 30 | #include "global.h" 31 | 32 | /// A rectangle in Funge-Space. 33 | typedef struct s_fungeRect { 34 | funge_cell x; ///< Upper left corner. 35 | funge_cell y; ///< Upper left corner. 36 | funge_cell w; ///< Width. 37 | funge_cell h; ///< Height. 38 | } fungeRect; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | Note that these examples mostly come from other sources. I have not written 2 | most of them myself. 3 | 4 | Those that are known: 5 | * From http://catseye.tc/projects/befunge93/eg/INDEX.html : 6 | * dladv.bf Simple (or rather minimal!) adventure game in Befunge93. 7 | * life.bf Game of life in Befunge93. 8 | * pi2.bf Generate first 100 digits of Pi. 9 | * prime.bf Print all prime numbers up to 254. 10 | * robot.b93 A simple game in Befunge93. Note this one does NOT work in 11 | Befunge98 mode due to space in string issues. 12 | Run with -s 93 option to cfunge. 13 | * wumpus.bf Hunt the wumpus in Befunge93 14 | * My own ones (all GPL3 with proxy like the main code): 15 | * hello-concurrent1.b98 16 | Use two threads to print hello world, uses several "mutexes" to lock. 17 | For this example to work the interpreter must be compiled with concurrency. 18 | * hello-concurrent2.b98 19 | A lock free version of the above. 20 | For this example to work the interpreter must be compiled with concurrency. 21 | * roman.b98 22 | This shows an example of how to use fingerprints. Also valid in unefunge98. 23 | * count.b98 24 | This one just asks for a number to be input, then prints all numbers from 25 | 1 up to (and including) that number. The number entered should be positive. 26 | Unknown ones: 27 | * fib.bf 28 | Calculate the n-th element in the Fibonacci sequence. 29 | * hello.bf 30 | Standard Hello world, done in the most simple way possible. 31 | -------------------------------------------------------------------------------- /lib/fungestring/funge_memchr.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "../../src/global.h" 23 | #include "funge_string.h" 24 | 25 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 26 | void *funge_memchr(const void *s, funge_cell c, size_t n) 27 | { 28 | const funge_cell *p = (const funge_cell *)s; 29 | const funge_cell *end = p + n; 30 | 31 | for (; p < end; p++) { 32 | FUNGE_WARNING_IGNORE("-Wcast-qual") 33 | if (*p == c) 34 | return (void *)p; 35 | FUNGE_WARNING_RESTORE() 36 | } 37 | 38 | return NULL; 39 | } 40 | -------------------------------------------------------------------------------- /src/instructions/execute.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * execute.c contains the implementation of the = instruction. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INSTRUCTIONS_EXECUTE_H 28 | #define FUNGE_HAD_SRC_INSTRUCTIONS_EXECUTE_H 29 | 30 | #include "../global.h" 31 | #include "../stack.h" 32 | #include "../ip.h" 33 | #include "../stack.h" 34 | 35 | /// This is the = instruction. 36 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 37 | void run_system_execute(instructionPointer * restrict ip); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /examples/dladv.bf: -------------------------------------------------------------------------------- 1 | 052*"*** nooM eht morf epacsE ***">:v v < 2 | >v ^,_ v >v 3 | "" >:v1 "Big explosion. You're awake in"*25 < "" 4 | . ^,_ v er 5 | Ne >:v1 "Cage. One rod of South wall is breaking. s>" << 'e 6 | od ^,_>~"s"-v sh 7 | a ^ _ v T 8 | wc >:v1 "Zoo room. Door at East is open. en>" < :v ^,_>~:"n"-v n. 10 | yr^,_>~"n"-v | -"e"_$ ^ ee 11 | .r ^ _ > v t 12 | a >:v1 "Corridor. Way lead to North and South. nsw>" < La 13 | nB ^,_>~:"w"-v el 14 | >" >- |v-"n":_$ ^vP 15 | ">^^"s" _$ v e 16 | ^ " < rg 17 | v,_@ >" eloh roolf ni llaF">:v0 _ v .n 18 | >:^1 "Vacoom. You're dead."< ^,_~:"w"-!v - i 19 | v!-"w"~_, v ^ $_"d"^ ly 20 | v_ 1^!:< "Ready to exit. Sluice at West. w>" < el 21 | > ">ew .tseW ta etalP gniylF .ecafrus nooM">:v ^ $_"w"v>F | !-"l"< 22 | ^,_~:"e"-!^ -""v,_>~:"e"-| 23 | ^0 _^>>:^ $ 24 | ^ < 25 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 11 | BUILD_TYPE: Release 12 | 13 | jobs: 14 | build: 15 | # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. 16 | # You can convert this to a matrix build if you need cross-platform coverage. 17 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | with: 23 | submodules: 'true' 24 | 25 | - name: Configure CMake 26 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 27 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 28 | run: cmake -B ${{github.workspace}}/../build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 29 | 30 | - name: Build 31 | # Build your program with the given configuration 32 | run: cmake --build ${{github.workspace}}/../build --config ${{env.BUILD_TYPE}} 33 | 34 | - name: Test 35 | working-directory: ${{github.workspace}}/../build 36 | # Execute tests defined by the CMake configuration. 37 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 38 | run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure 39 | -------------------------------------------------------------------------------- /src/fingerprints/NCRS/NCRS.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_NCRS_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_NCRS_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if defined(HAVE_NCURSES) 29 | 30 | bool finger_NCRS_load(instructionPointer * ip); 31 | 32 | // Used by TERM to be specific to check coordinate ncurses state changes 33 | #ifdef FUNGE_EXTENDS_NCRS 34 | FUNGE_ATTR_FAST FUNGE_ATTR_PURE 35 | bool finger_NCRS_need_setupterm(void); 36 | #endif 37 | 38 | #endif /* defined(HAVE_NCURSES) */ 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | For license please see the the file COPYING. 2 | 3 | Developer 4 | --------- 5 | 6 | Arvid Norlander 7 | 8 | 9 | Thanks to 10 | --------- 11 | 12 | Alex Smith (maintainer of C-INTERCAL)... 13 | ...for finding several bugs in cfunge. 14 | ...for writing the C-INTERCAL/Befunge FFI. 15 | 16 | Matti Niemenmaa... 17 | ...for being the author of the excellent Befunge test suite Mycology. 18 | ...for writing the Befunge interpreter CCBI which was very helpful to study 19 | when writing cfunge. 20 | 21 | 22 | Third party code 23 | ---------------- 24 | 25 | Some of the code has been inspired by how the Befunge interpreter CCBI 26 | (coded in D) solves certain issues: 27 | CCBI was written by Matti Niemenmaa. 28 | See http://iki.fi/matti.niemenmaa/befunge/ccbi.html for more information. 29 | 30 | Some code have been taken from other projects (all in lib/*). 31 | They have been modified as needed to work in the cfunge project. 32 | 33 | Some whole libraries were imported: 34 | 35 | Genx, A library for writing XML files. 36 | By: Tim Bray. 37 | URL: http://www.tbray.org/ongoing/genx/ 38 | lib/genx/* 39 | 40 | libghthash, A generic hash library. 41 | By: Simon Kagstrom 42 | URL: http://www.ipd.bth.se/ska/sim_home/libghthash.html 43 | lib/libghthash/* 44 | 45 | Just a few files were taken from: 46 | 47 | CrossFire, A Multiplayer game for X-windows: 48 | By: Crossfire Development Team 49 | URL: http://crossfire.real-time.com/ 50 | lib/stringbuffer/* 51 | Some string buffer routines to make constructing strings by appending 52 | easier. 53 | -------------------------------------------------------------------------------- /src/vector.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | #include "global.h" 22 | #include "vector.h" 23 | #include 24 | 25 | // NOTE: This has been duplicated in funge-space.c for speed reasons. 26 | 27 | FUNGE_ATTR_PURE FUNGE_ATTR_FAST 28 | inline bool vector_is_cardinal(const funge_vector * restrict v) 29 | { 30 | // Due to unsigned this can't overflow in the addition below. 31 | funge_unsigned_cell x = (funge_unsigned_cell)ABS(v->x); 32 | funge_unsigned_cell y = (funge_unsigned_cell)ABS(v->y); 33 | if ((x + y) != 1) 34 | return false; 35 | if (x && y) 36 | return false; 37 | return true; 38 | } 39 | -------------------------------------------------------------------------------- /src/fingerprints/SOCK/SOCK.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_SOCK_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_SOCK_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | bool finger_SOCK_load(instructionPointer * ip); 29 | 30 | // Used by other fingerprints wanting to mess in SOCK, like SCKE 31 | #ifdef FUNGE_EXTENDS_SOCK 32 | typedef struct FungeSocketHandle { 33 | int family; 34 | int fd; 35 | } FungeSocketHandle; 36 | 37 | FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED 38 | FungeSocketHandle* finger_SOCK_LookupHandle(funge_cell h); 39 | 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /cmake/modules/CfungeRequireInclude.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a given include file exists and error out if not. 2 | # CFUNGE_REQUIRE_INCLUDE(_name) 3 | # 4 | # _name - Include file to check for. 5 | # 6 | # The same variables as for CheckIncludeFile affect this macro. 7 | # 8 | # Will set CFUNGE_CHECKINCLUDE_ (as CheckIncludeFile out variable). 9 | # 10 | 11 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 12 | # Copyright (C) 2008 Arvid Norlander 13 | # 14 | # This program is free software: you can redistribute it and/or modify 15 | # it under the terms of the GNU General Public License as published by 16 | # the Free Software Foundation, either version 3 of the License, or 17 | # (at the proxy's option) any later version. Arvid Norlander is a 18 | # proxy who can decide which future versions of the GNU General Public 19 | # License can be used. 20 | # 21 | # This program is distributed in the hope that it will be useful, 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | # GNU General Public License for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program. If not, see . 28 | 29 | include(CheckIncludeFile) 30 | 31 | macro(CFUNGE_REQUIRE_INCLUDE _name) 32 | CHECK_INCLUDE_FILE(${_name} "CFUNGE_CHECKINCLUDE_${_name}") 33 | if (NOT CFUNGE_CHECKINCLUDE_${_name}) 34 | message(FATAL_ERROR 35 | "Your system seems to be missing the header \"${_name}\" which is required by cfunge.") 36 | endif () 37 | endmacro(CFUNGE_REQUIRE_INCLUDE) 38 | -------------------------------------------------------------------------------- /src/prng.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Random number functions for Cfunge. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_PRNG_H 28 | #define FUNGE_HAD_SRC_PRNG_H 29 | 30 | #include "global.h" 31 | 32 | /** 33 | * Initialize the PRNG (if it needs it) 34 | */ 35 | void prng_init(void); 36 | 37 | /** 38 | * Generate a random number in the range [0,max_value). 39 | * It has protection against modulo bias. 40 | * 41 | * @param max_value Upper bound. 42 | */ 43 | FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED 44 | funge_unsigned_cell prng_generate_unsigned(funge_unsigned_cell max_value); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /cmake/modules/CfungeRequireFunction.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a given function exists and error out if not. 2 | # CFUNGE_REQUIRE_FUNCTION(_name) 3 | # 4 | # _name - Function name to check for. 5 | # 6 | # The same variables as for CheckFunctionExists affect this macro. 7 | # 8 | # Will set CFUNGE_CHECKFUNC_ (as CheckFunctionExists out variable). 9 | # 10 | 11 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 12 | # Copyright (C) 2008 Arvid Norlander 13 | # 14 | # This program is free software: you can redistribute it and/or modify 15 | # it under the terms of the GNU General Public License as published by 16 | # the Free Software Foundation, either version 3 of the License, or 17 | # (at the proxy's option) any later version. Arvid Norlander is a 18 | # proxy who can decide which future versions of the GNU General Public 19 | # License can be used. 20 | # 21 | # This program is distributed in the hope that it will be useful, 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | # GNU General Public License for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program. If not, see . 28 | 29 | 30 | include(CheckFunctionExists) 31 | 32 | macro(CFUNGE_REQUIRE_FUNCTION _name) 33 | CHECK_FUNCTION_EXISTS(${_name} CFUNGE_CHECKFUNC_${_name}) 34 | if (NOT CFUNGE_CHECKFUNC_${_name}) 35 | message(FATAL_ERROR 36 | "Your system seems to be missing the function \"${_name}\" which is required by cfunge.") 37 | endif () 38 | endmacro(CFUNGE_REQUIRE_FUNCTION) 39 | -------------------------------------------------------------------------------- /src/instructions/sysinfo.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * sysinfo.c contains the implementation of the y instruction. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INSTRUCTIONS_SYSINFO_H 28 | #define FUNGE_HAD_SRC_INSTRUCTIONS_SYSINFO_H 29 | 30 | #include "../global.h" 31 | #include "../stack.h" 32 | #include "../ip.h" 33 | #include "../stack.h" 34 | #include "../funge-space/funge-space.h" 35 | 36 | /// Implements the y instruction. 37 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 38 | void run_sys_info(instructionPointer * ip); 39 | 40 | #ifndef NDEBUG 41 | FUNGE_ATTR_FAST 42 | void sysinfo_cleanup(void); 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/fingerprints/TERM/TERM.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #ifndef FUNGE_HAD_SRC_FINGERPRINTS_TERM_H 23 | #define FUNGE_HAD_SRC_FINGERPRINTS_TERM_H 24 | 25 | #include "../../global.h" 26 | #include "../manager.h" 27 | 28 | #if defined(HAVE_NCURSES) 29 | 30 | bool finger_TERM_load(instructionPointer * ip); 31 | 32 | // Used by NCRS to be specific to check coordinate ncurses state changes 33 | #ifdef FUNGE_EXTENDS_TERM 34 | 35 | FUNGE_ATTR_FAST 36 | void finger_TERM_fix_before_NCRS_init(void); 37 | 38 | FUNGE_ATTR_FAST 39 | void finger_TERM_fix_after_NCRS_teardown(void); 40 | 41 | #endif 42 | 43 | #endif /* defined(HAVE_NCURSES) */ 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/instructions/safe_env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 3 | * Copyright (C) 2008-2013 Arvid Norlander 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at the proxy's option) any later version. Arvid Norlander is a 9 | * proxy who can decide which future versions of the GNU General Public 10 | * License can be used. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /** 22 | * @file 23 | * safe_env.c is a perfect hash generated with gperf used to check 24 | * if a certain environment variable should be visible in sandbox mode. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INSTRUCTIONS_SAFE_ENV_H 28 | #define FUNGE_HAD_SRC_INSTRUCTIONS_SAFE_ENV_H 29 | 30 | #include "../global.h" 31 | #include 32 | 33 | /** 34 | * Check if an environment variable is safe for sandbox. 35 | * @param envvar The string to check, this must be a full line like: 36 | * foo=bar. 37 | * @return True if safe, otherwise false. 38 | */ 39 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED 40 | bool check_env_is_safe(const char *envvar); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /cmake/modules/CfungeCheckCflag.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the C compiler supports a specific flag and if yes add it. 2 | # CFUNGE_CHECK_CFLAG(_name _flag) 3 | # 4 | # _name - Name to use for cache variable. 5 | # _flag - Flag to check for 6 | # 7 | # The same variables as for CheckCCompilerFlag affect this macro. 8 | # 9 | # Will set CFUNGE_CHECKFLAG_ (as CheckCCompilerFlag out variable). 10 | # Will use add_definitions() to add the if supported. 11 | # 12 | 13 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 14 | # Copyright (C) 2008 Arvid Norlander 15 | # 16 | # This program is free software: you can redistribute it and/or modify 17 | # it under the terms of the GNU General Public License as published by 18 | # the Free Software Foundation, either version 3 of the License, or 19 | # (at the proxy's option) any later version. Arvid Norlander is a 20 | # proxy who can decide which future versions of the GNU General Public 21 | # License can be used. 22 | # 23 | # This program is distributed in the hope that it will be useful, 24 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | # GNU General Public License for more details. 27 | # 28 | # You should have received a copy of the GNU General Public License 29 | # along with this program. If not, see . 30 | 31 | include(CheckCCompilerFlag) 32 | 33 | macro(CFUNGE_CHECK_CFLAG _name _flag) 34 | CHECK_C_COMPILER_FLAG(${_flag} CFUNGE_CHECKFLAG_${_name}) 35 | if (CFUNGE_CHECKFLAG_${_name}) 36 | add_definitions(${_flag}) 37 | endif (CFUNGE_CHECKFLAG_${_name}) 38 | endmacro(CFUNGE_CHECK_CFLAG) 39 | -------------------------------------------------------------------------------- /tests/mycology/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 2 | # Copyright (C) 2017 Arvid Norlander 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at the proxy's option) any later version. Arvid Norlander is a 8 | # proxy who can decide which future versions of the GNU General Public 9 | # License can be used. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | # If the mycology sub module is checked out, run it. 20 | if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/mycology.b98") 21 | message(WARNING "Mycology sub module missing, can not run mycology test.") 22 | return() 23 | endif() 24 | 25 | find_program(BASH_PATH bash) 26 | mark_as_advanced(BASH_PATH) 27 | if (${BASH_PATH} STREQUAL "BASH_PATH-NOTFOUND") 28 | message(WARNING "Needs bash to run wrapper script for mycology.") 29 | return() 30 | endif() 31 | 32 | add_test( 33 | NAME mycology 34 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 35 | COMMAND ${BASH_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/mycology_runner.sh 36 | ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../test_runner.py 37 | $ 38 | ${CMAKE_CURRENT_SOURCE_DIR}) -------------------------------------------------------------------------------- /src/fingerprints/TOYS.spec: -------------------------------------------------------------------------------- 1 | %fingerprint-spec 1.2 2 | %fprint:TOYS 3 | %url:http://catseye.tc/projects/funge98/library/TOYS.html 4 | %desc:Funge-98 Standard Toys 5 | %safe:true 6 | %begin-instrs 7 | #I name desc 8 | A gable gable (Duplicate stack top n times) 9 | B pair_of_shoes pair of shoes (Butterfly operation) 10 | C bracelet bracelet (Low order copy) 11 | D toilet_seat toilet seat (Decrement top of stack) 12 | E pitchfork_head pitchfork head (Replace stack with sum of all items on stack) 13 | F calipers calipers (Write matrix to funge space from stack) 14 | G counterclockwise counterclockwise (Read matrix from funge space onto stack) 15 | H pair_of_stilts pair of stilts (Bitshift) 16 | I doric_column doric column (Increment top of stack) 17 | J fishhook fishhook (Translate current funge space column) 18 | K scissors scissors (High order copy) 19 | L corner corner (Like ' but picks up cell to left and doesn't skip) 20 | M kittycat kittycat (Low order move) 21 | N lightning_bolt lightning bolt (Negate top of stack) 22 | O boulder boulder (Translate current funge space row) 23 | P mailbox mailbox (Replace stack with product of all items on stack) 24 | Q necklace necklace (Write behind IP) 25 | R can_opener can opener (Like L but to the right) 26 | S chicane chicane (memset on funge space) 27 | T barstool barstool (Act like _ or | depending on popped number) 28 | U tumbler tumbler (Like ? but replaces instruction with said random choice) 29 | V dixiecup dixiecup (High order move) 30 | W television_antenna television antenna (Atomic g/wait and try again/reverse) 31 | X buried_treasure buried treasure (Increment IP's x coord) 32 | Y slingshot slingshot (Increment IP's y coord) 33 | Z barn_door barn door (Increment IP's z coord) 34 | %end 35 | -------------------------------------------------------------------------------- /src/instructions/io.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * execute.c contains the implementation of the instructions i and o. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INSTRUCTIONS_IO_H 28 | #define FUNGE_HAD_SRC_INSTRUCTIONS_IO_H 29 | 30 | #include "../global.h" 31 | #include "../stack.h" 32 | #include "../ip.h" 33 | #include "../stack.h" 34 | #include "../funge-space/funge-space.h" 35 | 36 | /// The i instruction. 37 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 38 | void run_file_input(instructionPointer * restrict ip); 39 | /// The o instruction. 40 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 41 | void run_file_output(instructionPointer * restrict ip); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /cmake/modules/CfungeCheckFunction.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a given function exists; add define and set variable if found. 2 | # CFUNGE_CHECK_FUNCTION(_name) 3 | # 4 | # _name - Function name to check for. 5 | # 6 | # The same variables as for CheckFunctionExists affect this macro. 7 | # 8 | # Will set CFUNGE_CHECKFUNC_ (as CheckFunctionExists out variable). 9 | # Will #define HAVE_ if found. 10 | # Will set the variable CFUNGE_HAVE_ if found. 11 | # 12 | 13 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 14 | # Copyright (C) 2008 Arvid Norlander 15 | # 16 | # This program is free software: you can redistribute it and/or modify 17 | # it under the terms of the GNU General Public License as published by 18 | # the Free Software Foundation, either version 3 of the License, or 19 | # (at the proxy's option) any later version. Arvid Norlander is a 20 | # proxy who can decide which future versions of the GNU General Public 21 | # License can be used. 22 | # 23 | # This program is distributed in the hope that it will be useful, 24 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | # GNU General Public License for more details. 27 | # 28 | # You should have received a copy of the GNU General Public License 29 | # along with this program. If not, see . 30 | 31 | 32 | include(CheckFunctionExists) 33 | 34 | macro(CFUNGE_CHECK_FUNCTION _name) 35 | CHECK_FUNCTION_EXISTS(${_name} CFUNGE_CHECKFUNC_${_name}) 36 | if (CFUNGE_CHECKFUNC_${_name}) 37 | set(CFUNGE_HAVE_${_name} true) 38 | add_definitions(-DHAVE_${_name}) 39 | endif (CFUNGE_CHECKFUNC_${_name}) 40 | endmacro(CFUNGE_CHECK_FUNCTION) 41 | -------------------------------------------------------------------------------- /cmake/modules/CfungeRequireMultipleIncludes.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a given include file exists and error out if not. 2 | # CFUNGE_REQUIRE_INCLUDE(_files _name) 3 | # 4 | # _files - List of includes file to check for. 5 | # _name - Used for cache variable name. 6 | # 7 | # The same variables as for CheckIncludeFile affect this macro. 8 | # 9 | # Will set CFUNGE_CHECKMULTIINCLUDES_ (as CheckIncludeFiles out variable). 10 | # 11 | 12 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 13 | # Copyright (C) 2008 Arvid Norlander 14 | # 15 | # This program is free software: you can redistribute it and/or modify 16 | # it under the terms of the GNU General Public License as published by 17 | # the Free Software Foundation, either version 3 of the License, or 18 | # (at the proxy's option) any later version. Arvid Norlander is a 19 | # proxy who can decide which future versions of the GNU General Public 20 | # License can be used. 21 | # 22 | # This program is distributed in the hope that it will be useful, 23 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | # GNU General Public License for more details. 26 | # 27 | # You should have received a copy of the GNU General Public License 28 | # along with this program. If not, see . 29 | 30 | include(CheckIncludeFiles) 31 | 32 | macro(CFUNGE_REQUIRE_MULTIPLE_INCLUDES _files _name) 33 | CHECK_INCLUDE_FILES("${_files}" "CFUNGE_CHECKMULTIINCLUDES_${_name}") 34 | if (NOT CFUNGE_CHECKMULTIINCLUDES_${_name}) 35 | message(FATAL_ERROR 36 | "Your system seems to be missing one or several of the headers \"${_files}\" which are required by cfunge.") 37 | endif () 38 | endmacro(CFUNGE_REQUIRE_MULTIPLE_INCLUDES) 39 | -------------------------------------------------------------------------------- /src/main.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Header for main.c. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_MAIN_H 28 | #define FUNGE_HAD_SRC_MAIN_H 29 | 30 | #include "global.h" 31 | 32 | /** 33 | * @defgroup fungearg Interpreter command line arguments 34 | * 35 | * Contains information about command line parameters 36 | * @note 37 | * DO NOT MODIFY these two! 38 | * (They are declared in main.c by the way.) 39 | */ 40 | /*@{*/ 41 | /// Points to program name argument of argv, don't modify. 42 | /// 43 | /// Currently this points into the real argv of main(). Though that may change 44 | /// without prior notice. 45 | extern const char *const *fungeargv; 46 | /// Copy of argc, don't modify. 47 | extern int fungeargc; 48 | /*@}*/ 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /doc/API_CHANGES: -------------------------------------------------------------------------------- 1 | In this file is a list of API changes that caused API to increment: 2 | 3 | Version 1 4 | --------- 5 | Initial version, external API was not versioned before this. 6 | 7 | 8 | Version 2 9 | --------- 10 | Main breaking change was changing prototype of fungespace_load_string from 11 | void fungespace_load_string(const unsigned char * restrict program); 12 | to 13 | void fungespace_load_string(const unsigned char * restrict program, 14 | size_t length); 15 | 16 | The parameter "length" should be like taking a strlen() on the program parameter 17 | (if program contains no embedded null-bytes). However as long as length is 18 | correct the code can handle embedded null bytes. 19 | 20 | Version 3 21 | --------- 22 | Added CFUN_IS_IFFI to disable most of main.c. 23 | If you are not building with cmake, #define these as string constants: 24 | * CFUN_TARGET_PLATFORM 25 | Platform such as returned by uname -m (on target). 26 | * CFUN_TARGET_OS 27 | Platform as returned by uname -s (on target). 28 | * CFUN_COMPILER 29 | Compiler (full path). 30 | * CFUN_BUILD_TYPE 31 | Build type. For standard builds with cmake possible alternatives are: 32 | None, Debug, Release, RelWithDebInfo and MinSizeRel. 33 | * CFUN_COMPILED_ON 34 | A string constant like (shell syntax): 35 | "$(uname -s) $(uname -r) ($(uname -m))". 36 | This one represents the build system, not the target system (in case of cross 37 | compilation). 38 | * CFUN_USER_CFLAGS 39 | User defined CFLAGS (ones added by cfunge build system internally are not 40 | included). 41 | * CFUN_USER_LDFLAGS 42 | User defined LDFLAGS (ones added by cfunge build system internally are not 43 | included). 44 | 45 | Note that defining CFUN_IS_IFFI will currently disable the place where these are 46 | used. This may change without prior notice. 47 | -------------------------------------------------------------------------------- /src/fingerprints/ROMA/ROMA.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "ROMA.h" 23 | #include "../../stack.h" 24 | 25 | 26 | #define ROMAPUSH(x, y) \ 27 | static void finger_ROMA_push ## x (instructionPointer * ip) \ 28 | { \ 29 | stack_push(ip->stack, (funge_cell)(y)); \ 30 | } 31 | 32 | ROMAPUSH(I, 1) 33 | ROMAPUSH(V, 5) 34 | ROMAPUSH(X, 10) 35 | ROMAPUSH(L, 50) 36 | ROMAPUSH(C, 100) 37 | ROMAPUSH(D, 500) 38 | ROMAPUSH(M, 1000) 39 | 40 | 41 | 42 | bool finger_ROMA_load(instructionPointer * ip) 43 | { 44 | manager_add_opcode(ROMA, 'C', pushC); 45 | manager_add_opcode(ROMA, 'D', pushD); 46 | manager_add_opcode(ROMA, 'I', pushI); 47 | manager_add_opcode(ROMA, 'L', pushL); 48 | manager_add_opcode(ROMA, 'M', pushM); 49 | manager_add_opcode(ROMA, 'V', pushV); 50 | manager_add_opcode(ROMA, 'X', pushX); 51 | return true; 52 | } 53 | -------------------------------------------------------------------------------- /cmake/modules/CfungeSetBuildInfoFlags.cmake: -------------------------------------------------------------------------------- 1 | # - Set build info defines for use in -v output. 2 | # CFUNGE_SET_BUILD_INFO_FLAGS() 3 | # 4 | # The same variables as for CheckCCompilerFlag affect this macro. 5 | # 6 | # NOTE: Set CMAKE_BUILD_TYPE_UPPERCASE first! 7 | # 8 | # Will use add_definitions() to add the the relevant defines. 9 | # 10 | 11 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 12 | # Copyright (C) 2008 Arvid Norlander 13 | # 14 | # This program is free software: you can redistribute it and/or modify 15 | # it under the terms of the GNU General Public License as published by 16 | # the Free Software Foundation, either version 3 of the License, or 17 | # (at the proxy's option) any later version. Arvid Norlander is a 18 | # proxy who can decide which future versions of the GNU General Public 19 | # License can be used. 20 | # 21 | # This program is distributed in the hope that it will be useful, 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | # GNU General Public License for more details. 25 | # 26 | # You should have received a copy of the GNU General Public License 27 | # along with this program. If not, see . 28 | 29 | macro(CFUNGE_SET_BUILD_INFO_FLAGS) 30 | add_definitions("-DCFUN_TARGET_PLATFORM=\"${CMAKE_SYSTEM_PROCESSOR}\"") 31 | add_definitions("-DCFUN_TARGET_OS=\"${CMAKE_SYSTEM_NAME}\"") 32 | add_definitions("-DCFUN_COMPILED_ON=\"${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} (${CMAKE_SYSTEM_PROCESSOR})\"") 33 | add_definitions("-DCFUN_COMPILER=\"${CMAKE_C_COMPILER}\"") 34 | add_definitions("-DCFUN_BUILD_TYPE=\"${CMAKE_BUILD_TYPE}\"") 35 | add_definitions("-DCFUN_USER_CFLAGS=\"${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}\"") 36 | add_definitions("-DCFUN_USER_LDFLAGS=\"${CMAKE_EXE_LINKER_FLAGS}\"") 37 | endmacro(CFUNGE_SET_BUILD_INFO_FLAGS) 38 | -------------------------------------------------------------------------------- /examples/life.bf: -------------------------------------------------------------------------------- 1 | v>>31g> ::51gg:2v++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 | 9p BXY|-+98 *7^>+\-0|<+ * * + 4 | *5 ^:+ 1pg15\,:< + * *** + 5 | 10^ <>$25*,51g1v+ + 6 | -^ p<| -*46p15:+<+ + 7 | > 31^> 151p>92*4v+ + 8 | ^_ ".", ^ vp1<+ + 9 | >v >41p >0 v+ + 10 | :5! vg-1g15-1g14<+ + 11 | +1-+>+41g1-51gg+v+ + 12 | 1p-1vg+1g15-1g14<+ + 13 | g61g>+41g51g1-g+v+ + 14 | 14*1v4+g+1g15g14<+ * * + 15 | 5>^4>1g1+51g1-g+v+ * * + 16 | ^ _^v4+gg15+1g14<+ *** + 17 | >v! >1g1+51g1+g+v+ + 18 | g8-v14/*25-*4*88<+ + 19 | 19+>g51gg" "- v + + 20 | 4*5 v< v-2:_3v+ + 21 | >^ |!-3_$ v<-+ + 22 | ^ < < <|<+ ***+ 23 | >g51gp ^ >51gp^>v+ + 24 | ^14"+"< ^g14"!"<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 25 | -------------------------------------------------------------------------------- /doc/cfunge-man-fingerprints.in: -------------------------------------------------------------------------------- 1 | [FINGERPRINTS] 2 | Short descriptions of implemented fingerprints: 3 | .TP 4 | 3DSP 5 | 3D space manipulation extension 6 | .TP 7 | BASE 8 | I/O for numbers in other bases 9 | .TP 10 | BOOL 11 | Logic Functions 12 | .TP 13 | CPLI 14 | Complex Integer extension 15 | .TP 16 | DATE 17 | Date Functions 18 | .TP 19 | DIRF 20 | Directory functions extension (not available in sandbox mode) 21 | .TP 22 | FILE 23 | File I/O functions (not available in sandbox mode) 24 | .TP 25 | FING 26 | Operate on single fingerprint semantics 27 | .TP 28 | FIXP 29 | Some useful math functions 30 | .TP 31 | FPDP 32 | Double precision floating point 33 | .TP 34 | FPSP 35 | Single precision floating point 36 | .TP 37 | FRTH 38 | Some common forth commands 39 | .TP 40 | HRTI 41 | High-Resolution Timer Interface 42 | .TP 43 | INDV 44 | Pointer functions 45 | .TP 46 | JSTR 47 | Read and write strings in Funge-Space 48 | .TP 49 | MODU 50 | Modulo Arithmetic 51 | .TP 52 | NCRS 53 | ncurses extension 54 | .TP 55 | NULL 56 | Null Fingerprint 57 | .TP 58 | ORTH 59 | Orthogonal Easement Library 60 | .TP 61 | PERL 62 | Generic Interface to the Perl Language (not available in sandbox mode) 63 | .TP 64 | REFC 65 | Referenced Cells Extension 66 | .TP 67 | REXP 68 | Regular Expression Matching 69 | .TP 70 | ROMA 71 | Roman Numerals 72 | .TP 73 | SCKE 74 | TCP/IP async socket and dns resolving extension (not available in sandbox mode) 75 | .TP 76 | SOCK 77 | TCP/IP socket extension (not available in sandbox mode) 78 | .TP 79 | STRN 80 | String functions 81 | .TP 82 | SUBR 83 | Subroutine extension 84 | .TP 85 | TERM 86 | Terminal control functions 87 | .TP 88 | TIME 89 | Time and Date functions 90 | .TP 91 | TOYS 92 | Funge-98 Standard Toys 93 | .TP 94 | TURT 95 | Simple Turtle Graphics Library 96 | .LP 97 | For more details please see the specs for each fingerprint. 98 | In cases of undefined behaviour in fingerprints, cfunge mostly tries to do the 99 | same thing as CCBI. 100 | -------------------------------------------------------------------------------- /tests/automated/wrap.b98: -------------------------------------------------------------------------------- 1 | v@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 2 | @@@@@@@@@@@@@ @@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@ @@@@@@@ 3 | #@v@@@@@@@@> #@ #@ 4 | @@@@ @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@#@@@@@@@ 5 | @@@@>a"> :DOOG" >:#,_ v@v <@@@@@@@@@@@@@@@@@ @@@@@@@ 6 | @@@@@@@@@@@@@@@@@@@@@@@ @ @@@@@@@@@@@@@@@@@@@@ @@@@@@@ 7 | @# <@ @@@@@v @# 8 | @@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@ @@@@@@@@@@@@@@#@@@@@@@ 9 | @@@@v @# <@@@@@@@@@@@@@@ @@@@@@@ 10 | @@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ @@@@@@@ 11 | @@@@>a"< :DOOG" >:#,_ v@@@@@@@@@@@@@@@@@ @@@@@@@ 12 | @@@@@@@@@@@@@@@@@@@@@@@@@> a"v :DOOG" >:#,_^@@@@@@@ 13 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@ 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@>a"^ :DOOG" >:#,_ v@ 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@@@@@@@@@@@ @ 16 | @ Test wrap around behaviour in various directions @ @ 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@@@@@@@@@@@@@@@@@@@ @ 18 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@^ <@@@@@ @ 19 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@ @ 20 | @ This should print: @ @@@@@@@@@@@@@@@@@ @@@@@ @ 21 | @ GOOD: > @ @@@@@@@@@@@@@@@@@ @@@@@ @ 22 | @ GOOD: < @ @@@@@@@@@@@@@@@@@ @@@@@ @ 23 | @ GOOD: v @ @@@@@@@@@@@@@@@@@ @@@@@ @ 24 | @ GOOD: ^ @ @@@@@@@@@@@@@@@@@ @@@@@ @ 25 | @ GOOD: Flying worked @ @@@@@@@@@@@@@@@@@ @@@@@ @ 26 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@ @@@@@ @ 27 | @@@@v -30-f0 @# @# <@ 28 | @@@@ @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@#@@@@@@@ 29 | @@@@> 03a*4+-05- x@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 31 | @@@@@@@@@@@@v"GOOD: Flying worked"a<@@@@@@@@ @@@@@@@ 32 | @@@@@@@@@@@@>:#,_@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 33 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 34 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@x@ 35 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@ 36 | -------------------------------------------------------------------------------- /examples/wumpus.bf: -------------------------------------------------------------------------------- 1 | 0>:48*- #v_$>0145*p0>:045*p:48*1--#v_$7>44*>?< _$++++\1-:#^_v >>^ > 2 | ^+1p*73\0:< ^+1 _v#`2g*73:<>:2/ :v >0\2/:^ v< ^"TWANG.."< 3 | 145*g1+:145*p8 8*` #v_ $> > 44*>?< _$++++:37*g2`!#v_ > 4 | >7*p:37*g37*+p^vg*540+1g$#*73g<^$< <>0\2/:^v _v#!`g*540: < # >"rra ehT."^ 5 | ^3\+1g*73::p*73< >+2*+p# 045*^ ^ < <>:045*g64*1-g-#v_^ >:#,_$$ ^ 6 | C."*5205*p ^v1$< >025*".niaga gniyrT .sevac gnikam pu dewercS"^>"iF :)CB 8 | A,B,C."<^ 41 < _^#:p*7303p*37\5p*37\5p*37\5p*37\4p*37\4p*37\4$ :045*g^>" raeh uoY">545*g!#v_25*".tfard "v>v #"Tunnels lead to:">#<6*g- 12 | 20_v$_^#!-g+1*73g*540:g*541$_,#! #:<"You feel a" <,:>$":A",,045*g:65+2*g1v^,:*5 13 | 1>>025*"!supmuw a l" v> `#v_v v_\$37*1++v^_^#v-1*46:,,"B:",*52.+< 14 | 2v^ $_,#! #:<"You smel"<2v` 2:-"A"$< g1+.":C"25*,,,64*g1+.">" 15 | v>5*,,> ~:25*-!#v_:"a"-:^>#v_:01 vv0:<>`^>:045*p37*g: 4- #v_$025*"!tab tnaig a" 16 | <>_#"#^^# $<"0$ _v#!`-<> 1-^v$_,#! #:<"Yo" "u've been snatched by " 17 | "ni llef uoY...eeeeeeEEEEEE" "Y">:#,_$@0 >:2/: v> ^ <>5-#v_025*"!tip a ot" 18 | \37*g5-#v_ $> $$> $$>$ > >44*>?< _$++++: : 045*g\:145*g\:37*g 19 | " net"v">4-!#^_-!#^_-!#^_\0+# 45 *p#^ #1 #0\2/:^#v541g *5\0< >"!supmuw a yb" 20 | :#,_$@>"ae neeb ev'uoY...PLUG" ^ >:#,_$^> > ^>*g-#^_025*>?>v>"llik uoY"> 21 | >37*1++v^"You bumped the wumpus." ^#<^"ed the w"< 22 | v40<^"The crafty wumpus dodged your arrow" < " 23 | 5>0\25*\#v_ #^ #<"!">?".gnihtyna tih t'ndid wo"vv_$^v"s"< " 25 | >g\g14^>_v#" >:2/ :v "0< v<,: >"upm"^ 26 | -------------------------------------------------------------------------------- /cmake/modules/CfungeCheckLinkerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the Linker supports a specific flag and if yes add it. 2 | # CFUNGE_CHECK_LINKER_FLAG(_target _name _flag) 3 | # 4 | # _target - Target to add to. 5 | # _name - Name to use for cache variable. 6 | # _flag - Flag to check for 7 | # 8 | # The same variables as for CheckCSourceCompiles affect this macro. 9 | # Exception: SAFE_CMAKE_REQUIRED_FLAGS is overridden. 10 | # 11 | # Will set CFUNGE_CHECKLINKERFLAG_$ (as CheckCCompilerFlag out variable). 12 | # Will use MACRO_ADD_LINK_FLAGS() to add the if supported. 13 | # 14 | 15 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 16 | # Copyright (C) 2008 Arvid Norlander 17 | # 18 | # This program is free software: you can redistribute it and/or modify 19 | # it under the terms of the GNU General Public License as published by 20 | # the Free Software Foundation, either version 3 of the License, or 21 | # (at the proxy's option) any later version. Arvid Norlander is a 22 | # proxy who can decide which future versions of the GNU General Public 23 | # License can be used. 24 | # 25 | # This program is distributed in the hope that it will be useful, 26 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | # GNU General Public License for more details. 29 | # 30 | # You should have received a copy of the GNU General Public License 31 | # along with this program. If not, see . 32 | 33 | include(CheckCSourceCompiles) 34 | include(MacroAddLinkFlags) 35 | 36 | macro(CFUNGE_CHECK_LINKER_FLAG _target _name _flag) 37 | SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 38 | SET(CMAKE_REQUIRED_FLAGS "${_flag}") 39 | CHECK_C_SOURCE_COMPILES("int main() { return 0;}" CFUNGE_CHECKLINKERFLAG_${_name}) 40 | if (CFUNGE_CHECKLINKERFLAG_${_name}) 41 | MACRO_ADD_LINK_FLAGS(${_target} ${_flag}) 42 | endif (CFUNGE_CHECKLINKERFLAG_${_name}) 43 | SET(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") 44 | endmacro(CFUNGE_CHECK_LINKER_FLAG) 45 | -------------------------------------------------------------------------------- /lib/fungestring/funge_string.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** @file funge_string.h 23 | * 24 | * Implements funge_strstr: a strstr and strchr for Funge multibyte strings. 25 | */ 26 | 27 | /** 28 | * @defgroup fungestring String handling functions for Funge multibyte strings. 29 | * A generic stringbuffer for building strings with. 30 | */ 31 | /*@{*/ 32 | 33 | #ifndef FUNGE_STRING_H 34 | #define FUNGE_STRING_H 35 | 36 | #include "../../src/global.h" 37 | 38 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 39 | funge_cell * funge_strstr(const funge_cell *haystack, 40 | const funge_cell *needle); 41 | 42 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 43 | funge_cell * funge_strchr(const funge_cell *s, 44 | const funge_cell c); 45 | 46 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 47 | size_t funge_strlen(const funge_cell *s); 48 | 49 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_PURE 50 | void *funge_memchr(const void *s, funge_cell c, size_t n); 51 | 52 | /*@}*/ 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/vector.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | /** 22 | * @file 23 | * Definition of, and functions for, a Funge vector. 24 | */ 25 | #ifndef FUNGE_HAD_SRC_VECTOR_H 26 | #define FUNGE_HAD_SRC_VECTOR_H 27 | 28 | #include "global.h" 29 | 30 | #include 31 | 32 | /// A vector in Funge-Space 33 | typedef struct s_funge_vector { 34 | funge_cell x; ///< You should be able to guess what this is. 35 | funge_cell y; ///< You should be able to guess what this is. 36 | } funge_vector; 37 | 38 | /// Useful to create a vector in a list of parameter for example. 39 | /// The vector is created on the stack. 40 | /// @param a This should be the x value. 41 | /// @param b This should be the y value. 42 | /// @return A pointer to a vector allocated on the stack, so no need to free it. 43 | #define vector_create_ref(a, b) (& (funge_vector) { .x = (a), .y = (b) }) 44 | 45 | /** 46 | * Checks if vector is cardinal (as in ^>v<). 47 | * @param v The vector to check. 48 | */ 49 | FUNGE_ATTR_PURE FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED 50 | bool vector_is_cardinal(const funge_vector * restrict v); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/instructions/iterate.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * interate.c contains the implementation of the k instruction. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INSTRUCTIONS_ITERATE_H 28 | #define FUNGE_HAD_SRC_INSTRUCTIONS_ITERATE_H 29 | 30 | #include "../global.h" 31 | #include "../stack.h" 32 | #include "../ip.h" 33 | #include "../stack.h" 34 | #include "../funge-space/funge-space.h" 35 | 36 | /** 37 | * Implements the k instruction, prototype differ depending on if 38 | * CONCURRENT_FUNGE is defined. 39 | * @param ip Instruction pointer to operate on. 40 | * @param IPList Pointer to IP list (only if CONCURRENT_FUNGE is defined). 41 | * @param threadindex What index in IPList the IP we operate on is. 42 | * (only if CONCURRENT_FUNGE is defined). 43 | */ 44 | #ifdef CONCURRENT_FUNGE 45 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 46 | void run_iterate(instructionPointer * restrict ip, 47 | ipList ** IPList, 48 | ssize_t * restrict threadindex); 49 | #else 50 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL 51 | void run_iterate(instructionPointer * restrict ip); 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/fingerprints/BOOL/BOOL.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "BOOL.h" 23 | #include "../../stack.h" 24 | 25 | /// A - and 26 | static void finger_BOOL_and(instructionPointer * ip) 27 | { 28 | funge_cell a = stack_pop(ip->stack); 29 | funge_cell b = stack_pop(ip->stack); 30 | stack_push(ip->stack, a & b); 31 | } 32 | 33 | /// N - not 34 | static void finger_BOOL_not(instructionPointer * ip) 35 | { 36 | funge_cell a = stack_pop(ip->stack); 37 | stack_push(ip->stack, ~a); 38 | } 39 | 40 | /// O - or 41 | static void finger_BOOL_or(instructionPointer * ip) 42 | { 43 | funge_cell a = stack_pop(ip->stack); 44 | funge_cell b = stack_pop(ip->stack); 45 | stack_push(ip->stack, a | b); 46 | } 47 | 48 | /// X - xor 49 | static void finger_BOOL_xor(instructionPointer * ip) 50 | { 51 | funge_cell a = stack_pop(ip->stack); 52 | funge_cell b = stack_pop(ip->stack); 53 | stack_push(ip->stack, a ^ b); 54 | } 55 | 56 | bool finger_BOOL_load(instructionPointer * ip) 57 | { 58 | manager_add_opcode(BOOL, 'A', and); 59 | manager_add_opcode(BOOL, 'N', not); 60 | manager_add_opcode(BOOL, 'O', or); 61 | manager_add_opcode(BOOL, 'X', xor); 62 | return true; 63 | } 64 | -------------------------------------------------------------------------------- /cmake/modules/CfungeCheckLibraryFunction.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a given library exists and have a specific function. 2 | # CFUNGE_CHECK_LIBRARY_FUNCTION(_target _library _function _location) 3 | # 4 | # _target - Build target to add the library for to link. 5 | # _library - Library to check for and then check for function in. 6 | # _function - Function name to check for. 7 | # _location - Location where the library should be found. 8 | # 9 | # The same variables as for CheckLibraryExists affect this macro. 10 | # 11 | # Will set CFUNGE_CHECKLIBFUNC__ (as CheckLibraryExists out variable). 12 | # Will #define HAVE_ if found. 13 | # Will set the variable CFUNGE_HAVE__ if found. 14 | # Will add the library to target_link_libraries() if found. 15 | # 16 | 17 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 18 | # Copyright (C) 2008 Arvid Norlander 19 | # 20 | # This program is free software: you can redistribute it and/or modify 21 | # it under the terms of the GNU General Public License as published by 22 | # the Free Software Foundation, either version 3 of the License, or 23 | # (at the proxy's option) any later version. Arvid Norlander is a 24 | # proxy who can decide which future versions of the GNU General Public 25 | # License can be used. 26 | # 27 | # This program is distributed in the hope that it will be useful, 28 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | # GNU General Public License for more details. 31 | # 32 | # You should have received a copy of the GNU General Public License 33 | # along with this program. If not, see . 34 | 35 | include(CheckLibraryExists) 36 | 37 | macro(CFUNGE_CHECK_LIBRARY_FUNCTION _target _library _function _location) 38 | CHECK_LIBRARY_EXISTS(${_library} ${_function} ${_location} CFUNGE_CHECKLIBFUNC_${_library}_${_function}) 39 | if (CFUNGE_CHECKLIBFUNC_${_library}_${_function}) 40 | set(CFUNGE_HAVE_${_library}_${_function} true) 41 | add_definitions(-DHAVE_${_function}) 42 | target_link_libraries(${_target} ${_library}) 43 | endif (CFUNGE_CHECKLIBFUNC_${_library}_${_function}) 44 | endmacro(CFUNGE_CHECK_LIBRARY_FUNCTION) 45 | -------------------------------------------------------------------------------- /src/instructions/execute.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "../global.h" 23 | #include "execute.h" 24 | #include "../stack.h" 25 | #include "../ip.h" 26 | #include "../settings.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // On empty string 35 | #define FUNGE_NOCOMMAND (-2) 36 | 37 | FUNGE_ATTR_FAST void run_system_execute(instructionPointer * restrict ip) 38 | { 39 | assert(ip != NULL); 40 | 41 | if (setting_enable_sandbox) { 42 | ip_reverse(ip); 43 | return; 44 | } 45 | 46 | { 47 | char * restrict command; 48 | int retval; 49 | // Pop stuff. 50 | command = (char*)stack_pop_string(ip->stack, NULL); 51 | 52 | // Sanity test! 53 | if (!command || (*command == '\0')) { 54 | stack_free_string(command); 55 | stack_push(ip->stack, FUNGE_NOCOMMAND); 56 | return; 57 | } 58 | 59 | retval = system(command); 60 | // POSIX says we may only use WEXITSTATUS if WIFEXITED returns true... 61 | if (WIFEXITED(retval)) { 62 | stack_push(ip->stack, (funge_cell)WEXITSTATUS(retval)); 63 | } else { 64 | stack_push(ip->stack, (funge_cell)retval); 65 | } 66 | stack_free_string(command); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/division.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2015 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Definition of a rectangle in Funge-Space. 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_DIVISION_H 28 | #define FUNGE_HAD_SRC_DIVISION_H 29 | 30 | #include "global.h" 31 | 32 | /** 33 | * Performs division of funge cell values that will never cause SIGFPE 34 | * @param numerator Value to divide 35 | * @param denominator Value to divide by 36 | * @return Returns the value. 37 | */ 38 | FUNGE_ATTR_ALWAYS_INLINE FUNGE_ATTR_CONST 39 | static inline funge_cell funge_division(funge_cell numerator, funge_cell denominator) 40 | { 41 | if (denominator == 0) 42 | return 0; 43 | if (numerator == FUNGECELL_MIN && denominator == -1) 44 | return FUNGECELL_MIN; 45 | return numerator / denominator; 46 | } 47 | 48 | /** 49 | * Performs division of funge cell values that will never cause SIGFPE 50 | * @param numerator Value to divide 51 | * @param denominator Value to divide by 52 | * @return Returns the value. 53 | */ 54 | FUNGE_ATTR_ALWAYS_INLINE FUNGE_ATTR_CONST 55 | static inline funge_cell funge_modulo(funge_cell numerator, funge_cell denominator) 56 | { 57 | if (denominator == 0) 58 | return 0; 59 | if (numerator == FUNGECELL_MIN && denominator == -1) 60 | return 0; 61 | return numerator % denominator; 62 | } 63 | #endif 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /tests/automated/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 2 | # Copyright (C) 2017 Arvid Norlander 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at the proxy's option) any later version. Arvid Norlander is a 8 | # proxy who can decide which future versions of the GNU General Public 9 | # License can be used. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | function(cfunge_test test_name) 20 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_name}) 21 | add_test( 22 | NAME ${test_name} 23 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_name} 24 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../test_runner.py $ ${CMAKE_CURRENT_SOURCE_DIR}/${test_name}) 25 | endfunction() 26 | 27 | cfunge_test(bool-test.b98) 28 | cfunge_test(bounds.b98) 29 | cfunge_test(concurrent-issues.b98) 30 | cfunge_test(dirf-errors.b98) 31 | cfunge_test(file-errors.b98) 32 | cfunge_test(frth-test.b98) 33 | cfunge_test(io-errors.b98) 34 | cfunge_test(iterate-exit.b98) 35 | cfunge_test(iterate-fetchchar.b98) 36 | cfunge_test(iterate-iterate.b109) 37 | cfunge_test(iterate-iterate2.b109) 38 | cfunge_test(iterate-jump.b109) 39 | cfunge_test(iterate-space.b109) 40 | cfunge_test(iterate-zero.b98) 41 | cfunge_test(multi-file.b98) 42 | cfunge_test(perl.b98) 43 | cfunge_test(refc-force-resize.b98) 44 | cfunge_test(refc-invalid-deref.b98) 45 | cfunge_test(s-nowrap.b98) 46 | cfunge_test(sigfpe.b98) 47 | cfunge_test(split-in-iterate.b98) 48 | cfunge_test(strn-A.b98) 49 | cfunge_test(strn-F.b98) 50 | cfunge_test(strn-G.b98) 51 | cfunge_test(subr-test.b98) 52 | cfunge_test(sysexec.b98) 53 | cfunge_test(sysinfo-pick.b98) 54 | cfunge_test(test-formfeed.b98) 55 | cfunge_test(toys-errors.b98) 56 | cfunge_test(turt.b98) 57 | cfunge_test(turt2.b98) 58 | cfunge_test(wrap.b98) 59 | -------------------------------------------------------------------------------- /tests/automated/file-errors.b98: -------------------------------------------------------------------------------- 1 | "ELIF"4(v ; Test error handling for FILE ; 2 | 3 | Tests with invalid file handle 4 | 5 | > 8 #vC na")eldnah dilavni( C :DAB" >:#,_v 6 | v > na")eldnah dilavni( C :DOOG" >:#,_> 7 | 8 | > 8 #vG na")eldnah dilavni( G :DAB" >:#,_v 9 | v > na")eldnah dilavni( G :DOOG" >:#,_> 10 | 11 | > 8 #vL na")eldnah dilavni( L :DAB" >:#,_v 12 | v > na")eldnah dilavni( L :DOOG" >:#,_> 13 | 14 | > 8 #vP na")eldnah dilavni( P :DAB" >:#,_v 15 | v > na")eldnah dilavni( P :DOOG" >:#,_> 16 | 17 | > 8 #vR na")eldnah dilavni( R :DAB" >:#,_v 18 | v > na")eldnah dilavni( R :DOOG" >:#,_> 19 | 20 | > 8 #vS na")eldnah dilavni( S :DAB" >:#,_v 21 | v > na")eldnah dilavni( S :DOOG" >:#,_> 22 | 23 | > 8 #vW na")eldnah dilavni( W :DAB" >:#,_v 24 | v > na")eldnah dilavni( W :DOOG" >:#,_> 25 | 26 | Tests with open file (write only) 27 | 28 | ; Store handle at (0,0) ; 00p 30 | > na")1( deliaf O :DAB" >:#,_@ 31 | >v 32 | v> 00g 0d"a"P 33 | 34 | > 00g #vG na")ylno etirw( G :DAB" >:#,_v 35 | v > na")ylno etirw( G :DOOG" >:#,_> 36 | 37 | > 00g 1 #vR na")ylno etirw( R :DAB" >:#,_v 38 | v > na")ylno etirw( R :DOOG" >:#,_> 39 | 40 | > 00g 9 9 #vS na")1( S :DAB" >:#,_v 41 | v > na")1( S :DOOG" >:#,_> 42 | 43 | Close write only file, reopen read only 44 | 45 | ; Store handle at (0,0) ; 00p 47 | > na")2( deliaf O :DAB" >:#,_@ 48 | 49 | 50 | > 00g #vG na")ylno daer( G :DOOG" >:#,_v 51 | v > na")ylno daer( G :DAB" >:#,_> 52 | 53 | > 00g 5- #vR na")tnuoc evitagen( R :DAB" >:#,_v 54 | v > na")tnuoc evitagen( R :DOOG" >:#,_> 55 | 56 | > 00g 0"a" #vP na")ylno daer( P :DAB" >:#,_v 57 | v > na")ylno daer( P :DOOG" >:#,_> 58 | 59 | > 00g 6 #vW na")ylno daer( W :DAB" >:#,_v 60 | v > na")ylno daer( W :DOOG" >:#,_> 61 | 62 | 63 | Close read only file, delete it 64 | 65 | >ngCn"tset.elif"#vD na")1( D :DOOG" >:#,_v 66 | v > na")1( D :DAB " >:#,_> 67 | 68 | > "hcuson" #vD na")elif hcuson( D :DAB" >:#,_v 69 | v > na")elif hcuson( D :DOOG" >:#,_> 70 | 71 | >@ 72 | -------------------------------------------------------------------------------- /doc/fingerprintspecformat.txt: -------------------------------------------------------------------------------- 1 | cfunge use a special file format to generate fingerprints from. 2 | The format is quite simple. An example follows: 3 | 4 | %fingerprint-spec 1.4 5 | %fprint:TEST 6 | %url:http://example.com/desc/test.html 7 | %f109-uri:http://example.com/test 8 | %condition:defined(HAVE_foo) && !defined(__FOOBAR) 9 | %desc:This is a test of the fingerprint spec file system. 10 | %safe:true 11 | %alias:FOOO 12 | %begin-instrs 13 | # a comment 14 | #I name desc 15 | A foobar Description 16 | B quux Other Description 17 | %end 18 | 19 | The first line should always be "%fingerprint-spec 1.4" (or in future versions, 20 | possibly higher numbers). 21 | 22 | Note: 23 | * The format is case sensitive. 24 | * Any lines after the first starting with a # is considered a comment. 25 | 26 | After that fprint, url, desc, safe and alias can follow in any order. 27 | * fprint is the fingerprint name 28 | * url is the url for more info on the fingerprint (docs and such) 29 | * f109-uri is an optional Funge-109 URI for the fingerprint. 30 | * condition is an optional C preprocessor condition. If the line exists it will 31 | be used as an #if condition to enable or disable this fingerprint at compile 32 | time. It is up to you to make sure the condition is sane and valid C. 33 | * desc is a short one line description. Less than 60 chars is definitly 34 | recommended. 35 | * safe can be either true or false, true indicates it is safe in sandbox mode 36 | and false that it isn't. 37 | * alias is special because it is: 38 | * It is optional. 39 | * You can have several. 40 | alias allows a fingerprint to be known under several names. It's use is 41 | highly discouraged. If you really want to use it, you need to work out how 42 | by reading the code. 43 | 44 | After that, to indicate that the instruction list begins, use %begin-instrs 45 | The instruction list must be sorted and contain no duplicates. 46 | 47 | Each line in this section consists of: 48 | whitespace whitespace 49 | 50 | * Whitespace consists of one or more tabs and/or spaces. 51 | * The instruction must be in the range A-Z. 52 | * The name should be a valid name to use in a C function name (it is currently 53 | not sanity checked). 54 | * The description is a short string describing the fuction. 55 | 56 | Finally there should be a line %end after the instruction list. 57 | Any further lines are ignored (currently, but that may change). 58 | -------------------------------------------------------------------------------- /src/fingerprints/DIRF/DIRF.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "DIRF.h" 23 | #include "../../stack.h" 24 | 25 | #include /* chdir, rmdir */ 26 | #include /* mkdir */ 27 | #include /* mkdir (not required by POSIX?) */ 28 | 29 | static void finger_DIRF_chdir(instructionPointer * ip) 30 | { 31 | size_t len; 32 | char * restrict str = (char*)stack_pop_string(ip->stack, &len); 33 | if (!str || (len < 1)) { 34 | ip_reverse(ip); 35 | } else if (chdir(str) != 0) { 36 | ip_reverse(ip); 37 | } 38 | stack_free_string(str); 39 | } 40 | 41 | static void finger_DIRF_mkdir(instructionPointer * ip) 42 | { 43 | size_t len; 44 | char * restrict str = (char*)stack_pop_string(ip->stack, &len); 45 | if (!str || (len < 1)) { 46 | ip_reverse(ip); 47 | } else if (mkdir(str, S_IRWXU) != 0) { 48 | ip_reverse(ip); 49 | } 50 | stack_free_string(str); 51 | } 52 | 53 | static void finger_DIRF_rmdir(instructionPointer * ip) 54 | { 55 | size_t len; 56 | char * restrict str = (char*)stack_pop_string(ip->stack, &len); 57 | if (!str || (len < 1)) { 58 | ip_reverse(ip); 59 | } else if (rmdir(str) != 0) { 60 | ip_reverse(ip); 61 | } 62 | stack_free_string(str); 63 | } 64 | 65 | 66 | bool finger_DIRF_load(instructionPointer * ip) 67 | { 68 | manager_add_opcode(DIRF, 'C', chdir); 69 | manager_add_opcode(DIRF, 'M', mkdir); 70 | manager_add_opcode(DIRF, 'R', rmdir); 71 | return true; 72 | } 73 | -------------------------------------------------------------------------------- /src/fingerprints/JSTR/JSTR.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "JSTR.h" 23 | #include "../../stack.h" 24 | 25 | /// G - Read with delta 26 | static void finger_JSTR_push_n(instructionPointer * ip) 27 | { 28 | funge_cell n; 29 | funge_vector pos, delta; 30 | 31 | n = stack_pop(ip->stack); 32 | pos = stack_pop_vector(ip->stack); 33 | delta = stack_pop_vector(ip->stack); 34 | pos.x += ip->storageOffset.x; 35 | pos.y += ip->storageOffset.y; 36 | 37 | if (n <= 0) { 38 | ip_reverse(ip); 39 | return; 40 | } 41 | 42 | stack_push(ip->stack, 0); 43 | 44 | while (n--) { 45 | stack_push(ip->stack, fungespace_get(&pos)); 46 | pos.x += delta.x; 47 | pos.y += delta.y; 48 | } 49 | } 50 | 51 | /// P - Write with delta 52 | static void finger_JSTR_pop_n(instructionPointer * ip) 53 | { 54 | funge_cell n; 55 | funge_vector pos, delta; 56 | 57 | n = stack_pop(ip->stack); 58 | pos = stack_pop_vector(ip->stack); 59 | delta = stack_pop_vector(ip->stack); 60 | pos.x += ip->storageOffset.x; 61 | pos.y += ip->storageOffset.y; 62 | 63 | if (n <= 0) { 64 | ip_reverse(ip); 65 | return; 66 | } 67 | 68 | while (n--) { 69 | fungespace_set(stack_pop(ip->stack), &pos); 70 | pos.x += delta.x; 71 | pos.y += delta.y; 72 | } 73 | } 74 | 75 | bool finger_JSTR_load(instructionPointer * ip) 76 | { 77 | manager_add_opcode(JSTR, 'G', push_n); 78 | manager_add_opcode(JSTR, 'P', pop_n); 79 | return true; 80 | } 81 | -------------------------------------------------------------------------------- /tests/automated/turt.b98: -------------------------------------------------------------------------------- 1 | v >0a"detroppus ton TRUT">:#,_@ 2 | >#^"TRUT"4(n 11x ; Load fingerprint ; 3 | " si neP :FEDNU">:#,_E.a, 11x> ; UNDEF: Initial pen state ; 4 | "=x si noitisoP :FEDNU">:#,_Q."=y",,.a, 11x> ; UNDEF: Initial position ; 5 | " si gnidaeH :FEDNU">:#,_A.a"seerged">:#,_ 11x> ; UNDEF: Initial heading ; 6 | "( era sdnuoB :FEDNU">:#,_U.."( )",,,..a'),, 11x> ; UNDEF: Bounds ; 7 | a7+3*5*N 0C 11x> ; Clear with blue. Set pen to black ; 8 | 0H 1P 11x> ; Set direction, pen down. ; 9 | 52*1-F 0P 2F 1P 53*1-F 11x> ; Draw first line with a gap in it. ; 10 | 2f+8*8*8*8*8*6*5*1+C 9a*H 11x> ; Set colour to red and turn to 90 deg. ; 11 | 5F 9a*L 11x> ; Draw vertical line, turn 90 deg right.; 12 | 0C 5F 11x> ; Change to black, draw line. ; 13 | 0P 5B 9a*R aB 1P 11x> ; Lift pen Go back and draw first dot. ; 14 | 0P f1+8*8*a*6*C 11x> ; Lift pen, Set green. ; 15 | 005-T 1P 11x> ; Teleport to the other dot, pen down. ; 16 | I a"egami kcehc won ,ENOD">:#,_@ > ; Print out and quit. ; 17 | 18 | What the image should look like: 19 | 20 | This program should draw a pattern like below. 21 | The * is a dot. 22 | The horizontal (black) line should be 25 units long. 23 | There should be a gap 2/3rd along the line of 2 units. 24 | Then a red line (5 units long) at a straight angle. 25 | The specs doesn't say if 90 degrees is upwards or downwards. So either is 26 | allowed. 27 | The red should be (#ff0001) (a slight slight blue tint). 28 | Then another (black) line of length 5 at straight angle. 29 | This should be 90 degrees *right* from the red line. 30 | The dots should be 5 units above the first line. 31 | In other words one should be at (0,-5) the other at (25,-5). 32 | Or below, depending on where 90 degrees is. 33 | The dot at (25,-5) should be black. 34 | The dot at (0,-5) should be green. 35 | The background should be blue (#0000ff). 36 | 37 | 38 | * * 39 | 40 | 41 | 42 | --------- --------------. 43 | | 44 | | 45 | | 46 | | 47 | .----- 48 | -------------------------------------------------------------------------------- /src/diagnostic.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | #include "global.h" 22 | #include "diagnostic.h" 23 | 24 | #include /* abort, exit */ 25 | #include 26 | 27 | FUNGE_ATTR_FAST FUNGE_ATTR_COLD FUNGE_ATTR_NONNULL FUNGE_ATTR_NORET 28 | void diag_fatal(const char* message) 29 | { 30 | fprintf(stderr, "FATAL: %s\n", message); 31 | exit(1); 32 | } 33 | 34 | FUNGE_ATTR_FAST 35 | void diag_error(const char* message) 36 | { 37 | if (FUNGE_UNLIKELY(setting_enable_errors)) 38 | fprintf(stderr, "ERROR: %s\n", message); 39 | } 40 | 41 | FUNGE_ATTR_FAST 42 | void diag_warn(const char* message) 43 | { 44 | if (FUNGE_UNLIKELY(setting_enable_warnings)) 45 | fprintf(stderr, "WARN: %s\n", message); 46 | } 47 | 48 | FUNGE_ATTR_FAST FUNGE_ATTR_COLD FUNGE_ATTR_NONNULL FUNGE_ATTR_NORET 49 | FUNGE_ATTR_FORMAT(printf, 1, 2) 50 | void diag_fatal_format(const char* format, ...) 51 | { 52 | va_list ap; 53 | fputs("FATAL: ", stderr); 54 | va_start(ap, format); 55 | vfprintf(stderr, format, ap); 56 | va_end(ap); 57 | fputc('\n', stderr); 58 | exit(1); 59 | } 60 | 61 | FUNGE_ATTR_FAST 62 | void diag_error_format(const char* format, ...) 63 | { 64 | if (FUNGE_UNLIKELY(setting_enable_errors)) { 65 | va_list ap; 66 | fputs("ERROR: ", stderr); 67 | va_start(ap, format); 68 | vfprintf(stderr, format, ap); 69 | va_end(ap); 70 | fputc('\n', stderr); 71 | } 72 | } 73 | 74 | FUNGE_ATTR_FAST 75 | void diag_warn_format(const char* format, ...) 76 | { 77 | if (FUNGE_UNLIKELY(setting_enable_warnings)) { 78 | va_list ap; 79 | fputs("WARN: ", stderr); 80 | va_start(ap, format); 81 | vfprintf(stderr, format, ap); 82 | va_end(ap); 83 | fputc('\n', stderr); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/settings.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Definition of variables holding settings for current session. 25 | */ 26 | 27 | // This file contains global runtime settings 28 | #ifndef FUNGE_HAD_SRC_SETTINGS_H 29 | #define FUNGE_HAD_SRC_SETTINGS_H 30 | 31 | #include "global.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | /// What version of the Funge standard we are executing. 38 | /// @note 39 | /// Out of order to make default initialise to 0. 40 | /// (A few bytes smaller binary that way, The standard one should always be 0) 41 | typedef enum { stdver98 = 0, stdver93 = 1, stdver109 = 2 } standardVersion; 42 | 43 | /// What version we should simulate. 44 | /// Affects space processing. 45 | extern standardVersion setting_current_standard; 46 | 47 | /// Level of trace output 48 | extern uint_fast16_t setting_trace_level; 49 | /// Should we enable warnings 50 | extern bool setting_enable_warnings; 51 | /// Should we enable certain error messages. 52 | /// Fatal errors are always shown. 53 | extern bool setting_enable_errors; 54 | 55 | /// Should fingerprints be enabled 56 | extern bool setting_disable_fingerprints; 57 | 58 | /// Sandbox, prevent bad programs affecting system. 59 | /// If true: 60 | /// - Any file, filesystem or network IO is forbidden. 61 | /// - The program can not access network using network fingerprints. 62 | /// - The environment variables it can see are restricted. 63 | /// 64 | /// Summary: 65 | /// - In core opcodes: =, o and i are forbidden and certain environment 66 | /// variables are hidden. 67 | /// - In fingerprints: Non-safe fingerprints are not loaded. 68 | extern bool setting_enable_sandbox; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/fingerprints/MODU/MODU.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "MODU.h" 23 | #include "../../stack.h" 24 | 25 | // This was more or less taken from CCBI 26 | FUNGE_ATTR_CONST FUNGE_ATTR_FAST 27 | static inline funge_cell floordiv(funge_cell x, funge_cell y) 28 | { 29 | x /= y; 30 | if (x < 0) 31 | return x - 1; 32 | else 33 | return x; 34 | } 35 | 36 | static void finger_MODU_signed_result(instructionPointer * ip) 37 | { 38 | funge_cell x, y; 39 | y = stack_pop(ip->stack); 40 | x = stack_pop(ip->stack); 41 | if (x == FUNGECELL_MIN && y == -1) { 42 | stack_push(ip->stack, 0); 43 | } else if (y) { 44 | stack_push(ip->stack, x - floordiv(x, y) * y); 45 | } else { 46 | stack_push(ip->stack, 0); 47 | } 48 | } 49 | 50 | static void finger_MODU_unsigned_result(instructionPointer * ip) 51 | { 52 | funge_cell x, y; 53 | y = stack_pop(ip->stack); 54 | x = stack_pop(ip->stack); 55 | if (x == FUNGECELL_MIN && y == -1) { 56 | stack_push(ip->stack, 0); 57 | } else if (y) { 58 | stack_push(ip->stack, ABS(x % y)); 59 | } else { 60 | stack_push(ip->stack, 0); 61 | } 62 | } 63 | 64 | // C style reminder. 65 | static void finger_MODU_remainder(instructionPointer * ip) 66 | { 67 | funge_cell x, y; 68 | y = stack_pop(ip->stack); 69 | x = stack_pop(ip->stack); 70 | if (x == FUNGECELL_MIN && y == -1) { 71 | stack_push(ip->stack, 0); 72 | } else if (y) { 73 | // Well that's easy, this *is* C. 74 | stack_push(ip->stack, x % y); 75 | } else { 76 | stack_push(ip->stack, 0); 77 | } 78 | } 79 | 80 | 81 | bool finger_MODU_load(instructionPointer * ip) 82 | { 83 | manager_add_opcode(MODU, 'M', signed_result); 84 | manager_add_opcode(MODU, 'R', remainder); 85 | manager_add_opcode(MODU, 'U', unsigned_result); 86 | return true; 87 | } 88 | -------------------------------------------------------------------------------- /lib/libghthash/hash_table.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * 3 | * Copyright (C) 2001-2005, Simon Kagstrom 4 | * 5 | * Filename: hash_table.c 6 | * Description: The implementation of the hash table (MK2). 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 11 | * of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 21 | * 02111-1307, USA. 22 | * 23 | * $Id: hash_table.c 15761 2007-07-15 06:08:52Z ska $ 24 | * 25 | ********************************************************************/ 26 | 27 | #include /* malloc */ 28 | #include /* perror */ 29 | #include /* errno */ 30 | #include /* memcmp */ 31 | #include 32 | #include /* assert */ 33 | 34 | #define CF_GHT_INTERNAL 35 | #include "ght_hash_table.h" 36 | 37 | #include "../../src/global.h" 38 | #include "../../src/diagnostic.h" 39 | 40 | #define CFUNGE_MEMPOOL_HASHLIB 41 | #include "../mempool/cfunge_mempool.h" 42 | 43 | /* Flags for the elements. This is currently unused. */ 44 | #define FLAGS_NONE 0 /* No flags */ 45 | #define FLAGS_NORMAL 0 /* Normal item. All user-inserted stuff is normal */ 46 | #define FLAGS_INTERNAL 1 /* The item is internal to the hash table */ 47 | 48 | #define CF_GHT_VAR fspace 49 | #define CF_GHT_KEY fungeSpaceHashKey 50 | #define CF_GHT_DATA funge_cell 51 | #define CF_GHT_COMPAREKEYS(m_a, m_b) (((m_a)->p_key.x == (m_b)->p_key.x) && ((m_a)->p_key.y == (m_b)->p_key.y)) 52 | #define CF_GHT_COPYKEY(m_target, m_source) \ 53 | do { \ 54 | (m_target).x = (m_source)->x; \ 55 | (m_target).y = (m_source)->y; \ 56 | } while (0) 57 | 58 | #include "hash_table_priv.h" 59 | 60 | #undef CF_GHT_VAR 61 | #undef CF_GHT_KEY 62 | #undef CF_GHT_DATA 63 | #undef CF_GHT_COMPAREKEYS 64 | #undef CF_GHT_COPYKEY 65 | 66 | #ifdef CFUN_EXACT_BOUNDS 67 | # define CF_GHT_VAR fspacecount 68 | # define CF_GHT_KEY funge_cell 69 | # define CF_GHT_DATA funge_unsigned_cell 70 | # define CF_GHT_COMPAREKEYS(m_a, m_b) ((m_a)->p_key == (m_b)->p_key) 71 | # define CF_GHT_COPYKEY(m_target, m_source) \ 72 | do { (m_target) = *(m_source); } while (0) 73 | 74 | # include "hash_table_priv.h" 75 | #endif 76 | -------------------------------------------------------------------------------- /src/input.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * The file input.c contains functions for reading user input from STDIN, 25 | * buffered as needed. 26 | */ 27 | 28 | #ifndef FUNGE_HAD_SRC_INPUT_H 29 | #define FUNGE_HAD_SRC_INPUT_H 30 | 31 | #include "global.h" 32 | #include 33 | 34 | /** 35 | * Return type of input_getint() 36 | */ 37 | typedef enum ret_getint { 38 | rgi_success = 0, ///< Successfully got an integer 39 | rgi_eof = 1, ///< We got an EOF and should reflect 40 | rgi_noint = 2, ///< We didn't get an int, please call us again. 41 | } ret_getint; 42 | 43 | /** 44 | * For use in input instruction & and in some fingerprints. 45 | * @param value Pointer to some memory to place the read integer in. 46 | * @param base What base to read the number as. 47 | * @return 48 | * Returns rgi_success if it got an integer in the given base, otherwise 49 | * rgi_noint or rgi_eof. 50 | * @note The read integer is returned in the value parameter. 51 | */ 52 | FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR_FAST 53 | ret_getint input_getint(funge_cell * restrict value, int base); 54 | 55 | /** 56 | * For use in input instruction ~ and in some fingerprints. 57 | * This uses a buffer and read in one line (if the buffer is empty, 58 | * otherwise it reuse the values from the old buffer). 59 | * @param chr Pointer to a funge_cell to return value in. 60 | * @return True if we got a char, false if we got EOF and should reflect. 61 | */ 62 | FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR_FAST 63 | bool input_getchar(funge_cell * restrict chr); 64 | 65 | /** 66 | * For use in input some fingerprints. 67 | * This will return the whole buffer. 68 | * @param str Pointer to a string pointer to fill in. 69 | * @return True if we got a string, false if we got EOF and should reflect. 70 | */ 71 | FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR_FAST 72 | bool input_getline(unsigned char ** str); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/interpreter.h: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * Header for interpreter.c (that contains the main loop and parser). 25 | */ 26 | 27 | #ifndef FUNGE_HAD_SRC_INTERPRETER_H 28 | #define FUNGE_HAD_SRC_INTERPRETER_H 29 | 30 | #include "global.h" 31 | 32 | #include 33 | #include 34 | 35 | #include "ip.h" 36 | 37 | // Certain instructions that are also used elsewhere. 38 | /** 39 | * Run a _ instruction. 40 | * @param ip to IP to execute this instruction for. 41 | */ 42 | FUNGE_ATTR_NONNULL FUNGE_ATTR_FAST 43 | void if_east_west(instructionPointer * restrict ip); 44 | /** 45 | * Run a | instruction. 46 | * @param ip to IP to execute this instruction for. 47 | */ 48 | FUNGE_ATTR_NONNULL FUNGE_ATTR_FAST 49 | void if_north_south(instructionPointer * restrict ip); 50 | 51 | /** 52 | * Run instruction. Different prototype depending on if CONCURRENT_FUNGE 53 | * is defined or not. 54 | * @param opcode Instruction to execute 55 | * @param ip Instruction pointer to execute the instruction in. 56 | * @param threadindex The thread index (only if CONCURRENT_FUNGE is defined) 57 | * @returns 58 | * Return value only if CONCURRENT_FUNGE is defined. If true we executed an 59 | * instruction that took 0 ticks, so call me again right away (in main loop)! 60 | */ 61 | #ifdef CONCURRENT_FUNGE 62 | FUNGE_ATTR_NONNULL FUNGE_ATTR_FAST 63 | bool execute_instruction(funge_cell opcode, 64 | instructionPointer * restrict ip, 65 | ssize_t * threadindex); 66 | #else 67 | FUNGE_ATTR_NONNULL FUNGE_ATTR_FAST 68 | void execute_instruction(funge_cell opcode, 69 | instructionPointer * restrict ip); 70 | #endif 71 | 72 | /** 73 | * Start interpreter on a specific filename. 74 | * @warning MUST only be called from main.c 75 | * @param filename Filename to operate on. 76 | */ 77 | FUNGE_ATTR_NORET FUNGE_ATTR_FAST 78 | void interpreter_run(const char *filename); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/fingerprints/REFC/REFC.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "REFC.h" 23 | #include "../../stack.h" 24 | #include "../../vector.h" 25 | 26 | #include 27 | 28 | #define ALLOCCHUNK 5 29 | // Array holding references. 30 | static funge_vector *references = NULL; 31 | // Top index used in array. 32 | static size_t referencesTop = 0; 33 | // Size of array (including allocated but not yet used elements). 34 | static size_t referencesSize = 0; 35 | 36 | static void finger_REFC_reference(instructionPointer * ip) 37 | { 38 | funge_cell x, y; 39 | y = stack_pop(ip->stack); 40 | x = stack_pop(ip->stack); 41 | if (referencesSize == referencesTop + 1) { 42 | funge_vector * newrefs = (funge_vector*)realloc(references, (referencesSize + ALLOCCHUNK) * sizeof(funge_vector)); 43 | if (newrefs == NULL) { 44 | ip_reverse(ip); 45 | return; 46 | } 47 | references = newrefs; 48 | referencesSize += ALLOCCHUNK; 49 | } 50 | // TODO: Return same value for the same cell each time! 51 | // Yes cell 0 will never be used, but that is a hack to prevent having 52 | // errors on someone doing 0D before they do any R. 53 | referencesTop++; 54 | references[referencesTop].x = x; 55 | references[referencesTop].y = y; 56 | stack_push(ip->stack, (funge_cell)referencesTop); 57 | } 58 | 59 | static void finger_REFC_dereference(instructionPointer * ip) 60 | { 61 | funge_cell ref; 62 | ref = stack_pop(ip->stack); 63 | if ((ref <= 0) || ((size_t)ref > referencesTop)) { 64 | ip_reverse(ip); 65 | return; 66 | } 67 | stack_push_vector(ip->stack, &references[ref]); 68 | } 69 | 70 | FUNGE_ATTR_FAST static inline bool init_references(void) 71 | { 72 | assert(!references); 73 | references = (funge_vector*)malloc(ALLOCCHUNK * sizeof(funge_vector)); 74 | if (!references) 75 | return false; 76 | referencesSize = ALLOCCHUNK; 77 | return true; 78 | } 79 | 80 | 81 | bool finger_REFC_load(instructionPointer * ip) 82 | { 83 | if (!references) 84 | if (!init_references()) 85 | return false; 86 | manager_add_opcode(REFC, 'D', dereference); 87 | manager_add_opcode(REFC, 'R', reference); 88 | return true; 89 | } 90 | -------------------------------------------------------------------------------- /src/fingerprints/INDV/INDV.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- 2 | * 3 | * cfunge - A standard-conforming Befunge93/98/109 interpreter in C. 4 | * Copyright (C) 2008-2013 Arvid Norlander 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at the proxy's option) any later version. Arvid Norlander is a 10 | * proxy who can decide which future versions of the GNU General Public 11 | * License can be used. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | #include "INDV.h" 23 | #include "../../stack.h" 24 | 25 | /// This simply fetches the second vector. 26 | FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED 27 | static inline funge_vector get_second_vector(instructionPointer * restrict ip) 28 | { 29 | funge_vector a, b; 30 | 31 | a = stack_pop_vector(ip->stack); 32 | // Add first level of storage offset... 33 | a.x += ip->storageOffset.x; 34 | a.y += ip->storageOffset.y; 35 | b.x = fungespace_get(vector_create_ref(a.x + 1, a.y)); 36 | b.y = fungespace_get(&a); 37 | // Add in second level of storage offset... 38 | b.x += ip->storageOffset.x; 39 | b.y += ip->storageOffset.y; 40 | return b; 41 | } 42 | 43 | /// G - Get value using indirect vector 44 | static void finger_INDV_get_num(instructionPointer * ip) 45 | { 46 | funge_vector v = get_second_vector(ip); 47 | stack_push(ip->stack, fungespace_get(&v)); 48 | } 49 | 50 | /// P - Put value using indirect vector 51 | static void finger_INDV_put_num(instructionPointer * ip) 52 | { 53 | funge_vector v = get_second_vector(ip); 54 | fungespace_set(stack_pop(ip->stack), &v); 55 | } 56 | 57 | /// V - Get vector using indirect vector 58 | static void finger_INDV_get_vec(instructionPointer * ip) 59 | { 60 | funge_vector v = get_second_vector(ip); 61 | stack_push_vector(ip->stack, 62 | vector_create_ref( 63 | fungespace_get(vector_create_ref(v.x + 1, v.y)), 64 | fungespace_get(&v) 65 | ) 66 | ); 67 | } 68 | 69 | /// W - Write vector using indirect vector 70 | static void finger_INDV_put_vec(instructionPointer * ip) 71 | { 72 | funge_vector a, b; 73 | a = get_second_vector(ip); 74 | b = stack_pop_vector(ip->stack); 75 | fungespace_set(b.y, &a); 76 | fungespace_set(b.x, vector_create_ref(a.x + 1, a.y)); 77 | } 78 | 79 | bool finger_INDV_load(instructionPointer * ip) 80 | { 81 | manager_add_opcode(INDV, 'G', get_num); 82 | manager_add_opcode(INDV, 'P', put_num); 83 | manager_add_opcode(INDV, 'V', get_vec); 84 | manager_add_opcode(INDV, 'W', put_vec); 85 | return true; 86 | } 87 | --------------------------------------------------------------------------------