24 |
|
|
25 |
/* First, define some types. */ |
/* First, define some types. */ |
26 |
|
|
27 |
|
struct cons_struct; |
28 |
|
struct symbol_struct; |
29 |
|
|
30 |
/* A value of some type */ |
/* A value of some type */ |
31 |
typedef struct { |
typedef struct { |
32 |
enum { |
enum { |
34 |
tfloat, |
tfloat, |
35 |
string, |
string, |
36 |
func, /* Function pointer */ |
func, /* Function pointer */ |
37 |
symb, |
symb, /* Symbol */ |
38 |
list |
tcons /* A pair of two values */ |
39 |
} type:4; /* Type of stack element */ |
} type:4; /* Type of stack element */ |
40 |
|
|
41 |
int gc_garb:1; |
union { |
42 |
|
struct { |
43 |
|
unsigned int mark:1; /* Used internally in the GC */ |
44 |
|
unsigned int protect:1; /* Protect from GC */ |
45 |
|
} flag; |
46 |
|
unsigned int no_gc:2; /* Both flags as one integer */ |
47 |
|
} gc; /* Garbage collector stuff */ |
48 |
|
|
49 |
union { |
union { |
50 |
void *ptr; /* Pointer to the content */ |
void *ptr; /* Pointer to the content */ |
51 |
|
struct cons_struct *c; /* ...or a pointer to a cons cell */ |
52 |
|
struct symbol_struct *sym; /* ...or a pointer to a symbol */ |
53 |
int i; /* ...or an integer */ |
int i; /* ...or an integer */ |
54 |
float f; |
float f; /* ...or a floating point number */ |
55 |
} content; /* Stores a pointer or an integer */ |
} content; /* Stores a pointer or an integer */ |
56 |
|
|
57 |
} value; |
} value; |
58 |
|
|
59 |
|
/* 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 |
|
typedef struct cons_struct { /* A pair of two values */ |
68 |
|
value *car; |
69 |
|
value *cdr; |
70 |
|
} cons; |
71 |
|
|
72 |
/* A symbol with a name and possible value */ |
/* A symbol with a name and possible value */ |
73 |
/* (These do not need reference counters, they are kept unique by |
/* (These do not need reference counters, they are kept unique by |
74 |
hashing.) */ |
hashing.) */ |
81 |
/* A type for a hash table for symbols */ |
/* A type for a hash table for symbols */ |
82 |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
83 |
|
|
|
/* 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; |
|
|
|
|
84 |
/* An environment; gives access to the stack and a hash table of |
/* An environment; gives access to the stack and a hash table of |
85 |
defined symbols */ |
defined symbols */ |
86 |
typedef struct { |
typedef struct { |
87 |
stackitem *gc_ref; |
stackitem *gc_ref; |
|
stackitem *gc_protect; |
|
88 |
int gc_limit, gc_count; |
int gc_limit, gc_count; |
89 |
|
|
90 |
stackitem *head; /* Head of the stack */ |
value *head; /* Head of the stack */ |
91 |
hashtbl symbols; /* Hash table of all variable bindings */ |
hashtbl symbols; /* Hash table of all variable bindings */ |
92 |
int err; /* Error flag */ |
int err; /* Error flag */ |
93 |
char *in_string; /* Input pending to be read */ |
char *in_string; /* Input pending to be read */ |
118 |
void push_sym(environment*, const char*); |
void push_sym(environment*, const char*); |
119 |
extern void nl(); |
extern void nl(); |
120 |
extern void type(environment*); |
extern void type(environment*); |
121 |
void print_h(stackitem*, int); |
void print_h(value*, int); |
122 |
extern void print_(environment*); |
extern void print_(environment*); |
123 |
extern void print(environment*); |
extern void print(environment*); |
124 |
extern void princ_(environment*); |
extern void princ_(environment*); |
125 |
extern void princ(environment*); |
extern void princ(environment*); |
126 |
void print_st(stackitem*, long); |
void print_st(value*, long); |
127 |
extern void printstack(environment*); |
extern void printstack(environment*); |
128 |
extern void swap(environment*); |
extern void swap(environment*); |
129 |
extern void rot(environment*); |
extern void rot(environment*); |
155 |
extern void readline(environment*); |
extern void readline(environment*); |
156 |
extern void sx_72656164(environment*); |
extern void sx_72656164(environment*); |
157 |
extern void foreach(environment*); |
extern void foreach(environment*); |
158 |
void protect(environment*, value*); |
void protect(value*); |
159 |
void unprotect(environment*); |
void unprotect(value*); |
160 |
extern void copying(environment*); |
extern void copying(environment*); |
161 |
extern void warranty(environment*); |
extern void warranty(environment*); |
162 |
extern void sx_2a(environment*); |
extern void sx_2a(environment*); |
166 |
extern void sx_3c3d(environment*); |
extern void sx_3c3d(environment*); |
167 |
extern void sx_3e3d(environment*); |
extern void sx_3e3d(environment*); |
168 |
extern void sx_646976(environment*); |
extern void sx_646976(environment*); |
169 |
|
extern void then(environment*); |