--- stack/stack.c 2002/03/17 02:15:01 1.114 +++ stack/stack.c 2002/03/17 12:49:27 1.116 @@ -1,3 +1,4 @@ +/* -*- coding: utf-8; -*- */ /* stack - an interactive interpreter for a stack-based language Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn @@ -165,7 +166,6 @@ extern void gc_init(environment *env) { stackitem *new_head= NULL, *titem; - cons *iterator; symbol *tsymb; int i; @@ -195,8 +195,21 @@ if(!(env->gc_ref->item->gc.no_gc)){ /* neither mark nor protect */ - if(env->gc_ref->item->type==string) /* Remove content */ + /* Remove content */ + switch(env->gc_ref->item->type){ + case string: free(env->gc_ref->item->content.ptr); + break; + case tcons: + free(env->gc_ref->item->content.c); + break; + case empty: + case integer: + case tfloat: + case func: + case symb: + /* Symbol strings are freed when walking the hash table */ + } free(env->gc_ref->item); /* Remove from gc_ref */ titem= env->gc_ref->next; @@ -285,8 +298,9 @@ { value *new_value= new_val(env); - new_value->content.c= malloc(sizeof(cons)); + new_value->content.c= malloc(sizeof(pair)); assert(new_value->content.c!=NULL); + env->gc_count += sizeof(pair); new_value->type= tcons; CAR(new_value)= val; CDR(new_value)= env->head; @@ -720,7 +734,10 @@ unprotect(temp_val); return; - default: + case empty: + case integer: + case tfloat: + case string: return; } } @@ -1049,7 +1066,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.114 $\n\ + printf("Stack version $Revision: 1.116 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ Stack comes with ABSOLUTELY NO WARRANTY; for details type 'warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\ @@ -1324,6 +1341,7 @@ case integer: case func: case symb: + case empty: new_value->content= old_value->content; break; case string: @@ -1332,8 +1350,9 @@ break; case tcons: - new_value->content.c= malloc(sizeof(cons)); + new_value->content.c= malloc(sizeof(pair)); assert(new_value->content.c!=NULL); + env->gc_count += sizeof(pair); CAR(new_value)= copy_val(env, CAR(old_value)); /* recurse */ CDR(new_value)= copy_val(env, CDR(old_value)); /* recurse */ @@ -1691,7 +1710,7 @@ int count= -1; float ftemp; static int depth= 0; - char *match, *ctemp; + char *match; size_t inlength; if(env->in_string==NULL) { @@ -2353,3 +2372,31 @@ CAR(env->head)=CDR(CAR(env->head)); } + +extern void cons(environment *env) +{ + value *val; + + if(env->head->type==empty || CDR(env->head)->type==empty) { + printerr("Too Few Arguments"); + env->err= 1; + return; + } + + val=new_val(env); + val->content.c= malloc(sizeof(pair)); + assert(val->content.c!=NULL); + + env->gc_count += sizeof(pair); + val->type=tcons; + + CAR(val)= CAR(CDR(env->head)); + CDR(val)= CAR(env->head); + + push_val(env, val); + + swap(env); if(env->err) return; + toss(env); if(env->err) return; + swap(env); if(env->err) return; + toss(env); if(env->err) return; +}