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

Diff of /stack/stack.h

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

revision 1.2 by masse, Sun Feb 17 04:03:57 2002 UTC revision 1.24 by masse, Mon Aug 4 14:13:16 2003 UTC
# Line 1  Line 1 
1    /*
2        stack - an interactive interpreter for a stack-based language
3        Copyright (C) 2002  Mats Alritzson and Teddy Hogeborn
4    
5        This program is free software; you can redistribute it and/or modify
6        it under the terms of the GNU General Public License as published by
7        the Free Software Foundation; either version 2 of the License, or
8        (at your option) any later version.
9    
10        This program is distributed in the hope that it will be useful,
11        but WITHOUT ANY WARRANTY; without even the implied warranty of
12        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13        GNU General Public License for more details.
14    
15        You should have received a copy of the GNU General Public License
16        along with this program; if not, write to the Free Software
17        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18    
19        Authors: Mats Alritzson <masse@fukt.bth.se>
20                 Teddy Hogeborn <teddy@fukt.bth.se>
21    */
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    
45    #ifdef __linux__
46    /* mtrace, muntrace */
47    #include <mcheck.h>
48    /* ioctl */
49    #include <sys/ioctl.h>
50    /* KDMKTONE */
51    #include <linux/kd.h>
52    #endif /* __linux__ */
53    
54    
55    
56  /* First, define some types. */  /* First, define some types. */
57    
58    struct cons_struct;
59    struct symbol_struct;
60    struct environment_struct;
61    
62    /* A type for pointers to external functions */
63    typedef void (*funcp)(struct environment_struct*);
64    /* funcp is a pointer to a void function (environment *) */
65    
66  /* A value of some type */  /* A value of some type */
67  typedef struct {  typedef struct {
68    enum {    enum {
69        empty,                      /* The empty list */
70      integer,      integer,
71        tfloat,
72      string,      string,
73      func,                       /* Function pointer */      func,                       /* Function pointer */
74      symb,      symb,                       /* Symbol */
75      list      tcons,                      /* A pair of two values */
76    } type:3;                     /* Type of stack element */      port                        /* An I/O port */
77      } type:4;                     /* Type of stack element */
78    
79    int gc_garb:1;    union {
80        struct {
81          unsigned int mark:1;      /* Used internally in the GC */
82          unsigned int protect:1;   /* Protect from GC */
83        } flag;
84        unsigned int no_gc:2;       /* Both flags as one integer */
85      } gc;                         /* Garbage collector stuff */
86    
87    union {    union {
88      void *ptr;                  /* Pointer to the content */      void *ptr;                  /* Pointer to the content */
89      int val;                    /* ...or an integer */      struct cons_struct *c;      /* ...or a pointer to a cons cell */
90        struct symbol_struct *sym;  /* ...or a pointer to a symbol */
91        FILE *p;                    /* ...or an I/O stream */
92        int i;                      /* ...or an integer */
93        float f;                    /* ...or a floating point number */
94        funcp func;                 /* ...or a function pointer */
95        char *string;               /* ...or a string */
96    } content;                    /* Stores a pointer or an integer */    } content;                    /* Stores a pointer or an integer */
97    
98  } value;  } value;
99    
100    /* An item (value) on a stack */
101    typedef struct stackitem_struct
102    {
103      value *item;                 /* The value on the stack */
104                                   /* (This is never NULL) */
105      struct stackitem_struct *next; /* Next item */
106    } stackitem;
107    
108    typedef struct cons_struct {    /* A pair of two values */
109      value *car;
110      value *cdr;
111    } pair;
112    
113  /* A symbol with a name and possible value */  /* A symbol with a name and possible value */
114  /* (These do not need reference counters, they are kept unique by  /* (These do not need reference counters, they are kept unique by
115     hashing.) */     hashing.) */
# Line 34  typedef struct symbol_struct { Line 122  typedef struct symbol_struct {
122  /* A type for a hash table for symbols */  /* A type for a hash table for symbols */
123  typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */  typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */
124    
 /* 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;  
   
125  /* An environment; gives access to the stack and a hash table of  /* An environment; gives access to the stack and a hash table of
126     defined symbols */     defined symbols */
127  typedef struct {  typedef struct {
128    stackitem *gc_ref;    value *head;                  /* Head of the stack */
   int gc_limit, gc_count;  
   
   stackitem *head;              /* Head of the stack */  
129    hashtbl symbols;              /* Hash table of all variable bindings */    hashtbl symbols;              /* Hash table of all variable bindings */
130    int err;                      /* Error flag */    int err;                      /* Error flag */
131    char *in_string;              /* Input pending to be read */    char *in_string;              /* Input pending to be read */
132    char *free_string;            /* Free this string when all input is    char *free_string;            /* Free this string when all input is
133                                     read from in_string */                                     read from in_string */
134    FILE *inputstream;            /* stdin or a file, most likely */    FILE *inputstream;            /* stdin or a file, most likely */
135    int interactive;              /* print prompts, stack, etc */    int interactive;              /* print prompts, stack, etc */
136    
137      /* Garbage Collector stuff*/
138      stackitem *gc_ref;            /* Stack of all allocated values */
139      int gc_limit;                 /* Run GC when this much is allocated */
140      int gc_count;                 /* Amount currently allocated */
141  } environment;  } environment;
142    
 /* A type for pointers to external functions */  
 typedef void (*funcp)(environment*); /* funcp is a pointer to a void  
                                          function (environment *) */  
143    
144  void init_env(environment*);  void init_env(environment*);
145  void printerr(const char*);  void printerr(const char*);
# Line 68  extern void toss(environment*); Line 147  extern void toss(environment*);
147  symbol **hash(hashtbl, const char*);  symbol **hash(hashtbl, const char*);
148  value* new_val(environment*);  value* new_val(environment*);
149  void gc_mark(value*);  void gc_mark(value*);
150    void gc_maybe(environment*);
151  extern void gc_init(environment*);  extern void gc_init(environment*);
152    void protect(value*);
153    void unprotect(value*);
154  void push_val(environment*, value*);  void push_val(environment*, value*);
155  void push_int(environment*, int);  void push_int(environment*, int);
156    void push_float(environment*, float);
157  void push_cstring(environment*, const char*);  void push_cstring(environment*, const char*);
158  char *mangle_str(const char*);  char *mangle_str(const char*);
159  extern void mangle(environment*);  extern void mangle(environment*);
160  void push_sym(environment*, const char*);  void push_sym(environment*, const char*);
161  extern void nl();  extern void nl(environment*);
162    extern void nlport(environment*);
163  extern void type(environment*);  extern void type(environment*);
164  void print_h(stackitem*, int);  void print_val(environment *, value*, int, stackitem*, FILE*);
165  extern void print_(environment*);  extern void print_(environment*);
166  extern void print(environment*);  extern void print(environment*);
167  extern void princ_(environment*);  extern void princ_(environment*);
168  extern void princ(environment*);  extern void princ(environment*);
169  void print_st(stackitem*, long);  extern void printport_(environment*);
170    extern void printport(environment*);
171    extern void princport_(environment*);
172    extern void princport(environment*);
173    void print_st(environment*, value*, long);
174  extern void printstack(environment*);  extern void printstack(environment*);
175  extern void swap(environment*);  extern void swap(environment*);
176  extern void rot(environment*);  extern void rot(environment*);
# Line 104  extern void errn(environment*); Line 192  extern void errn(environment*);
192  extern void sx_2b(environment*);  extern void sx_2b(environment*);
193  extern void sx_2d(environment*);  extern void sx_2d(environment*);
194  extern void sx_3e(environment*);  extern void sx_3e(environment*);
195    extern void sx_3c(environment*);
196    extern void sx_3c3d(environment*);
197    extern void sx_3e3d(environment*);
198  value *copy_val(environment*, value*);  value *copy_val(environment*, value*);
199  extern void sx_647570(environment*);  extern void sx_647570(environment*);
200  extern void sx_6966(environment*);  extern void sx_6966(environment*);
201  extern void ifelse(environment*);  extern void ifelse(environment*);
202    extern void sx_656c7365(environment*);
203    extern void then(environment*);
204  extern void sx_7768696c65(environment*);  extern void sx_7768696c65(environment*);
205  extern void sx_666f72(environment*);  extern void sx_666f72(environment*);
206    extern void foreach(environment*);
207  extern void to(environment*);  extern void to(environment*);
208  extern void readline(environment*);  extern void readline(environment*);
209    extern void readlineport(environment*);
210    void readlinestream(environment*, FILE*);
211  extern void sx_72656164(environment*);  extern void sx_72656164(environment*);
212  extern void foreach(environment*);  extern void readport(environment*);
213    void readstream(environment*, FILE*);
214    extern void beep(environment*);
215    extern void sx_77616974(environment*);
216    extern void copying(environment*);
217    extern void warranty(environment*);
218    extern void sx_2a(environment*);
219    extern void sx_2f(environment*);
220    extern void mod(environment*);
221    extern void sx_646976(environment*);
222    extern void setcar(environment*);
223    extern void setcdr(environment*);
224    extern void car(environment*);
225    extern void cdr(environment*);
226    extern void cons(environment*);
227    extern void assq(environment*);
228    void assocgen(environment*, funcp);
229    extern void sx_646f(environment *);
230    extern void sx_6f70656e(environment*);
231    extern void sx_636c6f7365(environment*);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.24

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26