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

Contents of /stack/stack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Sun Mar 10 10:06:36 2002 UTC (22 years, 2 months ago) by teddy
Branch: MAIN
Changes since 1.8: +7 -2 lines
File MIME type: text/plain
stack.h (value): Renamed gc_protect to gc.flag.protect and replaced gc_garb with gc.flag.mark with reversed meaning.  All users changed.
(value): New field "no_gc", which is both flag.protect and flag.mark.
stack.c: All users of gc_protect and gc_garb changed.
(gc_init): Check both mark and protect at the same time through gc.no_gc.
(new_val): Initialize gc.flag.protect too.

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

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26