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

Diff of /stack/stack.c

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

revision 1.37 by teddy, Wed Feb 6 01:51:08 2002 UTC revision 1.40 by teddy, Wed Feb 6 11:44:02 2002 UTC
# Line 307  void print_h(stackitem *stack_head) Line 307  void print_h(stackitem *stack_head)
307      printf("#<function %p>", (funcp)(stack_head->item->content.ptr));      printf("#<function %p>", (funcp)(stack_head->item->content.ptr));
308      break;      break;
309    case list:    case list:
310      printf("#<list %p>", (funcp)(stack_head->item->content.ptr));      /* A list is just a stack, so make stack_head point to it */
311        stack_head=(stackitem *)(stack_head->item->content.ptr);
312        printf("[ ");
313        while(stack_head != NULL) {
314          print_h(stack_head);
315          printf(" ");
316          stack_head=stack_head->next;
317        }
318        printf("]");
319      break;      break;
320    default:    default:
321      printf("#<unknown %p>", (funcp)(stack_head->item->content.ptr));      printf("#<unknown %p>", (stack_head->item->content.ptr));
322      break;      break;
323    }    }
324  }  }
# Line 446  extern void eval(environment *env) Line 454  extern void eval(environment *env)
454    }    }
455  }  }
456    
457    /* Reverse a list */
458    extern void rev(environment *env){
459      stackitem *old_head, *new_head, *item;
460    
461      if((env->head)==NULL) {
462        printerr("Too Few Arguments");
463        env->err=1;
464        return;
465      }
466    
467      if(env->head->item->type!=list) {
468        printerr("Bad Argument Type");
469        env->err=2;
470        return;
471      }
472    
473      old_head=(stackitem *)(env->head->item->content.ptr);
474      new_head=NULL;
475      while(old_head != NULL){
476        item=old_head;
477        old_head=old_head->next;
478        item->next=new_head;
479        new_head=item;
480      }
481      env->head->item->content.ptr=new_head;
482    }
483    
484  /* Make a list. */  /* Make a list. */
485  extern void pack(environment *env)  extern void pack(environment *env)
486  {  {
# Line 486  extern void pack(environment *env) Line 521  extern void pack(environment *env)
521    temp->item= pack;    temp->item= pack;
522    
523    push(&(env->head), temp);    push(&(env->head), temp);
524      rev(env);
525  }  }
526    
527  /* Parse input. */  /* Parse input. */

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.40

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26