raw
tinyscheme_genesi...    1 /* scheme-private.h */
tinyscheme_genesi... 2
tinyscheme_genesi... 3 #ifndef _SCHEME_PRIVATE_H
tinyscheme_genesi... 4 #define _SCHEME_PRIVATE_H
tinyscheme_genesi... 5
tinyscheme_genesi... 6 #include "scheme.h"
tinyscheme_genesi... 7 /*------------------ Ugly internals -----------------------------------*/
tinyscheme_genesi... 8 /*------------------ Of interest only to FFI users --------------------*/
tinyscheme_genesi... 9
tinyscheme_genesi... 10 #ifdef __cplusplus
tinyscheme_genesi... 11 extern "C" {
tinyscheme_genesi... 12 #endif
tinyscheme_genesi... 13
tinyscheme_genesi... 14 enum scheme_port_kind {
tinyscheme_genesi... 15 port_free=0,
tinyscheme_genesi... 16 port_file=1,
tinyscheme_genesi... 17 port_string=2,
tinyscheme_genesi... 18 port_srfi6=4,
tinyscheme_genesi... 19 port_input=16,
tinyscheme_genesi... 20 port_output=32,
tinyscheme_genesi... 21 port_saw_EOF=64
tinyscheme_genesi... 22 };
tinyscheme_genesi... 23
tinyscheme_genesi... 24 typedef struct port {
tinyscheme_genesi... 25 unsigned char kind;
tinyscheme_genesi... 26 union {
tinyscheme_genesi... 27 struct {
tinyscheme_genesi... 28 FILE *file;
asciilifeform_tin... 29 int interactive;
tinyscheme_genesi... 30 int closeit;
tinyscheme_genesi... 31 #if SHOW_ERROR_LINE
tinyscheme_genesi... 32 int curr_line;
tinyscheme_genesi... 33 char *filename;
tinyscheme_genesi... 34 #endif
tinyscheme_genesi... 35 } stdio;
tinyscheme_genesi... 36 struct {
tinyscheme_genesi... 37 char *start;
tinyscheme_genesi... 38 char *past_the_end;
tinyscheme_genesi... 39 char *curr;
tinyscheme_genesi... 40 } string;
tinyscheme_genesi... 41 } rep;
tinyscheme_genesi... 42 } port;
tinyscheme_genesi... 43
tinyscheme_genesi... 44 /* cell structure */
tinyscheme_genesi... 45 struct cell {
tinyscheme_genesi... 46 unsigned int _flag;
tinyscheme_genesi... 47 union {
tinyscheme_genesi... 48 struct {
tinyscheme_genesi... 49 char *_svalue;
tinyscheme_genesi... 50 int _length;
tinyscheme_genesi... 51 } _string;
tinyscheme_genesi... 52 num _number;
tinyscheme_genesi... 53 port *_port;
tinyscheme_genesi... 54 foreign_func _ff;
tinyscheme_genesi... 55 struct {
tinyscheme_genesi... 56 struct cell *_car;
tinyscheme_genesi... 57 struct cell *_cdr;
tinyscheme_genesi... 58 } _cons;
tinyscheme_genesi... 59 } _object;
tinyscheme_genesi... 60 };
tinyscheme_genesi... 61
tinyscheme_genesi... 62 struct scheme {
tinyscheme_genesi... 63 /* arrays for segments */
tinyscheme_genesi... 64 func_alloc malloc;
tinyscheme_genesi... 65 func_dealloc free;
tinyscheme_genesi... 66
tinyscheme_genesi... 67 /* return code */
tinyscheme_genesi... 68 int retcode;
tinyscheme_genesi... 69 int tracing;
tinyscheme_genesi... 70
tinyscheme_genesi... 71
tinyscheme_genesi... 72 #define CELL_SEGSIZE 5000 /* # of cells in one segment */
tinyscheme_genesi... 73 #define CELL_NSEGMENT 10 /* # of segments for cells */
tinyscheme_genesi... 74 char *alloc_seg[CELL_NSEGMENT];
tinyscheme_genesi... 75 pointer cell_seg[CELL_NSEGMENT];
tinyscheme_genesi... 76 int last_cell_seg;
tinyscheme_genesi... 77
tinyscheme_genesi... 78 /* We use 4 registers. */
tinyscheme_genesi... 79 pointer args; /* register for arguments of function */
tinyscheme_genesi... 80 pointer envir; /* stack register for current environment */
tinyscheme_genesi... 81 pointer code; /* register for current code */
tinyscheme_genesi... 82 pointer dump; /* stack register for next evaluation */
tinyscheme_genesi... 83
tinyscheme_genesi... 84 int interactive_repl; /* are we in an interactive REPL? */
tinyscheme_genesi... 85
tinyscheme_genesi... 86 struct cell _sink;
tinyscheme_genesi... 87 pointer sink; /* when mem. alloc. fails */
tinyscheme_genesi... 88 struct cell _NIL;
tinyscheme_genesi... 89 pointer NIL; /* special cell representing empty cell */
tinyscheme_genesi... 90 struct cell _HASHT;
tinyscheme_genesi... 91 pointer T; /* special cell representing #t */
tinyscheme_genesi... 92 struct cell _HASHF;
tinyscheme_genesi... 93 pointer F; /* special cell representing #f */
tinyscheme_genesi... 94 struct cell _EOF_OBJ;
tinyscheme_genesi... 95 pointer EOF_OBJ; /* special cell representing end-of-file object */
tinyscheme_genesi... 96 pointer oblist; /* pointer to symbol table */
tinyscheme_genesi... 97 pointer global_env; /* pointer to global environment */
tinyscheme_genesi... 98 pointer c_nest; /* stack for nested calls from C */
tinyscheme_genesi... 99
tinyscheme_genesi... 100 /* global pointers to special symbols */
tinyscheme_genesi... 101 pointer LAMBDA; /* pointer to syntax lambda */
tinyscheme_genesi... 102 pointer QUOTE; /* pointer to syntax quote */
tinyscheme_genesi... 103
tinyscheme_genesi... 104 pointer QQUOTE; /* pointer to symbol quasiquote */
tinyscheme_genesi... 105 pointer UNQUOTE; /* pointer to symbol unquote */
tinyscheme_genesi... 106 pointer UNQUOTESP; /* pointer to symbol unquote-splicing */
tinyscheme_genesi... 107 pointer FEED_TO; /* => */
tinyscheme_genesi... 108 pointer COLON_HOOK; /* *colon-hook* */
tinyscheme_genesi... 109 pointer ERROR_HOOK; /* *error-hook* */
tinyscheme_genesi... 110 pointer SHARP_HOOK; /* *sharp-hook* */
tinyscheme_genesi... 111 pointer COMPILE_HOOK; /* *compile-hook* */
tinyscheme_genesi... 112
tinyscheme_genesi... 113 pointer free_cell; /* pointer to top of free cells */
tinyscheme_genesi... 114 long fcells; /* # of free cells */
tinyscheme_genesi... 115
tinyscheme_genesi... 116 pointer inport;
tinyscheme_genesi... 117 pointer outport;
tinyscheme_genesi... 118 pointer save_inport;
tinyscheme_genesi... 119 pointer loadport;
tinyscheme_genesi... 120
tinyscheme_genesi... 121 #define MAXFIL 64
tinyscheme_genesi... 122 port load_stack[MAXFIL]; /* Stack of open files for port -1 (LOADing) */
tinyscheme_genesi... 123 int nesting_stack[MAXFIL];
tinyscheme_genesi... 124 int file_i;
tinyscheme_genesi... 125 int nesting;
tinyscheme_genesi... 126
tinyscheme_genesi... 127 char gc_verbose; /* if gc_verbose is not zero, print gc status */
tinyscheme_genesi... 128 char no_memory; /* Whether mem. alloc. has failed */
tinyscheme_genesi... 129
tinyscheme_genesi... 130 #define LINESIZE 1024
tinyscheme_genesi... 131 char linebuff[LINESIZE];
tinyscheme_genesi... 132 #define STRBUFFSIZE 256
tinyscheme_genesi... 133 char strbuff[STRBUFFSIZE];
tinyscheme_genesi... 134
tinyscheme_genesi... 135 FILE *tmpfp;
tinyscheme_genesi... 136 int tok;
tinyscheme_genesi... 137 int print_flag;
tinyscheme_genesi... 138 pointer value;
tinyscheme_genesi... 139 int op;
tinyscheme_genesi... 140
tinyscheme_genesi... 141 void *ext_data; /* For the benefit of foreign functions */
tinyscheme_genesi... 142 long gensym_cnt;
tinyscheme_genesi... 143
tinyscheme_genesi... 144 struct scheme_interface *vptr;
tinyscheme_genesi... 145 void *dump_base; /* pointer to base of allocated dump stack */
tinyscheme_genesi... 146 int dump_size; /* number of frames allocated for dump stack */
tinyscheme_genesi... 147 };
tinyscheme_genesi... 148
tinyscheme_genesi... 149 /* operator code */
tinyscheme_genesi... 150 enum scheme_opcodes {
tinyscheme_genesi... 151 #define _OP_DEF(A,B,C,D,E,OP) OP,
tinyscheme_genesi... 152 #include "opdefines.h"
tinyscheme_genesi... 153 OP_MAXDEFINED
tinyscheme_genesi... 154 };
tinyscheme_genesi... 155
tinyscheme_genesi... 156
tinyscheme_genesi... 157 #define cons(sc,a,b) _cons(sc,a,b,0)
tinyscheme_genesi... 158 #define immutable_cons(sc,a,b) _cons(sc,a,b,1)
tinyscheme_genesi... 159
tinyscheme_genesi... 160 int is_string(pointer p);
tinyscheme_genesi... 161 char *string_value(pointer p);
tinyscheme_genesi... 162 int is_number(pointer p);
tinyscheme_genesi... 163 num nvalue(pointer p);
tinyscheme_genesi... 164 long ivalue(pointer p);
tinyscheme_genesi... 165 double rvalue(pointer p);
tinyscheme_genesi... 166 int is_integer(pointer p);
tinyscheme_genesi... 167 int is_real(pointer p);
tinyscheme_genesi... 168 int is_character(pointer p);
tinyscheme_genesi... 169 long charvalue(pointer p);
tinyscheme_genesi... 170 int is_vector(pointer p);
tinyscheme_genesi... 171
tinyscheme_genesi... 172 int is_port(pointer p);
tinyscheme_genesi... 173
tinyscheme_genesi... 174 int is_pair(pointer p);
tinyscheme_genesi... 175 pointer pair_car(pointer p);
tinyscheme_genesi... 176 pointer pair_cdr(pointer p);
tinyscheme_genesi... 177 pointer set_car(pointer p, pointer q);
tinyscheme_genesi... 178 pointer set_cdr(pointer p, pointer q);
tinyscheme_genesi... 179
tinyscheme_genesi... 180 int is_symbol(pointer p);
tinyscheme_genesi... 181 char *symname(pointer p);
tinyscheme_genesi... 182 int hasprop(pointer p);
tinyscheme_genesi... 183
tinyscheme_genesi... 184 int is_syntax(pointer p);
tinyscheme_genesi... 185 int is_proc(pointer p);
tinyscheme_genesi... 186 int is_foreign(pointer p);
tinyscheme_genesi... 187 char *syntaxname(pointer p);
tinyscheme_genesi... 188 int is_closure(pointer p);
tinyscheme_genesi... 189 #ifdef USE_MACRO
tinyscheme_genesi... 190 int is_macro(pointer p);
tinyscheme_genesi... 191 #endif
tinyscheme_genesi... 192 pointer closure_code(pointer p);
tinyscheme_genesi... 193 pointer closure_env(pointer p);
tinyscheme_genesi... 194
tinyscheme_genesi... 195 int is_continuation(pointer p);
tinyscheme_genesi... 196 int is_promise(pointer p);
tinyscheme_genesi... 197 int is_environment(pointer p);
tinyscheme_genesi... 198 int is_immutable(pointer p);
tinyscheme_genesi... 199 void setimmutable(pointer p);
tinyscheme_genesi... 200
tinyscheme_genesi... 201 #ifdef __cplusplus
tinyscheme_genesi... 202 }
tinyscheme_genesi... 203 #endif
tinyscheme_genesi... 204
tinyscheme_genesi... 205 #endif
tinyscheme_genesi... 206
tinyscheme_genesi... 207 /*
tinyscheme_genesi... 208 Local variables:
tinyscheme_genesi... 209 c-file-style: "k&r"
tinyscheme_genesi... 210 End:
tinyscheme_genesi... 211 */