/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.74 by masse, Tue Feb 12 23:59:05 2002 UTC revision 1.75 by masse, Wed Feb 13 00:16:00 2002 UTC
# Line 155  symbol **hash(hashtbl in_hashtbl, const Line 155  symbol **hash(hashtbl in_hashtbl, const
155    }    }
156  }  }
157    
 /* Generic push function. */  
 void push(environment *env, stackitem* in_item)  
 {  
   in_item->next= env->head;  
   env->head= in_item;  
 }  
   
158  /* Push a value onto the stack */  /* Push a value onto the stack */
159  void push_val(environment *env, value *val)  void push_val(environment *env, value *val)
160  {  {
161    stackitem *new_item= malloc(sizeof(stackitem));    stackitem *new_item= malloc(sizeof(stackitem));
162    new_item->item= val;    new_item->item= val;
163    val->refcount++;    val->refcount++;
164    push(env, new_item);    new_item->next= env->head;
165      env->head= new_item;
166  }  }
167    
168  /* Push an integer onto the stack. */  /* Push an integer onto the stack. */
169  void push_int(environment *env, int in_val)  void push_int(environment *env, int in_val)
170  {  {
171    value *new_value= malloc(sizeof(value));    value *new_value= malloc(sizeof(value));
   stackitem *new_item= malloc(sizeof(stackitem));  
   new_item->item= new_value;  
172        
173    new_value->content.val= in_val;    new_value->content.val= in_val;
174    new_value->type= integer;    new_value->type= integer;
175    new_value->refcount=1;    new_value->refcount=1;
176    
177    push(env, new_item);    push_val(env, new_value);
178  }  }
179    
180  /* Copy a string onto the stack. */  /* Copy a string onto the stack. */
181  void push_cstring(environment *env, const char *in_string)  void push_cstring(environment *env, const char *in_string)
182  {  {
183    value *new_value= malloc(sizeof(value));    value *new_value= malloc(sizeof(value));
   stackitem *new_item= malloc(sizeof(stackitem));  
   new_item->item=new_value;  
184    
185    new_value->content.ptr= malloc(strlen(in_string)+1);    new_value->content.ptr= malloc(strlen(in_string)+1);
186    strcpy(new_value->content.ptr, in_string);    strcpy(new_value->content.ptr, in_string);
187    new_value->type= string;    new_value->type= string;
188    new_value->refcount=1;    new_value->refcount=1;
189    
190    push(env, new_item);    push_val(env, new_value);
191  }  }
192    
193  /* Mangle a symbol name to a valid C identifier name */  /* Mangle a symbol name to a valid C identifier name */
# Line 252  extern void mangle(environment *env){ Line 242  extern void mangle(environment *env){
242  /* Push a symbol onto the stack. */  /* Push a symbol onto the stack. */
243  void push_sym(environment *env, const char *in_string)  void push_sym(environment *env, const char *in_string)
244  {  {
   stackitem *new_item;          /* The new stack item */  
   /* ...which will contain... */  
245    value *new_value;             /* A new symbol value */    value *new_value;             /* A new symbol value */
246    /* ...which might point to... */    /* ...which might point to... */
247    symbol **new_symbol;          /* (if needed) A new actual symbol */    symbol **new_symbol;          /* (if needed) A new actual symbol */
# Line 266  void push_sym(environment *env, const ch Line 254  void push_sym(environment *env, const ch
254    const char *dlerr;            /* Dynamic linker error */    const char *dlerr;            /* Dynamic linker error */
255    char *mangled;                /* Mangled function name */    char *mangled;                /* Mangled function name */
256    
   /* Create a new stack item containing a new value */  
   new_item= malloc(sizeof(stackitem));  
257    new_value= malloc(sizeof(value));    new_value= malloc(sizeof(value));
   new_item->item=new_value;  
258    
259    /* The new value is a symbol */    /* The new value is a symbol */
260    new_value->type= symb;    new_value->type= symb;
# Line 313  void push_sym(environment *env, const ch Line 298  void push_sym(environment *env, const ch
298        new_fvalue->refcount= 1;        new_fvalue->refcount= 1;
299      }      }
300    }    }
301    push(env, new_item);    push_val(env, new_value);
302  }  }
303    
304  /* Print newline. */  /* Print newline. */

Legend:
Removed from v.1.74  
changed lines
  Added in v.1.75

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26