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.25 by root, Fri Nov 27 04:37:26 2015 UTC vs.
Revision 1.45 by root, Mon Nov 30 07:44:23 2015 UTC

16 * (MINISCM) This is a revised and modified version by Akira KIDA. 16 * (MINISCM) This is a revised and modified version by Akira KIDA.
17 * (MINISCM) current version is 0.85k4 (15 May 1994) 17 * (MINISCM) current version is 0.85k4 (15 May 1994)
18 * 18 *
19 */ 19 */
20 20
21#define EXPERIMENT 1
22
21#define PAGE_SIZE 4096 /* does not work on sparc/alpha */ 23#define PAGE_SIZE 4096 /* does not work on sparc/alpha */
22#include "malloc.c" 24#include "malloc.c"
23 25
24#define SCHEME_SOURCE 26#define SCHEME_SOURCE
25#include "scheme-private.h" 27#include "scheme-private.h"
34 36
35#include <sys/types.h> 37#include <sys/types.h>
36#include <sys/stat.h> 38#include <sys/stat.h>
37#include <fcntl.h> 39#include <fcntl.h>
38 40
41#if !USE_ERROR_CHECKING
42# define NDEBUG
43#endif
44
45#include <assert.h>
46#include <stdlib.h>
39#include <string.h> 47#include <string.h>
40#include <stdlib.h>
41 48
42#include <limits.h> 49#include <limits.h>
43#include <inttypes.h> 50#include <inttypes.h>
44#include <float.h> 51#include <float.h>
45//#include <ctype.h> 52//#include <ctype.h>
53
54#if '1' != '0' + 1 \
55 || '2' != '0' + 2 || '3' != '0' + 3 || '4' != '0' + 4 || '5' != '0' + 5 \
56 || '6' != '0' + 6 || '7' != '0' + 7 || '8' != '0' + 8 || '9' != '0' + 9 \
57 || 'b' != 'a' + 1 || 'c' != 'a' + 2 || 'd' != 'a' + 3 || 'e' != 'a' + 4 \
58 || 'f' != 'a' + 5
59# error "execution character set digits not consecutive"
60#endif
46 61
47enum { 62enum {
48 TOK_EOF, 63 TOK_EOF,
49 TOK_LPAREN, 64 TOK_LPAREN,
50 TOK_RPAREN, 65 TOK_RPAREN,
51 TOK_DOT, 66 TOK_DOT,
52 TOK_ATOM, 67 TOK_ATOM,
68 TOK_DOTATOM, /* atom name starting with '.' */
69 TOK_STRATOM, /* atom name enclosed in | */
53 TOK_QUOTE, 70 TOK_QUOTE,
54 TOK_DQUOTE, 71 TOK_DQUOTE,
55 TOK_BQUOTE, 72 TOK_BQUOTE,
56 TOK_COMMA, 73 TOK_COMMA,
57 TOK_ATMARK, 74 TOK_ATMARK,
59 TOK_SHARP_CONST, 76 TOK_SHARP_CONST,
60 TOK_VEC 77 TOK_VEC
61}; 78};
62 79
63#define BACKQUOTE '`' 80#define BACKQUOTE '`'
64#define DELIMITERS "()\";\f\t\v\n\r " 81#define WHITESPACE " \t\r\n\v\f"
82#define DELIMITERS "()\";" WHITESPACE
65 83
66#define NIL (&SCHEME_V->xNIL) //TODO: make this 0? 84#define NIL (&SCHEME_V->xNIL) //TODO: make this 0?
67#define S_T (&SCHEME_V->xT) //TODO: magic ptr value? 85#define S_T (&SCHEME_V->xT) //TODO: magic ptr value?
68#define S_F (&SCHEME_V->xF) //TODO: magic ptr value? 86#define S_F (&SCHEME_V->xF) //TODO: magic ptr value?
69#define S_SINK (&SCHEME_V->xsink) 87#define S_SINK (&SCHEME_V->xsink)
182# define FIRST_CELLSEGS 3 200# define FIRST_CELLSEGS 3
183#endif 201#endif
184 202
185enum scheme_types 203enum scheme_types
186{ 204{
205 T_INTEGER,
187 T_FREE, 206 T_REAL,
188 T_STRING, 207 T_STRING,
189 T_NUMBER,
190 T_SYMBOL, 208 T_SYMBOL,
191 T_PROC, 209 T_PROC,
192 T_PAIR, 210 T_PAIR, /* also used for free cells */
193 T_CLOSURE, 211 T_CLOSURE,
194 T_CONTINUATION, 212 T_CONTINUATION,
195 T_FOREIGN, 213 T_FOREIGN,
196 T_CHARACTER, 214 T_CHARACTER,
197 T_PORT, 215 T_PORT,
207#define T_SYNTAX 0x0010 225#define T_SYNTAX 0x0010
208#define T_IMMUTABLE 0x0020 226#define T_IMMUTABLE 0x0020
209#define T_ATOM 0x0040 /* only for gc */ 227#define T_ATOM 0x0040 /* only for gc */
210#define T_MARK 0x0080 /* only for gc */ 228#define T_MARK 0x0080 /* only for gc */
211 229
230/* num, for generic arithmetic */
231struct num
232{
233 IVALUE ivalue;
234#if USE_REAL
235 RVALUE rvalue;
236 char is_fixnum;
237#endif
238};
239
240#if USE_REAL
241# define num_is_fixnum(n) (n).is_fixnum
242# define num_set_fixnum(n,f) (n).is_fixnum = (f)
243# define num_ivalue(n) (n).ivalue
244# define num_rvalue(n) (n).rvalue
245# define num_set_ivalue(n,i) (n).rvalue = (n).ivalue = (i)
246# define num_set_rvalue(n,r) (n).rvalue = (r)
247#else
248# define num_is_fixnum(n) 1
249# define num_set_fixnum(n,f) 0
250# define num_ivalue(n) (n).ivalue
251# define num_rvalue(n) (n).ivalue
252# define num_set_ivalue(n,i) (n).ivalue = (i)
253# define num_set_rvalue(n,r) (n).ivalue = (r)
254#endif
255
212enum num_op { NUM_ADD, NUM_SUB, NUM_MUL, NUM_INTDIV }; 256enum num_op { NUM_ADD, NUM_SUB, NUM_MUL, NUM_INTDIV };
213 257
214static num num_op (enum num_op op, num a, num b); 258static num num_op (enum num_op op, num a, num b);
215static num num_intdiv (num a, num b); 259static num num_intdiv (num a, num b);
216static num num_rem (num a, num b); 260static num num_rem (num a, num b);
236} 280}
237 281
238#define strvalue(p) ((p)->object.string.svalue) 282#define strvalue(p) ((p)->object.string.svalue)
239#define strlength(p) ((p)->object.string.length) 283#define strlength(p) ((p)->object.string.length)
240 284
241INTERFACE int is_list (SCHEME_P_ pointer p);
242
243INTERFACE int 285INTERFACE int
244is_vector (pointer p) 286is_vector (pointer p)
245{ 287{
246 return type (p) == T_VECTOR; 288 return type (p) == T_VECTOR;
247} 289}
248 290
249#define vecvalue(p) ((p)->object.vector.vvalue) 291#define vecvalue(p) ((p)->object.vector.vvalue)
250#define veclength(p) ((p)->object.vector.length) 292#define veclength(p) ((p)->object.vector.length)
251INTERFACE void fill_vector (pointer vec, pointer obj); 293INTERFACE void fill_vector (pointer vec, uint32_t start, pointer obj);
252INTERFACE uint32_t vector_length (pointer vec);
253INTERFACE pointer vector_elem (pointer vec, uint32_t ielem); 294INTERFACE pointer vector_get (pointer vec, uint32_t ielem);
254INTERFACE void set_vector_elem (pointer vec, uint32_t ielem, pointer a); 295INTERFACE void vector_set (pointer vec, uint32_t ielem, pointer a);
255 296
256INTERFACE uint32_t 297INTERFACE int
257vector_length (pointer vec) 298is_integer (pointer p)
258{ 299{
259 return vec->object.vector.length; 300 return type (p) == T_INTEGER;
301}
302
303/* not the same as in scheme, where integers are (correctly :) reals */
304INTERFACE int
305is_real (pointer p)
306{
307 return type (p) == T_REAL;
260} 308}
261 309
262INTERFACE int 310INTERFACE int
263is_number (pointer p) 311is_number (pointer p)
264{ 312{
265 return type (p) == T_NUMBER; 313 return is_integer (p) || is_real (p);
266}
267
268INTERFACE int
269is_integer (pointer p)
270{
271 return is_number (p) && num_is_fixnum (p->object.number);
272}
273
274INTERFACE int
275is_real (pointer p)
276{
277 return is_number (p) && !num_is_fixnum (p->object.number);
278} 314}
279 315
280INTERFACE int 316INTERFACE int
281is_character (pointer p) 317is_character (pointer p)
282{ 318{
287string_value (pointer p) 323string_value (pointer p)
288{ 324{
289 return strvalue (p); 325 return strvalue (p);
290} 326}
291 327
292ecb_inline num
293nvalue (pointer p)
294{
295 return (p)->object.number;
296}
297
298static IVALUE
299num_get_ivalue (const num n)
300{
301 return num_is_fixnum (n) ? num_ivalue (n) : (IVALUE)num_rvalue (n);
302}
303
304static RVALUE
305num_get_rvalue (const num n)
306{
307 return num_is_fixnum (n) ? (RVALUE)num_ivalue (n) : num_rvalue (n);
308}
309
310INTERFACE IVALUE
311ivalue (pointer p)
312{
313 return num_get_ivalue (p->object.number);
314}
315
316INTERFACE RVALUE
317rvalue (pointer p)
318{
319 return num_get_rvalue (p->object.number);
320}
321
322#define ivalue_unchecked(p) ((p)->object.number.value.ivalue) 328#define ivalue_unchecked(p) (p)->object.ivalue
329#define set_ivalue(p,v) (p)->object.ivalue = (v)
330
323#if USE_REAL 331#if USE_REAL
324# define rvalue_unchecked(p) ((p)->object.number.value.rvalue) 332#define rvalue_unchecked(p) (p)->object.rvalue
325# define set_num_integer(p) (p)->object.number.is_fixnum=1; 333#define set_rvalue(p,v) (p)->object.rvalue = (v)
326# define set_num_real(p) (p)->object.number.is_fixnum=0;
327#else 334#else
328# define rvalue_unchecked(p) ((p)->object.number.value.ivalue) 335#define rvalue_unchecked(p) (p)->object.ivalue
329# define set_num_integer(p) 0 336#define set_rvalue(p,v) (p)->object.ivalue = (v)
330# define set_num_real(p) 0
331#endif 337#endif
332 338
333INTERFACE long 339INTERFACE long
334charvalue (pointer p) 340charvalue (pointer p)
335{ 341{
403} 409}
404 410
405INTERFACE char * 411INTERFACE char *
406symname (pointer p) 412symname (pointer p)
407{ 413{
408 return strvalue (car (p)); 414 return strvalue (p);
409} 415}
410 416
411#if USE_PLIST 417#if USE_PLIST
418#define symprop(p) cdr(p)
412SCHEME_EXPORT int 419SCHEME_EXPORT int
413hasprop (pointer p) 420hasprop (pointer p)
414{ 421{
415 return typeflag (p) & T_SYMBOL; 422 return typeflag (p) & T_SYMBOL;
416} 423}
417
418# define symprop(p) cdr(p)
419#endif 424#endif
420 425
421INTERFACE int 426INTERFACE int
422is_syntax (pointer p) 427is_syntax (pointer p)
423{ 428{
437} 442}
438 443
439INTERFACE char * 444INTERFACE char *
440syntaxname (pointer p) 445syntaxname (pointer p)
441{ 446{
442 return strvalue (car (p)); 447 return strvalue (p);
443} 448}
444 449
445#define procnum(p) ivalue (p) 450#define procnum(p) ivalue_unchecked (p)
446static const char *procname (pointer x); 451static const char *procname (pointer x);
447 452
448INTERFACE int 453INTERFACE int
449is_closure (pointer p) 454is_closure (pointer p)
450{ 455{
511setimmutable (pointer p) 516setimmutable (pointer p)
512{ 517{
513#if USE_ERROR_CHECKING 518#if USE_ERROR_CHECKING
514 set_typeflag (p, typeflag (p) | T_IMMUTABLE); 519 set_typeflag (p, typeflag (p) | T_IMMUTABLE);
515#endif 520#endif
521}
522
523/* Result is:
524 proper list: length
525 circular list: -1
526 not even a pair: -2
527 dotted list: -2 minus length before dot
528*/
529INTERFACE int
530list_length (SCHEME_P_ pointer a)
531{
532 int i = 0;
533 pointer slow, fast;
534
535 slow = fast = a;
536
537 while (1)
538 {
539 if (fast == NIL)
540 return i;
541
542 if (!is_pair (fast))
543 return -2 - i;
544
545 fast = cdr (fast);
546 ++i;
547
548 if (fast == NIL)
549 return i;
550
551 if (!is_pair (fast))
552 return -2 - i;
553
554 ++i;
555 fast = cdr (fast);
556
557 /* Safe because we would have already returned if `fast'
558 encountered a non-pair. */
559 slow = cdr (slow);
560
561 if (fast == slow)
562 {
563 /* the fast pointer has looped back around and caught up
564 with the slow pointer, hence the structure is circular,
565 not of finite length, and therefore not a list */
566 return -1;
567 }
568 }
569}
570
571INTERFACE int
572is_list (SCHEME_P_ pointer a)
573{
574 return list_length (SCHEME_A_ a) >= 0;
516} 575}
517 576
518#if USE_CHAR_CLASSIFIERS 577#if USE_CHAR_CLASSIFIERS
519ecb_inline int 578ecb_inline int
520Cisalpha (int c) 579Cisalpha (int c)
609#endif 668#endif
610 669
611static int file_push (SCHEME_P_ const char *fname); 670static int file_push (SCHEME_P_ const char *fname);
612static void file_pop (SCHEME_P); 671static void file_pop (SCHEME_P);
613static int file_interactive (SCHEME_P); 672static int file_interactive (SCHEME_P);
614ecb_inline int is_one_of (char *s, int c); 673ecb_inline int is_one_of (const char *s, int c);
615static int alloc_cellseg (SCHEME_P_ int n); 674static int alloc_cellseg (SCHEME_P_ int n);
616ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); 675ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b);
617static void finalize_cell (SCHEME_P_ pointer a); 676static void finalize_cell (SCHEME_P_ pointer a);
618static int count_consecutive_cells (pointer x, int needed); 677static int count_consecutive_cells (pointer x, int needed);
619static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); 678static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all);
636static void mark (pointer a); 695static void mark (pointer a);
637static void gc (SCHEME_P_ pointer a, pointer b); 696static void gc (SCHEME_P_ pointer a, pointer b);
638static int basic_inchar (port *pt); 697static int basic_inchar (port *pt);
639static int inchar (SCHEME_P); 698static int inchar (SCHEME_P);
640static void backchar (SCHEME_P_ int c); 699static void backchar (SCHEME_P_ int c);
641static char *readstr_upto (SCHEME_P_ char *delim); 700static char *readstr_upto (SCHEME_P_ int skip, const char *delim);
642static pointer readstrexp (SCHEME_P); 701static pointer readstrexp (SCHEME_P_ char delim);
643ecb_inline int skipspace (SCHEME_P); 702ecb_inline int skipspace (SCHEME_P);
644static int token (SCHEME_P); 703static int token (SCHEME_P);
645static void printslashstring (SCHEME_P_ char *s, int len); 704static void printslashstring (SCHEME_P_ char *s, int len);
646static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); 705static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen);
647static void printatom (SCHEME_P_ pointer l, int f); 706static void printatom (SCHEME_P_ pointer l, int f);
664static void Eval_Cycle (SCHEME_P_ enum scheme_opcodes op); 723static void Eval_Cycle (SCHEME_P_ enum scheme_opcodes op);
665static void assign_syntax (SCHEME_P_ const char *name); 724static void assign_syntax (SCHEME_P_ const char *name);
666static int syntaxnum (pointer p); 725static int syntaxnum (pointer p);
667static void assign_proc (SCHEME_P_ enum scheme_opcodes, const char *name); 726static void assign_proc (SCHEME_P_ enum scheme_opcodes, const char *name);
668 727
728static IVALUE
729ivalue (pointer x)
730{
731 return is_integer (x) ? ivalue_unchecked (x) : rvalue_unchecked (x);
732}
733
734static RVALUE
735rvalue (pointer x)
736{
737 return is_integer (x) ? ivalue_unchecked (x) : rvalue_unchecked (x);
738}
739
740INTERFACE num
741nvalue (pointer x)
742{
743 num n;
744
745 num_set_fixnum (n, is_integer (x));
746
747 if (num_is_fixnum (n))
748 num_set_ivalue (n, ivalue_unchecked (x));
749 else
750 num_set_rvalue (n, rvalue_unchecked (x));
751
752 return n;
753}
754
669static num 755static num
670num_op (enum num_op op, num a, num b) 756num_op (enum num_op op, num a, num b)
671{ 757{
672 num ret; 758 num ret;
673 759
674 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b)); 760 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b));
675 761
676 if (num_is_fixnum (ret)) 762 if (num_is_fixnum (ret))
677 { 763 {
678 IVALUE av = num_get_ivalue (a);
679 IVALUE bv = num_get_ivalue (b);
680
681 switch (op) 764 switch (op)
682 { 765 {
683 case NUM_ADD: av += bv; break; 766 case NUM_ADD: a.ivalue += b.ivalue; break;
684 case NUM_SUB: av -= bv; break; 767 case NUM_SUB: a.ivalue -= b.ivalue; break;
685 case NUM_MUL: av *= bv; break; 768 case NUM_MUL: a.ivalue *= b.ivalue; break;
686 case NUM_INTDIV: av /= bv; break; 769 case NUM_INTDIV: a.ivalue /= b.ivalue; break;
687 } 770 }
688 771
689 num_set_ivalue (ret, av); 772 num_set_ivalue (ret, a.ivalue);
690 } 773 }
774#if USE_REAL
691 else 775 else
692 { 776 {
693 RVALUE av = num_get_rvalue (a);
694 RVALUE bv = num_get_rvalue (b);
695
696 switch (op) 777 switch (op)
697 { 778 {
698 case NUM_ADD: av += bv; break; 779 case NUM_ADD: a.rvalue += b.rvalue; break;
699 case NUM_SUB: av -= bv; break; 780 case NUM_SUB: a.rvalue -= b.rvalue; break;
700 case NUM_MUL: av *= bv; break; 781 case NUM_MUL: a.rvalue *= b.rvalue; break;
701 case NUM_INTDIV: av /= bv; break; 782 case NUM_INTDIV: a.rvalue /= b.rvalue; break;
702 } 783 }
703 784
704 num_set_rvalue (ret, av); 785 num_set_rvalue (ret, a.rvalue);
705 } 786 }
787#endif
706 788
707 return ret; 789 return ret;
708} 790}
709 791
710static num 792static num
711num_div (num a, num b) 793num_div (num a, num b)
712{ 794{
713 num ret; 795 num ret;
714 796
715 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b) && num_get_ivalue (a) % num_get_ivalue (b) == 0); 797 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b) && num_ivalue (a) % num_ivalue (b) == 0);
716 798
717 if (num_is_fixnum (ret)) 799 if (num_is_fixnum (ret))
718 num_set_ivalue (ret, num_get_ivalue (a) / num_get_ivalue (b)); 800 num_set_ivalue (ret, num_ivalue (a) / num_ivalue (b));
719 else 801 else
720 num_set_rvalue (ret, num_get_rvalue (a) / num_get_rvalue (b)); 802 num_set_rvalue (ret, num_rvalue (a) / num_rvalue (b));
721 803
722 return ret; 804 return ret;
723} 805}
724 806
725static num 807static num
727{ 809{
728 num ret; 810 num ret;
729 long e1, e2, res; 811 long e1, e2, res;
730 812
731 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b)); 813 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b));
732 e1 = num_get_ivalue (a); 814 e1 = num_ivalue (a);
733 e2 = num_get_ivalue (b); 815 e2 = num_ivalue (b);
734 res = e1 % e2; 816 res = e1 % e2;
735 817
736 /* remainder should have same sign as second operand */ 818 /* remainder should have same sign as second operand */
737 if (res > 0) 819 if (res > 0)
738 { 820 {
754{ 836{
755 num ret; 837 num ret;
756 long e1, e2, res; 838 long e1, e2, res;
757 839
758 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b)); 840 num_set_fixnum (ret, num_is_fixnum (a) && num_is_fixnum (b));
759 e1 = num_get_ivalue (a); 841 e1 = num_ivalue (a);
760 e2 = num_get_ivalue (b); 842 e2 = num_ivalue (b);
761 res = e1 % e2; 843 res = e1 % e2;
762 844
763 /* modulo should have same sign as second operand */ 845 /* modulo should have same sign as second operand */
764 if (res * e2 < 0) 846 if (res * e2 < 0)
765 res += e2; 847 res += e2;
775 int is_fixnum = num_is_fixnum (a) && num_is_fixnum (b); 857 int is_fixnum = num_is_fixnum (a) && num_is_fixnum (b);
776 int ret; 858 int ret;
777 859
778 if (is_fixnum) 860 if (is_fixnum)
779 { 861 {
780 IVALUE av = num_get_ivalue (a); 862 IVALUE av = num_ivalue (a);
781 IVALUE bv = num_get_ivalue (b); 863 IVALUE bv = num_ivalue (b);
782 864
783 ret = av == bv ? 0 : av < bv ? -1 : +1; 865 ret = av == bv ? 0 : av < bv ? -1 : +1;
784 } 866 }
785 else 867 else
786 { 868 {
787 RVALUE av = num_get_rvalue (a); 869 RVALUE av = num_rvalue (a);
788 RVALUE bv = num_get_rvalue (b); 870 RVALUE bv = num_rvalue (b);
789 871
790 ret = av == bv ? 0 : av < bv ? -1 : +1; 872 ret = av == bv ? 0 : av < bv ? -1 : +1;
791 } 873 }
792 874
793 return ret; 875 return ret;
856 return k; 938 return k;
857 939
858 i = ++SCHEME_V->last_cell_seg; 940 i = ++SCHEME_V->last_cell_seg;
859 SCHEME_V->alloc_seg[i] = cp; 941 SCHEME_V->alloc_seg[i] = cp;
860 942
861 /* insert new segment in address order */
862 newp = (pointer)cp; 943 newp = (pointer)cp;
863 SCHEME_V->cell_seg[i] = newp; 944 SCHEME_V->cell_seg[i] = newp;
864 SCHEME_V->cell_segsize[i] = segsize; 945 SCHEME_V->cell_segsize[i] = segsize;
865
866 //TODO: insert, not swap
867 while (i > 0 && SCHEME_V->cell_seg[i - 1] > SCHEME_V->cell_seg[i])
868 {
869 p = SCHEME_V->cell_seg[i];
870 SCHEME_V->cell_seg[i] = SCHEME_V->cell_seg[i - 1];
871 SCHEME_V->cell_seg[i - 1] = p;
872
873 k = SCHEME_V->cell_segsize[i];
874 SCHEME_V->cell_segsize[i] = SCHEME_V->cell_segsize[i - 1];
875 SCHEME_V->cell_segsize[i - 1] = k;
876
877 --i;
878 }
879
880 SCHEME_V->fcells += segsize; 946 SCHEME_V->fcells += segsize;
881 last = newp + segsize - 1; 947 last = newp + segsize - 1;
882 948
883 for (p = newp; p <= last; p++) 949 for (p = newp; p <= last; p++)
884 { 950 {
885 set_typeflag (p, T_FREE); 951 set_typeflag (p, T_PAIR);
886 set_car (p, NIL); 952 set_car (p, NIL);
887 set_cdr (p, p + 1); 953 set_cdr (p, p + 1);
888 } 954 }
889 955
890 /* insert new cells in address order on free list */
891 if (SCHEME_V->free_cell == NIL || p < SCHEME_V->free_cell)
892 {
893 set_cdr (last, SCHEME_V->free_cell); 956 set_cdr (last, SCHEME_V->free_cell);
894 SCHEME_V->free_cell = newp; 957 SCHEME_V->free_cell = newp;
895 }
896 else
897 {
898 p = SCHEME_V->free_cell;
899
900 while (cdr (p) != NIL && newp > cdr (p))
901 p = cdr (p);
902
903 set_cdr (last, cdr (p));
904 set_cdr (p, newp);
905 }
906 } 958 }
907 959
908 return n; 960 return n;
909} 961}
910 962
917 if (SCHEME_V->no_memory && USE_ERROR_CHECKING) 969 if (SCHEME_V->no_memory && USE_ERROR_CHECKING)
918 return S_SINK; 970 return S_SINK;
919 971
920 if (SCHEME_V->free_cell == NIL) 972 if (SCHEME_V->free_cell == NIL)
921 { 973 {
922 const int min_to_be_recovered = SCHEME_V->last_cell_seg < 128 ? 128 * 8 : SCHEME_V->last_cell_seg * 8; 974 const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 2;
923 975
924 gc (SCHEME_A_ a, b); 976 gc (SCHEME_A_ a, b);
925 977
926 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) 978 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL)
927 { 979 {
978} 1030}
979 1031
980static pointer 1032static pointer
981get_vector_object (SCHEME_P_ uint32_t len, pointer init) 1033get_vector_object (SCHEME_P_ uint32_t len, pointer init)
982{ 1034{
983 pointer v = get_cell_x (SCHEME_A_ 0, 0); 1035 pointer v = get_cell_x (SCHEME_A_ NIL, NIL);
984 pointer *e = malloc (len * sizeof (pointer)); 1036 pointer *e = malloc (len * sizeof (pointer));
985 1037
986 if (!e && USE_ERROR_CHECKING) 1038 if (!e && USE_ERROR_CHECKING)
987 return S_SINK; 1039 return S_SINK;
988 1040
989 /* Record it as a vector so that gc understands it. */ 1041 /* Record it as a vector so that gc understands it. */
990 set_typeflag (v, T_VECTOR | T_ATOM); 1042 set_typeflag (v, T_VECTOR | T_ATOM);
991 1043
992 v->object.vector.vvalue = e; 1044 v->object.vector.vvalue = e;
993 v->object.vector.length = len; 1045 v->object.vector.length = len;
994 fill_vector (v, init); 1046 fill_vector (v, 0, init);
995 push_recent_alloc (SCHEME_A_ v, NIL); 1047 push_recent_alloc (SCHEME_A_ v, NIL);
996 1048
997 return v; 1049 return v;
998} 1050}
999 1051
1042 set_cdr (x, b); 1094 set_cdr (x, b);
1043 1095
1044 return x; 1096 return x;
1045} 1097}
1046 1098
1099static pointer
1100generate_symbol (SCHEME_P_ const char *name)
1101{
1102 pointer x = mk_string (SCHEME_A_ name);
1103 setimmutable (x);
1104 set_typeflag (x, T_SYMBOL | T_ATOM);
1105 return x;
1106}
1107
1047/* ========== oblist implementation ========== */ 1108/* ========== oblist implementation ========== */
1048 1109
1049#ifndef USE_OBJECT_LIST 1110#ifndef USE_OBJECT_LIST
1050 1111
1112static int
1051static int hash_fn (const char *key, int table_size); 1113hash_fn (const char *key, int table_size)
1114{
1115 const unsigned char *p = key;
1116 uint32_t hash = 2166136261;
1117
1118 while (*p)
1119 hash = (hash ^ *p++) * 16777619;
1120
1121 return hash % table_size;
1122}
1052 1123
1053static pointer 1124static pointer
1054oblist_initial_value (SCHEME_P) 1125oblist_initial_value (SCHEME_P)
1055{ 1126{
1056 return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ 1127 return mk_vector (SCHEME_A_ 461); /* probably should be bigger */
1058 1129
1059/* returns the new symbol */ 1130/* returns the new symbol */
1060static pointer 1131static pointer
1061oblist_add_by_name (SCHEME_P_ const char *name) 1132oblist_add_by_name (SCHEME_P_ const char *name)
1062{ 1133{
1063 int location; 1134 pointer x = generate_symbol (SCHEME_A_ name);
1064
1065 pointer x = immutable_cons (mk_string (SCHEME_A_ name), NIL);
1066 set_typeflag (x, T_SYMBOL);
1067 setimmutable (car (x));
1068
1069 location = hash_fn (name, veclength (SCHEME_V->oblist)); 1135 int location = hash_fn (name, veclength (SCHEME_V->oblist));
1070 set_vector_elem (SCHEME_V->oblist, location, immutable_cons (x, vector_elem (SCHEME_V->oblist, location))); 1136 vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location)));
1071 return x; 1137 return x;
1072} 1138}
1073 1139
1074ecb_inline pointer 1140ecb_inline pointer
1075oblist_find_by_name (SCHEME_P_ const char *name) 1141oblist_find_by_name (SCHEME_P_ const char *name)
1078 pointer x; 1144 pointer x;
1079 char *s; 1145 char *s;
1080 1146
1081 location = hash_fn (name, veclength (SCHEME_V->oblist)); 1147 location = hash_fn (name, veclength (SCHEME_V->oblist));
1082 1148
1083 for (x = vector_elem (SCHEME_V->oblist, location); x != NIL; x = cdr (x)) 1149 for (x = vector_get (SCHEME_V->oblist, location); x != NIL; x = cdr (x))
1084 { 1150 {
1085 s = symname (car (x)); 1151 s = symname (car (x));
1086 1152
1087 /* case-insensitive, per R5RS section 2 */ 1153 /* case-insensitive, per R5RS section 2 */
1088 if (stricmp (name, s) == 0) 1154 if (stricmp (name, s) == 0)
1098 int i; 1164 int i;
1099 pointer x; 1165 pointer x;
1100 pointer ob_list = NIL; 1166 pointer ob_list = NIL;
1101 1167
1102 for (i = 0; i < veclength (SCHEME_V->oblist); i++) 1168 for (i = 0; i < veclength (SCHEME_V->oblist); i++)
1103 for (x = vector_elem (SCHEME_V->oblist, i); x != NIL; x = cdr (x)) 1169 for (x = vector_get (SCHEME_V->oblist, i); x != NIL; x = cdr (x))
1104 ob_list = cons (x, ob_list); 1170 ob_list = cons (x, ob_list);
1105 1171
1106 return ob_list; 1172 return ob_list;
1107} 1173}
1108 1174
1134 1200
1135/* returns the new symbol */ 1201/* returns the new symbol */
1136static pointer 1202static pointer
1137oblist_add_by_name (SCHEME_P_ const char *name) 1203oblist_add_by_name (SCHEME_P_ const char *name)
1138{ 1204{
1139 pointer x; 1205 pointer x = mk_string (SCHEME_A_ name);
1140
1141 x = immutable_cons (mk_string (SCHEME_A_ name), NIL);
1142 set_typeflag (x, T_SYMBOL); 1206 set_typeflag (x, T_SYMBOL);
1143 setimmutable (car (x)); 1207 setimmutable (x);
1144 SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); 1208 SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist);
1145 return x; 1209 return x;
1146} 1210}
1147 1211
1148static pointer 1212static pointer
1181mk_character (SCHEME_P_ int c) 1245mk_character (SCHEME_P_ int c)
1182{ 1246{
1183 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1247 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1184 1248
1185 set_typeflag (x, (T_CHARACTER | T_ATOM)); 1249 set_typeflag (x, (T_CHARACTER | T_ATOM));
1186 ivalue_unchecked (x) = c & 0xff; 1250 set_ivalue (x, c & 0xff);
1187 set_num_integer (x); 1251
1188 return x; 1252 return x;
1189} 1253}
1190 1254
1191/* get number atom (integer) */ 1255/* get number atom (integer) */
1192INTERFACE pointer 1256INTERFACE pointer
1193mk_integer (SCHEME_P_ long num) 1257mk_integer (SCHEME_P_ long n)
1194{ 1258{
1195 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1259 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1196 1260
1197 set_typeflag (x, (T_NUMBER | T_ATOM)); 1261 set_typeflag (x, (T_INTEGER | T_ATOM));
1198 ivalue_unchecked (x) = num; 1262 set_ivalue (x, n);
1199 set_num_integer (x); 1263
1200 return x; 1264 return x;
1201} 1265}
1202 1266
1203INTERFACE pointer 1267INTERFACE pointer
1204mk_real (SCHEME_P_ RVALUE n) 1268mk_real (SCHEME_P_ RVALUE n)
1205{ 1269{
1270#if USE_REAL
1206 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1271 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1207 1272
1208 set_typeflag (x, (T_NUMBER | T_ATOM)); 1273 set_typeflag (x, (T_REAL | T_ATOM));
1209 rvalue_unchecked (x) = n; 1274 set_rvalue (x, n);
1210 set_num_real (x); 1275
1211 return x; 1276 return x;
1277#else
1278 return mk_integer (SCHEME_A_ n);
1279#endif
1212} 1280}
1213 1281
1214static pointer 1282static pointer
1215mk_number (SCHEME_P_ const num n) 1283mk_number (SCHEME_P_ const num n)
1216{ 1284{
1285#if USE_REAL
1217 if (num_is_fixnum (n)) 1286 return num_is_fixnum (n)
1287 ? mk_integer (SCHEME_A_ num_ivalue (n))
1288 : mk_real (SCHEME_A_ num_rvalue (n));
1289#else
1218 return mk_integer (SCHEME_A_ num_get_ivalue (n)); 1290 return mk_integer (SCHEME_A_ num_ivalue (n));
1219 else 1291#endif
1220 return mk_real (SCHEME_A_ num_get_rvalue (n));
1221} 1292}
1222 1293
1223/* allocate name to string area */ 1294/* allocate name to string area */
1224static char * 1295static char *
1225store_string (SCHEME_P_ uint32_t len_str, const char *str, char fill) 1296store_string (SCHEME_P_ uint32_t len_str, const char *str, char fill)
1231 SCHEME_V->no_memory = 1; 1302 SCHEME_V->no_memory = 1;
1232 return SCHEME_V->strbuff; 1303 return SCHEME_V->strbuff;
1233 } 1304 }
1234 1305
1235 if (str) 1306 if (str)
1236 { 1307 memcpy (q, str , len_str); /* caller must ensure that *str has length len_str */
1237 int l = strlen (str);
1238
1239 if (l > len_str)
1240 l = len_str;
1241
1242 memcpy (q, str, l);
1243 q[l] = 0;
1244 }
1245 else 1308 else
1246 {
1247 memset (q, fill, len_str); 1309 memset (q, fill, len_str);
1310
1248 q[len_str] = 0; 1311 q[len_str] = 0;
1249 }
1250 1312
1251 return q; 1313 return q;
1252} 1314}
1253 1315
1254INTERFACE pointer 1316INTERFACE pointer
1268 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1330 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1269 1331
1270 set_typeflag (x, T_STRING | T_ATOM); 1332 set_typeflag (x, T_STRING | T_ATOM);
1271 strvalue (x) = store_string (SCHEME_A_ len, str, 0); 1333 strvalue (x) = store_string (SCHEME_A_ len, str, 0);
1272 strlength (x) = len; 1334 strlength (x) = len;
1335
1273 return x; 1336 return x;
1274} 1337}
1275 1338
1276INTERFACE pointer 1339INTERFACE pointer
1277mk_string (SCHEME_P_ const char *str) 1340mk_string (SCHEME_P_ const char *str)
1284{ 1347{
1285 return get_vector_object (SCHEME_A_ len, NIL); 1348 return get_vector_object (SCHEME_A_ len, NIL);
1286} 1349}
1287 1350
1288INTERFACE void 1351INTERFACE void
1289fill_vector (pointer vec, pointer obj) 1352fill_vector (pointer vec, uint32_t start, pointer obj)
1290{ 1353{
1291 int i; 1354 int i;
1292 1355
1293 for (i = 0; i < vec->object.vector.length; i++) 1356 for (i = start; i < veclength (vec); i++)
1294 vecvalue (vec)[i] = obj; 1357 vecvalue (vec)[i] = obj;
1295} 1358}
1296 1359
1360INTERFACE void
1361vector_resize (pointer vec, uint32_t newsize, pointer fill)
1362{
1363 uint32_t oldsize = veclength (vec);
1364 vecvalue (vec) = realloc (vecvalue (vec), newsize * sizeof (pointer));
1365 veclength (vec) = newsize;
1366 fill_vector (vec, oldsize, fill);
1367}
1368
1297INTERFACE pointer 1369INTERFACE pointer
1298vector_elem (pointer vec, uint32_t ielem) 1370vector_get (pointer vec, uint32_t ielem)
1299{ 1371{
1300 return vecvalue(vec)[ielem]; 1372 return vecvalue(vec)[ielem];
1301} 1373}
1302 1374
1303INTERFACE void 1375INTERFACE void
1304set_vector_elem (pointer vec, uint32_t ielem, pointer a) 1376vector_set (pointer vec, uint32_t ielem, pointer a)
1305{ 1377{
1306 vecvalue(vec)[ielem] = a; 1378 vecvalue(vec)[ielem] = a;
1307} 1379}
1308 1380
1309/* get new symbol */ 1381/* get new symbol */
1321 1393
1322INTERFACE pointer 1394INTERFACE pointer
1323gensym (SCHEME_P) 1395gensym (SCHEME_P)
1324{ 1396{
1325 pointer x; 1397 pointer x;
1326
1327 for (; SCHEME_V->gensym_cnt < LONG_MAX; SCHEME_V->gensym_cnt++)
1328 {
1329 char name[40] = "gensym-"; 1398 char name[40] = "gensym-";
1330 xnum (name + 7, SCHEME_V->gensym_cnt); 1399 xnum (name + 7, ++SCHEME_V->gensym_cnt);
1331 1400
1332 /* first check oblist */ 1401 return generate_symbol (SCHEME_A_ name);
1333 x = oblist_find_by_name (SCHEME_A_ name); 1402}
1334 1403
1335 if (x == NIL) 1404static int
1336 { 1405is_gensym (SCHEME_P_ pointer x)
1337 x = oblist_add_by_name (SCHEME_A_ name); 1406{
1338 return x; 1407 return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x;
1339 }
1340 }
1341
1342 return NIL;
1343} 1408}
1344 1409
1345/* make symbol or number atom from string */ 1410/* make symbol or number atom from string */
1346static pointer 1411static pointer
1347mk_atom (SCHEME_P_ char *q) 1412mk_atom (SCHEME_P_ char *q)
1401 } 1466 }
1402 else if ((c == 'e') || (c == 'E')) 1467 else if ((c == 'e') || (c == 'E'))
1403 { 1468 {
1404 if (!has_fp_exp) 1469 if (!has_fp_exp)
1405 { 1470 {
1406 has_dec_point = 1; /* decimal point illegal 1471 has_dec_point = 1; /* decimal point illegal from now on */
1407 from now on */
1408 p++; 1472 p++;
1409 1473
1410 if ((*p == '-') || (*p == '+') || isdigit (*p)) 1474 if ((*p == '-') || (*p == '+') || isdigit (*p))
1411 continue; 1475 continue;
1412 } 1476 }
1500 1564
1501 if (ecb_expect_false (is_vector (p))) 1565 if (ecb_expect_false (is_vector (p)))
1502 { 1566 {
1503 int i; 1567 int i;
1504 1568
1505 for (i = 0; i < p->object.vector.length; i++) 1569 for (i = 0; i < veclength (p); i++)
1506 mark (vecvalue (p)[i]); 1570 mark (vecvalue (p)[i]);
1507 } 1571 }
1508 1572
1509 if (is_atom (p)) 1573 if (is_atom (p))
1510 goto E6; 1574 goto E6;
1592 /* garbage collect */ 1656 /* garbage collect */
1593 clrmark (NIL); 1657 clrmark (NIL);
1594 SCHEME_V->fcells = 0; 1658 SCHEME_V->fcells = 0;
1595 SCHEME_V->free_cell = NIL; 1659 SCHEME_V->free_cell = NIL;
1596 1660
1597 /* free-list is kept sorted by address so as to maintain consecutive 1661 if (SCHEME_V->gc_verbose)
1598 ranges, if possible, for use with vectors. Here we scan the cells 1662 xwrstr ("freeing...");
1599 (which are also kept sorted by address) downwards to build the 1663
1600 free-list in sorted order. 1664 uint32_t total = 0;
1601 */ 1665
1666 /* Here we scan the cells to build the free-list. */
1602 for (i = SCHEME_V->last_cell_seg; i >= 0; i--) 1667 for (i = SCHEME_V->last_cell_seg; i >= 0; i--)
1603 { 1668 {
1604 p = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i]; 1669 pointer end = SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize [i];
1670 total += SCHEME_V->cell_segsize [i];
1605 1671
1606 while (--p >= SCHEME_V->cell_seg[i]) 1672 for (p = SCHEME_V->cell_seg[i]; p < end; ++p)
1607 { 1673 {
1608 if (is_mark (p)) 1674 if (is_mark (p))
1609 clrmark (p); 1675 clrmark (p);
1610 else 1676 else
1611 { 1677 {
1612 /* reclaim cell */ 1678 /* reclaim cell */
1613 if (typeflag (p) != T_FREE) 1679 if (typeflag (p) != T_PAIR)
1614 { 1680 {
1615 finalize_cell (SCHEME_A_ p); 1681 finalize_cell (SCHEME_A_ p);
1616 set_typeflag (p, T_FREE); 1682 set_typeflag (p, T_PAIR);
1617 set_car (p, NIL); 1683 set_car (p, NIL);
1618 } 1684 }
1619 1685
1620 ++SCHEME_V->fcells; 1686 ++SCHEME_V->fcells;
1621 set_cdr (p, SCHEME_V->free_cell); 1687 set_cdr (p, SCHEME_V->free_cell);
1623 } 1689 }
1624 } 1690 }
1625 } 1691 }
1626 1692
1627 if (SCHEME_V->gc_verbose) 1693 if (SCHEME_V->gc_verbose)
1694 {
1628 xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" cells were recovered.\n"); 1695 xwrstr ("done: "); xwrnum (SCHEME_V->fcells); xwrstr (" out of "); xwrnum (total); xwrstr (" cells were recovered.\n");
1696 }
1629} 1697}
1630 1698
1631static void 1699static void
1632finalize_cell (SCHEME_P_ pointer a) 1700finalize_cell (SCHEME_P_ pointer a)
1633{ 1701{
1634 /* TODO, fast bitmap check? */ 1702 /* TODO, fast bitmap check? */
1635 if (is_string (a)) 1703 if (is_string (a) || is_symbol (a))
1636 free (strvalue (a)); 1704 free (strvalue (a));
1637 else if (is_vector (a)) 1705 else if (is_vector (a))
1638 free (vecvalue (a)); 1706 free (vecvalue (a));
1639#if USE_PORTS 1707#if USE_PORTS
1640 else if (is_port (a)) 1708 else if (is_port (a))
2062#endif 2130#endif
2063} 2131}
2064 2132
2065/* read characters up to delimiter, but cater to character constants */ 2133/* read characters up to delimiter, but cater to character constants */
2066static char * 2134static char *
2067readstr_upto (SCHEME_P_ char *delim) 2135readstr_upto (SCHEME_P_ int skip, const char *delim)
2068{ 2136{
2069 char *p = SCHEME_V->strbuff; 2137 char *p = SCHEME_V->strbuff + skip;
2070 2138
2071 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); 2139 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A))));
2072 2140
2073 if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\') 2141 if (p == SCHEME_V->strbuff + 2 && p[-2] == '\\')
2074 *p = 0; 2142 *p = 0;
2081 return SCHEME_V->strbuff; 2149 return SCHEME_V->strbuff;
2082} 2150}
2083 2151
2084/* read string expression "xxx...xxx" */ 2152/* read string expression "xxx...xxx" */
2085static pointer 2153static pointer
2086readstrexp (SCHEME_P) 2154readstrexp (SCHEME_P_ char delim)
2087{ 2155{
2088 char *p = SCHEME_V->strbuff; 2156 char *p = SCHEME_V->strbuff;
2089 int c; 2157 int c;
2090 int c1 = 0; 2158 int c1 = 0;
2091 enum
2092 { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok; 2159 enum { st_ok, st_bsl, st_x1, st_x2, st_oct1, st_oct2 } state = st_ok;
2093 2160
2094 for (;;) 2161 for (;;)
2095 { 2162 {
2096 c = inchar (SCHEME_A); 2163 c = inchar (SCHEME_A);
2097 2164
2099 return S_F; 2166 return S_F;
2100 2167
2101 switch (state) 2168 switch (state)
2102 { 2169 {
2103 case st_ok: 2170 case st_ok:
2104 switch (c) 2171 if (ecb_expect_false (c == delim))
2105 {
2106 case '\\':
2107 state = st_bsl;
2108 break;
2109
2110 case '"':
2111 *p = 0;
2112 return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff); 2172 return mk_counted_string (SCHEME_A_ SCHEME_V->strbuff, p - SCHEME_V->strbuff);
2113 2173
2114 default: 2174 if (ecb_expect_false (c == '\\'))
2175 state = st_bsl;
2176 else
2115 *p++ = c; 2177 *p++ = c;
2116 break;
2117 }
2118 2178
2119 break; 2179 break;
2120 2180
2121 case st_bsl: 2181 case st_bsl:
2122 switch (c) 2182 switch (c)
2152 case 'r': 2212 case 'r':
2153 *p++ = '\r'; 2213 *p++ = '\r';
2154 state = st_ok; 2214 state = st_ok;
2155 break; 2215 break;
2156 2216
2157 case '"':
2158 *p++ = '"';
2159 state = st_ok;
2160 break;
2161
2162 default: 2217 default:
2163 *p++ = c; 2218 *p++ = c;
2164 state = st_ok; 2219 state = st_ok;
2165 break; 2220 break;
2166 } 2221 }
2167 2222
2168 break; 2223 break;
2169 2224
2170 case st_x1: 2225 case st_x1:
2171 case st_x2: 2226 case st_x2:
2172 c = toupper (c); 2227 c = tolower (c);
2173 2228
2174 if (c >= '0' && c <= 'F') 2229 if (c >= '0' && c <= '9')
2175 {
2176 if (c <= '9')
2177 c1 = (c1 << 4) + c - '0'; 2230 c1 = (c1 << 4) + c - '0';
2178 else 2231 else if (c >= 'a' && c <= 'f')
2179 c1 = (c1 << 4) + c - 'A' + 10; 2232 c1 = (c1 << 4) + c - 'a' + 10;
2180
2181 if (state == st_x1)
2182 state = st_x2;
2183 else
2184 {
2185 *p++ = c1;
2186 state = st_ok;
2187 }
2188 }
2189 else 2233 else
2190 return S_F; 2234 return S_F;
2235
2236 if (state == st_x1)
2237 state = st_x2;
2238 else
2239 {
2240 *p++ = c1;
2241 state = st_ok;
2242 }
2191 2243
2192 break; 2244 break;
2193 2245
2194 case st_oct1: 2246 case st_oct1:
2195 case st_oct2: 2247 case st_oct2:
2199 backchar (SCHEME_A_ c); 2251 backchar (SCHEME_A_ c);
2200 state = st_ok; 2252 state = st_ok;
2201 } 2253 }
2202 else 2254 else
2203 { 2255 {
2204 if (state == st_oct2 && c1 >= 32) 2256 if (state == st_oct2 && c1 >= ' ')
2205 return S_F; 2257 return S_F;
2206 2258
2207 c1 = (c1 << 3) + (c - '0'); 2259 c1 = (c1 << 3) + (c - '0');
2208 2260
2209 if (state == st_oct1) 2261 if (state == st_oct1)
2214 state = st_ok; 2266 state = st_ok;
2215 } 2267 }
2216 } 2268 }
2217 2269
2218 break; 2270 break;
2219
2220 } 2271 }
2221 } 2272 }
2222} 2273}
2223 2274
2224/* check c is in chars */ 2275/* check c is in chars */
2225ecb_inline int 2276ecb_inline int
2226is_one_of (char *s, int c) 2277is_one_of (const char *s, int c)
2227{ 2278{
2228 if (c == EOF)
2229 return 1;
2230
2231 return !!strchr (s, c); 2279 return c == EOF || !!strchr (s, c);
2232} 2280}
2233 2281
2234/* skip white characters */ 2282/* skip white characters */
2235ecb_inline int 2283ecb_inline int
2236skipspace (SCHEME_P) 2284skipspace (SCHEME_P)
2238 int c, curr_line = 0; 2286 int c, curr_line = 0;
2239 2287
2240 do 2288 do
2241 { 2289 {
2242 c = inchar (SCHEME_A); 2290 c = inchar (SCHEME_A);
2291
2243#if SHOW_ERROR_LINE 2292#if SHOW_ERROR_LINE
2244 if (c == '\n') 2293 if (ecb_expect_false (c == '\n'))
2245 curr_line++; 2294 curr_line++;
2246#endif 2295#endif
2296
2297 if (ecb_expect_false (c == EOF))
2298 return c;
2247 } 2299 }
2248 while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); 2300 while (is_one_of (WHITESPACE, c));
2249 2301
2250 /* record it */ 2302 /* record it */
2251#if SHOW_ERROR_LINE 2303#if SHOW_ERROR_LINE
2252 if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file) 2304 if (SCHEME_V->load_stack[SCHEME_V->file_i].kind & port_file)
2253 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line; 2305 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.curr_line += curr_line;
2254#endif 2306#endif
2255 2307
2256 if (c != EOF)
2257 {
2258 backchar (SCHEME_A_ c); 2308 backchar (SCHEME_A_ c);
2259 return 1; 2309 return 1;
2260 }
2261 else
2262 return EOF;
2263} 2310}
2264 2311
2265/* get token */ 2312/* get token */
2266static int 2313static int
2267token (SCHEME_P) 2314token (SCHEME_P)
2283 return TOK_RPAREN; 2330 return TOK_RPAREN;
2284 2331
2285 case '.': 2332 case '.':
2286 c = inchar (SCHEME_A); 2333 c = inchar (SCHEME_A);
2287 2334
2288 if (is_one_of (" \n\t", c)) 2335 if (is_one_of (WHITESPACE, c))
2289 return TOK_DOT; 2336 return TOK_DOT;
2290 else 2337 else
2291 { 2338 {
2292 //TODO: ungetc twice in a row is not supported in C
2293 backchar (SCHEME_A_ c); 2339 backchar (SCHEME_A_ c);
2294 backchar (SCHEME_A_ '.');
2295 return TOK_ATOM; 2340 return TOK_DOTATOM;
2296 } 2341 }
2342
2343 case '|':
2344 return TOK_STRATOM;
2297 2345
2298 case '\'': 2346 case '\'':
2299 return TOK_QUOTE; 2347 return TOK_QUOTE;
2300 2348
2301 case ';': 2349 case ';':
2433 } 2481 }
2434 2482
2435 putcharacter (SCHEME_A_ '"'); 2483 putcharacter (SCHEME_A_ '"');
2436} 2484}
2437 2485
2438
2439/* print atoms */ 2486/* print atoms */
2440static void 2487static void
2441printatom (SCHEME_P_ pointer l, int f) 2488printatom (SCHEME_P_ pointer l, int f)
2442{ 2489{
2443 char *p; 2490 char *p;
2444 int len; 2491 int len;
2445 2492
2446 atom2str (SCHEME_A_ l, f, &p, &len); 2493 atom2str (SCHEME_A_ l, f, &p, &len);
2447 putchars (SCHEME_A_ p, len); 2494 putchars (SCHEME_A_ p, len);
2448} 2495}
2449
2450 2496
2451/* Uses internal buffer unless string pointer is already available */ 2497/* Uses internal buffer unless string pointer is already available */
2452static void 2498static void
2453atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2499atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen)
2454{ 2500{
2615#endif 2661#endif
2616 } 2662 }
2617 else if (is_continuation (l)) 2663 else if (is_continuation (l))
2618 p = "#<CONTINUATION>"; 2664 p = "#<CONTINUATION>";
2619 else 2665 else
2666 {
2667#if USE_PRINTF
2668 p = SCHEME_V->strbuff;
2669 snprintf (p, STRBUFFSIZE, "#<ERROR %x>", (int)typeflag (l));
2670#else
2620 p = "#<ERROR>"; 2671 p = "#<ERROR>";
2672#endif
2673 }
2621 2674
2622 *pp = p; 2675 *pp = p;
2623 *plen = strlen (p); 2676 *plen = strlen (p);
2624} 2677}
2625 2678
2769/* () is #t in R5RS */ 2822/* () is #t in R5RS */
2770#define is_true(p) ((p) != S_F) 2823#define is_true(p) ((p) != S_F)
2771#define is_false(p) ((p) == S_F) 2824#define is_false(p) ((p) == S_F)
2772 2825
2773/* ========== Environment implementation ========== */ 2826/* ========== Environment implementation ========== */
2774
2775#if !defined(USE_ALIST_ENV) || !defined(USE_OBJECT_LIST)
2776
2777static int
2778hash_fn (const char *key, int table_size)
2779{
2780 const unsigned char *p = key;
2781 uint32_t hash = 2166136261;
2782
2783 while (*p)
2784 hash = (hash ^ *p++) * 16777619;
2785
2786 return hash % table_size;
2787}
2788#endif
2789 2827
2790#ifndef USE_ALIST_ENV 2828#ifndef USE_ALIST_ENV
2791 2829
2792/* 2830/*
2793 * In this implementation, each frame of the environment may be 2831 * In this implementation, each frame of the environment may be
2810 2848
2811 SCHEME_V->envir = immutable_cons (new_frame, old_env); 2849 SCHEME_V->envir = immutable_cons (new_frame, old_env);
2812 setenvironment (SCHEME_V->envir); 2850 setenvironment (SCHEME_V->envir);
2813} 2851}
2814 2852
2853static uint32_t
2854sym_hash (pointer sym, uint32_t size)
2855{
2856 uintptr_t ptr = (uintptr_t)sym;
2857
2858#if 0
2859 /* table size is prime, so why mix */
2860 ptr += ptr >> 32;
2861 ptr += ptr >> 16;
2862 ptr += ptr >> 8;
2863#endif
2864
2865 return ptr % size;
2866}
2867
2815ecb_inline void 2868ecb_inline void
2816new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) 2869new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value)
2817{ 2870{
2818 pointer slot = immutable_cons (variable, value); 2871 pointer slot = immutable_cons (variable, value);
2819 2872
2820 if (is_vector (car (env))) 2873 if (is_vector (car (env)))
2821 { 2874 {
2822 int location = hash_fn (symname (variable), veclength (car (env))); 2875 int location = sym_hash (variable, veclength (car (env)));
2823
2824 set_vector_elem (car (env), location, immutable_cons (slot, vector_elem (car (env), location))); 2876 vector_set (car (env), location, immutable_cons (slot, vector_get (car (env), location)));
2825 } 2877 }
2826 else 2878 else
2827 set_car (env, immutable_cons (slot, car (env))); 2879 set_car (env, immutable_cons (slot, car (env)));
2828} 2880}
2829 2881
2830static pointer 2882static pointer
2831find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) 2883find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all)
2832{ 2884{
2833 pointer x, y; 2885 pointer x, y;
2834 int location;
2835 2886
2836 for (x = env; x != NIL; x = cdr (x)) 2887 for (x = env; x != NIL; x = cdr (x))
2837 { 2888 {
2838 if (is_vector (car (x))) 2889 if (is_vector (car (x)))
2839 { 2890 {
2840 location = hash_fn (symname (hdl), veclength (car (x))); 2891 int location = sym_hash (hdl, veclength (car (x)));
2841 y = vector_elem (car (x), location); 2892 y = vector_get (car (x), location);
2842 } 2893 }
2843 else 2894 else
2844 y = car (x); 2895 y = car (x);
2845 2896
2846 for (; y != NIL; y = cdr (y)) 2897 for (; y != NIL; y = cdr (y))
2847 if (caar (y) == hdl) 2898 if (caar (y) == hdl)
2848 break; 2899 break;
2849 2900
2850 if (y != NIL) 2901 if (y != NIL)
2902 return car (y);
2903
2904 if (!all)
2851 break; 2905 break;
2852
2853 if (!all)
2854 return NIL;
2855 } 2906 }
2856
2857 if (x != NIL)
2858 return car (y);
2859 2907
2860 return NIL; 2908 return NIL;
2861} 2909}
2862 2910
2863#else /* USE_ALIST_ENV */ 2911#else /* USE_ALIST_ENV */
2885 for (y = car (x); y != NIL; y = cdr (y)) 2933 for (y = car (x); y != NIL; y = cdr (y))
2886 if (caar (y) == hdl) 2934 if (caar (y) == hdl)
2887 break; 2935 break;
2888 2936
2889 if (y != NIL) 2937 if (y != NIL)
2938 return car (y);
2890 break; 2939 break;
2891 2940
2892 if (!all) 2941 if (!all)
2893 return NIL; 2942 break;
2894 } 2943 }
2895
2896 if (x != NIL)
2897 return car (y);
2898 2944
2899 return NIL; 2945 return NIL;
2900} 2946}
2901 2947
2902#endif /* USE_ALIST_ENV else */ 2948#endif /* USE_ALIST_ENV else */
2903 2949
2904ecb_inline void 2950ecb_inline void
2905new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2951new_slot_in_env (SCHEME_P_ pointer variable, pointer value)
2906{ 2952{
2953 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2
2907 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); 2954 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value);
2908} 2955}
2909 2956
2910ecb_inline void 2957ecb_inline void
2911set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2958set_slot_in_env (SCHEME_P_ pointer slot, pointer value)
3119 int i = 0; 3166 int i = 0;
3120 struct dump_stack_frame *frame = SCHEME_V->dump_base; 3167 struct dump_stack_frame *frame = SCHEME_V->dump_base;
3121 3168
3122 while (cont != NIL) 3169 while (cont != NIL)
3123 { 3170 {
3124 frame->op = ivalue (car (cont)); cont = cdr (cont); 3171 frame->op = ivalue_unchecked (car (cont)); cont = cdr (cont);
3125 frame->args = car (cont) ; cont = cdr (cont); 3172 frame->args = car (cont) ; cont = cdr (cont);
3126 frame->envir = car (cont) ; cont = cdr (cont); 3173 frame->envir = car (cont) ; cont = cdr (cont);
3127 frame->code = car (cont) ; cont = cdr (cont); 3174 frame->code = car (cont) ; cont = cdr (cont);
3128 3175
3129 ++frame; 3176 ++frame;
3130 ++i; 3177 ++i;
3131 } 3178 }
3132 3179
3161 SCHEME_V->value = a; 3208 SCHEME_V->value = a;
3162 3209
3163 if (dump == NIL) 3210 if (dump == NIL)
3164 return -1; 3211 return -1;
3165 3212
3166 SCHEME_V->op = ivalue (car (dump)); dump = cdr (dump); 3213 SCHEME_V->op = ivalue_unchecked (car (dump)); dump = cdr (dump);
3167 SCHEME_V->args = car (dump) ; dump = cdr (dump); 3214 SCHEME_V->args = car (dump) ; dump = cdr (dump);
3168 SCHEME_V->envir = car (dump) ; dump = cdr (dump); 3215 SCHEME_V->envir = car (dump) ; dump = cdr (dump);
3169 SCHEME_V->code = car (dump) ; dump = cdr (dump); 3216 SCHEME_V->code = car (dump) ; dump = cdr (dump);
3170 3217
3171 SCHEME_V->dump = dump; 3218 SCHEME_V->dump = dump;
3172 3219
3173 return 0; 3220 return 0;
3174} 3221}
3203 3250
3204#endif 3251#endif
3205 3252
3206#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3253#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3207 3254
3255#if EXPERIMENT
3256static int
3257debug (SCHEME_P_ int indent, pointer x)
3258{
3259 int c;
3260
3261 if (is_syntax (x))
3262 {
3263 printf ("%*ssyntax<%s,%d>\n", indent, "", syntaxname(x),syntaxnum(x));
3264 return 8 + 8;
3265 }
3266
3267 if (x == NIL)
3268 {
3269 printf ("%*sNIL\n", indent, "");
3270 return 3;
3271 }
3272
3273 switch (type (x))
3274 {
3275 case T_INTEGER:
3276 printf ("%*sI<%d>%p\n", indent, "", (int)ivalue_unchecked (x), x);
3277 return 32+8;
3278
3279 case T_SYMBOL:
3280 printf ("%*sS<%s>\n", indent, "", symname (x));
3281 return 24+8;
3282
3283 case T_CLOSURE:
3284 printf ("%*sS<%s>\n", indent, "", "closure");
3285 debug (SCHEME_A_ indent + 3, cdr(x));
3286 return 32 + debug (SCHEME_A_ indent + 3, car (x));
3287
3288 case T_PAIR:
3289 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3290 c = debug (SCHEME_A_ indent + 3, car (x));
3291 c += debug (SCHEME_A_ indent + 3, cdr (x));
3292 return c + 1;
3293
3294 case T_PORT:
3295 printf ("%*sS<%s>\n", indent, "", "port");
3296 return 24+8;
3297
3298 case T_VECTOR:
3299 printf ("%*sS<%s>\n", indent, "", "vector");
3300 return 24+8;
3301
3302 case T_ENVIRONMENT:
3303 printf ("%*sS<%s>\n", indent, "", "environment");
3304 return 0 + debug (SCHEME_A_ indent + 3, car (x));
3305
3306 default:
3307 printf ("unhandled type %d\n", type (x));
3308 break;
3309 }
3310}
3311#endif
3312
3208static int 3313static int
3209opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3314opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3210{ 3315{
3211 pointer args = SCHEME_V->args; 3316 pointer args = SCHEME_V->args;
3212 pointer x, y; 3317 pointer x, y;
3213 3318
3214 switch (op) 3319 switch (op)
3215 { 3320 {
3321#if EXPERIMENT //D
3322 case OP_DEBUG:
3323 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8);
3324 printf ("\n");
3325 s_return (S_T);
3326#endif
3216 case OP_LOAD: /* load */ 3327 case OP_LOAD: /* load */
3217 if (file_interactive (SCHEME_A)) 3328 if (file_interactive (SCHEME_A))
3218 { 3329 {
3219 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n"); 3330 xwrstr ("Loading "); xwrstr (strvalue (car (args))); xwrstr ("\n");
3220 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args))); 3331 //D fprintf (SCHEME_V->outport->object.port->rep.stdio.file, "Loading %s\n", strvalue (car (args)));
3343 } 3454 }
3344 else 3455 else
3345 s_return (SCHEME_V->code); 3456 s_return (SCHEME_V->code);
3346 3457
3347 case OP_E0ARGS: /* eval arguments */ 3458 case OP_E0ARGS: /* eval arguments */
3348 if (is_macro (SCHEME_V->value)) /* macro expansion */ 3459 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3349 { 3460 {
3350 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3461 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3351 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3462 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3352 SCHEME_V->code = SCHEME_V->value; 3463 SCHEME_V->code = SCHEME_V->value;
3353 s_goto (OP_APPLY); 3464 s_goto (OP_APPLY);
3380 3491
3381 case OP_TRACING: 3492 case OP_TRACING:
3382 { 3493 {
3383 int tr = SCHEME_V->tracing; 3494 int tr = SCHEME_V->tracing;
3384 3495
3385 SCHEME_V->tracing = ivalue (car (args)); 3496 SCHEME_V->tracing = ivalue_unchecked (car (args));
3386 s_return (mk_integer (SCHEME_A_ tr)); 3497 s_return (mk_integer (SCHEME_A_ tr));
3387 } 3498 }
3388 3499
3389#endif 3500#endif
3390 3501
3909{ 4020{
3910 pointer args = SCHEME_V->args; 4021 pointer args = SCHEME_V->args;
3911 pointer x = car (args); 4022 pointer x = car (args);
3912 num v; 4023 num v;
3913 4024
3914#if USE_MATH
3915 RVALUE dd;
3916#endif
3917
3918 switch (op) 4025 switch (op)
3919 { 4026 {
3920#if USE_MATH 4027#if USE_MATH
3921 case OP_INEX2EX: /* inexact->exact */ 4028 case OP_INEX2EX: /* inexact->exact */
4029 {
3922 if (is_integer (x)) 4030 if (is_integer (x))
3923 s_return (x); 4031 s_return (x);
3924 else if (modf (rvalue_unchecked (x), &dd) == 0) 4032
4033 RVALUE r = rvalue_unchecked (x);
4034
4035 if (r == (RVALUE)(IVALUE)r)
3925 s_return (mk_integer (SCHEME_A_ ivalue (x))); 4036 s_return (mk_integer (SCHEME_A_ rvalue_unchecked (x)));
3926 else 4037 else
3927 Error_1 ("inexact->exact: not integral:", x); 4038 Error_1 ("inexact->exact: not integral:", x);
4039 }
3928 4040
3929 case OP_EXP: s_return (mk_real (SCHEME_A_ exp (rvalue (x)))); 4041 case OP_EXP: s_return (mk_real (SCHEME_A_ exp (rvalue (x))));
3930 case OP_LOG: s_return (mk_real (SCHEME_A_ log (rvalue (x)))); 4042 case OP_LOG: s_return (mk_real (SCHEME_A_ log (rvalue (x))));
3931 case OP_SIN: s_return (mk_real (SCHEME_A_ sin (rvalue (x)))); 4043 case OP_SIN: s_return (mk_real (SCHEME_A_ sin (rvalue (x))));
3932 case OP_COS: s_return (mk_real (SCHEME_A_ cos (rvalue (x)))); 4044 case OP_COS: s_return (mk_real (SCHEME_A_ cos (rvalue (x))));
3966 /* If the test fails, result is too big for integer. */ 4078 /* If the test fails, result is too big for integer. */
3967 if (!real_result) 4079 if (!real_result)
3968 { 4080 {
3969 long result_as_long = result; 4081 long result_as_long = result;
3970 4082
3971 if (result != (RVALUE) result_as_long) 4083 if (result != result_as_long)
3972 real_result = 1; 4084 real_result = 1;
3973 } 4085 }
3974 4086
3975 if (real_result) 4087 if (real_result)
3976 s_return (mk_real (SCHEME_A_ result)); 4088 s_return (mk_real (SCHEME_A_ result));
3981 case OP_FLOOR: s_return (mk_real (SCHEME_A_ floor (rvalue (x)))); 4093 case OP_FLOOR: s_return (mk_real (SCHEME_A_ floor (rvalue (x))));
3982 case OP_CEILING: s_return (mk_real (SCHEME_A_ ceil (rvalue (x)))); 4094 case OP_CEILING: s_return (mk_real (SCHEME_A_ ceil (rvalue (x))));
3983 4095
3984 case OP_TRUNCATE: 4096 case OP_TRUNCATE:
3985 { 4097 {
3986 RVALUE rvalue_of_x; 4098 RVALUE n = rvalue (x);
3987
3988 rvalue_of_x = rvalue (x);
3989
3990 if (rvalue_of_x > 0)
3991 s_return (mk_real (SCHEME_A_ floor (rvalue_of_x))); 4099 s_return (mk_real (SCHEME_A_ n > 0 ? floor (n) : ceil (n)));
3992 else
3993 s_return (mk_real (SCHEME_A_ ceil (rvalue_of_x)));
3994 } 4100 }
3995 4101
3996 case OP_ROUND: 4102 case OP_ROUND:
3997 if (num_is_integer (x)) 4103 if (is_integer (x))
3998 s_return (x); 4104 s_return (x);
3999 4105
4000 s_return (mk_real (SCHEME_A_ round_per_R5RS (rvalue (x)))); 4106 s_return (mk_real (SCHEME_A_ round_per_R5RS (rvalue (x))));
4001#endif 4107#endif
4002 4108
4122 } 4228 }
4123 else 4229 else
4124 Error_0 ("set-cdr!: unable to alter immutable pair"); 4230 Error_0 ("set-cdr!: unable to alter immutable pair");
4125 4231
4126 case OP_CHAR2INT: /* char->integer */ 4232 case OP_CHAR2INT: /* char->integer */
4127 s_return (mk_integer (SCHEME_A_ ivalue (x))); 4233 s_return (mk_integer (SCHEME_A_ ivalue_unchecked (x)));
4128 4234
4129 case OP_INT2CHAR: /* integer->char */ 4235 case OP_INT2CHAR: /* integer->char */
4130 s_return (mk_character (SCHEME_A_ ivalue (x))); 4236 s_return (mk_character (SCHEME_A_ ivalue_unchecked (x)));
4131 4237
4132 case OP_CHARUPCASE: 4238 case OP_CHARUPCASE:
4133 { 4239 {
4134 unsigned char c = ivalue (x); 4240 unsigned char c = ivalue_unchecked (x);
4135 c = toupper (c); 4241 c = toupper (c);
4136 s_return (mk_character (SCHEME_A_ c)); 4242 s_return (mk_character (SCHEME_A_ c));
4137 } 4243 }
4138 4244
4139 case OP_CHARDNCASE: 4245 case OP_CHARDNCASE:
4140 { 4246 {
4141 unsigned char c = ivalue (x); 4247 unsigned char c = ivalue_unchecked (x);
4142 c = tolower (c); 4248 c = tolower (c);
4143 s_return (mk_character (SCHEME_A_ c)); 4249 s_return (mk_character (SCHEME_A_ c));
4144 } 4250 }
4145 4251
4146 case OP_STR2SYM: /* string->symbol */ 4252 case OP_STR2SYM: /* string->symbol */
4223 Error_1 ("atom->string: not an atom:", x); 4329 Error_1 ("atom->string: not an atom:", x);
4224 } 4330 }
4225 4331
4226 case OP_MKSTRING: /* make-string */ 4332 case OP_MKSTRING: /* make-string */
4227 { 4333 {
4228 int fill = ' '; 4334 int fill = cdr (args) != NIL ? charvalue (cadr (args)) : ' ';
4229 int len;
4230
4231 len = ivalue (x); 4335 int len = ivalue_unchecked (x);
4232
4233 if (cdr (args) != NIL)
4234 fill = charvalue (cadr (args));
4235 4336
4236 s_return (mk_empty_string (SCHEME_A_ len, fill)); 4337 s_return (mk_empty_string (SCHEME_A_ len, fill));
4237 } 4338 }
4238 4339
4239 case OP_STRLEN: /* string-length */ 4340 case OP_STRLEN: /* string-length */
4240 s_return (mk_integer (SCHEME_A_ strlength (x))); 4341 s_return (mk_integer (SCHEME_A_ strlength (x)));
4241 4342
4242 case OP_STRREF: /* string-ref */ 4343 case OP_STRREF: /* string-ref */
4243 { 4344 {
4244 char *str;
4245 int index;
4246
4247 str = strvalue (x); 4345 char *str = strvalue (x);
4248
4249 index = ivalue (cadr (args)); 4346 int index = ivalue_unchecked (cadr (args));
4250 4347
4251 if (index >= strlength (x)) 4348 if (index >= strlength (x))
4252 Error_1 ("string-ref: out of bounds:", cadr (args)); 4349 Error_1 ("string-ref: out of bounds:", cadr (args));
4253 4350
4254 s_return (mk_character (SCHEME_A_ ((unsigned char *)str)[index])); 4351 s_return (mk_character (SCHEME_A_ ((unsigned char *)str)[index]));
4255 } 4352 }
4256 4353
4257 case OP_STRSET: /* string-set! */ 4354 case OP_STRSET: /* string-set! */
4258 { 4355 {
4259 char *str; 4356 char *str = strvalue (x);
4260 int index; 4357 int index = ivalue_unchecked (cadr (args));
4261 int c; 4358 int c;
4262 4359
4263 if (is_immutable (x)) 4360 if (is_immutable (x))
4264 Error_1 ("string-set!: unable to alter immutable string:", x); 4361 Error_1 ("string-set!: unable to alter immutable string:", x);
4265
4266 str = strvalue (x);
4267
4268 index = ivalue (cadr (args));
4269 4362
4270 if (index >= strlength (x)) 4363 if (index >= strlength (x))
4271 Error_1 ("string-set!: out of bounds:", cadr (args)); 4364 Error_1 ("string-set!: out of bounds:", cadr (args));
4272 4365
4273 c = charvalue (caddr (args)); 4366 c = charvalue (caddr (args));
4296 s_return (newstr); 4389 s_return (newstr);
4297 } 4390 }
4298 4391
4299 case OP_SUBSTR: /* substring */ 4392 case OP_SUBSTR: /* substring */
4300 { 4393 {
4301 char *str; 4394 char *str = strvalue (x);
4302 int index0; 4395 int index0 = ivalue_unchecked (cadr (args));
4303 int index1; 4396 int index1;
4304 int len; 4397 int len;
4305 4398
4306 str = strvalue (x);
4307
4308 index0 = ivalue (cadr (args));
4309
4310 if (index0 > strlength (x)) 4399 if (index0 > strlength (x))
4311 Error_1 ("substring: start out of bounds:", cadr (args)); 4400 Error_1 ("substring: start out of bounds:", cadr (args));
4312 4401
4313 if (cddr (args) != NIL) 4402 if (cddr (args) != NIL)
4314 { 4403 {
4315 index1 = ivalue (caddr (args)); 4404 index1 = ivalue_unchecked (caddr (args));
4316 4405
4317 if (index1 > strlength (x) || index1 < index0) 4406 if (index1 > strlength (x) || index1 < index0)
4318 Error_1 ("substring: end out of bounds:", caddr (args)); 4407 Error_1 ("substring: end out of bounds:", caddr (args));
4319 } 4408 }
4320 else 4409 else
4343 if (SCHEME_V->no_memory) 4432 if (SCHEME_V->no_memory)
4344 s_return (S_SINK); 4433 s_return (S_SINK);
4345#endif 4434#endif
4346 4435
4347 for (x = args, i = 0; is_pair (x); x = cdr (x), i++) 4436 for (x = args, i = 0; is_pair (x); x = cdr (x), i++)
4348 set_vector_elem (vec, i, car (x)); 4437 vector_set (vec, i, car (x));
4349 4438
4350 s_return (vec); 4439 s_return (vec);
4351 } 4440 }
4352 4441
4353 case OP_MKVECTOR: /* make-vector */ 4442 case OP_MKVECTOR: /* make-vector */
4354 { 4443 {
4355 pointer fill = NIL; 4444 pointer fill = NIL;
4356 int len;
4357 pointer vec; 4445 pointer vec;
4358
4359 len = ivalue (x); 4446 int len = ivalue_unchecked (x);
4360 4447
4361 if (cdr (args) != NIL) 4448 if (cdr (args) != NIL)
4362 fill = cadr (args); 4449 fill = cadr (args);
4363 4450
4364 vec = mk_vector (SCHEME_A_ len); 4451 vec = mk_vector (SCHEME_A_ len);
4367 if (SCHEME_V->no_memory) 4454 if (SCHEME_V->no_memory)
4368 s_return (S_SINK); 4455 s_return (S_SINK);
4369#endif 4456#endif
4370 4457
4371 if (fill != NIL) 4458 if (fill != NIL)
4372 fill_vector (vec, fill); 4459 fill_vector (vec, 0, fill);
4373 4460
4374 s_return (vec); 4461 s_return (vec);
4375 } 4462 }
4376 4463
4377 case OP_VECLEN: /* vector-length */ 4464 case OP_VECLEN: /* vector-length */
4378 s_return (mk_integer (SCHEME_A_ veclength (x))); 4465 s_return (mk_integer (SCHEME_A_ veclength (x)));
4379 4466
4467 case OP_VECRESIZE:
4468 vector_resize (x, ivalue_unchecked (cadr (args)), caddr (args));
4469 s_return (x);
4470
4380 case OP_VECREF: /* vector-ref */ 4471 case OP_VECREF: /* vector-ref */
4381 { 4472 {
4382 int index;
4383
4384 index = ivalue (cadr (args)); 4473 int index = ivalue_unchecked (cadr (args));
4385 4474
4386 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4475 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4387 Error_1 ("vector-ref: out of bounds:", cadr (args)); 4476 Error_1 ("vector-ref: out of bounds:", cadr (args));
4388 4477
4389 s_return (vector_elem (x, index)); 4478 s_return (vector_get (x, index));
4390 } 4479 }
4391 4480
4392 case OP_VECSET: /* vector-set! */ 4481 case OP_VECSET: /* vector-set! */
4393 { 4482 {
4394 int index; 4483 int index = ivalue_unchecked (cadr (args));
4395 4484
4396 if (is_immutable (x)) 4485 if (is_immutable (x))
4397 Error_1 ("vector-set!: unable to alter immutable vector:", x); 4486 Error_1 ("vector-set!: unable to alter immutable vector:", x);
4398 4487
4399 index = ivalue (cadr (args));
4400
4401 if (index >= veclength (car (args)) && USE_ERROR_CHECKING) 4488 if (index >= veclength (car (args)) && USE_ERROR_CHECKING)
4402 Error_1 ("vector-set!: out of bounds:", cadr (args)); 4489 Error_1 ("vector-set!: out of bounds:", cadr (args));
4403 4490
4404 set_vector_elem (x, index, caddr (args)); 4491 vector_set (x, index, caddr (args));
4405 s_return (x); 4492 s_return (x);
4406 } 4493 }
4407 } 4494 }
4408 4495
4409 if (USE_ERROR_CHECKING) abort (); 4496 if (USE_ERROR_CHECKING) abort ();
4410}
4411
4412INTERFACE int
4413is_list (SCHEME_P_ pointer a)
4414{
4415 return list_length (SCHEME_A_ a) >= 0;
4416}
4417
4418/* Result is:
4419 proper list: length
4420 circular list: -1
4421 not even a pair: -2
4422 dotted list: -2 minus length before dot
4423*/
4424INTERFACE int
4425list_length (SCHEME_P_ pointer a)
4426{
4427 int i = 0;
4428 pointer slow, fast;
4429
4430 slow = fast = a;
4431
4432 while (1)
4433 {
4434 if (fast == NIL)
4435 return i;
4436
4437 if (!is_pair (fast))
4438 return -2 - i;
4439
4440 fast = cdr (fast);
4441 ++i;
4442
4443 if (fast == NIL)
4444 return i;
4445
4446 if (!is_pair (fast))
4447 return -2 - i;
4448
4449 ++i;
4450 fast = cdr (fast);
4451
4452 /* Safe because we would have already returned if `fast'
4453 encountered a non-pair. */
4454 slow = cdr (slow);
4455
4456 if (fast == slow)
4457 {
4458 /* the fast pointer has looped back around and caught up
4459 with the slow pointer, hence the structure is circular,
4460 not of finite length, and therefore not a list */
4461 return -1;
4462 }
4463 }
4464} 4497}
4465 4498
4466static int 4499static int
4467opexe_2 (SCHEME_P_ enum scheme_opcodes op) 4500opexe_2 (SCHEME_P_ enum scheme_opcodes op)
4468{ 4501{
4502 pointer d = cdr (args); 4535 pointer d = cdr (args);
4503 int r; 4536 int r;
4504 4537
4505 switch (op) 4538 switch (op)
4506 { 4539 {
4507 case OP_NOT: /* not */ r = is_false (a) ; break; 4540 case OP_NOT: /* not */ r = is_false (a) ; break;
4508 case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T; break; 4541 case OP_BOOLP: /* boolean? */ r = a == S_F || a == S_T ; break;
4509 case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break; 4542 case OP_EOFOBJP: /* eof-object? */ r = a == S_EOF ; break;
4510 case OP_NULLP: /* null? */ r = a == NIL ; break; 4543 case OP_NULLP: /* null? */ r = a == NIL ; break;
4511 case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break; 4544 case OP_SYMBOLP: /* symbol? */ r = is_symbol (a) ; break;
4545 case OP_GENSYMP: /* gensym? */ r = is_gensym (SCHEME_A_ a); break;
4512 case OP_NUMBERP: /* number? */ r = is_number (a) ; break; 4546 case OP_NUMBERP: /* number? */ r = is_number (a) ; break;
4513 case OP_STRINGP: /* string? */ r = is_string (a) ; break; 4547 case OP_STRINGP: /* string? */ r = is_string (a) ; break;
4514 case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break; 4548 case OP_INTEGERP: /* integer? */ r = is_integer (a) ; break;
4515 case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */ 4549 case OP_REALP: /* real? */ r = is_number (a) ; break; /* all numbers are real */
4516 case OP_CHARP: /* char? */ r = is_character (a) ; break; 4550 case OP_CHARP: /* char? */ r = is_character (a) ; break;
4517 4551
4518#if USE_CHAR_CLASSIFIERS 4552#if USE_CHAR_CLASSIFIERS
4519 case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue (a)); break; 4553 case OP_CHARAP: /* char-alphabetic? */ r = Cisalpha (ivalue_unchecked (a)); break;
4520 case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue (a)); break; 4554 case OP_CHARNP: /* char-numeric? */ r = Cisdigit (ivalue_unchecked (a)); break;
4521 case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue (a)); break; 4555 case OP_CHARWP: /* char-whitespace? */ r = Cisspace (ivalue_unchecked (a)); break;
4522 case OP_CHARUP: /* char-upper-case? */ r = Cisupper (ivalue (a)); break; 4556 case OP_CHARUP: /* char-upper-case? */ r = Cisupper (ivalue_unchecked (a)); break;
4523 case OP_CHARLP: /* char-lower-case? */ r = Cislower (ivalue (a)); break; 4557 case OP_CHARLP: /* char-lower-case? */ r = Cislower (ivalue_unchecked (a)); break;
4524#endif 4558#endif
4525 4559
4526#if USE_PORTS 4560#if USE_PORTS
4527 case OP_PORTP: /* port? */ r = is_port (a) ; break; 4561 case OP_PORTP: /* port? */ r = is_port (a) ; break;
4528 case OP_INPORTP: /* input-port? */ r = is_inport (a) ; break; 4562 case OP_INPORTP: /* input-port? */ r = is_inport (a) ; break;
4729 4763
4730 case OP_NEWSEGMENT: /* new-segment */ 4764 case OP_NEWSEGMENT: /* new-segment */
4731 if (!is_pair (args) || !is_number (a)) 4765 if (!is_pair (args) || !is_number (a))
4732 Error_0 ("new-segment: argument must be a number"); 4766 Error_0 ("new-segment: argument must be a number");
4733 4767
4734 alloc_cellseg (SCHEME_A_ (int)ivalue (a)); 4768 alloc_cellseg (SCHEME_A_ ivalue (a));
4735 4769
4736 s_return (S_T); 4770 s_return (S_T);
4737 4771
4738 case OP_OBLIST: /* oblist */ 4772 case OP_OBLIST: /* oblist */
4739 s_return (oblist_all_symbols (SCHEME_A)); 4773 s_return (oblist_all_symbols (SCHEME_A));
4997 s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL); 5031 s_save (SCHEME_A_ OP_RDUQTSP, NIL, NIL);
4998 SCHEME_V->tok = token (SCHEME_A); 5032 SCHEME_V->tok = token (SCHEME_A);
4999 s_goto (OP_RDSEXPR); 5033 s_goto (OP_RDSEXPR);
5000 5034
5001 case TOK_ATOM: 5035 case TOK_ATOM:
5002 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))); 5036 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS)));
5037
5038 case TOK_DOTATOM:
5039 SCHEME_V->strbuff[0] = '.';
5040 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5041
5042 case TOK_STRATOM:
5043 x = readstrexp (SCHEME_A_ '|');
5044 //TODO: haven't checked whether the garbage collector could interfere
5045 s_return (mk_atom (SCHEME_A_ strvalue (x)));
5003 5046
5004 case TOK_DQUOTE: 5047 case TOK_DQUOTE:
5005 x = readstrexp (SCHEME_A); 5048 x = readstrexp (SCHEME_A_ '"');
5006 5049
5007 if (x == S_F) 5050 if (x == S_F)
5008 Error_0 ("Error reading string"); 5051 Error_0 ("Error reading string");
5009 5052
5010 setimmutable (x); 5053 setimmutable (x);
5022 s_goto (OP_EVAL); 5065 s_goto (OP_EVAL);
5023 } 5066 }
5024 } 5067 }
5025 5068
5026 case TOK_SHARP_CONST: 5069 case TOK_SHARP_CONST:
5027 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ DELIMITERS))) == NIL) 5070 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL)
5028 Error_0 ("undefined sharp expression"); 5071 Error_0 ("undefined sharp expression");
5029 else 5072 else
5030 s_return (x); 5073 s_return (x);
5031 5074
5032 default: 5075 default:
5184 putstr (SCHEME_A_ ")"); 5227 putstr (SCHEME_A_ ")");
5185 s_return (S_T); 5228 s_return (S_T);
5186 } 5229 }
5187 else 5230 else
5188 { 5231 {
5189 pointer elem = vector_elem (vec, i); 5232 pointer elem = vector_get (vec, i);
5190 5233
5191 ivalue_unchecked (cdr (args)) = i + 1; 5234 ivalue_unchecked (cdr (args)) = i + 1;
5192 s_save (SCHEME_A_ OP_PVECFROM, args, NIL); 5235 s_save (SCHEME_A_ OP_PVECFROM, args, NIL);
5193 SCHEME_V->args = elem; 5236 SCHEME_V->args = elem;
5194 5237
5254 5297
5255 case OP_CLOSUREP: /* closure? */ 5298 case OP_CLOSUREP: /* closure? */
5256 /* 5299 /*
5257 * Note, macro object is also a closure. 5300 * Note, macro object is also a closure.
5258 * Therefore, (closure? <#MACRO>) ==> #t 5301 * Therefore, (closure? <#MACRO>) ==> #t
5302 * (schmorp) well, obviously not, fix? TODO
5259 */ 5303 */
5260 s_retbool (is_closure (a)); 5304 s_retbool (is_closure (a));
5261 5305
5262 case OP_MACROP: /* macro? */ 5306 case OP_MACROP: /* macro? */
5263 s_retbool (is_macro (a)); 5307 s_retbool (is_macro (a));
5269/* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */ 5313/* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */
5270typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes); 5314typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes);
5271 5315
5272typedef int (*test_predicate)(pointer); 5316typedef int (*test_predicate)(pointer);
5273static int 5317static int
5274is_any (pointer p) 5318tst_any (pointer p)
5275{ 5319{
5276 return 1; 5320 return 1;
5277} 5321}
5278 5322
5279static int 5323static int
5280is_nonneg (pointer p) 5324tst_inonneg (pointer p)
5281{ 5325{
5282 return ivalue (p) >= 0 && is_integer (p); 5326 return is_integer (p) && ivalue_unchecked (p) >= 0;
5283} 5327}
5284 5328
5285static int 5329static int
5286tst_is_list (pointer p) 5330tst_is_list (SCHEME_P_ pointer p)
5287{ 5331{
5288 return p == NIL || is_pair (p); 5332 return p == NIL || is_pair (p);
5289} 5333}
5290 5334
5291/* Correspond carefully with following defines! */ 5335/* Correspond carefully with following defines! */
5292static struct 5336static struct
5293{ 5337{
5294 test_predicate fct; 5338 test_predicate fct;
5295 const char *kind; 5339 const char *kind;
5296} tests[] = 5340} tests[] = {
5297{
5298 { is_any, 0 }, 5341 { tst_any , 0 },
5299 { is_string, "string" }, 5342 { is_string , "string" },
5300 { is_symbol, "symbol" }, 5343 { is_symbol , "symbol" },
5301 { is_port, "port" }, 5344 { is_port , "port" },
5302 { is_inport, "input port" }, 5345 { is_inport , "input port" },
5303 { is_outport, "output port" }, 5346 { is_outport , "output port" },
5304 { is_environment, "environment" }, 5347 { is_environment, "environment" },
5305 { is_pair, "pair" }, 5348 { is_pair , "pair" },
5306 { tst_is_list, "pair or '()" }, 5349 { 0 , "pair or '()" },
5307 { is_character, "character" }, 5350 { is_character , "character" },
5308 { is_vector, "vector" }, 5351 { is_vector , "vector" },
5309 { is_number, "number" }, 5352 { is_number , "number" },
5310 { is_integer, "integer" }, 5353 { is_integer , "integer" },
5311 { is_nonneg, "non-negative integer" } 5354 { tst_inonneg , "non-negative integer" }
5312}; 5355};
5313 5356
5314#define TST_NONE 0 /* TST_NONE used for built-ins, 0 for internal ops */ 5357#define TST_NONE 0 /* TST_NONE used for built-ins, 0 for internal ops */
5315#define TST_ANY "\001" 5358#define TST_ANY "\001"
5316#define TST_STRING "\002" 5359#define TST_STRING "\002"
5357typedef struct 5400typedef struct
5358{ 5401{
5359 uint8_t func; 5402 uint8_t func;
5360 /*dispatch_func func;*//*TODO: maybe optionally keep the pointer, for speed? */ 5403 /*dispatch_func func;*//*TODO: maybe optionally keep the pointer, for speed? */
5361 uint8_t builtin; 5404 uint8_t builtin;
5405#if USE_ERROR_CHECKING
5362 uint8_t min_arity; 5406 uint8_t min_arity;
5363 uint8_t max_arity; 5407 uint8_t max_arity;
5364 char arg_tests_encoding[3]; 5408 char arg_tests_encoding[3];
5409#endif
5365} op_code_info; 5410} op_code_info;
5366 5411
5367static const op_code_info dispatch_table[] = { 5412static const op_code_info dispatch_table[] = {
5413#if USE_ERROR_CHECKING
5368#define OP_DEF(func,name,minarity,maxarity,argtest,op) { func, sizeof (name) > 1, minarity, maxarity, argtest }, 5414#define OP_DEF(func,name,minarity,maxarity,argtest,op) { func, sizeof (name) > 1, minarity, maxarity, argtest },
5415#else
5416#define OP_DEF(func,name,minarity,maxarity,argtest,op) { func, sizeof (name) > 1 },
5417#endif
5369#include "opdefines.h" 5418#include "opdefines.h"
5370#undef OP_DEF 5419#undef OP_DEF
5371 {0} 5420 {0}
5372}; 5421};
5373 5422
5415 { 5464 {
5416 pointer arg = car (arglist); 5465 pointer arg = car (arglist);
5417 5466
5418 j = t[0]; 5467 j = t[0];
5419 5468
5469 /*TODO: tst_is_list has different prototype - fix if other tests acquire same prototype */
5470 if (j == TST_LIST[0])
5471 {
5472 if (!tst_is_list (SCHEME_A_ arg))
5473 break;
5474 }
5475 else
5476 {
5420 if (!tests[j - 1].fct (arg)) 5477 if (!tests[j - 1].fct (arg))
5421 break; 5478 break;
5479 }
5422 5480
5423 if (t[1]) /* last test is replicated as necessary */ 5481 if (t < pcd->arg_tests_encoding + sizeof (pcd->arg_tests_encoding) - 1 && t[1]) /* last test is replicated as necessary */
5424 t++; 5482 t++;
5425 5483
5426 arglist = cdr (arglist); 5484 arglist = cdr (arglist);
5427 i++; 5485 i++;
5428 } 5486 }
5483mk_proc (SCHEME_P_ enum scheme_opcodes op) 5541mk_proc (SCHEME_P_ enum scheme_opcodes op)
5484{ 5542{
5485 pointer y = get_cell (SCHEME_A_ NIL, NIL); 5543 pointer y = get_cell (SCHEME_A_ NIL, NIL);
5486 set_typeflag (y, (T_PROC | T_ATOM)); 5544 set_typeflag (y, (T_PROC | T_ATOM));
5487 ivalue_unchecked (y) = op; 5545 ivalue_unchecked (y) = op;
5488 set_num_integer (y);
5489 return y; 5546 return y;
5490} 5547}
5491 5548
5492/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5549/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5493static int 5550static int
5494syntaxnum (pointer p) 5551syntaxnum (pointer p)
5495{ 5552{
5496 const char *s = strvalue (car (p)); 5553 const char *s = strvalue (p);
5497 5554
5498 switch (strlength (car (p))) 5555 switch (strlength (p))
5499 { 5556 {
5500 case 2: 5557 case 2:
5501 if (s[0] == 'i') 5558 if (s[0] == 'i')
5502 return OP_IF0; /* if */ 5559 return OP_IF0; /* if */
5503 else 5560 else
5939# endif 5996# endif
5940 int fin; 5997 int fin;
5941 char *file_name = InitFile; 5998 char *file_name = InitFile;
5942 int retcode; 5999 int retcode;
5943 int isfile = 1; 6000 int isfile = 1;
6001 system ("ps v $PPID");//D
5944 6002
5945 if (argc == 2 && strcmp (argv[1], "-?") == 0) 6003 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5946 { 6004 {
5947 xwrstr ("Usage: tinyscheme -?\n"); 6005 xwrstr ("Usage: tinyscheme -?\n");
5948 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n"); 6006 xwrstr ("or: tinyscheme [<file1> <file2> ...]\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines