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

Diff of /stack/stack.c

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

revision 1.87 by masse, Fri Feb 15 18:27:18 2002 UTC revision 1.88 by teddy, Sat Feb 16 00:51:32 2002 UTC
# Line 15  Line 15 
15  /* mtrace, muntrace */  /* mtrace, muntrace */
16  #include <mcheck.h>  #include <mcheck.h>
17    
18  #define HASHTBLSIZE 2048  #include "stack.h"
   
 /* First, define some types. */  
   
 /* A value of some type */  
 typedef struct {  
   enum {  
     integer,  
     string,  
     func,                       /* Function pointer */  
     symb,  
     list  
   } type;                       /* Type of stack element */  
   
   union {  
     void *ptr;                  /* Pointer to the content */  
     int val;                    /* ...or an integer */  
   } content;                    /* Stores a pointer or an integer */  
   
   int gc_garb;  
   
 } value;  
   
 /* A symbol with a name and possible value */  
 /* (These do not need reference counters, they are kept unique by  
    hashing.) */  
 typedef struct symbol_struct {  
   char *id;                     /* Symbol name */  
   value *val;                   /* The value (if any) bound to it */  
   struct symbol_struct *next;   /* In case of hashing conflicts, a */  
 } symbol;                       /* symbol is a kind of stack item. */  
   
 /* A type for a hash table for symbols */  
 typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */  
   
 /* An item (value) on a stack */  
 typedef struct stackitem_struct  
 {  
   value *item;                  /* The value on the stack */  
                                 /* (This is never NULL) */  
   struct stackitem_struct *next; /* Next item */  
 } stackitem;  
   
 /* An environment; gives access to the stack and a hash table of  
    defined symbols */  
 typedef struct {  
   stackitem *gc_ref;  
   int gc_limit, gc_count;  
   
   stackitem *head;              /* Head of the stack */  
   hashtbl symbols;              /* Hash table of all variable bindings */  
   int err;                      /* Error flag */  
   char *in_string;              /* Input pending to be read */  
   char *free_string;            /* Free this string when all input is  
                                    read from in_string */  
   FILE *inputstream;            /* stdin or a file, most likely */  
   int interactive;              /* print prompts, stack, etc */  
 } environment;  
   
 /* A type for pointers to external functions */  
 typedef void (*funcp)(environment *); /* funcp is a pointer to a void  
                                          function (environment *) */  
19    
20  /* Initialize a newly created environment */  /* Initialize a newly created environment */
21  void init_env(environment *env)  void init_env(environment *env)
# Line 144  symbol **hash(hashtbl in_hashtbl, const Line 83  symbol **hash(hashtbl in_hashtbl, const
83    }    }
84  }  }
85    
 extern void gc_init(environment*);  
   
86  value* new_val(environment *env) {  value* new_val(environment *env) {
87    value *nval= malloc(sizeof(value));    value *nval= malloc(sizeof(value));
88    stackitem *nitem= malloc(sizeof(stackitem));    stackitem *nitem= malloc(sizeof(stackitem));
# Line 808  extern void def(environment *env) Line 745  extern void def(environment *env)
745    toss(env); toss(env);    toss(env); toss(env);
746  }  }
747    
 extern void clear(environment *);  
 void forget_sym(symbol **);  
   
748  /* Quit stack. */  /* Quit stack. */
749  extern void quit(environment *env)  extern void quit(environment *env)
750  {  {
# Line 898  extern void errn(environment *env){ Line 832  extern void errn(environment *env){
832    push_int(env, env->err);    push_int(env, env->err);
833  }  }
834    
 extern void sx_72656164(environment*);  
   
835  int main(int argc, char **argv)  int main(int argc, char **argv)
836  {  {
837    environment myenv;    environment myenv;

Legend:
Removed from v.1.87  
changed lines
  Added in v.1.88

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26