I'm trying to figure with which implementations I can compile to C
source code, and from there generate very small executables. My target
platform has only 256 kByte RAM available and provides only a C compiler.
Bigloo, Chicken, Gambit, Schlep and Petit Larceny seem good candidates,
but before doing the preliminary tests all myself, can anyone already
give me hints which ones would allow me to considerably reduce the size
of executables and would therefore be good choices?
Thanks a lot in advance!
1st European Lisp Symposium (ELS'08)
> I'm trying to figure with which implementations I can compile to C
> source code, and from there generate very small executables. My target
> platform has only 256 kByte RAM available and provides only a C compiler.
With only 256k bytes, I think you'd be better off
using a byte code interpreter than compiling to C.
> Bigloo, Chicken, Gambit, Schlep and Petit Larceny seem good candidates,
> but before doing the preliminary tests all myself, can anyone already
> give me hints which ones would allow me to considerably reduce the size
> of executables and would therefore be good choices?
In native Larceny, the R6RS-compatible get-datum
procedure compiles into a single chunk of machine
code that's over 300k bytes on x86-32 and over
400k bytes on the SPARC.
On Petit Larceny, get-datum compiles to a single
C function that takes gcc about an hour to compile
on our Linux box. I'm pretty sure the machine code
that gcc generates for that one C function is larger
than the machine code that native Larceny generates.
On a SPARC, that one .o file is over 700k bytes.
That's an extreme example, caused in part by the
complexity of R6RS lexical syntax, but it illustrates
The standard interpreters for Bigloo, Chicken, Gambit,
and Petit Larceny all occupy several megabytes, all
by themselves. You could probably cross-compile and
execute smallish programs, but anything that pulls in
a substantial fraction of the usual libraries (small
as they are) is likely to exceed 256k bytes.
Hi, try Stalin. I wrote a lot of code in Stalin, and it is stingy (and
fast too). Schlep generates very small exec too, but I am not sure
that one can call it a Scheme implementation. Anyway, it is quite easy
to combine Schlep with Siod, and get a working stand alone with most
of Scheme functionality. You need to modify schlep to generate code
that is compatible with Siod. Here is an example of program for the
'((eed (array "unsigned char"))
(ate (array "unsigned char"))
(sta (array "unsigned char"))
(sra (array unsigned))
(argv (ptr (ptr "char")))
("rgv" (array (array char)))
(define (fat n acc)
(if (< n 1) acc
(fat (- n 1) (* n acc))))
(define (fat_s x_)
(if (nflonump x_) (err "argumento errado" x_))
(flocons (toreal (fat (toint (flonm x_)) 1))))
(define (fib n)
(if (< n 2) 1
(+ (fib (- n 1)) (fib (- n 2)) )))
(define (fib_s n_)
(flocons (toreal (fib (toint (flonm n_)) )) ))
(define (main argc argv)
(let ((retval 0))
(process_cla argc argv 0)
(init_subr_1 "fatori" fat_s)
(init_subr_1 "fibo" fib_s)
(set! retval (repl_driver 1 1 c_null))
Modified Schlep generates the following C code:
int fat(n, acc)
int T_n = (n)-1;
acc = (n)*(acc);
n = T_n;
err("argumento errado", x_);
return flocons(toreal(fat(toint(flonm(x_)), 1)));
else return (fib((n)-1))+(fib((n)-2));
int main(argc, argv)
int retval = 0;
process_cla(argc, argv, 0);
retval = repl_driver(1, 1, c_null);
The stand alone has only 59 K.
Thanks a lot for your response, these look like very promising
alternatives. Your feedback is appreciated.
Yes, that's a possibility, although not the best one for our case. But
thanks for your comments anyway.
P.S.: Hm, wasn't Scheme supposed to be a minimal language? ;-)
You may want to try Pre-Scheme. It is very minimal, but still quite
OK, could be an option. But is there any documentation available?
Unfortunately I haven't been able to find any except
http://mumble.net/~kelsey/papers/prescheme.ps.gz (which isn't very
useful for as a PreScheme user) and the source itself, but hopefully
that shouldn't be a big problem for an embedded project - presumably
you don't need libraries.
BTW, In theory I disagree with the assessment that a Scheme
applications needs a byte-code interpreter to be able to run inside
256KB. It barely needs any runtime system at all except a GC. Bigints,
rationals, etc, are clearly optional.
The fact that some implementations of get-datum (which itself is not
needed in an embedded implementation) compile to hundreds of kilobytes
really means nothing except that these implementations aren't
concerned with code size (nobody programming on a PC is anymore).
Turbo Pascal 3 was significantly more complex than get-datum and was
smaller than 64 KB.
That said, I think that in practice, given the current state of
affairs, you are probably out of luck.
> OK, could be an option. But is there any documentation available?
You should still be able to find Taylor Campbell's manual on the
Internet archives: The PreScheme compiler hasn't changed (except for bug
fixes) since it was written. There are several active PreScheme
projects going on, though, and we generally try to help on the Scheme 48
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
Thanks a lot!