24 |
|
|
25 |
/* First, define some types. */ |
/* First, define some types. */ |
26 |
|
|
27 |
|
struct cons_struct; |
28 |
|
|
29 |
/* A value of some type */ |
/* A value of some type */ |
30 |
typedef struct { |
typedef struct { |
31 |
enum { |
enum { |
34 |
string, |
string, |
35 |
func, /* Function pointer */ |
func, /* Function pointer */ |
36 |
symb, |
symb, |
37 |
list |
tcons |
38 |
} type:4; /* Type of stack element */ |
} type:4; /* Type of stack element */ |
39 |
|
|
40 |
union { |
union { |
46 |
} gc; |
} gc; |
47 |
|
|
48 |
union { |
union { |
49 |
|
struct cons_struct *c; |
50 |
void *ptr; /* Pointer to the content */ |
void *ptr; /* Pointer to the content */ |
51 |
int i; /* ...or an integer */ |
int i; /* ...or an integer */ |
52 |
float f; |
float f; |
54 |
|
|
55 |
} value; |
} value; |
56 |
|
|
57 |
|
/* An item (value) on a stack */ |
58 |
|
typedef struct stackitem_struct |
59 |
|
{ |
60 |
|
value *item; /* The value on the stack */ |
61 |
|
/* (This is never NULL) */ |
62 |
|
struct stackitem_struct *next; /* Next item */ |
63 |
|
} stackitem; |
64 |
|
|
65 |
|
typedef struct cons_struct { |
66 |
|
value *car; |
67 |
|
value *cdr; |
68 |
|
} cons; |
69 |
|
|
70 |
/* A symbol with a name and possible value */ |
/* A symbol with a name and possible value */ |
71 |
/* (These do not need reference counters, they are kept unique by |
/* (These do not need reference counters, they are kept unique by |
72 |
hashing.) */ |
hashing.) */ |
79 |
/* A type for a hash table for symbols */ |
/* A type for a hash table for symbols */ |
80 |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
81 |
|
|
|
/* 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; |
|
|
|
|
82 |
/* An environment; gives access to the stack and a hash table of |
/* An environment; gives access to the stack and a hash table of |
83 |
defined symbols */ |
defined symbols */ |
84 |
typedef struct { |
typedef struct { |
85 |
stackitem *gc_ref; |
stackitem *gc_ref; |
86 |
int gc_limit, gc_count; |
int gc_limit, gc_count; |
87 |
|
|
88 |
stackitem *head; /* Head of the stack */ |
cons *head; /* Head of the stack */ |
89 |
hashtbl symbols; /* Hash table of all variable bindings */ |
hashtbl symbols; /* Hash table of all variable bindings */ |
90 |
int err; /* Error flag */ |
int err; /* Error flag */ |
91 |
char *in_string; /* Input pending to be read */ |
char *in_string; /* Input pending to be read */ |
116 |
void push_sym(environment*, const char*); |
void push_sym(environment*, const char*); |
117 |
extern void nl(); |
extern void nl(); |
118 |
extern void type(environment*); |
extern void type(environment*); |
119 |
void print_h(stackitem*, int); |
void print_h(cons*, int); |
120 |
extern void print_(environment*); |
extern void print_(environment*); |
121 |
extern void print(environment*); |
extern void print(environment*); |
122 |
extern void princ_(environment*); |
extern void princ_(environment*); |
123 |
extern void princ(environment*); |
extern void princ(environment*); |
124 |
void print_st(stackitem*, long); |
void print_st(cons*, long); |
125 |
extern void printstack(environment*); |
extern void printstack(environment*); |
126 |
extern void swap(environment*); |
extern void swap(environment*); |
127 |
extern void rot(environment*); |
extern void rot(environment*); |