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

Diff of /stack/stack.c

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

revision 1.25 by masse, Sat Feb 2 20:06:11 2002 UTC revision 1.26 by masse, Sat Feb 2 20:49:34 2002 UTC
# Line 205  extern void print_(stackitem** stack_hea Line 205  extern void print_(stackitem** stack_hea
205      return;      return;
206    }    }
207    
208    while(temp->type==ref)    while(temp->type==ref) {
209      temp= temp->content.ptr;      temp= temp->content.ptr;
210    
211        if(temp->type!=ref) {
212          printf("ref-> %s", temp->id);
213          return;
214        }
215      }
216    
217    switch(temp->type) {    switch(temp->type) {
218    case value:    case value:
219      printf("%d", temp->content.val);      printf("%d", temp->content.val);
# Line 254  extern void printstack(stackitem** stack Line 260  extern void printstack(stackitem** stack
260    }    }
261  }  }
262    
263    /* Swap the two top elements on the stack. */
264    extern void swap(stackitem** stack_head)
265    {
266      stackitem* temp= (*stack_head);
267      
268      if((*stack_head)==NULL) {
269        printerr("Stack empty");
270        return;
271      }
272    
273      if((*stack_head)->next==NULL)
274        return;
275    
276      *stack_head= (*stack_head)->next;
277      temp->next= (*stack_head)->next;
278      (*stack_head)->next= temp;
279    }
280    
281    stackitem* copy(stackitem* in_item)
282    {
283      stackitem* out_item= malloc(sizeof(stackitem));
284    
285      memcpy(out_item, in_item, sizeof(stackitem));
286      out_item->next= NULL;
287    
288      return out_item;
289    }
290    
291    
292  /* If the top element is a reference, determine if it's a reference to a  /* If the top element is a reference, determine if it's a reference to a
293     function, and if it is, toss the reference and execute the function. */     function, and if it is, toss the reference and execute the function. */
294  extern void eval(stackitem** stack_head)  extern void eval(stackitem** stack_head)
# Line 274  extern void eval(stackitem** stack_head) Line 309  extern void eval(stackitem** stack_head)
309      toss(stack_head);      toss(stack_head);
310      (*in_func)(stack_head);      (*in_func)(stack_head);
311      return;      return;
312    }    }
313        
314    printerr("Couldn't evaluate");    push(stack_head, copy(temp));
315      swap(stack_head);
316      toss(stack_head);
317  }  }
318    
319  /* Make a list. */  /* Make a list. */
# Line 418  extern void expand(stackitem** stack_hea Line 455  extern void expand(stackitem** stack_hea
455    *stack_head= new_head;        /* ...and voila! */    *stack_head= new_head;        /* ...and voila! */
456  }  }
457    
 /* Swap the two top elements on the stack. */  
 extern void swap(stackitem** stack_head)  
 {  
   stackitem* temp= (*stack_head);  
     
   if((*stack_head)==NULL) {  
     printerr("Stack empty");  
     return;  
   }  
   
   if((*stack_head)->next==NULL)  
     return;  
   
   *stack_head= (*stack_head)->next;  
   temp->next= (*stack_head)->next;  
   (*stack_head)->next= temp;  
 }  
   
458  /* Compares two elements by reference. */  /* Compares two elements by reference. */
459  extern void eq(stackitem** stack_head)  extern void eq(stackitem** stack_head)
460  {  {

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26