--- stack/stack.c 2002/03/17 00:55:58 1.113 +++ stack/stack.c 2002/03/17 11:26:35 1.115 @@ -165,7 +165,7 @@ extern void gc_init(environment *env) { stackitem *new_head= NULL, *titem; - cons *iterator; + pair *iterator; symbol *tsymb; int i; @@ -233,7 +233,7 @@ /* Keep values */ env->gc_count += sizeof(value); if(env->gc_ref->item->type==string) - env->gc_count += strlen(env->gc_ref->item->content.ptr); + env->gc_count += strlen(env->gc_ref->item->content.ptr)+1; titem= env->gc_ref->next; env->gc_ref->next= new_head; @@ -285,7 +285,7 @@ { 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); new_value->type= tcons; CAR(new_value)= val; @@ -484,7 +484,7 @@ toss(env); } -/* Prints the top element of the stack. */ +/* Print a value */ void print_val(value *val, int noquote) { switch(val->type) { @@ -513,7 +513,8 @@ printf("[ "); do { print_val(CAR(val), noquote); - switch(CDR(val)->type){ + val= CDR(val); + switch(val->type){ case empty: break; case tcons: @@ -521,9 +522,8 @@ break; default: printf(" . "); /* Improper list */ - print_val(CDR(val), noquote); + print_val(val, noquote); } - val= CDR(val); } while(val->type == tcons); printf(" ]"); break; @@ -1049,7 +1049,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.113 $\n\ + printf("Stack version $Revision: 1.115 $\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\ @@ -1332,7 +1332,7 @@ break; case tcons: - new_value->content.c= malloc(sizeof(cons)); + new_value->content.c= malloc(sizeof(pair)); assert(new_value->content.c!=NULL); CAR(new_value)= copy_val(env, CAR(old_value)); /* recurse */ @@ -1725,6 +1725,9 @@ } else { push_float(env, ftemp); } + } else if(sscanf(env->in_string, "\"\"%n", &readlength) != EOF + && readlength != -1) { + push_cstring(env, ""); } else if(sscanf(env->in_string, strform, match, &readlength) != EOF && readlength != -1) { push_cstring(env, match); @@ -2350,3 +2353,29 @@ 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); + 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; +}