… | |
… | |
16 | * (MINISCM) This is a revised and modified version by Akira KIDA. |
16 | * (MINISCM) This is a revised and modified version by Akira KIDA. |
17 | * (MINISCM) current version is 0.85k4 (15 May 1994) |
17 | * (MINISCM) current version is 0.85k4 (15 May 1994) |
18 | * |
18 | * |
19 | */ |
19 | */ |
20 | |
20 | |
|
|
21 | #define EXPERIMENT 1 |
|
|
22 | |
21 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
23 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
22 | #include "malloc.c" |
24 | #include "malloc.c" |
23 | |
25 | |
24 | #define SCHEME_SOURCE |
26 | #define SCHEME_SOURCE |
25 | #include "scheme-private.h" |
27 | #include "scheme-private.h" |
… | |
… | |
74 | TOK_SHARP_CONST, |
76 | TOK_SHARP_CONST, |
75 | TOK_VEC |
77 | TOK_VEC |
76 | }; |
78 | }; |
77 | |
79 | |
78 | #define BACKQUOTE '`' |
80 | #define BACKQUOTE '`' |
79 | #define DELIMITERS "()\";\f\t\v\n\r " |
81 | #define WHITESPACE " \t\r\n\v\f" |
|
|
82 | #define DELIMITERS "()\";" WHITESPACE |
80 | |
83 | |
81 | #define NIL (&SCHEME_V->xNIL) //TODO: make this 0? |
84 | #define NIL (&SCHEME_V->xNIL) |
82 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
85 | #define S_T (&SCHEME_V->xT) |
83 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
86 | #define S_F (&SCHEME_V->xF) |
84 | #define S_SINK (&SCHEME_V->xsink) |
87 | #define S_SINK (&SCHEME_V->xsink) |
85 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
88 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
86 | |
89 | |
87 | #if !USE_MULTIPLICITY |
90 | #if !USE_MULTIPLICITY |
88 | static scheme sc; |
91 | static scheme sc; |
… | |
… | |
410 | { |
413 | { |
411 | return strvalue (p); |
414 | return strvalue (p); |
412 | } |
415 | } |
413 | |
416 | |
414 | #if USE_PLIST |
417 | #if USE_PLIST |
|
|
418 | #error plists are broken because symbols are no longer pairs |
|
|
419 | #define symprop(p) cdr(p) |
415 | SCHEME_EXPORT int |
420 | SCHEME_EXPORT int |
416 | hasprop (pointer p) |
421 | hasprop (pointer p) |
417 | { |
422 | { |
418 | return typeflag (p) & T_SYMBOL; |
423 | return typeflag (p) & T_SYMBOL; |
419 | } |
424 | } |
420 | |
|
|
421 | # define symprop(p) cdr(p) |
|
|
422 | #endif |
425 | #endif |
423 | |
426 | |
424 | INTERFACE int |
427 | INTERFACE int |
425 | is_syntax (pointer p) |
428 | is_syntax (pointer p) |
426 | { |
429 | { |
… | |
… | |
967 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
970 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
968 | return S_SINK; |
971 | return S_SINK; |
969 | |
972 | |
970 | if (SCHEME_V->free_cell == NIL) |
973 | if (SCHEME_V->free_cell == NIL) |
971 | { |
974 | { |
972 | const int min_to_be_recovered = SCHEME_V->last_cell_seg < 128 ? 128 * 8 : SCHEME_V->last_cell_seg * 8; |
975 | const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 1; |
973 | |
976 | |
974 | gc (SCHEME_A_ a, b); |
977 | gc (SCHEME_A_ a, b); |
975 | |
978 | |
976 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
979 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
977 | { |
980 | { |
… | |
… | |
1028 | } |
1031 | } |
1029 | |
1032 | |
1030 | static pointer |
1033 | static pointer |
1031 | get_vector_object (SCHEME_P_ uint32_t len, pointer init) |
1034 | get_vector_object (SCHEME_P_ uint32_t len, pointer init) |
1032 | { |
1035 | { |
1033 | pointer v = get_cell_x (SCHEME_A_ 0, 0); |
1036 | pointer v = get_cell_x (SCHEME_A_ NIL, NIL); |
1034 | pointer *e = malloc (len * sizeof (pointer)); |
1037 | pointer *e = malloc (len * sizeof (pointer)); |
1035 | |
1038 | |
1036 | if (!e && USE_ERROR_CHECKING) |
1039 | if (!e && USE_ERROR_CHECKING) |
1037 | return S_SINK; |
1040 | return S_SINK; |
1038 | |
1041 | |
… | |
… | |
1092 | set_cdr (x, b); |
1095 | set_cdr (x, b); |
1093 | |
1096 | |
1094 | return x; |
1097 | return x; |
1095 | } |
1098 | } |
1096 | |
1099 | |
1097 | /* ========== oblist implementation ========== */ |
|
|
1098 | |
|
|
1099 | static pointer |
1100 | static pointer |
1100 | generate_symbol (SCHEME_P_ const char *name) |
1101 | generate_symbol (SCHEME_P_ const char *name) |
1101 | { |
1102 | { |
1102 | pointer x = mk_string (SCHEME_A_ name); |
1103 | pointer x = mk_string (SCHEME_A_ name); |
1103 | setimmutable (x); |
1104 | setimmutable (x); |
1104 | set_typeflag (x, T_SYMBOL | T_ATOM); |
1105 | set_typeflag (x, T_SYMBOL | T_ATOM); |
1105 | return x; |
1106 | return x; |
1106 | } |
1107 | } |
1107 | |
1108 | |
|
|
1109 | /* ========== oblist implementation ========== */ |
|
|
1110 | |
1108 | #ifndef USE_OBJECT_LIST |
1111 | #ifndef USE_OBJECT_LIST |
1109 | |
1112 | |
1110 | static int |
1113 | static int |
1111 | hash_fn (const char *key, int table_size) |
1114 | hash_fn (const char *key, int table_size) |
1112 | { |
1115 | { |
… | |
… | |
1198 | |
1201 | |
1199 | /* returns the new symbol */ |
1202 | /* returns the new symbol */ |
1200 | static pointer |
1203 | static pointer |
1201 | oblist_add_by_name (SCHEME_P_ const char *name) |
1204 | oblist_add_by_name (SCHEME_P_ const char *name) |
1202 | { |
1205 | { |
1203 | pointer x = mk_string (SCHEME_A_ name); |
1206 | pointer x = generate_symbol (SCHEME_A_ name); |
1204 | set_typeflag (x, T_SYMBOL); |
|
|
1205 | setimmutable (x); |
|
|
1206 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1207 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1207 | return x; |
1208 | return x; |
1208 | } |
1209 | } |
1209 | |
1210 | |
1210 | static pointer |
1211 | static pointer |
… | |
… | |
1231 | pointer |
1232 | pointer |
1232 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1233 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1233 | { |
1234 | { |
1234 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1235 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1235 | |
1236 | |
1236 | set_typeflag (x, (T_FOREIGN | T_ATOM)); |
1237 | set_typeflag (x, T_FOREIGN | T_ATOM); |
1237 | x->object.ff = f; |
1238 | x->object.ff = f; |
1238 | |
1239 | |
1239 | return x; |
1240 | return x; |
1240 | } |
1241 | } |
1241 | |
1242 | |
1242 | INTERFACE pointer |
1243 | INTERFACE pointer |
1243 | mk_character (SCHEME_P_ int c) |
1244 | mk_character (SCHEME_P_ int c) |
1244 | { |
1245 | { |
1245 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1246 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1246 | |
1247 | |
1247 | set_typeflag (x, (T_CHARACTER | T_ATOM)); |
1248 | set_typeflag (x, T_CHARACTER | T_ATOM); |
1248 | set_ivalue (x, c & 0xff); |
1249 | set_ivalue (x, c & 0xff); |
1249 | |
1250 | |
1250 | return x; |
1251 | return x; |
1251 | } |
1252 | } |
1252 | |
1253 | |
1253 | /* get number atom (integer) */ |
1254 | /* get number atom (integer) */ |
1254 | INTERFACE pointer |
1255 | INTERFACE pointer |
1255 | mk_integer (SCHEME_P_ long n) |
1256 | mk_integer (SCHEME_P_ long n) |
1256 | { |
1257 | { |
|
|
1258 | pointer p = 0; |
|
|
1259 | pointer *pp = &p; |
|
|
1260 | |
|
|
1261 | #if USE_INTCACHE |
|
|
1262 | if (n >= INTCACHE_MIN && n <= INTCACHE_MAX) |
|
|
1263 | pp = &SCHEME_V->intcache[n - INTCACHE_MIN]; |
|
|
1264 | #endif |
|
|
1265 | |
|
|
1266 | if (!*pp) |
|
|
1267 | { |
1257 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1268 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1258 | |
1269 | |
1259 | set_typeflag (x, (T_INTEGER | T_ATOM)); |
1270 | set_typeflag (x, T_INTEGER | T_ATOM); |
|
|
1271 | setimmutable (x); /* shouldn't do anythi9ng, doesn't cost anything */ |
1260 | set_ivalue (x, n); |
1272 | set_ivalue (x, n); |
1261 | |
1273 | |
|
|
1274 | *pp = x; |
|
|
1275 | } |
|
|
1276 | |
1262 | return x; |
1277 | return *pp; |
1263 | } |
1278 | } |
1264 | |
1279 | |
1265 | INTERFACE pointer |
1280 | INTERFACE pointer |
1266 | mk_real (SCHEME_P_ RVALUE n) |
1281 | mk_real (SCHEME_P_ RVALUE n) |
1267 | { |
1282 | { |
1268 | #if USE_REAL |
1283 | #if USE_REAL |
1269 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1284 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1270 | |
1285 | |
1271 | set_typeflag (x, (T_REAL | T_ATOM)); |
1286 | set_typeflag (x, T_REAL | T_ATOM); |
1272 | set_rvalue (x, n); |
1287 | set_rvalue (x, n); |
1273 | |
1288 | |
1274 | return x; |
1289 | return x; |
1275 | #else |
1290 | #else |
1276 | return mk_integer (SCHEME_A_ n); |
1291 | return mk_integer (SCHEME_A_ n); |
… | |
… | |
1392 | INTERFACE pointer |
1407 | INTERFACE pointer |
1393 | gensym (SCHEME_P) |
1408 | gensym (SCHEME_P) |
1394 | { |
1409 | { |
1395 | pointer x; |
1410 | pointer x; |
1396 | char name[40] = "gensym-"; |
1411 | char name[40] = "gensym-"; |
1397 | xnum (name + 7, SCHEME_V->gensym_cnt); |
1412 | xnum (name + 7, ++SCHEME_V->gensym_cnt); |
1398 | |
1413 | |
1399 | return generate_symbol (SCHEME_A_ name); |
1414 | return generate_symbol (SCHEME_A_ name); |
|
|
1415 | } |
|
|
1416 | |
|
|
1417 | static int |
|
|
1418 | is_gensym (SCHEME_P_ pointer x) |
|
|
1419 | { |
|
|
1420 | return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x; |
1400 | } |
1421 | } |
1401 | |
1422 | |
1402 | /* make symbol or number atom from string */ |
1423 | /* make symbol or number atom from string */ |
1403 | static pointer |
1424 | static pointer |
1404 | mk_atom (SCHEME_P_ char *q) |
1425 | mk_atom (SCHEME_P_ char *q) |
… | |
… | |
1639 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1660 | /* Mark recent objects the interpreter doesn't know about yet. */ |
1640 | mark (car (S_SINK)); |
1661 | mark (car (S_SINK)); |
1641 | /* Mark any older stuff above nested C calls */ |
1662 | /* Mark any older stuff above nested C calls */ |
1642 | mark (SCHEME_V->c_nest); |
1663 | mark (SCHEME_V->c_nest); |
1643 | |
1664 | |
|
|
1665 | #if USE_INTCACHE |
|
|
1666 | /* mark intcache */ |
|
|
1667 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1668 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1669 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
|
|
1670 | #endif |
|
|
1671 | |
1644 | /* mark variables a, b */ |
1672 | /* mark variables a, b */ |
1645 | mark (a); |
1673 | mark (a); |
1646 | mark (b); |
1674 | mark (b); |
1647 | |
1675 | |
1648 | /* garbage collect */ |
1676 | /* garbage collect */ |
1649 | clrmark (NIL); |
1677 | clrmark (NIL); |
1650 | SCHEME_V->fcells = 0; |
1678 | SCHEME_V->fcells = 0; |
1651 | SCHEME_V->free_cell = NIL; |
1679 | SCHEME_V->free_cell = NIL; |
1652 | |
1680 | |
1653 | /* free-list is kept sorted by address so as to maintain consecutive |
1681 | if (SCHEME_V->gc_verbose) |
1654 | ranges, if possible, for use with vectors. Here we scan the cells |
1682 | xwrstr ("freeing..."); |
1655 | (which are also kept sorted by address) downwards to build the |
1683 | |
1656 | free-list in sorted order. |
1684 | uint32_t total = 0; |
1657 | */ |
1685 | |
|
|
1686 | /* Here we scan the cells to build the free-list. */ |
1658 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1687 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1659 | { |
1688 | { |
1660 | p = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
1689 | pointer end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; |
|
|
1690 | total += SCHEME_V->cell_segsize [i]; |
1661 | |
1691 | |
1662 | while (--p >= SCHEME_V->cell_seg[i]) |
1692 | for (p = SCHEME_V->cell_seg[i]; p < end; ++p) |
1663 | { |
1693 | { |
1664 | if (is_mark (p)) |
1694 | if (is_mark (p)) |
1665 | clrmark (p); |
1695 | clrmark (p); |
1666 | else |
1696 | else |
1667 | { |
1697 | { |
… | |
… | |
1680 | } |
1710 | } |
1681 | } |
1711 | } |
1682 | |
1712 | |
1683 | if (SCHEME_V->gc_verbose) |
1713 | if (SCHEME_V->gc_verbose) |
1684 | { |
1714 | { |
1685 | xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" cells were recovered.\n"); |
1715 | xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" out of "); xwrnum (total); xwrstr (" cells were recovered.\n"); |
1686 | } |
1716 | } |
1687 | } |
1717 | } |
1688 | |
1718 | |
1689 | static void |
1719 | static void |
1690 | finalize_cell (SCHEME_P_ pointer a) |
1720 | finalize_cell (SCHEME_P_ pointer a) |
1691 | { |
1721 | { |
1692 | /* TODO, fast bitmap check? */ |
1722 | /* TODO, fast bitmap check? */ |
1693 | if (is_string (a)) |
1723 | if (is_string (a) || is_symbol (a)) |
1694 | free (strvalue (a)); |
1724 | free (strvalue (a)); |
1695 | else if (is_vector (a)) |
1725 | else if (is_vector (a)) |
1696 | free (vecvalue (a)); |
1726 | free (vecvalue (a)); |
1697 | #if USE_PORTS |
1727 | #if USE_PORTS |
1698 | else if (is_port (a)) |
1728 | else if (is_port (a)) |
… | |
… | |
2264 | |
2294 | |
2265 | /* check c is in chars */ |
2295 | /* check c is in chars */ |
2266 | ecb_inline int |
2296 | ecb_inline int |
2267 | is_one_of (const char *s, int c) |
2297 | is_one_of (const char *s, int c) |
2268 | { |
2298 | { |
2269 | if (c == EOF) |
|
|
2270 | return 1; |
|
|
2271 | |
|
|
2272 | return !!strchr (s, c); |
2299 | return c == EOF || !!strchr (s, c); |
2273 | } |
2300 | } |
2274 | |
2301 | |
2275 | /* skip white characters */ |
2302 | /* skip white characters */ |
2276 | ecb_inline int |
2303 | ecb_inline int |
2277 | skipspace (SCHEME_P) |
2304 | skipspace (SCHEME_P) |
… | |
… | |
2279 | int c, curr_line = 0; |
2306 | int c, curr_line = 0; |
2280 | |
2307 | |
2281 | do |
2308 | do |
2282 | { |
2309 | { |
2283 | c = inchar (SCHEME_A); |
2310 | c = inchar (SCHEME_A); |
|
|
2311 | |
2284 | #if SHOW_ERROR_LINE |
2312 | #if SHOW_ERROR_LINE |
2285 | if (c == '\n') |
2313 | if (ecb_expect_false (c == '\n')) |
2286 | curr_line++; |
2314 | curr_line++; |
2287 | #endif |
2315 | #endif |
|
|
2316 | |
|
|
2317 | if (ecb_expect_false (c == EOF)) |
|
|
2318 | return c; |
2288 | } |
2319 | } |
2289 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); |
2320 | while (is_one_of (WHITESPACE, c)); |
2290 | |
2321 | |
2291 | /* record it */ |
2322 | /* record it */ |
2292 | #if SHOW_ERROR_LINE |
2323 | #if SHOW_ERROR_LINE |
2293 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2324 | if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) |
2294 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
2325 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; |
2295 | #endif |
2326 | #endif |
2296 | |
2327 | |
2297 | if (c != EOF) |
|
|
2298 | { |
|
|
2299 | backchar (SCHEME_A_ c); |
2328 | backchar (SCHEME_A_ c); |
2300 | return 1; |
2329 | return 1; |
2301 | } |
|
|
2302 | else |
|
|
2303 | return EOF; |
|
|
2304 | } |
2330 | } |
2305 | |
2331 | |
2306 | /* get token */ |
2332 | /* get token */ |
2307 | static int |
2333 | static int |
2308 | token (SCHEME_P) |
2334 | token (SCHEME_P) |
… | |
… | |
2324 | return TOK_RPAREN; |
2350 | return TOK_RPAREN; |
2325 | |
2351 | |
2326 | case '.': |
2352 | case '.': |
2327 | c = inchar (SCHEME_A); |
2353 | c = inchar (SCHEME_A); |
2328 | |
2354 | |
2329 | if (is_one_of (" \n\t", c)) |
2355 | if (is_one_of (WHITESPACE, c)) |
2330 | return TOK_DOT; |
2356 | return TOK_DOT; |
2331 | else |
2357 | else |
2332 | { |
2358 | { |
2333 | backchar (SCHEME_A_ c); |
2359 | backchar (SCHEME_A_ c); |
2334 | return TOK_DOTATOM; |
2360 | return TOK_DOTATOM; |
… | |
… | |
3244 | |
3270 | |
3245 | #endif |
3271 | #endif |
3246 | |
3272 | |
3247 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3273 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3248 | |
3274 | |
3249 | #if 1 |
3275 | #if EXPERIMENT |
3250 | static int |
3276 | static int |
3251 | debug (SCHEME_P_ int indent, pointer x) |
3277 | debug (SCHEME_P_ int indent, pointer x) |
3252 | { |
3278 | { |
3253 | int c; |
3279 | int c; |
3254 | |
3280 | |
… | |
… | |
3310 | pointer args = SCHEME_V->args; |
3336 | pointer args = SCHEME_V->args; |
3311 | pointer x, y; |
3337 | pointer x, y; |
3312 | |
3338 | |
3313 | switch (op) |
3339 | switch (op) |
3314 | { |
3340 | { |
3315 | #if 1 //D |
3341 | #if EXPERIMENT //D |
3316 | case OP_DEBUG: |
3342 | case OP_DEBUG: |
3317 | printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); |
3343 | printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); |
3318 | printf ("\n"); |
3344 | printf ("\n"); |
3319 | s_return (S_T); |
3345 | s_return (S_T); |
3320 | #endif |
3346 | #endif |
… | |
… | |
3559 | |
3585 | |
3560 | case OP_DOMACRO: /* do macro */ |
3586 | case OP_DOMACRO: /* do macro */ |
3561 | SCHEME_V->code = SCHEME_V->value; |
3587 | SCHEME_V->code = SCHEME_V->value; |
3562 | s_goto (OP_EVAL); |
3588 | s_goto (OP_EVAL); |
3563 | |
3589 | |
3564 | #if 1 |
|
|
3565 | |
|
|
3566 | case OP_LAMBDA: /* lambda */ |
3590 | case OP_LAMBDA: /* lambda */ |
3567 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3591 | /* If the hook is defined, apply it to SCHEME_V->code, otherwise |
3568 | set SCHEME_V->value fall thru */ |
3592 | set SCHEME_V->value fall thru */ |
3569 | { |
3593 | { |
3570 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
3594 | pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->COMPILE_HOOK, 1); |
… | |
… | |
3576 | SCHEME_V->code = slot_value_in_env (f); |
3600 | SCHEME_V->code = slot_value_in_env (f); |
3577 | s_goto (OP_APPLY); |
3601 | s_goto (OP_APPLY); |
3578 | } |
3602 | } |
3579 | |
3603 | |
3580 | SCHEME_V->value = SCHEME_V->code; |
3604 | SCHEME_V->value = SCHEME_V->code; |
3581 | /* Fallthru */ |
|
|
3582 | } |
3605 | } |
|
|
3606 | /* Fallthru */ |
3583 | |
3607 | |
3584 | case OP_LAMBDA1: |
3608 | case OP_LAMBDA1: |
3585 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3609 | s_return (mk_closure (SCHEME_A_ SCHEME_V->value, SCHEME_V->envir)); |
3586 | |
|
|
3587 | #else |
|
|
3588 | |
|
|
3589 | case OP_LAMBDA: /* lambda */ |
|
|
3590 | s_return (mk_closure (SCHEME_A_ SCHEME_V->code, SCHEME_V->envir)); |
|
|
3591 | |
|
|
3592 | #endif |
|
|
3593 | |
3610 | |
3594 | case OP_MKCLOSURE: /* make-closure */ |
3611 | case OP_MKCLOSURE: /* make-closure */ |
3595 | x = car (args); |
3612 | x = car (args); |
3596 | |
3613 | |
3597 | if (car (x) == SCHEME_V->LAMBDA) |
3614 | if (car (x) == SCHEME_V->LAMBDA) |
… | |
… | |
4193 | else |
4210 | else |
4194 | Error_0 ("modulo: division by zero"); |
4211 | Error_0 ("modulo: division by zero"); |
4195 | |
4212 | |
4196 | s_return (mk_number (SCHEME_A_ v)); |
4213 | s_return (mk_number (SCHEME_A_ v)); |
4197 | |
4214 | |
4198 | case OP_CAR: /* car */ |
4215 | /* the compiler will optimize this mess... */ |
4199 | s_return (caar (args)); |
4216 | case OP_CAR: op_car: s_return (car (x)); |
4200 | |
4217 | case OP_CDR: op_cdr: s_return (cdr (x)); |
4201 | case OP_CDR: /* cdr */ |
4218 | case OP_CAAR: op_caar: x = car (x); goto op_car; |
4202 | s_return (cdar (args)); |
4219 | case OP_CADR: op_cadr: x = cdr (x); goto op_car; |
|
|
4220 | case OP_CDAR: op_cdar: x = car (x); goto op_cdr; |
|
|
4221 | case OP_CDDR: op_cddr: x = cdr (x); goto op_cdr; |
|
|
4222 | case OP_CAAAR: op_caaar: x = car (x); goto op_caar; |
|
|
4223 | case OP_CAADR: op_caadr: x = cdr (x); goto op_caar; |
|
|
4224 | case OP_CADAR: op_cadar: x = car (x); goto op_cadr; |
|
|
4225 | case OP_CADDR: op_caddr: x = cdr (x); goto op_cadr; |
|
|
4226 | case OP_CDAAR: op_cdaar: x = car (x); goto op_cdar; |
|
|
4227 | case OP_CDADR: op_cdadr: x = cdr (x); goto op_cdar; |
|
|
4228 | case OP_CDDAR: op_cddar: x = car (x); goto op_cddr; |
|
|
4229 | case OP_CDDDR: op_cdddr: x = cdr (x); goto op_cddr; |
|
|
4230 | case OP_CAAAAR: x = car (x); goto op_caaar; |
|
|
4231 | case OP_CAAADR: x = cdr (x); goto op_caaar; |
|
|
4232 | case OP_CAADAR: x = car (x); goto op_caadr; |
|
|
4233 | case OP_CAADDR: x = cdr (x); goto op_caadr; |
|
|
4234 | case OP_CADAAR: x = car (x); goto op_cadar; |
|
|
4235 | case OP_CADADR: x = cdr (x); goto op_cadar; |
|
|
4236 | case OP_CADDAR: x = car (x); goto op_caddr; |
|
|
4237 | case OP_CADDDR: x = cdr (x); goto op_caddr; |
|
|
4238 | case OP_CDAAAR: x = car (x); goto op_cdaar; |
|
|
4239 | case OP_CDAADR: x = cdr (x); goto op_cdaar; |
|
|
4240 | case OP_CDADAR: x = car (x); goto op_cdadr; |
|
|
4241 | case OP_CDADDR: x = cdr (x); goto op_cdadr; |
|
|
4242 | case OP_CDDAAR: x = car (x); goto op_cddar; |
|
|
4243 | case OP_CDDADR: x = cdr (x); goto op_cddar; |
|
|
4244 | case OP_CDDDAR: x = car (x); goto op_cdddr; |
|
|
4245 | case OP_CDDDDR: x = cdr (x); goto op_cdddr; |
4203 | |
4246 | |
4204 | case OP_CONS: /* cons */ |
4247 | case OP_CONS: /* cons */ |
4205 | set_cdr (args, cadr (args)); |
4248 | set_cdr (args, cadr (args)); |
4206 | s_return (args); |
4249 | s_return (args); |
4207 | |
4250 | |
… | |
… | |
4529 | pointer d = cdr (args); |
4572 | pointer d = cdr (args); |
4530 | int r; |
4573 | int r; |
4531 | |
4574 | |
4532 | switch (op) |
4575 | switch (op) |
4533 | { |
4576 | { |
4534 | case OP_NOT: /* not */ r = is_false (a) ; break; |
4577 | case OP_NOT: /* not */ r = is_false (a) ; break; |
4535 | case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T; break; |
4578 | case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T ; break; |
4536 | case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; |
4579 | case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; |
4537 | case OP_NULLP: /* null? */ r = a == NIL ; break; |
4580 | case OP_NULLP: /* null? */ r = a == NIL ; break; |
4538 | case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; |
4581 | case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; |
|
|
4582 | case OP_GENSYMP: /* gensym? */ r = is_gensym (SCHEME_A_ a); break; |
4539 | case OP_NUMBERP: /* number? */ r = is_number (a) ; break; |
4583 | case OP_NUMBERP: /* number? */ r = is_number (a) ; break; |
4540 | case OP_STRINGP: /* string? */ r = is_string (a) ; break; |
4584 | case OP_STRINGP: /* string? */ r = is_string (a) ; break; |
4541 | case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; |
4585 | case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; |
4542 | case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ |
4586 | case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ |
4543 | case OP_CHARP: /* char? */ r = is_character (a) ; break; |
4587 | case OP_CHARP: /* char? */ r = is_character (a) ; break; |
4544 | |
4588 | |
4545 | #if USE_CHAR_CLASSIFIERS |
4589 | #if USE_CHAR_CLASSIFIERS |
4546 | case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break; |
4590 | case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break; |
4547 | case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break; |
4591 | case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break; |
4548 | case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break; |
4592 | case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break; |
… | |
… | |
5629 | scheme_init (SCHEME_P) |
5673 | scheme_init (SCHEME_P) |
5630 | { |
5674 | { |
5631 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5675 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5632 | pointer x; |
5676 | pointer x; |
5633 | |
5677 | |
|
|
5678 | /* this memset is not strictly correct, as we assume (intcache) |
|
|
5679 | * that memset 0 will also set pointers to 0, but memset does |
|
|
5680 | * of course not guarantee that. screw such systems. |
|
|
5681 | */ |
|
|
5682 | memset (SCHEME_V, 0, sizeof (*SCHEME_V)); |
|
|
5683 | |
5634 | num_set_fixnum (num_zero, 1); |
5684 | num_set_fixnum (num_zero, 1); |
5635 | num_set_ivalue (num_zero, 0); |
5685 | num_set_ivalue (num_zero, 0); |
5636 | num_set_fixnum (num_one, 1); |
5686 | num_set_fixnum (num_one, 1); |
5637 | num_set_ivalue (num_one, 1); |
5687 | num_set_ivalue (num_one, 1); |
5638 | |
5688 | |