… | |
… | |
34 | |
34 | |
35 | #include <sys/types.h> |
35 | #include <sys/types.h> |
36 | #include <sys/stat.h> |
36 | #include <sys/stat.h> |
37 | #include <fcntl.h> |
37 | #include <fcntl.h> |
38 | |
38 | |
|
|
39 | #if !USE_ERROR_CHECKING |
|
|
40 | # define NDEBUG |
|
|
41 | #endif |
|
|
42 | |
|
|
43 | #include <assert.h> |
|
|
44 | #include <stdlib.h> |
39 | #include <string.h> |
45 | #include <string.h> |
40 | #include <stdlib.h> |
|
|
41 | |
46 | |
42 | #include <limits.h> |
47 | #include <limits.h> |
43 | #include <inttypes.h> |
48 | #include <inttypes.h> |
44 | #include <float.h> |
49 | #include <float.h> |
45 | //#include <ctype.h> |
50 | //#include <ctype.h> |
|
|
51 | |
|
|
52 | #if '1' != '0' + 1 \ |
|
|
53 | || '2' != '0' + 2 || '3' != '0' + 3 || '4' != '0' + 4 || '5' != '0' + 5 \ |
|
|
54 | || '6' != '0' + 6 || '7' != '0' + 7 || '8' != '0' + 8 || '9' != '0' + 9 \ |
|
|
55 | || 'b' != 'a' + 1 || 'c' != 'a' + 2 || 'd' != 'a' + 3 || 'e' != 'a' + 4 \ |
|
|
56 | || 'f' != 'a' + 5 |
|
|
57 | # error "execution character set digits not consecutive" |
|
|
58 | #endif |
46 | |
59 | |
47 | enum { |
60 | enum { |
48 | TOK_EOF, |
61 | TOK_EOF, |
49 | TOK_LPAREN, |
62 | TOK_LPAREN, |
50 | TOK_RPAREN, |
63 | TOK_RPAREN, |
51 | TOK_DOT, |
64 | TOK_DOT, |
52 | TOK_ATOM, |
65 | TOK_ATOM, |
|
|
66 | TOK_DOTATOM, /* atom name starting with '.' */ |
|
|
67 | TOK_STRATOM, /* atom name enclosed in | */ |
53 | TOK_QUOTE, |
68 | TOK_QUOTE, |
54 | TOK_DQUOTE, |
69 | TOK_DQUOTE, |
55 | TOK_BQUOTE, |
70 | TOK_BQUOTE, |
56 | TOK_COMMA, |
71 | TOK_COMMA, |
57 | TOK_ATMARK, |
72 | TOK_ATMARK, |
… | |
… | |
391 | } |
406 | } |
392 | |
407 | |
393 | INTERFACE char * |
408 | INTERFACE char * |
394 | symname (pointer p) |
409 | symname (pointer p) |
395 | { |
410 | { |
396 | return strvalue (p); |
411 | return strvalue (car (p)); |
397 | } |
412 | } |
398 | |
413 | |
399 | #if USE_PLIST |
414 | #if USE_PLIST |
400 | SCHEME_EXPORT int |
415 | SCHEME_EXPORT int |
401 | hasprop (pointer p) |
416 | hasprop (pointer p) |
… | |
… | |
651 | #endif |
666 | #endif |
652 | |
667 | |
653 | static int file_push (SCHEME_P_ const char *fname); |
668 | static int file_push (SCHEME_P_ const char *fname); |
654 | static void file_pop (SCHEME_P); |
669 | static void file_pop (SCHEME_P); |
655 | static int file_interactive (SCHEME_P); |
670 | static int file_interactive (SCHEME_P); |
656 | ecb_inline int is_one_of (char *s, int c); |
671 | ecb_inline int is_one_of (const char *s, int c); |
657 | static int alloc_cellseg (SCHEME_P_ int n); |
672 | static int alloc_cellseg (SCHEME_P_ int n); |
658 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
673 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
659 | static void finalize_cell (SCHEME_P_ pointer a); |
674 | static void finalize_cell (SCHEME_P_ pointer a); |
660 | static int count_consecutive_cells (pointer x, int needed); |
675 | static int count_consecutive_cells (pointer x, int needed); |
661 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
676 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
… | |
… | |
678 | static void mark (pointer a); |
693 | static void mark (pointer a); |
679 | static void gc (SCHEME_P_ pointer a, pointer b); |
694 | static void gc (SCHEME_P_ pointer a, pointer b); |
680 | static int basic_inchar (port *pt); |
695 | static int basic_inchar (port *pt); |
681 | static int inchar (SCHEME_P); |
696 | static int inchar (SCHEME_P); |
682 | static void backchar (SCHEME_P_ int c); |
697 | static void backchar (SCHEME_P_ int c); |
683 | static char *readstr_upto (SCHEME_P_ char *delim); |
698 | static char *readstr_upto (SCHEME_P_ int skip, const char *delim); |
684 | static pointer readstrexp (SCHEME_P); |
699 | static pointer readstrexp (SCHEME_P_ char delim); |
685 | ecb_inline int skipspace (SCHEME_P); |
700 | ecb_inline int skipspace (SCHEME_P); |
686 | static int token (SCHEME_P); |
701 | static int token (SCHEME_P); |
687 | static void printslashstring (SCHEME_P_ char *s, int len); |
702 | static void printslashstring (SCHEME_P_ char *s, int len); |
688 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
703 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
689 | static void printatom (SCHEME_P_ pointer l, int f); |
704 | static void printatom (SCHEME_P_ pointer l, int f); |
… | |
… | |
1079 | return x; |
1094 | return x; |
1080 | } |
1095 | } |
1081 | |
1096 | |
1082 | /* ========== oblist implementation ========== */ |
1097 | /* ========== oblist implementation ========== */ |
1083 | |
1098 | |
|
|
1099 | static pointer |
|
|
1100 | generate_symbol (SCHEME_P_ const char *name) |
|
|
1101 | { |
|
|
1102 | pointer x = mk_string (SCHEME_A_ name); |
|
|
1103 | setimmutable (x); |
|
|
1104 | x = immutable_cons (x, NIL); |
|
|
1105 | set_typeflag (x, T_SYMBOL); |
|
|
1106 | return x; |
|
|
1107 | } |
|
|
1108 | |
1084 | #ifndef USE_OBJECT_LIST |
1109 | #ifndef USE_OBJECT_LIST |
1085 | |
1110 | |
|
|
1111 | static int |
1086 | static int hash_fn (const char *key, int table_size); |
1112 | hash_fn (const char *key, int table_size) |
|
|
1113 | { |
|
|
1114 | const unsigned char *p = key; |
|
|
1115 | uint32_t hash = 2166136261; |
|
|
1116 | |
|
|
1117 | while (*p) |
|
|
1118 | hash = (hash ^ *p++) * 16777619; |
|
|
1119 | |
|
|
1120 | return hash % table_size; |
|
|
1121 | } |
1087 | |
1122 | |
1088 | static pointer |
1123 | static pointer |
1089 | oblist_initial_value (SCHEME_P) |
1124 | oblist_initial_value (SCHEME_P) |
1090 | { |
1125 | { |
1091 | return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ |
1126 | return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ |
… | |
… | |
1093 | |
1128 | |
1094 | /* returns the new symbol */ |
1129 | /* returns the new symbol */ |
1095 | static pointer |
1130 | static pointer |
1096 | oblist_add_by_name (SCHEME_P_ const char *name) |
1131 | oblist_add_by_name (SCHEME_P_ const char *name) |
1097 | { |
1132 | { |
1098 | int location; |
|
|
1099 | |
|
|
1100 | pointer x = mk_string (SCHEME_A_ name); |
1133 | pointer x = generate_symbol (SCHEME_A_ name); |
1101 | set_typeflag (x, T_SYMBOL); |
|
|
1102 | setimmutable (car (x)); |
|
|
1103 | |
|
|
1104 | location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1134 | int location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1105 | vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location))); |
1135 | vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location))); |
1106 | return x; |
1136 | return x; |
1107 | } |
1137 | } |
1108 | |
1138 | |
1109 | ecb_inline pointer |
1139 | ecb_inline pointer |
… | |
… | |
1169 | |
1199 | |
1170 | /* returns the new symbol */ |
1200 | /* returns the new symbol */ |
1171 | static pointer |
1201 | static pointer |
1172 | oblist_add_by_name (SCHEME_P_ const char *name) |
1202 | oblist_add_by_name (SCHEME_P_ const char *name) |
1173 | { |
1203 | { |
1174 | pointer x; |
1204 | pointer x = mk_string (SCHEME_A_ name); |
1175 | |
|
|
1176 | x = immutable_cons (mk_string (SCHEME_A_ name), NIL); |
|
|
1177 | set_typeflag (x, T_SYMBOL); |
1205 | set_typeflag (x, T_SYMBOL); |
1178 | setimmutable (car (x)); |
1206 | setimmutable (x); |
1179 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1207 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1180 | return x; |
1208 | return x; |
1181 | } |
1209 | } |
1182 | |
1210 | |
1183 | static pointer |
1211 | static pointer |
… | |
… | |
1273 | SCHEME_V->no_memory = 1; |
1301 | SCHEME_V->no_memory = 1; |
1274 | return SCHEME_V->strbuff; |
1302 | return SCHEME_V->strbuff; |
1275 | } |
1303 | } |
1276 | |
1304 | |
1277 | if (str) |
1305 | if (str) |
1278 | { |
1306 | memcpy (q, str , len_str); /* caller must ensure that *str has length len_str */ |
1279 | int l = strlen (str); |
|
|
1280 | |
|
|
1281 | if (l > len_str) |
|
|
1282 | l = len_str; |
|
|
1283 | |
|
|
1284 | memcpy (q, str, l); |
|
|
1285 | q[l] = 0; |
|
|
1286 | } |
|
|
1287 | else |
1307 | else |
1288 | { |
|
|
1289 | memset (q, fill, len_str); |
1308 | memset (q, fill, len_str); |
|
|
1309 | |
1290 | q[len_str] = 0; |
1310 | q[len_str] = 0; |
1291 | } |
|
|
1292 | |
1311 | |
1293 | return q; |
1312 | return q; |
1294 | } |
1313 | } |
1295 | |
1314 | |
1296 | INTERFACE pointer |
1315 | INTERFACE pointer |
… | |
… | |
1310 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1329 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1311 | |
1330 | |
1312 | set_typeflag (x, T_STRING | T_ATOM); |
1331 | set_typeflag (x, T_STRING | T_ATOM); |
1313 | strvalue (x) = store_string (SCHEME_A_ len, str, 0); |
1332 | strvalue (x) = store_string (SCHEME_A_ len, str, 0); |
1314 | strlength (x) = len; |
1333 | strlength (x) = len; |
|
|
1334 | |
1315 | return x; |
1335 | return x; |
1316 | } |
1336 | } |
1317 | |
1337 | |
1318 | INTERFACE pointer |
1338 | INTERFACE pointer |
1319 | mk_string (SCHEME_P_ const char *str) |
1339 | mk_string (SCHEME_P_ const char *str) |
… | |
… | |
1363 | |
1383 | |
1364 | INTERFACE pointer |
1384 | INTERFACE pointer |
1365 | gensym (SCHEME_P) |
1385 | gensym (SCHEME_P) |
1366 | { |
1386 | { |
1367 | pointer x; |
1387 | pointer x; |
1368 | |
|
|
1369 | for (; SCHEME_V->gensym_cnt < LONG_MAX; SCHEME_V->gensym_cnt++) |
|
|
1370 | { |
|
|
1371 | char name[40] = "gensym-"; |
1388 | char name[40] = "gensym-"; |
1372 | xnum (name + 7, SCHEME_V->gensym_cnt); |
1389 | xnum (name + 7, SCHEME_V->gensym_cnt); |
1373 | |
1390 | |
1374 | /* first check oblist */ |
1391 | return generate_symbol (SCHEME_A_ name); |
1375 | x = oblist_find_by_name (SCHEME_A_ name); |
|
|
1376 | |
|
|
1377 | if (x == NIL) |
|
|
1378 | { |
|
|
1379 | x = oblist_add_by_name (SCHEME_A_ name); |
|
|
1380 | return x; |
|
|
1381 | } |
|
|
1382 | } |
|
|
1383 | |
|
|
1384 | return NIL; |
|
|
1385 | } |
1392 | } |
1386 | |
1393 | |
1387 | /* make symbol or number atom from string */ |
1394 | /* make symbol or number atom from string */ |
1388 | static pointer |
1395 | static pointer |
1389 | mk_atom (SCHEME_P_ char *q) |
1396 | mk_atom (SCHEME_P_ char *q) |
… | |
… | |
2105 | #endif |
2112 | #endif |
2106 | } |
2113 | } |
2107 | |
2114 | |
2108 | /* read characters up to delimiter, but cater to character constants */ |
2115 | /* read characters up to delimiter, but cater to character constants */ |
2109 | static char * |
2116 | static char * |
2110 | readstr_upto (SCHEME_P_ char *delim) |
2117 | readstr_upto (SCHEME_P_ int skip, const char *delim) |
2111 | { |
2118 | { |
2112 | char *p = SCHEME_V->strbuff; |
2119 | char *p = SCHEME_V->strbuff + skip; |
2113 | |
2120 | |
2114 | while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); |
2121 | while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); |
2115 | |
2122 | |
2116 | if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\') |
2123 | if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\') |
2117 | *p = 0; |
2124 | *p = 0; |
… | |
… | |
2124 | return SCHEME_V->strbuff; |
2131 | return SCHEME_V->strbuff; |
2125 | } |
2132 | } |
2126 | |
2133 | |
2127 | /* read string expression "xxx...xxx" */ |
2134 | /* read string expression "xxx...xxx" */ |
2128 | static pointer |
2135 | static pointer |
2129 | readstrexp (SCHEME_P) |
2136 | readstrexp (SCHEME_P_ char delim) |
2130 | { |
2137 | { |
2131 | char *p = SCHEME_V->strbuff; |
2138 | char *p = SCHEME_V->strbuff; |
2132 | int c; |
2139 | int c; |
2133 | int c1 = 0; |
2140 | int c1 = 0; |
2134 | enum |
|
|
2135 | { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok; |
2141 | enum { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok; |
2136 | |
2142 | |
2137 | for (;;) |
2143 | for (;;) |
2138 | { |
2144 | { |
2139 | c = inchar (SCHEME_A); |
2145 | c = inchar (SCHEME_A); |
2140 | |
2146 | |
… | |
… | |
2142 | return S_F; |
2148 | return S_F; |
2143 | |
2149 | |
2144 | switch (state) |
2150 | switch (state) |
2145 | { |
2151 | { |
2146 | case st_ok: |
2152 | case st_ok: |
2147 | switch (c) |
2153 | if (ecb_expect_false (c == delim)) |
2148 | { |
|
|
2149 | case '\\': |
|
|
2150 | state = st_bsl; |
|
|
2151 | break; |
|
|
2152 | |
|
|
2153 | case '"': |
|
|
2154 | *p = 0; |
|
|
2155 | return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff); |
2154 | return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff); |
2156 | |
2155 | |
2157 | default: |
2156 | if (ecb_expect_false (c == '\\')) |
|
|
2157 | state = st_bsl; |
|
|
2158 | else |
2158 | *p++ = c; |
2159 | *p++ = c; |
2159 | break; |
|
|
2160 | } |
|
|
2161 | |
2160 | |
2162 | break; |
2161 | break; |
2163 | |
2162 | |
2164 | case st_bsl: |
2163 | case st_bsl: |
2165 | switch (c) |
2164 | switch (c) |
… | |
… | |
2195 | case 'r': |
2194 | case 'r': |
2196 | *p++ = '\r'; |
2195 | *p++ = '\r'; |
2197 | state = st_ok; |
2196 | state = st_ok; |
2198 | break; |
2197 | break; |
2199 | |
2198 | |
2200 | case '"': |
|
|
2201 | *p++ = '"'; |
|
|
2202 | state = st_ok; |
|
|
2203 | break; |
|
|
2204 | |
|
|
2205 | default: |
2199 | default: |
2206 | *p++ = c; |
2200 | *p++ = c; |
2207 | state = st_ok; |
2201 | state = st_ok; |
2208 | break; |
2202 | break; |
2209 | } |
2203 | } |
2210 | |
2204 | |
2211 | break; |
2205 | break; |
2212 | |
2206 | |
2213 | case st_x1: |
2207 | case st_x1: |
2214 | case st_x2: |
2208 | case st_x2: |
2215 | c = toupper (c); |
2209 | c = tolower (c); |
2216 | |
2210 | |
2217 | if (c >= '0' && c <= 'F') |
2211 | if (c >= '0' && c <= '9') |
2218 | { |
|
|
2219 | if (c <= '9') |
|
|
2220 | c1 = (c1 << 4) + c - '0'; |
2212 | c1 = (c1 << 4) + c - '0'; |
2221 | else |
2213 | else if (c >= 'a' && c <= 'f') |
2222 | c1 = (c1 << 4) + c - 'A' + 10; |
2214 | c1 = (c1 << 4) + c - 'a' + 10; |
2223 | |
|
|
2224 | if (state == st_x1) |
|
|
2225 | state = st_x2; |
|
|
2226 | else |
|
|
2227 | { |
|
|
2228 | *p++ = c1; |
|
|
2229 | state = st_ok; |
|
|
2230 | } |
|
|
2231 | } |
|
|
2232 | else |
2215 | else |
2233 | return S_F; |
2216 | return S_F; |
|
|
2217 | |
|
|
2218 | if (state == st_x1) |
|
|
2219 | state = st_x2; |
|
|
2220 | else |
|
|
2221 | { |
|
|
2222 | *p++ = c1; |
|
|
2223 | state = st_ok; |
|
|
2224 | } |
2234 | |
2225 | |
2235 | break; |
2226 | break; |
2236 | |
2227 | |
2237 | case st_oct1: |
2228 | case st_oct1: |
2238 | case st_oct2: |
2229 | case st_oct2: |
… | |
… | |
2242 | backchar (SCHEME_A_ c); |
2233 | backchar (SCHEME_A_ c); |
2243 | state = st_ok; |
2234 | state = st_ok; |
2244 | } |
2235 | } |
2245 | else |
2236 | else |
2246 | { |
2237 | { |
2247 | if (state == st_oct2 && c1 >= 32) |
2238 | if (state == st_oct2 && c1 >= ' ') |
2248 | return S_F; |
2239 | return S_F; |
2249 | |
2240 | |
2250 | c1 = (c1 << 3) + (c - '0'); |
2241 | c1 = (c1 << 3) + (c - '0'); |
2251 | |
2242 | |
2252 | if (state == st_oct1) |
2243 | if (state == st_oct1) |
… | |
… | |
2257 | state = st_ok; |
2248 | state = st_ok; |
2258 | } |
2249 | } |
2259 | } |
2250 | } |
2260 | |
2251 | |
2261 | break; |
2252 | break; |
2262 | |
|
|
2263 | } |
2253 | } |
2264 | } |
2254 | } |
2265 | } |
2255 | } |
2266 | |
2256 | |
2267 | /* check c is in chars */ |
2257 | /* check c is in chars */ |
2268 | ecb_inline int |
2258 | ecb_inline int |
2269 | is_one_of (char *s, int c) |
2259 | is_one_of (const char *s, int c) |
2270 | { |
2260 | { |
2271 | if (c == EOF) |
2261 | if (c == EOF) |
2272 | return 1; |
2262 | return 1; |
2273 | |
2263 | |
2274 | return !!strchr (s, c); |
2264 | return !!strchr (s, c); |
… | |
… | |
2330 | |
2320 | |
2331 | if (is_one_of (" \n\t", c)) |
2321 | if (is_one_of (" \n\t", c)) |
2332 | return TOK_DOT; |
2322 | return TOK_DOT; |
2333 | else |
2323 | else |
2334 | { |
2324 | { |
2335 | //TODO: ungetc twice in a row is not supported in C |
|
|
2336 | backchar (SCHEME_A_ c); |
2325 | backchar (SCHEME_A_ c); |
2337 | backchar (SCHEME_A_ '.'); |
|
|
2338 | return TOK_ATOM; |
2326 | return TOK_DOTATOM; |
2339 | } |
2327 | } |
|
|
2328 | |
|
|
2329 | case '|': |
|
|
2330 | return TOK_STRATOM; |
2340 | |
2331 | |
2341 | case '\'': |
2332 | case '\'': |
2342 | return TOK_QUOTE; |
2333 | return TOK_QUOTE; |
2343 | |
2334 | |
2344 | case ';': |
2335 | case ';': |
… | |
… | |
2813 | #define is_true(p) ((p) != S_F) |
2804 | #define is_true(p) ((p) != S_F) |
2814 | #define is_false(p) ((p) == S_F) |
2805 | #define is_false(p) ((p) == S_F) |
2815 | |
2806 | |
2816 | /* ========== Environment implementation ========== */ |
2807 | /* ========== Environment implementation ========== */ |
2817 | |
2808 | |
2818 | #if !defined(USE_ALIST_ENV) || !defined(USE_OBJECT_LIST) |
|
|
2819 | |
|
|
2820 | static int |
|
|
2821 | hash_fn (const char *key, int table_size) |
|
|
2822 | { |
|
|
2823 | const unsigned char *p = key; |
|
|
2824 | uint32_t hash = 2166136261; |
|
|
2825 | |
|
|
2826 | while (*p) |
|
|
2827 | hash = (hash ^ *p++) * 16777619; |
|
|
2828 | |
|
|
2829 | return hash % table_size; |
|
|
2830 | } |
|
|
2831 | #endif |
|
|
2832 | |
|
|
2833 | #ifndef USE_ALIST_ENV |
2809 | #ifndef USE_ALIST_ENV |
2834 | |
2810 | |
2835 | /* |
2811 | /* |
2836 | * In this implementation, each frame of the environment may be |
2812 | * In this implementation, each frame of the environment may be |
2837 | * a hash table: a vector of alists hashed by variable name. |
2813 | * a hash table: a vector of alists hashed by variable name. |
… | |
… | |
2853 | |
2829 | |
2854 | SCHEME_V->envir = immutable_cons (new_frame, old_env); |
2830 | SCHEME_V->envir = immutable_cons (new_frame, old_env); |
2855 | setenvironment (SCHEME_V->envir); |
2831 | setenvironment (SCHEME_V->envir); |
2856 | } |
2832 | } |
2857 | |
2833 | |
|
|
2834 | static uint32_t |
|
|
2835 | sym_hash (pointer sym, uint32_t size) |
|
|
2836 | { |
|
|
2837 | uintptr_t ptr = (uintptr_t)sym; |
|
|
2838 | |
|
|
2839 | #if 0 |
|
|
2840 | /* table size is prime, so why mix */ |
|
|
2841 | ptr += ptr >> 32; |
|
|
2842 | ptr += ptr >> 16; |
|
|
2843 | ptr += ptr >> 8; |
|
|
2844 | #endif |
|
|
2845 | |
|
|
2846 | return ptr % size; |
|
|
2847 | } |
|
|
2848 | |
2858 | ecb_inline void |
2849 | ecb_inline void |
2859 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2850 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2860 | { |
2851 | { |
2861 | pointer slot = immutable_cons (variable, value); |
2852 | pointer slot = immutable_cons (variable, value); |
2862 | |
2853 | |
2863 | if (is_vector (car (env))) |
2854 | if (is_vector (car (env))) |
2864 | { |
2855 | { |
2865 | int location = hash_fn (symname (variable), veclength (car (env))); |
2856 | int location = sym_hash (variable, veclength (car (env))); |
2866 | |
|
|
2867 | vector_set (car (env), location, immutable_cons (slot, vector_get (car (env), location))); |
2857 | vector_set (car (env), location, immutable_cons (slot, vector_get (car (env), location))); |
2868 | } |
2858 | } |
2869 | else |
2859 | else |
2870 | set_car (env, immutable_cons (slot, car (env))); |
2860 | set_car (env, immutable_cons (slot, car (env))); |
2871 | } |
2861 | } |
2872 | |
2862 | |
2873 | static pointer |
2863 | static pointer |
2874 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2864 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2875 | { |
2865 | { |
2876 | pointer x, y; |
2866 | pointer x, y; |
2877 | int location; |
|
|
2878 | |
2867 | |
2879 | for (x = env; x != NIL; x = cdr (x)) |
2868 | for (x = env; x != NIL; x = cdr (x)) |
2880 | { |
2869 | { |
2881 | if (is_vector (car (x))) |
2870 | if (is_vector (car (x))) |
2882 | { |
2871 | { |
2883 | location = hash_fn (symname (hdl), veclength (car (x))); |
2872 | int location = sym_hash (hdl, veclength (car (x))); |
2884 | y = vector_get (car (x), location); |
2873 | y = vector_get (car (x), location); |
2885 | } |
2874 | } |
2886 | else |
2875 | else |
2887 | y = car (x); |
2876 | y = car (x); |
2888 | |
2877 | |
… | |
… | |
2925 | for (y = car (x); y != NIL; y = cdr (y)) |
2914 | for (y = car (x); y != NIL; y = cdr (y)) |
2926 | if (caar (y) == hdl) |
2915 | if (caar (y) == hdl) |
2927 | break; |
2916 | break; |
2928 | |
2917 | |
2929 | if (y != NIL) |
2918 | if (y != NIL) |
|
|
2919 | return car (y); |
2930 | break; |
2920 | break; |
2931 | |
2921 | |
2932 | if (!all) |
2922 | if (!all) |
2933 | return NIL; |
2923 | break; |
2934 | } |
2924 | } |
2935 | |
|
|
2936 | if (x != NIL) |
|
|
2937 | return car (y); |
|
|
2938 | |
2925 | |
2939 | return NIL; |
2926 | return NIL; |
2940 | } |
2927 | } |
2941 | |
2928 | |
2942 | #endif /* USE_ALIST_ENV else */ |
2929 | #endif /* USE_ALIST_ENV else */ |
… | |
… | |
4955 | s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL); |
4942 | s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL); |
4956 | SCHEME_V->tok = token (SCHEME_A); |
4943 | SCHEME_V->tok = token (SCHEME_A); |
4957 | s_goto (OP_RDSEXPR); |
4944 | s_goto (OP_RDSEXPR); |
4958 | |
4945 | |
4959 | case TOK_ATOM: |
4946 | case TOK_ATOM: |
4960 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))); |
4947 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))); |
|
|
4948 | |
|
|
4949 | case TOK_DOTATOM: |
|
|
4950 | SCHEME_V->strbuff[0] = '.'; |
|
|
4951 | s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); |
4961 | |
4952 | |
4962 | case TOK_DQUOTE: |
4953 | case TOK_DQUOTE: |
4963 | x = readstrexp (SCHEME_A); |
4954 | x = readstrexp (SCHEME_A_ '"'); |
4964 | |
4955 | |
4965 | if (x == S_F) |
4956 | if (x == S_F) |
4966 | Error_0 ("Error reading string"); |
4957 | Error_0 ("Error reading string"); |
4967 | |
4958 | |
4968 | setimmutable (x); |
4959 | setimmutable (x); |
… | |
… | |
4980 | s_goto (OP_EVAL); |
4971 | s_goto (OP_EVAL); |
4981 | } |
4972 | } |
4982 | } |
4973 | } |
4983 | |
4974 | |
4984 | case TOK_SHARP_CONST: |
4975 | case TOK_SHARP_CONST: |
4985 | if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))) == NIL) |
4976 | if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL) |
4986 | Error_0 ("undefined sharp expression"); |
4977 | Error_0 ("undefined sharp expression"); |
4987 | else |
4978 | else |
4988 | s_return (x); |
4979 | s_return (x); |
4989 | |
4980 | |
4990 | default: |
4981 | default: |