… | |
… | |
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 |
21 | #define _GNU_SOURCE 1 |
|
|
22 | #define _POSIX_C_SOURCE 200201 |
|
|
23 | #define _XOPEN_SOURCE 600 |
22 | |
24 | |
23 | #if 1 |
|
|
24 | #define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
|
|
25 | #include "malloc.c" |
|
|
26 | #endif |
|
|
27 | |
25 | |
28 | #define SCHEME_SOURCE |
26 | #define SCHEME_SOURCE |
29 | #include "scheme-private.h" |
27 | #include "scheme-private.h" |
30 | #ifndef WIN32 |
28 | #ifndef WIN32 |
31 | # include <unistd.h> |
29 | # include <unistd.h> |
32 | #endif |
30 | #endif |
33 | #if USE_MATH |
31 | #if USE_MATH |
34 | # include <math.h> |
32 | # include <math.h> |
35 | #endif |
33 | #endif |
36 | |
34 | |
|
|
35 | #define ECB_NO_THREADS 1 |
37 | #include "ecb.h" |
36 | #include "ecb.h" |
38 | |
37 | |
39 | #include <sys/types.h> |
38 | #include <sys/types.h> |
40 | #include <sys/stat.h> |
39 | #include <sys/stat.h> |
41 | #include <fcntl.h> |
40 | #include <fcntl.h> |
… | |
… | |
49 | #include <string.h> |
48 | #include <string.h> |
50 | |
49 | |
51 | #include <limits.h> |
50 | #include <limits.h> |
52 | #include <inttypes.h> |
51 | #include <inttypes.h> |
53 | #include <float.h> |
52 | #include <float.h> |
54 | //#include <ctype.h> |
53 | |
|
|
54 | #if !USE_SYSTEM_MALLOC |
|
|
55 | # define PAGE_SIZE 4096 /* does not work on sparc/alpha */ |
|
|
56 | # include "malloc.c" |
|
|
57 | # define malloc(n) tiny_malloc (n) |
|
|
58 | # define realloc(p,n) tiny_realloc (p, n) |
|
|
59 | # define free(p) tiny_free (p) |
|
|
60 | #endif |
55 | |
61 | |
56 | #if '1' != '0' + 1 \ |
62 | #if '1' != '0' + 1 \ |
57 | || '2' != '0' + 2 || '3' != '0' + 3 || '4' != '0' + 4 || '5' != '0' + 5 \ |
63 | || '2' != '0' + 2 || '3' != '0' + 3 || '4' != '0' + 4 || '5' != '0' + 5 \ |
58 | || '6' != '0' + 6 || '7' != '0' + 7 || '8' != '0' + 8 || '9' != '0' + 9 \ |
64 | || '6' != '0' + 6 || '7' != '0' + 7 || '8' != '0' + 8 || '9' != '0' + 9 \ |
59 | || 'b' != 'a' + 1 || 'c' != 'a' + 2 || 'd' != 'a' + 3 || 'e' != 'a' + 4 \ |
65 | || 'b' != 'a' + 1 || 'c' != 'a' + 2 || 'd' != 'a' + 3 || 'e' != 'a' + 4 \ |
… | |
… | |
91 | |
97 | |
92 | #if !USE_MULTIPLICITY |
98 | #if !USE_MULTIPLICITY |
93 | static scheme sc; |
99 | static scheme sc; |
94 | #endif |
100 | #endif |
95 | |
101 | |
96 | static void |
102 | ecb_cold static void |
97 | xbase (char *s, long n, int base) |
103 | xbase (char *s, long n, int base) |
98 | { |
104 | { |
99 | if (n < 0) |
105 | if (n < 0) |
100 | { |
106 | { |
101 | *s++ = '-'; |
107 | *s++ = '-'; |
… | |
… | |
116 | char x = *s; *s = *p; *p = x; |
122 | char x = *s; *s = *p; *p = x; |
117 | --p; ++s; |
123 | --p; ++s; |
118 | } |
124 | } |
119 | } |
125 | } |
120 | |
126 | |
121 | static void |
127 | ecb_cold static void |
122 | xnum (char *s, long n) |
128 | xnum (char *s, long n) |
123 | { |
129 | { |
124 | xbase (s, n, 10); |
130 | xbase (s, n, 10); |
125 | } |
131 | } |
126 | |
132 | |
127 | static void |
133 | ecb_cold static void |
128 | putnum (SCHEME_P_ long n) |
134 | putnum (SCHEME_P_ long n) |
129 | { |
135 | { |
130 | char buf[64]; |
136 | char buf[64]; |
131 | |
137 | |
132 | xnum (buf, n); |
138 | xnum (buf, n); |
133 | putstr (SCHEME_A_ buf); |
139 | putstr (SCHEME_A_ buf); |
134 | } |
140 | } |
|
|
141 | |
|
|
142 | #if USE_CHAR_CLASSIFIERS |
|
|
143 | #include <ctype.h> |
|
|
144 | #else |
135 | |
145 | |
136 | static char |
146 | static char |
137 | xtoupper (char c) |
147 | xtoupper (char c) |
138 | { |
148 | { |
139 | if (c >= 'a' && c <= 'z') |
149 | if (c >= 'a' && c <= 'z') |
… | |
… | |
159 | |
169 | |
160 | #define toupper(c) xtoupper (c) |
170 | #define toupper(c) xtoupper (c) |
161 | #define tolower(c) xtolower (c) |
171 | #define tolower(c) xtolower (c) |
162 | #define isdigit(c) xisdigit (c) |
172 | #define isdigit(c) xisdigit (c) |
163 | |
173 | |
|
|
174 | #endif |
|
|
175 | |
164 | #if USE_IGNORECASE |
176 | #if USE_IGNORECASE |
165 | static const char * |
177 | ecb_cold static const char * |
166 | xstrlwr (char *s) |
178 | xstrlwr (char *s) |
167 | { |
179 | { |
168 | const char *p = s; |
180 | const char *p = s; |
169 | |
181 | |
170 | while (*s) |
182 | while (*s) |
… | |
… | |
183 | # define stricmp(a,b) strcmp (a, b) |
195 | # define stricmp(a,b) strcmp (a, b) |
184 | # define strlwr(s) (s) |
196 | # define strlwr(s) (s) |
185 | #endif |
197 | #endif |
186 | |
198 | |
187 | #ifndef prompt |
199 | #ifndef prompt |
188 | # define prompt "ts> " |
200 | # define prompt "ms> " |
189 | #endif |
201 | #endif |
190 | |
202 | |
191 | #ifndef InitFile |
203 | #ifndef InitFile |
192 | # define InitFile "init.scm" |
204 | # define InitFile "init.scm" |
193 | #endif |
205 | #endif |
194 | |
206 | |
195 | enum scheme_types |
207 | enum scheme_types |
196 | { |
208 | { |
197 | T_INTEGER, |
209 | T_INTEGER, |
|
|
210 | T_CHARACTER, |
198 | T_REAL, |
211 | T_REAL, |
199 | T_STRING, |
212 | T_STRING, |
200 | T_SYMBOL, |
213 | T_SYMBOL, |
201 | T_PROC, |
214 | T_PROC, |
202 | T_PAIR, /* also used for free cells */ |
215 | T_PAIR, /* also used for free cells */ |
203 | T_CLOSURE, |
216 | T_CLOSURE, |
|
|
217 | T_BYTECODE, // temp |
|
|
218 | T_MACRO, |
204 | T_CONTINUATION, |
219 | T_CONTINUATION, |
205 | T_FOREIGN, |
220 | T_FOREIGN, |
206 | T_CHARACTER, |
|
|
207 | T_PORT, |
221 | T_PORT, |
208 | T_VECTOR, |
222 | T_VECTOR, |
209 | T_MACRO, |
|
|
210 | T_PROMISE, |
223 | T_PROMISE, |
211 | T_ENVIRONMENT, |
224 | T_ENVIRONMENT, |
212 | /* one more... */ |
225 | |
213 | T_NUM_SYSTEM_TYPES |
226 | T_NUM_SYSTEM_TYPES |
214 | }; |
227 | }; |
215 | |
228 | |
216 | #define T_MASKTYPE 0x000f |
229 | #define T_MASKTYPE 0x000f |
217 | #define T_SYNTAX 0x0010 |
230 | #define T_SYNTAX 0x0010 |
… | |
… | |
520 | proper list: length |
533 | proper list: length |
521 | circular list: -1 |
534 | circular list: -1 |
522 | not even a pair: -2 |
535 | not even a pair: -2 |
523 | dotted list: -2 minus length before dot |
536 | dotted list: -2 minus length before dot |
524 | */ |
537 | */ |
525 | INTERFACE int |
538 | ecb_hot INTERFACE int |
526 | list_length (SCHEME_P_ pointer a) |
539 | list_length (SCHEME_P_ pointer a) |
527 | { |
540 | { |
528 | int i = 0; |
541 | int i = 0; |
529 | pointer slow, fast; |
542 | pointer slow, fast; |
530 | |
543 | |
… | |
… | |
569 | { |
582 | { |
570 | return list_length (SCHEME_A_ a) >= 0; |
583 | return list_length (SCHEME_A_ a) >= 0; |
571 | } |
584 | } |
572 | |
585 | |
573 | #if USE_CHAR_CLASSIFIERS |
586 | #if USE_CHAR_CLASSIFIERS |
|
|
587 | |
574 | ecb_inline int |
588 | ecb_inline int |
575 | Cisalpha (int c) |
589 | Cisalpha (int c) |
576 | { |
590 | { |
577 | return isascii (c) && isalpha (c); |
591 | return isascii (c) && isalpha (c); |
578 | } |
592 | } |
… | |
… | |
636 | "gs", |
650 | "gs", |
637 | "rs", |
651 | "rs", |
638 | "us" |
652 | "us" |
639 | }; |
653 | }; |
640 | |
654 | |
641 | static int |
655 | ecb_cold static int |
642 | is_ascii_name (const char *name, int *pc) |
656 | is_ascii_name (const char *name, int *pc) |
643 | { |
657 | { |
644 | int i; |
658 | int i; |
645 | |
659 | |
646 | for (i = 0; i < 32; i++) |
660 | for (i = 0; i < 32; i++) |
… | |
… | |
668 | static int file_interactive (SCHEME_P); |
682 | static int file_interactive (SCHEME_P); |
669 | ecb_inline int is_one_of (const char *s, int c); |
683 | ecb_inline int is_one_of (const char *s, int c); |
670 | static int alloc_cellseg (SCHEME_P); |
684 | static int alloc_cellseg (SCHEME_P); |
671 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
685 | ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); |
672 | static void finalize_cell (SCHEME_P_ pointer a); |
686 | static void finalize_cell (SCHEME_P_ pointer a); |
673 | static int count_consecutive_cells (pointer x, int needed); |
|
|
674 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
687 | static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); |
675 | static pointer mk_number (SCHEME_P_ const num n); |
688 | static pointer mk_number (SCHEME_P_ const num n); |
676 | static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill); |
689 | static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill); |
677 | static pointer mk_vector (SCHEME_P_ uint32_t len); |
690 | static pointer mk_vector (SCHEME_P_ uint32_t len); |
678 | static pointer mk_atom (SCHEME_P_ char *q); |
691 | static pointer mk_atom (SCHEME_P_ char *q); |
679 | static pointer mk_sharp_const (SCHEME_P_ char *name); |
692 | static pointer mk_sharp_const (SCHEME_P_ char *name); |
680 | |
693 | |
|
|
694 | static pointer mk_port (SCHEME_P_ port *p); |
|
|
695 | |
681 | #if USE_PORTS |
696 | #if USE_PORTS |
682 | static pointer mk_port (SCHEME_P_ port *p); |
|
|
683 | static pointer port_from_filename (SCHEME_P_ const char *fn, int prop); |
697 | static pointer port_from_filename (SCHEME_P_ const char *fn, int prop); |
684 | static pointer port_from_file (SCHEME_P_ int, int prop); |
698 | static pointer port_from_file (SCHEME_P_ int, int prop); |
685 | static pointer port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); |
699 | static pointer port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); |
686 | static port *port_rep_from_filename (SCHEME_P_ const char *fn, int prop); |
700 | static port *port_rep_from_filename (SCHEME_P_ const char *fn, int prop); |
687 | static port *port_rep_from_file (SCHEME_P_ int, int prop); |
701 | static port *port_rep_from_file (SCHEME_P_ int, int prop); |
688 | static port *port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); |
702 | static port *port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); |
689 | static void port_close (SCHEME_P_ pointer p, int flag); |
703 | static void port_close (SCHEME_P_ pointer p, int flag); |
690 | #endif |
704 | #endif |
|
|
705 | |
691 | static void mark (pointer a); |
706 | static void mark (pointer a); |
692 | static void gc (SCHEME_P_ pointer a, pointer b); |
707 | static void gc (SCHEME_P_ pointer a, pointer b); |
693 | static int basic_inchar (port *pt); |
708 | static int basic_inchar (port *pt); |
694 | static int inchar (SCHEME_P); |
709 | static int inchar (SCHEME_P); |
695 | static void backchar (SCHEME_P_ int c); |
710 | static void backchar (SCHEME_P_ int c); |
696 | static char *readstr_upto (SCHEME_P_ int skip, const char *delim); |
711 | static char *readstr_upto (SCHEME_P_ int skip, const char *delim); |
697 | static pointer readstrexp (SCHEME_P_ char delim); |
712 | static pointer readstrexp (SCHEME_P_ char delim); |
698 | ecb_inline int skipspace (SCHEME_P); |
713 | static int skipspace (SCHEME_P); |
699 | static int token (SCHEME_P); |
714 | static int token (SCHEME_P); |
700 | static void printslashstring (SCHEME_P_ char *s, int len); |
715 | static void printslashstring (SCHEME_P_ char *s, int len); |
701 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
716 | static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); |
702 | static void printatom (SCHEME_P_ pointer l, int f); |
717 | static void printatom (SCHEME_P_ pointer l, int f); |
703 | static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op); |
718 | static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op); |
… | |
… | |
883 | #endif |
898 | #endif |
884 | #endif |
899 | #endif |
885 | } |
900 | } |
886 | |
901 | |
887 | /* allocate new cell segment */ |
902 | /* allocate new cell segment */ |
888 | static int |
903 | ecb_cold static int |
889 | alloc_cellseg (SCHEME_P) |
904 | alloc_cellseg (SCHEME_P) |
890 | { |
905 | { |
891 | struct cell *newp; |
906 | struct cell *newp; |
892 | struct cell *last; |
907 | struct cell *last; |
893 | struct cell *p; |
908 | struct cell *p; |
… | |
… | |
902 | |
917 | |
903 | if (!cp && USE_ERROR_CHECKING) |
918 | if (!cp && USE_ERROR_CHECKING) |
904 | return k; |
919 | return k; |
905 | |
920 | |
906 | i = ++SCHEME_V->last_cell_seg; |
921 | i = ++SCHEME_V->last_cell_seg; |
907 | SCHEME_V->alloc_seg[i] = cp; |
|
|
908 | |
922 | |
909 | newp = (struct cell *)cp; |
923 | newp = (struct cell *)cp; |
910 | SCHEME_V->cell_seg[i] = newp; |
924 | SCHEME_V->cell_seg[i] = newp; |
911 | SCHEME_V->cell_segsize[i] = segsize; |
925 | SCHEME_V->cell_segsize[i] = segsize; |
912 | SCHEME_V->fcells += segsize; |
926 | SCHEME_V->fcells += segsize; |
… | |
… | |
935 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
949 | if (SCHEME_V->no_memory && USE_ERROR_CHECKING) |
936 | return S_SINK; |
950 | return S_SINK; |
937 | |
951 | |
938 | if (SCHEME_V->free_cell == NIL) |
952 | if (SCHEME_V->free_cell == NIL) |
939 | { |
953 | { |
940 | const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 1; |
954 | const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 2; |
941 | |
955 | |
942 | gc (SCHEME_A_ a, b); |
956 | gc (SCHEME_A_ a, b); |
943 | |
957 | |
944 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
958 | if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) |
945 | { |
959 | { |
… | |
… | |
964 | } |
978 | } |
965 | } |
979 | } |
966 | |
980 | |
967 | /* To retain recent allocs before interpreter knows about them - |
981 | /* To retain recent allocs before interpreter knows about them - |
968 | Tehom */ |
982 | Tehom */ |
969 | static void |
983 | ecb_hot static void |
970 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
984 | push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) |
971 | { |
985 | { |
972 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
986 | pointer holder = get_cell_x (SCHEME_A_ recent, extra); |
973 | |
987 | |
974 | set_typeflag (holder, T_PAIR); |
988 | set_typeflag (holder, T_PAIR); |
… | |
… | |
976 | set_car (holder, recent); |
990 | set_car (holder, recent); |
977 | set_cdr (holder, car (S_SINK)); |
991 | set_cdr (holder, car (S_SINK)); |
978 | set_car (S_SINK, holder); |
992 | set_car (S_SINK, holder); |
979 | } |
993 | } |
980 | |
994 | |
981 | static pointer |
995 | ecb_hot static pointer |
982 | get_cell (SCHEME_P_ pointer a, pointer b) |
996 | get_cell (SCHEME_P_ pointer a, pointer b) |
983 | { |
997 | { |
984 | pointer cell = get_cell_x (SCHEME_A_ a, b); |
998 | pointer cell = get_cell_x (SCHEME_A_ a, b); |
985 | |
999 | |
986 | /* For right now, include "a" and "b" in "cell" so that gc doesn't |
1000 | /* For right now, include "a" and "b" in "cell" so that gc doesn't |
… | |
… | |
1043 | #endif |
1057 | #endif |
1044 | |
1058 | |
1045 | /* Medium level cell allocation */ |
1059 | /* Medium level cell allocation */ |
1046 | |
1060 | |
1047 | /* get new cons cell */ |
1061 | /* get new cons cell */ |
1048 | pointer |
1062 | ecb_hot static pointer |
1049 | xcons (SCHEME_P_ pointer a, pointer b, int immutable) |
1063 | xcons (SCHEME_P_ pointer a, pointer b) |
1050 | { |
1064 | { |
1051 | pointer x = get_cell (SCHEME_A_ a, b); |
1065 | pointer x = get_cell (SCHEME_A_ a, b); |
1052 | |
1066 | |
1053 | set_typeflag (x, T_PAIR); |
1067 | set_typeflag (x, T_PAIR); |
1054 | |
|
|
1055 | if (immutable) |
|
|
1056 | setimmutable (x); |
|
|
1057 | |
1068 | |
1058 | set_car (x, a); |
1069 | set_car (x, a); |
1059 | set_cdr (x, b); |
1070 | set_cdr (x, b); |
1060 | |
1071 | |
1061 | return x; |
1072 | return x; |
1062 | } |
1073 | } |
1063 | |
1074 | |
1064 | static pointer |
1075 | ecb_hot static pointer |
|
|
1076 | ximmutable_cons (SCHEME_P_ pointer a, pointer b) |
|
|
1077 | { |
|
|
1078 | pointer x = xcons (SCHEME_A_ a, b); |
|
|
1079 | setimmutable (x); |
|
|
1080 | return x; |
|
|
1081 | } |
|
|
1082 | |
|
|
1083 | #define cons(a,b) xcons (SCHEME_A_ a, b) |
|
|
1084 | #define immutable_cons(a,b) ximmutable_cons (SCHEME_A_ a, b) |
|
|
1085 | |
|
|
1086 | ecb_cold static pointer |
1065 | generate_symbol (SCHEME_P_ const char *name) |
1087 | generate_symbol (SCHEME_P_ const char *name) |
1066 | { |
1088 | { |
1067 | pointer x = mk_string (SCHEME_A_ name); |
1089 | pointer x = mk_string (SCHEME_A_ name); |
1068 | setimmutable (x); |
1090 | setimmutable (x); |
1069 | set_typeflag (x, T_SYMBOL | T_ATOM); |
1091 | set_typeflag (x, T_SYMBOL | T_ATOM); |
… | |
… | |
1075 | #ifndef USE_OBJECT_LIST |
1097 | #ifndef USE_OBJECT_LIST |
1076 | |
1098 | |
1077 | static int |
1099 | static int |
1078 | hash_fn (const char *key, int table_size) |
1100 | hash_fn (const char *key, int table_size) |
1079 | { |
1101 | { |
1080 | const unsigned char *p = key; |
1102 | const unsigned char *p = (unsigned char *)key; |
1081 | uint32_t hash = 2166136261; |
1103 | uint32_t hash = 2166136261U; |
1082 | |
1104 | |
1083 | while (*p) |
1105 | while (*p) |
1084 | hash = (hash ^ *p++) * 16777619; |
1106 | hash = (hash ^ *p++) * 16777619; |
1085 | |
1107 | |
1086 | return hash % table_size; |
1108 | return hash % table_size; |
1087 | } |
1109 | } |
1088 | |
1110 | |
1089 | static pointer |
1111 | ecb_cold static pointer |
1090 | oblist_initial_value (SCHEME_P) |
1112 | oblist_initial_value (SCHEME_P) |
1091 | { |
1113 | { |
1092 | return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ |
1114 | return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ |
1093 | } |
1115 | } |
1094 | |
1116 | |
1095 | /* returns the new symbol */ |
1117 | /* returns the new symbol */ |
1096 | static pointer |
1118 | ecb_cold static pointer |
1097 | oblist_add_by_name (SCHEME_P_ const char *name) |
1119 | oblist_add_by_name (SCHEME_P_ const char *name) |
1098 | { |
1120 | { |
1099 | pointer x = generate_symbol (SCHEME_A_ name); |
1121 | pointer x = generate_symbol (SCHEME_A_ name); |
1100 | int location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1122 | int location = hash_fn (name, veclength (SCHEME_V->oblist)); |
1101 | vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location))); |
1123 | vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location))); |
1102 | return x; |
1124 | return x; |
1103 | } |
1125 | } |
1104 | |
1126 | |
1105 | ecb_inline pointer |
1127 | ecb_cold static pointer |
1106 | oblist_find_by_name (SCHEME_P_ const char *name) |
1128 | oblist_find_by_name (SCHEME_P_ const char *name) |
1107 | { |
1129 | { |
1108 | int location; |
1130 | int location; |
1109 | pointer x; |
1131 | pointer x; |
1110 | char *s; |
1132 | char *s; |
… | |
… | |
1121 | } |
1143 | } |
1122 | |
1144 | |
1123 | return NIL; |
1145 | return NIL; |
1124 | } |
1146 | } |
1125 | |
1147 | |
1126 | static pointer |
1148 | ecb_cold static pointer |
1127 | oblist_all_symbols (SCHEME_P) |
1149 | oblist_all_symbols (SCHEME_P) |
1128 | { |
1150 | { |
1129 | int i; |
1151 | int i; |
1130 | pointer x; |
1152 | pointer x; |
1131 | pointer ob_list = NIL; |
1153 | pointer ob_list = NIL; |
… | |
… | |
1137 | return ob_list; |
1159 | return ob_list; |
1138 | } |
1160 | } |
1139 | |
1161 | |
1140 | #else |
1162 | #else |
1141 | |
1163 | |
1142 | static pointer |
1164 | ecb_cold static pointer |
1143 | oblist_initial_value (SCHEME_P) |
1165 | oblist_initial_value (SCHEME_P) |
1144 | { |
1166 | { |
1145 | return NIL; |
1167 | return NIL; |
1146 | } |
1168 | } |
1147 | |
1169 | |
1148 | ecb_inline pointer |
1170 | ecb_cold static pointer |
1149 | oblist_find_by_name (SCHEME_P_ const char *name) |
1171 | oblist_find_by_name (SCHEME_P_ const char *name) |
1150 | { |
1172 | { |
1151 | pointer x; |
1173 | pointer x; |
1152 | char *s; |
1174 | char *s; |
1153 | |
1175 | |
… | |
… | |
1162 | |
1184 | |
1163 | return NIL; |
1185 | return NIL; |
1164 | } |
1186 | } |
1165 | |
1187 | |
1166 | /* returns the new symbol */ |
1188 | /* returns the new symbol */ |
1167 | static pointer |
1189 | ecb_cold static pointer |
1168 | oblist_add_by_name (SCHEME_P_ const char *name) |
1190 | oblist_add_by_name (SCHEME_P_ const char *name) |
1169 | { |
1191 | { |
1170 | pointer x = generate_symbol (SCHEME_A_ name); |
1192 | pointer x = generate_symbol (SCHEME_A_ name); |
1171 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1193 | SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); |
1172 | return x; |
1194 | return x; |
1173 | } |
1195 | } |
1174 | |
1196 | |
1175 | static pointer |
1197 | ecb_cold static pointer |
1176 | oblist_all_symbols (SCHEME_P) |
1198 | oblist_all_symbols (SCHEME_P) |
1177 | { |
1199 | { |
1178 | return SCHEME_V->oblist; |
1200 | return SCHEME_V->oblist; |
1179 | } |
1201 | } |
1180 | |
1202 | |
1181 | #endif |
1203 | #endif |
1182 | |
1204 | |
1183 | #if USE_PORTS |
|
|
1184 | static pointer |
1205 | ecb_cold static pointer |
1185 | mk_port (SCHEME_P_ port *p) |
1206 | mk_port (SCHEME_P_ port *p) |
1186 | { |
1207 | { |
1187 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1208 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1188 | |
1209 | |
1189 | set_typeflag (x, T_PORT | T_ATOM); |
1210 | set_typeflag (x, T_PORT | T_ATOM); |
1190 | set_port (x, p); |
1211 | set_port (x, p); |
1191 | |
1212 | |
1192 | return x; |
1213 | return x; |
1193 | } |
1214 | } |
1194 | #endif |
|
|
1195 | |
1215 | |
1196 | pointer |
1216 | ecb_cold pointer |
1197 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1217 | mk_foreign_func (SCHEME_P_ foreign_func f) |
1198 | { |
1218 | { |
1199 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1219 | pointer x = get_cell (SCHEME_A_ NIL, NIL); |
1200 | |
1220 | |
1201 | set_typeflag (x, T_FOREIGN | T_ATOM); |
1221 | set_typeflag (x, T_FOREIGN | T_ATOM); |
… | |
… | |
1366 | x = oblist_add_by_name (SCHEME_A_ name); |
1386 | x = oblist_add_by_name (SCHEME_A_ name); |
1367 | |
1387 | |
1368 | return x; |
1388 | return x; |
1369 | } |
1389 | } |
1370 | |
1390 | |
1371 | INTERFACE pointer |
1391 | ecb_cold INTERFACE pointer |
1372 | gensym (SCHEME_P) |
1392 | gensym (SCHEME_P) |
1373 | { |
1393 | { |
1374 | pointer x; |
1394 | pointer x; |
1375 | char name[40] = "gensym-"; |
1395 | char name[40] = "gensym-"; |
1376 | xnum (name + 7, ++SCHEME_V->gensym_cnt); |
1396 | xnum (name + 7, ++SCHEME_V->gensym_cnt); |
… | |
… | |
1383 | { |
1403 | { |
1384 | return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x; |
1404 | return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x; |
1385 | } |
1405 | } |
1386 | |
1406 | |
1387 | /* make symbol or number atom from string */ |
1407 | /* make symbol or number atom from string */ |
1388 | static pointer |
1408 | ecb_cold static pointer |
1389 | mk_atom (SCHEME_P_ char *q) |
1409 | mk_atom (SCHEME_P_ char *q) |
1390 | { |
1410 | { |
1391 | char c, *p; |
1411 | char c, *p; |
1392 | int has_dec_point = 0; |
1412 | int has_dec_point = 0; |
1393 | int has_fp_exp = 0; |
1413 | int has_fp_exp = 0; |
… | |
… | |
1464 | |
1484 | |
1465 | return mk_integer (SCHEME_A_ strtol (q, 0, 10)); |
1485 | return mk_integer (SCHEME_A_ strtol (q, 0, 10)); |
1466 | } |
1486 | } |
1467 | |
1487 | |
1468 | /* make constant */ |
1488 | /* make constant */ |
1469 | static pointer |
1489 | ecb_cold static pointer |
1470 | mk_sharp_const (SCHEME_P_ char *name) |
1490 | mk_sharp_const (SCHEME_P_ char *name) |
1471 | { |
1491 | { |
1472 | if (!strcmp (name, "t")) |
1492 | if (!strcmp (name, "t")) |
1473 | return S_T; |
1493 | return S_T; |
1474 | else if (!strcmp (name, "f")) |
1494 | else if (!strcmp (name, "f")) |
… | |
… | |
1529 | } |
1549 | } |
1530 | } |
1550 | } |
1531 | |
1551 | |
1532 | /* ========== garbage collector ========== */ |
1552 | /* ========== garbage collector ========== */ |
1533 | |
1553 | |
|
|
1554 | static void |
|
|
1555 | finalize_cell (SCHEME_P_ pointer a) |
|
|
1556 | { |
|
|
1557 | /* TODO, fast bitmap check? */ |
|
|
1558 | if (is_string (a) || is_symbol (a)) |
|
|
1559 | free (strvalue (a)); |
|
|
1560 | else if (is_vector (a)) |
|
|
1561 | free (vecvalue (a)); |
|
|
1562 | #if USE_PORTS |
|
|
1563 | else if (is_port (a)) |
|
|
1564 | { |
|
|
1565 | if (port(a)->kind & port_file && port (a)->rep.stdio.closeit) |
|
|
1566 | port_close (SCHEME_A_ a, port_input | port_output); |
|
|
1567 | |
|
|
1568 | free (port (a)); |
|
|
1569 | } |
|
|
1570 | #endif |
|
|
1571 | } |
|
|
1572 | |
1534 | /*-- |
1573 | /*-- |
1535 | * We use algorithm E (Knuth, The Art of Computer Programming Vol.1, |
1574 | * We use algorithm E (Knuth, The Art of Computer Programming Vol.1, |
1536 | * sec. 2.3.5), the Schorr-Deutsch-Waite link-inversion algorithm, |
1575 | * sec. 2.3.5), the Schorr-Deutsch-Waite link-inversion algorithm, |
1537 | * for marking. |
1576 | * for marking. |
1538 | * |
1577 | * |
1539 | * The exception is vectors - vectors are currently marked recursively, |
1578 | * The exception is vectors - vectors are currently marked recursively, |
1540 | * which is inherited form tinyscheme and could be fixed by having another |
1579 | * which is inherited form tinyscheme and could be fixed by having another |
1541 | * word of context in the vector |
1580 | * word of context in the vector |
1542 | */ |
1581 | */ |
1543 | static void |
1582 | ecb_hot static void |
1544 | mark (pointer a) |
1583 | mark (pointer a) |
1545 | { |
1584 | { |
1546 | pointer t, q, p; |
1585 | pointer t, q, p; |
1547 | |
1586 | |
1548 | t = 0; |
1587 | t = 0; |
… | |
… | |
1605 | p = q; |
1644 | p = q; |
1606 | goto E6; |
1645 | goto E6; |
1607 | } |
1646 | } |
1608 | } |
1647 | } |
1609 | |
1648 | |
1610 | /* garbage collection. parameter a, b is marked. */ |
1649 | ecb_hot static void |
1611 | static void |
1650 | gc_free (SCHEME_P) |
1612 | gc (SCHEME_P_ pointer a, pointer b) |
|
|
1613 | { |
1651 | { |
1614 | int i; |
1652 | int i; |
1615 | |
|
|
1616 | if (SCHEME_V->gc_verbose) |
|
|
1617 | putstr (SCHEME_A_ "gc..."); |
|
|
1618 | |
|
|
1619 | /* mark system globals */ |
|
|
1620 | mark (SCHEME_V->oblist); |
|
|
1621 | mark (SCHEME_V->global_env); |
|
|
1622 | |
|
|
1623 | /* mark current registers */ |
|
|
1624 | mark (SCHEME_V->args); |
|
|
1625 | mark (SCHEME_V->envir); |
|
|
1626 | mark (SCHEME_V->code); |
|
|
1627 | dump_stack_mark (SCHEME_A); |
|
|
1628 | mark (SCHEME_V->value); |
|
|
1629 | mark (SCHEME_V->inport); |
|
|
1630 | mark (SCHEME_V->save_inport); |
|
|
1631 | mark (SCHEME_V->outport); |
|
|
1632 | mark (SCHEME_V->loadport); |
|
|
1633 | |
|
|
1634 | /* Mark recent objects the interpreter doesn't know about yet. */ |
|
|
1635 | mark (car (S_SINK)); |
|
|
1636 | /* Mark any older stuff above nested C calls */ |
|
|
1637 | mark (SCHEME_V->c_nest); |
|
|
1638 | |
|
|
1639 | #if USE_INTCACHE |
|
|
1640 | /* mark intcache */ |
|
|
1641 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1642 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1643 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
|
|
1644 | #endif |
|
|
1645 | |
|
|
1646 | /* mark variables a, b */ |
|
|
1647 | mark (a); |
|
|
1648 | mark (b); |
|
|
1649 | |
|
|
1650 | /* garbage collect */ |
|
|
1651 | clrmark (NIL); |
|
|
1652 | SCHEME_V->fcells = 0; |
|
|
1653 | SCHEME_V->free_cell = NIL; |
|
|
1654 | |
|
|
1655 | if (SCHEME_V->gc_verbose) |
|
|
1656 | putstr (SCHEME_A_ "freeing..."); |
|
|
1657 | |
|
|
1658 | uint32_t total = 0; |
1653 | uint32_t total = 0; |
1659 | |
1654 | |
1660 | /* Here we scan the cells to build the free-list. */ |
1655 | /* Here we scan the cells to build the free-list. */ |
1661 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1656 | for (i = SCHEME_V->last_cell_seg; i >= 0; i--) |
1662 | { |
1657 | { |
… | |
… | |
1691 | { |
1686 | { |
1692 | putstr (SCHEME_A_ "done: "); putnum (SCHEME_A_ SCHEME_V->fcells); putstr (SCHEME_A_ " out of "); putnum (SCHEME_A_ total); putstr (SCHEME_A_ " cells were recovered.\n"); |
1687 | putstr (SCHEME_A_ "done: "); putnum (SCHEME_A_ SCHEME_V->fcells); putstr (SCHEME_A_ " out of "); putnum (SCHEME_A_ total); putstr (SCHEME_A_ " cells were recovered.\n"); |
1693 | } |
1688 | } |
1694 | } |
1689 | } |
1695 | |
1690 | |
1696 | static void |
1691 | /* garbage collection. parameter a, b is marked. */ |
1697 | finalize_cell (SCHEME_P_ pointer a) |
1692 | ecb_cold static void |
|
|
1693 | gc (SCHEME_P_ pointer a, pointer b) |
1698 | { |
1694 | { |
1699 | /* TODO, fast bitmap check? */ |
1695 | int i; |
1700 | if (is_string (a) || is_symbol (a)) |
|
|
1701 | free (strvalue (a)); |
|
|
1702 | else if (is_vector (a)) |
|
|
1703 | free (vecvalue (a)); |
|
|
1704 | #if USE_PORTS |
|
|
1705 | else if (is_port (a)) |
|
|
1706 | { |
|
|
1707 | if (port(a)->kind & port_file && port (a)->rep.stdio.closeit) |
|
|
1708 | port_close (SCHEME_A_ a, port_input | port_output); |
|
|
1709 | |
1696 | |
1710 | free (port (a)); |
1697 | if (SCHEME_V->gc_verbose) |
1711 | } |
1698 | putstr (SCHEME_A_ "gc..."); |
|
|
1699 | |
|
|
1700 | /* mark system globals */ |
|
|
1701 | mark (SCHEME_V->oblist); |
|
|
1702 | mark (SCHEME_V->global_env); |
|
|
1703 | |
|
|
1704 | /* mark current registers */ |
|
|
1705 | mark (SCHEME_V->args); |
|
|
1706 | mark (SCHEME_V->envir); |
|
|
1707 | mark (SCHEME_V->code); |
|
|
1708 | dump_stack_mark (SCHEME_A); |
|
|
1709 | mark (SCHEME_V->value); |
|
|
1710 | mark (SCHEME_V->inport); |
|
|
1711 | mark (SCHEME_V->save_inport); |
|
|
1712 | mark (SCHEME_V->outport); |
|
|
1713 | mark (SCHEME_V->loadport); |
|
|
1714 | |
|
|
1715 | /* Mark recent objects the interpreter doesn't know about yet. */ |
|
|
1716 | mark (car (S_SINK)); |
|
|
1717 | /* Mark any older stuff above nested C calls */ |
|
|
1718 | mark (SCHEME_V->c_nest); |
|
|
1719 | |
|
|
1720 | #if USE_INTCACHE |
|
|
1721 | /* mark intcache */ |
|
|
1722 | for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i) |
|
|
1723 | if (SCHEME_V->intcache[i - INTCACHE_MIN]) |
|
|
1724 | mark (SCHEME_V->intcache[i - INTCACHE_MIN]); |
1712 | #endif |
1725 | #endif |
|
|
1726 | |
|
|
1727 | /* mark variables a, b */ |
|
|
1728 | mark (a); |
|
|
1729 | mark (b); |
|
|
1730 | |
|
|
1731 | /* garbage collect */ |
|
|
1732 | clrmark (NIL); |
|
|
1733 | SCHEME_V->fcells = 0; |
|
|
1734 | SCHEME_V->free_cell = NIL; |
|
|
1735 | |
|
|
1736 | if (SCHEME_V->gc_verbose) |
|
|
1737 | putstr (SCHEME_A_ "freeing..."); |
|
|
1738 | |
|
|
1739 | gc_free (SCHEME_A); |
1713 | } |
1740 | } |
1714 | |
1741 | |
1715 | /* ========== Routines for Reading ========== */ |
1742 | /* ========== Routines for Reading ========== */ |
1716 | |
1743 | |
1717 | static int |
1744 | ecb_cold static int |
1718 | file_push (SCHEME_P_ const char *fname) |
1745 | file_push (SCHEME_P_ const char *fname) |
1719 | { |
1746 | { |
1720 | #if USE_PORTS |
|
|
1721 | int fin; |
1747 | int fin; |
1722 | |
1748 | |
1723 | if (SCHEME_V->file_i == MAXFIL - 1) |
1749 | if (SCHEME_V->file_i == MAXFIL - 1) |
1724 | return 0; |
1750 | return 0; |
1725 | |
1751 | |
… | |
… | |
1742 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.filename = store_string (SCHEME_A_ strlen (fname), fname, 0); |
1768 | SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.filename = store_string (SCHEME_A_ strlen (fname), fname, 0); |
1743 | #endif |
1769 | #endif |
1744 | } |
1770 | } |
1745 | |
1771 | |
1746 | return fin >= 0; |
1772 | return fin >= 0; |
1747 | |
|
|
1748 | #else |
|
|
1749 | return 1; |
|
|
1750 | #endif |
|
|
1751 | } |
1773 | } |
1752 | |
1774 | |
1753 | static void |
1775 | ecb_cold static void |
1754 | file_pop (SCHEME_P) |
1776 | file_pop (SCHEME_P) |
1755 | { |
1777 | { |
1756 | if (SCHEME_V->file_i != 0) |
1778 | if (SCHEME_V->file_i != 0) |
1757 | { |
1779 | { |
1758 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
1780 | SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; |
… | |
… | |
1762 | SCHEME_V->file_i--; |
1784 | SCHEME_V->file_i--; |
1763 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1785 | set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); |
1764 | } |
1786 | } |
1765 | } |
1787 | } |
1766 | |
1788 | |
1767 | static int |
1789 | ecb_cold static int |
1768 | file_interactive (SCHEME_P) |
1790 | file_interactive (SCHEME_P) |
1769 | { |
1791 | { |
1770 | #if USE_PORTS |
1792 | #if USE_PORTS |
1771 | return SCHEME_V->file_i == 0 |
1793 | return SCHEME_V->file_i == 0 |
1772 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
1794 | && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO |
… | |
… | |
1775 | return 0; |
1797 | return 0; |
1776 | #endif |
1798 | #endif |
1777 | } |
1799 | } |
1778 | |
1800 | |
1779 | #if USE_PORTS |
1801 | #if USE_PORTS |
1780 | static port * |
1802 | ecb_cold static port * |
1781 | port_rep_from_filename (SCHEME_P_ const char *fn, int prop) |
1803 | port_rep_from_filename (SCHEME_P_ const char *fn, int prop) |
1782 | { |
1804 | { |
1783 | int fd; |
1805 | int fd; |
1784 | int flags; |
1806 | int flags; |
1785 | char *rw; |
1807 | char *rw; |
… | |
… | |
1808 | # endif |
1830 | # endif |
1809 | |
1831 | |
1810 | return pt; |
1832 | return pt; |
1811 | } |
1833 | } |
1812 | |
1834 | |
1813 | static pointer |
1835 | ecb_cold static pointer |
1814 | port_from_filename (SCHEME_P_ const char *fn, int prop) |
1836 | port_from_filename (SCHEME_P_ const char *fn, int prop) |
1815 | { |
1837 | { |
1816 | port *pt = port_rep_from_filename (SCHEME_A_ fn, prop); |
1838 | port *pt = port_rep_from_filename (SCHEME_A_ fn, prop); |
1817 | |
1839 | |
1818 | if (!pt && USE_ERROR_CHECKING) |
1840 | if (!pt && USE_ERROR_CHECKING) |
1819 | return NIL; |
1841 | return NIL; |
1820 | |
1842 | |
1821 | return mk_port (SCHEME_A_ pt); |
1843 | return mk_port (SCHEME_A_ pt); |
1822 | } |
1844 | } |
1823 | |
1845 | |
1824 | static port * |
1846 | ecb_cold static port * |
1825 | port_rep_from_file (SCHEME_P_ int f, int prop) |
1847 | port_rep_from_file (SCHEME_P_ int f, int prop) |
1826 | { |
1848 | { |
1827 | port *pt = malloc (sizeof *pt); |
1849 | port *pt = malloc (sizeof *pt); |
1828 | |
1850 | |
1829 | if (!pt && USE_ERROR_CHECKING) |
1851 | if (!pt && USE_ERROR_CHECKING) |
… | |
… | |
1834 | pt->rep.stdio.file = f; |
1856 | pt->rep.stdio.file = f; |
1835 | pt->rep.stdio.closeit = 0; |
1857 | pt->rep.stdio.closeit = 0; |
1836 | return pt; |
1858 | return pt; |
1837 | } |
1859 | } |
1838 | |
1860 | |
1839 | static pointer |
1861 | ecb_cold static pointer |
1840 | port_from_file (SCHEME_P_ int f, int prop) |
1862 | port_from_file (SCHEME_P_ int f, int prop) |
1841 | { |
1863 | { |
1842 | port *pt = port_rep_from_file (SCHEME_A_ f, prop); |
1864 | port *pt = port_rep_from_file (SCHEME_A_ f, prop); |
1843 | |
1865 | |
1844 | if (!pt && USE_ERROR_CHECKING) |
1866 | if (!pt && USE_ERROR_CHECKING) |
1845 | return NIL; |
1867 | return NIL; |
1846 | |
1868 | |
1847 | return mk_port (SCHEME_A_ pt); |
1869 | return mk_port (SCHEME_A_ pt); |
1848 | } |
1870 | } |
1849 | |
1871 | |
1850 | static port * |
1872 | ecb_cold static port * |
1851 | port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) |
1873 | port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) |
1852 | { |
1874 | { |
1853 | port *pt = malloc (sizeof (port)); |
1875 | port *pt = malloc (sizeof (port)); |
1854 | |
1876 | |
1855 | if (!pt && USE_ERROR_CHECKING) |
1877 | if (!pt && USE_ERROR_CHECKING) |
… | |
… | |
1861 | pt->rep.string.curr = start; |
1883 | pt->rep.string.curr = start; |
1862 | pt->rep.string.past_the_end = past_the_end; |
1884 | pt->rep.string.past_the_end = past_the_end; |
1863 | return pt; |
1885 | return pt; |
1864 | } |
1886 | } |
1865 | |
1887 | |
1866 | static pointer |
1888 | ecb_cold static pointer |
1867 | port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) |
1889 | port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) |
1868 | { |
1890 | { |
1869 | port *pt = port_rep_from_string (SCHEME_A_ start, past_the_end, prop); |
1891 | port *pt = port_rep_from_string (SCHEME_A_ start, past_the_end, prop); |
1870 | |
1892 | |
1871 | if (!pt && USE_ERROR_CHECKING) |
1893 | if (!pt && USE_ERROR_CHECKING) |
… | |
… | |
1874 | return mk_port (SCHEME_A_ pt); |
1896 | return mk_port (SCHEME_A_ pt); |
1875 | } |
1897 | } |
1876 | |
1898 | |
1877 | # define BLOCK_SIZE 256 |
1899 | # define BLOCK_SIZE 256 |
1878 | |
1900 | |
1879 | static port * |
1901 | ecb_cold static port * |
1880 | port_rep_from_scratch (SCHEME_P) |
1902 | port_rep_from_scratch (SCHEME_P) |
1881 | { |
1903 | { |
1882 | char *start; |
1904 | char *start; |
1883 | port *pt = malloc (sizeof (port)); |
1905 | port *pt = malloc (sizeof (port)); |
1884 | |
1906 | |
… | |
… | |
1898 | pt->rep.string.curr = start; |
1920 | pt->rep.string.curr = start; |
1899 | pt->rep.string.past_the_end = start + BLOCK_SIZE - 1; |
1921 | pt->rep.string.past_the_end = start + BLOCK_SIZE - 1; |
1900 | return pt; |
1922 | return pt; |
1901 | } |
1923 | } |
1902 | |
1924 | |
1903 | static pointer |
1925 | ecb_cold static pointer |
1904 | port_from_scratch (SCHEME_P) |
1926 | port_from_scratch (SCHEME_P) |
1905 | { |
1927 | { |
1906 | port *pt = port_rep_from_scratch (SCHEME_A); |
1928 | port *pt = port_rep_from_scratch (SCHEME_A); |
1907 | |
1929 | |
1908 | if (!pt && USE_ERROR_CHECKING) |
1930 | if (!pt && USE_ERROR_CHECKING) |
1909 | return NIL; |
1931 | return NIL; |
1910 | |
1932 | |
1911 | return mk_port (SCHEME_A_ pt); |
1933 | return mk_port (SCHEME_A_ pt); |
1912 | } |
1934 | } |
1913 | |
1935 | |
1914 | static void |
1936 | ecb_cold static void |
1915 | port_close (SCHEME_P_ pointer p, int flag) |
1937 | port_close (SCHEME_P_ pointer p, int flag) |
1916 | { |
1938 | { |
1917 | port *pt = port (p); |
1939 | port *pt = port (p); |
1918 | |
1940 | |
1919 | pt->kind &= ~flag; |
1941 | pt->kind &= ~flag; |
… | |
… | |
1939 | } |
1961 | } |
1940 | } |
1962 | } |
1941 | #endif |
1963 | #endif |
1942 | |
1964 | |
1943 | /* get new character from input file */ |
1965 | /* get new character from input file */ |
1944 | static int |
1966 | ecb_cold static int |
1945 | inchar (SCHEME_P) |
1967 | inchar (SCHEME_P) |
1946 | { |
1968 | { |
1947 | int c; |
1969 | int c; |
1948 | port *pt = port (SCHEME_V->inport); |
1970 | port *pt = port (SCHEME_V->inport); |
1949 | |
1971 | |
… | |
… | |
1963 | } |
1985 | } |
1964 | |
1986 | |
1965 | return c; |
1987 | return c; |
1966 | } |
1988 | } |
1967 | |
1989 | |
1968 | static int ungot = -1; |
1990 | ecb_cold static int |
1969 | |
|
|
1970 | static int |
|
|
1971 | basic_inchar (port *pt) |
1991 | basic_inchar (port *pt) |
1972 | { |
1992 | { |
1973 | #if USE_PORTS |
|
|
1974 | if (pt->unget != -1) |
1993 | if (pt->unget != -1) |
1975 | { |
1994 | { |
1976 | int r = pt->unget; |
1995 | int r = pt->unget; |
1977 | pt->unget = -1; |
1996 | pt->unget = -1; |
1978 | return r; |
1997 | return r; |
1979 | } |
1998 | } |
1980 | |
1999 | |
|
|
2000 | #if USE_PORTS |
1981 | if (pt->kind & port_file) |
2001 | if (pt->kind & port_file) |
1982 | { |
2002 | { |
1983 | char c; |
2003 | char c; |
1984 | |
2004 | |
1985 | if (!read (pt->rep.stdio.file, &c, 1)) |
2005 | if (!read (pt->rep.stdio.file, &c, 1)) |
… | |
… | |
1993 | return EOF; |
2013 | return EOF; |
1994 | else |
2014 | else |
1995 | return *pt->rep.string.curr++; |
2015 | return *pt->rep.string.curr++; |
1996 | } |
2016 | } |
1997 | #else |
2017 | #else |
1998 | if (ungot == -1) |
|
|
1999 | { |
|
|
2000 | char c; |
2018 | char c; |
2001 | if (!read (0, &c, 1)) |
2019 | |
|
|
2020 | if (!read (pt->rep.stdio.file, &c, 1)) |
2002 | return EOF; |
2021 | return EOF; |
2003 | |
2022 | |
2004 | ungot = c; |
|
|
2005 | } |
|
|
2006 | |
|
|
2007 | { |
|
|
2008 | int r = ungot; |
|
|
2009 | ungot = -1; |
|
|
2010 | return r; |
2023 | return c; |
2011 | } |
|
|
2012 | #endif |
2024 | #endif |
2013 | } |
2025 | } |
2014 | |
2026 | |
2015 | /* back character to input buffer */ |
2027 | /* back character to input buffer */ |
2016 | static void |
2028 | ecb_cold static void |
2017 | backchar (SCHEME_P_ int c) |
2029 | backchar (SCHEME_P_ int c) |
2018 | { |
2030 | { |
2019 | #if USE_PORTS |
2031 | port *pt = port (SCHEME_V->inport); |
2020 | port *pt; |
|
|
2021 | |
2032 | |
2022 | if (c == EOF) |
2033 | if (c == EOF) |
2023 | return; |
2034 | return; |
2024 | |
2035 | |
2025 | pt = port (SCHEME_V->inport); |
|
|
2026 | pt->unget = c; |
2036 | pt->unget = c; |
2027 | #else |
|
|
2028 | if (c == EOF) |
|
|
2029 | return; |
|
|
2030 | |
|
|
2031 | ungot = c; |
|
|
2032 | #endif |
|
|
2033 | } |
2037 | } |
2034 | |
2038 | |
2035 | #if USE_PORTS |
2039 | #if USE_PORTS |
2036 | static int |
2040 | ecb_cold static int |
2037 | realloc_port_string (SCHEME_P_ port *p) |
2041 | realloc_port_string (SCHEME_P_ port *p) |
2038 | { |
2042 | { |
2039 | char *start = p->rep.string.start; |
2043 | char *start = p->rep.string.start; |
2040 | size_t new_size = p->rep.string.past_the_end - start + 1 + BLOCK_SIZE; |
2044 | size_t new_size = p->rep.string.past_the_end - start + 1 + BLOCK_SIZE; |
2041 | char *str = malloc (new_size); |
2045 | char *str = malloc (new_size); |
… | |
… | |
2054 | else |
2058 | else |
2055 | return 0; |
2059 | return 0; |
2056 | } |
2060 | } |
2057 | #endif |
2061 | #endif |
2058 | |
2062 | |
2059 | INTERFACE void |
2063 | ecb_cold static void |
2060 | putstr (SCHEME_P_ const char *s) |
2064 | putchars (SCHEME_P_ const char *s, int len) |
2061 | { |
2065 | { |
|
|
2066 | port *pt = port (SCHEME_V->outport); |
|
|
2067 | |
2062 | #if USE_PORTS |
2068 | #if USE_PORTS |
2063 | port *pt = port (SCHEME_V->outport); |
|
|
2064 | |
|
|
2065 | if (pt->kind & port_file) |
|
|
2066 | write (pt->rep.stdio.file, s, strlen (s)); |
|
|
2067 | else |
|
|
2068 | for (; *s; s++) |
|
|
2069 | if (pt->rep.string.curr != pt->rep.string.past_the_end) |
|
|
2070 | *pt->rep.string.curr++ = *s; |
|
|
2071 | else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt)) |
|
|
2072 | *pt->rep.string.curr++ = *s; |
|
|
2073 | |
|
|
2074 | #else |
|
|
2075 | write (pt->rep.stdio.file, s, strlen (s)); |
|
|
2076 | #endif |
|
|
2077 | } |
|
|
2078 | |
|
|
2079 | static void |
|
|
2080 | putchars (SCHEME_P_ const char *s, int len) |
|
|
2081 | { |
|
|
2082 | #if USE_PORTS |
|
|
2083 | port *pt = port (SCHEME_V->outport); |
|
|
2084 | |
|
|
2085 | if (pt->kind & port_file) |
2069 | if (pt->kind & port_file) |
2086 | write (pt->rep.stdio.file, s, len); |
2070 | write (pt->rep.stdio.file, s, len); |
2087 | else |
2071 | else |
2088 | { |
2072 | { |
2089 | for (; len; len--) |
2073 | for (; len; len--) |
… | |
… | |
2094 | *pt->rep.string.curr++ = *s++; |
2078 | *pt->rep.string.curr++ = *s++; |
2095 | } |
2079 | } |
2096 | } |
2080 | } |
2097 | |
2081 | |
2098 | #else |
2082 | #else |
2099 | write (1, s, len); |
2083 | write (1, s, len); // output not initialised |
2100 | #endif |
2084 | #endif |
|
|
2085 | } |
|
|
2086 | |
|
|
2087 | INTERFACE void |
|
|
2088 | putstr (SCHEME_P_ const char *s) |
|
|
2089 | { |
|
|
2090 | putchars (SCHEME_A_ s, strlen (s)); |
2101 | } |
2091 | } |
2102 | |
2092 | |
2103 | INTERFACE void |
2093 | INTERFACE void |
2104 | putcharacter (SCHEME_P_ int c) |
2094 | putcharacter (SCHEME_P_ int c) |
2105 | { |
2095 | { |
2106 | #if USE_PORTS |
|
|
2107 | port *pt = port (SCHEME_V->outport); |
|
|
2108 | |
|
|
2109 | if (pt->kind & port_file) |
|
|
2110 | { |
|
|
2111 | char cc = c; |
|
|
2112 | write (pt->rep.stdio.file, &cc, 1); |
|
|
2113 | } |
|
|
2114 | else |
|
|
2115 | { |
|
|
2116 | if (pt->rep.string.curr != pt->rep.string.past_the_end) |
|
|
2117 | *pt->rep.string.curr++ = c; |
|
|
2118 | else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt)) |
|
|
2119 | *pt->rep.string.curr++ = c; |
|
|
2120 | } |
|
|
2121 | |
|
|
2122 | #else |
|
|
2123 | char cc = c; |
2096 | char cc = c; |
2124 | write (1, &c, 1); |
2097 | |
2125 | #endif |
2098 | putchars (SCHEME_A_ &cc, 1); |
2126 | } |
2099 | } |
2127 | |
2100 | |
2128 | /* read characters up to delimiter, but cater to character constants */ |
2101 | /* read characters up to delimiter, but cater to character constants */ |
2129 | static char * |
2102 | ecb_cold static char * |
2130 | readstr_upto (SCHEME_P_ int skip, const char *delim) |
2103 | readstr_upto (SCHEME_P_ int skip, const char *delim) |
2131 | { |
2104 | { |
2132 | char *p = SCHEME_V->strbuff + skip; |
2105 | char *p = SCHEME_V->strbuff + skip; |
2133 | |
2106 | |
2134 | while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); |
2107 | while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); |
… | |
… | |
2143 | |
2116 | |
2144 | return SCHEME_V->strbuff; |
2117 | return SCHEME_V->strbuff; |
2145 | } |
2118 | } |
2146 | |
2119 | |
2147 | /* read string expression "xxx...xxx" */ |
2120 | /* read string expression "xxx...xxx" */ |
2148 | static pointer |
2121 | ecb_cold static pointer |
2149 | readstrexp (SCHEME_P_ char delim) |
2122 | readstrexp (SCHEME_P_ char delim) |
2150 | { |
2123 | { |
2151 | char *p = SCHEME_V->strbuff; |
2124 | char *p = SCHEME_V->strbuff; |
2152 | int c; |
2125 | int c; |
2153 | int c1 = 0; |
2126 | int c1 = 0; |
… | |
… | |
2191 | case 'a': *p++ = '\a'; state = st_ok; break; |
2164 | case 'a': *p++ = '\a'; state = st_ok; break; |
2192 | case 'n': *p++ = '\n'; state = st_ok; break; |
2165 | case 'n': *p++ = '\n'; state = st_ok; break; |
2193 | case 'r': *p++ = '\r'; state = st_ok; break; |
2166 | case 'r': *p++ = '\r'; state = st_ok; break; |
2194 | case 't': *p++ = '\t'; state = st_ok; break; |
2167 | case 't': *p++ = '\t'; state = st_ok; break; |
2195 | |
2168 | |
2196 | //TODO: \whitespace eol whitespace |
2169 | // this overshoots the minimum requirements of r7rs |
|
|
2170 | case ' ': |
|
|
2171 | case '\t': |
|
|
2172 | case '\r': |
|
|
2173 | case '\n': |
|
|
2174 | skipspace (SCHEME_A); |
|
|
2175 | state = st_ok; |
|
|
2176 | break; |
2197 | |
2177 | |
2198 | //TODO: x should end in ;, not two-digit hex |
2178 | //TODO: x should end in ;, not two-digit hex |
2199 | case 'x': |
2179 | case 'x': |
2200 | case 'X': |
2180 | case 'X': |
2201 | state = st_x1; |
2181 | state = st_x1; |
… | |
… | |
2259 | } |
2239 | } |
2260 | } |
2240 | } |
2261 | } |
2241 | } |
2262 | |
2242 | |
2263 | /* check c is in chars */ |
2243 | /* check c is in chars */ |
2264 | ecb_inline int |
2244 | ecb_cold int |
2265 | is_one_of (const char *s, int c) |
2245 | is_one_of (const char *s, int c) |
2266 | { |
2246 | { |
2267 | return c == EOF || !!strchr (s, c); |
2247 | return c == EOF || !!strchr (s, c); |
2268 | } |
2248 | } |
2269 | |
2249 | |
2270 | /* skip white characters */ |
2250 | /* skip white characters */ |
2271 | ecb_inline int |
2251 | ecb_cold int |
2272 | skipspace (SCHEME_P) |
2252 | skipspace (SCHEME_P) |
2273 | { |
2253 | { |
2274 | int c, curr_line = 0; |
2254 | int c, curr_line = 0; |
2275 | |
2255 | |
2276 | do |
2256 | do |
… | |
… | |
2296 | backchar (SCHEME_A_ c); |
2276 | backchar (SCHEME_A_ c); |
2297 | return 1; |
2277 | return 1; |
2298 | } |
2278 | } |
2299 | |
2279 | |
2300 | /* get token */ |
2280 | /* get token */ |
2301 | static int |
2281 | ecb_cold static int |
2302 | token (SCHEME_P) |
2282 | token (SCHEME_P) |
2303 | { |
2283 | { |
2304 | int c = skipspace (SCHEME_A); |
2284 | int c = skipspace (SCHEME_A); |
2305 | |
2285 | |
2306 | if (c == EOF) |
2286 | if (c == EOF) |
… | |
… | |
2404 | } |
2384 | } |
2405 | |
2385 | |
2406 | /* ========== Routines for Printing ========== */ |
2386 | /* ========== Routines for Printing ========== */ |
2407 | #define ok_abbrev(x) (is_pair(x) && cdr(x) == NIL) |
2387 | #define ok_abbrev(x) (is_pair(x) && cdr(x) == NIL) |
2408 | |
2388 | |
2409 | static void |
2389 | ecb_cold static void |
2410 | printslashstring (SCHEME_P_ char *p, int len) |
2390 | printslashstring (SCHEME_P_ char *p, int len) |
2411 | { |
2391 | { |
2412 | int i; |
2392 | int i; |
2413 | unsigned char *s = (unsigned char *) p; |
2393 | unsigned char *s = (unsigned char *) p; |
2414 | |
2394 | |
… | |
… | |
2470 | |
2450 | |
2471 | putcharacter (SCHEME_A_ '"'); |
2451 | putcharacter (SCHEME_A_ '"'); |
2472 | } |
2452 | } |
2473 | |
2453 | |
2474 | /* print atoms */ |
2454 | /* print atoms */ |
2475 | static void |
2455 | ecb_cold static void |
2476 | printatom (SCHEME_P_ pointer l, int f) |
2456 | printatom (SCHEME_P_ pointer l, int f) |
2477 | { |
2457 | { |
2478 | char *p; |
2458 | char *p; |
2479 | int len; |
2459 | int len; |
2480 | |
2460 | |
2481 | atom2str (SCHEME_A_ l, f, &p, &len); |
2461 | atom2str (SCHEME_A_ l, f, &p, &len); |
2482 | putchars (SCHEME_A_ p, len); |
2462 | putchars (SCHEME_A_ p, len); |
2483 | } |
2463 | } |
2484 | |
2464 | |
2485 | /* Uses internal buffer unless string pointer is already available */ |
2465 | /* Uses internal buffer unless string pointer is already available */ |
2486 | static void |
2466 | ecb_cold static void |
2487 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2467 | atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) |
2488 | { |
2468 | { |
2489 | char *p; |
2469 | char *p; |
2490 | |
2470 | |
2491 | if (l == NIL) |
2471 | if (l == NIL) |
… | |
… | |
2698 | return car (d); |
2678 | return car (d); |
2699 | |
2679 | |
2700 | p = cons (car (d), cdr (d)); |
2680 | p = cons (car (d), cdr (d)); |
2701 | q = p; |
2681 | q = p; |
2702 | |
2682 | |
2703 | while (cdr (cdr (p)) != NIL) |
2683 | while (cddr (p) != NIL) |
2704 | { |
2684 | { |
2705 | d = cons (car (p), cdr (p)); |
2685 | d = cons (car (p), cdr (p)); |
2706 | |
2686 | |
2707 | if (cdr (cdr (p)) != NIL) |
2687 | if (cddr (p) != NIL) |
2708 | p = cdr (d); |
2688 | p = cdr (d); |
2709 | } |
2689 | } |
2710 | |
2690 | |
2711 | set_cdr (p, car (cdr (p))); |
2691 | set_cdr (p, cadr (p)); |
2712 | return q; |
2692 | return q; |
2713 | } |
2693 | } |
2714 | |
2694 | |
2715 | /* reverse list -- produce new list */ |
2695 | /* reverse list -- produce new list */ |
2716 | static pointer |
2696 | ecb_hot static pointer |
2717 | reverse (SCHEME_P_ pointer a) |
2697 | reverse (SCHEME_P_ pointer a) |
2718 | { |
2698 | { |
2719 | /* a must be checked by gc */ |
2699 | /* a must be checked by gc */ |
2720 | pointer p = NIL; |
2700 | pointer p = NIL; |
2721 | |
2701 | |
… | |
… | |
2724 | |
2704 | |
2725 | return p; |
2705 | return p; |
2726 | } |
2706 | } |
2727 | |
2707 | |
2728 | /* reverse list --- in-place */ |
2708 | /* reverse list --- in-place */ |
2729 | static pointer |
2709 | ecb_hot static pointer |
2730 | reverse_in_place (SCHEME_P_ pointer term, pointer list) |
2710 | reverse_in_place (SCHEME_P_ pointer term, pointer list) |
2731 | { |
2711 | { |
2732 | pointer result = term; |
2712 | pointer result = term; |
2733 | pointer p = list; |
2713 | pointer p = list; |
2734 | |
2714 | |
… | |
… | |
2742 | |
2722 | |
2743 | return result; |
2723 | return result; |
2744 | } |
2724 | } |
2745 | |
2725 | |
2746 | /* append list -- produce new list (in reverse order) */ |
2726 | /* append list -- produce new list (in reverse order) */ |
2747 | static pointer |
2727 | ecb_hot static pointer |
2748 | revappend (SCHEME_P_ pointer a, pointer b) |
2728 | revappend (SCHEME_P_ pointer a, pointer b) |
2749 | { |
2729 | { |
2750 | pointer result = a; |
2730 | pointer result = a; |
2751 | pointer p = b; |
2731 | pointer p = b; |
2752 | |
2732 | |
… | |
… | |
2761 | |
2741 | |
2762 | return S_F; /* signal an error */ |
2742 | return S_F; /* signal an error */ |
2763 | } |
2743 | } |
2764 | |
2744 | |
2765 | /* equivalence of atoms */ |
2745 | /* equivalence of atoms */ |
2766 | int |
2746 | ecb_hot int |
2767 | eqv (pointer a, pointer b) |
2747 | eqv (pointer a, pointer b) |
2768 | { |
2748 | { |
2769 | if (is_string (a)) |
2749 | if (is_string (a)) |
2770 | { |
2750 | { |
2771 | if (is_string (b)) |
2751 | if (is_string (b)) |
… | |
… | |
2865 | } |
2845 | } |
2866 | else |
2846 | else |
2867 | set_car (env, immutable_cons (slot, car (env))); |
2847 | set_car (env, immutable_cons (slot, car (env))); |
2868 | } |
2848 | } |
2869 | |
2849 | |
2870 | static pointer |
2850 | ecb_hot static pointer |
2871 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2851 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2872 | { |
2852 | { |
2873 | pointer x, y; |
2853 | pointer x, y; |
2874 | |
2854 | |
2875 | for (x = env; x != NIL; x = cdr (x)) |
2855 | for (x = env; x != NIL; x = cdr (x)) |
… | |
… | |
2896 | return NIL; |
2876 | return NIL; |
2897 | } |
2877 | } |
2898 | |
2878 | |
2899 | #else /* USE_ALIST_ENV */ |
2879 | #else /* USE_ALIST_ENV */ |
2900 | |
2880 | |
2901 | ecb_inline void |
2881 | static void |
2902 | new_frame_in_env (SCHEME_P_ pointer old_env) |
2882 | new_frame_in_env (SCHEME_P_ pointer old_env) |
2903 | { |
2883 | { |
2904 | SCHEME_V->envir = immutable_cons (NIL, old_env); |
2884 | SCHEME_V->envir = immutable_cons (NIL, old_env); |
2905 | setenvironment (SCHEME_V->envir); |
2885 | setenvironment (SCHEME_V->envir); |
2906 | } |
2886 | } |
2907 | |
2887 | |
2908 | ecb_inline void |
2888 | static void |
2909 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2889 | new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) |
2910 | { |
2890 | { |
2911 | set_car (env, immutable_cons (immutable_cons (variable, value), car (env))); |
2891 | set_car (env, immutable_cons (immutable_cons (variable, value), car (env))); |
2912 | } |
2892 | } |
2913 | |
2893 | |
2914 | static pointer |
2894 | ecb_hot static pointer |
2915 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2895 | find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) |
2916 | { |
2896 | { |
2917 | pointer x, y; |
2897 | pointer x, y; |
2918 | |
2898 | |
2919 | for (x = env; x != NIL; x = cdr (x)) |
2899 | for (x = env; x != NIL; x = cdr (x)) |
… | |
… | |
2933 | return NIL; |
2913 | return NIL; |
2934 | } |
2914 | } |
2935 | |
2915 | |
2936 | #endif /* USE_ALIST_ENV else */ |
2916 | #endif /* USE_ALIST_ENV else */ |
2937 | |
2917 | |
2938 | ecb_inline void |
2918 | static void |
2939 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2919 | new_slot_in_env (SCHEME_P_ pointer variable, pointer value) |
2940 | { |
2920 | { |
2941 | assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2 |
2921 | assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2 |
2942 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2922 | new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); |
2943 | } |
2923 | } |
2944 | |
2924 | |
2945 | ecb_inline void |
2925 | static void |
2946 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2926 | set_slot_in_env (SCHEME_P_ pointer slot, pointer value) |
2947 | { |
2927 | { |
2948 | set_cdr (slot, value); |
2928 | set_cdr (slot, value); |
2949 | } |
2929 | } |
2950 | |
2930 | |
2951 | ecb_inline pointer |
2931 | static pointer |
2952 | slot_value_in_env (pointer slot) |
2932 | slot_value_in_env (pointer slot) |
2953 | { |
2933 | { |
2954 | return cdr (slot); |
2934 | return cdr (slot); |
2955 | } |
2935 | } |
2956 | |
2936 | |
2957 | /* ========== Evaluation Cycle ========== */ |
2937 | /* ========== Evaluation Cycle ========== */ |
2958 | |
2938 | |
2959 | static int |
2939 | ecb_cold static int |
2960 | xError_1 (SCHEME_P_ const char *s, pointer a) |
2940 | xError_1 (SCHEME_P_ const char *s, pointer a) |
2961 | { |
2941 | { |
2962 | #if USE_ERROR_HOOK |
2942 | #if USE_ERROR_HOOK |
2963 | pointer x; |
2943 | pointer x; |
2964 | pointer hdl = SCHEME_V->ERROR_HOOK; |
2944 | pointer hdl = SCHEME_V->ERROR_HOOK; |
… | |
… | |
3040 | pointer code; |
3020 | pointer code; |
3041 | }; |
3021 | }; |
3042 | |
3022 | |
3043 | # define STACK_GROWTH 3 |
3023 | # define STACK_GROWTH 3 |
3044 | |
3024 | |
3045 | static void |
3025 | ecb_hot static void |
3046 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3026 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3047 | { |
3027 | { |
3048 | int nframes = (uintptr_t)SCHEME_V->dump; |
3028 | int nframes = (uintptr_t)SCHEME_V->dump; |
3049 | struct dump_stack_frame *next_frame; |
3029 | struct dump_stack_frame *next_frame; |
3050 | |
3030 | |
… | |
… | |
3063 | next_frame->code = code; |
3043 | next_frame->code = code; |
3064 | |
3044 | |
3065 | SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1); |
3045 | SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1); |
3066 | } |
3046 | } |
3067 | |
3047 | |
3068 | static int |
3048 | static ecb_hot int |
3069 | xs_return (SCHEME_P_ pointer a) |
3049 | xs_return (SCHEME_P_ pointer a) |
3070 | { |
3050 | { |
3071 | int nframes = (uintptr_t)SCHEME_V->dump; |
3051 | int nframes = (uintptr_t)SCHEME_V->dump; |
3072 | struct dump_stack_frame *frame; |
3052 | struct dump_stack_frame *frame; |
3073 | |
3053 | |
… | |
… | |
3084 | SCHEME_V->dump = (pointer)(uintptr_t)nframes; |
3064 | SCHEME_V->dump = (pointer)(uintptr_t)nframes; |
3085 | |
3065 | |
3086 | return 0; |
3066 | return 0; |
3087 | } |
3067 | } |
3088 | |
3068 | |
3089 | ecb_inline void |
3069 | ecb_cold void |
3090 | dump_stack_reset (SCHEME_P) |
3070 | dump_stack_reset (SCHEME_P) |
3091 | { |
3071 | { |
3092 | /* in this implementation, SCHEME_V->dump is the number of frames on the stack */ |
3072 | /* in this implementation, SCHEME_V->dump is the number of frames on the stack */ |
3093 | SCHEME_V->dump = (pointer)+0; |
3073 | SCHEME_V->dump = (pointer)+0; |
3094 | } |
3074 | } |
3095 | |
3075 | |
3096 | ecb_inline void |
3076 | ecb_cold void |
3097 | dump_stack_initialize (SCHEME_P) |
3077 | dump_stack_initialize (SCHEME_P) |
3098 | { |
3078 | { |
3099 | SCHEME_V->dump_size = 0; |
3079 | SCHEME_V->dump_size = 0; |
3100 | SCHEME_V->dump_base = 0; |
3080 | SCHEME_V->dump_base = 0; |
3101 | dump_stack_reset (SCHEME_A); |
3081 | dump_stack_reset (SCHEME_A); |
3102 | } |
3082 | } |
3103 | |
3083 | |
3104 | static void |
3084 | ecb_cold static void |
3105 | dump_stack_free (SCHEME_P) |
3085 | dump_stack_free (SCHEME_P) |
3106 | { |
3086 | { |
3107 | free (SCHEME_V->dump_base); |
3087 | free (SCHEME_V->dump_base); |
3108 | SCHEME_V->dump_base = 0; |
3088 | SCHEME_V->dump_base = 0; |
3109 | SCHEME_V->dump = (pointer)0; |
3089 | SCHEME_V->dump = (pointer)0; |
3110 | SCHEME_V->dump_size = 0; |
3090 | SCHEME_V->dump_size = 0; |
3111 | } |
3091 | } |
3112 | |
3092 | |
3113 | static void |
3093 | ecb_cold static void |
3114 | dump_stack_mark (SCHEME_P) |
3094 | dump_stack_mark (SCHEME_P) |
3115 | { |
3095 | { |
3116 | int nframes = (uintptr_t)SCHEME_V->dump; |
3096 | int nframes = (uintptr_t)SCHEME_V->dump; |
3117 | int i; |
3097 | int i; |
3118 | |
3098 | |
… | |
… | |
3124 | mark (frame->envir); |
3104 | mark (frame->envir); |
3125 | mark (frame->code); |
3105 | mark (frame->code); |
3126 | } |
3106 | } |
3127 | } |
3107 | } |
3128 | |
3108 | |
3129 | static pointer |
3109 | ecb_cold static pointer |
3130 | ss_get_cont (SCHEME_P) |
3110 | ss_get_cont (SCHEME_P) |
3131 | { |
3111 | { |
3132 | int nframes = (uintptr_t)SCHEME_V->dump; |
3112 | int nframes = (uintptr_t)SCHEME_V->dump; |
3133 | int i; |
3113 | int i; |
3134 | |
3114 | |
… | |
… | |
3146 | } |
3126 | } |
3147 | |
3127 | |
3148 | return cont; |
3128 | return cont; |
3149 | } |
3129 | } |
3150 | |
3130 | |
3151 | static void |
3131 | ecb_cold static void |
3152 | ss_set_cont (SCHEME_P_ pointer cont) |
3132 | ss_set_cont (SCHEME_P_ pointer cont) |
3153 | { |
3133 | { |
3154 | int i = 0; |
3134 | int i = 0; |
3155 | struct dump_stack_frame *frame = SCHEME_V->dump_base; |
3135 | struct dump_stack_frame *frame = SCHEME_V->dump_base; |
3156 | |
3136 | |
… | |
… | |
3168 | SCHEME_V->dump = (pointer)(uintptr_t)i; |
3148 | SCHEME_V->dump = (pointer)(uintptr_t)i; |
3169 | } |
3149 | } |
3170 | |
3150 | |
3171 | #else |
3151 | #else |
3172 | |
3152 | |
3173 | ecb_inline void |
3153 | ecb_cold void |
3174 | dump_stack_reset (SCHEME_P) |
3154 | dump_stack_reset (SCHEME_P) |
3175 | { |
3155 | { |
3176 | SCHEME_V->dump = NIL; |
3156 | SCHEME_V->dump = NIL; |
3177 | } |
3157 | } |
3178 | |
3158 | |
3179 | ecb_inline void |
3159 | ecb_cold void |
3180 | dump_stack_initialize (SCHEME_P) |
3160 | dump_stack_initialize (SCHEME_P) |
3181 | { |
3161 | { |
3182 | dump_stack_reset (SCHEME_A); |
3162 | dump_stack_reset (SCHEME_A); |
3183 | } |
3163 | } |
3184 | |
3164 | |
3185 | static void |
3165 | ecb_cold static void |
3186 | dump_stack_free (SCHEME_P) |
3166 | dump_stack_free (SCHEME_P) |
3187 | { |
3167 | { |
3188 | SCHEME_V->dump = NIL; |
3168 | SCHEME_V->dump = NIL; |
3189 | } |
3169 | } |
3190 | |
3170 | |
3191 | static int |
3171 | ecb_hot static int |
3192 | xs_return (SCHEME_P_ pointer a) |
3172 | xs_return (SCHEME_P_ pointer a) |
3193 | { |
3173 | { |
3194 | pointer dump = SCHEME_V->dump; |
3174 | pointer dump = SCHEME_V->dump; |
3195 | |
3175 | |
3196 | SCHEME_V->value = a; |
3176 | SCHEME_V->value = a; |
… | |
… | |
3206 | SCHEME_V->dump = dump; |
3186 | SCHEME_V->dump = dump; |
3207 | |
3187 | |
3208 | return 0; |
3188 | return 0; |
3209 | } |
3189 | } |
3210 | |
3190 | |
3211 | static void |
3191 | ecb_hot static void |
3212 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3192 | s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) |
3213 | { |
3193 | { |
3214 | SCHEME_V->dump = cons (mk_integer (SCHEME_A_ op), |
3194 | SCHEME_V->dump = cons (mk_integer (SCHEME_A_ op), |
3215 | cons (args, |
3195 | cons (args, |
3216 | cons (SCHEME_V->envir, |
3196 | cons (SCHEME_V->envir, |
3217 | cons (code, |
3197 | cons (code, |
3218 | SCHEME_V->dump)))); |
3198 | SCHEME_V->dump)))); |
3219 | } |
3199 | } |
3220 | |
3200 | |
|
|
3201 | ecb_cold static void |
|
|
3202 | dump_stack_mark (SCHEME_P) |
|
|
3203 | { |
|
|
3204 | mark (SCHEME_V->dump); |
|
|
3205 | } |
|
|
3206 | |
|
|
3207 | ecb_cold static pointer |
|
|
3208 | ss_get_cont (SCHEME_P) |
|
|
3209 | { |
|
|
3210 | return SCHEME_V->dump; |
|
|
3211 | } |
|
|
3212 | |
|
|
3213 | ecb_cold static void |
|
|
3214 | ss_set_cont (SCHEME_P_ pointer cont) |
|
|
3215 | { |
|
|
3216 | SCHEME_V->dump = cont; |
|
|
3217 | } |
|
|
3218 | |
|
|
3219 | #endif |
|
|
3220 | |
|
|
3221 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
|
|
3222 | |
|
|
3223 | #if EXPERIMENT |
|
|
3224 | |
|
|
3225 | typedef void *stream[1]; |
|
|
3226 | |
|
|
3227 | #define stream_init() { 0 } |
|
|
3228 | |
|
|
3229 | ecb_cold static void |
|
|
3230 | stream_put (void **s, uint8_t byte) |
|
|
3231 | { |
|
|
3232 | uint32_t *sp = *s; |
|
|
3233 | uint32_t size = sizeof (uint32_t) * 2; |
|
|
3234 | uint32_t offs = size; |
|
|
3235 | |
|
|
3236 | if (ecb_expect_true (sp)) |
|
|
3237 | { |
|
|
3238 | offs = sp[0]; |
|
|
3239 | size = sp[1]; |
|
|
3240 | } |
|
|
3241 | |
|
|
3242 | if (ecb_expect_false (offs == size)) |
|
|
3243 | { |
|
|
3244 | size *= 2; |
|
|
3245 | sp = realloc (sp, size); |
|
|
3246 | *s = sp; |
|
|
3247 | sp[1] = size; |
|
|
3248 | |
|
|
3249 | } |
|
|
3250 | |
|
|
3251 | ((uint8_t *)sp)[offs++] = byte; |
|
|
3252 | sp[0] = offs; |
|
|
3253 | } |
|
|
3254 | |
|
|
3255 | #define stream_data(s) ((char *)(s)[0] + sizeof (uint32_t) * 2) |
|
|
3256 | #define stream_size(s) (((uint32_t *)(s)[0])[0] - sizeof (uint32_t) * 2) |
|
|
3257 | #define stream_free(s) free (s[0]) |
|
|
3258 | |
|
|
3259 | // calculates a (preferably small) integer that makes it possible to find |
|
|
3260 | // the symbol again. if pointers were offsets into a memory area... until |
|
|
3261 | // then, we return segment number in the low bits, and offset in the high |
|
|
3262 | // bits |
|
|
3263 | static uint32_t |
|
|
3264 | symbol_id (SCHEME_P_ pointer sym) |
|
|
3265 | { |
|
|
3266 | struct cell *p = CELL (sym); |
|
|
3267 | int i; |
|
|
3268 | |
|
|
3269 | for (i = SCHEME_V->last_cell_seg; i >= 0; --i) |
|
|
3270 | if (SCHEME_V->cell_seg[i] <= p && p < SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize[i]) |
|
|
3271 | { |
|
|
3272 | printf ("seg %d ofs %d/%d\n",i,(p - SCHEME_V->cell_seg[i]),SCHEME_V->cell_segsize[i]);//D |
|
|
3273 | return i | ((p - SCHEME_V->cell_seg[i]) << CELL_NSEGMENT_LOG); |
|
|
3274 | } |
|
|
3275 | |
|
|
3276 | abort (); |
|
|
3277 | } |
|
|
3278 | |
3221 | static void |
3279 | static void |
3222 | dump_stack_mark (SCHEME_P) |
3280 | compile (SCHEME_P_ stream s, pointer x) |
3223 | { |
3281 | { |
3224 | mark (SCHEME_V->dump); |
3282 | if (x == NIL) |
3225 | } |
3283 | { |
|
|
3284 | stream_put (s, 0); |
|
|
3285 | return; |
|
|
3286 | } |
3226 | |
3287 | |
3227 | static pointer |
3288 | if (is_syntax (x)) |
3228 | ss_get_cont (SCHEME_P) |
3289 | { |
3229 | { |
3290 | stream_put (s, 1); |
3230 | return SCHEME_V->dump; |
3291 | stream_put (s, syntaxnum (x)); |
3231 | } |
3292 | return; |
|
|
3293 | } |
3232 | |
3294 | |
3233 | static void |
3295 | switch (type (x)) |
3234 | ss_set_cont (SCHEME_P_ pointer cont) |
3296 | { |
3235 | { |
3297 | case T_INTEGER: |
3236 | SCHEME_V->dump = cont; |
3298 | stream_put (s, 2); |
3237 | } |
3299 | stream_put (s, 0); |
|
|
3300 | stream_put (s, 0); |
|
|
3301 | stream_put (s, 0); |
|
|
3302 | stream_put (s, 0); |
|
|
3303 | return; |
3238 | |
3304 | |
3239 | #endif |
3305 | case T_SYMBOL: |
|
|
3306 | { |
|
|
3307 | uint32_t sym = symbol_id (SCHEME_A_ x); |
|
|
3308 | printf ("sym %x\n", sym);//D |
3240 | |
3309 | |
3241 | #define s_retbool(tf) s_return ((tf) ? S_T : S_F) |
3310 | stream_put (s, 3); |
3242 | |
3311 | |
3243 | #if EXPERIMENT |
3312 | while (sym > 0x7f) |
|
|
3313 | { |
|
|
3314 | stream_put (s, sym | 0x80); |
|
|
3315 | sym >>= 8; |
|
|
3316 | } |
|
|
3317 | |
|
|
3318 | stream_put (s, sym); |
|
|
3319 | } |
|
|
3320 | return; |
|
|
3321 | |
|
|
3322 | case T_PAIR: |
|
|
3323 | stream_put (s, 4); |
|
|
3324 | while (x != NIL) |
|
|
3325 | { |
|
|
3326 | compile (SCHEME_A_ s, car (x)); |
|
|
3327 | x = cdr (x); |
|
|
3328 | } |
|
|
3329 | stream_put (s, 0xff); |
|
|
3330 | return; |
|
|
3331 | |
|
|
3332 | default: |
|
|
3333 | stream_put (s, 5); |
|
|
3334 | stream_put (s, type (x)); |
|
|
3335 | stream_put (s, 0); |
|
|
3336 | stream_put (s, 0); |
|
|
3337 | stream_put (s, 0); |
|
|
3338 | stream_put (s, 0); |
|
|
3339 | break; |
|
|
3340 | } |
|
|
3341 | } |
|
|
3342 | |
3244 | static int |
3343 | static int |
|
|
3344 | compile_closure (SCHEME_P_ pointer p) |
|
|
3345 | { |
|
|
3346 | stream s = stream_init (); |
|
|
3347 | |
|
|
3348 | printatom (SCHEME_A_ p, 1);//D |
|
|
3349 | compile (SCHEME_A_ s, car (p)); |
|
|
3350 | |
|
|
3351 | FILE *xxd = popen ("xxd", "we"); |
|
|
3352 | fwrite (stream_data (s), 1, stream_size (s), xxd); |
|
|
3353 | fclose (xxd); |
|
|
3354 | |
|
|
3355 | return stream_size (s); |
|
|
3356 | } |
|
|
3357 | |
|
|
3358 | static int |
3245 | debug (SCHEME_P_ int indent, pointer x) |
3359 | dtree (SCHEME_P_ int indent, pointer x) |
3246 | { |
3360 | { |
3247 | int c; |
3361 | int c; |
3248 | |
3362 | |
3249 | if (is_syntax (x)) |
3363 | if (is_syntax (x)) |
3250 | { |
3364 | { |
… | |
… | |
3268 | printf ("%*sS<%s>\n", indent, "", symname (x)); |
3382 | printf ("%*sS<%s>\n", indent, "", symname (x)); |
3269 | return 24+8; |
3383 | return 24+8; |
3270 | |
3384 | |
3271 | case T_CLOSURE: |
3385 | case T_CLOSURE: |
3272 | printf ("%*sS<%s>\n", indent, "", "closure"); |
3386 | printf ("%*sS<%s>\n", indent, "", "closure"); |
3273 | debug (SCHEME_A_ indent + 3, cdr(x)); |
3387 | dtree (SCHEME_A_ indent + 3, cdr(x)); |
3274 | return 32 + debug (SCHEME_A_ indent + 3, car (x)); |
3388 | return 32 + dtree (SCHEME_A_ indent + 3, car (x)); |
3275 | |
3389 | |
3276 | case T_PAIR: |
3390 | case T_PAIR: |
3277 | printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); |
3391 | printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); |
3278 | c = debug (SCHEME_A_ indent + 3, car (x)); |
3392 | c = dtree (SCHEME_A_ indent + 3, car (x)); |
3279 | c += debug (SCHEME_A_ indent + 3, cdr (x)); |
3393 | c += dtree (SCHEME_A_ indent + 3, cdr (x)); |
3280 | return c + 1; |
3394 | return c + 1; |
3281 | |
3395 | |
3282 | case T_PORT: |
3396 | case T_PORT: |
3283 | printf ("%*sS<%s>\n", indent, "", "port"); |
3397 | printf ("%*sS<%s>\n", indent, "", "port"); |
3284 | return 24+8; |
3398 | return 24+8; |
… | |
… | |
3287 | printf ("%*sS<%s>\n", indent, "", "vector"); |
3401 | printf ("%*sS<%s>\n", indent, "", "vector"); |
3288 | return 24+8; |
3402 | return 24+8; |
3289 | |
3403 | |
3290 | case T_ENVIRONMENT: |
3404 | case T_ENVIRONMENT: |
3291 | printf ("%*sS<%s>\n", indent, "", "environment"); |
3405 | printf ("%*sS<%s>\n", indent, "", "environment"); |
3292 | return 0 + debug (SCHEME_A_ indent + 3, car (x)); |
3406 | return 0 + dtree (SCHEME_A_ indent + 3, car (x)); |
3293 | |
3407 | |
3294 | default: |
3408 | default: |
3295 | printf ("unhandled type %d\n", type (x)); |
3409 | printf ("unhandled type %d\n", type (x)); |
3296 | break; |
3410 | break; |
3297 | } |
3411 | } |
3298 | } |
3412 | } |
3299 | #endif |
3413 | #endif |
3300 | |
3414 | |
3301 | static int |
3415 | /* syntax, eval, core, ... */ |
|
|
3416 | ecb_hot static int |
3302 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3417 | opexe_0 (SCHEME_P_ enum scheme_opcodes op) |
3303 | { |
3418 | { |
3304 | pointer args = SCHEME_V->args; |
3419 | pointer args = SCHEME_V->args; |
3305 | pointer x, y; |
3420 | pointer x, y; |
3306 | |
3421 | |
3307 | switch (op) |
3422 | switch (op) |
3308 | { |
3423 | { |
3309 | #if EXPERIMENT //D |
3424 | #if EXPERIMENT //D |
3310 | case OP_DEBUG: |
3425 | case OP_DEBUG: |
3311 | printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); |
3426 | { |
|
|
3427 | uint32_t len = compile_closure (SCHEME_A_ car (args)); |
|
|
3428 | printf ("len = %d\n", len); |
3312 | printf ("\n"); |
3429 | printf ("\n"); |
3313 | s_return (S_T); |
3430 | s_return (S_T); |
|
|
3431 | } |
3314 | #endif |
3432 | #endif |
3315 | case OP_LOAD: /* load */ |
3433 | case OP_LOAD: /* load */ |
3316 | if (file_interactive (SCHEME_A)) |
3434 | if (file_interactive (SCHEME_A)) |
3317 | { |
3435 | { |
3318 | putstr (SCHEME_A_ "Loading "); putstr (SCHEME_A_ strvalue (car (args))); putstr (SCHEME_A_ "\n"); |
3436 | putstr (SCHEME_A_ "Loading "); |
3319 | //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); |
3437 | putstr (SCHEME_A_ strvalue (car (args))); |
|
|
3438 | putcharacter (SCHEME_A_ '\n'); |
3320 | } |
3439 | } |
3321 | |
3440 | |
3322 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3441 | if (!file_push (SCHEME_A_ strvalue (car (args)))) |
3323 | Error_1 ("unable to open", car (args)); |
3442 | Error_1 ("unable to open", car (args)); |
3324 | else |
3443 | |
3325 | { |
|
|
3326 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
3444 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
3327 | s_goto (OP_T0LVL); |
3445 | s_goto (OP_T0LVL); |
3328 | } |
|
|
3329 | |
3446 | |
3330 | case OP_T0LVL: /* top level */ |
3447 | case OP_T0LVL: /* top level */ |
3331 | |
3448 | |
3332 | /* If we reached the end of file, this loop is done. */ |
3449 | /* If we reached the end of file, this loop is done. */ |
3333 | if (port (SCHEME_V->loadport)->kind & port_saw_EOF) |
3450 | if (port (SCHEME_V->loadport)->kind & port_saw_EOF) |
… | |
… | |
3349 | /* If interactive, be nice to user. */ |
3466 | /* If interactive, be nice to user. */ |
3350 | if (file_interactive (SCHEME_A)) |
3467 | if (file_interactive (SCHEME_A)) |
3351 | { |
3468 | { |
3352 | SCHEME_V->envir = SCHEME_V->global_env; |
3469 | SCHEME_V->envir = SCHEME_V->global_env; |
3353 | dump_stack_reset (SCHEME_A); |
3470 | dump_stack_reset (SCHEME_A); |
3354 | putstr (SCHEME_A_ "\n"); |
3471 | putcharacter (SCHEME_A_ '\n'); |
|
|
3472 | #if EXPERIMENT |
|
|
3473 | system ("ps v $PPID"); |
|
|
3474 | #endif |
3355 | putstr (SCHEME_A_ prompt); |
3475 | putstr (SCHEME_A_ prompt); |
3356 | } |
3476 | } |
3357 | |
3477 | |
3358 | /* Set up another iteration of REPL */ |
3478 | /* Set up another iteration of REPL */ |
3359 | SCHEME_V->nesting = 0; |
3479 | SCHEME_V->nesting = 0; |
… | |
… | |
3394 | { |
3514 | { |
3395 | SCHEME_V->print_flag = 1; |
3515 | SCHEME_V->print_flag = 1; |
3396 | SCHEME_V->args = SCHEME_V->value; |
3516 | SCHEME_V->args = SCHEME_V->value; |
3397 | s_goto (OP_P0LIST); |
3517 | s_goto (OP_P0LIST); |
3398 | } |
3518 | } |
3399 | else |
3519 | |
3400 | s_return (SCHEME_V->value); |
3520 | s_return (SCHEME_V->value); |
3401 | |
3521 | |
3402 | case OP_EVAL: /* main part of evaluation */ |
3522 | case OP_EVAL: /* main part of evaluation */ |
3403 | #if USE_TRACING |
3523 | #if USE_TRACING |
3404 | if (SCHEME_V->tracing) |
3524 | if (SCHEME_V->tracing) |
3405 | { |
3525 | { |
… | |
… | |
3438 | /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */ |
3558 | /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */ |
3439 | SCHEME_V->code = x; |
3559 | SCHEME_V->code = x; |
3440 | s_goto (OP_EVAL); |
3560 | s_goto (OP_EVAL); |
3441 | } |
3561 | } |
3442 | } |
3562 | } |
3443 | else |
3563 | |
3444 | s_return (SCHEME_V->code); |
3564 | s_return (SCHEME_V->code); |
3445 | |
3565 | |
3446 | case OP_E0ARGS: /* eval arguments */ |
3566 | case OP_E0ARGS: /* eval arguments */ |
3447 | if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ |
3567 | if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ |
3448 | { |
3568 | { |
3449 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
3569 | s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); |
… | |
… | |
3621 | else |
3741 | else |
3622 | new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value); |
3742 | new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value); |
3623 | |
3743 | |
3624 | s_return (SCHEME_V->code); |
3744 | s_return (SCHEME_V->code); |
3625 | |
3745 | |
3626 | |
|
|
3627 | case OP_DEFP: /* defined? */ |
3746 | case OP_DEFP: /* defined? */ |
3628 | x = SCHEME_V->envir; |
3747 | x = SCHEME_V->envir; |
3629 | |
3748 | |
3630 | if (cdr (args) != NIL) |
3749 | if (cdr (args) != NIL) |
3631 | x = cadr (args); |
3750 | x = cadr (args); |
… | |
… | |
3648 | set_slot_in_env (SCHEME_A_ y, SCHEME_V->value); |
3767 | set_slot_in_env (SCHEME_A_ y, SCHEME_V->value); |
3649 | s_return (SCHEME_V->value); |
3768 | s_return (SCHEME_V->value); |
3650 | } |
3769 | } |
3651 | else |
3770 | else |
3652 | Error_1 ("set!: unbound variable:", SCHEME_V->code); |
3771 | Error_1 ("set!: unbound variable:", SCHEME_V->code); |
3653 | |
|
|
3654 | |
3772 | |
3655 | case OP_BEGIN: /* begin */ |
3773 | case OP_BEGIN: /* begin */ |
3656 | if (!is_pair (SCHEME_V->code)) |
3774 | if (!is_pair (SCHEME_V->code)) |
3657 | s_return (SCHEME_V->code); |
3775 | s_return (SCHEME_V->code); |
3658 | |
3776 | |
… | |
… | |
3670 | case OP_IF1: /* if */ |
3788 | case OP_IF1: /* if */ |
3671 | if (is_true (SCHEME_V->value)) |
3789 | if (is_true (SCHEME_V->value)) |
3672 | SCHEME_V->code = car (SCHEME_V->code); |
3790 | SCHEME_V->code = car (SCHEME_V->code); |
3673 | else |
3791 | else |
3674 | SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */ |
3792 | SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */ |
|
|
3793 | |
3675 | s_goto (OP_EVAL); |
3794 | s_goto (OP_EVAL); |
3676 | |
3795 | |
3677 | case OP_LET0: /* let */ |
3796 | case OP_LET0: /* let */ |
3678 | SCHEME_V->args = NIL; |
3797 | SCHEME_V->args = NIL; |
3679 | SCHEME_V->value = SCHEME_V->code; |
3798 | SCHEME_V->value = SCHEME_V->code; |
… | |
… | |
3835 | } |
3954 | } |
3836 | else |
3955 | else |
3837 | { |
3956 | { |
3838 | if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL) |
3957 | if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL) |
3839 | s_return (NIL); |
3958 | s_return (NIL); |
3840 | else |
3959 | |
3841 | { |
|
|
3842 | s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code); |
3960 | s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code); |
3843 | SCHEME_V->code = caar (SCHEME_V->code); |
3961 | SCHEME_V->code = caar (SCHEME_V->code); |
3844 | s_goto (OP_EVAL); |
3962 | s_goto (OP_EVAL); |
3845 | } |
|
|
3846 | } |
3963 | } |
3847 | |
3964 | |
3848 | case OP_DELAY: /* delay */ |
3965 | case OP_DELAY: /* delay */ |
3849 | x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir); |
3966 | x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir); |
3850 | set_typeflag (x, T_PROMISE); |
3967 | set_typeflag (x, T_PROMISE); |
… | |
… | |
3861 | case OP_AND1: /* and */ |
3978 | case OP_AND1: /* and */ |
3862 | if (is_false (SCHEME_V->value)) |
3979 | if (is_false (SCHEME_V->value)) |
3863 | s_return (SCHEME_V->value); |
3980 | s_return (SCHEME_V->value); |
3864 | else if (SCHEME_V->code == NIL) |
3981 | else if (SCHEME_V->code == NIL) |
3865 | s_return (SCHEME_V->value); |
3982 | s_return (SCHEME_V->value); |
3866 | else |
3983 | |
3867 | { |
|
|
3868 | s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code)); |
3984 | s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code)); |
3869 | SCHEME_V->code = car (SCHEME_V->code); |
3985 | SCHEME_V->code = car (SCHEME_V->code); |
3870 | s_goto (OP_EVAL); |
3986 | s_goto (OP_EVAL); |
3871 | } |
|
|
3872 | |
3987 | |
3873 | case OP_OR0: /* or */ |
3988 | case OP_OR0: /* or */ |
3874 | if (SCHEME_V->code == NIL) |
3989 | if (SCHEME_V->code == NIL) |
3875 | s_return (S_F); |
3990 | s_return (S_F); |
3876 | |
3991 | |
… | |
… | |
3881 | case OP_OR1: /* or */ |
3996 | case OP_OR1: /* or */ |
3882 | if (is_true (SCHEME_V->value)) |
3997 | if (is_true (SCHEME_V->value)) |
3883 | s_return (SCHEME_V->value); |
3998 | s_return (SCHEME_V->value); |
3884 | else if (SCHEME_V->code == NIL) |
3999 | else if (SCHEME_V->code == NIL) |
3885 | s_return (SCHEME_V->value); |
4000 | s_return (SCHEME_V->value); |
3886 | else |
4001 | |
3887 | { |
|
|
3888 | s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code)); |
4002 | s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code)); |
3889 | SCHEME_V->code = car (SCHEME_V->code); |
4003 | SCHEME_V->code = car (SCHEME_V->code); |
3890 | s_goto (OP_EVAL); |
4004 | s_goto (OP_EVAL); |
3891 | } |
|
|
3892 | |
4005 | |
3893 | case OP_C0STREAM: /* cons-stream */ |
4006 | case OP_C0STREAM: /* cons-stream */ |
3894 | s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code)); |
4007 | s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code)); |
3895 | SCHEME_V->code = car (SCHEME_V->code); |
4008 | SCHEME_V->code = car (SCHEME_V->code); |
3896 | s_goto (OP_EVAL); |
4009 | s_goto (OP_EVAL); |
… | |
… | |
3961 | s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x)); |
4074 | s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x)); |
3962 | SCHEME_V->code = caar (x); |
4075 | SCHEME_V->code = caar (x); |
3963 | s_goto (OP_EVAL); |
4076 | s_goto (OP_EVAL); |
3964 | } |
4077 | } |
3965 | } |
4078 | } |
3966 | else |
4079 | |
3967 | s_return (NIL); |
4080 | s_return (NIL); |
3968 | |
4081 | |
3969 | case OP_CASE2: /* case */ |
4082 | case OP_CASE2: /* case */ |
3970 | if (is_true (SCHEME_V->value)) |
4083 | if (is_true (SCHEME_V->value)) |
3971 | s_goto (OP_BEGIN); |
4084 | s_goto (OP_BEGIN); |
3972 | else |
4085 | |
3973 | s_return (NIL); |
4086 | s_return (NIL); |
3974 | |
4087 | |
3975 | case OP_PAPPLY: /* apply */ |
4088 | case OP_PAPPLY: /* apply */ |
3976 | SCHEME_V->code = car (args); |
4089 | SCHEME_V->code = car (args); |
3977 | SCHEME_V->args = list_star (SCHEME_A_ cdr (args)); |
4090 | SCHEME_V->args = list_star (SCHEME_A_ cdr (args)); |
3978 | /*SCHEME_V->args = cadr(args); */ |
4091 | /*SCHEME_V->args = cadr(args); */ |
… | |
… | |
3992 | } |
4105 | } |
3993 | |
4106 | |
3994 | if (USE_ERROR_CHECKING) abort (); |
4107 | if (USE_ERROR_CHECKING) abort (); |
3995 | } |
4108 | } |
3996 | |
4109 | |
3997 | static int |
4110 | /* math, cxr */ |
|
|
4111 | ecb_hot static int |
3998 | opexe_1 (SCHEME_P_ enum scheme_opcodes op) |
4112 | opexe_1 (SCHEME_P_ enum scheme_opcodes op) |
3999 | { |
4113 | { |
4000 | pointer args = SCHEME_V->args; |
4114 | pointer args = SCHEME_V->args; |
4001 | pointer x = car (args); |
4115 | pointer x = car (args); |
4002 | num v; |
4116 | num v; |
… | |
… | |
4483 | } |
4597 | } |
4484 | |
4598 | |
4485 | if (USE_ERROR_CHECKING) abort (); |
4599 | if (USE_ERROR_CHECKING) abort (); |
4486 | } |
4600 | } |
4487 | |
4601 | |
4488 | static int |
4602 | /* relational ops */ |
|
|
4603 | ecb_hot static int |
4489 | opexe_2 (SCHEME_P_ enum scheme_opcodes op) |
4604 | opexe_2 (SCHEME_P_ enum scheme_opcodes op) |
4490 | { |
4605 | { |
4491 | pointer x = SCHEME_V->args; |
4606 | pointer x = SCHEME_V->args; |
4492 | |
4607 | |
4493 | for (;;) |
4608 | for (;;) |
… | |
… | |
4514 | } |
4629 | } |
4515 | |
4630 | |
4516 | s_return (S_T); |
4631 | s_return (S_T); |
4517 | } |
4632 | } |
4518 | |
4633 | |
4519 | static int |
4634 | /* predicates */ |
|
|
4635 | ecb_hot static int |
4520 | opexe_3 (SCHEME_P_ enum scheme_opcodes op) |
4636 | opexe_3 (SCHEME_P_ enum scheme_opcodes op) |
4521 | { |
4637 | { |
4522 | pointer args = SCHEME_V->args; |
4638 | pointer args = SCHEME_V->args; |
4523 | pointer a = car (args); |
4639 | pointer a = car (args); |
4524 | pointer d = cdr (args); |
4640 | pointer d = cdr (args); |
… | |
… | |
4571 | } |
4687 | } |
4572 | |
4688 | |
4573 | s_retbool (r); |
4689 | s_retbool (r); |
4574 | } |
4690 | } |
4575 | |
4691 | |
4576 | static int |
4692 | /* promises, list ops, ports */ |
|
|
4693 | ecb_hot static int |
4577 | opexe_4 (SCHEME_P_ enum scheme_opcodes op) |
4694 | opexe_4 (SCHEME_P_ enum scheme_opcodes op) |
4578 | { |
4695 | { |
4579 | pointer args = SCHEME_V->args; |
4696 | pointer args = SCHEME_V->args; |
4580 | pointer a = car (args); |
4697 | pointer a = car (args); |
4581 | pointer x, y; |
4698 | pointer x, y; |
… | |
… | |
4598 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4715 | case OP_SAVE_FORCED: /* Save forced value replacing promise */ |
4599 | *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); |
4716 | *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); |
4600 | s_return (SCHEME_V->value); |
4717 | s_return (SCHEME_V->value); |
4601 | |
4718 | |
4602 | #if USE_PORTS |
4719 | #if USE_PORTS |
|
|
4720 | |
|
|
4721 | case OP_EOF_OBJECT: /* eof-object */ |
|
|
4722 | s_return (S_EOF); |
4603 | |
4723 | |
4604 | case OP_WRITE: /* write */ |
4724 | case OP_WRITE: /* write */ |
4605 | case OP_DISPLAY: /* display */ |
4725 | case OP_DISPLAY: /* display */ |
4606 | case OP_WRITE_CHAR: /* write-char */ |
4726 | case OP_WRITE_CHAR: /* write-char */ |
4607 | if (is_pair (cdr (SCHEME_V->args))) |
4727 | if (is_pair (cdr (SCHEME_V->args))) |
… | |
… | |
4621 | else |
4741 | else |
4622 | SCHEME_V->print_flag = 0; |
4742 | SCHEME_V->print_flag = 0; |
4623 | |
4743 | |
4624 | s_goto (OP_P0LIST); |
4744 | s_goto (OP_P0LIST); |
4625 | |
4745 | |
|
|
4746 | //TODO: move to scheme |
4626 | case OP_NEWLINE: /* newline */ |
4747 | case OP_NEWLINE: /* newline */ |
4627 | if (is_pair (args)) |
4748 | if (is_pair (args)) |
4628 | { |
4749 | { |
4629 | if (a != SCHEME_V->outport) |
4750 | if (a != SCHEME_V->outport) |
4630 | { |
4751 | { |
… | |
… | |
4632 | s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL); |
4753 | s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL); |
4633 | SCHEME_V->outport = a; |
4754 | SCHEME_V->outport = a; |
4634 | } |
4755 | } |
4635 | } |
4756 | } |
4636 | |
4757 | |
4637 | putstr (SCHEME_A_ "\n"); |
4758 | putcharacter (SCHEME_A_ '\n'); |
4638 | s_return (S_T); |
4759 | s_return (S_T); |
4639 | #endif |
4760 | #endif |
4640 | |
4761 | |
4641 | case OP_ERR0: /* error */ |
4762 | case OP_ERR0: /* error */ |
4642 | SCHEME_V->retcode = -1; |
4763 | SCHEME_V->retcode = -1; |
… | |
… | |
4651 | putstr (SCHEME_A_ strvalue (car (args))); |
4772 | putstr (SCHEME_A_ strvalue (car (args))); |
4652 | SCHEME_V->args = cdr (args); |
4773 | SCHEME_V->args = cdr (args); |
4653 | s_goto (OP_ERR1); |
4774 | s_goto (OP_ERR1); |
4654 | |
4775 | |
4655 | case OP_ERR1: /* error */ |
4776 | case OP_ERR1: /* error */ |
4656 | putstr (SCHEME_A_ " "); |
4777 | putcharacter (SCHEME_A_ ' '); |
4657 | |
4778 | |
4658 | if (args != NIL) |
4779 | if (args != NIL) |
4659 | { |
4780 | { |
4660 | s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL); |
4781 | s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL); |
4661 | SCHEME_V->args = a; |
4782 | SCHEME_V->args = a; |
4662 | SCHEME_V->print_flag = 1; |
4783 | SCHEME_V->print_flag = 1; |
4663 | s_goto (OP_P0LIST); |
4784 | s_goto (OP_P0LIST); |
4664 | } |
4785 | } |
4665 | else |
4786 | else |
4666 | { |
4787 | { |
4667 | putstr (SCHEME_A_ "\n"); |
4788 | putcharacter (SCHEME_A_ '\n'); |
4668 | |
4789 | |
4669 | if (SCHEME_V->interactive_repl) |
4790 | if (SCHEME_V->interactive_repl) |
4670 | s_goto (OP_T0LVL); |
4791 | s_goto (OP_T0LVL); |
4671 | else |
4792 | else |
4672 | return -1; |
4793 | return -1; |
… | |
… | |
4880 | } |
5001 | } |
4881 | |
5002 | |
4882 | if (USE_ERROR_CHECKING) abort (); |
5003 | if (USE_ERROR_CHECKING) abort (); |
4883 | } |
5004 | } |
4884 | |
5005 | |
4885 | static int |
5006 | /* reading */ |
|
|
5007 | ecb_cold static int |
4886 | opexe_5 (SCHEME_P_ enum scheme_opcodes op) |
5008 | opexe_5 (SCHEME_P_ enum scheme_opcodes op) |
4887 | { |
5009 | { |
4888 | pointer args = SCHEME_V->args; |
5010 | pointer args = SCHEME_V->args; |
4889 | pointer x; |
5011 | pointer x; |
4890 | |
5012 | |
… | |
… | |
5159 | pointer b = cdr (args); |
5281 | pointer b = cdr (args); |
5160 | int ok_abbr = ok_abbrev (b); |
5282 | int ok_abbr = ok_abbrev (b); |
5161 | SCHEME_V->args = car (b); |
5283 | SCHEME_V->args = car (b); |
5162 | |
5284 | |
5163 | if (a == SCHEME_V->QUOTE && ok_abbr) |
5285 | if (a == SCHEME_V->QUOTE && ok_abbr) |
5164 | putstr (SCHEME_A_ "'"); |
5286 | putcharacter (SCHEME_A_ '\''); |
5165 | else if (a == SCHEME_V->QQUOTE && ok_abbr) |
5287 | else if (a == SCHEME_V->QQUOTE && ok_abbr) |
5166 | putstr (SCHEME_A_ "`"); |
5288 | putcharacter (SCHEME_A_ '`'); |
5167 | else if (a == SCHEME_V->UNQUOTE && ok_abbr) |
5289 | else if (a == SCHEME_V->UNQUOTE && ok_abbr) |
5168 | putstr (SCHEME_A_ ","); |
5290 | putcharacter (SCHEME_A_ ','); |
5169 | else if (a == SCHEME_V->UNQUOTESP && ok_abbr) |
5291 | else if (a == SCHEME_V->UNQUOTESP && ok_abbr) |
5170 | putstr (SCHEME_A_ ",@"); |
5292 | putstr (SCHEME_A_ ",@"); |
5171 | else |
5293 | else |
5172 | { |
5294 | { |
5173 | putstr (SCHEME_A_ "("); |
5295 | putcharacter (SCHEME_A_ '('); |
5174 | s_save (SCHEME_A_ OP_P1LIST, b, NIL); |
5296 | s_save (SCHEME_A_ OP_P1LIST, b, NIL); |
5175 | SCHEME_V->args = a; |
5297 | SCHEME_V->args = a; |
5176 | } |
5298 | } |
5177 | |
5299 | |
5178 | s_goto (OP_P0LIST); |
5300 | s_goto (OP_P0LIST); |
… | |
… | |
5180 | |
5302 | |
5181 | case OP_P1LIST: |
5303 | case OP_P1LIST: |
5182 | if (is_pair (args)) |
5304 | if (is_pair (args)) |
5183 | { |
5305 | { |
5184 | s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL); |
5306 | s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL); |
5185 | putstr (SCHEME_A_ " "); |
5307 | putcharacter (SCHEME_A_ ' '); |
5186 | SCHEME_V->args = car (args); |
5308 | SCHEME_V->args = car (args); |
5187 | s_goto (OP_P0LIST); |
5309 | s_goto (OP_P0LIST); |
5188 | } |
5310 | } |
5189 | else if (is_vector (args)) |
5311 | else if (is_vector (args)) |
5190 | { |
5312 | { |
… | |
… | |
5198 | { |
5320 | { |
5199 | putstr (SCHEME_A_ " . "); |
5321 | putstr (SCHEME_A_ " . "); |
5200 | printatom (SCHEME_A_ args, SCHEME_V->print_flag); |
5322 | printatom (SCHEME_A_ args, SCHEME_V->print_flag); |
5201 | } |
5323 | } |
5202 | |
5324 | |
5203 | putstr (SCHEME_A_ ")"); |
5325 | putcharacter (SCHEME_A_ ')'); |
5204 | s_return (S_T); |
5326 | s_return (S_T); |
5205 | } |
5327 | } |
5206 | |
5328 | |
5207 | case OP_PVECFROM: |
5329 | case OP_PVECFROM: |
5208 | { |
5330 | { |
… | |
… | |
5210 | pointer vec = car (args); |
5332 | pointer vec = car (args); |
5211 | int len = veclength (vec); |
5333 | int len = veclength (vec); |
5212 | |
5334 | |
5213 | if (i == len) |
5335 | if (i == len) |
5214 | { |
5336 | { |
5215 | putstr (SCHEME_A_ ")"); |
5337 | putcharacter (SCHEME_A_ ')'); |
5216 | s_return (S_T); |
5338 | s_return (S_T); |
5217 | } |
5339 | } |
5218 | else |
5340 | else |
5219 | { |
5341 | { |
5220 | pointer elem = vector_get (vec, i); |
5342 | pointer elem = vector_get (vec, i); |
… | |
… | |
5222 | ivalue_unchecked (cdr (args)) = i + 1; |
5344 | ivalue_unchecked (cdr (args)) = i + 1; |
5223 | s_save (SCHEME_A_ OP_PVECFROM, args, NIL); |
5345 | s_save (SCHEME_A_ OP_PVECFROM, args, NIL); |
5224 | SCHEME_V->args = elem; |
5346 | SCHEME_V->args = elem; |
5225 | |
5347 | |
5226 | if (i > 0) |
5348 | if (i > 0) |
5227 | putstr (SCHEME_A_ " "); |
5349 | putcharacter (SCHEME_A_ ' '); |
5228 | |
5350 | |
5229 | s_goto (OP_P0LIST); |
5351 | s_goto (OP_P0LIST); |
5230 | } |
5352 | } |
5231 | } |
5353 | } |
5232 | } |
5354 | } |
5233 | |
5355 | |
5234 | if (USE_ERROR_CHECKING) abort (); |
5356 | if (USE_ERROR_CHECKING) abort (); |
5235 | } |
5357 | } |
5236 | |
5358 | |
5237 | static int |
5359 | /* list ops */ |
|
|
5360 | ecb_hot static int |
5238 | opexe_6 (SCHEME_P_ enum scheme_opcodes op) |
5361 | opexe_6 (SCHEME_P_ enum scheme_opcodes op) |
5239 | { |
5362 | { |
5240 | pointer args = SCHEME_V->args; |
5363 | pointer args = SCHEME_V->args; |
5241 | pointer a = car (args); |
5364 | pointer a = car (args); |
5242 | pointer x, y; |
5365 | pointer x, y; |
… | |
… | |
5265 | break; |
5388 | break; |
5266 | } |
5389 | } |
5267 | |
5390 | |
5268 | if (is_pair (y)) |
5391 | if (is_pair (y)) |
5269 | s_return (car (y)); |
5392 | s_return (car (y)); |
5270 | else |
5393 | |
5271 | s_return (S_F); |
5394 | s_return (S_F); |
5272 | |
|
|
5273 | |
5395 | |
5274 | case OP_GET_CLOSURE: /* get-closure-code *//* a.k */ |
5396 | case OP_GET_CLOSURE: /* get-closure-code *//* a.k */ |
5275 | SCHEME_V->args = a; |
5397 | SCHEME_V->args = a; |
5276 | |
5398 | |
5277 | if (SCHEME_V->args == NIL) |
5399 | if (SCHEME_V->args == NIL) |
5278 | s_return (S_F); |
5400 | s_return (S_F); |
5279 | else if (is_closure (SCHEME_V->args)) |
5401 | else if (is_closure (SCHEME_V->args) || is_macro (SCHEME_V->args)) |
5280 | s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value))); |
5402 | s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value))); |
5281 | else if (is_macro (SCHEME_V->args)) |
5403 | |
5282 | s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value))); |
|
|
5283 | else |
|
|
5284 | s_return (S_F); |
5404 | s_return (S_F); |
5285 | |
5405 | |
5286 | case OP_CLOSUREP: /* closure? */ |
5406 | case OP_CLOSUREP: /* closure? */ |
5287 | /* |
5407 | /* |
5288 | * Note, macro object is also a closure. |
5408 | * Note, macro object is also a closure. |
5289 | * Therefore, (closure? <#MACRO>) ==> #t |
5409 | * Therefore, (closure? <#MACRO>) ==> #t |
… | |
… | |
5300 | |
5420 | |
5301 | /* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */ |
5421 | /* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */ |
5302 | typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes); |
5422 | typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes); |
5303 | |
5423 | |
5304 | typedef int (*test_predicate)(pointer); |
5424 | typedef int (*test_predicate)(pointer); |
5305 | static int |
5425 | |
|
|
5426 | ecb_hot static int |
5306 | tst_any (pointer p) |
5427 | tst_any (pointer p) |
5307 | { |
5428 | { |
5308 | return 1; |
5429 | return 1; |
5309 | } |
5430 | } |
5310 | |
5431 | |
5311 | static int |
5432 | ecb_hot static int |
5312 | tst_inonneg (pointer p) |
5433 | tst_inonneg (pointer p) |
5313 | { |
5434 | { |
5314 | return is_integer (p) && ivalue_unchecked (p) >= 0; |
5435 | return is_integer (p) && ivalue_unchecked (p) >= 0; |
5315 | } |
5436 | } |
5316 | |
5437 | |
5317 | static int |
5438 | ecb_hot static int |
5318 | tst_is_list (SCHEME_P_ pointer p) |
5439 | tst_is_list (SCHEME_P_ pointer p) |
5319 | { |
5440 | { |
5320 | return p == NIL || is_pair (p); |
5441 | return p == NIL || is_pair (p); |
5321 | } |
5442 | } |
5322 | |
5443 | |
… | |
… | |
5365 | #define OP_DEF(func,name,minarity,maxarity,argtest,op) name "\x00" |
5486 | #define OP_DEF(func,name,minarity,maxarity,argtest,op) name "\x00" |
5366 | #include "opdefines.h" |
5487 | #include "opdefines.h" |
5367 | #undef OP_DEF |
5488 | #undef OP_DEF |
5368 | ; |
5489 | ; |
5369 | |
5490 | |
5370 | static const char * |
5491 | ecb_cold static const char * |
5371 | opname (int idx) |
5492 | opname (int idx) |
5372 | { |
5493 | { |
5373 | const char *name = opnames; |
5494 | const char *name = opnames; |
5374 | |
5495 | |
5375 | /* should do this at compile time, but would require external program, right? */ |
5496 | /* should do this at compile time, but would require external program, right? */ |
… | |
… | |
5377 | name += strlen (name) + 1; |
5498 | name += strlen (name) + 1; |
5378 | |
5499 | |
5379 | return *name ? name : "ILLEGAL"; |
5500 | return *name ? name : "ILLEGAL"; |
5380 | } |
5501 | } |
5381 | |
5502 | |
5382 | static const char * |
5503 | ecb_cold static const char * |
5383 | procname (pointer x) |
5504 | procname (pointer x) |
5384 | { |
5505 | { |
5385 | return opname (procnum (x)); |
5506 | return opname (procnum (x)); |
5386 | } |
5507 | } |
5387 | |
5508 | |
… | |
… | |
5407 | #undef OP_DEF |
5528 | #undef OP_DEF |
5408 | {0} |
5529 | {0} |
5409 | }; |
5530 | }; |
5410 | |
5531 | |
5411 | /* kernel of this interpreter */ |
5532 | /* kernel of this interpreter */ |
5412 | static void ecb_hot |
5533 | ecb_hot static void |
5413 | Eval_Cycle (SCHEME_P_ enum scheme_opcodes op) |
5534 | Eval_Cycle (SCHEME_P_ enum scheme_opcodes op) |
5414 | { |
5535 | { |
5415 | SCHEME_V->op = op; |
5536 | SCHEME_V->op = op; |
5416 | |
5537 | |
5417 | for (;;) |
5538 | for (;;) |
… | |
… | |
5508 | } |
5629 | } |
5509 | } |
5630 | } |
5510 | |
5631 | |
5511 | /* ========== Initialization of internal keywords ========== */ |
5632 | /* ========== Initialization of internal keywords ========== */ |
5512 | |
5633 | |
5513 | static void |
5634 | ecb_cold static void |
5514 | assign_syntax (SCHEME_P_ const char *name) |
5635 | assign_syntax (SCHEME_P_ const char *name) |
5515 | { |
5636 | { |
5516 | pointer x = oblist_add_by_name (SCHEME_A_ name); |
5637 | pointer x = oblist_add_by_name (SCHEME_A_ name); |
5517 | set_typeflag (x, typeflag (x) | T_SYNTAX); |
5638 | set_typeflag (x, typeflag (x) | T_SYNTAX); |
5518 | } |
5639 | } |
5519 | |
5640 | |
5520 | static void |
5641 | ecb_cold static void |
5521 | assign_proc (SCHEME_P_ enum scheme_opcodes op, const char *name) |
5642 | assign_proc (SCHEME_P_ enum scheme_opcodes op, const char *name) |
5522 | { |
5643 | { |
5523 | pointer x = mk_symbol (SCHEME_A_ name); |
5644 | pointer x = mk_symbol (SCHEME_A_ name); |
5524 | pointer y = mk_proc (SCHEME_A_ op); |
5645 | pointer y = mk_proc (SCHEME_A_ op); |
5525 | new_slot_in_env (SCHEME_A_ x, y); |
5646 | new_slot_in_env (SCHEME_A_ x, y); |
… | |
… | |
5533 | ivalue_unchecked (y) = op; |
5654 | ivalue_unchecked (y) = op; |
5534 | return y; |
5655 | return y; |
5535 | } |
5656 | } |
5536 | |
5657 | |
5537 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5658 | /* Hard-coded for the given keywords. Remember to rewrite if more are added! */ |
5538 | static int |
5659 | ecb_hot static int |
5539 | syntaxnum (pointer p) |
5660 | syntaxnum (pointer p) |
5540 | { |
5661 | { |
5541 | const char *s = strvalue (p); |
5662 | const char *s = strvalue (p); |
5542 | |
5663 | |
5543 | switch (strlength (p)) |
5664 | switch (strlength (p)) |
… | |
… | |
5660 | #endif |
5781 | #endif |
5661 | } |
5782 | } |
5662 | |
5783 | |
5663 | SCHEME_V->gc_verbose = 0; |
5784 | SCHEME_V->gc_verbose = 0; |
5664 | dump_stack_initialize (SCHEME_A); |
5785 | dump_stack_initialize (SCHEME_A); |
5665 | SCHEME_V->code = NIL; |
5786 | SCHEME_V->code = NIL; |
5666 | SCHEME_V->args = NIL; |
5787 | SCHEME_V->args = NIL; |
5667 | SCHEME_V->envir = NIL; |
5788 | SCHEME_V->envir = NIL; |
|
|
5789 | SCHEME_V->value = NIL; |
5668 | SCHEME_V->tracing = 0; |
5790 | SCHEME_V->tracing = 0; |
5669 | |
5791 | |
5670 | /* init NIL */ |
5792 | /* init NIL */ |
5671 | set_typeflag (NIL, T_ATOM | T_MARK); |
5793 | set_typeflag (NIL, T_ATOM | T_MARK); |
5672 | set_car (NIL, NIL); |
5794 | set_car (NIL, NIL); |
… | |
… | |
5728 | |
5850 | |
5729 | return !SCHEME_V->no_memory; |
5851 | return !SCHEME_V->no_memory; |
5730 | } |
5852 | } |
5731 | |
5853 | |
5732 | #if USE_PORTS |
5854 | #if USE_PORTS |
5733 | void |
5855 | ecb_cold void |
5734 | scheme_set_input_port_file (SCHEME_P_ int fin) |
5856 | scheme_set_input_port_file (SCHEME_P_ int fin) |
5735 | { |
5857 | { |
5736 | SCHEME_V->inport = port_from_file (SCHEME_A_ fin, port_input); |
5858 | SCHEME_V->inport = port_from_file (SCHEME_A_ fin, port_input); |
5737 | } |
5859 | } |
5738 | |
5860 | |
5739 | void |
5861 | ecb_cold void |
5740 | scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end) |
5862 | scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end) |
5741 | { |
5863 | { |
5742 | SCHEME_V->inport = port_from_string (SCHEME_A_ start, past_the_end, port_input); |
5864 | SCHEME_V->inport = port_from_string (SCHEME_A_ start, past_the_end, port_input); |
5743 | } |
5865 | } |
5744 | |
5866 | |
5745 | void |
5867 | ecb_cold void |
5746 | scheme_set_output_port_file (SCHEME_P_ int fout) |
5868 | scheme_set_output_port_file (SCHEME_P_ int fout) |
5747 | { |
5869 | { |
5748 | SCHEME_V->outport = port_from_file (SCHEME_A_ fout, port_output); |
5870 | SCHEME_V->outport = port_from_file (SCHEME_A_ fout, port_output); |
5749 | } |
5871 | } |
5750 | |
5872 | |
5751 | void |
5873 | ecb_cold void |
5752 | scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end) |
5874 | scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end) |
5753 | { |
5875 | { |
5754 | SCHEME_V->outport = port_from_string (SCHEME_A_ start, past_the_end, port_output); |
5876 | SCHEME_V->outport = port_from_string (SCHEME_A_ start, past_the_end, port_output); |
5755 | } |
5877 | } |
5756 | #endif |
5878 | #endif |
5757 | |
5879 | |
5758 | void |
5880 | ecb_cold void |
5759 | scheme_set_external_data (SCHEME_P_ void *p) |
5881 | scheme_set_external_data (SCHEME_P_ void *p) |
5760 | { |
5882 | { |
5761 | SCHEME_V->ext_data = p; |
5883 | SCHEME_V->ext_data = p; |
5762 | } |
5884 | } |
5763 | |
5885 | |
… | |
… | |
5795 | SCHEME_V->loadport = NIL; |
5917 | SCHEME_V->loadport = NIL; |
5796 | SCHEME_V->gc_verbose = 0; |
5918 | SCHEME_V->gc_verbose = 0; |
5797 | gc (SCHEME_A_ NIL, NIL); |
5919 | gc (SCHEME_A_ NIL, NIL); |
5798 | |
5920 | |
5799 | for (i = 0; i <= SCHEME_V->last_cell_seg; i++) |
5921 | for (i = 0; i <= SCHEME_V->last_cell_seg; i++) |
5800 | free (SCHEME_V->alloc_seg[i]); |
5922 | free (SCHEME_V->cell_seg[i]); |
5801 | |
5923 | |
5802 | #if SHOW_ERROR_LINE |
5924 | #if SHOW_ERROR_LINE |
5803 | for (i = 0; i <= SCHEME_V->file_i; i++) |
5925 | for (i = 0; i <= SCHEME_V->file_i; i++) |
5804 | { |
|
|
5805 | if (SCHEME_V->load_stack[i].kind & port_file) |
5926 | if (SCHEME_V->load_stack[i].kind & port_file) |
5806 | { |
5927 | { |
5807 | fname = SCHEME_V->load_stack[i].rep.stdio.filename; |
5928 | fname = SCHEME_V->load_stack[i].rep.stdio.filename; |
5808 | |
5929 | |
5809 | if (fname) |
5930 | if (fname) |
5810 | free (fname); |
5931 | free (fname); |
5811 | } |
5932 | } |
5812 | } |
|
|
5813 | #endif |
5933 | #endif |
5814 | } |
5934 | } |
5815 | |
5935 | |
5816 | void |
5936 | ecb_cold void |
5817 | scheme_load_file (SCHEME_P_ int fin) |
5937 | scheme_load_file (SCHEME_P_ int fin) |
5818 | { |
5938 | { |
5819 | scheme_load_named_file (SCHEME_A_ fin, 0); |
5939 | scheme_load_named_file (SCHEME_A_ fin, 0); |
5820 | } |
5940 | } |
5821 | |
5941 | |
5822 | void |
5942 | ecb_cold void |
5823 | scheme_load_named_file (SCHEME_P_ int fin, const char *filename) |
5943 | scheme_load_named_file (SCHEME_P_ int fin, const char *filename) |
5824 | { |
5944 | { |
5825 | dump_stack_reset (SCHEME_A); |
5945 | dump_stack_reset (SCHEME_A); |
5826 | SCHEME_V->envir = SCHEME_V->global_env; |
5946 | SCHEME_V->envir = SCHEME_V->global_env; |
5827 | SCHEME_V->file_i = 0; |
5947 | SCHEME_V->file_i = 0; |
5828 | SCHEME_V->load_stack[0].unget = -1; |
5948 | SCHEME_V->load_stack[0].unget = -1; |
5829 | SCHEME_V->load_stack[0].kind = port_input | port_file; |
5949 | SCHEME_V->load_stack[0].kind = port_input | port_file; |
5830 | SCHEME_V->load_stack[0].rep.stdio.file = fin; |
5950 | SCHEME_V->load_stack[0].rep.stdio.file = fin; |
5831 | #if USE_PORTS |
|
|
5832 | SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); |
5951 | SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); |
5833 | #endif |
|
|
5834 | SCHEME_V->retcode = 0; |
5952 | SCHEME_V->retcode = 0; |
5835 | |
5953 | |
5836 | #if USE_PORTS |
|
|
5837 | if (fin == STDIN_FILENO) |
5954 | if (fin == STDIN_FILENO) |
5838 | SCHEME_V->interactive_repl = 1; |
5955 | SCHEME_V->interactive_repl = 1; |
5839 | #endif |
|
|
5840 | |
5956 | |
5841 | #if USE_PORTS |
5957 | #if USE_PORTS |
5842 | #if SHOW_ERROR_LINE |
5958 | #if SHOW_ERROR_LINE |
5843 | SCHEME_V->load_stack[0].rep.stdio.curr_line = 0; |
5959 | SCHEME_V->load_stack[0].rep.stdio.curr_line = 0; |
5844 | |
5960 | |
… | |
… | |
5848 | #endif |
5964 | #endif |
5849 | |
5965 | |
5850 | SCHEME_V->inport = SCHEME_V->loadport; |
5966 | SCHEME_V->inport = SCHEME_V->loadport; |
5851 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
5967 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
5852 | Eval_Cycle (SCHEME_A_ OP_T0LVL); |
5968 | Eval_Cycle (SCHEME_A_ OP_T0LVL); |
|
|
5969 | |
5853 | set_typeflag (SCHEME_V->loadport, T_ATOM); |
5970 | set_typeflag (SCHEME_V->loadport, T_ATOM); |
5854 | |
5971 | |
5855 | if (SCHEME_V->retcode == 0) |
5972 | if (SCHEME_V->retcode == 0) |
5856 | SCHEME_V->retcode = SCHEME_V->nesting != 0; |
5973 | SCHEME_V->retcode = SCHEME_V->nesting != 0; |
5857 | } |
5974 | } |
5858 | |
5975 | |
5859 | void |
5976 | ecb_cold void |
5860 | scheme_load_string (SCHEME_P_ const char *cmd) |
5977 | scheme_load_string (SCHEME_P_ const char *cmd) |
5861 | { |
5978 | { |
|
|
5979 | #if USE_PORTs |
5862 | dump_stack_reset (SCHEME_A); |
5980 | dump_stack_reset (SCHEME_A); |
5863 | SCHEME_V->envir = SCHEME_V->global_env; |
5981 | SCHEME_V->envir = SCHEME_V->global_env; |
5864 | SCHEME_V->file_i = 0; |
5982 | SCHEME_V->file_i = 0; |
5865 | SCHEME_V->load_stack[0].kind = port_input | port_string; |
5983 | SCHEME_V->load_stack[0].kind = port_input | port_string; |
5866 | SCHEME_V->load_stack[0].rep.string.start = (char *)cmd; /* This func respects const */ |
5984 | SCHEME_V->load_stack[0].rep.string.start = (char *)cmd; /* This func respects const */ |
5867 | SCHEME_V->load_stack[0].rep.string.past_the_end = (char *)cmd + strlen (cmd); |
5985 | SCHEME_V->load_stack[0].rep.string.past_the_end = (char *)cmd + strlen (cmd); |
5868 | SCHEME_V->load_stack[0].rep.string.curr = (char *)cmd; |
5986 | SCHEME_V->load_stack[0].rep.string.curr = (char *)cmd; |
5869 | #if USE_PORTS |
|
|
5870 | SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); |
5987 | SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); |
5871 | #endif |
|
|
5872 | SCHEME_V->retcode = 0; |
5988 | SCHEME_V->retcode = 0; |
5873 | SCHEME_V->interactive_repl = 0; |
5989 | SCHEME_V->interactive_repl = 0; |
5874 | SCHEME_V->inport = SCHEME_V->loadport; |
5990 | SCHEME_V->inport = SCHEME_V->loadport; |
5875 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
5991 | SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); |
5876 | Eval_Cycle (SCHEME_A_ OP_T0LVL); |
5992 | Eval_Cycle (SCHEME_A_ OP_T0LVL); |
5877 | set_typeflag (SCHEME_V->loadport, T_ATOM); |
5993 | set_typeflag (SCHEME_V->loadport, T_ATOM); |
5878 | |
5994 | |
5879 | if (SCHEME_V->retcode == 0) |
5995 | if (SCHEME_V->retcode == 0) |
5880 | SCHEME_V->retcode = SCHEME_V->nesting != 0; |
5996 | SCHEME_V->retcode = SCHEME_V->nesting != 0; |
|
|
5997 | #else |
|
|
5998 | abort (); |
|
|
5999 | #endif |
5881 | } |
6000 | } |
5882 | |
6001 | |
5883 | void |
6002 | ecb_cold void |
5884 | scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value) |
6003 | scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value) |
5885 | { |
6004 | { |
5886 | pointer x; |
6005 | pointer x; |
5887 | |
6006 | |
5888 | x = find_slot_in_env (SCHEME_A_ envir, symbol, 0); |
6007 | x = find_slot_in_env (SCHEME_A_ envir, symbol, 0); |
… | |
… | |
5893 | new_slot_spec_in_env (SCHEME_A_ envir, symbol, value); |
6012 | new_slot_spec_in_env (SCHEME_A_ envir, symbol, value); |
5894 | } |
6013 | } |
5895 | |
6014 | |
5896 | #if !STANDALONE |
6015 | #if !STANDALONE |
5897 | |
6016 | |
5898 | void |
6017 | ecb_cold void |
5899 | scheme_register_foreign_func (scheme * sc, scheme_registerable * sr) |
6018 | scheme_register_foreign_func (scheme * sc, scheme_registerable * sr) |
5900 | { |
6019 | { |
5901 | scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ sr->name), mk_foreign_func (SCHEME_A_ sr->f)); |
6020 | scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ sr->name), mk_foreign_func (SCHEME_A_ sr->f)); |
5902 | } |
6021 | } |
5903 | |
6022 | |
5904 | void |
6023 | ecb_cold void |
5905 | scheme_register_foreign_func_list (scheme * sc, scheme_registerable * list, int count) |
6024 | scheme_register_foreign_func_list (scheme * sc, scheme_registerable * list, int count) |
5906 | { |
6025 | { |
5907 | int i; |
6026 | int i; |
5908 | |
6027 | |
5909 | for (i = 0; i < count; i++) |
6028 | for (i = 0; i < count; i++) |
5910 | scheme_register_foreign_func (SCHEME_A_ list + i); |
6029 | scheme_register_foreign_func (SCHEME_A_ list + i); |
5911 | } |
6030 | } |
5912 | |
6031 | |
5913 | pointer |
6032 | ecb_cold pointer |
5914 | scheme_apply0 (SCHEME_P_ const char *procname) |
6033 | scheme_apply0 (SCHEME_P_ const char *procname) |
5915 | { |
6034 | { |
5916 | return scheme_eval (SCHEME_A_ cons (mk_symbol (SCHEME_A_ procname), NIL)); |
6035 | return scheme_eval (SCHEME_A_ cons (mk_symbol (SCHEME_A_ procname), NIL)); |
5917 | } |
6036 | } |
5918 | |
6037 | |
5919 | void |
6038 | ecb_cold void |
5920 | save_from_C_call (SCHEME_P) |
6039 | save_from_C_call (SCHEME_P) |
5921 | { |
6040 | { |
5922 | pointer saved_data = cons (car (S_SINK), |
6041 | pointer saved_data = cons (car (S_SINK), |
5923 | cons (SCHEME_V->envir, |
6042 | cons (SCHEME_V->envir, |
5924 | SCHEME_V->dump)); |
6043 | SCHEME_V->dump)); |
… | |
… | |
5928 | /* Truncate the dump stack so TS will return here when done, not |
6047 | /* Truncate the dump stack so TS will return here when done, not |
5929 | directly resume pre-C-call operations. */ |
6048 | directly resume pre-C-call operations. */ |
5930 | dump_stack_reset (SCHEME_A); |
6049 | dump_stack_reset (SCHEME_A); |
5931 | } |
6050 | } |
5932 | |
6051 | |
5933 | void |
6052 | ecb_cold void |
5934 | restore_from_C_call (SCHEME_P) |
6053 | restore_from_C_call (SCHEME_P) |
5935 | { |
6054 | { |
5936 | set_car (S_SINK, caar (SCHEME_V->c_nest)); |
6055 | set_car (S_SINK, caar (SCHEME_V->c_nest)); |
5937 | SCHEME_V->envir = cadar (SCHEME_V->c_nest); |
6056 | SCHEME_V->envir = cadar (SCHEME_V->c_nest); |
5938 | SCHEME_V->dump = cdr (cdar (SCHEME_V->c_nest)); |
6057 | SCHEME_V->dump = cdr (cdar (SCHEME_V->c_nest)); |
5939 | /* Pop */ |
6058 | /* Pop */ |
5940 | SCHEME_V->c_nest = cdr (SCHEME_V->c_nest); |
6059 | SCHEME_V->c_nest = cdr (SCHEME_V->c_nest); |
5941 | } |
6060 | } |
5942 | |
6061 | |
5943 | /* "func" and "args" are assumed to be already eval'ed. */ |
6062 | /* "func" and "args" are assumed to be already eval'ed. */ |
5944 | pointer |
6063 | ecb_cold pointer |
5945 | scheme_call (SCHEME_P_ pointer func, pointer args) |
6064 | scheme_call (SCHEME_P_ pointer func, pointer args) |
5946 | { |
6065 | { |
5947 | int old_repl = SCHEME_V->interactive_repl; |
6066 | int old_repl = SCHEME_V->interactive_repl; |
5948 | |
6067 | |
5949 | SCHEME_V->interactive_repl = 0; |
6068 | SCHEME_V->interactive_repl = 0; |
… | |
… | |
5956 | SCHEME_V->interactive_repl = old_repl; |
6075 | SCHEME_V->interactive_repl = old_repl; |
5957 | restore_from_C_call (SCHEME_A); |
6076 | restore_from_C_call (SCHEME_A); |
5958 | return SCHEME_V->value; |
6077 | return SCHEME_V->value; |
5959 | } |
6078 | } |
5960 | |
6079 | |
5961 | pointer |
6080 | ecb_cold pointer |
5962 | scheme_eval (SCHEME_P_ pointer obj) |
6081 | scheme_eval (SCHEME_P_ pointer obj) |
5963 | { |
6082 | { |
5964 | int old_repl = SCHEME_V->interactive_repl; |
6083 | int old_repl = SCHEME_V->interactive_repl; |
5965 | |
6084 | |
5966 | SCHEME_V->interactive_repl = 0; |
6085 | SCHEME_V->interactive_repl = 0; |
… | |
… | |
5978 | |
6097 | |
5979 | /* ========== Main ========== */ |
6098 | /* ========== Main ========== */ |
5980 | |
6099 | |
5981 | #if STANDALONE |
6100 | #if STANDALONE |
5982 | |
6101 | |
5983 | int |
6102 | ecb_cold int |
5984 | main (int argc, char **argv) |
6103 | main (int argc, char **argv) |
5985 | { |
6104 | { |
5986 | # if USE_MULTIPLICITY |
6105 | # if USE_MULTIPLICITY |
5987 | scheme ssc; |
6106 | scheme ssc; |
5988 | scheme *const SCHEME_V = &ssc; |
6107 | scheme *const SCHEME_V = &ssc; |
… | |
… | |
5990 | # endif |
6109 | # endif |
5991 | int fin; |
6110 | int fin; |
5992 | char *file_name = InitFile; |
6111 | char *file_name = InitFile; |
5993 | int retcode; |
6112 | int retcode; |
5994 | int isfile = 1; |
6113 | int isfile = 1; |
|
|
6114 | #if EXPERIMENT |
5995 | system ("ps v $PPID");//D |
6115 | system ("ps v $PPID"); |
|
|
6116 | #endif |
5996 | |
6117 | |
5997 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
6118 | if (argc == 2 && strcmp (argv[1], "-?") == 0) |
5998 | { |
6119 | { |
5999 | putstr (SCHEME_A_ "Usage: tinyscheme -?\n"); |
6120 | putstr (SCHEME_A_ "Usage: tinyscheme -?\n"); |
6000 | putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n"); |
6121 | putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n"); |
… | |
… | |
6029 | } |
6150 | } |
6030 | #endif |
6151 | #endif |
6031 | |
6152 | |
6032 | do |
6153 | do |
6033 | { |
6154 | { |
6034 | #if USE_PORTS |
|
|
6035 | if (strcmp (file_name, "-") == 0) |
6155 | if (strcmp (file_name, "-") == 0) |
6036 | fin = STDIN_FILENO; |
6156 | fin = STDIN_FILENO; |
6037 | else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0) |
6157 | else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0) |
6038 | { |
6158 | { |
6039 | pointer args = NIL; |
6159 | pointer args = NIL; |
… | |
… | |
6057 | scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args); |
6177 | scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args); |
6058 | |
6178 | |
6059 | } |
6179 | } |
6060 | else |
6180 | else |
6061 | fin = open (file_name, O_RDONLY); |
6181 | fin = open (file_name, O_RDONLY); |
6062 | #endif |
|
|
6063 | |
6182 | |
6064 | if (isfile && fin < 0) |
6183 | if (isfile && fin < 0) |
6065 | { |
6184 | { |
6066 | putstr (SCHEME_A_ "Could not open file "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); |
6185 | putstr (SCHEME_A_ "Could not open file "); |
|
|
6186 | putstr (SCHEME_A_ file_name); |
|
|
6187 | putcharacter (SCHEME_A_ '\n'); |
6067 | } |
6188 | } |
6068 | else |
6189 | else |
6069 | { |
6190 | { |
6070 | if (isfile) |
6191 | if (isfile) |
6071 | scheme_load_named_file (SCHEME_A_ fin, file_name); |
6192 | scheme_load_named_file (SCHEME_A_ fin, file_name); |
6072 | else |
6193 | else |
6073 | scheme_load_string (SCHEME_A_ file_name); |
6194 | scheme_load_string (SCHEME_A_ file_name); |
6074 | |
6195 | |
6075 | #if USE_PORTS |
|
|
6076 | if (!isfile || fin != STDIN_FILENO) |
6196 | if (!isfile || fin != STDIN_FILENO) |
6077 | { |
6197 | { |
6078 | if (SCHEME_V->retcode != 0) |
6198 | if (SCHEME_V->retcode != 0) |
6079 | { |
6199 | { |
6080 | putstr (SCHEME_A_ "Errors encountered reading "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); |
6200 | putstr (SCHEME_A_ "Errors encountered reading "); |
|
|
6201 | putstr (SCHEME_A_ file_name); |
|
|
6202 | putcharacter (SCHEME_A_ '\n'); |
6081 | } |
6203 | } |
6082 | |
6204 | |
6083 | if (isfile) |
6205 | if (isfile) |
6084 | close (fin); |
6206 | close (fin); |
6085 | } |
6207 | } |
6086 | #endif |
|
|
6087 | } |
6208 | } |
6088 | |
6209 | |
6089 | file_name = *argv++; |
6210 | file_name = *argv++; |
6090 | } |
6211 | } |
6091 | while (file_name != 0); |
6212 | while (file_name != 0); |