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