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

Diff of /stack/stack.c

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

revision 1.73 by masse, Tue Feb 12 23:16:56 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. */
# Line 606  extern void pack(environment *env) Line 591  extern void pack(environment *env)
591    pack->content.ptr= temp;    pack->content.ptr= temp;
592    pack->refcount= 1;    pack->refcount= 1;
593    
594    temp= malloc(sizeof(stackitem));    push_val(env, pack);
   temp->item= pack;  
   
   push(env, temp);  
595    rev(env);    rev(env);
596  }  }
597    
# Line 1144  extern void sx_666f72(environment *env) Line 1126  extern void sx_666f72(environment *env)
1126  /* 'to' */  /* 'to' */
1127  extern void to(environment *env) {  extern void to(environment *env) {
1128    int i, start, ending;    int i, start, ending;
1129      stackitem *temp_head;
1130      value *temp_val;
1131        
1132    if((env->head)==NULL || env->head->next==NULL) {    if((env->head)==NULL || env->head->next==NULL) {
1133      printerr("Too Few Arguments");      printerr("Too Few Arguments");
# Line 1163  extern void to(environment *env) { Line 1147  extern void to(environment *env) {
1147    start= env->head->item->content.val;    start= env->head->item->content.val;
1148    toss(env); if(env->err) return;    toss(env); if(env->err) return;
1149    
1150    push_sym(env, "[");    temp_head= env->head;
1151      env->head= NULL;
1152    
1153    if(ending>=start) {    if(ending>=start) {
1154      for(i= start; i<=ending; i++)      for(i= ending; i>=start; i--)
1155        push_int(env, i);        push_int(env, i);
1156    } else {    } else {
1157      for(i= start; i>=ending; i--)      for(i= ending; i<=start; i++)
1158        push_int(env, i);        push_int(env, i);
1159    }    }
1160    
1161    pack(env); if(env->err) return;    temp_val= malloc(sizeof(value));
1162      temp_val->content.ptr= env->head;
1163      temp_val->refcount= 1;
1164      temp_val->type= list;
1165      env->head= temp_head;
1166      push_val(env, temp_val);
1167  }  }
1168    
1169  /* Read a string */  /* Read a string */

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

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26