Back to index

texmacs  1.0.7.15
scheme-private.h
Go to the documentation of this file.
00001 /* scheme-private.h */
00002 
00003 #ifndef _SCHEME_PRIVATE_H
00004 #define _SCHEME_PRIVATE_H
00005 
00006 #include "scheme.h"
00007 /*------------------ Ugly internals -----------------------------------*/
00008 /*------------------ Of interest only to FFI users --------------------*/
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 enum scheme_port_kind {
00015   port_free=0,
00016   port_file=1,
00017   port_string=2,
00018   port_srfi6=4,
00019   port_input=16,
00020   port_output=32,
00021   port_saw_EOF=64,
00022 };
00023 
00024 typedef struct port {
00025   unsigned char kind;
00026   union {
00027     struct {
00028       FILE *file;
00029       int closeit;
00030 #if SHOW_ERROR_LINE
00031       int curr_line;
00032       char *filename;
00033 #endif
00034     } stdio;
00035     struct {
00036       char *start;
00037       char *past_the_end;
00038       char *curr;
00039     } string;
00040   } rep;
00041 } port;
00042 
00043 /* cell structure */
00044 struct cell {
00045   unsigned int _flag;
00046   union {
00047     struct {
00048       char   *_svalue;
00049       int   _length;
00050     } _string;
00051     num _number;
00052     port *_port;
00053     foreign_func _ff;
00054     struct {
00055       struct cell *_car;
00056       struct cell *_cdr;
00057     } _cons;
00058   } _object;
00059 };
00060 
00061 struct scheme {
00062 /* arrays for segments */
00063 func_alloc malloc;
00064 func_dealloc free;
00065 
00066 /* return code */
00067 int retcode;
00068 int tracing;
00069 
00070 
00071 #define CELL_SEGSIZE    5000  /* # of cells in one segment */
00072 #define CELL_NSEGMENT   10    /* # of segments for cells */
00073 char *alloc_seg[CELL_NSEGMENT];
00074 cell_ptr cell_seg[CELL_NSEGMENT];
00075 int     last_cell_seg;
00076 
00077 /* We use 4 registers. */
00078 cell_ptr args;            /* register for arguments of function */
00079 cell_ptr envir;           /* stack register for current environment */
00080 cell_ptr code;            /* register for current code */
00081 cell_ptr dump;            /* stack register for next evaluation */
00082 
00083 int interactive_repl;    /* are we in an interactive REPL? */
00084 
00085 struct cell _sink;
00086 cell_ptr sink;            /* when mem. alloc. fails */
00087 struct cell _NIL;
00088 cell_ptr NIL;             /* special cell representing empty cell */
00089 struct cell _HASHT;
00090 cell_ptr T;               /* special cell representing #t */
00091 struct cell _HASHF;
00092 cell_ptr F;               /* special cell representing #f */
00093 struct cell _EOF_OBJ;
00094 cell_ptr EOF_OBJ;         /* special cell representing end-of-file object */
00095 cell_ptr oblist;          /* pointer to symbol table */
00096 cell_ptr global_env;      /* pointer to global environment */
00097 cell_ptr c_nest;          /* stack for nested calls from C */
00098 
00099 /* global pointers to special symbols */
00100 cell_ptr LAMBDA;               /* pointer to syntax lambda */
00101 cell_ptr QUOTE;           /* pointer to syntax quote */
00102 
00103 cell_ptr QQUOTE;               /* pointer to symbol quasiquote */
00104 cell_ptr UNQUOTE;         /* pointer to symbol unquote */
00105 cell_ptr UNQUOTESP;       /* pointer to symbol unquote-splicing */
00106 cell_ptr FEED_TO;         /* => */
00107 cell_ptr COLON_HOOK;      /* *colon-hook* */
00108 cell_ptr ERROR_HOOK;      /* *error-hook* */
00109 cell_ptr SHARP_HOOK;  /* *sharp-hook* */
00110 cell_ptr COMPILE_HOOK;  /* *compile-hook* */
00111 
00112 cell_ptr free_cell;       /* pointer to top of free cells */
00113 long    fcells;          /* # of free cells */
00114 
00115 cell_ptr inport;
00116 cell_ptr outport;
00117 cell_ptr save_inport;
00118 cell_ptr loadport;
00119 
00120 #define MAXFIL 64
00121 port load_stack[MAXFIL];     /* Stack of open files for port -1 (LOADing) */
00122 int nesting_stack[MAXFIL];
00123 int file_i;
00124 int nesting;
00125 
00126 char    gc_verbose;      /* if gc_verbose is not zero, print gc status */
00127 char    no_memory;       /* Whether mem. alloc. has failed */
00128 
00129 #define LINESIZE 1024
00130 char    linebuff[LINESIZE];
00131 #define STRBUFFSIZE 256
00132 char    strbuff[STRBUFFSIZE];
00133 
00134 FILE *tmpfp;
00135 int tok;
00136 int print_flag;
00137 cell_ptr value;
00138 int op;
00139 
00140 void *ext_data;     /* For the benefit of foreign functions */
00141 long gensym_cnt;
00142 
00143 struct scheme_interface *vptr;
00144 void *dump_base;      /* pointer to base of allocated dump stack */
00145 int dump_size;               /* number of frames allocated for dump stack */
00146 };
00147 
00148 /* operator code */
00149 enum scheme_opcodes {
00150 #define _OP_DEF(A,B,C,D,E,OP) OP,
00151 #include "opdefines.h"
00152   OP_MAXDEFINED
00153 };
00154 
00155 
00156 #define cons(sc,a,b) _cons(sc,a,b,0)
00157 #define immutable_cons(sc,a,b) _cons(sc,a,b,1)
00158 
00159 int is_string(cell_ptr p);
00160 char *string_value(cell_ptr p);
00161 int string_length(cell_ptr p);
00162 int is_number(cell_ptr p);
00163 num nvalue(cell_ptr p);
00164 long ivalue(cell_ptr p);
00165 double rvalue(cell_ptr p);
00166 int is_integer(cell_ptr p);
00167 int is_real(cell_ptr p);
00168 int is_character(cell_ptr p);
00169 long charvalue(cell_ptr p);
00170 int is_vector(cell_ptr p);
00171 int is_blackbox(cell_ptr p);
00172 void *blackboxvalue(cell_ptr p);
00173        
00174 int is_port(cell_ptr p);
00175 
00176 int is_pair(cell_ptr p);
00177 cell_ptr pair_car(cell_ptr p);
00178 cell_ptr pair_cdr(cell_ptr p);
00179 cell_ptr set_car(cell_ptr p, cell_ptr q);
00180 cell_ptr set_cdr(cell_ptr p, cell_ptr q);
00181 
00182 int is_symbol(cell_ptr p);
00183 char *symname(cell_ptr p);
00184 int symlen(cell_ptr p);
00185 int hasprop(cell_ptr p);
00186 
00187 int is_syntax(cell_ptr p);
00188 int is_proc(cell_ptr p);
00189 int is_foreign(cell_ptr p);
00190 char *syntaxname(cell_ptr p);
00191 int is_closure(cell_ptr p);
00192 #ifdef USE_MACRO
00193 int is_macro(cell_ptr p);
00194 #endif
00195 cell_ptr closure_code(cell_ptr p);
00196 cell_ptr closure_env(cell_ptr p);
00197 
00198 int is_continuation(cell_ptr p);
00199 int is_promise(cell_ptr p);
00200 int is_environment(cell_ptr p);
00201 int is_immutable(cell_ptr p);
00202 void setimmutable(cell_ptr p);
00203 
00204 #ifdef __cplusplus
00205 }
00206 #endif
00207 
00208 #endif
00209 
00210 /*
00211 Local variables:
00212 c-file-style: "k&r"
00213 End:
00214 */