--- old/Makefile	Fri Jul 15 19:33:54 2005
+++ Makefile	Mon Jul 18 20:19:08 2005
@@ -4,7 +4,7 @@
 #CFLAGS+=-g -DDEBUG
 SRCS=builtin.c cons.c float.c func.c integer.c main.c nil.c quote.c rawfunc.c reader.c scope.c stream.c string.c throw.c util.c word.c
 BUILDDIR=obj/
-VERSION=1.1
+VERSION=1.2
 DISTFILES=CHANGELOG Makefile lisp.h $(SRCS) preload.lisp
 
 $(BUILDDIR)mikelisp : $(SRCS:%.c=$(BUILDDIR)%.o) lisp.h
@@ -23,3 +23,9 @@
 	tar -czf mikelisp-$(VERSION).tar.gz $(DISTFILES:%=mikelisp-$(VERSION)/%)
 	rm mikelisp-$(VERSION)
 
+patch : mikelisp-$(VERSION).patch
+	
+mikelisp-$(VERSION).patch : $(DISTFILES)
+	ln -s /www/html/mikelisp old
+	for f in $(DISTFILES);do diff -u old/$$f $$f;done > $@ || true
+	rm old
--- old/lisp.h	Tue Jul 12 16:38:44 2005
+++ lisp.h	Mon Jul 18 20:11:09 2005
@@ -1,4 +1,4 @@
-/* lisp.h   by Michael Thorpe   2005-07-12 */
+/* lisp.h   by Michael Thorpe   2005-07-18 */
 
 #ifndef OBJ_H
 #define OBJ_H
@@ -32,7 +32,10 @@
 
 struct obj {
 	objtype *type;
-	unsigned long refcount;
+	union {
+		unsigned long refcount;
+		obj *nextfree;
+	} rcnf;
 	union {
 		struct c {
 			obj *a;
@@ -170,11 +173,11 @@
 void real_decref(obj *o,const char *file,int line);
 #define incref(o) real_incref((o),__FILE__,__LINE__)
 obj *real_incref(obj *o,const char *file,int line);
-extern unsigned long total_objects,known_objects;
+extern unsigned long known_objects,total_objects;
 #define INC_KNOWN_OBJECTS(n) (known_objects+=(n))
 #else
-#define decref(o) do{if(!--(o)->refcount)drop_object(o);}while(0)
-#define incref(o) ((o)->refcount++,(o))
+#define decref(o) do{if(!--(o)->rcnf.refcount)drop_object(o);}while(0)
+#define incref(o) ((o)->rcnf.refcount++,(o))
 #define INC_KNOWN_OBJECTS(n) do{}while(0)
 #endif
 void drop_object(obj *o);
@@ -185,6 +188,7 @@
 void show_remaining_objects();
 #endif
 int util_init();
+void util_exit();
 
 /* word.c */
 obj *newword(const char *data,unsigned long len);
--- old/integer.c	Thu Dec  4 20:34:06 2003
+++ integer.c	Mon Jul 18 20:08:26 2005
@@ -1,4 +1,4 @@
-/* integer.c   by Michael Thorpe   2003-05-26 */
+/* integer.c   by Michael Thorpe   2005-07-18 */
 
 #include <stdio.h>
 #include "lisp.h"
@@ -21,5 +21,5 @@
 	tostring: integer_tostring
 };
 
-obj trueobj={&integer_objtype,1,{i:1}};
+obj trueobj={&integer_objtype,{refcount:1},{i:1}};
 
--- old/main.c	Tue Jul 12 18:11:42 2005
+++ main.c	Mon Jul 18 20:09:24 2005
@@ -1,4 +1,4 @@
-/* main.c   by Michael Thorpe   2005-07-12 */
+/* main.c   by Michael Thorpe   2005-07-18 */
 
 #include <stdio.h>
 #include "lisp.h"
@@ -74,6 +74,7 @@
 		return(1);
 	}
 	decscoperef(globalscope);
+	util_exit();
 #ifdef DEBUG
 	fflush(stdout);
 	if(total_scopes)
--- old/nil.c	Sun Jul 10 21:57:54 2005
+++ nil.c	Mon Jul 18 20:08:40 2005
@@ -1,4 +1,4 @@
-/* nil.c   by Michael Thorpe   2005-07-10 */
+/* nil.c   by Michael Thorpe   2005-07-18 */
 
 #include "lisp.h"
 
@@ -12,5 +12,5 @@
 	tostring: nil_tostring
 };
 
-obj nilobj={&nil_objtype,1};
+obj nilobj={&nil_objtype,{refcount:1}};
 
--- old/scope.c	Fri Jul 15 19:29:50 2005
+++ scope.c	Mon Jul 18 20:08:56 2005
@@ -1,4 +1,4 @@
-/* scope.c   by Michael Thorpe   2005-07-15 */
+/* scope.c   by Michael Thorpe   2005-07-18 */
 
 #include <stdlib.h>
 #include <string.h>
@@ -19,7 +19,7 @@
 static scope topscope={1,0,0};
 scope *globalscope=0;
 
-static obj undefined_error={&word_objtype,1,{s:{"undefined",9}}};
+static obj undefined_error={&word_objtype,{refcount:1},{s:{"undefined",9}}};
 
 /* real_lookup doesn't decref/incref anything */
 static entry *real_lookup(scope *scope,obj *name) {
--- old/util.c	Wed Jul 13 14:24:42 2005
+++ util.c	Mon Jul 18 20:11:43 2005
@@ -1,20 +1,21 @@
-/* util.c   by Michael Thorpe   2005-07-13 */
+/* util.c   by Michael Thorpe   2005-07-18 */
 
 #include <stdlib.h>
 #include <string.h>
 #include "lisp.h"
 
+static obj *freelist=0;
 #ifdef DEBUG
-unsigned long total_objects=0,known_objects=0;
-obj *firstobj=0;
+unsigned long known_objects=0,total_objects=0;
+static obj *firstobj=0;
 
 obj *real_incref(obj *o,const char *file,int line) {
 #if DEBUG > 2
 	fprintf(stderr,"%s:%d: incref(%p)\n",file,line,o);
 #endif
-	if(o->refcount>10000000)
+	if(o->rcnf.refcount>10000000)
 		*(char *)0=0;
-	o->refcount++;
+	o->rcnf.refcount++;
 	return(o);
 }
 
@@ -22,18 +23,18 @@
 #if DEBUG > 2
 	fprintf(stderr,"%s:%d: decref(%p)\n",file,line,o);
 #endif
-	if(!--o->refcount)
+	if(!--o->rcnf.refcount)
 		drop_object(o);
 }
 #endif
 
 void drop_object(obj *o) {
-	if(o->type->dropobj)
-		(o->type->dropobj)(o);
 #ifdef DEBUG
 #if DEBUG > 1
 	fprintf(stderr,"drop_object(%p)\n",o);
 #endif
+	if(o->type->dropobj)
+		(o->type->dropobj)(o);
 	total_objects--;
 	if(o->prev)
 		o->prev->next=o->next;
@@ -43,7 +44,8 @@
 		o->next->prev=o->prev;
 	memset(o,'o',sizeof(obj));
 #else
-	free(o);
+	o->rcnf.nextfree=freelist;
+	freelist=o;
 #endif
 }
 
@@ -73,11 +75,18 @@
 obj *newobj(objtype *type) {
 	obj *o;
 
-	o=(obj *)calloc(1,sizeof(obj));
-	if(!o)
-		return(throwoom());
+	if(freelist) {
+		o=freelist;
+		freelist=o->rcnf.nextfree;
+		if(o->type->dropobj)
+			(o->type->dropobj)(o);
+	} else {
+		o=(obj *)calloc(1,sizeof(obj));
+		if(!o)
+			return(throwoom());
+	}
 	o->type=type;
-	o->refcount=1;
+	o->rcnf.refcount=1;
 #ifdef DEBUG
 #if DEBUG > 1
 	fprintf(stderr,"newobj(%s)=%p\n",type->name,o);
@@ -90,6 +99,8 @@
 	firstobj=o;
 #endif
 	return(o);
+	if(o->type->dropobj)
+		(o->type->dropobj)(o);
 }
 
 int register_objtype(objtype *type) {
@@ -118,7 +129,7 @@
 			fprintf(stderr,"%p: dropped object found!\n",o);
 			break;
 		}
-		fprintf(stderr,"%p: <%lu:%s:",o,o->refcount,o->type->name);
+		fprintf(stderr,"%p: <%lu:%s:",o,o->rcnf.refcount,o->type->name);
 		if(&word_objtype==o->type)
 			fprintf(stderr,"%p=\"%.*s\"",o->value.s.data,(int)o->value.s.len,o->value.s.data);
 		else
@@ -144,4 +155,16 @@
 	|| register_objtype(&word_objtype))
 		return(1);
 	return(0);
+}
+
+void util_exit() {
+	obj *o;
+
+	while(freelist) {
+		o=freelist;
+		freelist=o->rcnf.nextfree;
+		if(o->type->dropobj)
+			(o->type->dropobj)(o);
+		free(o);
+	}
 }
--- old/preload.lisp	Wed Jul 13 16:09:23 2005
+++ preload.lisp	Fri Jul 15 19:56:55 2005
@@ -128,10 +128,6 @@
 			(cons 'progn body)
 			(list 'throw ''exit-loop #f))))
 
-(define (dprint o)
-	(write-object #standard-out o)
-	(write-char #standard-out 10))
-
 (define (write-newline file)
 	(write-char file 10))
 (define (show-error error errorvalue)
