| 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 { |
| 33 |
|
empty, /* The empty list */ |
| 34 |
integer, |
integer, |
| 35 |
tfloat, |
tfloat, |
| 36 |
string, |
string, |
| 37 |
func, /* Function pointer */ |
func, /* Function pointer */ |
| 38 |
symb, |
symb, /* Symbol */ |
| 39 |
list |
tcons /* A pair of two values */ |
| 40 |
} type:4; /* Type of stack element */ |
} type:4; /* Type of stack element */ |
| 41 |
|
|
| 42 |
int gc_garb:1; |
union { |
| 43 |
int gc_protect:1; |
struct { |
| 44 |
|
unsigned int mark:1; /* Used internally in the GC */ |
| 45 |
|
unsigned int protect:1; /* Protect from GC */ |
| 46 |
|
} flag; |
| 47 |
|
unsigned int no_gc:2; /* Both flags as one integer */ |
| 48 |
|
} gc; /* Garbage collector stuff */ |
| 49 |
|
|
| 50 |
union { |
union { |
| 51 |
void *ptr; /* Pointer to the content */ |
void *ptr; /* Pointer to the content */ |
| 52 |
|
struct cons_struct *c; /* ...or a pointer to a cons cell */ |
| 53 |
|
struct symbol_struct *sym; /* ...or a pointer to a symbol */ |
| 54 |
int i; /* ...or an integer */ |
int i; /* ...or an integer */ |
| 55 |
float f; |
float f; /* ...or a floating point number */ |
| 56 |
} content; /* Stores a pointer or an integer */ |
} content; /* Stores a pointer or an integer */ |
| 57 |
|
|
| 58 |
} value; |
} value; |
| 59 |
|
|
| 60 |
|
/* An item (value) on a stack */ |
| 61 |
|
typedef struct stackitem_struct |
| 62 |
|
{ |
| 63 |
|
value *item; /* The value on the stack */ |
| 64 |
|
/* (This is never NULL) */ |
| 65 |
|
struct stackitem_struct *next; /* Next item */ |
| 66 |
|
} stackitem; |
| 67 |
|
|
| 68 |
|
typedef struct cons_struct { /* A pair of two values */ |
| 69 |
|
value *car; |
| 70 |
|
value *cdr; |
| 71 |
|
} cons; |
| 72 |
|
|
| 73 |
/* A symbol with a name and possible value */ |
/* A symbol with a name and possible value */ |
| 74 |
/* (These do not need reference counters, they are kept unique by |
/* (These do not need reference counters, they are kept unique by |
| 75 |
hashing.) */ |
hashing.) */ |
| 82 |
/* A type for a hash table for symbols */ |
/* A type for a hash table for symbols */ |
| 83 |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
typedef symbol *hashtbl[HASHTBLSIZE]; /* Hash table declaration */ |
| 84 |
|
|
|
/* 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; |
|
|
|
|
| 85 |
/* An environment; gives access to the stack and a hash table of |
/* An environment; gives access to the stack and a hash table of |
| 86 |
defined symbols */ |
defined symbols */ |
| 87 |
typedef struct { |
typedef struct { |
| 88 |
stackitem *gc_ref; |
value *head; /* Head of the stack */ |
|
int gc_limit, gc_count; |
|
|
|
|
|
stackitem *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 */ |
| 93 |
read from in_string */ |
read from in_string */ |
| 94 |
FILE *inputstream; /* stdin or a file, most likely */ |
FILE *inputstream; /* stdin or a file, most likely */ |
| 95 |
int interactive; /* print prompts, stack, etc */ |
int interactive; /* print prompts, stack, etc */ |
| 96 |
|
|
| 97 |
|
/* Garbage Collector stuff*/ |
| 98 |
|
stackitem *gc_ref; /* Stack of all allocated values */ |
| 99 |
|
int gc_limit; /* Run GC when this much is allocated */ |
| 100 |
|
int gc_count; /* Amount currently allocated */ |
| 101 |
} environment; |
} environment; |
| 102 |
|
|
| 103 |
/* A type for pointers to external functions */ |
/* A type for pointers to external functions */ |
| 121 |
void push_sym(environment*, const char*); |
void push_sym(environment*, const char*); |
| 122 |
extern void nl(); |
extern void nl(); |
| 123 |
extern void type(environment*); |
extern void type(environment*); |
| 124 |
void print_h(stackitem*, int); |
void print_h(value*, int); |
| 125 |
extern void print_(environment*); |
extern void print_(environment*); |
| 126 |
extern void print(environment*); |
extern void print(environment*); |
| 127 |
extern void princ_(environment*); |
extern void princ_(environment*); |
| 128 |
extern void princ(environment*); |
extern void princ(environment*); |
| 129 |
void print_st(stackitem*, long); |
void print_st(value*, long); |
| 130 |
extern void printstack(environment*); |
extern void printstack(environment*); |
| 131 |
extern void swap(environment*); |
extern void swap(environment*); |
| 132 |
extern void rot(environment*); |
extern void rot(environment*); |
| 169 |
extern void sx_3c3d(environment*); |
extern void sx_3c3d(environment*); |
| 170 |
extern void sx_3e3d(environment*); |
extern void sx_3e3d(environment*); |
| 171 |
extern void sx_646976(environment*); |
extern void sx_646976(environment*); |
| 172 |
|
extern void then(environment*); |