--- stack/stack.c 2003/08/04 11:57:33 1.127 +++ stack/stack.c 2003/08/05 09:09:51 1.131 @@ -153,7 +153,7 @@ /* Remove content */ switch(env->gc_ref->item->type){ case string: - free(env->gc_ref->item->content.ptr); + free(env->gc_ref->item->content.string); break; case tcons: free(env->gc_ref->item->content.c); @@ -185,7 +185,7 @@ printf(" integer: %d", env->gc_ref->item->content.i); break; case func: - printf(" func: %p", env->gc_ref->item->content.ptr); + printf(" func: %p", env->gc_ref->item->content.func); break; case symb: printf(" symb: %s", env->gc_ref->item->content.sym->id); @@ -203,7 +203,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)+1; + env->gc_count += strlen(env->gc_ref->item->content.string)+1; titem= env->gc_ref->next; env->gc_ref->next= new_head; @@ -300,10 +300,10 @@ value *new_value= new_val(env); int length= strlen(in_string)+1; - new_value->content.ptr= malloc(length); + new_value->content.string= malloc(length); assert(new_value != NULL); env->gc_count += length; - strcpy(new_value->content.ptr, in_string); + strcpy(new_value->content.string, in_string); new_value->type= string; push_val(env, new_value); @@ -330,31 +330,6 @@ return new_string; /* The caller must free() it */ } -extern void mangle(environment *env) -{ - char *new_string; - - if(env->head->type==empty) { - printerr("Too Few Arguments"); - env->err= 1; - return; - } - - if(CAR(env->head)->type!=string) { - printerr("Bad Argument Type"); - env->err= 2; - return; - } - - new_string= - mangle_str((const char *)(CAR(env->head)->content.ptr)); - - toss(env); - if(env->err) return; - - push_cstring(env, new_string); -} - /* Push a symbol onto the stack. */ void push_sym(environment *env, const char *in_string) { @@ -380,7 +355,7 @@ /* Look up the symbol name in the hash table */ new_symbol= hash(env->symbols, in_string); - new_value->content.ptr= *new_symbol; + new_value->content.sym= *new_symbol; if(*new_symbol==NULL) { /* If symbol was undefined */ @@ -394,7 +369,7 @@ strcpy((*new_symbol)->id, in_string); /* Intern the new symbol in the hash table */ - new_value->content.ptr= *new_symbol; + new_value->content.sym= *new_symbol; /* Try to load the symbol name as an external function, to see if we should bind the symbol to a new function pointer value */ @@ -412,7 +387,7 @@ if(dlerr==NULL) { /* If a function was found */ new_fvalue->type= func; /* The new value is a function pointer */ - new_fvalue->content.ptr= funcptr; /* Store function pointer */ + new_fvalue->content.func= funcptr; /* Store function pointer */ (*new_symbol)->val= new_fvalue; /* Bind the symbol to the new function value */ } @@ -454,13 +429,13 @@ break; case string: if(noquote){ - if(fprintf(stream, "%s", (char*)(val->content.ptr)) < 0){ + if(fprintf(stream, "%s", val->content.string) < 0){ perror("print_val"); env->err= 5; return; } } else { /* quote */ - if(fprintf(stream, "\"%s\"", (char*)(val->content.ptr)) < 0){ + if(fprintf(stream, "\"%s\"", val->content.string) < 0){ perror("print_val"); env->err= 5; return; @@ -475,14 +450,14 @@ } break; case func: - if(fprintf(stream, "#", (funcp)(val->content.ptr)) < 0){ + if(fprintf(stream, "#", val->content.func) < 0){ perror("print_val"); env->err= 5; return; } break; case port: - if(fprintf(stream, "#", (funcp)(val->content.p)) < 0){ + if(fprintf(stream, "#", val->content.p) < 0){ perror("print_val"); env->err= 5; return; @@ -653,7 +628,7 @@ /* If it's a lone function value, run it */ case func: - in_func= (funcp)(CAR(env->head)->content.ptr); + in_func= CAR(env->head)->content.func; toss(env); if(env->err) return; return in_func(env); @@ -823,7 +798,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.127 $\n\ + printf("Stack version $Revision: 1.131 $\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\ @@ -881,8 +856,7 @@ new_value->content= old_value->content; break; case string: - (char *)(new_value->content.ptr)= - strdup((char *)(old_value->content.ptr)); + new_value->content.string= strdup(old_value->content.string); break; case tcons: @@ -1006,15 +980,15 @@ readlinestream(env, env->inputstream); if(env->err) return; - if(((char *)(CAR(env->head)->content.ptr))[0]=='\0'){ + if((CAR(env->head)->content.string)[0]=='\0'){ env->err= 4; /* "" means EOF */ return; } - env->in_string= malloc(strlen(CAR(env->head)->content.ptr)+1); + env->in_string= malloc(strlen(CAR(env->head)->content.string)+1); assert(env->in_string != NULL); env->free_string= env->in_string; /* Save the original pointer */ - strcpy(env->in_string, CAR(env->head)->content.ptr); + strcpy(env->in_string, CAR(env->head)->content.string); toss(env); if(env->err) return; } @@ -1352,76 +1326,6 @@ POSSIBILITY OF SUCH DAMAGES.\n"); } -/* General assoc function */ -void assocgen(environment *env, funcp eqfunc) -{ - value *key, *item; - - /* Needs two values on the stack, the top one must be an association - list */ - if(env->head->type==empty || CDR(env->head)->type==empty) { - printerr("Too Few Arguments"); - env->err= 1; - return; - } - - if(CAR(env->head)->type!=tcons) { - printerr("Bad Argument Type"); - env->err= 2; - return; - } - - key=CAR(CDR(env->head)); - item=CAR(env->head); - - while(item->type == tcons){ - if(CAR(item)->type != tcons){ - printerr("Bad Argument Type"); - env->err= 2; - return; - } - push_val(env, key); - push_val(env, CAR(CAR(item))); - eqfunc(env); if(env->err) return; - - /* Check the result of 'eqfunc' */ - if(env->head->type==empty) { - printerr("Too Few Arguments"); - env->err= 1; - return; - } - if(CAR(env->head)->type!=integer) { - printerr("Bad Argument Type"); - env->err= 2; - return; - } - - if(CAR(env->head)->content.i){ - toss(env); if(env->err) return; - break; - } - toss(env); if(env->err) return; - - if(item->type!=tcons) { - printerr("Bad Argument Type"); - env->err= 2; - return; - } - - item=CDR(item); - } - - if(item->type == tcons){ /* A match was found */ - push_val(env, CAR(item)); - } else { - push_int(env, 0); - } - swap(env); if(env->err) return; - toss(env); if(env->err) return; - swap(env); if(env->err) return; - toss(env); -} - /* Discard the top element of the stack. */ extern void toss(environment *env) {