… | |
… | |
18 | * |
18 | * |
19 | */ |
19 | */ |
20 | |
20 | |
21 | #define EXPERIMENT 1 |
21 | #define EXPERIMENT 1 |
22 | |
22 | |
|
|
23 | #if 1 |
23 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
24 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
24 | #include "malloc.c" |
25 | #include "malloc.c" |
|
|
26 | #endif |
25 | |
27 | |
26 | #define SCHEME_SOURCE |
28 | #define SCHEME_SOURCE |
27 | #include "scheme-private.h" |
29 | #include "scheme-private.h" |
28 | #ifndef WIN32 |
30 | #ifndef WIN32 |
29 | # include <unistd.h> |
31 | # include <unistd.h> |
… | |
… | |
79 | |
81 | |
80 | #define BACKQUOTE '`' |
82 | #define BACKQUOTE '`' |
81 | #define WHITESPACE " \t\r\n\v\f" |
83 | #define WHITESPACE " \t\r\n\v\f" |
82 | #define DELIMITERS "()\";" WHITESPACE |
84 | #define DELIMITERS "()\";" WHITESPACE |
83 | |
85 | |
84 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
86 | #define NIL POINTER (&SCHEME_V->xNIL) |
85 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
87 | #define S_T POINTER (&SCHEME_V->xT) |
86 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
88 | #define S_F POINTER (&SCHEME_V->xF) |
87 | #define S_SINK (&SCHEME_V->xsink) |
89 | #define S_SINK POINTER (&SCHEME_V->xsink) |
88 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
90 | #define S_EOF POINTER (&SCHEME_V->xEOF_OBJ) |
89 | |
91 | |
90 | #if !USE_MULTIPLICITY |
92 | #if !USE_MULTIPLICITY |
91 | static scheme sc; |
93 | static scheme sc; |
92 | #endif |
94 | #endif |
93 | |
95 | |
… | |
… | |
192 | # define prompt "ts> " |
194 | # define prompt "ts> " |
193 | #endif |
195 | #endif |
194 | |
196 | |
195 | #ifndef InitFile |
197 | #ifndef InitFile |
196 | # define InitFile "init.scm" |
198 | # define InitFile "init.scm" |
197 | #endif |
|
|
198 | |
|
|
199 | #ifndef FIRST_CELLSEGS |
|
|
200 | # define FIRST_CELLSEGS 3 |
|
|
201 | #endif |
199 | #endif |
202 | |
200 | |
203 | enum scheme_types |
201 | enum scheme_types |
204 | { |
202 | { |
205 | T_INTEGER, |
203 | T_INTEGER, |
… | |
… | |
266 | static int is_zero_rvalue (RVALUE x); |
264 | static int is_zero_rvalue (RVALUE x); |
267 | |
265 | |
268 | static num num_zero; |
266 | static num num_zero; |
269 | static num num_one; |
267 | static num num_one; |
270 | |
268 | |
|
|
269 | /* convert "pointer" to cell* / cell* to pointer */ |
|
|
270 | #define CELL(p) ((struct cell *)(p) + 0) |
|
|
271 | #define POINTER(c) ((void *)((c) - 0)) |
|
|
272 | |
271 | /* macros for cell operations */ |
273 | /* macros for cell operations */ |
272 | #define typeflag(p) ((p)->flag + 0) |
274 | #define typeflag(p) (CELL(p)->flag + 0) |
273 | #define set_typeflag(p,v) ((p)->flag = (v)) |
275 | #define set_typeflag(p,v) (CELL(p)->flag = (v)) |
274 | #define type(p) (typeflag (p) & T_MASKTYPE) |
276 | #define type(p) (typeflag (p) & T_MASKTYPE) |
275 | |
277 | |
276 | INTERFACE int |
278 | INTERFACE int |
277 | is_string (pointer p) |
279 | is_string (pointer p) |
278 | { |
280 | { |
279 | return type (p) == T_STRING; |
281 | return type (p) == T_STRING; |
280 | } |
282 | } |
281 | |
283 | |
282 | #define strvalue(p) ((p)->object.string.svalue) |
284 | #define strvalue(p) (CELL(p)->object.string.svalue) |
283 | #define strlength(p) ((p)->object.string.length) |
285 | #define strlength(p) (CELL(p)->object.string.length) |
284 | |
286 | |
285 | INTERFACE int |
287 | INTERFACE int |
286 | is_vector (pointer p) |
288 | is_vector (pointer p) |
287 | { |
289 | { |
288 | return type (p) == T_VECTOR; |
290 | return type (p) == T_VECTOR; |
289 | } |
291 | } |
290 | |
292 | |
291 | #define vecvalue(p) ((p)->object.vector.vvalue) |
293 | #define vecvalue(p) (CELL(p)->object.vector.vvalue) |
292 | #define veclength(p) ((p)->object.vector.length) |
294 | #define veclength(p) (CELL(p)->object.vector.length) |
293 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
295 | INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj); |
294 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
296 | INTERFACE pointer vector_get (pointer vec, uint32_t ielem); |
295 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
297 | INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a); |
296 | |
298 | |
297 | INTERFACE int |
299 | INTERFACE int |
… | |
… | |
323 | string_value (pointer p) |
325 | string_value (pointer p) |
324 | { |
326 | { |
325 | return strvalue (p); |
327 | return strvalue (p); |
326 | } |
328 | } |
327 | |
329 | |
328 | #define ivalue_unchecked(p) (p)->object.ivalue |
330 | #define ivalue_unchecked(p) CELL(p)->object.ivalue |
329 | #define set_ivalue(p,v) (p)->object.ivalue = (v) |
331 | #define set_ivalue(p,v) CELL(p)->object.ivalue = (v) |
330 | |
332 | |
331 | #if USE_REAL |
333 | #if USE_REAL |
332 | #define rvalue_unchecked(p) (p)->object.rvalue |
334 | #define rvalue_unchecked(p) CELL(p)->object.rvalue |
333 | #define set_rvalue(p,v) (p)->object.rvalue = (v) |
335 | #define set_rvalue(p,v) CELL(p)->object.rvalue = (v) |
334 | #else |
336 | #else |
335 | #define rvalue_unchecked(p) (p)->object.ivalue |
337 | #define rvalue_unchecked(p) CELL(p)->object.ivalue |
336 | #define set_rvalue(p,v) (p)->object.ivalue = (v) |
338 | #define set_rvalue(p,v) CELL(p)->object.ivalue = (v) |
337 | #endif |
339 | #endif |
338 | |
340 | |
339 | INTERFACE long |
341 | INTERFACE long |
340 | charvalue (pointer p) |
342 | charvalue (pointer p) |
341 | { |
343 | { |
342 | return ivalue_unchecked (p); |
344 | return ivalue_unchecked (p); |
343 | } |
345 | } |
344 | |
346 | |
|
|
347 | #define port(p) CELL(p)->object.port |
|
|
348 | #define set_port(p,v) port(p) = (v) |
345 | INTERFACE int |
349 | INTERFACE int |
346 | is_port (pointer p) |
350 | is_port (pointer p) |
347 | { |
351 | { |
348 | return type (p) == T_PORT; |
352 | return type (p) == T_PORT; |
349 | } |
353 | } |
350 | |
354 | |
351 | INTERFACE int |
355 | INTERFACE int |
352 | is_inport (pointer p) |
356 | is_inport (pointer p) |
353 | { |
357 | { |
354 | return is_port (p) && p->object.port->kind & port_input; |
358 | return is_port (p) && port (p)->kind & port_input; |
355 | } |
359 | } |
356 | |
360 | |
357 | INTERFACE int |
361 | INTERFACE int |
358 | is_outport (pointer p) |
362 | is_outport (pointer p) |
359 | { |
363 | { |
360 | return is_port (p) && p->object.port->kind & port_output; |
364 | return is_port (p) && port (p)->kind & port_output; |
361 | } |
365 | } |
362 | |
366 | |
363 | INTERFACE int |
367 | INTERFACE int |
364 | is_pair (pointer p) |
368 | is_pair (pointer p) |
365 | { |
369 | { |
366 | return type (p) == T_PAIR; |
370 | return type (p) == T_PAIR; |
367 | } |
371 | } |
368 | |
372 | |
369 | #define car(p) ((p)->object.cons.car + 0) |
373 | #define car(p) (POINTER (CELL(p)->object.cons.car)) |
370 | #define cdr(p) ((p)->object.cons.cdr + 0) |
374 | #define cdr(p) (POINTER (CELL(p)->object.cons.cdr)) |
371 | |
375 | |
372 | static pointer caar (pointer p) { return car (car (p)); } |
376 | static pointer caar (pointer p) { return car (car (p)); } |
373 | static pointer cadr (pointer p) { return car (cdr (p)); } |
377 | static pointer cadr (pointer p) { return car (cdr (p)); } |
374 | static pointer cdar (pointer p) { return cdr (car (p)); } |
378 | static pointer cdar (pointer p) { return cdr (car (p)); } |
375 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
379 | static pointer cddr (pointer p) { return cdr (cdr (p)); } |
… | |
… | |
379 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
383 | static pointer cdaar (pointer p) { return cdr (car (car (p))); } |
380 | |
384 | |
381 | INTERFACE void |
385 | INTERFACE void |
382 | set_car (pointer p, pointer q) |
386 | set_car (pointer p, pointer q) |
383 | { |
387 | { |
384 | p->object.cons.car = q; |
388 | CELL(p)->object.cons.car = CELL (q); |
385 | } |
389 | } |
386 | |
390 | |
387 | INTERFACE void |
391 | INTERFACE void |
388 | set_cdr (pointer p, pointer q) |
392 | set_cdr (pointer p, pointer q) |
389 | { |
393 | { |
390 | p->object.cons.cdr = q; |
394 | CELL(p)->object.cons.cdr = CELL (q); |
391 | } |
395 | } |
392 | |
396 | |
393 | INTERFACE pointer |
397 | INTERFACE pointer |
394 | pair_car (pointer p) |
398 | pair_car (pointer p) |
395 | { |
399 | { |
… | |
… | |
413 | { |
417 | { |
414 | return strvalue (p); |
418 | return strvalue (p); |
415 | } |
419 | } |
416 | |
420 | |
417 | #if USE_PLIST |
421 | #if USE_PLIST |
|
|
422 | #error plists are broken because symbols are no longer pairs |
418 | #define symprop(p) cdr(p) |
423 | #define symprop(p) cdr(p) |
419 | SCHEME_EXPORT int |
424 | SCHEME_EXPORT int |
420 | hasprop (pointer p) |
425 | hasprop (pointer p) |
421 | { |
426 | { |
422 | return typeflag (p) & T_SYMBOL; |
427 | return typeflag (p) & T_SYMBOL; |
… | |
… | |
669 | |
674 | |
670 | static int file_push (SCHEME_P_ const char *fname); |
675 | static int file_push (SCHEME_P_ const char *fname); |
671 | static void file_pop (SCHEME_P); |
676 | static void file_pop (SCHEME_P); |
672 | static int file_interactive (SCHEME_P); |
677 | static int file_interactive (SCHEME_P); |
673 | ecb_inline int is_one_of (const char *s, int c); |
678 | ecb_inline int is_one_of (const char *s, int c); |
674 | static int alloc_cellseg (SCHEME_P_ int n); |
679 | static int alloc_cellseg (SCHEME_P); |
675 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
680 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
676 | static void finalize_cell (SCHEME_P_ pointer a); |
681 | static void finalize_cell (SCHEME_P_ pointer a); |
677 | static int count_consecutive_cells (pointer x, int needed); |
682 | static int count_consecutive_cells (pointer x, int needed); |
678 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
683 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
679 | static pointer mk_number (SCHEME_P_ const num n); |
684 | static pointer mk_number (SCHEME_P_ const num n); |
… | |
… | |
913 | #endif |
918 | #endif |
914 | } |
919 | } |
915 | |
920 | |
916 | /* allocate new cell segment */ |
921 | /* allocate new cell segment */ |
917 | static int |
922 | static int |
918 | alloc_cellseg (SCHEME_P_ int n) |
923 | alloc_cellseg (SCHEME_P) |
919 | { |
924 | { |
920 | pointer newp; |
925 | struct cell *newp; |
921 | pointer last; |
926 | struct cell *last; |
922 | pointer p; |
927 | struct cell *p; |
923 | char *cp; |
928 | char *cp; |
924 | long i; |
929 | long i; |
925 | int k; |
930 | int k; |
926 | |
931 | |
927 | static int segsize = CELL_SEGSIZE >> 1; |
932 | static int segsize = CELL_SEGSIZE >> 1; |
928 | segsize <<= 1; |
933 | segsize <<= 1; |
929 | |
934 | |
930 | for (k = 0; k < n; k++) |
|
|
931 | { |
|
|
932 | if (SCHEME_V->last_cell_seg >= CELL_NSEGMENT - 1) |
|
|
933 | return k; |
|
|
934 | |
|
|
935 | cp = malloc (segsize * sizeof (struct cell)); |
935 | cp = malloc (segsize * sizeof (struct cell)); |
936 | |
936 | |
937 | if (!cp && USE_ERROR_CHECKING) |
937 | if (!cp && USE_ERROR_CHECKING) |
938 | return k; |
938 | return k; |
939 | |
939 | |
940 | i = ++SCHEME_V->last_cell_seg; |
940 | i = ++SCHEME_V->last_cell_seg; |
941 | SCHEME_V->alloc_seg[i] = cp; |
941 | SCHEME_V->alloc_seg[i] = cp; |
942 | |
942 | |
943 | newp = (pointer)cp; |
943 | newp = (struct cell *)cp; |
944 | SCHEME_V->cell_seg[i] = newp; |
944 | SCHEME_V->cell_seg[i] = newp; |
945 | SCHEME_V->cell_segsize[i] = segsize; |
945 | SCHEME_V->cell_segsize[i] = segsize; |
946 | SCHEME_V->fcells += segsize; |
946 | SCHEME_V->fcells += segsize; |
947 | last = newp + segsize - 1; |
947 | last = newp + segsize - 1; |
948 | |
948 | |
949 | for (p = newp; p <= last; p++) |
949 | for (p = newp; p <= last; p++) |
950 | { |
950 | { |
|
|
951 | pointer cp = POINTER (p); |
951 | set_typeflag (p, T_PAIR); |
952 | set_typeflag (cp, T_PAIR); |
952 | set_car (p, NIL); |
953 | set_car (cp, NIL); |
953 | set_cdr (p, p + 1); |
954 | set_cdr (cp, POINTER (p + 1)); |
954 | } |
955 | } |
955 | |
956 | |
956 | set_cdr (last, SCHEME_V->free_cell); |
957 | set_cdr (POINTER (last), SCHEME_V->free_cell); |
957 | SCHEME_V->free_cell = newp; |
958 | SCHEME_V->free_cell = POINTER (newp); |
958 | } |
|
|
959 | |
959 | |
960 | return n; |
960 | return 1; |
961 | } |
961 | } |
962 | |
962 | |
963 | /* get new cell. parameter a, b is marked by gc. */ |
963 | /* get new cell. parameter a, b is marked by gc. */ |
964 | ecb_inline pointer |
964 | ecb_inline pointer |
965 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
965 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
… | |
… | |
976 | gc (SCHEME_A_ a, b); |
976 | gc (SCHEME_A_ a, b); |
977 | |
977 | |
978 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
978 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
979 | { |
979 | { |
980 | /* if only a few recovered, get more to avoid fruitless gc's */ |
980 | /* if only a few recovered, get more to avoid fruitless gc's */ |
981 | if (!alloc_cellseg (SCHEME_A_ 1) && SCHEME_V->free_cell == NIL) |
981 | if (!alloc_cellseg (SCHEME_A) && SCHEME_V->free_cell == NIL) |
982 | { |
982 | { |
983 | #if USE_ERROR_CHECKING |
983 | #if USE_ERROR_CHECKING |
984 | SCHEME_V->no_memory = 1; |
984 | SCHEME_V->no_memory = 1; |
985 | return S_SINK; |
985 | return S_SINK; |
986 | #endif |
986 | #endif |
… | |
… | |
998 | } |
998 | } |
999 | } |
999 | } |
1000 | |
1000 | |
1001 | /* To retain recent allocs before interpreter knows about them - |
1001 | /* To retain recent allocs before interpreter knows about them - |
1002 | Tehom */ |
1002 | Tehom */ |
1003 | |
|
|
1004 | static void |
1003 | static void |
1005 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
1004 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
1006 | { |
1005 | { |
1007 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1006 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
1008 | |
1007 | |
… | |
… | |
1039 | return S_SINK; |
1038 | return S_SINK; |
1040 | |
1039 | |
1041 | /* Record it as a vector so that gc understands it. */ |
1040 | /* Record it as a vector so that gc understands it. */ |
1042 | set_typeflag (v, T_VECTOR | T_ATOM); |
1041 | set_typeflag (v, T_VECTOR | T_ATOM); |
1043 | |
1042 | |
1044 | v->object.vector.vvalue = e; |
1043 | CELL(v)->object.vector.vvalue = e; |
1045 | v->object.vector.length = len; |
1044 | CELL(v)->object.vector.length = len; |
1046 | fill_vector (v, 0, init); |
1045 | fill_vector (v, 0, init); |
1047 | push_recent_alloc (SCHEME_A_ v, NIL); |
1046 | push_recent_alloc (SCHEME_A_ v, NIL); |
1048 | |
1047 | |
1049 | return v; |
1048 | return v; |
1050 | } |
1049 | } |
… | |
… | |
1200 | |
1199 | |
1201 | /* returns the new symbol */ |
1200 | /* returns the new symbol */ |
1202 | static pointer |
1201 | static pointer |
1203 | oblist_add_by_name (SCHEME_P_ const char *name) |
1202 | oblist_add_by_name (SCHEME_P_ const char *name) |
1204 | { |
1203 | { |
1205 | pointer x = mk_string (SCHEME_A_ name); |
1204 | pointer x = generate_symbol (SCHEME_A_ name); |
1206 | set_typeflag (x, T_SYMBOL); |
|
|
1207 | setimmutable (x); |
|
|
1208 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1205 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1209 | return x; |
1206 | return x; |
1210 | } |
1207 | } |
1211 | |
1208 | |
1212 | static pointer |
1209 | static pointer |
… | |
… | |
1222 | mk_port (SCHEME_P_ port *p) |
1219 | mk_port (SCHEME_P_ port *p) |
1223 | { |
1220 | { |
1224 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1221 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1225 | |
1222 | |
1226 | set_typeflag (x, T_PORT | T_ATOM); |
1223 | set_typeflag (x, T_PORT | T_ATOM); |
1227 | x->object.port = p; |
1224 | set_port (x, p); |
1228 | |
1225 | |
1229 | return x; |
1226 | return x; |
1230 | } |
1227 | } |
1231 | #endif |
1228 | #endif |
1232 | |
1229 | |
1233 | pointer |
1230 | pointer |
1234 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1231 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1235 | { |
1232 | { |
1236 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1233 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1237 | |
1234 | |
1238 | set_typeflag (x, (T_FOREIGN | T_ATOM)); |
1235 | set_typeflag (x, T_FOREIGN | T_ATOM); |
1239 | x->object.ff = f; |
1236 | CELL(x)->object.ff = f; |
1240 | |
1237 | |
1241 | return x; |
1238 | return x; |
1242 | } |
1239 | } |
1243 | |
1240 | |
1244 | INTERFACE pointer |
1241 | INTERFACE pointer |
1245 | mk_character (SCHEME_P_ int c) |
1242 | mk_character (SCHEME_P_ int c) |
1246 | { |
1243 | { |
1247 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1244 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1248 | |
1245 | |
1249 | set_typeflag (x, (T_CHARACTER | T_ATOM)); |
1246 | set_typeflag (x, T_CHARACTER | T_ATOM); |
1250 | set_ivalue (x, c & 0xff); |
1247 | set_ivalue (x, c & 0xff); |
1251 | |
1248 | |
1252 | return x; |
1249 | return x; |
1253 | } |
1250 | } |
1254 | |
1251 | |
1255 | /* get number atom (integer) */ |
1252 | /* get number atom (integer) */ |
1256 | INTERFACE pointer |
1253 | INTERFACE pointer |
1257 | mk_integer (SCHEME_P_ long n) |
1254 | mk_integer (SCHEME_P_ long n) |
1258 | { |
1255 | { |
|
|
1256 | pointer p = 0; |
|
|
1257 | pointer *pp = &p; |
|
|
1258 | |
|
|
1259 | #if USE_INTCACHE |
|
|
1260 | if (n >= INTCACHE_MIN && n <= INTCACHE_MAX) |
|
|
1261 | pp = &SCHEME_V->intcache[n - INTCACHE_MIN]; |
|
|
1262 | #endif |
|
|
1263 | |
|
|
1264 | if (!*pp) |
|
|
1265 | { |
1259 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1266 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1260 | |
1267 | |
1261 | set_typeflag (x, (T_INTEGER | T_ATOM)); |
1268 | set_typeflag (x, T_INTEGER | T_ATOM); |
|
|
1269 | setimmutable (x); /* shouldn't do anythi9ng, doesn't cost anything */ |
1262 | set_ivalue (x, n); |
1270 | set_ivalue (x, n); |
1263 | |
1271 | |
|
|
1272 | *pp = x; |
|
|
1273 | } |
|
|
1274 | |
1264 | return x; |
1275 | return *pp; |
1265 | } |
1276 | } |
1266 | |
1277 | |
1267 | INTERFACE pointer |
1278 | INTERFACE pointer |
1268 | mk_real (SCHEME_P_ RVALUE n) |
1279 | mk_real (SCHEME_P_ RVALUE n) |
1269 | { |
1280 | { |
1270 | #if USE_REAL |
1281 | #if USE_REAL |
1271 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1282 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1272 | |
1283 | |
1273 | set_typeflag (x, (T_REAL | T_ATOM)); |
1284 | set_typeflag (x, T_REAL | T_ATOM); |
1274 | set_rvalue (x, n); |
1285 | set_rvalue (x, n); |
1275 | |
1286 | |
1276 | return x; |
1287 | return x; |
1277 | #else |
1288 | #else |
1278 | return mk_integer (SCHEME_A_ n); |
1289 | return mk_integer (SCHEME_A_ n); |
… | |
… | |
1621 | |
1632 | |
1622 | /* garbage collection. parameter a, b is marked. */ |
1633 | /* garbage collection. parameter a, b is marked. */ |
1623 | static void |
1634 | static void |
1624 | gc (SCHEME_P_ pointer a, pointer b) |
1635 | gc (SCHEME_P_ pointer a, pointer b) |
1625 | { |
1636 | { |
1626 | pointer p; |
|
|
1627 | int i; |
1637 | int i; |
1628 | |
1638 | |
1629 | if (SCHEME_V->gc_verbose) |
1639 | if (SCHEME_V->gc_verbose) |
1630 | putstr (SCHEME_A_ "gc..."); |
1640 | putstr (SCHEME_A_ "gc..."); |
1631 | |
1641 | |
… | |
… | |
1647 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1657 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1648 | mark (car (S_SINK)); |
1658 | mark (car (S_SINK)); |
1649 | /* Mark any older stuff above nested C calls */ |
1659 | /* Mark any older stuff above nested C calls */ |
1650 | mark (SCHEME_V->c_nest); |
1660 | mark (SCHEME_V->c_nest); |
1651 | |
1661 | |
|
|
1662 | #if USE_INTCACHE |
|
|
1663 | /* mark intcache */ |
|
|
1664 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1665 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1666 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
|
|
1667 | #endif |
|
|
1668 | |
1652 | /* mark variables a, b */ |
1669 | /* mark variables a, b */ |
1653 | mark (a); |
1670 | mark (a); |
1654 | mark (b); |
1671 | mark (b); |
1655 | |
1672 | |
1656 | /* garbage collect */ |
1673 | /* garbage collect */ |
… | |
… | |
1664 | uint32_t total = 0; |
1681 | uint32_t total = 0; |
1665 | |
1682 | |
1666 | /* Here we scan the cells to build the free-list. */ |
1683 | /* Here we scan the cells to build the free-list. */ |
1667 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1684 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1668 | { |
1685 | { |
1669 | pointer end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
1686 | struct cell *end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
|
|
1687 | struct cell *p; |
1670 | total += SCHEME_V->cell_segsize [i]; |
1688 | total += SCHEME_V->cell_segsize [i]; |
1671 | |
1689 | |
1672 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1690 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1673 | { |
1691 | { |
|
|
1692 | pointer c = POINTER (p); |
|
|
1693 | |
1674 | if (is_mark (p)) |
1694 | if (is_mark (c)) |
1675 | clrmark (p); |
1695 | clrmark (c); |
1676 | else |
1696 | else |
1677 | { |
1697 | { |
1678 | /* reclaim cell */ |
1698 | /* reclaim cell */ |
1679 | if (typeflag (p) != T_PAIR) |
1699 | if (typeflag (c) != T_PAIR) |
1680 | { |
1700 | { |
1681 | finalize_cell (SCHEME_A_ p); |
1701 | finalize_cell (SCHEME_A_ c); |
1682 | set_typeflag (p, T_PAIR); |
1702 | set_typeflag (c, T_PAIR); |
1683 | set_car (p, NIL); |
1703 | set_car (c, NIL); |
1684 | } |
1704 | } |
1685 | |
1705 | |
1686 | ++SCHEME_V->fcells; |
1706 | ++SCHEME_V->fcells; |
1687 | set_cdr (p, SCHEME_V->free_cell); |
1707 | set_cdr (c, SCHEME_V->free_cell); |
1688 | SCHEME_V->free_cell = p; |
1708 | SCHEME_V->free_cell = c; |
1689 | } |
1709 | } |
1690 | } |
1710 | } |
1691 | } |
1711 | } |
1692 | |
1712 | |
1693 | if (SCHEME_V->gc_verbose) |
1713 | if (SCHEME_V->gc_verbose) |
… | |
… | |
1705 | else if (is_vector (a)) |
1725 | else if (is_vector (a)) |
1706 | free (vecvalue (a)); |
1726 | free (vecvalue (a)); |
1707 | #if USE_PORTS |
1727 | #if USE_PORTS |
1708 | else if (is_port (a)) |
1728 | else if (is_port (a)) |
1709 | { |
1729 | { |
1710 | if (a->object.port->kind & port_file && a->object.port->rep.stdio.closeit) |
1730 | if (port(a)->kind & port_file && port (a)->rep.stdio.closeit) |
1711 | port_close (SCHEME_A_ a, port_input | port_output); |
1731 | port_close (SCHEME_A_ a, port_input | port_output); |
1712 | |
1732 | |
1713 | free (a->object.port); |
1733 | free (port (a)); |
1714 | } |
1734 | } |
1715 | #endif |
1735 | #endif |
1716 | } |
1736 | } |
1717 | |
1737 | |
1718 | /* ========== Routines for Reading ========== */ |
1738 | /* ========== Routines for Reading ========== */ |
… | |
… | |
1734 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1754 | SCHEME_V->load_stack[SCHEME_V->file_i].unget = -1; |
1735 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1755 | SCHEME_V->load_stack[SCHEME_V->file_i].kind = port_file | port_input; |
1736 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1756 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.file = fin; |
1737 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1757 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.closeit = 1; |
1738 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1758 | SCHEME_V->nesting_stack[SCHEME_V->file_i] = 0; |
1739 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1759 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1740 | |
1760 | |
1741 | #if SHOW_ERROR_LINE |
1761 | #if SHOW_ERROR_LINE |
1742 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1762 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line = 0; |
1743 | |
1763 | |
1744 | if (fname) |
1764 | if (fname) |
… | |
… | |
1761 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1781 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1762 | #if USE_PORTS |
1782 | #if USE_PORTS |
1763 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1783 | port_close (SCHEME_A_ SCHEME_V->loadport, port_input); |
1764 | #endif |
1784 | #endif |
1765 | SCHEME_V->file_i--; |
1785 | SCHEME_V->file_i--; |
1766 | SCHEME_V->loadport->object.port = SCHEME_V->load_stack + SCHEME_V->file_i; |
1786 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1767 | } |
1787 | } |
1768 | } |
1788 | } |
1769 | |
1789 | |
1770 | static int |
1790 | static int |
1771 | file_interactive (SCHEME_P) |
1791 | file_interactive (SCHEME_P) |
1772 | { |
1792 | { |
1773 | #if USE_PORTS |
1793 | #if USE_PORTS |
1774 | return SCHEME_V->file_i == 0 |
1794 | return SCHEME_V->file_i == 0 |
1775 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1795 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1776 | && (SCHEME_V->inport->object.port->kind & port_file); |
1796 | && (port (SCHEME_V->inport)->kind & port_file); |
1777 | #else |
1797 | #else |
1778 | return 0; |
1798 | return 0; |
1779 | #endif |
1799 | #endif |
1780 | } |
1800 | } |
1781 | |
1801 | |
… | |
… | |
1915 | } |
1935 | } |
1916 | |
1936 | |
1917 | static void |
1937 | static void |
1918 | port_close (SCHEME_P_ pointer p, int flag) |
1938 | port_close (SCHEME_P_ pointer p, int flag) |
1919 | { |
1939 | { |
1920 | port *pt = p->object.port; |
1940 | port *pt = port (p); |
1921 | |
1941 | |
1922 | pt->kind &= ~flag; |
1942 | pt->kind &= ~flag; |
1923 | |
1943 | |
1924 | if ((pt->kind & (port_input | port_output)) == 0) |
1944 | if ((pt->kind & (port_input | port_output)) == 0) |
1925 | { |
1945 | { |
… | |
… | |
1946 | /* get new character from input file */ |
1966 | /* get new character from input file */ |
1947 | static int |
1967 | static int |
1948 | inchar (SCHEME_P) |
1968 | inchar (SCHEME_P) |
1949 | { |
1969 | { |
1950 | int c; |
1970 | int c; |
1951 | port *pt; |
1971 | port *pt = port (SCHEME_V->inport); |
1952 | |
|
|
1953 | pt = SCHEME_V->inport->object.port; |
|
|
1954 | |
1972 | |
1955 | if (pt->kind & port_saw_EOF) |
1973 | if (pt->kind & port_saw_EOF) |
1956 | return EOF; |
1974 | return EOF; |
1957 | |
1975 | |
1958 | c = basic_inchar (pt); |
1976 | c = basic_inchar (pt); |
… | |
… | |
2025 | port *pt; |
2043 | port *pt; |
2026 | |
2044 | |
2027 | if (c == EOF) |
2045 | if (c == EOF) |
2028 | return; |
2046 | return; |
2029 | |
2047 | |
2030 | pt = SCHEME_V->inport->object.port; |
2048 | pt = port (SCHEME_V->inport); |
2031 | pt->unget = c; |
2049 | pt->unget = c; |
2032 | #else |
2050 | #else |
2033 | if (c == EOF) |
2051 | if (c == EOF) |
2034 | return; |
2052 | return; |
2035 | |
2053 | |
… | |
… | |
2063 | |
2081 | |
2064 | INTERFACE void |
2082 | INTERFACE void |
2065 | putstr (SCHEME_P_ const char *s) |
2083 | putstr (SCHEME_P_ const char *s) |
2066 | { |
2084 | { |
2067 | #if USE_PORTS |
2085 | #if USE_PORTS |
2068 | port *pt = SCHEME_V->outport->object.port; |
2086 | port *pt = port (SCHEME_V->outport); |
2069 | |
2087 | |
2070 | if (pt->kind & port_file) |
2088 | if (pt->kind & port_file) |
2071 | write (pt->rep.stdio.file, s, strlen (s)); |
2089 | write (pt->rep.stdio.file, s, strlen (s)); |
2072 | else |
2090 | else |
2073 | for (; *s; s++) |
2091 | for (; *s; s++) |
… | |
… | |
2083 | |
2101 | |
2084 | static void |
2102 | static void |
2085 | putchars (SCHEME_P_ const char *s, int len) |
2103 | putchars (SCHEME_P_ const char *s, int len) |
2086 | { |
2104 | { |
2087 | #if USE_PORTS |
2105 | #if USE_PORTS |
2088 | port *pt = SCHEME_V->outport->object.port; |
2106 | port *pt = port (SCHEME_V->outport); |
2089 | |
2107 | |
2090 | if (pt->kind & port_file) |
2108 | if (pt->kind & port_file) |
2091 | write (pt->rep.stdio.file, s, len); |
2109 | write (pt->rep.stdio.file, s, len); |
2092 | else |
2110 | else |
2093 | { |
2111 | { |
… | |
… | |
2107 | |
2125 | |
2108 | INTERFACE void |
2126 | INTERFACE void |
2109 | putcharacter (SCHEME_P_ int c) |
2127 | putcharacter (SCHEME_P_ int c) |
2110 | { |
2128 | { |
2111 | #if USE_PORTS |
2129 | #if USE_PORTS |
2112 | port *pt = SCHEME_V->outport->object.port; |
2130 | port *pt = port (SCHEME_V->outport); |
2113 | |
2131 | |
2114 | if (pt->kind & port_file) |
2132 | if (pt->kind & port_file) |
2115 | { |
2133 | { |
2116 | char cc = c; |
2134 | char cc = c; |
2117 | write (pt->rep.stdio.file, &cc, 1); |
2135 | write (pt->rep.stdio.file, &cc, 1); |
… | |
… | |
3059 | { |
3077 | { |
3060 | int nframes = (uintptr_t)SCHEME_V->dump; |
3078 | int nframes = (uintptr_t)SCHEME_V->dump; |
3061 | struct dump_stack_frame *next_frame; |
3079 | struct dump_stack_frame *next_frame; |
3062 | |
3080 | |
3063 | /* enough room for the next frame? */ |
3081 | /* enough room for the next frame? */ |
3064 | if (nframes >= SCHEME_V->dump_size) |
3082 | if (ecb_expect_false (nframes >= SCHEME_V->dump_size)) |
3065 | { |
3083 | { |
3066 | SCHEME_V->dump_size += STACK_GROWTH; |
3084 | SCHEME_V->dump_size += STACK_GROWTH; |
3067 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3085 | SCHEME_V->dump_base = realloc (SCHEME_V->dump_base, sizeof (struct dump_stack_frame) * SCHEME_V->dump_size); |
3068 | } |
3086 | } |
3069 | |
3087 | |
… | |
… | |
3326 | #endif |
3344 | #endif |
3327 | case OP_LOAD: /* load */ |
3345 | case OP_LOAD: /* load */ |
3328 | if (file_interactive (SCHEME_A)) |
3346 | if (file_interactive (SCHEME_A)) |
3329 | { |
3347 | { |
3330 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3348 | xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); |
3331 | //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3349 | //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3332 | } |
3350 | } |
3333 | |
3351 | |
3334 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3352 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3335 | Error_1 ("unable to open", car (args)); |
3353 | Error_1 ("unable to open", car (args)); |
3336 | else |
3354 | else |
… | |
… | |
3340 | } |
3358 | } |
3341 | |
3359 | |
3342 | case OP_T0LVL: /* top level */ |
3360 | case OP_T0LVL: /* top level */ |
3343 | |
3361 | |
3344 | /* If we reached the end of file, this loop is done. */ |
3362 | /* If we reached the end of file, this loop is done. */ |
3345 | if (SCHEME_V->loadport->object.port->kind & port_saw_EOF) |
3363 | if (port (SCHEME_V->loadport)->kind & port_saw_EOF) |
3346 | { |
3364 | { |
3347 | if (SCHEME_V->file_i == 0) |
3365 | if (SCHEME_V->file_i == 0) |
3348 | { |
3366 | { |
3349 | SCHEME_V->args = NIL; |
3367 | SCHEME_V->args = NIL; |
3350 | s_goto (OP_QUIT); |
3368 | s_goto (OP_QUIT); |
… | |
… | |
3428 | #endif |
3446 | #endif |
3429 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3447 | if (is_symbol (SCHEME_V->code)) /* symbol */ |
3430 | { |
3448 | { |
3431 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3449 | x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->code, 1); |
3432 | |
3450 | |
3433 | if (x != NIL) |
3451 | if (x == NIL) |
3434 | s_return (slot_value_in_env (x)); |
|
|
3435 | else |
|
|
3436 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
3452 | Error_1 ("eval: unbound variable:", SCHEME_V->code); |
|
|
3453 | |
|
|
3454 | s_return (slot_value_in_env (x)); |
3437 | } |
3455 | } |
3438 | else if (is_pair (SCHEME_V->code)) |
3456 | else if (is_pair (SCHEME_V->code)) |
3439 | { |
3457 | { |
3440 | x = car (SCHEME_V->code); |
3458 | x = car (SCHEME_V->code); |
3441 | |
3459 | |
… | |
… | |
3518 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3536 | s_goto (procnum (SCHEME_V->code)); /* PROCEDURE */ |
3519 | else if (is_foreign (SCHEME_V->code)) |
3537 | else if (is_foreign (SCHEME_V->code)) |
3520 | { |
3538 | { |
3521 | /* Keep nested calls from GC'ing the arglist */ |
3539 | /* Keep nested calls from GC'ing the arglist */ |
3522 | push_recent_alloc (SCHEME_A_ args, NIL); |
3540 | push_recent_alloc (SCHEME_A_ args, NIL); |
3523 | x = SCHEME_V->code->object.ff (SCHEME_A_ args); |
3541 | x = CELL(SCHEME_V->code)->object.ff (SCHEME_A_ args); |
3524 | |
3542 | |
3525 | s_return (x); |
3543 | s_return (x); |
3526 | } |
3544 | } |
3527 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3545 | else if (is_closure (SCHEME_V->code) || is_macro (SCHEME_V->code) || is_promise (SCHEME_V->code)) /* CLOSURE */ |
3528 | { |
3546 | { |
… | |
… | |
3565 | |
3583 | |
3566 | case OP_DOMACRO: /* do macro */ |
3584 | case OP_DOMACRO: /* do macro */ |
3567 | SCHEME_V->code = SCHEME_V->value; |
3585 | SCHEME_V->code = SCHEME_V->value; |
3568 | s_goto (OP_EVAL); |
3586 | s_goto (OP_EVAL); |
3569 | |
3587 | |
3570 | #if 1 |
|
|
3571 | |
|
|
3572 | case OP_LAMBDA: /* lambda */ |
3588 | case OP_LAMBDA: /* lambda */ |
3573 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3589 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3574 | set SCHEME_V->value fall thru */ |
3590 | set SCHEME_V->value fall thru */ |
3575 | { |
3591 | { |
3576 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
3592 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
… | |
… | |
3582 | SCHEME_V->code = slot_value_in_env (f); |
3598 | SCHEME_V->code = slot_value_in_env (f); |
3583 | s_goto (OP_APPLY); |
3599 | s_goto (OP_APPLY); |
3584 | } |
3600 | } |
3585 | |
3601 | |
3586 | SCHEME_V->value = SCHEME_V->code; |
3602 | SCHEME_V->value = SCHEME_V->code; |
3587 | /* Fallthru */ |
|
|
3588 | } |
3603 | } |
|
|
3604 | /* Fallthru */ |
3589 | |
3605 | |
3590 | case OP_LAMBDA1: |
3606 | case OP_LAMBDA1: |
3591 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3607 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3592 | |
|
|
3593 | #else |
|
|
3594 | |
|
|
3595 | case OP_LAMBDA: /* lambda */ |
|
|
3596 | s_return (mk_closure (SCHEME_A_ SCHEME_V->code, SCHEME_V->envir)); |
|
|
3597 | |
|
|
3598 | #endif |
|
|
3599 | |
3608 | |
3600 | case OP_MKCLOSURE: /* make-closure */ |
3609 | case OP_MKCLOSURE: /* make-closure */ |
3601 | x = car (args); |
3610 | x = car (args); |
3602 | |
3611 | |
3603 | if (car (x) == SCHEME_V->LAMBDA) |
3612 | if (car (x) == SCHEME_V->LAMBDA) |
… | |
… | |
4631 | } |
4640 | } |
4632 | else |
4641 | else |
4633 | s_return (SCHEME_V->code); |
4642 | s_return (SCHEME_V->code); |
4634 | |
4643 | |
4635 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4644 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4636 | memcpy (SCHEME_V->code, SCHEME_V->value, sizeof (struct cell)); |
4645 | *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); |
4637 | s_return (SCHEME_V->value); |
4646 | s_return (SCHEME_V->value); |
4638 | |
4647 | |
4639 | #if USE_PORTS |
4648 | #if USE_PORTS |
4640 | |
4649 | |
4641 | case OP_WRITE: /* write */ |
4650 | case OP_WRITE: /* write */ |
… | |
… | |
4786 | SCHEME_V->gc_verbose = (a != S_F); |
4795 | SCHEME_V->gc_verbose = (a != S_F); |
4787 | s_retbool (was); |
4796 | s_retbool (was); |
4788 | } |
4797 | } |
4789 | |
4798 | |
4790 | case OP_NEWSEGMENT: /* new-segment */ |
4799 | case OP_NEWSEGMENT: /* new-segment */ |
|
|
4800 | #if 0 |
4791 | if (!is_pair (args) || !is_number (a)) |
4801 | if (!is_pair (args) || !is_number (a)) |
4792 | Error_0 ("new-segment: argument must be a number"); |
4802 | Error_0 ("new-segment: argument must be a number"); |
4793 | |
4803 | #endif |
4794 | alloc_cellseg (SCHEME_A_ ivalue (a)); |
4804 | s_retbool (alloc_cellseg (SCHEME_A)); |
4795 | |
|
|
4796 | s_return (S_T); |
|
|
4797 | |
4805 | |
4798 | case OP_OBLIST: /* oblist */ |
4806 | case OP_OBLIST: /* oblist */ |
4799 | s_return (oblist_all_symbols (SCHEME_A)); |
4807 | s_return (oblist_all_symbols (SCHEME_A)); |
4800 | |
4808 | |
4801 | #if USE_PORTS |
4809 | #if USE_PORTS |
… | |
… | |
4871 | s_return (p == NIL ? S_F : p); |
4879 | s_return (p == NIL ? S_F : p); |
4872 | } |
4880 | } |
4873 | |
4881 | |
4874 | case OP_GET_OUTSTRING: /* get-output-string */ |
4882 | case OP_GET_OUTSTRING: /* get-output-string */ |
4875 | { |
4883 | { |
4876 | port *p; |
4884 | port *p = port (a); |
4877 | |
4885 | |
4878 | if ((p = a->object.port)->kind & port_string) |
4886 | if (p->kind & port_string) |
4879 | { |
4887 | { |
4880 | off_t size; |
4888 | off_t size; |
4881 | char *str; |
4889 | char *str; |
4882 | |
4890 | |
4883 | size = p->rep.string.curr - p->rep.string.start + 1; |
4891 | size = p->rep.string.curr - p->rep.string.start + 1; |
… | |
… | |
4988 | int res; |
4996 | int res; |
4989 | |
4997 | |
4990 | if (is_pair (args)) |
4998 | if (is_pair (args)) |
4991 | p = car (args); |
4999 | p = car (args); |
4992 | |
5000 | |
4993 | res = p->object.port->kind & port_string; |
5001 | res = port (p)->kind & port_string; |
4994 | |
5002 | |
4995 | s_retbool (res); |
5003 | s_retbool (res); |
4996 | } |
5004 | } |
4997 | |
5005 | |
4998 | case OP_SET_INPORT: /* set-input-port */ |
5006 | case OP_SET_INPORT: /* set-input-port */ |
… | |
… | |
5662 | scheme_init (SCHEME_P) |
5670 | scheme_init (SCHEME_P) |
5663 | { |
5671 | { |
5664 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5672 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5665 | pointer x; |
5673 | pointer x; |
5666 | |
5674 | |
|
|
5675 | /* this memset is not strictly correct, as we assume (intcache) |
|
|
5676 | * that memset 0 will also set pointers to 0, but memset does |
|
|
5677 | * of course not guarantee that. screw such systems. |
|
|
5678 | */ |
|
|
5679 | memset (SCHEME_V, 0, sizeof (*SCHEME_V)); |
|
|
5680 | |
5667 | num_set_fixnum (num_zero, 1); |
5681 | num_set_fixnum (num_zero, 1); |
5668 | num_set_ivalue (num_zero, 0); |
5682 | num_set_ivalue (num_zero, 0); |
5669 | num_set_fixnum (num_one, 1); |
5683 | num_set_fixnum (num_one, 1); |
5670 | num_set_ivalue (num_one, 1); |
5684 | num_set_ivalue (num_one, 1); |
5671 | |
5685 | |
… | |
… | |
5682 | SCHEME_V->save_inport = NIL; |
5696 | SCHEME_V->save_inport = NIL; |
5683 | SCHEME_V->loadport = NIL; |
5697 | SCHEME_V->loadport = NIL; |
5684 | SCHEME_V->nesting = 0; |
5698 | SCHEME_V->nesting = 0; |
5685 | SCHEME_V->interactive_repl = 0; |
5699 | SCHEME_V->interactive_repl = 0; |
5686 | |
5700 | |
5687 | if (alloc_cellseg (SCHEME_A_ FIRST_CELLSEGS) != FIRST_CELLSEGS) |
5701 | if (!alloc_cellseg (SCHEME_A)) |
5688 | { |
5702 | { |
5689 | #if USE_ERROR_CHECKING |
5703 | #if USE_ERROR_CHECKING |
5690 | SCHEME_V->no_memory = 1; |
5704 | SCHEME_V->no_memory = 1; |
5691 | return 0; |
5705 | return 0; |
5692 | #endif |
5706 | #endif |