--- stack/stack.c 2002/02/12 23:59:05 1.74 +++ stack/stack.c 2002/02/13 00:16:00 1.75 @@ -155,49 +155,39 @@ } } -/* Generic push function. */ -void push(environment *env, stackitem* in_item) -{ - in_item->next= env->head; - env->head= in_item; -} - /* Push a value onto the stack */ void push_val(environment *env, value *val) { stackitem *new_item= malloc(sizeof(stackitem)); new_item->item= val; val->refcount++; - push(env, new_item); + new_item->next= env->head; + env->head= new_item; } /* Push an integer onto the stack. */ void push_int(environment *env, int in_val) { value *new_value= malloc(sizeof(value)); - stackitem *new_item= malloc(sizeof(stackitem)); - new_item->item= new_value; new_value->content.val= in_val; new_value->type= integer; new_value->refcount=1; - push(env, new_item); + push_val(env, new_value); } /* Copy a string onto the stack. */ void push_cstring(environment *env, const char *in_string) { value *new_value= malloc(sizeof(value)); - stackitem *new_item= malloc(sizeof(stackitem)); - new_item->item=new_value; new_value->content.ptr= malloc(strlen(in_string)+1); strcpy(new_value->content.ptr, in_string); new_value->type= string; new_value->refcount=1; - push(env, new_item); + push_val(env, new_value); } /* Mangle a symbol name to a valid C identifier name */ @@ -252,8 +242,6 @@ /* Push a symbol onto the stack. */ void push_sym(environment *env, const char *in_string) { - stackitem *new_item; /* The new stack item */ - /* ...which will contain... */ value *new_value; /* A new symbol value */ /* ...which might point to... */ symbol **new_symbol; /* (if needed) A new actual symbol */ @@ -266,10 +254,7 @@ const char *dlerr; /* Dynamic linker error */ char *mangled; /* Mangled function name */ - /* Create a new stack item containing a new value */ - new_item= malloc(sizeof(stackitem)); new_value= malloc(sizeof(value)); - new_item->item=new_value; /* The new value is a symbol */ new_value->type= symb; @@ -313,7 +298,7 @@ new_fvalue->refcount= 1; } } - push(env, new_item); + push_val(env, new_value); } /* Print newline. */