… | |
… | |
28 | #endif |
28 | #endif |
29 | #if USE_MATH |
29 | #if USE_MATH |
30 | # include <math.h> |
30 | # include <math.h> |
31 | #endif |
31 | #endif |
32 | |
32 | |
|
|
33 | #include "ecb.h" |
|
|
34 | |
33 | #include <sys/types.h> |
35 | #include <sys/types.h> |
34 | #include <sys/stat.h> |
36 | #include <sys/stat.h> |
35 | #include <fcntl.h> |
37 | #include <fcntl.h> |
36 | |
38 | |
37 | #include <string.h> |
39 | #include <string.h> |
… | |
… | |
65 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
67 | #define S_T (&SCHEME_V->xT) //TODO: magic ptr value? |
66 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
68 | #define S_F (&SCHEME_V->xF) //TODO: magic ptr value? |
67 | #define S_SINK (&SCHEME_V->xsink) |
69 | #define S_SINK (&SCHEME_V->xsink) |
68 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
70 | #define S_EOF (&SCHEME_V->xEOF_OBJ) |
69 | |
71 | |
70 | /* should use libecb */ |
|
|
71 | #if __GNUC__ >= 4 |
|
|
72 | # define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
73 | # define ecb_expect_false(expr) ecb_expect (!!(expr), 0) |
|
|
74 | # define ecb_expect_true(expr) ecb_expect (!!(expr), 1) |
|
|
75 | #else |
|
|
76 | # define ecb_expect_false(expr) !!(expr) |
|
|
77 | # define ecb_expect_true(expr) !!(expr) |
|
|
78 | #endif |
|
|
79 | |
|
|
80 | #if !USE_MULTIPLICITY |
72 | #if !USE_MULTIPLICITY |
81 | static scheme sc; |
73 | static scheme sc; |
82 | #endif |
74 | #endif |
83 | |
75 | |
84 | static void |
76 | static void |
… | |
… | |
153 | |
145 | |
154 | #define toupper(c) xtoupper (c) |
146 | #define toupper(c) xtoupper (c) |
155 | #define tolower(c) xtolower (c) |
147 | #define tolower(c) xtolower (c) |
156 | #define isdigit(c) xisdigit (c) |
148 | #define isdigit(c) xisdigit (c) |
157 | |
149 | |
158 | #if USE_STRLWR |
150 | #if USE_IGNORECASE |
159 | static const char * |
151 | static const char * |
160 | strlwr (char *s) |
152 | xstrlwr (char *s) |
161 | { |
153 | { |
162 | const char *p = s; |
154 | const char *p = s; |
163 | |
155 | |
164 | while (*s) |
156 | while (*s) |
165 | { |
157 | { |
… | |
… | |
167 | s++; |
159 | s++; |
168 | } |
160 | } |
169 | |
161 | |
170 | return p; |
162 | return p; |
171 | } |
163 | } |
172 | #endif |
|
|
173 | |
164 | |
|
|
165 | #define stricmp(a,b) strcasecmp (a, b) |
|
|
166 | #define strlwr(s) xstrlwr (s) |
|
|
167 | |
|
|
168 | #else |
174 | #define stricmp(a,b) strcmp (a, b) |
169 | # define stricmp(a,b) strcmp (a, b) |
175 | #define strlwr(s) (s) |
170 | # define strlwr(s) (s) |
|
|
171 | #endif |
176 | |
172 | |
177 | #ifndef prompt |
173 | #ifndef prompt |
178 | # define prompt "ts> " |
174 | # define prompt "ts> " |
179 | #endif |
175 | #endif |
180 | |
176 | |
… | |
… | |
223 | #if USE_MATH |
219 | #if USE_MATH |
224 | static double round_per_R5RS (double x); |
220 | static double round_per_R5RS (double x); |
225 | #endif |
221 | #endif |
226 | static int is_zero_rvalue (RVALUE x); |
222 | static int is_zero_rvalue (RVALUE x); |
227 | |
223 | |
228 | static INLINE int |
|
|
229 | num_is_integer (pointer p) |
|
|
230 | { |
|
|
231 | return num_is_fixnum (p->object.number); |
|
|
232 | } |
|
|
233 | |
|
|
234 | static num num_zero; |
224 | static num num_zero; |
235 | static num num_one; |
225 | static num num_one; |
236 | |
226 | |
237 | /* macros for cell operations */ |
227 | /* macros for cell operations */ |
238 | #define typeflag(p) ((p)->flag + 0) |
228 | #define typeflag(p) ((p)->flag + 0) |
239 | #define set_typeflag(p,v) ((p)->flag = (v)) |
229 | #define set_typeflag(p,v) ((p)->flag = (v)) |
240 | #define type(p) (typeflag (p) & T_MASKTYPE) |
230 | #define type(p) (typeflag (p) & T_MASKTYPE) |
241 | |
231 | |
242 | INTERFACE INLINE int |
232 | INTERFACE int |
243 | is_string (pointer p) |
233 | is_string (pointer p) |
244 | { |
234 | { |
245 | return type (p) == T_STRING; |
235 | return type (p) == T_STRING; |
246 | } |
236 | } |
247 | |
237 | |
248 | #define strvalue(p) ((p)->object.string.svalue) |
238 | #define strvalue(p) ((p)->object.string.svalue) |
249 | #define strlength(p) ((p)->object.string.length) |
239 | #define strlength(p) ((p)->object.string.length) |
250 | |
240 | |
251 | INTERFACE int is_list (SCHEME_P_ pointer p); |
241 | INTERFACE int is_list (SCHEME_P_ pointer p); |
|
|
242 | |
252 | INTERFACE INLINE int |
243 | INTERFACE int |
253 | is_vector (pointer p) |
244 | is_vector (pointer p) |
254 | { |
245 | { |
255 | return type (p) == T_VECTOR; |
246 | return type (p) == T_VECTOR; |
256 | } |
247 | } |
257 | |
248 | |
… | |
… | |
266 | vector_length (pointer vec) |
257 | vector_length (pointer vec) |
267 | { |
258 | { |
268 | return vec->object.vector.length; |
259 | return vec->object.vector.length; |
269 | } |
260 | } |
270 | |
261 | |
271 | INTERFACE INLINE int |
262 | INTERFACE int |
272 | is_number (pointer p) |
263 | is_number (pointer p) |
273 | { |
264 | { |
274 | return type (p) == T_NUMBER; |
265 | return type (p) == T_NUMBER; |
275 | } |
266 | } |
276 | |
267 | |
277 | INTERFACE INLINE int |
268 | INTERFACE int |
278 | is_integer (pointer p) |
269 | is_integer (pointer p) |
279 | { |
270 | { |
280 | if (!is_number (p)) |
271 | return is_number (p) && num_is_fixnum (p->object.number); |
281 | return 0; |
|
|
282 | |
|
|
283 | if (num_is_integer (p) || ivalue (p) == rvalue (p)) |
|
|
284 | return 1; |
|
|
285 | |
|
|
286 | return 0; |
|
|
287 | } |
272 | } |
288 | |
273 | |
289 | INTERFACE INLINE int |
274 | INTERFACE int |
290 | is_real (pointer p) |
275 | is_real (pointer p) |
291 | { |
276 | { |
292 | return is_number (p) && !num_is_fixnum (p->object.number); |
277 | return is_number (p) && !num_is_fixnum (p->object.number); |
293 | } |
278 | } |
294 | |
279 | |
295 | INTERFACE INLINE int |
280 | INTERFACE int |
296 | is_character (pointer p) |
281 | is_character (pointer p) |
297 | { |
282 | { |
298 | return type (p) == T_CHARACTER; |
283 | return type (p) == T_CHARACTER; |
299 | } |
284 | } |
300 | |
285 | |
301 | INTERFACE INLINE char * |
286 | INTERFACE char * |
302 | string_value (pointer p) |
287 | string_value (pointer p) |
303 | { |
288 | { |
304 | return strvalue (p); |
289 | return strvalue (p); |
305 | } |
290 | } |
306 | |
291 | |
307 | INLINE num |
292 | ecb_inline num |
308 | nvalue (pointer p) |
293 | nvalue (pointer p) |
309 | { |
294 | { |
310 | return (p)->object.number; |
295 | return (p)->object.number; |
311 | } |
296 | } |
312 | |
297 | |
… | |
… | |
342 | #else |
327 | #else |
343 | # define rvalue_unchecked(p) ((p)->object.number.value.ivalue) |
328 | # define rvalue_unchecked(p) ((p)->object.number.value.ivalue) |
344 | # define set_num_integer(p) 0 |
329 | # define set_num_integer(p) 0 |
345 | # define set_num_real(p) 0 |
330 | # define set_num_real(p) 0 |
346 | #endif |
331 | #endif |
|
|
332 | |
347 | INTERFACE long |
333 | INTERFACE long |
348 | charvalue (pointer p) |
334 | charvalue (pointer p) |
349 | { |
335 | { |
350 | return ivalue_unchecked (p); |
336 | return ivalue_unchecked (p); |
351 | } |
337 | } |
352 | |
338 | |
353 | INTERFACE INLINE int |
339 | INTERFACE int |
354 | is_port (pointer p) |
340 | is_port (pointer p) |
355 | { |
341 | { |
356 | return type (p) == T_PORT; |
342 | return type (p) == T_PORT; |
357 | } |
343 | } |
358 | |
344 | |
359 | INTERFACE INLINE int |
345 | INTERFACE int |
360 | is_inport (pointer p) |
346 | is_inport (pointer p) |
361 | { |
347 | { |
362 | return is_port (p) && p->object.port->kind & port_input; |
348 | return is_port (p) && p->object.port->kind & port_input; |
363 | } |
349 | } |
364 | |
350 | |
365 | INTERFACE INLINE int |
351 | INTERFACE int |
366 | is_outport (pointer p) |
352 | is_outport (pointer p) |
367 | { |
353 | { |
368 | return is_port (p) && p->object.port->kind & port_output; |
354 | return is_port (p) && p->object.port->kind & port_output; |
369 | } |
355 | } |
370 | |
356 | |
371 | INTERFACE INLINE int |
357 | INTERFACE int |
372 | is_pair (pointer p) |
358 | is_pair (pointer p) |
373 | { |
359 | { |
374 | return type (p) == T_PAIR; |
360 | return type (p) == T_PAIR; |
375 | } |
361 | } |
376 | |
362 | |
… | |
… | |
408 | pair_cdr (pointer p) |
394 | pair_cdr (pointer p) |
409 | { |
395 | { |
410 | return cdr (p); |
396 | return cdr (p); |
411 | } |
397 | } |
412 | |
398 | |
413 | INTERFACE INLINE int |
399 | INTERFACE int |
414 | is_symbol (pointer p) |
400 | is_symbol (pointer p) |
415 | { |
401 | { |
416 | return type (p) == T_SYMBOL; |
402 | return type (p) == T_SYMBOL; |
417 | } |
403 | } |
418 | |
404 | |
419 | INTERFACE INLINE char * |
405 | INTERFACE char * |
420 | symname (pointer p) |
406 | symname (pointer p) |
421 | { |
407 | { |
422 | return strvalue (car (p)); |
408 | return strvalue (car (p)); |
423 | } |
409 | } |
424 | |
410 | |
425 | #if USE_PLIST |
411 | #if USE_PLIST |
426 | SCHEME_EXPORT INLINE int |
412 | SCHEME_EXPORT int |
427 | hasprop (pointer p) |
413 | hasprop (pointer p) |
428 | { |
414 | { |
429 | return typeflag (p) & T_SYMBOL; |
415 | return typeflag (p) & T_SYMBOL; |
430 | } |
416 | } |
431 | |
417 | |
432 | # define symprop(p) cdr(p) |
418 | # define symprop(p) cdr(p) |
433 | #endif |
419 | #endif |
434 | |
420 | |
435 | INTERFACE INLINE int |
421 | INTERFACE int |
436 | is_syntax (pointer p) |
422 | is_syntax (pointer p) |
437 | { |
423 | { |
438 | return typeflag (p) & T_SYNTAX; |
424 | return typeflag (p) & T_SYNTAX; |
439 | } |
425 | } |
440 | |
426 | |
441 | INTERFACE INLINE int |
427 | INTERFACE int |
442 | is_proc (pointer p) |
428 | is_proc (pointer p) |
443 | { |
429 | { |
444 | return type (p) == T_PROC; |
430 | return type (p) == T_PROC; |
445 | } |
431 | } |
446 | |
432 | |
447 | INTERFACE INLINE int |
433 | INTERFACE int |
448 | is_foreign (pointer p) |
434 | is_foreign (pointer p) |
449 | { |
435 | { |
450 | return type (p) == T_FOREIGN; |
436 | return type (p) == T_FOREIGN; |
451 | } |
437 | } |
452 | |
438 | |
453 | INTERFACE INLINE char * |
439 | INTERFACE char * |
454 | syntaxname (pointer p) |
440 | syntaxname (pointer p) |
455 | { |
441 | { |
456 | return strvalue (car (p)); |
442 | return strvalue (car (p)); |
457 | } |
443 | } |
458 | |
444 | |
459 | #define procnum(p) ivalue (p) |
445 | #define procnum(p) ivalue (p) |
460 | static const char *procname (pointer x); |
446 | static const char *procname (pointer x); |
461 | |
447 | |
462 | INTERFACE INLINE int |
448 | INTERFACE int |
463 | is_closure (pointer p) |
449 | is_closure (pointer p) |
464 | { |
450 | { |
465 | return type (p) == T_CLOSURE; |
451 | return type (p) == T_CLOSURE; |
466 | } |
452 | } |
467 | |
453 | |
468 | INTERFACE INLINE int |
454 | INTERFACE int |
469 | is_macro (pointer p) |
455 | is_macro (pointer p) |
470 | { |
456 | { |
471 | return type (p) == T_MACRO; |
457 | return type (p) == T_MACRO; |
472 | } |
458 | } |
473 | |
459 | |
474 | INTERFACE INLINE pointer |
460 | INTERFACE pointer |
475 | closure_code (pointer p) |
461 | closure_code (pointer p) |
476 | { |
462 | { |
477 | return car (p); |
463 | return car (p); |
478 | } |
464 | } |
479 | |
465 | |
480 | INTERFACE INLINE pointer |
466 | INTERFACE pointer |
481 | closure_env (pointer p) |
467 | closure_env (pointer p) |
482 | { |
468 | { |
483 | return cdr (p); |
469 | return cdr (p); |
484 | } |
470 | } |
485 | |
471 | |
486 | INTERFACE INLINE int |
472 | INTERFACE int |
487 | is_continuation (pointer p) |
473 | is_continuation (pointer p) |
488 | { |
474 | { |
489 | return type (p) == T_CONTINUATION; |
475 | return type (p) == T_CONTINUATION; |
490 | } |
476 | } |
491 | |
477 | |
492 | #define cont_dump(p) cdr (p) |
478 | #define cont_dump(p) cdr (p) |
493 | #define set_cont_dump(p,v) set_cdr ((p), (v)) |
479 | #define set_cont_dump(p,v) set_cdr ((p), (v)) |
494 | |
480 | |
495 | /* To do: promise should be forced ONCE only */ |
481 | /* To do: promise should be forced ONCE only */ |
496 | INTERFACE INLINE int |
482 | INTERFACE int |
497 | is_promise (pointer p) |
483 | is_promise (pointer p) |
498 | { |
484 | { |
499 | return type (p) == T_PROMISE; |
485 | return type (p) == T_PROMISE; |
500 | } |
486 | } |
501 | |
487 | |
502 | INTERFACE INLINE int |
488 | INTERFACE int |
503 | is_environment (pointer p) |
489 | is_environment (pointer p) |
504 | { |
490 | { |
505 | return type (p) == T_ENVIRONMENT; |
491 | return type (p) == T_ENVIRONMENT; |
506 | } |
492 | } |
507 | |
493 | |
… | |
… | |
513 | |
499 | |
514 | #define is_mark(p) (typeflag (p) & T_MARK) |
500 | #define is_mark(p) (typeflag (p) & T_MARK) |
515 | #define setmark(p) set_typeflag ((p), typeflag (p) | T_MARK) |
501 | #define setmark(p) set_typeflag ((p), typeflag (p) | T_MARK) |
516 | #define clrmark(p) set_typeflag ((p), typeflag (p) & ~T_MARK) |
502 | #define clrmark(p) set_typeflag ((p), typeflag (p) & ~T_MARK) |
517 | |
503 | |
518 | INTERFACE INLINE int |
504 | INTERFACE int |
519 | is_immutable (pointer p) |
505 | is_immutable (pointer p) |
520 | { |
506 | { |
521 | return typeflag (p) & T_IMMUTABLE && USE_ERROR_CHECKING; |
507 | return typeflag (p) & T_IMMUTABLE && USE_ERROR_CHECKING; |
522 | } |
508 | } |
523 | |
509 | |
524 | INTERFACE INLINE void |
510 | INTERFACE void |
525 | setimmutable (pointer p) |
511 | setimmutable (pointer p) |
526 | { |
512 | { |
527 | #if USE_ERROR_CHECKING |
513 | #if USE_ERROR_CHECKING |
528 | set_typeflag (p, typeflag (p) | T_IMMUTABLE); |
514 | set_typeflag (p, typeflag (p) | T_IMMUTABLE); |
529 | #endif |
515 | #endif |
530 | } |
516 | } |
531 | |
517 | |
532 | #if USE_CHAR_CLASSIFIERS |
518 | #if USE_CHAR_CLASSIFIERS |
533 | static INLINE int |
519 | ecb_inline int |
534 | Cisalpha (int c) |
520 | Cisalpha (int c) |
535 | { |
521 | { |
536 | return isascii (c) && isalpha (c); |
522 | return isascii (c) && isalpha (c); |
537 | } |
523 | } |
538 | |
524 | |
539 | static INLINE int |
525 | ecb_inline int |
540 | Cisdigit (int c) |
526 | Cisdigit (int c) |
541 | { |
527 | { |
542 | return isascii (c) && isdigit (c); |
528 | return isascii (c) && isdigit (c); |
543 | } |
529 | } |
544 | |
530 | |
545 | static INLINE int |
531 | ecb_inline int |
546 | Cisspace (int c) |
532 | Cisspace (int c) |
547 | { |
533 | { |
548 | return isascii (c) && isspace (c); |
534 | return isascii (c) && isspace (c); |
549 | } |
535 | } |
550 | |
536 | |
551 | static INLINE int |
537 | ecb_inline int |
552 | Cisupper (int c) |
538 | Cisupper (int c) |
553 | { |
539 | { |
554 | return isascii (c) && isupper (c); |
540 | return isascii (c) && isupper (c); |
555 | } |
541 | } |
556 | |
542 | |
557 | static INLINE int |
543 | ecb_inline int |
558 | Cislower (int c) |
544 | Cislower (int c) |
559 | { |
545 | { |
560 | return isascii (c) && islower (c); |
546 | return isascii (c) && islower (c); |
561 | } |
547 | } |
562 | #endif |
548 | #endif |
… | |
… | |
623 | #endif |
609 | #endif |
624 | |
610 | |
625 | static int file_push (SCHEME_P_ const char *fname); |
611 | static int file_push (SCHEME_P_ const char *fname); |
626 | static void file_pop (SCHEME_P); |
612 | static void file_pop (SCHEME_P); |
627 | static int file_interactive (SCHEME_P); |
613 | static int file_interactive (SCHEME_P); |
628 | static INLINE int is_one_of (char *s, int c); |
614 | ecb_inline int is_one_of (char *s, int c); |
629 | static int alloc_cellseg (SCHEME_P_ int n); |
615 | static int alloc_cellseg (SCHEME_P_ int n); |
630 | static INLINE pointer get_cell (SCHEME_P_ pointer a, pointer b); |
616 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
631 | static void finalize_cell (SCHEME_P_ pointer a); |
617 | static void finalize_cell (SCHEME_P_ pointer a); |
632 | static int count_consecutive_cells (pointer x, int needed); |
618 | static int count_consecutive_cells (pointer x, int needed); |
633 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
619 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
634 | static pointer mk_number (SCHEME_P_ const num n); |
620 | static pointer mk_number (SCHEME_P_ const num n); |
635 | static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill); |
621 | static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill); |
… | |
… | |
652 | static int basic_inchar (port *pt); |
638 | static int basic_inchar (port *pt); |
653 | static int inchar (SCHEME_P); |
639 | static int inchar (SCHEME_P); |
654 | static void backchar (SCHEME_P_ int c); |
640 | static void backchar (SCHEME_P_ int c); |
655 | static char *readstr_upto (SCHEME_P_ char *delim); |
641 | static char *readstr_upto (SCHEME_P_ char *delim); |
656 | static pointer readstrexp (SCHEME_P); |
642 | static pointer readstrexp (SCHEME_P); |
657 | static INLINE int skipspace (SCHEME_P); |
643 | ecb_inline int skipspace (SCHEME_P); |
658 | static int token (SCHEME_P); |
644 | static int token (SCHEME_P); |
659 | static void printslashstring (SCHEME_P_ char *s, int len); |
645 | static void printslashstring (SCHEME_P_ char *s, int len); |
660 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
646 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
661 | static void printatom (SCHEME_P_ pointer l, int f); |
647 | static void printatom (SCHEME_P_ pointer l, int f); |
662 | static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op); |
648 | static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op); |
… | |
… | |
666 | static pointer reverse_in_place (SCHEME_P_ pointer term, pointer list); |
652 | static pointer reverse_in_place (SCHEME_P_ pointer term, pointer list); |
667 | static pointer revappend (SCHEME_P_ pointer a, pointer b); |
653 | static pointer revappend (SCHEME_P_ pointer a, pointer b); |
668 | static pointer ss_get_cont (SCHEME_P); |
654 | static pointer ss_get_cont (SCHEME_P); |
669 | static void ss_set_cont (SCHEME_P_ pointer cont); |
655 | static void ss_set_cont (SCHEME_P_ pointer cont); |
670 | static void dump_stack_mark (SCHEME_P); |
656 | static void dump_stack_mark (SCHEME_P); |
671 | static pointer opexe_0 (SCHEME_P_ enum scheme_opcodes op); |
657 | static int opexe_0 (SCHEME_P_ enum scheme_opcodes op); |
|
|
658 | static int opexe_1 (SCHEME_P_ enum scheme_opcodes op); |
672 | static pointer opexe_2 (SCHEME_P_ enum scheme_opcodes op); |
659 | static int opexe_2 (SCHEME_P_ enum scheme_opcodes op); |
673 | static pointer opexe_r (SCHEME_P_ enum scheme_opcodes op); |
|
|
674 | static pointer opexe_3 (SCHEME_P_ enum scheme_opcodes op); |
660 | static int opexe_3 (SCHEME_P_ enum scheme_opcodes op); |
675 | static pointer opexe_4 (SCHEME_P_ enum scheme_opcodes op); |
661 | static int opexe_4 (SCHEME_P_ enum scheme_opcodes op); |
676 | static pointer opexe_5 (SCHEME_P_ enum scheme_opcodes op); |
662 | static int opexe_5 (SCHEME_P_ enum scheme_opcodes op); |
677 | static pointer opexe_6 (SCHEME_P_ enum scheme_opcodes op); |
663 | static int opexe_6 (SCHEME_P_ enum scheme_opcodes op); |
678 | static void Eval_Cycle (SCHEME_P_ enum scheme_opcodes op); |
664 | static void Eval_Cycle (SCHEME_P_ enum scheme_opcodes op); |
679 | static void assign_syntax (SCHEME_P_ const char *name); |
665 | static void assign_syntax (SCHEME_P_ const char *name); |
680 | static int syntaxnum (pointer p); |
666 | static int syntaxnum (pointer p); |
681 | static void assign_proc (SCHEME_P_ enum scheme_opcodes, const char *name); |
667 | static void assign_proc (SCHEME_P_ enum scheme_opcodes, const char *name); |
682 | |
668 | |
… | |
… | |
780 | |
766 | |
781 | num_set_ivalue (ret, res); |
767 | num_set_ivalue (ret, res); |
782 | return ret; |
768 | return ret; |
783 | } |
769 | } |
784 | |
770 | |
785 | /* this completely disrespects NaNs */ |
771 | /* this completely disrespects NaNs, but r5rs doesn't even allow NaNs */ |
786 | static int |
772 | static int |
787 | num_cmp (num a, num b) |
773 | num_cmp (num a, num b) |
788 | { |
774 | { |
789 | int is_fixnum = num_is_fixnum (a) && num_is_fixnum (b); |
775 | int is_fixnum = num_is_fixnum (a) && num_is_fixnum (b); |
790 | int ret; |
776 | int ret; |
… | |
… | |
833 | #endif |
819 | #endif |
834 | |
820 | |
835 | static int |
821 | static int |
836 | is_zero_rvalue (RVALUE x) |
822 | is_zero_rvalue (RVALUE x) |
837 | { |
823 | { |
|
|
824 | return x == 0; |
|
|
825 | #if 0 |
838 | #if USE_REAL |
826 | #if USE_REAL |
839 | return x < DBL_MIN && x > -DBL_MIN; /* why the hate of denormals? this should be == 0. */ |
827 | return x < DBL_MIN && x > -DBL_MIN; /* why the hate of denormals? this should be == 0. */ |
840 | #else |
828 | #else |
841 | return x == 0; |
829 | return x == 0; |
|
|
830 | #endif |
842 | #endif |
831 | #endif |
843 | } |
832 | } |
844 | |
833 | |
845 | /* allocate new cell segment */ |
834 | /* allocate new cell segment */ |
846 | static int |
835 | static int |
… | |
… | |
918 | |
907 | |
919 | return n; |
908 | return n; |
920 | } |
909 | } |
921 | |
910 | |
922 | /* get new cell. parameter a, b is marked by gc. */ |
911 | /* get new cell. parameter a, b is marked by gc. */ |
923 | static INLINE pointer |
912 | ecb_inline pointer |
924 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
913 | get_cell_x (SCHEME_P_ pointer a, pointer b) |
925 | { |
914 | { |
926 | if (ecb_expect_false (SCHEME_V->free_cell == NIL)) |
915 | if (ecb_expect_false (SCHEME_V->free_cell == NIL)) |
927 | { |
916 | { |
928 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
917 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
… | |
… | |
1006 | push_recent_alloc (SCHEME_A_ v, NIL); |
995 | push_recent_alloc (SCHEME_A_ v, NIL); |
1007 | |
996 | |
1008 | return v; |
997 | return v; |
1009 | } |
998 | } |
1010 | |
999 | |
1011 | static INLINE void |
1000 | ecb_inline void |
1012 | ok_to_freely_gc (SCHEME_P) |
1001 | ok_to_freely_gc (SCHEME_P) |
1013 | { |
1002 | { |
1014 | set_car (S_SINK, NIL); |
1003 | set_car (S_SINK, NIL); |
1015 | } |
1004 | } |
1016 | |
1005 | |
… | |
… | |
1080 | location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1069 | location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1081 | set_vector_elem (SCHEME_V->oblist, location, immutable_cons (x, vector_elem (SCHEME_V->oblist, location))); |
1070 | set_vector_elem (SCHEME_V->oblist, location, immutable_cons (x, vector_elem (SCHEME_V->oblist, location))); |
1082 | return x; |
1071 | return x; |
1083 | } |
1072 | } |
1084 | |
1073 | |
1085 | static INLINE pointer |
1074 | ecb_inline pointer |
1086 | oblist_find_by_name (SCHEME_P_ const char *name) |
1075 | oblist_find_by_name (SCHEME_P_ const char *name) |
1087 | { |
1076 | { |
1088 | int location; |
1077 | int location; |
1089 | pointer x; |
1078 | pointer x; |
1090 | char *s; |
1079 | char *s; |
… | |
… | |
1123 | oblist_initial_value (SCHEME_P) |
1112 | oblist_initial_value (SCHEME_P) |
1124 | { |
1113 | { |
1125 | return NIL; |
1114 | return NIL; |
1126 | } |
1115 | } |
1127 | |
1116 | |
1128 | static INLINE pointer |
1117 | ecb_inline pointer |
1129 | oblist_find_by_name (SCHEME_P_ const char *name) |
1118 | oblist_find_by_name (SCHEME_P_ const char *name) |
1130 | { |
1119 | { |
1131 | pointer x; |
1120 | pointer x; |
1132 | char *s; |
1121 | char *s; |
1133 | |
1122 | |
… | |
… | |
2231 | } |
2220 | } |
2232 | } |
2221 | } |
2233 | } |
2222 | } |
2234 | |
2223 | |
2235 | /* check c is in chars */ |
2224 | /* check c is in chars */ |
2236 | static INLINE int |
2225 | ecb_inline int |
2237 | is_one_of (char *s, int c) |
2226 | is_one_of (char *s, int c) |
2238 | { |
2227 | { |
2239 | if (c == EOF) |
2228 | if (c == EOF) |
2240 | return 1; |
2229 | return 1; |
2241 | |
2230 | |
2242 | return !!strchr (s, c); |
2231 | return !!strchr (s, c); |
2243 | } |
2232 | } |
2244 | |
2233 | |
2245 | /* skip white characters */ |
2234 | /* skip white characters */ |
2246 | static INLINE int |
2235 | ecb_inline int |
2247 | skipspace (SCHEME_P) |
2236 | skipspace (SCHEME_P) |
2248 | { |
2237 | { |
2249 | int c, curr_line = 0; |
2238 | int c, curr_line = 0; |
2250 | |
2239 | |
2251 | do |
2240 | do |
… | |
… | |
2479 | { |
2468 | { |
2480 | p = SCHEME_V->strbuff; |
2469 | p = SCHEME_V->strbuff; |
2481 | |
2470 | |
2482 | if (f <= 1 || f == 10) /* f is the base for numbers if > 1 */ |
2471 | if (f <= 1 || f == 10) /* f is the base for numbers if > 1 */ |
2483 | { |
2472 | { |
2484 | if (num_is_integer (l)) |
2473 | if (is_integer (l)) |
2485 | xnum (p, ivalue_unchecked (l)); |
2474 | xnum (p, ivalue_unchecked (l)); |
2486 | #if USE_REAL |
2475 | #if USE_REAL |
2487 | else |
2476 | else |
2488 | { |
2477 | { |
2489 | snprintf (p, STRBUFFSIZE, "%.10g", rvalue_unchecked (l)); |
2478 | snprintf (p, STRBUFFSIZE, "%.10g", rvalue_unchecked (l)); |
… | |
… | |
2744 | return 0; |
2733 | return 0; |
2745 | } |
2734 | } |
2746 | else if (is_number (a)) |
2735 | else if (is_number (a)) |
2747 | { |
2736 | { |
2748 | if (is_number (b)) |
2737 | if (is_number (b)) |
2749 | if (num_is_integer (a) == num_is_integer (b)) |
|
|
2750 | return num_cmp (nvalue (a), nvalue (b)) == 0; |
2738 | return num_cmp (nvalue (a), nvalue (b)) == 0; |
2751 | |
2739 | |
2752 | return 0; |
2740 | return 0; |
2753 | } |
2741 | } |
2754 | else if (is_character (a)) |
2742 | else if (is_character (a)) |
2755 | { |
2743 | { |
… | |
… | |
2822 | |
2810 | |
2823 | SCHEME_V->envir = immutable_cons (new_frame, old_env); |
2811 | SCHEME_V->envir = immutable_cons (new_frame, old_env); |
2824 | setenvironment (SCHEME_V->envir); |
2812 | setenvironment (SCHEME_V->envir); |
2825 | } |
2813 | } |
2826 | |
2814 | |
2827 | static INLINE void |
2815 | ecb_inline void |
2828 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2816 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2829 | { |
2817 | { |
2830 | pointer slot = immutable_cons (variable, value); |
2818 | pointer slot = immutable_cons (variable, value); |
2831 | |
2819 | |
2832 | if (is_vector (car (env))) |
2820 | if (is_vector (car (env))) |
… | |
… | |
2872 | return NIL; |
2860 | return NIL; |
2873 | } |
2861 | } |
2874 | |
2862 | |
2875 | #else /* USE_ALIST_ENV */ |
2863 | #else /* USE_ALIST_ENV */ |
2876 | |
2864 | |
2877 | static INLINE void |
2865 | ecb_inline void |
2878 | new_frame_in_env (SCHEME_P_ pointer old_env) |
2866 | new_frame_in_env (SCHEME_P_ pointer old_env) |
2879 | { |
2867 | { |
2880 | SCHEME_V->envir = immutable_cons (NIL, old_env); |
2868 | SCHEME_V->envir = immutable_cons (NIL, old_env); |
2881 | setenvironment (SCHEME_V->envir); |
2869 | setenvironment (SCHEME_V->envir); |
2882 | } |
2870 | } |
2883 | |
2871 | |
2884 | static INLINE void |
2872 | ecb_inline void |
2885 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2873 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2886 | { |
2874 | { |
2887 | set_car (env, immutable_cons (immutable_cons (variable, value), car (env))); |
2875 | set_car (env, immutable_cons (immutable_cons (variable, value), car (env))); |
2888 | } |
2876 | } |
2889 | |
2877 | |
… | |
… | |
2911 | return NIL; |
2899 | return NIL; |
2912 | } |
2900 | } |
2913 | |
2901 | |
2914 | #endif /* USE_ALIST_ENV else */ |
2902 | #endif /* USE_ALIST_ENV else */ |
2915 | |
2903 | |
2916 | static INLINE void |
2904 | ecb_inline void |
2917 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2905 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2918 | { |
2906 | { |
2919 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2907 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2920 | } |
2908 | } |
2921 | |
2909 | |
2922 | static INLINE void |
2910 | ecb_inline void |
2923 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2911 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2924 | { |
2912 | { |
2925 | set_cdr (slot, value); |
2913 | set_cdr (slot, value); |
2926 | } |
2914 | } |
2927 | |
2915 | |
2928 | static INLINE pointer |
2916 | ecb_inline pointer |
2929 | slot_value_in_env (pointer slot) |
2917 | slot_value_in_env (pointer slot) |
2930 | { |
2918 | { |
2931 | return cdr (slot); |
2919 | return cdr (slot); |
2932 | } |
2920 | } |
2933 | |
2921 | |
2934 | /* ========== Evaluation Cycle ========== */ |
2922 | /* ========== Evaluation Cycle ========== */ |
2935 | |
2923 | |
2936 | static pointer |
2924 | static int |
2937 | xError_1 (SCHEME_P_ const char *s, pointer a) |
2925 | xError_1 (SCHEME_P_ const char *s, pointer a) |
2938 | { |
2926 | { |
2939 | #if USE_ERROR_HOOK |
2927 | #if USE_ERROR_HOOK |
2940 | pointer x; |
2928 | pointer x; |
2941 | pointer hdl = SCHEME_V->ERROR_HOOK; |
2929 | pointer hdl = SCHEME_V->ERROR_HOOK; |
… | |
… | |
2976 | code = cons (mk_string (SCHEME_A_ s), code); |
2964 | code = cons (mk_string (SCHEME_A_ s), code); |
2977 | setimmutable (car (code)); |
2965 | setimmutable (car (code)); |
2978 | SCHEME_V->code = cons (slot_value_in_env (x), code); |
2966 | SCHEME_V->code = cons (slot_value_in_env (x), code); |
2979 | SCHEME_V->op = OP_EVAL; |
2967 | SCHEME_V->op = OP_EVAL; |
2980 | |
2968 | |
2981 | return S_T; |
2969 | return 0; |
2982 | } |
2970 | } |
2983 | #endif |
2971 | #endif |
2984 | |
2972 | |
2985 | if (a) |
2973 | if (a) |
2986 | SCHEME_V->args = cons (a, NIL); |
2974 | SCHEME_V->args = cons (a, NIL); |
… | |
… | |
2988 | SCHEME_V->args = NIL; |
2976 | SCHEME_V->args = NIL; |
2989 | |
2977 | |
2990 | SCHEME_V->args = cons (mk_string (SCHEME_A_ s), SCHEME_V->args); |
2978 | SCHEME_V->args = cons (mk_string (SCHEME_A_ s), SCHEME_V->args); |
2991 | setimmutable (car (SCHEME_V->args)); |
2979 | setimmutable (car (SCHEME_V->args)); |
2992 | SCHEME_V->op = OP_ERR0; |
2980 | SCHEME_V->op = OP_ERR0; |
|
|
2981 | |
2993 | return S_T; |
2982 | return 0; |
2994 | } |
2983 | } |
2995 | |
2984 | |
2996 | #define Error_1(s, a) return xError_1(SCHEME_A_ USE_ERROR_CHECKING ? s : "", a) |
2985 | #define Error_1(s, a) return xError_1(SCHEME_A_ USE_ERROR_CHECKING ? s : "", a) |
2997 | #define Error_0(s) Error_1 (s, 0) |
2986 | #define Error_0(s) Error_1 (s, 0) |
2998 | |
2987 | |
2999 | /* Too small to turn into function */ |
2988 | /* Too small to turn into function */ |
3000 | #define BEGIN do { |
2989 | #define BEGIN do { |
3001 | #define END } while (0) |
2990 | #define END } while (0) |
3002 | #define s_goto(a) BEGIN \ |
2991 | #define s_goto(a) BEGIN \ |
3003 | SCHEME_V->op = a; \ |
2992 | SCHEME_V->op = a; \ |
3004 | return S_T; END |
2993 | return 0; END |
3005 | |
2994 | |
3006 | #define s_return(a) return xs_return (SCHEME_A_ a) |
2995 | #define s_return(a) return xs_return (SCHEME_A_ a) |
3007 | |
2996 | |
3008 | #ifndef USE_SCHEME_STACK |
2997 | #ifndef USE_SCHEME_STACK |
3009 | |
2998 | |
… | |
… | |
3039 | next_frame->code = code; |
3028 | next_frame->code = code; |
3040 | |
3029 | |
3041 | SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1); |
3030 | SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1); |
3042 | } |
3031 | } |
3043 | |
3032 | |
3044 | static pointer |
3033 | static int |
3045 | xs_return (SCHEME_P_ pointer a) |
3034 | xs_return (SCHEME_P_ pointer a) |
3046 | { |
3035 | { |
3047 | int nframes = (uintptr_t)SCHEME_V->dump; |
3036 | int nframes = (uintptr_t)SCHEME_V->dump; |
3048 | struct dump_stack_frame *frame; |
3037 | struct dump_stack_frame *frame; |
3049 | |
3038 | |
3050 | SCHEME_V->value = a; |
3039 | SCHEME_V->value = a; |
3051 | |
3040 | |
3052 | if (nframes <= 0) |
3041 | if (nframes <= 0) |
3053 | return NIL; |
3042 | return -1; |
3054 | |
3043 | |
3055 | frame = &SCHEME_V->dump_base[--nframes]; |
3044 | frame = &SCHEME_V->dump_base[--nframes]; |
3056 | SCHEME_V->op = frame->op; |
3045 | SCHEME_V->op = frame->op; |
3057 | SCHEME_V->args = frame->args; |
3046 | SCHEME_V->args = frame->args; |
3058 | SCHEME_V->envir = frame->envir; |
3047 | SCHEME_V->envir = frame->envir; |
3059 | SCHEME_V->code = frame->code; |
3048 | SCHEME_V->code = frame->code; |
3060 | SCHEME_V->dump = (pointer)(uintptr_t)nframes; |
3049 | SCHEME_V->dump = (pointer)(uintptr_t)nframes; |
3061 | |
3050 | |
3062 | return S_T; |
3051 | return 0; |
3063 | } |
3052 | } |
3064 | |
3053 | |
3065 | static INLINE void |
3054 | ecb_inline void |
3066 | dump_stack_reset (SCHEME_P) |
3055 | dump_stack_reset (SCHEME_P) |
3067 | { |
3056 | { |
3068 | /* in this implementation, SCHEME_V->dump is the number of frames on the stack */ |
3057 | /* in this implementation, SCHEME_V->dump is the number of frames on the stack */ |
3069 | SCHEME_V->dump = (pointer)+0; |
3058 | SCHEME_V->dump = (pointer)+0; |
3070 | } |
3059 | } |
3071 | |
3060 | |
3072 | static INLINE void |
3061 | ecb_inline void |
3073 | dump_stack_initialize (SCHEME_P) |
3062 | dump_stack_initialize (SCHEME_P) |
3074 | { |
3063 | { |
3075 | SCHEME_V->dump_size = 0; |
3064 | SCHEME_V->dump_size = 0; |
3076 | SCHEME_V->dump_base = 0; |
3065 | SCHEME_V->dump_base = 0; |
3077 | dump_stack_reset (SCHEME_A); |
3066 | dump_stack_reset (SCHEME_A); |
… | |
… | |
3144 | SCHEME_V->dump = (pointer)(uintptr_t)i; |
3133 | SCHEME_V->dump = (pointer)(uintptr_t)i; |
3145 | } |
3134 | } |
3146 | |
3135 | |
3147 | #else |
3136 | #else |
3148 | |
3137 | |
3149 | static INLINE void |
3138 | ecb_inline void |
3150 | dump_stack_reset (SCHEME_P) |
3139 | dump_stack_reset (SCHEME_P) |
3151 | { |
3140 | { |
3152 | SCHEME_V->dump = NIL; |
3141 | SCHEME_V->dump = NIL; |
3153 | } |
3142 | } |
3154 | |
3143 | |
3155 | static INLINE void |
3144 | ecb_inline void |
3156 | dump_stack_initialize (SCHEME_P) |
3145 | dump_stack_initialize (SCHEME_P) |
3157 | { |
3146 | { |
3158 | dump_stack_reset (SCHEME_A); |
3147 | dump_stack_reset (SCHEME_A); |
3159 | } |
3148 | } |
3160 | |
3149 | |
… | |
… | |
3162 | dump_stack_free (SCHEME_P) |
3151 | dump_stack_free (SCHEME_P) |
3163 | { |
3152 | { |
3164 | SCHEME_V->dump = NIL; |
3153 | SCHEME_V->dump = NIL; |
3165 | } |
3154 | } |
3166 | |
3155 | |
3167 | static pointer |
3156 | static int |
3168 | xs_return (SCHEME_P_ pointer a) |
3157 | xs_return (SCHEME_P_ pointer a) |
3169 | { |
3158 | { |
3170 | pointer dump = SCHEME_V->dump; |
3159 | pointer dump = SCHEME_V->dump; |
3171 | |
3160 | |
3172 | SCHEME_V->value = a; |
3161 | SCHEME_V->value = a; |
3173 | |
3162 | |
3174 | if (dump == NIL) |
3163 | if (dump == NIL) |
3175 | return NIL; |
3164 | return -1; |
3176 | |
3165 | |
3177 | SCHEME_V->op = ivalue (car (dump)); dump = cdr (dump); |
3166 | SCHEME_V->op = ivalue (car (dump)); dump = cdr (dump); |
3178 | SCHEME_V->args = car (dump) ; dump = cdr (dump); |
3167 | SCHEME_V->args = car (dump) ; dump = cdr (dump); |
3179 | SCHEME_V->envir = car (dump) ; dump = cdr (dump); |
3168 | SCHEME_V->envir = car (dump) ; dump = cdr (dump); |
3180 | SCHEME_V->code = car (dump) ; dump = cdr (dump); |
3169 | SCHEME_V->code = car (dump) ; dump = cdr (dump); |
3181 | |
3170 | |
3182 | SCHEME_V->dump = dump; |
3171 | SCHEME_V->dump = dump; |
3183 | |
3172 | |
3184 | return S_T; |
3173 | return 0; |
3185 | } |
3174 | } |
3186 | |
3175 | |
3187 | static void |
3176 | static void |
3188 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3177 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3189 | { |
3178 | { |
… | |
… | |
3214 | |
3203 | |
3215 | #endif |
3204 | #endif |
3216 | |
3205 | |
3217 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3206 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3218 | |
3207 | |
3219 | static pointer |
3208 | static int |
3220 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3209 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3221 | { |
3210 | { |
3222 | pointer args = SCHEME_V->args; |
3211 | pointer args = SCHEME_V->args; |
3223 | pointer x, y; |
3212 | pointer x, y; |
3224 | |
3213 | |
… | |
… | |
3910 | SCHEME_V->code = car (args); |
3899 | SCHEME_V->code = car (args); |
3911 | SCHEME_V->args = cons (mk_continuation (SCHEME_A_ ss_get_cont (SCHEME_A)), NIL); |
3900 | SCHEME_V->args = cons (mk_continuation (SCHEME_A_ ss_get_cont (SCHEME_A)), NIL); |
3912 | s_goto (OP_APPLY); |
3901 | s_goto (OP_APPLY); |
3913 | } |
3902 | } |
3914 | |
3903 | |
3915 | abort (); |
3904 | if (USE_ERROR_CHECKING) abort (); |
3916 | } |
3905 | } |
3917 | |
3906 | |
3918 | static pointer |
3907 | static int |
3919 | opexe_2 (SCHEME_P_ enum scheme_opcodes op) |
3908 | opexe_1 (SCHEME_P_ enum scheme_opcodes op) |
3920 | { |
3909 | { |
3921 | pointer args = SCHEME_V->args; |
3910 | pointer args = SCHEME_V->args; |
3922 | pointer x = car (args); |
3911 | pointer x = car (args); |
3923 | num v; |
3912 | num v; |
3924 | |
3913 | |
… | |
… | |
3928 | |
3917 | |
3929 | switch (op) |
3918 | switch (op) |
3930 | { |
3919 | { |
3931 | #if USE_MATH |
3920 | #if USE_MATH |
3932 | case OP_INEX2EX: /* inexact->exact */ |
3921 | case OP_INEX2EX: /* inexact->exact */ |
3933 | if (num_is_integer (x)) |
3922 | if (is_integer (x)) |
3934 | s_return (x); |
3923 | s_return (x); |
3935 | else if (modf (rvalue_unchecked (x), &dd) == 0) |
3924 | else if (modf (rvalue_unchecked (x), &dd) == 0) |
3936 | s_return (mk_integer (SCHEME_A_ ivalue (x))); |
3925 | s_return (mk_integer (SCHEME_A_ ivalue (x))); |
3937 | else |
3926 | else |
3938 | Error_1 ("inexact->exact: not integral:", x); |
3927 | Error_1 ("inexact->exact: not integral:", x); |
… | |
… | |
3961 | { |
3950 | { |
3962 | RVALUE result; |
3951 | RVALUE result; |
3963 | int real_result = 1; |
3952 | int real_result = 1; |
3964 | pointer y = cadr (args); |
3953 | pointer y = cadr (args); |
3965 | |
3954 | |
3966 | if (num_is_integer (x) && num_is_integer (y)) |
3955 | if (is_integer (x) && is_integer (y)) |
3967 | real_result = 0; |
3956 | real_result = 0; |
3968 | |
3957 | |
3969 | /* This 'if' is an R5RS compatibility fix. */ |
3958 | /* This 'if' is an R5RS compatibility fix. */ |
3970 | /* NOTE: Remove this 'if' fix for R6RS. */ |
3959 | /* NOTE: Remove this 'if' fix for R6RS. */ |
3971 | if (rvalue (x) == 0 && rvalue (y) < 0) |
3960 | if (rvalue (x) == 0 && rvalue (y) < 0) |
… | |
… | |
4013 | |
4002 | |
4014 | case OP_ADD: /* + */ |
4003 | case OP_ADD: /* + */ |
4015 | v = num_zero; |
4004 | v = num_zero; |
4016 | |
4005 | |
4017 | for (x = args; x != NIL; x = cdr (x)) |
4006 | for (x = args; x != NIL; x = cdr (x)) |
4018 | v = num_op ('+', v, nvalue (car (x))); |
4007 | v = num_op (NUM_ADD, v, nvalue (car (x))); |
4019 | |
4008 | |
4020 | s_return (mk_number (SCHEME_A_ v)); |
4009 | s_return (mk_number (SCHEME_A_ v)); |
4021 | |
4010 | |
4022 | case OP_MUL: /* * */ |
4011 | case OP_MUL: /* * */ |
4023 | v = num_one; |
4012 | v = num_one; |
4024 | |
4013 | |
4025 | for (x = args; x != NIL; x = cdr (x)) |
4014 | for (x = args; x != NIL; x = cdr (x)) |
4026 | v = num_op ('+', v, nvalue (car (x))); |
4015 | v = num_op (NUM_MUL, v, nvalue (car (x))); |
4027 | |
4016 | |
4028 | s_return (mk_number (SCHEME_A_ v)); |
4017 | s_return (mk_number (SCHEME_A_ v)); |
4029 | |
4018 | |
4030 | case OP_SUB: /* - */ |
4019 | case OP_SUB: /* - */ |
4031 | if (cdr (args) == NIL) |
4020 | if (cdr (args) == NIL) |
… | |
… | |
4038 | x = cdr (args); |
4027 | x = cdr (args); |
4039 | v = nvalue (car (args)); |
4028 | v = nvalue (car (args)); |
4040 | } |
4029 | } |
4041 | |
4030 | |
4042 | for (; x != NIL; x = cdr (x)) |
4031 | for (; x != NIL; x = cdr (x)) |
4043 | v = num_op ('+', v, nvalue (car (x))); |
4032 | v = num_op (NUM_SUB, v, nvalue (car (x))); |
4044 | |
4033 | |
4045 | s_return (mk_number (SCHEME_A_ v)); |
4034 | s_return (mk_number (SCHEME_A_ v)); |
4046 | |
4035 | |
4047 | case OP_DIV: /* / */ |
4036 | case OP_DIV: /* / */ |
4048 | if (cdr (args) == NIL) |
4037 | if (cdr (args) == NIL) |
… | |
… | |
4055 | x = cdr (args); |
4044 | x = cdr (args); |
4056 | v = nvalue (car (args)); |
4045 | v = nvalue (car (args)); |
4057 | } |
4046 | } |
4058 | |
4047 | |
4059 | for (; x != NIL; x = cdr (x)) |
4048 | for (; x != NIL; x = cdr (x)) |
4060 | { |
|
|
4061 | if (!is_zero_rvalue (rvalue (car (x)))) |
4049 | if (!is_zero_rvalue (rvalue (car (x)))) |
4062 | v = num_div (v, nvalue (car (x))); |
4050 | v = num_div (v, nvalue (car (x))); |
4063 | else |
4051 | else |
4064 | Error_0 ("/: division by zero"); |
4052 | Error_0 ("/: division by zero"); |
4065 | } |
|
|
4066 | |
4053 | |
4067 | s_return (mk_number (SCHEME_A_ v)); |
4054 | s_return (mk_number (SCHEME_A_ v)); |
4068 | |
4055 | |
4069 | case OP_INTDIV: /* quotient */ |
4056 | case OP_INTDIV: /* quotient */ |
4070 | if (cdr (args) == NIL) |
4057 | if (cdr (args) == NIL) |
… | |
… | |
4079 | } |
4066 | } |
4080 | |
4067 | |
4081 | for (; x != NIL; x = cdr (x)) |
4068 | for (; x != NIL; x = cdr (x)) |
4082 | { |
4069 | { |
4083 | if (ivalue (car (x)) != 0) |
4070 | if (ivalue (car (x)) != 0) |
4084 | v = num_op ('/', v, nvalue (car (x))); |
4071 | v = num_op (NUM_INTDIV, v, nvalue (car (x))); |
4085 | else |
4072 | else |
4086 | Error_0 ("quotient: division by zero"); |
4073 | Error_0 ("quotient: division by zero"); |
4087 | } |
4074 | } |
4088 | |
4075 | |
4089 | s_return (mk_number (SCHEME_A_ v)); |
4076 | s_return (mk_number (SCHEME_A_ v)); |
… | |
… | |
4417 | set_vector_elem (x, index, caddr (args)); |
4404 | set_vector_elem (x, index, caddr (args)); |
4418 | s_return (x); |
4405 | s_return (x); |
4419 | } |
4406 | } |
4420 | } |
4407 | } |
4421 | |
4408 | |
4422 | return S_T; |
4409 | if (USE_ERROR_CHECKING) abort (); |
4423 | } |
4410 | } |
4424 | |
4411 | |
4425 | INTERFACE int |
4412 | INTERFACE int |
4426 | is_list (SCHEME_P_ pointer a) |
4413 | is_list (SCHEME_P_ pointer a) |
4427 | { |
4414 | { |
… | |
… | |
4474 | return -1; |
4461 | return -1; |
4475 | } |
4462 | } |
4476 | } |
4463 | } |
4477 | } |
4464 | } |
4478 | |
4465 | |
4479 | static pointer |
4466 | static int |
4480 | opexe_r (SCHEME_P_ enum scheme_opcodes op) |
4467 | opexe_2 (SCHEME_P_ enum scheme_opcodes op) |
4481 | { |
4468 | { |
4482 | pointer x = SCHEME_V->args; |
4469 | pointer x = SCHEME_V->args; |
4483 | |
4470 | |
4484 | for (;;) |
4471 | for (;;) |
4485 | { |
4472 | { |
… | |
… | |
4505 | } |
4492 | } |
4506 | |
4493 | |
4507 | s_return (S_T); |
4494 | s_return (S_T); |
4508 | } |
4495 | } |
4509 | |
4496 | |
4510 | static pointer |
4497 | static int |
4511 | opexe_3 (SCHEME_P_ enum scheme_opcodes op) |
4498 | opexe_3 (SCHEME_P_ enum scheme_opcodes op) |
4512 | { |
4499 | { |
4513 | pointer args = SCHEME_V->args; |
4500 | pointer args = SCHEME_V->args; |
4514 | pointer a = car (args); |
4501 | pointer a = car (args); |
4515 | pointer d = cdr (args); |
4502 | pointer d = cdr (args); |
… | |
… | |
4561 | } |
4548 | } |
4562 | |
4549 | |
4563 | s_retbool (r); |
4550 | s_retbool (r); |
4564 | } |
4551 | } |
4565 | |
4552 | |
4566 | static pointer |
4553 | static int |
4567 | opexe_4 (SCHEME_P_ enum scheme_opcodes op) |
4554 | opexe_4 (SCHEME_P_ enum scheme_opcodes op) |
4568 | { |
4555 | { |
4569 | pointer args = SCHEME_V->args; |
4556 | pointer args = SCHEME_V->args; |
4570 | pointer a = car (args); |
4557 | pointer a = car (args); |
4571 | pointer x, y; |
4558 | pointer x, y; |
… | |
… | |
4657 | putstr (SCHEME_A_ "\n"); |
4644 | putstr (SCHEME_A_ "\n"); |
4658 | |
4645 | |
4659 | if (SCHEME_V->interactive_repl) |
4646 | if (SCHEME_V->interactive_repl) |
4660 | s_goto (OP_T0LVL); |
4647 | s_goto (OP_T0LVL); |
4661 | else |
4648 | else |
4662 | return NIL; |
4649 | return -1; |
4663 | } |
4650 | } |
4664 | |
4651 | |
4665 | case OP_REVERSE: /* reverse */ |
4652 | case OP_REVERSE: /* reverse */ |
4666 | s_return (reverse (SCHEME_A_ a)); |
4653 | s_return (reverse (SCHEME_A_ a)); |
4667 | |
4654 | |
… | |
… | |
4724 | |
4711 | |
4725 | case OP_QUIT: /* quit */ |
4712 | case OP_QUIT: /* quit */ |
4726 | if (is_pair (args)) |
4713 | if (is_pair (args)) |
4727 | SCHEME_V->retcode = ivalue (a); |
4714 | SCHEME_V->retcode = ivalue (a); |
4728 | |
4715 | |
4729 | return NIL; |
4716 | return -1; |
4730 | |
4717 | |
4731 | case OP_GC: /* gc */ |
4718 | case OP_GC: /* gc */ |
4732 | gc (SCHEME_A_ NIL, NIL); |
4719 | gc (SCHEME_A_ NIL, NIL); |
4733 | s_return (S_T); |
4720 | s_return (S_T); |
4734 | |
4721 | |
… | |
… | |
4781 | break; |
4768 | break; |
4782 | } |
4769 | } |
4783 | |
4770 | |
4784 | p = port_from_filename (SCHEME_A_ strvalue (a), prop); |
4771 | p = port_from_filename (SCHEME_A_ strvalue (a), prop); |
4785 | |
4772 | |
4786 | if (p == NIL) |
4773 | s_return (p == NIL ? S_F : p); |
4787 | s_return (S_F); |
|
|
4788 | |
|
|
4789 | s_return (p); |
|
|
4790 | } |
4774 | } |
4791 | |
4775 | |
4792 | # if USE_STRING_PORTS |
4776 | # if USE_STRING_PORTS |
4793 | |
4777 | |
4794 | case OP_OPEN_INSTRING: /* open-input-string */ |
4778 | case OP_OPEN_INSTRING: /* open-input-string */ |
… | |
… | |
4809 | } |
4793 | } |
4810 | |
4794 | |
4811 | p = port_from_string (SCHEME_A_ strvalue (a), |
4795 | p = port_from_string (SCHEME_A_ strvalue (a), |
4812 | strvalue (a) + strlength (a), prop); |
4796 | strvalue (a) + strlength (a), prop); |
4813 | |
4797 | |
4814 | if (p == NIL) |
4798 | s_return (p == NIL ? S_F : p); |
4815 | s_return (S_F); |
|
|
4816 | |
|
|
4817 | s_return (p); |
|
|
4818 | } |
4799 | } |
4819 | |
4800 | |
4820 | case OP_OPEN_OUTSTRING: /* open-output-string */ |
4801 | case OP_OPEN_OUTSTRING: /* open-output-string */ |
4821 | { |
4802 | { |
4822 | pointer p; |
4803 | pointer p; |
4823 | |
4804 | |
4824 | if (a == NIL) |
4805 | if (a == NIL) |
4825 | { |
|
|
4826 | p = port_from_scratch (SCHEME_A); |
4806 | p = port_from_scratch (SCHEME_A); |
4827 | |
|
|
4828 | if (p == NIL) |
|
|
4829 | s_return (S_F); |
|
|
4830 | } |
|
|
4831 | else |
4807 | else |
4832 | { |
|
|
4833 | p = port_from_string (SCHEME_A_ strvalue (a), |
4808 | p = port_from_string (SCHEME_A_ strvalue (a), |
4834 | strvalue (a) + strlength (a), port_output); |
4809 | strvalue (a) + strlength (a), port_output); |
4835 | |
4810 | |
4836 | if (p == NIL) |
4811 | s_return (p == NIL ? S_F : p); |
4837 | s_return (S_F); |
|
|
4838 | } |
|
|
4839 | |
|
|
4840 | s_return (p); |
|
|
4841 | } |
4812 | } |
4842 | |
4813 | |
4843 | case OP_GET_OUTSTRING: /* get-output-string */ |
4814 | case OP_GET_OUTSTRING: /* get-output-string */ |
4844 | { |
4815 | { |
4845 | port *p; |
4816 | port *p; |
… | |
… | |
4884 | case OP_CURR_ENV: /* current-environment */ |
4855 | case OP_CURR_ENV: /* current-environment */ |
4885 | s_return (SCHEME_V->envir); |
4856 | s_return (SCHEME_V->envir); |
4886 | |
4857 | |
4887 | } |
4858 | } |
4888 | |
4859 | |
4889 | abort (); |
4860 | if (USE_ERROR_CHECKING) abort (); |
4890 | } |
4861 | } |
4891 | |
4862 | |
4892 | static pointer |
4863 | static int |
4893 | opexe_5 (SCHEME_P_ enum scheme_opcodes op) |
4864 | opexe_5 (SCHEME_P_ enum scheme_opcodes op) |
4894 | { |
4865 | { |
4895 | pointer args = SCHEME_V->args; |
4866 | pointer args = SCHEME_V->args; |
4896 | pointer x; |
4867 | pointer x; |
4897 | |
4868 | |
… | |
… | |
5227 | s_goto (OP_P0LIST); |
5198 | s_goto (OP_P0LIST); |
5228 | } |
5199 | } |
5229 | } |
5200 | } |
5230 | } |
5201 | } |
5231 | |
5202 | |
5232 | abort (); |
5203 | if (USE_ERROR_CHECKING) abort (); |
5233 | } |
5204 | } |
5234 | |
5205 | |
5235 | static pointer |
5206 | static int |
5236 | opexe_6 (SCHEME_P_ enum scheme_opcodes op) |
5207 | opexe_6 (SCHEME_P_ enum scheme_opcodes op) |
5237 | { |
5208 | { |
5238 | pointer args = SCHEME_V->args; |
5209 | pointer args = SCHEME_V->args; |
5239 | pointer a = car (args); |
5210 | pointer a = car (args); |
5240 | pointer x, y; |
5211 | pointer x, y; |
… | |
… | |
5290 | |
5261 | |
5291 | case OP_MACROP: /* macro? */ |
5262 | case OP_MACROP: /* macro? */ |
5292 | s_retbool (is_macro (a)); |
5263 | s_retbool (is_macro (a)); |
5293 | } |
5264 | } |
5294 | |
5265 | |
5295 | abort (); |
5266 | if (USE_ERROR_CHECKING) abort (); |
5296 | } |
5267 | } |
5297 | |
5268 | |
|
|
5269 | /* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */ |
5298 | typedef pointer (*dispatch_func) (SCHEME_P_ enum scheme_opcodes); |
5270 | typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes); |
5299 | |
5271 | |
5300 | typedef int (*test_predicate) (pointer); |
5272 | typedef int (*test_predicate)(pointer); |
5301 | static int |
5273 | static int |
5302 | is_any (pointer p) |
5274 | is_any (pointer p) |
5303 | { |
5275 | { |
5304 | return 1; |
5276 | return 1; |
5305 | } |
5277 | } |
5306 | |
5278 | |
5307 | static int |
5279 | static int |
5308 | is_nonneg (pointer p) |
5280 | is_nonneg (pointer p) |
5309 | { |
5281 | { |
5310 | return ivalue (p) >= 0 && is_integer (p); |
5282 | return ivalue (p) >= 0 && is_integer (p); |
|
|
5283 | } |
|
|
5284 | |
|
|
5285 | static int |
|
|
5286 | tst_is_list (pointer p) |
|
|
5287 | { |
|
|
5288 | return p == NIL || is_pair (p); |
5311 | } |
5289 | } |
5312 | |
5290 | |
5313 | /* Correspond carefully with following defines! */ |
5291 | /* Correspond carefully with following defines! */ |
5314 | static struct |
5292 | static struct |
5315 | { |
5293 | { |
5316 | test_predicate fct; |
5294 | test_predicate fct; |
5317 | const char *kind; |
5295 | const char *kind; |
5318 | } tests[] = |
5296 | } tests[] = |
5319 | { |
5297 | { |
5320 | { 0, 0}, /* unused */ |
5298 | { is_any, 0 }, |
5321 | { is_any, 0}, |
5299 | { is_string, "string" }, |
5322 | { is_string, "string" }, |
5300 | { is_symbol, "symbol" }, |
5323 | { is_symbol, "symbol" }, |
5301 | { is_port, "port" }, |
5324 | { is_port, "port" }, |
|
|
5325 | { is_inport, "input port" }, |
5302 | { is_inport, "input port" }, |
5326 | { is_outport, "output port" }, |
5303 | { is_outport, "output port" }, |
5327 | { is_environment, "environment" }, |
5304 | { is_environment, "environment" }, |
5328 | { is_pair, "pair" }, |
5305 | { is_pair, "pair" }, |
5329 | { 0, "pair or '()" }, |
5306 | { tst_is_list, "pair or '()" }, |
5330 | { is_character, "character" }, |
5307 | { is_character, "character" }, |
5331 | { is_vector, "vector" }, |
5308 | { is_vector, "vector" }, |
5332 | { is_number, "number" }, |
5309 | { is_number, "number" }, |
5333 | { is_integer, "integer" }, |
5310 | { is_integer, "integer" }, |
5334 | { is_nonneg, "non-negative integer" } |
5311 | { is_nonneg, "non-negative integer" } |
5335 | }; |
5312 | }; |
5336 | |
5313 | |
5337 | #define TST_NONE 0 /* TST_NONE used for standard procedures, for internal ops, 0 is used */ |
5314 | #define TST_NONE 0 /* TST_NONE used for built-ins, 0 for internal ops */ |
5338 | #define TST_ANY "\001" |
5315 | #define TST_ANY "\001" |
5339 | #define TST_STRING "\002" |
5316 | #define TST_STRING "\002" |
5340 | #define TST_SYMBOL "\003" |
5317 | #define TST_SYMBOL "\003" |
5341 | #define TST_PORT "\004" |
5318 | #define TST_PORT "\004" |
5342 | #define TST_INPORT "\005" |
5319 | #define TST_INPORT "\005" |
… | |
… | |
5348 | #define TST_VECTOR "\013" |
5325 | #define TST_VECTOR "\013" |
5349 | #define TST_NUMBER "\014" |
5326 | #define TST_NUMBER "\014" |
5350 | #define TST_INTEGER "\015" |
5327 | #define TST_INTEGER "\015" |
5351 | #define TST_NATURAL "\016" |
5328 | #define TST_NATURAL "\016" |
5352 | |
5329 | |
|
|
5330 | #define INF_ARG 0xff |
|
|
5331 | #define UNNAMED_OP "" |
|
|
5332 | |
|
|
5333 | static const char opnames[] = |
|
|
5334 | #define OP_DEF(func,name,minarity,maxarity,argtest,op) name "\x00" |
|
|
5335 | #include "opdefines.h" |
|
|
5336 | #undef OP_DEF |
|
|
5337 | ; |
|
|
5338 | |
|
|
5339 | static const char * |
|
|
5340 | opname (int idx) |
|
|
5341 | { |
|
|
5342 | const char *name = opnames; |
|
|
5343 | |
|
|
5344 | /* should do this at compile time, but would require external program, right? */ |
|
|
5345 | while (idx--) |
|
|
5346 | name += strlen (name) + 1; |
|
|
5347 | |
|
|
5348 | return *name ? name : "ILLEGAL"; |
|
|
5349 | } |
|
|
5350 | |
|
|
5351 | static const char * |
|
|
5352 | procname (pointer x) |
|
|
5353 | { |
|
|
5354 | return opname (procnum (x)); |
|
|
5355 | } |
|
|
5356 | |
5353 | typedef struct |
5357 | typedef struct |
5354 | { |
5358 | { |
5355 | dispatch_func func; |
5359 | uint8_t func; |
5356 | char *name; |
5360 | /*dispatch_func func;*//*TODO: maybe optionally keep the pointer, for speed? */ |
|
|
5361 | uint8_t builtin; |
5357 | int min_arity; |
5362 | uint8_t min_arity; |
5358 | int max_arity; |
5363 | uint8_t max_arity; |
5359 | char arg_tests_encoding[3]; |
5364 | char arg_tests_encoding[3]; |
5360 | } op_code_info; |
5365 | } op_code_info; |
5361 | |
5366 | |
5362 | #define INF_ARG 0xffff |
|
|
5363 | |
|
|
5364 | static op_code_info dispatch_table[] = { |
5367 | static const op_code_info dispatch_table[] = { |
5365 | #define OP_DEF(func,name,minarity,maxarity,argtest,op) { opexe_ ## func, name, minarity, maxarity, argtest }, |
5368 | #define OP_DEF(func,name,minarity,maxarity,argtest,op) { func, sizeof (name) > 1, minarity, maxarity, argtest }, |
5366 | #include "opdefines.h" |
5369 | #include "opdefines.h" |
5367 | #undef OP_DEF |
5370 | #undef OP_DEF |
5368 | {0} |
5371 | {0} |
5369 | }; |
5372 | }; |
5370 | |
5373 | |
5371 | static const char * |
|
|
5372 | procname (pointer x) |
|
|
5373 | { |
|
|
5374 | int n = procnum (x); |
|
|
5375 | const char *name = dispatch_table[n].name; |
|
|
5376 | |
|
|
5377 | if (name == 0) |
|
|
5378 | name = "ILLEGAL!"; |
|
|
5379 | |
|
|
5380 | return name; |
|
|
5381 | } |
|
|
5382 | |
|
|
5383 | /* kernel of this interpreter */ |
5374 | /* kernel of this interpreter */ |
5384 | static void |
5375 | static void ecb_hot |
5385 | Eval_Cycle (SCHEME_P_ enum scheme_opcodes op) |
5376 | Eval_Cycle (SCHEME_P_ enum scheme_opcodes op) |
5386 | { |
5377 | { |
5387 | SCHEME_V->op = op; |
5378 | SCHEME_V->op = op; |
5388 | |
5379 | |
5389 | for (;;) |
5380 | for (;;) |
5390 | { |
5381 | { |
5391 | op_code_info *pcd = dispatch_table + SCHEME_V->op; |
5382 | const op_code_info *pcd = dispatch_table + SCHEME_V->op; |
5392 | |
5383 | |
5393 | #if USE_ERROR_CHECKING |
5384 | #if USE_ERROR_CHECKING |
5394 | if (pcd->name) /* if built-in function, check arguments */ |
5385 | if (pcd->builtin) /* if built-in function, check arguments */ |
5395 | { |
5386 | { |
5396 | int ok = 1; |
|
|
5397 | char msg[STRBUFFSIZE]; |
5387 | char msg[STRBUFFSIZE]; |
5398 | int n = list_length (SCHEME_A_ SCHEME_V->args); |
5388 | int n = list_length (SCHEME_A_ SCHEME_V->args); |
5399 | |
5389 | |
5400 | /* Check number of arguments */ |
5390 | /* Check number of arguments */ |
5401 | if (ecb_expect_false (n < pcd->min_arity)) |
5391 | if (ecb_expect_false (n < pcd->min_arity)) |
5402 | { |
5392 | { |
5403 | ok = 0; |
|
|
5404 | snprintf (msg, STRBUFFSIZE, "%s: needs%s %d argument(s)", |
5393 | snprintf (msg, STRBUFFSIZE, "%s: needs%s %d argument(s)", |
5405 | pcd->name, pcd->min_arity == pcd->max_arity ? "" : " at least", pcd->min_arity); |
5394 | opname (SCHEME_V->op), pcd->min_arity == pcd->max_arity ? "" : " at least", pcd->min_arity); |
|
|
5395 | xError_1 (SCHEME_A_ msg, 0); |
|
|
5396 | continue; |
5406 | } |
5397 | } |
5407 | else if (ecb_expect_false (n > pcd->max_arity)) |
5398 | else if (ecb_expect_false (n > pcd->max_arity && pcd->max_arity != INF_ARG)) |
5408 | { |
5399 | { |
5409 | ok = 0; |
|
|
5410 | snprintf (msg, STRBUFFSIZE, "%s: needs%s %d argument(s)", |
5400 | snprintf (msg, STRBUFFSIZE, "%s: needs%s %d argument(s)", |
5411 | pcd->name, pcd->min_arity == pcd->max_arity ? "" : " at most", pcd->max_arity); |
5401 | opname (SCHEME_V->op), pcd->min_arity == pcd->max_arity ? "" : " at most", pcd->max_arity); |
|
|
5402 | xError_1 (SCHEME_A_ msg, 0); |
|
|
5403 | continue; |
5412 | } |
5404 | } |
5413 | |
5405 | else |
5414 | if (ecb_expect_false (ok)) |
|
|
5415 | { |
5406 | { |
5416 | if (*pcd->arg_tests_encoding) |
5407 | if (*pcd->arg_tests_encoding) /* literal 0 and TST_NONE treated the same */ |
5417 | { |
5408 | { |
5418 | int i = 0; |
5409 | int i = 0; |
5419 | int j; |
5410 | int j; |
5420 | const char *t = pcd->arg_tests_encoding; |
5411 | const char *t = pcd->arg_tests_encoding; |
5421 | pointer arglist = SCHEME_V->args; |
5412 | pointer arglist = SCHEME_V->args; |
… | |
… | |
5424 | { |
5415 | { |
5425 | pointer arg = car (arglist); |
5416 | pointer arg = car (arglist); |
5426 | |
5417 | |
5427 | j = t[0]; |
5418 | j = t[0]; |
5428 | |
5419 | |
5429 | if (j == TST_LIST[0]) |
5420 | if (!tests[j - 1].fct (arg)) |
5430 | { |
|
|
5431 | if (arg != NIL && !is_pair (arg)) |
|
|
5432 | break; |
5421 | break; |
5433 | } |
|
|
5434 | else |
|
|
5435 | { |
|
|
5436 | if (!tests[j].fct (arg)) |
|
|
5437 | break; |
|
|
5438 | } |
|
|
5439 | |
5422 | |
5440 | if (t[1]) /* last test is replicated as necessary */ |
5423 | if (t[1]) /* last test is replicated as necessary */ |
5441 | t++; |
5424 | t++; |
5442 | |
5425 | |
5443 | arglist = cdr (arglist); |
5426 | arglist = cdr (arglist); |
… | |
… | |
5445 | } |
5428 | } |
5446 | while (i < n); |
5429 | while (i < n); |
5447 | |
5430 | |
5448 | if (i < n) |
5431 | if (i < n) |
5449 | { |
5432 | { |
5450 | ok = 0; |
|
|
5451 | snprintf (msg, STRBUFFSIZE, "%s: argument %d must be: %s", pcd->name, i + 1, tests[j].kind); |
5433 | snprintf (msg, STRBUFFSIZE, "%s: argument %d must be: %s", opname (SCHEME_V->op), i + 1, tests[j].kind); |
|
|
5434 | xError_1 (SCHEME_A_ msg, 0); |
|
|
5435 | continue; |
5452 | } |
5436 | } |
5453 | } |
5437 | } |
5454 | } |
5438 | } |
5455 | |
|
|
5456 | if (!ok) |
|
|
5457 | { |
|
|
5458 | if (xError_1 (SCHEME_A_ msg, 0) == NIL) |
|
|
5459 | return; |
|
|
5460 | |
|
|
5461 | pcd = dispatch_table + SCHEME_V->op; |
|
|
5462 | } |
|
|
5463 | } |
5439 | } |
5464 | #endif |
5440 | #endif |
5465 | |
5441 | |
5466 | ok_to_freely_gc (SCHEME_A); |
5442 | ok_to_freely_gc (SCHEME_A); |
5467 | |
5443 | |
|
|
5444 | static const dispatch_func dispatch_funcs[] = { |
|
|
5445 | opexe_0, |
|
|
5446 | opexe_1, |
|
|
5447 | opexe_2, |
|
|
5448 | opexe_3, |
|
|
5449 | opexe_4, |
|
|
5450 | opexe_5, |
|
|
5451 | opexe_6, |
|
|
5452 | }; |
|
|
5453 | |
5468 | if (ecb_expect_false (pcd->func (SCHEME_A_ SCHEME_V->op) == NIL)) |
5454 | if (ecb_expect_false (dispatch_funcs [pcd->func] (SCHEME_A_ SCHEME_V->op) != 0)) |
5469 | return; |
5455 | return; |
5470 | |
5456 | |
5471 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
5457 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
5472 | { |
5458 | { |
5473 | xwrstr ("No memory!\n"); |
5459 | xwrstr ("No memory!\n"); |
… | |
… | |
5572 | return OP_C0STREAM; /* cons-stream */ |
5558 | return OP_C0STREAM; /* cons-stream */ |
5573 | } |
5559 | } |
5574 | } |
5560 | } |
5575 | |
5561 | |
5576 | #if USE_MULTIPLICITY |
5562 | #if USE_MULTIPLICITY |
5577 | scheme * |
5563 | ecb_cold scheme * |
5578 | scheme_init_new () |
5564 | scheme_init_new () |
5579 | { |
5565 | { |
5580 | scheme *sc = malloc (sizeof (scheme)); |
5566 | scheme *sc = malloc (sizeof (scheme)); |
5581 | |
5567 | |
5582 | if (!scheme_init (SCHEME_A)) |
5568 | if (!scheme_init (SCHEME_A)) |
… | |
… | |
5587 | else |
5573 | else |
5588 | return sc; |
5574 | return sc; |
5589 | } |
5575 | } |
5590 | #endif |
5576 | #endif |
5591 | |
5577 | |
5592 | int |
5578 | ecb_cold int |
5593 | scheme_init (SCHEME_P) |
5579 | scheme_init (SCHEME_P) |
5594 | { |
5580 | { |
5595 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5581 | int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); |
5596 | pointer x; |
5582 | pointer x; |
5597 | |
5583 | |
… | |
… | |
5670 | |
5656 | |
5671 | for (i = 0; i < sizeof (syntax_names) / sizeof (*syntax_names); ++i) |
5657 | for (i = 0; i < sizeof (syntax_names) / sizeof (*syntax_names); ++i) |
5672 | assign_syntax (SCHEME_A_ syntax_names[i]); |
5658 | assign_syntax (SCHEME_A_ syntax_names[i]); |
5673 | } |
5659 | } |
5674 | |
5660 | |
|
|
5661 | // TODO: should iterate via strlen, to avoid n² complexity |
5675 | for (i = 0; i < n; i++) |
5662 | for (i = 0; i < n; i++) |
5676 | if (dispatch_table[i].name != 0) |
5663 | if (dispatch_table[i].builtin) |
5677 | assign_proc (SCHEME_A_ i, dispatch_table[i].name); |
5664 | assign_proc (SCHEME_A_ i, opname (i)); |
5678 | |
5665 | |
5679 | /* initialization of global pointers to special symbols */ |
5666 | /* initialization of global pointers to special symbols */ |
5680 | SCHEME_V->LAMBDA = mk_symbol (SCHEME_A_ "lambda"); |
5667 | SCHEME_V->LAMBDA = mk_symbol (SCHEME_A_ "lambda"); |
5681 | SCHEME_V->QUOTE = mk_symbol (SCHEME_A_ "quote"); |
5668 | SCHEME_V->QUOTE = mk_symbol (SCHEME_A_ "quote"); |
5682 | SCHEME_V->QQUOTE = mk_symbol (SCHEME_A_ "quasiquote"); |
5669 | SCHEME_V->QQUOTE = mk_symbol (SCHEME_A_ "quasiquote"); |
… | |
… | |
5721 | scheme_set_external_data (SCHEME_P_ void *p) |
5708 | scheme_set_external_data (SCHEME_P_ void *p) |
5722 | { |
5709 | { |
5723 | SCHEME_V->ext_data = p; |
5710 | SCHEME_V->ext_data = p; |
5724 | } |
5711 | } |
5725 | |
5712 | |
5726 | void |
5713 | ecb_cold void |
5727 | scheme_deinit (SCHEME_P) |
5714 | scheme_deinit (SCHEME_P) |
5728 | { |
5715 | { |
5729 | int i; |
5716 | int i; |
5730 | |
5717 | |
5731 | #if SHOW_ERROR_LINE |
5718 | #if SHOW_ERROR_LINE |