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

Annotation of /stack/stack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Tue Mar 12 14:53:19 2002 UTC (22 years, 1 month ago) by masse
Branch: MAIN
Changes since 1.12: +2 -0 lines
File MIME type: text/plain
stack.h:
(value->content.sym): New entry in content union. All callers changed.

stack.c:
(foreach): Bugfix.

1 teddy 1.4 /*
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 teddy 1.1
23     #define HASHTBLSIZE 2048
24    
25     /* First, define some types. */
26    
27 masse 1.10 struct cons_struct;
28 masse 1.13 struct symbol_struct;
29 masse 1.10
30 teddy 1.1 /* A value of some type */
31     typedef struct {
32     enum {
33     integer,
34 masse 1.5 tfloat,
35 teddy 1.1 string,
36     func, /* Function pointer */
37 teddy 1.11 symb, /* Symbol */
38     tcons /* A pair of two values */
39 masse 1.5 } type:4; /* Type of stack element */
40 masse 1.2
41 teddy 1.9 union {
42     struct {
43 teddy 1.11 unsigned int mark:1; /* Used internally in the GC */
44     unsigned int protect:1; /* Protect from GC */
45 teddy 1.9 } flag;
46 teddy 1.11 unsigned int no_gc:2; /* Both flags as one integer */
47     } gc; /* Garbage collector stuff */
48 teddy 1.1
49     union {
50     void *ptr; /* Pointer to the content */
51 teddy 1.11 struct cons_struct *c; /* ...or a pointer to a cons cell */
52 masse 1.13 struct symbol_struct *sym; /* ...or a pointer to a symbol */
53 masse 1.5 int i; /* ...or an integer */
54 teddy 1.11 float f; /* ...or a floating point number */
55 teddy 1.1 } content; /* Stores a pointer or an integer */
56    
57     } value;
58    
59 masse 1.10 /* An item (value) on a stack */
60     typedef struct stackitem_struct
61     {
62     value *item; /* The value on the stack */
63     /* (This is never NULL) */
64     struct stackitem_struct *next; /* Next item */
65     } stackitem;
66    
67 teddy 1.11 typedef struct cons_struct { /* A pair of two values */
68 masse 1.10 value *car;
69     value *cdr;
70     } cons;
71    
72 teddy 1.1 /* A symbol with a name and possible value */
73     /* (These do not need reference counters, they are kept unique by
74     hashing.) */
75     typedef struct symbol_struct {
76     char *id; /* Symbol name */
77     value *val; /* The value (if any) bound to it */
78     struct symbol_struct *next; /* In case of hashing conflicts, a */
79     } symbol; /* symbol is a kind of stack item. */
80    
81     /* A type for a hash table for symbols */
82     typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */
83    
84     /* An environment; gives access to the stack and a hash table of
85     defined symbols */
86     typedef struct {
87     stackitem *gc_ref;
88     int gc_limit, gc_count;
89    
90 masse 1.12 value *head; /* Head of the stack */
91 teddy 1.1 hashtbl symbols; /* Hash table of all variable bindings */
92     int err; /* Error flag */
93     char *in_string; /* Input pending to be read */
94     char *free_string; /* Free this string when all input is
95 teddy 1.4 read from in_string */
96 teddy 1.1 FILE *inputstream; /* stdin or a file, most likely */
97     int interactive; /* print prompts, stack, etc */
98     } environment;
99    
100     /* A type for pointers to external functions */
101 masse 1.2 typedef void (*funcp)(environment*); /* funcp is a pointer to a void
102 teddy 1.1 function (environment *) */
103    
104 masse 1.2 void init_env(environment*);
105     void printerr(const char*);
106     extern void toss(environment*);
107     symbol **hash(hashtbl, const char*);
108     value* new_val(environment*);
109     void gc_mark(value*);
110 teddy 1.7 void gc_maybe(environment *env);
111 masse 1.2 extern void gc_init(environment*);
112     void push_val(environment*, value*);
113     void push_int(environment*, int);
114 masse 1.5 void push_float(environment*, float);
115 masse 1.2 void push_cstring(environment*, const char*);
116     char *mangle_str(const char*);
117     extern void mangle(environment*);
118     void push_sym(environment*, const char*);
119 teddy 1.1 extern void nl();
120 masse 1.2 extern void type(environment*);
121 masse 1.12 void print_h(value*, int);
122 masse 1.2 extern void print_(environment*);
123     extern void print(environment*);
124     extern void princ_(environment*);
125     extern void princ(environment*);
126 masse 1.12 void print_st(value*, long);
127 masse 1.2 extern void printstack(environment*);
128     extern void swap(environment*);
129     extern void rot(environment*);
130     extern void rcl(environment*);
131     extern void eval(environment*);
132     extern void rev(environment*);
133     extern void pack(environment*);
134     extern void expand(environment*);
135     extern void eq(environment*);
136     extern void not(environment*);
137     extern void neq(environment*);
138     extern void def(environment*);
139     extern void quit(environment*);
140     extern void clear(environment*);
141     extern void words(environment*);
142     void forget_sym(symbol**);
143     extern void forget(environment*);
144     extern void errn(environment*);
145     extern void sx_2b(environment*);
146     extern void sx_2d(environment*);
147     extern void sx_3e(environment*);
148     value *copy_val(environment*, value*);
149     extern void sx_647570(environment*);
150     extern void sx_6966(environment*);
151     extern void ifelse(environment*);
152     extern void sx_7768696c65(environment*);
153     extern void sx_666f72(environment*);
154     extern void to(environment*);
155     extern void readline(environment*);
156     extern void sx_72656164(environment*);
157     extern void foreach(environment*);
158 masse 1.8 void protect(value*);
159     void unprotect(value*);
160 masse 1.5 extern void copying(environment*);
161     extern void warranty(environment*);
162     extern void sx_2a(environment*);
163     extern void sx_2f(environment*);
164     extern void mod(environment*);
165     extern void sx_3c(environment*);
166     extern void sx_3c3d(environment*);
167     extern void sx_3e3d(environment*);
168 masse 1.6 extern void sx_646976(environment*);

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26