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 |
|
|
28 |
typedef struct { |
typedef struct { |
29 |
enum { |
enum { |
30 |
integer, |
integer, |
31 |
|
tfloat, |
32 |
string, |
string, |
33 |
func, /* Function pointer */ |
func, /* Function pointer */ |
34 |
symb, |
symb, |
35 |
list |
list |
36 |
} type:3; /* Type of stack element */ |
} type:4; /* Type of stack element */ |
37 |
|
|
38 |
int gc_garb:1; |
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 { |
union { |
47 |
void *ptr; /* Pointer to the content */ |
void *ptr; /* Pointer to the content */ |
48 |
int val; /* ...or an integer */ |
int i; /* ...or an integer */ |
49 |
|
float f; |
50 |
} content; /* Stores a pointer or an integer */ |
} content; /* Stores a pointer or an integer */ |
51 |
|
|
52 |
} value; |
} value; |
82 |
int err; /* Error flag */ |
int err; /* Error flag */ |
83 |
char *in_string; /* Input pending to be read */ |
char *in_string; /* Input pending to be read */ |
84 |
char *free_string; /* Free this string when all input is |
char *free_string; /* Free this string when all input is |
85 |
read from in_string */ |
read from in_string */ |
86 |
FILE *inputstream; /* stdin or a file, most likely */ |
FILE *inputstream; /* stdin or a file, most likely */ |
87 |
int interactive; /* print prompts, stack, etc */ |
int interactive; /* print prompts, stack, etc */ |
88 |
} environment; |
} environment; |
97 |
symbol **hash(hashtbl, const char*); |
symbol **hash(hashtbl, const char*); |
98 |
value* new_val(environment*); |
value* new_val(environment*); |
99 |
void gc_mark(value*); |
void gc_mark(value*); |
100 |
|
void gc_maybe(environment *env); |
101 |
extern void gc_init(environment*); |
extern void gc_init(environment*); |
102 |
void push_val(environment*, value*); |
void push_val(environment*, value*); |
103 |
void push_int(environment*, int); |
void push_int(environment*, int); |
104 |
|
void push_float(environment*, float); |
105 |
void push_cstring(environment*, const char*); |
void push_cstring(environment*, const char*); |
106 |
char *mangle_str(const char*); |
char *mangle_str(const char*); |
107 |
extern void mangle(environment*); |
extern void mangle(environment*); |
145 |
extern void readline(environment*); |
extern void readline(environment*); |
146 |
extern void sx_72656164(environment*); |
extern void sx_72656164(environment*); |
147 |
extern void foreach(environment*); |
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*); |