996
|
1 This is cfunge - a fast Befunge93/98/109 interpreter in C.
|
|
2
|
|
3 cfunge offers some features that many other standard conforming interpreters
|
|
4 don't. For example:
|
|
5 * Sandbox mode, prevents programs from harming system (more details below).
|
|
6 * Advance tracing support, debugging protocol support system under development.
|
|
7 * Passes mycology (of course other conforming interpreters does this, but most
|
|
8 interpreters are, sadly, not conforming).
|
|
9 * Tested using Valgrind and similar tools.
|
|
10 * Tested with fuzz testing to ensure cfunge does not segfault on random stuff.
|
|
11 * Coded for maximum performance AND correctness.
|
|
12 * Support for selecting either 64-bit or 32-bit integers as datatype in
|
|
13 funge-space at compile time.
|
|
14
|
|
15
|
|
16 Dependencies
|
|
17 ------------
|
|
18 REQUIRED:
|
|
19 * cmake (http://www.cmake.org/) to generate Makefile for cfunge. At least
|
|
20 version 2.6 is required.
|
|
21
|
|
22 * A C99 compiler, or one that supports a large subset of C99, like GCC.
|
|
23 + GCC 3.4.6, 4.1.2, 4.2.1, 4.3.2 and 4.3.3 are known to work, other versions
|
|
24 may or may not work.
|
|
25 + ICC 10.1 is known to work too.
|
|
26 + Open64 4.1 should work, but isn't recommended.
|
|
27 + Very recent SVN versions of clang works on 32-bit x86 (as of 2009-03-28),
|
|
28 but can currently not be recommended since clang is not very stable yet.
|
|
29 - TCC 0.9.24 is known to fail at certain C99 constructs used in cfunge.
|
|
30 Other compilers may or may not work.
|
|
31
|
|
32 * A POSIX.1-2001 system with the memory mapped file option. It also needs the
|
|
33 function strdup() which is part of the XSI extension. (For POSIX.1-2008 both
|
|
34 strdup() and memory mapped files are mandatory and part of the base.)
|
|
35 Operating systems known to work:
|
|
36 + Linux 2.6.27 (with glibc 2.8) and later (earlier versions unknown but will
|
|
37 probably work unless very old).
|
|
38 + FreeBSD 6.4 or later (earlier versions unknown).
|
|
39 + Mac OS X (unknown version) has been reported to work but I don't have it
|
|
40 myself and thus can't test it.
|
|
41 + OpenBSD 4.4 (sparc64): I have not managed to get cmake 2.6 to compile on
|
|
42 OpenBSD, but I did manage to build cfunge by hand, required some strange
|
|
43 workarounds and defines.
|
|
44 Windows most likely won't work. Nor do I plan to support it. Cygwin may work,
|
|
45 but you are on your own if it doesn't.
|
|
46
|
|
47 HIGHLY RECOMMENDED:
|
|
48 * Ncurses (http://www.gnu.org/software/ncurses/), needed for the TERM
|
|
49 fingerprint. This is most likely already installed. Ncurses will be
|
|
50 automatically used if found.
|
|
51
|
|
52 * IEC 60559 floating-point arithmetic. Please see Annex F in ISO/IEC 9899 for
|
|
53 more details.
|
|
54
|
|
55 OPTIONAL:
|
|
56 * Boehm-GC (http://www.hpl.hp.com/personal/Hans_Boehm/gc/) version 7 or later.
|
|
57 You have to manually enable some compile time options to use Boehm-GC.
|
|
58
|
|
59
|
|
60 Configuring
|
|
61 -----------
|
|
62 Warning: Out of tree builds are highly recommended. Building in the source tree
|
|
63 may work but is _completely_ untested.
|
|
64
|
|
65 To build using cmake, you can run these commands in the top source directory:
|
|
66 mkdir build && cd build
|
|
67 cmake ..
|
|
68
|
|
69 If you are on a 32-bit system you may want to use 32-bit integers (instead of
|
|
70 64-bit integers) for speed. It is also slightly faster on some 64-bit systems
|
|
71 to use 32-bit integers. This may vary between architectures. To use 32-bit
|
|
72 integers you could use these commands instead of the above ones:
|
|
73 mkdir build && cd build
|
|
74 cmake -DUSE_64BIT=OFF ..
|
|
75
|
|
76 If you want to see a list of available options use ccmake. It will allow you to
|
|
77 select options in a ncurses based user interface. Help is always shown at the
|
|
78 bottom of the screen.
|
|
79 mkdir build && cd build
|
|
80 ccmake ..
|
|
81 (press c)
|
|
82 (change options - use t to show advanced options)
|
|
83 (press c again)
|
|
84 (press g to generate make file)
|
|
85
|
|
86 For more information see:
|
|
87 cmake --help
|
|
88 and/or
|
|
89 ccmake --help
|
|
90
|
|
91 To enable garbage collector you can run cmake with -DUSE_GC=ON. However using a
|
|
92 GC isn't as fast as not using one and it could also cause issues with certain
|
|
93 fingerprints.
|
|
94
|
|
95
|
|
96 Compiling
|
|
97 ---------
|
|
98 After having run cmake as described in the above section, just run:
|
|
99 make
|
|
100
|
|
101
|
|
102 Installing
|
|
103 ----------
|
|
104 Not needed, cfunge can be run from build directory, but if you want to (after
|
|
105 having compiled cfunge):
|
|
106 make install
|
|
107
|
|
108
|
|
109 Fingerprints
|
|
110 ------------
|
|
111 It is planned to implement most or all of the existing fingerprints,
|
|
112 with some exceptions:
|
|
113 * FNGR - Contradicts with 98 standard.
|
|
114 * IMAP - Too intrusive.
|
|
115 * MODE - Intrusive into IP handling.
|
|
116 * TRDS - Exceedingly complex and intrusive.
|
|
117 * WIND - Too complex to implement and not portable.
|
|
118
|
|
119 Short descriptions of implemented fingerprints:
|
|
120 3DSP 3D space manipulation extension
|
|
121 BASE I/O for numbers in other bases
|
|
122 CPLI Complex Integer extension
|
|
123 DATE Date Functions
|
|
124 DIRF Directory functions extension
|
|
125 FILE File I/O functions
|
|
126 FING Operate on single fingerprint semantics
|
|
127 FIXP Some useful math functions
|
|
128 FPDP Double precision floating point
|
|
129 FPSP Single precision floating point
|
|
130 FRTH Some common forth commands
|
|
131 HRTI High-Resolution Timer Interface
|
|
132 INDV Pointer functions
|
|
133 JSTR Read and write strings in Funge-Space
|
|
134 MODU Modulo Arithmetic Extension
|
|
135 NCRS Ncurses Extension
|
|
136 NULL Funge-98 Null Fingerprint
|
|
137 ORTH Orthogonal Easement Library
|
|
138 PERL Generic Interface to the Perl Language
|
|
139 REFC Referenced Cells Extension
|
|
140 REXP Regular Expression Matching
|
|
141 ROMA Funge-98 Roman Numerals
|
|
142 SCKE TCP/IP async socket and dns resolving extension
|
|
143 SOCK TCP/IP socket extension
|
|
144 STRN String functions
|
|
145 SUBR Subroutine extension
|
|
146 TERM Terminal control functions
|
|
147 TIME Time and Date functions
|
|
148 TOYS Funge-98 Standard Toys
|
|
149 TURT Simple Turtle Graphics Library
|
|
150 For more details please see the specs for each fingerprint.
|
|
151 In cases of undefined behaviour in fingerprints, cfunge mostly tries to do the
|
|
152 same thing as CCBI.
|
|
153
|
|
154
|
|
155 Undefined behaviour
|
|
156 -------------------
|
|
157 The Befunge98 standard leaves some things undefined, here is what we do for
|
|
158 some of those cases:
|
|
159 * y pushes time in UTC not local time.
|
|
160 * k with a negative argument reflects.
|
|
161 * # across edge of funge-space may or may not skip first char after wrapping
|
|
162 depending on exact situation.
|
|
163 * ( and ) with a negative count reflects and doesn't pop any fingerprint.
|
|
164 * Loaded fingerprints are inherited to child IPs at split (t).
|
|
165 * STDOUT is only flushed at:
|
|
166 * Newline (line feed, ASCII 10) printed using , instruction.
|
|
167 * Any input instructions.
|
|
168 * End of program.
|
|
169 * Standard input is read one line at a time and buffered internally. Those
|
|
170 instructions reading chars fetch one char from this buffer, leaving the rest
|
|
171 (if any) including any ending newline. Instructions reading an integer will
|
|
172 leave anything after the integer in the buffer with one exception: if the
|
|
173 next char is a newline it will be discarded.
|
|
174
|
|
175
|
|
176 Notes on different standards
|
|
177 ----------------------------
|
|
178 The option -s 93 does not prevent the program from accessing outside the first
|
|
179 80x25 cells. Nor does it disallow instructions that didn't exist in 93. It does
|
|
180 however change space behaviour to match 93 style.
|
|
181
|
|
182 If a program depends on a instruction that is undefined in 93 to reflect, it
|
|
183 should be easy to replace such instructions with a r for reflect or any in the
|
|
184 range A-Z (and not load any fingerprint).
|
|
185
|
|
186 Further division by zero always returns 0 in all modes, though the Befunge93
|
|
187 specs says the interpreter should ask the user what result he/she wants in that
|
|
188 situation.
|
|
189
|
|
190
|
|
191 Sandbox mode
|
|
192 ------------
|
|
193 Sandbox mode prevents Funge programs from doing "harmful" things, this includes,
|
|
194 but is not limited to:
|
|
195 * Any file or filesystem IO is forbidden.
|
|
196 * The list of environment variables the program can see in y are restricted.
|
|
197 * Non-safe fingerprints can not be loaded (this includes network and file
|
|
198 system access as well as other things).
|