Lisp500

Is your program large and complex? Are you tired of Greenspunning? Now, in only 500 lines, here we have an informally-specified bug-ridden implementation of Common Lisp, ready to meet your needs.
-- Christophe Rhodes

Lisp500 is a 500-line implementation of an informally specified dialect of Lisp. It attempts to be not too bug-ridden. Unfortunately, it is 500 lines of C, not Fortran.

News

News as an RSS feed.

2004-07-22 * Refactored the compiler to get rid of two 500-line functions. Now have two functions for each special operator instead.
2004-05-11 Implemented flet and labels in the compiler. During a short break in working on lisp500, I apparently managed to forget how the stack discipline goes. It was somewhat painful to figure out how.
2004-04-28 Optimized C file size.
2004-04-26 Polished the compiler. Compiled code can actually be loaded and run now! The empty loop is many (less than ten) times faster than when interpreted! DEFUN works! Everything really simple works, nothing complicated works.
2004-04-22 Implemented the simplistic SETF in Lisp. This is required for the compiler.
2004-04-15 Changed the function representation to allow running compiled code. Accidentally diminished interpreter consing by about half. Enabled the lisp side repl, so the C side reader and printer are no longer seen by the user. No dotted lisp support in the lisp side reader yet. Fixed backtrace in the (lisp side) debugger. You can still end up in the C side debugger if you get an error during initialization.
2004-04-08 Implemented tagbody-local, go, go-unbound; block-local, return-from, return-from-unbound; lambda and if into write-c. Functions are a bit sloppily implemented, only mandatory arguments work now, and there's no argument count checking yet.
2004-04-07 Implemented constant, dynamic-reference, dynamic-setq, funcall-global, let, progn and reference in write-c. The wrapping code is still missing, so none of this can actually be compiled and run, but it can be visually inspected for obvious bogosity.
2004-04-07 Added an RSS feed for lisp500 news.
2004-04-05 Started on the write-c function which is the second pass of the compiler.
2004-04-02 Sped up operation on MACH by conditionally using sigsetjmp instead of setjmp. Also fixed to work (at least a bit) on big-endian machines.
2004-04-01 Started the actual code transform phase of the compiler.
2004-03-31 Fixed both the value dumper and loader. Tested to work for immediates, symbols, strings and vectors.
2004-03-30 More work on the compiler's constant value dumper. Also implemented the corresponding loader.
2004-03-29 Fixed LENGTH for general arrays. Implemented bit of ADJUST-ARRAY. Started on the compiler.
2004-03-26 Added :up :down and :locals to the debugger. Added optional environment argument for EVAL, and use it to have the environment of the selected frame in the debugger when evaluating forms. Made :back nicer.
2004-03-25 Munged the stack layout to support inspection. Added backtrace to the Lisp side debugger.
2004-03-24 Made condition classes instances of standard-class which divided startup time by four. Work on the debugger and a repl.
2004-03-22 Reordered stuff in the C to make it slightly less uncompliant (compiles with Visual C again).
2004-03-22 Implemented effective method function memoization and thus halved startup time. MAKE-CONDITION now works.
2004-03-19 Implemented all required conditions.
2004-03-19 Added define-condition and made it a lot faster.
2004-03-18 Implemented a kick-ass elisplet to automatically update lisp-implementation-version and prompt for news items when publishing new versions of the code.
2004-03-16 :around, :before and :after methods.
2004-03-14 There's a bit of format and beginnings of CLOS. When I get a bit more of both done, I get conditions working and can move the debugger and the repl to the Lisp side.
2004-03-05 Changed the C core to use a separate Lisp object stack. Change pretty comprehensive, something may be broken as a result.
2004-02-21 Bug 7 provisionally fixed by an alternative version of the C source.
2004-02-19 It hasn't really been a good idea to try to use lisp500 without the init file loaded for some time now.
2004-02-19 Fixed bugs 5 and 6. I'm 28 years old.
2004-02-11 The init file has finally surpassed the actual program in length.
2004-02-11 On Brian's insistence, put up the text of the ad-less BSD license. Now you know what you can do with it.

License

Copyright © 2004 Teemu Kalvas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Installation

cc -o lisp500 lisp500.c -lm -ldl

or on Cygwin

cc -Wl,--out-implib=lisp500.imp -Wl,--export-all-symbols -o lisp500 lisp500.c

or on Windows

cl /MD lisp500.c

Usage

lisp500 <lisp-file1> <lisp-file2> ...

Loads the lisp-files and runs a read-eval-print loop. Mind you, the init file is not loaded automatically, if you want to have the definitions contained therein available, include it on the command line.

Known bugs

iddate posteddescriptionfixed time/plan
1 setf is incomplete, it only implements functions with name (setf foo)fixable in lisp
2 always &allows-other-keysignore for now
3 &aux not implemented, actuallycunning plan for finding out the heretics
4 supplied-p parameters not implementedwill fix
52004-02-19various crashers found: on visual C without optimization, and on tinycc on linux/x86 after the first gc during init file evaluation2004-02-19Z13:56
62004-02-19stream functions don't work2004-02-19Z13:11
72004-02-19doesn't appear to work with tinycc -g or checkergcc. it'd be interesting to know whywill look into any patch

Ok, report some.

Features

lisp500.c

&allow-other-keys &aux &body &environment &key &optional &rest &whole
declare special
nil t
block catch flet function go labels let let* macrolet multiple-value-call multiple-value-prog1 progn progv quote return-from setq symbol-macrolet tagbody throw unwind-protect
setf
apply funcall values
close-file-stream finish-file-stream gc iboundp iref imakunbound ival jref make-file-stream makei makej read-file-stream write-file-stream
= < + - * / car cdr char-code code-char cons dpb eq gensym ldb list load print string subseq
*standard-input* *standard-output* *error-output*

init500.lisp

` , @

defmacro (setf macro-function) define-symbol-macro special-operator-p constantp

type-of

defun fdefinition function-lambda-expression functionp defparameter defvar return not eql identity complement constantly every some notevery notany and cond or when unless case ecase multiple-value-bind multiple-value-list values-list nth-value prog prog* prog1 prog2

dolist

10. Symbols

11. Packages

/= > <= >= max min minusp plusp zerop abs incf decf byte byte-size byte-position

13. Characters

14. Conses

make-array adjustable-array-p aref array-dimension array-dimensions array-has-fill-pointer-p array-displacement array-in-bounds-p array-rank array-row-major-index array-total-size arrayp fill-pointer row-major-aref upgraded-array-element-type simple-vector-p svref vector vector-pop vector-push vector-push-extend vectorp simple-bit-vector-p

16. Strings

elt fill map-into count count-if count-if-not find find-if find-if-not position position-if position-if-not reverse nreverse

21. Streams (except file-length and file-position)

print-object write prin1 princ write-to-string prin1-to-string princ-to-string (beginnings of formatter and format)

23. Reader (the initial readtable is missing bits, though)