| 22 |
|
|
| 23 |
#define HASHTBLSIZE 2048 |
#define HASHTBLSIZE 2048 |
| 24 |
|
|
| 25 |
|
#define CAR(X) ((X)->content.c->car) |
| 26 |
|
#define CDR(X) ((X)->content.c->cdr) |
| 27 |
|
|
| 28 |
|
/* printf, sscanf, fgets, fprintf, fopen, perror */ |
| 29 |
|
#include <stdio.h> |
| 30 |
|
/* exit, EXIT_SUCCESS, malloc, free */ |
| 31 |
|
#include <stdlib.h> |
| 32 |
|
/* NULL */ |
| 33 |
|
#include <stddef.h> |
| 34 |
|
/* dlopen, dlsym, dlerror */ |
| 35 |
|
#include <dlfcn.h> |
| 36 |
|
/* strcmp, strcpy, strlen, strcat, strdup */ |
| 37 |
|
#include <string.h> |
| 38 |
|
/* getopt, STDIN_FILENO, STDOUT_FILENO, usleep */ |
| 39 |
|
#include <unistd.h> |
| 40 |
|
/* EX_NOINPUT, EX_USAGE */ |
| 41 |
|
#include <sysexits.h> |
| 42 |
|
/* assert */ |
| 43 |
|
#include <assert.h> |
| 44 |
|
/* waitpid */ |
| 45 |
|
#include <sys/wait.h> |
| 46 |
|
/* va_list, va_start, va_arg, va_end */ |
| 47 |
|
#include <stdarg.h> |
| 48 |
|
|
| 49 |
|
#ifdef __linux__ |
| 50 |
|
/* mtrace, muntrace */ |
| 51 |
|
#include <mcheck.h> |
| 52 |
|
/* ioctl */ |
| 53 |
|
#include <sys/ioctl.h> |
| 54 |
|
/* KDMKTONE */ |
| 55 |
|
#include <linux/kd.h> |
| 56 |
|
#endif /* __linux__ */ |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
/* First, define some types. */ |
/* First, define some types. */ |
| 61 |
|
|
| 62 |
struct cons_struct; |
struct cons_struct; |
| 63 |
struct symbol_struct; |
struct symbol_struct; |
| 64 |
|
struct environment_struct; |
| 65 |
|
|
| 66 |
|
/* A type for pointers to external functions */ |
| 67 |
|
typedef void (*funcp)(struct environment_struct*); |
| 68 |
|
/* funcp is a pointer to a void function (environment *) */ |
| 69 |
|
|
| 70 |
|
enum type_enum { |
| 71 |
|
unknown, |
| 72 |
|
empty, /* The empty list */ |
| 73 |
|
integer, |
| 74 |
|
tfloat, |
| 75 |
|
string, |
| 76 |
|
func, /* Function pointer */ |
| 77 |
|
symb, /* Symbol */ |
| 78 |
|
tcons, /* A pair of two values */ |
| 79 |
|
port /* An I/O port */ |
| 80 |
|
}; /* Type of stack element */ |
| 81 |
|
|
| 82 |
|
|
| 83 |
/* A value of some type */ |
/* A value of some type */ |
| 84 |
typedef struct { |
typedef struct { |
| 85 |
enum { |
enum type_enum type:4; |
|
empty, /* The empty list */ |
|
|
integer, |
|
|
tfloat, |
|
|
string, |
|
|
func, /* Function pointer */ |
|
|
symb, /* Symbol */ |
|
|
tcons /* A pair of two values */ |
|
|
} type:4; /* Type of stack element */ |
|
| 86 |
|
|
| 87 |
union { |
union { |
| 88 |
struct { |
struct { |
| 96 |
void *ptr; /* Pointer to the content */ |
void *ptr; /* Pointer to the content */ |
| 97 |
struct cons_struct *c; /* ...or a pointer to a cons cell */ |
struct cons_struct *c; /* ...or a pointer to a cons cell */ |
| 98 |
struct symbol_struct *sym; /* ...or a pointer to a symbol */ |
struct symbol_struct *sym; /* ...or a pointer to a symbol */ |
| 99 |
|
FILE *p; /* ...or an I/O stream */ |
| 100 |
int i; /* ...or an integer */ |
int i; /* ...or an integer */ |
| 101 |
float f; /* ...or a floating point number */ |
float f; /* ...or a floating point number */ |
| 102 |
|
funcp func; /* ...or a function pointer */ |
| 103 |
|
char *string; /* ...or a string */ |
| 104 |
} content; /* Stores a pointer or an integer */ |
} content; /* Stores a pointer or an integer */ |
| 105 |
|
|
| 106 |
} value; |
} value; |
| 136 |
value *head; /* Head of the stack */ |
value *head; /* Head of the stack */ |
| 137 |
hashtbl symbols; /* Hash table of all variable bindings */ |
hashtbl symbols; /* Hash table of all variable bindings */ |
| 138 |
int err; /* Error flag */ |
int err; /* Error flag */ |
| 139 |
|
char *errsymb; |
| 140 |
char *in_string; /* Input pending to be read */ |
char *in_string; /* Input pending to be read */ |
| 141 |
char *free_string; /* Free this string when all input is |
char *free_string; /* Free this string when all input is |
| 142 |
read from in_string */ |
read from in_string */ |
| 149 |
int gc_count; /* Amount currently allocated */ |
int gc_count; /* Amount currently allocated */ |
| 150 |
} environment; |
} environment; |
| 151 |
|
|
|
/* A type for pointers to external functions */ |
|
|
typedef void (*funcp)(environment*); /* funcp is a pointer to a void |
|
|
function (environment *) */ |
|
| 152 |
|
|
| 153 |
void init_env(environment*); |
void init_env(environment*); |
| 154 |
void printerr(const char*); |
void printerr(environment*, const char*); |
| 155 |
extern void toss(environment*); |
extern void toss(environment*); |
| 156 |
symbol **hash(hashtbl, const char*); |
symbol **hash(hashtbl, const char*); |
| 157 |
value* new_val(environment*); |
value* new_val(environment*); |
| 167 |
char *mangle_str(const char*); |
char *mangle_str(const char*); |
| 168 |
extern void mangle(environment*); |
extern void mangle(environment*); |
| 169 |
void push_sym(environment*, const char*); |
void push_sym(environment*, const char*); |
| 170 |
extern void nl(); |
extern void nl(environment*); |
| 171 |
|
extern void nlport(environment*); |
| 172 |
extern void type(environment*); |
extern void type(environment*); |
| 173 |
void print_val(value*, int, stackitem*); |
void print_val(environment *, value*, int, stackitem*, FILE*); |
| 174 |
extern void print_(environment*); |
extern void print_(environment*); |
| 175 |
extern void print(environment*); |
extern void print(environment*); |
| 176 |
extern void princ_(environment*); |
extern void princ_(environment*); |
| 177 |
extern void princ(environment*); |
extern void princ(environment*); |
| 178 |
void print_st(value*, long); |
extern void printport_(environment*); |
| 179 |
|
extern void printport(environment*); |
| 180 |
|
extern void princport_(environment*); |
| 181 |
|
extern void princport(environment*); |
| 182 |
|
void print_st(environment*, value*, long); |
| 183 |
extern void printstack(environment*); |
extern void printstack(environment*); |
| 184 |
extern void swap(environment*); |
extern void swap(environment*); |
| 185 |
extern void rot(environment*); |
extern void rot(environment*); |
| 215 |
extern void foreach(environment*); |
extern void foreach(environment*); |
| 216 |
extern void to(environment*); |
extern void to(environment*); |
| 217 |
extern void readline(environment*); |
extern void readline(environment*); |
| 218 |
|
extern void readlineport(environment*); |
| 219 |
|
void readlinestream(environment*, FILE*); |
| 220 |
extern void sx_72656164(environment*); |
extern void sx_72656164(environment*); |
| 221 |
|
extern void readport(environment*); |
| 222 |
|
void readstream(environment*, FILE*); |
| 223 |
extern void beep(environment*); |
extern void beep(environment*); |
| 224 |
extern void sx_77616974(environment*); |
extern void sx_77616974(environment*); |
| 225 |
extern void copying(environment*); |
extern void copying(environment*); |
| 234 |
extern void cdr(environment*); |
extern void cdr(environment*); |
| 235 |
extern void cons(environment*); |
extern void cons(environment*); |
| 236 |
extern void assq(environment*); |
extern void assq(environment*); |
| 237 |
|
void assocgen(environment*, funcp); |
| 238 |
|
extern void sx_646f(environment *); |
| 239 |
|
extern void sx_6f70656e(environment*); |
| 240 |
|
extern void sx_636c6f7365(environment*); |
| 241 |
|
int check_args(environment*, ...); |