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

Diff of /stack/stack.c

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

revision 1.36 by teddy, Wed Feb 6 00:52:31 2002 UTC revision 1.38 by teddy, Wed Feb 6 11:15:05 2002 UTC
# Line 218  void free_val(value *val){ Line 218  void free_val(value *val){
218      switch (val->type){         /* and free the contents if necessary */      switch (val->type){         /* and free the contents if necessary */
219      case string:      case string:
220        free(val->content.ptr);        free(val->content.ptr);
221          break;
222      case list:                  /* lists needs to be freed recursively */      case list:                  /* lists needs to be freed recursively */
223        item=val->content.ptr;        item=val->content.ptr;
224        while(item != NULL) {     /* for all stack items */        while(item != NULL) {     /* for all stack items */
# Line 256  extern void nl() Line 257  extern void nl()
257    printf("\n");    printf("\n");
258  }  }
259    
260    /* Gets the type of a value */
261    extern void type(environment *env){
262      int typenum;
263    
264      if((env->head)==NULL) {
265        printerr("Too Few Arguments");
266        env->err=1;
267        return;
268      }
269      typenum=env->head->item->type;
270      toss(env);
271      switch(typenum){
272      case integer:
273        push_sym(env, "integer");
274        break;
275      case string:
276        push_sym(env, "string");
277        break;
278      case symb:
279        push_sym(env, "symbol");
280        break;
281      case func:
282        push_sym(env, "function");
283        break;
284      case list:
285        push_sym(env, "list");
286        break;
287      default:
288        push_sym(env, "unknown");
289        break;
290      }
291    }    
292    
293  /* Prints the top element of the stack. */  /* Prints the top element of the stack. */
294  void print_h(stackitem *stack_head)  void print_h(stackitem *stack_head)
295  {  {
# Line 273  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 314  void print_st(stackitem *stack_head, lon Line 356  void print_st(stackitem *stack_head, lon
356  extern void printstack(environment *env)  extern void printstack(environment *env)
357  {  {
358    if(env->head == NULL) {    if(env->head == NULL) {
     printerr("Too Few Arguments");  
     env->err=1;  
359      return;      return;
360    }    }
361    print_st(env->head, 1);    print_st(env->head, 1);
# Line 457  extern void pack(environment *env) Line 497  extern void pack(environment *env)
497  }  }
498    
499  /* Parse input. */  /* Parse input. */
500  int stack_read(environment *env, char *in_line)  void stack_read(environment *env, char *in_line)
501  {  {
502    char *temp, *rest;    char *temp, *rest;
503    int itemp;    int itemp;
# Line 518  int stack_read(environment *env, char *i Line 558  int stack_read(environment *env, char *i
558      }      }
559    } while(0);    } while(0);
560    
   
561    free(temp);    free(temp);
562    
563    if(convert<2) {    if(convert<2) {
564      free(rest);      free(rest);
565      return 0;      return;
566    }    }
567        
568    stack_read(env, rest);    stack_read(env, rest);
569        
570    free(rest);    free(rest);
   return 1;  
571  }  }
572    
573  /* Relocate elements of the list on the stack. */  /* Relocate elements of the list on the stack. */

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.38

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26