--- old/CHANGELOG	Fri Jul 15 19:26:47 2005
+++ CHANGELOG	Fri Jul 15 19:25:41 2005
@@ -0,0 +1,6 @@
+2005-07-13: 1.0: Initial release. Has basic I/O and a "soft" repl loop
+(i.e., one written in lisp).
+
+2005-07-15: 1.1: General cleanup and refcount bug fix in builtin.c.
+newscope() now calls throwoom so callers merely need return(0). New
+strings are initialized to null bytes.
--- old/Makefile	Wed Jul 13 16:10:25 2005
+++ Makefile	Fri Jul 15 19:31:43 2005
@@ -4,8 +4,8 @@
 #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.0
-DISTFILES=Makefile lisp.h $(SRCS) preload.lisp
+VERSION=1.1
+DISTFILES=CHANGELOG Makefile lisp.h $(SRCS) preload.lisp
 
 $(BUILDDIR)mikelisp : $(SRCS:%.c=$(BUILDDIR)%.o) lisp.h
 	$(CC) $(CFLAGS) -o $@ $(SRCS:%.c=$(BUILDDIR)%.o)
--- old/builtin.c	Wed Jul 13 15:16:51 2005
+++ builtin.c	Fri Jul 15 19:17:50 2005
@@ -1,4 +1,4 @@
-/* builtin.c   by Michael Thorpe   2005-07-13 */
+/* builtin.c   by Michael Thorpe   2005-07-15 */
 
 #include <ctype.h>
 #include <limits.h>
@@ -13,6 +13,7 @@
 static obj *add(obj *a,obj *b) {
 	long result;
 	int overflow=0;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -27,17 +28,18 @@
 		overflow=1;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a) {
-		a->value.i=result;
+	r=newobj(&integer_objtype);
+	if(r) {
+		r->value.i=result;
 		if(overflow)
-			return(throw(overflowerror,a));
+			return(throw(incref(overflowerror),r));
 	}
-	return(a);
+	return(r);
 }
 
 static obj *bitand(obj *a,obj *b) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -50,27 +52,29 @@
 	result=a->value.i&b->value.i;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 static obj *bitnot(obj *a) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype)
 		return(throwtypeerror(a));
 	result=~a->value.i;
 	decref(a);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 static obj *bitor(obj *a,obj *b) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -83,14 +87,15 @@
 	result=a->value.i|b->value.i;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 static obj *bitxor(obj *a,obj *b) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -103,14 +108,15 @@
 	result=a->value.i^b->value.i;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 static obj *div(obj *a,obj *b) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -122,15 +128,15 @@
 	}
 	if(b->value.i==0) {
 		decref(b);
-		return(throw(divideby0error,a));
+		return(throw(incref(divideby0error),a));
 	}
 	result=a->value.i/b->value.i;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 static obj *eq(obj *a,obj *b) {
@@ -150,47 +156,47 @@
 
 static obj *ifelse(scope *s,obj *cond,obj *iftrue,obj *iffalse) {
 	decref(cond);
-	if(cond != &nilobj) {
-		decref(iffalse);
-		return(evaluate(s,iftrue));
-	} else {
+	if(cond==&nilobj) {
 		decref(iftrue);
 		return(evaluate(s,iffalse));
+	} else {
+		decref(iffalse);
+		return(evaluate(s,iftrue));
 	}
 }
 
 static obj *isasciip(obj *a) {
-	long result;
+	int result;
 
 	if(a->type != &integer_objtype)
 		return(throwtypeerror(a));
 	if(a->value.i<0 || a->value.i>UCHAR_MAX)
 		return(throwrangecheck(a));
-	result=isascii((unsigned char)a->value.i);
+	result=isascii((int)a->value.i);
 	decref(a);
 	return(incref(result?&trueobj:&nilobj));
 }
 
 static obj *isdigitp(obj *a) {
-	long result;
+	int result;
 
 	if(a->type != &integer_objtype)
 		return(throwtypeerror(a));
 	if(a->value.i<0 || a->value.i>UCHAR_MAX)
 		return(throwrangecheck(a));
-	result=isdigit((unsigned char)a->value.i);
+	result=isdigit((int)a->value.i);
 	decref(a);
 	return(incref(result?&trueobj:&nilobj));
 }
 
 static obj *isspacep(obj *a) {
-	long result;
+	int result;
 
 	if(a->type != &integer_objtype)
 		return(throwtypeerror(a));
 	if(a->value.i<0 || a->value.i>UCHAR_MAX)
 		return(throwrangecheck(a));
-	result=isspace((unsigned char)a->value.i);
+	result=isspace((int)a->value.i);
 	decref(a);
 	return(incref(result?&trueobj:&nilobj));
 }
@@ -202,6 +208,9 @@
 	if(o) {
 		o->value.func.args=args;
 		o->value.func.prog=prog;
+	} else {
+		decref(args);
+		decref(prog);
 	}
 	return(o);
 }
@@ -218,14 +227,18 @@
 		if(!real_eqv(exception,nextloop))
 			break;
 		decref(exception);
+		exception=incref(&nilobj);
 		decref(exceptionvalue);
+		exceptionvalue=incref(&nilobj);
 	}
 	decref(o);
 	decscoperef(s);
 	if(real_eqv(exception,exitloop)) {
-		o=exceptionvalue;
 		decref(exception);
-		return(o);
+		exception=incref(&nilobj);
+		p=exceptionvalue;
+		exceptionvalue=incref(&nilobj);
+		return(p);
 	}
 	return(0);
 }
@@ -236,15 +249,16 @@
 
 	s=newscope(s);
 	if(!s)
-		goto fail_nostart;
+		goto fail_noscope;
 	length=0;
 	for(new=list;&cons_objtype==new->type;new=new->value.c.d)
 		length++;
 	if(!length) {
-		tmp=define_local(incscoperef(s),incref(mapvar),list);
+		tmp=define_local(incscoperef(s),incref(mapvar),incref(list));
 		if(!tmp)
-			goto fail_nolist;
+			goto fail_nostart;
 		decref(tmp);
+		decref(list);
 		return(evaluate(s,expr));
 	}
 	start=newlist(length);
@@ -285,15 +299,16 @@
 fail:
 	decref(start);
 fail_nostart:
-	decref(list);
-fail_nolist:
-	decref(expr);
 	decscoperef(s);
+fail_noscope:
+	decref(expr);
+	decref(list);
 	return(0);
 }
 
 static obj *mul(obj *a,obj *b) {
 	long result;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -307,10 +322,10 @@
 	result=a->value.i*b->value.i;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a)
-		a->value.i=result;
-	return(a);
+	r=newobj(&integer_objtype);
+	if(r)
+		r->value.i=result;
+	return(r);
 }
 
 #define NUMCMP_LT 1
@@ -369,6 +384,7 @@
 static obj *sub(obj *a,obj *b) {
 	long result;
 	int overflow=0;
+	obj *r;
 
 	if(a->type != &integer_objtype) {
 		decref(b);
@@ -383,13 +399,13 @@
 		overflow=1;
 	decref(a);
 	decref(b);
-	a=newobj(&integer_objtype);
-	if(a) {
-		a->value.i=result;
+	r=newobj(&integer_objtype);
+	if(r) {
+		r->value.i=result;
 		if(overflow)
-			return(throw(overflowerror,a));
+			return(throw(overflowerror,r));
 	}
-	return(a);
+	return(r);
 }
 
 static obj *tostring(obj *o) {
@@ -397,14 +413,11 @@
 }
 
 static obj *subscope(scope *s,obj *o) {
-	scope *t;
-
-	t=newscope(s);
-	if(!t) {
-		decref(o);
-		return(throwoom());
-	}
-	return(evaluate(t,o));
+	s=newscope(s);
+	if(s)
+		return(evaluate(s,o));
+	decref(o);
+	return(0);
 }
 
 int builtin_init() {
--- old/cons.c	Sun Jul 10 21:05:37 2005
+++ cons.c	Thu Jul 14 23:17:59 2005
@@ -1,4 +1,4 @@
-/* cons.c   by Michael Thorpe   2005-07-10 */
+/* cons.c   by Michael Thorpe   2005-07-14 */
 
 #include <stdlib.h>
 #include <string.h>
@@ -57,7 +57,7 @@
 
 	for(i=0,tmp=in;tmp->type==&cons_objtype;tmp=tmp->value.c.d)
 		i++;
-	a=(obj **)malloc((i+1)*sizeof(char *));
+	a=(obj **)malloc((i+1)*sizeof(obj *));
 	if(!a) {
 		decref(in);
 		return(0);
--- old/reader.c	Tue Jul 12 14:14:51 2005
+++ reader.c	Fri Jul 15 18:40:40 2005
@@ -1,13 +1,10 @@
-/* reader.c   by Michael Thorpe   2005-07-12 */
+/* reader.c   by Michael Thorpe   2005-07-15 */
 
 #include <ctype.h>
 #include <stdlib.h>
 #include "lisp.h"
 
 static obj *close_paren,*dot_word,*list_word,*no_object,*reader_error,*unquote_word;
-
-/* This should be static */
-obj *read_object(obj *stream);
 
 static obj *macro_tick(obj *stream) {
 	obj *o;
--- old/scope.c	Tue Jul 12 14:22:52 2005
+++ scope.c	Fri Jul 15 19:18:11 2005
@@ -1,4 +1,4 @@
-/* scope.c   by Michael Thorpe   2005-07-12 */
+/* scope.c   by Michael Thorpe   2005-07-15 */
 
 #include <stdlib.h>
 #include <string.h>
@@ -116,6 +116,7 @@
 	new=(scope *)malloc(sizeof(scope));
 	if(!new) {
 		decscoperef(parent);
+		throwoom();
 		return(0);
 	}
 #ifdef DEBUG
--- old/stream.c	Wed Jul 13 14:34:01 2005
+++ stream.c	Thu Jul 14 23:26:11 2005
@@ -1,4 +1,4 @@
-/* stream.c   by Michael Thorpe   2005-07-13 */
+/* stream.c   by Michael Thorpe   2005-07-14 */
 
 #include <limits.h>
 #include <stdio.h>
--- old/string.c	Mon Jul 11 11:20:48 2005
+++ string.c	Thu Jul 14 23:20:23 2005
@@ -1,4 +1,4 @@
-/* string.c   by Michael Thorpe   2005-07-11 */
+/* string.c   by Michael Thorpe   2005-07-14 */
 
 #include <limits.h>
 #include <stdlib.h>
@@ -181,6 +181,8 @@
 	o->value.s.len=len;
 	if(data)
 		memcpy(o->value.s.data,data,len);
+	else
+		memset(o->value.s.data,0,len);
 	return(o);
 }
 
--- old/word.c	Mon Jul 11 11:48:36 2005
+++ word.c	Thu Jul 14 23:20:03 2005
@@ -1,4 +1,4 @@
-/* word.c   by Michael Thorpe   2005-07-11 */
+/* word.c   by Michael Thorpe   2005-07-14 */
 
 #include <stdlib.h>
 #include <string.h>
@@ -36,6 +36,8 @@
 	o->value.s.len=len;
 	if(data)
 		memcpy(o->value.s.data,data,len);
+	else
+		memset(o->value.s.data,0,len);
 	return(o);
 }
 
