ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/microscheme/scheme.c
(Generate patch)

Comparing cvsroot/microscheme/scheme.c (file contents):
Revision 1.33 by root, Sat Nov 28 10:59:14 2015 UTC vs.
Revision 1.40 by root, Mon Nov 30 05:19:01 2015 UTC

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
47enum { 60enum {
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,
59 TOK_SHARP_CONST, 74 TOK_SHARP_CONST,
60 TOK_VEC 75 TOK_VEC
61}; 76};
62 77
63#define BACKQUOTE '`' 78#define BACKQUOTE '`'
64#define DELIMITERS "()\";\f\t\v\n\r " 79#define WHITESPACE " \t\r\n\v\f"
80#define DELIMITERS "()\";" WHITESPACE
65 81
66#define NIL (&SCHEME_V->xNIL) //TODO: make this 0? 82#define NIL (&SCHEME_V->xNIL) //TODO: make this 0?
67#define S_T (&SCHEME_V->xT) //TODO: magic ptr value? 83#define S_T (&SCHEME_V->xT) //TODO: magic ptr value?
68#define S_F (&SCHEME_V->xF) //TODO: magic ptr value? 84#define S_F (&SCHEME_V->xF) //TODO: magic ptr value?
69#define S_SINK (&SCHEME_V->xsink) 85#define S_SINK (&SCHEME_V->xsink)
391} 407}
392 408
393INTERFACE char * 409INTERFACE char *
394symname (pointer p) 410symname (pointer p)
395{ 411{
396 return strvalue (car (p)); 412 return strvalue (p);
397} 413}
398 414
399#if USE_PLIST 415#if USE_PLIST
400SCHEME_EXPORT int 416SCHEME_EXPORT int
401hasprop (pointer p) 417hasprop (pointer p)
425} 441}
426 442
427INTERFACE char * 443INTERFACE char *
428syntaxname (pointer p) 444syntaxname (pointer p)
429{ 445{
430 return strvalue (car (p)); 446 return strvalue (p);
431} 447}
432 448
433#define procnum(p) ivalue_unchecked (p) 449#define procnum(p) ivalue_unchecked (p)
434static const char *procname (pointer x); 450static const char *procname (pointer x);
435 451
651#endif 667#endif
652 668
653static int file_push (SCHEME_P_ const char *fname); 669static int file_push (SCHEME_P_ const char *fname);
654static void file_pop (SCHEME_P); 670static void file_pop (SCHEME_P);
655static int file_interactive (SCHEME_P); 671static int file_interactive (SCHEME_P);
656ecb_inline int is_one_of (char *s, int c); 672ecb_inline int is_one_of (const char *s, int c);
657static int alloc_cellseg (SCHEME_P_ int n); 673static int alloc_cellseg (SCHEME_P_ int n);
658ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); 674ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b);
659static void finalize_cell (SCHEME_P_ pointer a); 675static void finalize_cell (SCHEME_P_ pointer a);
660static int count_consecutive_cells (pointer x, int needed); 676static int count_consecutive_cells (pointer x, int needed);
661static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); 677static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all);
678static void mark (pointer a); 694static void mark (pointer a);
679static void gc (SCHEME_P_ pointer a, pointer b); 695static void gc (SCHEME_P_ pointer a, pointer b);
680static int basic_inchar (port *pt); 696static int basic_inchar (port *pt);
681static int inchar (SCHEME_P); 697static int inchar (SCHEME_P);
682static void backchar (SCHEME_P_ int c); 698static void backchar (SCHEME_P_ int c);
683static char *readstr_upto (SCHEME_P_ char *delim); 699static char *readstr_upto (SCHEME_P_ int skip, const char *delim);
684static pointer readstrexp (SCHEME_P); 700static pointer readstrexp (SCHEME_P_ char delim);
685ecb_inline int skipspace (SCHEME_P); 701ecb_inline int skipspace (SCHEME_P);
686static int token (SCHEME_P); 702static int token (SCHEME_P);
687static void printslashstring (SCHEME_P_ char *s, int len); 703static void printslashstring (SCHEME_P_ char *s, int len);
688static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); 704static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen);
689static void printatom (SCHEME_P_ pointer l, int f); 705static void printatom (SCHEME_P_ pointer l, int f);
1079 return x; 1095 return x;
1080} 1096}
1081 1097
1082/* ========== oblist implementation ========== */ 1098/* ========== oblist implementation ========== */
1083 1099
1100static pointer
1101generate_symbol (SCHEME_P_ const char *name)
1102{
1103 pointer x = mk_string (SCHEME_A_ name);
1104 setimmutable (x);
1105 set_typeflag (x, T_SYMBOL | T_ATOM);
1106 return x;
1107}
1108
1084#ifndef USE_OBJECT_LIST 1109#ifndef USE_OBJECT_LIST
1085 1110
1086static int 1111static int
1087hash_fn (const char *key, int table_size) 1112hash_fn (const char *key, int table_size)
1088{ 1113{
1103 1128
1104/* returns the new symbol */ 1129/* returns the new symbol */
1105static pointer 1130static pointer
1106oblist_add_by_name (SCHEME_P_ const char *name) 1131oblist_add_by_name (SCHEME_P_ const char *name)
1107{ 1132{
1108 int location; 1133 pointer x = generate_symbol (SCHEME_A_ name);
1109
1110 pointer x = immutable_cons (mk_string (SCHEME_A_ name), NIL);
1111 set_typeflag (x, T_SYMBOL);
1112 setimmutable (car (x));
1113
1114 location = hash_fn (name, veclength (SCHEME_V->oblist)); 1134 int location = hash_fn (name, veclength (SCHEME_V->oblist));
1115 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)));
1116 return x; 1136 return x;
1117} 1137}
1118 1138
1119ecb_inline pointer 1139ecb_inline pointer
1281 SCHEME_V->no_memory = 1; 1301 SCHEME_V->no_memory = 1;
1282 return SCHEME_V->strbuff; 1302 return SCHEME_V->strbuff;
1283 } 1303 }
1284 1304
1285 if (str) 1305 if (str)
1286 { 1306 memcpy (q, str , len_str); /* caller must ensure that *str has length len_str */
1287 int l = strlen (str);
1288
1289 if (l > len_str)
1290 l = len_str;
1291
1292 memcpy (q, str, l);
1293 q[l] = 0;
1294 }
1295 else 1307 else
1296 {
1297 memset (q, fill, len_str); 1308 memset (q, fill, len_str);
1309
1298 q[len_str] = 0; 1310 q[len_str] = 0;
1299 }
1300 1311
1301 return q; 1312 return q;
1302} 1313}
1303 1314
1304INTERFACE pointer 1315INTERFACE pointer
1318 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1329 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1319 1330
1320 set_typeflag (x, T_STRING | T_ATOM); 1331 set_typeflag (x, T_STRING | T_ATOM);
1321 strvalue (x) = store_string (SCHEME_A_ len, str, 0); 1332 strvalue (x) = store_string (SCHEME_A_ len, str, 0);
1322 strlength (x) = len; 1333 strlength (x) = len;
1334
1323 return x; 1335 return x;
1324} 1336}
1325 1337
1326INTERFACE pointer 1338INTERFACE pointer
1327mk_string (SCHEME_P_ const char *str) 1339mk_string (SCHEME_P_ const char *str)
1340{ 1352{
1341 int i; 1353 int i;
1342 1354
1343 for (i = start; i < veclength (vec); i++) 1355 for (i = start; i < veclength (vec); i++)
1344 vecvalue (vec)[i] = obj; 1356 vecvalue (vec)[i] = obj;
1357}
1358
1359INTERFACE void
1360vector_resize (pointer vec, uint32_t newsize, pointer fill)
1361{
1362 uint32_t oldsize = veclength (vec);
1363 vecvalue (vec) = realloc (vecvalue (vec), newsize * sizeof (pointer));
1364 veclength (vec) = newsize;
1365 fill_vector (vec, oldsize, fill);
1345} 1366}
1346 1367
1347INTERFACE pointer 1368INTERFACE pointer
1348vector_get (pointer vec, uint32_t ielem) 1369vector_get (pointer vec, uint32_t ielem)
1349{ 1370{
1371 1392
1372INTERFACE pointer 1393INTERFACE pointer
1373gensym (SCHEME_P) 1394gensym (SCHEME_P)
1374{ 1395{
1375 pointer x; 1396 pointer x;
1376
1377 for (; SCHEME_V->gensym_cnt < LONG_MAX; SCHEME_V->gensym_cnt++)
1378 {
1379 char name[40] = "gensym-"; 1397 char name[40] = "gensym-";
1380 xnum (name + 7, SCHEME_V->gensym_cnt); 1398 xnum (name + 7, SCHEME_V->gensym_cnt);
1381 1399
1382 /* first check oblist */ 1400 return generate_symbol (SCHEME_A_ name);
1383 x = oblist_find_by_name (SCHEME_A_ name);
1384
1385 if (x == NIL)
1386 {
1387 x = oblist_add_by_name (SCHEME_A_ name);
1388 return x;
1389 }
1390 }
1391
1392 return NIL;
1393} 1401}
1394 1402
1395/* make symbol or number atom from string */ 1403/* make symbol or number atom from string */
1396static pointer 1404static pointer
1397mk_atom (SCHEME_P_ char *q) 1405mk_atom (SCHEME_P_ char *q)
1681 1689
1682static void 1690static void
1683finalize_cell (SCHEME_P_ pointer a) 1691finalize_cell (SCHEME_P_ pointer a)
1684{ 1692{
1685 /* TODO, fast bitmap check? */ 1693 /* TODO, fast bitmap check? */
1686 if (is_string (a)) 1694 if (is_string (a) || is_symbol (a))
1687 free (strvalue (a)); 1695 free (strvalue (a));
1688 else if (is_vector (a)) 1696 else if (is_vector (a))
1689 free (vecvalue (a)); 1697 free (vecvalue (a));
1690#if USE_PORTS 1698#if USE_PORTS
1691 else if (is_port (a)) 1699 else if (is_port (a))
2113#endif 2121#endif
2114} 2122}
2115 2123
2116/* read characters up to delimiter, but cater to character constants */ 2124/* read characters up to delimiter, but cater to character constants */
2117static char * 2125static char *
2118readstr_upto (SCHEME_P_ char *delim) 2126readstr_upto (SCHEME_P_ int skip, const char *delim)
2119{ 2127{
2120 char *p = SCHEME_V->strbuff; 2128 char *p = SCHEME_V->strbuff + skip;
2121 2129
2122 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); 2130 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A))));
2123 2131
2124 if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\') 2132 if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\')
2125 *p = 0; 2133 *p = 0;
2132 return SCHEME_V->strbuff; 2140 return SCHEME_V->strbuff;
2133} 2141}
2134 2142
2135/* read string expression "xxx...xxx" */ 2143/* read string expression "xxx...xxx" */
2136static pointer 2144static pointer
2137readstrexp (SCHEME_P) 2145readstrexp (SCHEME_P_ char delim)
2138{ 2146{
2139 char *p = SCHEME_V->strbuff; 2147 char *p = SCHEME_V->strbuff;
2140 int c; 2148 int c;
2141 int c1 = 0; 2149 int c1 = 0;
2142 enum
2143 { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok; 2150 enum { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok;
2144 2151
2145 for (;;) 2152 for (;;)
2146 { 2153 {
2147 c = inchar (SCHEME_A); 2154 c = inchar (SCHEME_A);
2148 2155
2150 return S_F; 2157 return S_F;
2151 2158
2152 switch (state) 2159 switch (state)
2153 { 2160 {
2154 case st_ok: 2161 case st_ok:
2155 switch (c) 2162 if (ecb_expect_false (c == delim))
2156 {
2157 case '\\':
2158 state = st_bsl;
2159 break;
2160
2161 case '"':
2162 *p = 0;
2163 return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff); 2163 return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff);
2164 2164
2165 default: 2165 if (ecb_expect_false (c == '\\'))
2166 state = st_bsl;
2167 else
2166 *p++ = c; 2168 *p++ = c;
2167 break;
2168 }
2169 2169
2170 break; 2170 break;
2171 2171
2172 case st_bsl: 2172 case st_bsl:
2173 switch (c) 2173 switch (c)
2203 case 'r': 2203 case 'r':
2204 *p++ = '\r'; 2204 *p++ = '\r';
2205 state = st_ok; 2205 state = st_ok;
2206 break; 2206 break;
2207 2207
2208 case '"':
2209 *p++ = '"';
2210 state = st_ok;
2211 break;
2212
2213 default: 2208 default:
2214 *p++ = c; 2209 *p++ = c;
2215 state = st_ok; 2210 state = st_ok;
2216 break; 2211 break;
2217 } 2212 }
2218 2213
2219 break; 2214 break;
2220 2215
2221 case st_x1: 2216 case st_x1:
2222 case st_x2: 2217 case st_x2:
2223 c = toupper (c); 2218 c = tolower (c);
2224 2219
2225 if (c >= '0' && c <= 'F') 2220 if (c >= '0' && c <= '9')
2226 {
2227 if (c <= '9')
2228 c1 = (c1 << 4) + c - '0'; 2221 c1 = (c1 << 4) + c - '0';
2229 else 2222 else if (c >= 'a' && c <= 'f')
2230 c1 = (c1 << 4) + c - 'A' + 10; 2223 c1 = (c1 << 4) + c - 'a' + 10;
2231
2232 if (state == st_x1)
2233 state = st_x2;
2234 else
2235 {
2236 *p++ = c1;
2237 state = st_ok;
2238 }
2239 }
2240 else 2224 else
2241 return S_F; 2225 return S_F;
2226
2227 if (state == st_x1)
2228 state = st_x2;
2229 else
2230 {
2231 *p++ = c1;
2232 state = st_ok;
2233 }
2242 2234
2243 break; 2235 break;
2244 2236
2245 case st_oct1: 2237 case st_oct1:
2246 case st_oct2: 2238 case st_oct2:
2250 backchar (SCHEME_A_ c); 2242 backchar (SCHEME_A_ c);
2251 state = st_ok; 2243 state = st_ok;
2252 } 2244 }
2253 else 2245 else
2254 { 2246 {
2255 if (state == st_oct2 && c1 >= 32) 2247 if (state == st_oct2 && c1 >= ' ')
2256 return S_F; 2248 return S_F;
2257 2249
2258 c1 = (c1 << 3) + (c - '0'); 2250 c1 = (c1 << 3) + (c - '0');
2259 2251
2260 if (state == st_oct1) 2252 if (state == st_oct1)
2265 state = st_ok; 2257 state = st_ok;
2266 } 2258 }
2267 } 2259 }
2268 2260
2269 break; 2261 break;
2270
2271 } 2262 }
2272 } 2263 }
2273} 2264}
2274 2265
2275/* check c is in chars */ 2266/* check c is in chars */
2276ecb_inline int 2267ecb_inline int
2277is_one_of (char *s, int c) 2268is_one_of (const char *s, int c)
2278{ 2269{
2279 if (c == EOF)
2280 return 1;
2281
2282 return !!strchr (s, c); 2270 return c == EOF || !!strchr (s, c);
2283} 2271}
2284 2272
2285/* skip white characters */ 2273/* skip white characters */
2286ecb_inline int 2274ecb_inline int
2287skipspace (SCHEME_P) 2275skipspace (SCHEME_P)
2294#if SHOW_ERROR_LINE 2282#if SHOW_ERROR_LINE
2295 if (c == '\n') 2283 if (c == '\n')
2296 curr_line++; 2284 curr_line++;
2297#endif 2285#endif
2298 } 2286 }
2299 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 2287 while (is_one_of (WHITESPACE, c));
2300 2288
2301 /* record it */ 2289 /* record it */
2302#if SHOW_ERROR_LINE 2290#if SHOW_ERROR_LINE
2303 if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) 2291 if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file)
2304 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; 2292 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line;
2334 return TOK_RPAREN; 2322 return TOK_RPAREN;
2335 2323
2336 case '.': 2324 case '.':
2337 c = inchar (SCHEME_A); 2325 c = inchar (SCHEME_A);
2338 2326
2339 if (is_one_of (" \n\t", c)) 2327 if (is_one_of (WHITESPACE, c))
2340 return TOK_DOT; 2328 return TOK_DOT;
2341 else 2329 else
2342 { 2330 {
2343 //TODO: ungetc twice in a row is not supported in C
2344 backchar (SCHEME_A_ c); 2331 backchar (SCHEME_A_ c);
2345 backchar (SCHEME_A_ '.');
2346 return TOK_ATOM; 2332 return TOK_DOTATOM;
2347 } 2333 }
2334
2335 case '|':
2336 return TOK_STRATOM;
2348 2337
2349 case '\'': 2338 case '\'':
2350 return TOK_QUOTE; 2339 return TOK_QUOTE;
2351 2340
2352 case ';': 2341 case ';':
2484 } 2473 }
2485 2474
2486 putcharacter (SCHEME_A_ '"'); 2475 putcharacter (SCHEME_A_ '"');
2487} 2476}
2488 2477
2489
2490/* print atoms */ 2478/* print atoms */
2491static void 2479static void
2492printatom (SCHEME_P_ pointer l, int f) 2480printatom (SCHEME_P_ pointer l, int f)
2493{ 2481{
2494 char *p; 2482 char *p;
2495 int len; 2483 int len;
2496 2484
2497 atom2str (SCHEME_A_ l, f, &p, &len); 2485 atom2str (SCHEME_A_ l, f, &p, &len);
2498 putchars (SCHEME_A_ p, len); 2486 putchars (SCHEME_A_ p, len);
2499} 2487}
2500
2501 2488
2502/* Uses internal buffer unless string pointer is already available */ 2489/* Uses internal buffer unless string pointer is already available */
2503static void 2490static void
2504atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2491atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen)
2505{ 2492{
2666#endif 2653#endif
2667 } 2654 }
2668 else if (is_continuation (l)) 2655 else if (is_continuation (l))
2669 p = "#<CONTINUATION>"; 2656 p = "#<CONTINUATION>";
2670 else 2657 else
2658 {
2659#if USE_PRINTF
2660 p = SCHEME_V->strbuff;
2661 snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l));
2662#else
2671 p = "#<ERROR>"; 2663 p = "#<ERROR>";
2664#endif
2665 }
2672 2666
2673 *pp = p; 2667 *pp = p;
2674 *plen = strlen (p); 2668 *plen = strlen (p);
2675} 2669}
2676 2670
2946#endif /* USE_ALIST_ENV else */ 2940#endif /* USE_ALIST_ENV else */
2947 2941
2948ecb_inline void 2942ecb_inline void
2949new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2943new_slot_in_env (SCHEME_P_ pointer variable, pointer value)
2950{ 2944{
2945 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2
2951 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); 2946 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value);
2952} 2947}
2953 2948
2954ecb_inline void 2949ecb_inline void
2955set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2950set_slot_in_env (SCHEME_P_ pointer slot, pointer value)
3247 3242
3248#endif 3243#endif
3249 3244
3250#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3245#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3251 3246
3247#if 1
3248static int
3249debug (SCHEME_P_ int indent, pointer x)
3250{
3251 int c;
3252
3253 if (is_syntax (x))
3254 {
3255 printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x));
3256 return 8 + 8;
3257 }
3258
3259 if (x == NIL)
3260 {
3261 printf ("%*sNIL\n", indent, "");
3262 return 3;
3263 }
3264
3265 switch (type (x))
3266 {
3267 case T_INTEGER:
3268 printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x);
3269 return 32+8;
3270
3271 case T_SYMBOL:
3272 printf ("%*sS<%s>\n", indent, "", symname (x));
3273 return 24+8;
3274
3275 case T_CLOSURE:
3276 printf ("%*sS<%s>\n", indent, "", "closure");
3277 debug (SCHEME_A_ indent + 3, cdr(x));
3278 return 32 + debug (SCHEME_A_ indent + 3, car (x));
3279
3280 case T_PAIR:
3281 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3282 c = debug (SCHEME_A_ indent + 3, car (x));
3283 c += debug (SCHEME_A_ indent + 3, cdr (x));
3284 return c + 1;
3285
3286 case T_PORT:
3287 printf ("%*sS<%s>\n", indent, "", "port");
3288 return 24+8;
3289
3290 case T_VECTOR:
3291 printf ("%*sS<%s>\n", indent, "", "vector");
3292 return 24+8;
3293
3294 case T_ENVIRONMENT:
3295 printf ("%*sS<%s>\n", indent, "", "environment");
3296 return 0 + debug (SCHEME_A_ indent + 3, car (x));
3297
3298 default:
3299 printf ("unhandled type %d\n", type (x));
3300 break;
3301 }
3302}
3303#endif
3304
3252static int 3305static int
3253opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3306opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3254{ 3307{
3255 pointer args = SCHEME_V->args; 3308 pointer args = SCHEME_V->args;
3256 pointer x, y; 3309 pointer x, y;
3257 3310
3258 switch (op) 3311 switch (op)
3259 { 3312 {
3313#if 1 //D
3314 case OP_DEBUG:
3315 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8);
3316 printf ("\n");
3317 s_return (S_T);
3318#endif
3260 case OP_LOAD: /* load */ 3319 case OP_LOAD: /* load */
3261 if (file_interactive (SCHEME_A)) 3320 if (file_interactive (SCHEME_A))
3262 { 3321 {
3263 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); 3322 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n");
3264 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); 3323 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args)));
3387 } 3446 }
3388 else 3447 else
3389 s_return (SCHEME_V->code); 3448 s_return (SCHEME_V->code);
3390 3449
3391 case OP_E0ARGS: /* eval arguments */ 3450 case OP_E0ARGS: /* eval arguments */
3392 if (is_macro (SCHEME_V->value)) /* macro expansion */ 3451 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3393 { 3452 {
3394 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3453 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3395 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3454 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3396 SCHEME_V->code = SCHEME_V->value; 3455 SCHEME_V->code = SCHEME_V->value;
3397 s_goto (OP_APPLY); 3456 s_goto (OP_APPLY);
4395 } 4454 }
4396 4455
4397 case OP_VECLEN: /* vector-length */ 4456 case OP_VECLEN: /* vector-length */
4398 s_return (mk_integer (SCHEME_A_ veclength (x))); 4457 s_return (mk_integer (SCHEME_A_ veclength (x)));
4399 4458
4459 case OP_VECRESIZE:
4460 vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args));
4461 s_return (x);
4462
4400 case OP_VECREF: /* vector-ref */ 4463 case OP_VECREF: /* vector-ref */
4401 { 4464 {
4402 int index = ivalue_unchecked (cadr (args)); 4465 int index = ivalue_unchecked (cadr (args));
4403 4466
4404 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4467 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4959 s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL); 5022 s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL);
4960 SCHEME_V->tok = token (SCHEME_A); 5023 SCHEME_V->tok = token (SCHEME_A);
4961 s_goto (OP_RDSEXPR); 5024 s_goto (OP_RDSEXPR);
4962 5025
4963 case TOK_ATOM: 5026 case TOK_ATOM:
4964 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))); 5027 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS)));
5028
5029 case TOK_DOTATOM:
5030 SCHEME_V->strbuff[0] = '.';
5031 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5032
5033 case TOK_STRATOM:
5034 x = readstrexp (SCHEME_A_ '|');
5035 //TODO: haven't checked whether the garbage collector could interfere
5036 s_return (mk_atom (SCHEME_A_ strvalue (x)));
4965 5037
4966 case TOK_DQUOTE: 5038 case TOK_DQUOTE:
4967 x = readstrexp (SCHEME_A); 5039 x = readstrexp (SCHEME_A_ '"');
4968 5040
4969 if (x == S_F) 5041 if (x == S_F)
4970 Error_0 ("Error reading string"); 5042 Error_0 ("Error reading string");
4971 5043
4972 setimmutable (x); 5044 setimmutable (x);
4984 s_goto (OP_EVAL); 5056 s_goto (OP_EVAL);
4985 } 5057 }
4986 } 5058 }
4987 5059
4988 case TOK_SHARP_CONST: 5060 case TOK_SHARP_CONST:
4989 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))) == NIL) 5061 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL)
4990 Error_0 ("undefined sharp expression"); 5062 Error_0 ("undefined sharp expression");
4991 else 5063 else
4992 s_return (x); 5064 s_return (x);
4993 5065
4994 default: 5066 default:
5216 5288
5217 case OP_CLOSUREP: /* closure? */ 5289 case OP_CLOSUREP: /* closure? */
5218 /* 5290 /*
5219 * Note, macro object is also a closure. 5291 * Note, macro object is also a closure.
5220 * Therefore, (closure? <#MACRO>) ==> #t 5292 * Therefore, (closure? <#MACRO>) ==> #t
5293 * (schmorp) well, obviously not, fix? TODO
5221 */ 5294 */
5222 s_retbool (is_closure (a)); 5295 s_retbool (is_closure (a));
5223 5296
5224 case OP_MACROP: /* macro? */ 5297 case OP_MACROP: /* macro? */
5225 s_retbool (is_macro (a)); 5298 s_retbool (is_macro (a));
5466 5539
5467/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5540/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5468static int 5541static int
5469syntaxnum (pointer p) 5542syntaxnum (pointer p)
5470{ 5543{
5471 const char *s = strvalue (car (p)); 5544 const char *s = strvalue (p);
5472 5545
5473 switch (strlength (car (p))) 5546 switch (strlength (p))
5474 { 5547 {
5475 case 2: 5548 case 2:
5476 if (s[0] == 'i') 5549 if (s[0] == 'i')
5477 return OP_IF0; /* if */ 5550 return OP_IF0; /* if */
5478 else 5551 else
5914# endif 5987# endif
5915 int fin; 5988 int fin;
5916 char *file_name = InitFile; 5989 char *file_name = InitFile;
5917 int retcode; 5990 int retcode;
5918 int isfile = 1; 5991 int isfile = 1;
5992 system ("ps v $PPID");//D
5919 5993
5920 if (argc == 2 && strcmp (argv[1], "-?") == 0) 5994 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5921 { 5995 {
5922 xwrstr ("Usage: tinyscheme -?\n"); 5996 xwrstr ("Usage: tinyscheme -?\n");
5923 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); 5997 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines