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

Diff of /stack/stack.h

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

revision 1.8 by masse, Sun Mar 10 09:13:36 2002 UTC revision 1.25 by masse, Fri Aug 8 14:20:49 2003 UTC
# Line 22  Line 22 
22    
23  #define HASHTBLSIZE 2048  #define HASHTBLSIZE 2048
24    
25    #define CAR(X) ((X)->content.c->car)
26    #define CDR(X) ((X)->content.c->cdr)
27    
28    /* printf, sscanf, fgets, fprintf, fopen, perror */
29    #include <stdio.h>
30    /* exit, EXIT_SUCCESS, malloc, free */
31    #include <stdlib.h>
32    /* NULL */
33    #include <stddef.h>
34    /* dlopen, dlsym, dlerror */
35    #include <dlfcn.h>
36    /* strcmp, strcpy, strlen, strcat, strdup */
37    #include <string.h>
38    /* getopt, STDIN_FILENO, STDOUT_FILENO, usleep */
39    #include <unistd.h>
40    /* EX_NOINPUT, EX_USAGE */
41    #include <sysexits.h>
42    /* assert */
43    #include <assert.h>
44    /* waitpid */
45    #include <sys/wait.h>
46    
47    #ifdef __linux__
48    /* mtrace, muntrace */
49    #include <mcheck.h>
50    /* ioctl */
51    #include <sys/ioctl.h>
52    /* KDMKTONE */
53    #include <linux/kd.h>
54    #endif /* __linux__ */
55    
56    
57    
58  /* First, define some types. */  /* First, define some types. */
59    
60    struct cons_struct;
61    struct symbol_struct;
62    struct environment_struct;
63    
64    /* A type for pointers to external functions */
65    typedef void (*funcp)(struct environment_struct*);
66    /* funcp is a pointer to a void function (environment *) */
67    
68  /* A value of some type */  /* A value of some type */
69  typedef struct {  typedef struct {
70    enum {    enum {
71        empty,                      /* The empty list */
72      integer,      integer,
73      tfloat,      tfloat,
74      string,      string,
75      func,                       /* Function pointer */      func,                       /* Function pointer */
76      symb,      symb,                       /* Symbol */
77      list      tcons,                      /* A pair of two values */
78        port                        /* An I/O port */
79    } type:4;                     /* Type of stack element */    } type:4;                     /* Type of stack element */
80    
81    int gc_garb:1;    union {
82    int gc_protect:1;      struct {
83          unsigned int mark:1;      /* Used internally in the GC */
84          unsigned int protect:1;   /* Protect from GC */
85        } flag;
86        unsigned int no_gc:2;       /* Both flags as one integer */
87      } gc;                         /* Garbage collector stuff */
88    
89    union {    union {
90      void *ptr;                  /* Pointer to the content */      void *ptr;                  /* Pointer to the content */
91        struct cons_struct *c;      /* ...or a pointer to a cons cell */
92        struct symbol_struct *sym;  /* ...or a pointer to a symbol */
93        FILE *p;                    /* ...or an I/O stream */
94      int i;                      /* ...or an integer */      int i;                      /* ...or an integer */
95      float f;      float f;                    /* ...or a floating point number */
96        funcp func;                 /* ...or a function pointer */
97        char *string;               /* ...or a string */
98    } content;                    /* Stores a pointer or an integer */    } content;                    /* Stores a pointer or an integer */
99    
100  } value;  } value;
101    
102    /* An item (value) on a stack */
103    typedef struct stackitem_struct
104    {
105      value *item;                 /* The value on the stack */
106                                   /* (This is never NULL) */
107      struct stackitem_struct *next; /* Next item */
108    } stackitem;
109    
110    typedef struct cons_struct {    /* A pair of two values */
111      value *car;
112      value *cdr;
113    } pair;
114    
115  /* A symbol with a name and possible value */  /* A symbol with a name and possible value */
116  /* (These do not need reference counters, they are kept unique by  /* (These do not need reference counters, they are kept unique by
117     hashing.) */     hashing.) */
# Line 58  typedef struct symbol_struct { Line 124  typedef struct symbol_struct {
124  /* A type for a hash table for symbols */  /* A type for a hash table for symbols */
125  typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */  typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */
126    
 /* 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;  
   
127  /* An environment; gives access to the stack and a hash table of  /* An environment; gives access to the stack and a hash table of
128     defined symbols */     defined symbols */
129  typedef struct {  typedef struct {
130    stackitem *gc_ref;    value *head;                  /* Head of the stack */
   int gc_limit, gc_count;  
   
   stackitem *head;              /* Head of the stack */  
131    hashtbl symbols;              /* Hash table of all variable bindings */    hashtbl symbols;              /* Hash table of all variable bindings */
132    int err;                      /* Error flag */    int err;                      /* Error flag */
133    char *in_string;              /* Input pending to be read */    char *in_string;              /* Input pending to be read */
# Line 80  typedef struct { Line 135  typedef struct {
135                                     read from in_string */                                     read from in_string */
136    FILE *inputstream;            /* stdin or a file, most likely */    FILE *inputstream;            /* stdin or a file, most likely */
137    int interactive;              /* print prompts, stack, etc */    int interactive;              /* print prompts, stack, etc */
138    
139      /* Garbage Collector stuff*/
140      stackitem *gc_ref;            /* Stack of all allocated values */
141      int gc_limit;                 /* Run GC when this much is allocated */
142      int gc_count;                 /* Amount currently allocated */
143  } environment;  } environment;
144    
 /* A type for pointers to external functions */  
 typedef void (*funcp)(environment*); /* funcp is a pointer to a void  
                                          function (environment *) */  
145    
146  void init_env(environment*);  void init_env(environment*);
147  void printerr(const char*);  void printerr(const char*);
# Line 92  extern void toss(environment*); Line 149  extern void toss(environment*);
149  symbol **hash(hashtbl, const char*);  symbol **hash(hashtbl, const char*);
150  value* new_val(environment*);  value* new_val(environment*);
151  void gc_mark(value*);  void gc_mark(value*);
152  void gc_maybe(environment *env);  void gc_maybe(environment*);
153  extern void gc_init(environment*);  extern void gc_init(environment*);
154    void protect(value*);
155    void unprotect(value*);
156  void push_val(environment*, value*);  void push_val(environment*, value*);
157  void push_int(environment*, int);  void push_int(environment*, int);
158  void push_float(environment*, float);  void push_float(environment*, float);
# Line 101  void push_cstring(environment*, const ch Line 160  void push_cstring(environment*, const ch
160  char *mangle_str(const char*);  char *mangle_str(const char*);
161  extern void mangle(environment*);  extern void mangle(environment*);
162  void push_sym(environment*, const char*);  void push_sym(environment*, const char*);
163  extern void nl();  extern void nl(environment*);
164    extern void nlport(environment*);
165  extern void type(environment*);  extern void type(environment*);
166  void print_h(stackitem*, int);  void print_val(environment *, value*, int, stackitem*, FILE*);
167  extern void print_(environment*);  extern void print_(environment*);
168  extern void print(environment*);  extern void print(environment*);
169  extern void princ_(environment*);  extern void princ_(environment*);
170  extern void princ(environment*);  extern void princ(environment*);
171  void print_st(stackitem*, long);  extern void printport_(environment*);
172    extern void printport(environment*);
173    extern void princport_(environment*);
174    extern void princport(environment*);
175    void print_st(environment*, value*, long);
176  extern void printstack(environment*);  extern void printstack(environment*);
177  extern void swap(environment*);  extern void swap(environment*);
178  extern void rot(environment*);  extern void rot(environment*);
# Line 130  extern void errn(environment*); Line 194  extern void errn(environment*);
194  extern void sx_2b(environment*);  extern void sx_2b(environment*);
195  extern void sx_2d(environment*);  extern void sx_2d(environment*);
196  extern void sx_3e(environment*);  extern void sx_3e(environment*);
197    extern void sx_3c(environment*);
198    extern void sx_3c3d(environment*);
199    extern void sx_3e3d(environment*);
200  value *copy_val(environment*, value*);  value *copy_val(environment*, value*);
201  extern void sx_647570(environment*);  extern void sx_647570(environment*);
202  extern void sx_6966(environment*);  extern void sx_6966(environment*);
203  extern void ifelse(environment*);  extern void ifelse(environment*);
204    extern void sx_656c7365(environment*);
205    extern void then(environment*);
206  extern void sx_7768696c65(environment*);  extern void sx_7768696c65(environment*);
207  extern void sx_666f72(environment*);  extern void sx_666f72(environment*);
208    extern void foreach(environment*);
209  extern void to(environment*);  extern void to(environment*);
210  extern void readline(environment*);  extern void readline(environment*);
211    extern void readlineport(environment*);
212    void readlinestream(environment*, FILE*);
213  extern void sx_72656164(environment*);  extern void sx_72656164(environment*);
214  extern void foreach(environment*);  extern void readport(environment*);
215  void protect(value*);  void readstream(environment*, FILE*);
216  void unprotect(value*);  extern void beep(environment*);
217    extern void sx_77616974(environment*);
218  extern void copying(environment*);  extern void copying(environment*);
219  extern void warranty(environment*);  extern void warranty(environment*);
220  extern void sx_2a(environment*);  extern void sx_2a(environment*);
221  extern void sx_2f(environment*);  extern void sx_2f(environment*);
222  extern void mod(environment*);  extern void mod(environment*);
 extern void sx_3c(environment*);  
 extern void sx_3c3d(environment*);  
 extern void sx_3e3d(environment*);  
223  extern void sx_646976(environment*);  extern void sx_646976(environment*);
224    extern void setcar(environment*);
225    extern void setcdr(environment*);
226    extern void car(environment*);
227    extern void cdr(environment*);
228    extern void cons(environment*);
229    extern void assq(environment*);
230    void assocgen(environment*, funcp);
231    extern void sx_646f(environment *);
232    extern void sx_6f70656e(environment*);
233    extern void sx_636c6f7365(environment*);

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

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26