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

Comparing microscheme/scheme.c (file contents):
Revision 1.55 by root, Tue Dec 1 03:03:11 2015 UTC vs.
Revision 1.69 by root, Mon Dec 7 22:12:53 2015 UTC

16 * (MINISCM) This is a revised and modified version by Akira KIDA. 16 * (MINISCM) This is a revised and modified version by Akira KIDA.
17 * (MINISCM) current version is 0.85k4 (15 May 1994) 17 * (MINISCM) current version is 0.85k4 (15 May 1994)
18 * 18 *
19 */ 19 */
20 20
21#define EXPERIMENT 1 21#define _POSIX_C_SOURCE 200201
22 22#define _XOPEN_SOURCE 600
23#if 1 23#define _GNU_SOURCE 1 /* for malloc mremap */
24#define PAGE_SIZE 4096 /* does not work on sparc/alpha */
25#include "malloc.c"
26#endif
27 24
28#define SCHEME_SOURCE 25#define SCHEME_SOURCE
29#include "scheme-private.h" 26#include "scheme-private.h"
30#ifndef WIN32 27#ifndef WIN32
31# include <unistd.h> 28# include <unistd.h>
32#endif 29#endif
33#if USE_MATH 30#if USE_MATH
34# include <math.h> 31# include <math.h>
35#endif 32#endif
36 33
34#define ECB_NO_THREADS 1
37#include "ecb.h" 35#include "ecb.h"
38 36
39#include <sys/types.h> 37#include <sys/types.h>
40#include <sys/stat.h> 38#include <sys/stat.h>
41#include <fcntl.h> 39#include <fcntl.h>
49#include <string.h> 47#include <string.h>
50 48
51#include <limits.h> 49#include <limits.h>
52#include <inttypes.h> 50#include <inttypes.h>
53#include <float.h> 51#include <float.h>
54//#include <ctype.h> 52
53#if !USE_SYSTEM_MALLOC
54# define PAGE_SIZE 4096 /* does not work on sparc/alpha */
55# include "malloc.c"
56# define malloc(n) tiny_malloc (n)
57# define realloc(p,n) tiny_realloc (p, n)
58# define free(p) tiny_free (p)
59#endif
55 60
56#if '1' != '0' + 1 \ 61#if '1' != '0' + 1 \
57 || '2' != '0' + 2 || '3' != '0' + 3 || '4' != '0' + 4 || '5' != '0' + 5 \ 62 || '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 \ 63 || '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 \ 64 || 'b' != 'a' + 1 || 'c' != 'a' + 2 || 'd' != 'a' + 3 || 'e' != 'a' + 4 \
91 96
92#if !USE_MULTIPLICITY 97#if !USE_MULTIPLICITY
93static scheme sc; 98static scheme sc;
94#endif 99#endif
95 100
96static void 101ecb_cold static void
97xbase (char *s, long n, int base) 102xbase (char *s, long n, int base)
98{ 103{
99 if (n < 0) 104 if (n < 0)
100 { 105 {
101 *s++ = '-'; 106 *s++ = '-';
116 char x = *s; *s = *p; *p = x; 121 char x = *s; *s = *p; *p = x;
117 --p; ++s; 122 --p; ++s;
118 } 123 }
119} 124}
120 125
121static void 126ecb_cold static void
122xnum (char *s, long n) 127xnum (char *s, long n)
123{ 128{
124 xbase (s, n, 10); 129 xbase (s, n, 10);
125} 130}
126 131
127static void 132ecb_cold static void
128putnum (SCHEME_P_ long n) 133putnum (SCHEME_P_ long n)
129{ 134{
130 char buf[64]; 135 char buf[64];
131 136
132 xnum (buf, n); 137 xnum (buf, n);
133 putstr (SCHEME_A_ buf); 138 putstr (SCHEME_A_ buf);
134} 139}
140
141#if USE_CHAR_CLASSIFIERS
142#include <ctype.h>
143#else
135 144
136static char 145static char
137xtoupper (char c) 146xtoupper (char c)
138{ 147{
139 if (c >= 'a' && c <= 'z') 148 if (c >= 'a' && c <= 'z')
159 168
160#define toupper(c) xtoupper (c) 169#define toupper(c) xtoupper (c)
161#define tolower(c) xtolower (c) 170#define tolower(c) xtolower (c)
162#define isdigit(c) xisdigit (c) 171#define isdigit(c) xisdigit (c)
163 172
173#endif
174
164#if USE_IGNORECASE 175#if USE_IGNORECASE
165static const char * 176ecb_cold static const char *
166xstrlwr (char *s) 177xstrlwr (char *s)
167{ 178{
168 const char *p = s; 179 const char *p = s;
169 180
170 while (*s) 181 while (*s)
183# define stricmp(a,b) strcmp (a, b) 194# define stricmp(a,b) strcmp (a, b)
184# define strlwr(s) (s) 195# define strlwr(s) (s)
185#endif 196#endif
186 197
187#ifndef prompt 198#ifndef prompt
188# define prompt "ts> " 199# define prompt "ms> "
189#endif 200#endif
190 201
191#ifndef InitFile 202#ifndef InitFile
192# define InitFile "init.scm" 203# define InitFile "init.scm"
193#endif 204#endif
194 205
195enum scheme_types 206enum scheme_types
196{ 207{
197 T_INTEGER, 208 T_INTEGER,
209 T_CHARACTER,
198 T_REAL, 210 T_REAL,
199 T_STRING, 211 T_STRING,
200 T_SYMBOL, 212 T_SYMBOL,
201 T_PROC, 213 T_PROC,
202 T_PAIR, /* also used for free cells */ 214 T_PAIR, /* also used for free cells */
203 T_CLOSURE, 215 T_CLOSURE,
216 T_BYTECODE, // temp
217 T_MACRO,
204 T_CONTINUATION, 218 T_CONTINUATION,
205 T_FOREIGN, 219 T_FOREIGN,
206 T_CHARACTER,
207 T_PORT, 220 T_PORT,
208 T_VECTOR, 221 T_VECTOR,
209 T_MACRO,
210 T_PROMISE, 222 T_PROMISE,
211 T_ENVIRONMENT, 223 T_ENVIRONMENT,
212 /* one more... */ 224 T_SPECIAL, // #t, #f, '(), eof-object
225
213 T_NUM_SYSTEM_TYPES 226 T_NUM_SYSTEM_TYPES
214}; 227};
215 228
216#define T_MASKTYPE 0x000f 229#define T_MASKTYPE 0x001f
217#define T_SYNTAX 0x0010 230#define T_SYNTAX 0x0020
218#define T_IMMUTABLE 0x0020 231#define T_IMMUTABLE 0x0040
219#define T_ATOM 0x0040 /* only for gc */ 232#define T_ATOM 0x0080 /* only for gc */
220#define T_MARK 0x0080 /* only for gc */ 233//#define T_MARK 0x0080 /* only for gc */
221 234
222/* num, for generic arithmetic */ 235/* num, for generic arithmetic */
223struct num 236struct num
224{ 237{
225 IVALUE ivalue; 238 IVALUE ivalue;
316string_value (pointer p) 329string_value (pointer p)
317{ 330{
318 return strvalue (p); 331 return strvalue (p);
319} 332}
320 333
321#define ivalue_unchecked(p) CELL(p)->object.ivalue 334#define ivalue_unchecked(p) (CELL(p)->object.ivalue + 0)
322#define set_ivalue(p,v) CELL(p)->object.ivalue = (v) 335#define set_ivalue(p,v) CELL(p)->object.ivalue = (v)
323 336
324#if USE_REAL 337#if USE_REAL
325#define rvalue_unchecked(p) CELL(p)->object.rvalue 338#define rvalue_unchecked(p) CELL(p)->object.rvalue
326#define set_rvalue(p,v) CELL(p)->object.rvalue = (v) 339#define set_rvalue(p,v) CELL(p)->object.rvalue = (v)
371 384
372static pointer cadar (pointer p) { return car (cdr (car (p))); } 385static pointer cadar (pointer p) { return car (cdr (car (p))); }
373static pointer caddr (pointer p) { return car (cdr (cdr (p))); } 386static pointer caddr (pointer p) { return car (cdr (cdr (p))); }
374static pointer cdaar (pointer p) { return cdr (car (car (p))); } 387static pointer cdaar (pointer p) { return cdr (car (car (p))); }
375 388
389static pointer cadddr (pointer p) { return car (car (car (cdr (p)))); }
390
376INTERFACE void 391INTERFACE void
377set_car (pointer p, pointer q) 392set_car (pointer p, pointer q)
378{ 393{
379 CELL(p)->object.cons.car = CELL (q); 394 CELL(p)->object.cons.car = CELL (q);
380} 395}
496 511
497#define is_atom(p) (typeflag (p) & T_ATOM) 512#define is_atom(p) (typeflag (p) & T_ATOM)
498#define setatom(p) set_typeflag ((p), typeflag (p) | T_ATOM) 513#define setatom(p) set_typeflag ((p), typeflag (p) | T_ATOM)
499#define clratom(p) set_typeflag ((p), typeflag (p) & ~T_ATOM) 514#define clratom(p) set_typeflag ((p), typeflag (p) & ~T_ATOM)
500 515
516#if 1
517#define is_mark(p) (CELL(p)->mark)
518#define setmark(p) (CELL(p)->mark = 1)
519#define clrmark(p) (CELL(p)->mark = 0)
520#else
501#define is_mark(p) (typeflag (p) & T_MARK) 521#define is_mark(p) (typeflag (p) & T_MARK)
502#define setmark(p) set_typeflag ((p), typeflag (p) | T_MARK) 522#define setmark(p) set_typeflag ((p), typeflag (p) | T_MARK)
503#define clrmark(p) set_typeflag ((p), typeflag (p) & ~T_MARK) 523#define clrmark(p) set_typeflag ((p), typeflag (p) & ~T_MARK)
524#endif
504 525
505INTERFACE int 526INTERFACE int
506is_immutable (pointer p) 527is_immutable (pointer p)
507{ 528{
508 return typeflag (p) & T_IMMUTABLE && USE_ERROR_CHECKING; 529 return typeflag (p) & T_IMMUTABLE && USE_ERROR_CHECKING;
520 proper list: length 541 proper list: length
521 circular list: -1 542 circular list: -1
522 not even a pair: -2 543 not even a pair: -2
523 dotted list: -2 minus length before dot 544 dotted list: -2 minus length before dot
524*/ 545*/
525INTERFACE int 546ecb_hot INTERFACE int
526list_length (SCHEME_P_ pointer a) 547list_length (SCHEME_P_ pointer a)
527{ 548{
528 int i = 0; 549 int i = 0;
529 pointer slow, fast; 550 pointer slow, fast;
530 551
569{ 590{
570 return list_length (SCHEME_A_ a) >= 0; 591 return list_length (SCHEME_A_ a) >= 0;
571} 592}
572 593
573#if USE_CHAR_CLASSIFIERS 594#if USE_CHAR_CLASSIFIERS
595
574ecb_inline int 596ecb_inline int
575Cisalpha (int c) 597Cisalpha (int c)
576{ 598{
577 return isascii (c) && isalpha (c); 599 return isascii (c) && isalpha (c);
578} 600}
636 "gs", 658 "gs",
637 "rs", 659 "rs",
638 "us" 660 "us"
639}; 661};
640 662
641static int 663ecb_cold static int
642is_ascii_name (const char *name, int *pc) 664is_ascii_name (const char *name, int *pc)
643{ 665{
644 int i; 666 int i;
645 667
646 for (i = 0; i < 32; i++) 668 for (i = 0; i < 32; i++)
668static int file_interactive (SCHEME_P); 690static int file_interactive (SCHEME_P);
669ecb_inline int is_one_of (const char *s, int c); 691ecb_inline int is_one_of (const char *s, int c);
670static int alloc_cellseg (SCHEME_P); 692static int alloc_cellseg (SCHEME_P);
671ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b); 693ecb_inline pointer get_cell (SCHEME_P_ pointer a, pointer b);
672static void finalize_cell (SCHEME_P_ pointer a); 694static void finalize_cell (SCHEME_P_ pointer a);
673static int count_consecutive_cells (pointer x, int needed);
674static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all); 695static pointer find_slot_in_env (SCHEME_P_ pointer env, pointer sym, int all);
675static pointer mk_number (SCHEME_P_ const num n); 696static pointer mk_number (SCHEME_P_ const num n);
676static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill); 697static char *store_string (SCHEME_P_ uint32_t len, const char *str, char fill);
677static pointer mk_vector (SCHEME_P_ uint32_t len); 698static pointer mk_vector (SCHEME_P_ uint32_t len);
678static pointer mk_atom (SCHEME_P_ char *q); 699static pointer mk_atom (SCHEME_P_ char *q);
679static pointer mk_sharp_const (SCHEME_P_ char *name); 700static pointer mk_sharp_const (SCHEME_P_ char *name);
680 701
702static pointer mk_port (SCHEME_P_ port *p);
703
681#if USE_PORTS 704#if USE_PORTS
682static pointer mk_port (SCHEME_P_ port *p);
683static pointer port_from_filename (SCHEME_P_ const char *fn, int prop); 705static pointer port_from_filename (SCHEME_P_ const char *fn, int prop);
684static pointer port_from_file (SCHEME_P_ int, int prop); 706static pointer port_from_file (SCHEME_P_ int, int prop);
685static pointer port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); 707static pointer port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop);
686static port *port_rep_from_filename (SCHEME_P_ const char *fn, int prop); 708static port *port_rep_from_filename (SCHEME_P_ const char *fn, int prop);
687static port *port_rep_from_file (SCHEME_P_ int, int prop); 709static port *port_rep_from_file (SCHEME_P_ int, int prop);
688static port *port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop); 710static port *port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop);
689static void port_close (SCHEME_P_ pointer p, int flag); 711static void port_close (SCHEME_P_ pointer p, int flag);
690#endif 712#endif
713
691static void mark (pointer a); 714static void mark (pointer a);
692static void gc (SCHEME_P_ pointer a, pointer b); 715static void gc (SCHEME_P_ pointer a, pointer b);
693static int basic_inchar (port *pt); 716static int basic_inchar (port *pt);
694static int inchar (SCHEME_P); 717static int inchar (SCHEME_P);
695static void backchar (SCHEME_P_ int c); 718static void backchar (SCHEME_P_ int c);
696static char *readstr_upto (SCHEME_P_ int skip, const char *delim); 719static char *readstr_upto (SCHEME_P_ int skip, const char *delim);
697static pointer readstrexp (SCHEME_P_ char delim); 720static pointer readstrexp (SCHEME_P_ char delim);
698ecb_inline int skipspace (SCHEME_P); 721static int skipspace (SCHEME_P);
699static int token (SCHEME_P); 722static int token (SCHEME_P);
700static void printslashstring (SCHEME_P_ char *s, int len); 723static void printslashstring (SCHEME_P_ char *s, int len);
701static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen); 724static void atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen);
702static void printatom (SCHEME_P_ pointer l, int f); 725static void printatom (SCHEME_P_ pointer l, int f);
703static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op); 726static pointer mk_proc (SCHEME_P_ enum scheme_opcodes op);
883#endif 906#endif
884#endif 907#endif
885} 908}
886 909
887/* allocate new cell segment */ 910/* allocate new cell segment */
888static int 911ecb_cold static int
889alloc_cellseg (SCHEME_P) 912alloc_cellseg (SCHEME_P)
890{ 913{
891 struct cell *newp; 914 struct cell *newp;
892 struct cell *last; 915 struct cell *last;
893 struct cell *p; 916 struct cell *p;
902 925
903 if (!cp && USE_ERROR_CHECKING) 926 if (!cp && USE_ERROR_CHECKING)
904 return k; 927 return k;
905 928
906 i = ++SCHEME_V->last_cell_seg; 929 i = ++SCHEME_V->last_cell_seg;
907 SCHEME_V->alloc_seg[i] = cp;
908 930
909 newp = (struct cell *)cp; 931 newp = (struct cell *)cp;
910 SCHEME_V->cell_seg[i] = newp; 932 SCHEME_V->cell_seg[i] = newp;
911 SCHEME_V->cell_segsize[i] = segsize; 933 SCHEME_V->cell_segsize[i] = segsize;
912 SCHEME_V->fcells += segsize; 934 SCHEME_V->fcells += segsize;
913 last = newp + segsize - 1; 935 last = newp + segsize - 1;
914 936
915 for (p = newp; p <= last; p++) 937 for (p = newp; p <= last; p++)
916 { 938 {
917 pointer cp = POINTER (p); 939 pointer cp = POINTER (p);
940 clrmark (cp);
918 set_typeflag (cp, T_PAIR); 941 set_typeflag (cp, T_PAIR);
919 set_car (cp, NIL); 942 set_car (cp, NIL);
920 set_cdr (cp, POINTER (p + 1)); 943 set_cdr (cp, POINTER (p + 1));
921 } 944 }
922 945
935 if (SCHEME_V->no_memory && USE_ERROR_CHECKING) 958 if (SCHEME_V->no_memory && USE_ERROR_CHECKING)
936 return S_SINK; 959 return S_SINK;
937 960
938 if (SCHEME_V->free_cell == NIL) 961 if (SCHEME_V->free_cell == NIL)
939 { 962 {
940 const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 1; 963 const int min_to_be_recovered = SCHEME_V->cell_segsize [SCHEME_V->last_cell_seg] >> 2;
941 964
942 gc (SCHEME_A_ a, b); 965 gc (SCHEME_A_ a, b);
943 966
944 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL) 967 if (SCHEME_V->fcells < min_to_be_recovered || SCHEME_V->free_cell == NIL)
945 { 968 {
964 } 987 }
965} 988}
966 989
967/* To retain recent allocs before interpreter knows about them - 990/* To retain recent allocs before interpreter knows about them -
968 Tehom */ 991 Tehom */
969static void 992ecb_hot static void
970push_recent_alloc (SCHEME_P_ pointer recent, pointer extra) 993push_recent_alloc (SCHEME_P_ pointer recent, pointer extra)
971{ 994{
972 pointer holder = get_cell_x (SCHEME_A_ recent, extra); 995 pointer holder = get_cell_x (SCHEME_A_ recent, extra);
973 996
974 set_typeflag (holder, T_PAIR); 997 set_typeflag (holder, T_PAIR);
976 set_car (holder, recent); 999 set_car (holder, recent);
977 set_cdr (holder, car (S_SINK)); 1000 set_cdr (holder, car (S_SINK));
978 set_car (S_SINK, holder); 1001 set_car (S_SINK, holder);
979} 1002}
980 1003
981static pointer 1004ecb_hot static pointer
982get_cell (SCHEME_P_ pointer a, pointer b) 1005get_cell (SCHEME_P_ pointer a, pointer b)
983{ 1006{
984 pointer cell = get_cell_x (SCHEME_A_ a, b); 1007 pointer cell = get_cell_x (SCHEME_A_ a, b);
985 1008
986 /* For right now, include "a" and "b" in "cell" so that gc doesn't 1009 /* For right now, include "a" and "b" in "cell" so that gc doesn't
1043#endif 1066#endif
1044 1067
1045/* Medium level cell allocation */ 1068/* Medium level cell allocation */
1046 1069
1047/* get new cons cell */ 1070/* get new cons cell */
1048pointer 1071ecb_hot static pointer
1049xcons (SCHEME_P_ pointer a, pointer b, int immutable) 1072xcons (SCHEME_P_ pointer a, pointer b)
1050{ 1073{
1051 pointer x = get_cell (SCHEME_A_ a, b); 1074 pointer x = get_cell (SCHEME_A_ a, b);
1052 1075
1053 set_typeflag (x, T_PAIR); 1076 set_typeflag (x, T_PAIR);
1054
1055 if (immutable)
1056 setimmutable (x);
1057 1077
1058 set_car (x, a); 1078 set_car (x, a);
1059 set_cdr (x, b); 1079 set_cdr (x, b);
1060 1080
1061 return x; 1081 return x;
1062} 1082}
1063 1083
1064static pointer 1084ecb_hot static pointer
1085ximmutable_cons (SCHEME_P_ pointer a, pointer b)
1086{
1087 pointer x = xcons (SCHEME_A_ a, b);
1088 setimmutable (x);
1089 return x;
1090}
1091
1092#define cons(a,b) xcons (SCHEME_A_ a, b)
1093#define immutable_cons(a,b) ximmutable_cons (SCHEME_A_ a, b)
1094
1095ecb_cold static pointer
1065generate_symbol (SCHEME_P_ const char *name) 1096generate_symbol (SCHEME_P_ const char *name)
1066{ 1097{
1067 pointer x = mk_string (SCHEME_A_ name); 1098 pointer x = mk_string (SCHEME_A_ name);
1068 setimmutable (x); 1099 setimmutable (x);
1069 set_typeflag (x, T_SYMBOL | T_ATOM); 1100 set_typeflag (x, T_SYMBOL | T_ATOM);
1075#ifndef USE_OBJECT_LIST 1106#ifndef USE_OBJECT_LIST
1076 1107
1077static int 1108static int
1078hash_fn (const char *key, int table_size) 1109hash_fn (const char *key, int table_size)
1079{ 1110{
1080 const unsigned char *p = key; 1111 const unsigned char *p = (unsigned char *)key;
1081 uint32_t hash = 2166136261; 1112 uint32_t hash = 2166136261U;
1082 1113
1083 while (*p) 1114 while (*p)
1084 hash = (hash ^ *p++) * 16777619; 1115 hash = (hash ^ *p++) * 16777619;
1085 1116
1086 return hash % table_size; 1117 return hash % table_size;
1087} 1118}
1088 1119
1089static pointer 1120ecb_cold static pointer
1090oblist_initial_value (SCHEME_P) 1121oblist_initial_value (SCHEME_P)
1091{ 1122{
1092 return mk_vector (SCHEME_A_ 461); /* probably should be bigger */ 1123 return mk_vector (SCHEME_A_ 461); /* probably should be bigger */
1093} 1124}
1094 1125
1095/* returns the new symbol */ 1126/* returns the new symbol */
1096static pointer 1127ecb_cold static pointer
1097oblist_add_by_name (SCHEME_P_ const char *name) 1128oblist_add_by_name (SCHEME_P_ const char *name)
1098{ 1129{
1099 pointer x = generate_symbol (SCHEME_A_ name); 1130 pointer x = generate_symbol (SCHEME_A_ name);
1100 int location = hash_fn (name, veclength (SCHEME_V->oblist)); 1131 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))); 1132 vector_set (SCHEME_V->oblist, location, immutable_cons (x, vector_get (SCHEME_V->oblist, location)));
1102 return x; 1133 return x;
1103} 1134}
1104 1135
1105ecb_inline pointer 1136ecb_cold static pointer
1106oblist_find_by_name (SCHEME_P_ const char *name) 1137oblist_find_by_name (SCHEME_P_ const char *name)
1107{ 1138{
1108 int location; 1139 int location;
1109 pointer x; 1140 pointer x;
1110 char *s; 1141 char *s;
1121 } 1152 }
1122 1153
1123 return NIL; 1154 return NIL;
1124} 1155}
1125 1156
1126static pointer 1157ecb_cold static pointer
1127oblist_all_symbols (SCHEME_P) 1158oblist_all_symbols (SCHEME_P)
1128{ 1159{
1129 int i; 1160 int i;
1130 pointer x; 1161 pointer x;
1131 pointer ob_list = NIL; 1162 pointer ob_list = NIL;
1137 return ob_list; 1168 return ob_list;
1138} 1169}
1139 1170
1140#else 1171#else
1141 1172
1142static pointer 1173ecb_cold static pointer
1143oblist_initial_value (SCHEME_P) 1174oblist_initial_value (SCHEME_P)
1144{ 1175{
1145 return NIL; 1176 return NIL;
1146} 1177}
1147 1178
1148ecb_inline pointer 1179ecb_cold static pointer
1149oblist_find_by_name (SCHEME_P_ const char *name) 1180oblist_find_by_name (SCHEME_P_ const char *name)
1150{ 1181{
1151 pointer x; 1182 pointer x;
1152 char *s; 1183 char *s;
1153 1184
1162 1193
1163 return NIL; 1194 return NIL;
1164} 1195}
1165 1196
1166/* returns the new symbol */ 1197/* returns the new symbol */
1167static pointer 1198ecb_cold static pointer
1168oblist_add_by_name (SCHEME_P_ const char *name) 1199oblist_add_by_name (SCHEME_P_ const char *name)
1169{ 1200{
1170 pointer x = generate_symbol (SCHEME_A_ name); 1201 pointer x = generate_symbol (SCHEME_A_ name);
1171 SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist); 1202 SCHEME_V->oblist = immutable_cons (x, SCHEME_V->oblist);
1172 return x; 1203 return x;
1173} 1204}
1174 1205
1175static pointer 1206ecb_cold static pointer
1176oblist_all_symbols (SCHEME_P) 1207oblist_all_symbols (SCHEME_P)
1177{ 1208{
1178 return SCHEME_V->oblist; 1209 return SCHEME_V->oblist;
1179} 1210}
1180 1211
1181#endif 1212#endif
1182 1213
1183#if USE_PORTS
1184static pointer 1214ecb_cold static pointer
1185mk_port (SCHEME_P_ port *p) 1215mk_port (SCHEME_P_ port *p)
1186{ 1216{
1187 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1217 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1188 1218
1189 set_typeflag (x, T_PORT | T_ATOM); 1219 set_typeflag (x, T_PORT | T_ATOM);
1190 set_port (x, p); 1220 set_port (x, p);
1191 1221
1192 return x; 1222 return x;
1193} 1223}
1194#endif
1195 1224
1196pointer 1225ecb_cold pointer
1197mk_foreign_func (SCHEME_P_ foreign_func f) 1226mk_foreign_func (SCHEME_P_ foreign_func f)
1198{ 1227{
1199 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1228 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1200 1229
1201 set_typeflag (x, T_FOREIGN | T_ATOM); 1230 set_typeflag (x, T_FOREIGN | T_ATOM);
1230 if (!*pp) 1259 if (!*pp)
1231 { 1260 {
1232 pointer x = get_cell (SCHEME_A_ NIL, NIL); 1261 pointer x = get_cell (SCHEME_A_ NIL, NIL);
1233 1262
1234 set_typeflag (x, T_INTEGER | T_ATOM); 1263 set_typeflag (x, T_INTEGER | T_ATOM);
1235 setimmutable (x); /* shouldn't do anythi9ng, doesn't cost anything */ 1264 setimmutable (x); /* shouldn't do anything, doesn't cost anything */
1236 set_ivalue (x, n); 1265 set_ivalue (x, n);
1237 1266
1238 *pp = x; 1267 *pp = x;
1239 } 1268 }
1240 1269
1366 x = oblist_add_by_name (SCHEME_A_ name); 1395 x = oblist_add_by_name (SCHEME_A_ name);
1367 1396
1368 return x; 1397 return x;
1369} 1398}
1370 1399
1371INTERFACE pointer 1400ecb_cold INTERFACE pointer
1372gensym (SCHEME_P) 1401gensym (SCHEME_P)
1373{ 1402{
1374 pointer x; 1403 pointer x;
1375 char name[40] = "gensym-"; 1404 char name[40] = "gensym-";
1376 xnum (name + 7, ++SCHEME_V->gensym_cnt); 1405 xnum (name + 7, ++SCHEME_V->gensym_cnt);
1383{ 1412{
1384 return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x; 1413 return is_symbol (x) && oblist_find_by_name (SCHEME_A_ strvalue (x)) != x;
1385} 1414}
1386 1415
1387/* make symbol or number atom from string */ 1416/* make symbol or number atom from string */
1388static pointer 1417ecb_cold static pointer
1389mk_atom (SCHEME_P_ char *q) 1418mk_atom (SCHEME_P_ char *q)
1390{ 1419{
1391 char c, *p; 1420 char c, *p;
1392 int has_dec_point = 0; 1421 int has_dec_point = 0;
1393 int has_fp_exp = 0; 1422 int has_fp_exp = 0;
1464 1493
1465 return mk_integer (SCHEME_A_ strtol (q, 0, 10)); 1494 return mk_integer (SCHEME_A_ strtol (q, 0, 10));
1466} 1495}
1467 1496
1468/* make constant */ 1497/* make constant */
1469static pointer 1498ecb_cold static pointer
1470mk_sharp_const (SCHEME_P_ char *name) 1499mk_sharp_const (SCHEME_P_ char *name)
1471{ 1500{
1472 if (!strcmp (name, "t")) 1501 if (!strcmp (name, "t"))
1473 return S_T; 1502 return S_T;
1474 else if (!strcmp (name, "f")) 1503 else if (!strcmp (name, "f"))
1475 return S_F; 1504 return S_F;
1476 else if (*name == '\\') /* #\w (character) */ 1505 else if (*name == '\\') /* #\w (character) */
1477 { 1506 {
1478 int c; 1507 int c;
1479 1508
1509 // TODO: optimise
1480 if (stricmp (name + 1, "space") == 0) 1510 if (stricmp (name + 1, "space") == 0)
1481 c = ' '; 1511 c = ' ';
1482 else if (stricmp (name + 1, "newline") == 0) 1512 else if (stricmp (name + 1, "newline") == 0)
1483 c = '\n'; 1513 c = '\n';
1484 else if (stricmp (name + 1, "return") == 0) 1514 else if (stricmp (name + 1, "return") == 0)
1485 c = '\r'; 1515 c = '\r';
1486 else if (stricmp (name + 1, "tab") == 0) 1516 else if (stricmp (name + 1, "tab") == 0)
1487 c = '\t'; 1517 c = '\t';
1518 else if (stricmp (name + 1, "alarm") == 0)
1519 c = 0x07;
1520 else if (stricmp (name + 1, "backspace") == 0)
1521 c = 0x08;
1522 else if (stricmp (name + 1, "escape") == 0)
1523 c = 0x1b;
1524 else if (stricmp (name + 1, "delete") == 0)
1525 c = 0x7f;
1526 else if (stricmp (name + 1, "null") == 0)
1527 c = 0;
1488 else if (name[1] == 'x' && name[2] != 0) 1528 else if (name[1] == 'x' && name[2] != 0)
1489 { 1529 {
1490 long c1 = strtol (name + 2, 0, 16); 1530 long c1 = strtol (name + 2, 0, 16);
1491 1531
1492 if (0 <= c1 && c1 <= UCHAR_MAX) 1532 if (0 <= c1 && c1 <= UCHAR_MAX)
1506 return mk_character (SCHEME_A_ c); 1546 return mk_character (SCHEME_A_ c);
1507 } 1547 }
1508 else 1548 else
1509 { 1549 {
1510 /* identify base by string index */ 1550 /* identify base by string index */
1511 const char baseidx[17] = "ffbf" "ffff" "ofdf" "ffff" "x"; 1551 const char baseidx[18] = "ffbf" "ffff" "ofdf" "ffff" "x";
1512 char *base = strchr (baseidx, *name); 1552 char *base = strchr (baseidx, *name);
1513 1553
1514 if (base) 1554 if (base && *base)
1515 return mk_integer (SCHEME_A_ strtol (name + 1, 0, base - baseidx)); 1555 return mk_integer (SCHEME_A_ strtol (name + 1, 0, base - baseidx));
1516 1556
1517 return NIL; 1557 return NIL;
1518 } 1558 }
1519} 1559}
1520 1560
1521/* ========== garbage collector ========== */ 1561/* ========== garbage collector ========== */
1562
1563static void
1564finalize_cell (SCHEME_P_ pointer a)
1565{
1566 /* TODO, fast bitmap check? */
1567 if (is_string (a) || is_symbol (a))
1568 free (strvalue (a));
1569 else if (is_vector (a))
1570 free (vecvalue (a));
1571#if USE_PORTS
1572 else if (is_port (a))
1573 {
1574 if (port(a)->kind & port_file && port (a)->rep.stdio.closeit)
1575 port_close (SCHEME_A_ a, port_input | port_output);
1576
1577 free (port (a));
1578 }
1579#endif
1580}
1522 1581
1523/*-- 1582/*--
1524 * We use algorithm E (Knuth, The Art of Computer Programming Vol.1, 1583 * We use algorithm E (Knuth, The Art of Computer Programming Vol.1,
1525 * sec. 2.3.5), the Schorr-Deutsch-Waite link-inversion algorithm, 1584 * sec. 2.3.5), the Schorr-Deutsch-Waite link-inversion algorithm,
1526 * for marking. 1585 * for marking.
1527 * 1586 *
1528 * The exception is vectors - vectors are currently marked recursively, 1587 * The exception is vectors - vectors are currently marked recursively,
1529 * which is inherited form tinyscheme and could be fixed by having another 1588 * which is inherited form tinyscheme and could be fixed by having another
1530 * word of context in the vector 1589 * word of context in the vector
1531 */ 1590 */
1532static void 1591ecb_hot static void
1533mark (pointer a) 1592mark (pointer a)
1534{ 1593{
1535 pointer t, q, p; 1594 pointer t, q, p;
1536 1595
1537 t = 0; 1596 t = 0;
1594 p = q; 1653 p = q;
1595 goto E6; 1654 goto E6;
1596 } 1655 }
1597} 1656}
1598 1657
1599/* garbage collection. parameter a, b is marked. */ 1658ecb_hot static void
1600static void 1659gc_free (SCHEME_P)
1601gc (SCHEME_P_ pointer a, pointer b)
1602{ 1660{
1603 int i; 1661 int i;
1604
1605 if (SCHEME_V->gc_verbose)
1606 putstr (SCHEME_A_ "gc...");
1607
1608 /* mark system globals */
1609 mark (SCHEME_V->oblist);
1610 mark (SCHEME_V->global_env);
1611
1612 /* mark current registers */
1613 mark (SCHEME_V->args);
1614 mark (SCHEME_V->envir);
1615 mark (SCHEME_V->code);
1616 dump_stack_mark (SCHEME_A);
1617 mark (SCHEME_V->value);
1618 mark (SCHEME_V->inport);
1619 mark (SCHEME_V->save_inport);
1620 mark (SCHEME_V->outport);
1621 mark (SCHEME_V->loadport);
1622
1623 /* Mark recent objects the interpreter doesn't know about yet. */
1624 mark (car (S_SINK));
1625 /* Mark any older stuff above nested C calls */
1626 mark (SCHEME_V->c_nest);
1627
1628#if USE_INTCACHE
1629 /* mark intcache */
1630 for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i)
1631 if (SCHEME_V->intcache[i - INTCACHE_MIN])
1632 mark (SCHEME_V->intcache[i - INTCACHE_MIN]);
1633#endif
1634
1635 /* mark variables a, b */
1636 mark (a);
1637 mark (b);
1638
1639 /* garbage collect */
1640 clrmark (NIL);
1641 SCHEME_V->fcells = 0;
1642 SCHEME_V->free_cell = NIL;
1643
1644 if (SCHEME_V->gc_verbose)
1645 putstr (SCHEME_A_ "freeing...");
1646
1647 uint32_t total = 0; 1662 uint32_t total = 0;
1648 1663
1649 /* Here we scan the cells to build the free-list. */ 1664 /* Here we scan the cells to build the free-list. */
1650 for (i = SCHEME_V->last_cell_seg; i >= 0; i--) 1665 for (i = SCHEME_V->last_cell_seg; i >= 0; i--)
1651 { 1666 {
1680 { 1695 {
1681 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"); 1696 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");
1682 } 1697 }
1683} 1698}
1684 1699
1685static void 1700/* garbage collection. parameter a, b is marked. */
1686finalize_cell (SCHEME_P_ pointer a) 1701ecb_cold static void
1702gc (SCHEME_P_ pointer a, pointer b)
1687{ 1703{
1688 /* TODO, fast bitmap check? */ 1704 int i;
1689 if (is_string (a) || is_symbol (a))
1690 free (strvalue (a));
1691 else if (is_vector (a))
1692 free (vecvalue (a));
1693#if USE_PORTS
1694 else if (is_port (a))
1695 {
1696 if (port(a)->kind & port_file && port (a)->rep.stdio.closeit)
1697 port_close (SCHEME_A_ a, port_input | port_output);
1698 1705
1699 free (port (a)); 1706 if (SCHEME_V->gc_verbose)
1700 } 1707 putstr (SCHEME_A_ "gc...");
1708
1709 /* mark system globals */
1710 mark (SCHEME_V->oblist);
1711 mark (SCHEME_V->global_env);
1712
1713 /* mark current registers */
1714 mark (SCHEME_V->args);
1715 mark (SCHEME_V->envir);
1716 mark (SCHEME_V->code);
1717 dump_stack_mark (SCHEME_A);
1718 mark (SCHEME_V->value);
1719 mark (SCHEME_V->inport);
1720 mark (SCHEME_V->save_inport);
1721 mark (SCHEME_V->outport);
1722 mark (SCHEME_V->loadport);
1723
1724 /* Mark recent objects the interpreter doesn't know about yet. */
1725 mark (car (S_SINK));
1726 /* Mark any older stuff above nested C calls */
1727 mark (SCHEME_V->c_nest);
1728
1729#if USE_INTCACHE
1730 /* mark intcache */
1731 for (i = INTCACHE_MIN; i <= INTCACHE_MAX; ++i)
1732 if (SCHEME_V->intcache[i - INTCACHE_MIN])
1733 mark (SCHEME_V->intcache[i - INTCACHE_MIN]);
1701#endif 1734#endif
1735
1736 /* mark variables a, b */
1737 mark (a);
1738 mark (b);
1739
1740 /* garbage collect */
1741 clrmark (NIL);
1742 SCHEME_V->fcells = 0;
1743 SCHEME_V->free_cell = NIL;
1744
1745 if (SCHEME_V->gc_verbose)
1746 putstr (SCHEME_A_ "freeing...");
1747
1748 gc_free (SCHEME_A);
1702} 1749}
1703 1750
1704/* ========== Routines for Reading ========== */ 1751/* ========== Routines for Reading ========== */
1705 1752
1706static int 1753ecb_cold static int
1707file_push (SCHEME_P_ const char *fname) 1754file_push (SCHEME_P_ const char *fname)
1708{ 1755{
1709#if USE_PORTS
1710 int fin; 1756 int fin;
1711 1757
1712 if (SCHEME_V->file_i == MAXFIL - 1) 1758 if (SCHEME_V->file_i == MAXFIL - 1)
1713 return 0; 1759 return 0;
1714 1760
1731 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.filename = store_string (SCHEME_A_ strlen (fname), fname, 0); 1777 SCHEME_V->load_stack[SCHEME_V->file_i].rep.stdio.filename = store_string (SCHEME_A_ strlen (fname), fname, 0);
1732#endif 1778#endif
1733 } 1779 }
1734 1780
1735 return fin >= 0; 1781 return fin >= 0;
1736
1737#else
1738 return 1;
1739#endif
1740} 1782}
1741 1783
1742static void 1784ecb_cold static void
1743file_pop (SCHEME_P) 1785file_pop (SCHEME_P)
1744{ 1786{
1745 if (SCHEME_V->file_i != 0) 1787 if (SCHEME_V->file_i != 0)
1746 { 1788 {
1747 SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i]; 1789 SCHEME_V->nesting = SCHEME_V->nesting_stack[SCHEME_V->file_i];
1751 SCHEME_V->file_i--; 1793 SCHEME_V->file_i--;
1752 set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i); 1794 set_port (SCHEME_V->loadport, SCHEME_V->load_stack + SCHEME_V->file_i);
1753 } 1795 }
1754} 1796}
1755 1797
1756static int 1798ecb_cold static int
1757file_interactive (SCHEME_P) 1799file_interactive (SCHEME_P)
1758{ 1800{
1759#if USE_PORTS 1801#if USE_PORTS
1760 return SCHEME_V->file_i == 0 1802 return SCHEME_V->file_i == 0
1761 && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO 1803 && SCHEME_V->load_stack[0].rep.stdio.file == STDIN_FILENO
1764 return 0; 1806 return 0;
1765#endif 1807#endif
1766} 1808}
1767 1809
1768#if USE_PORTS 1810#if USE_PORTS
1769static port * 1811ecb_cold static port *
1770port_rep_from_filename (SCHEME_P_ const char *fn, int prop) 1812port_rep_from_filename (SCHEME_P_ const char *fn, int prop)
1771{ 1813{
1772 int fd; 1814 int fd;
1773 int flags; 1815 int flags;
1774 char *rw; 1816 char *rw;
1797# endif 1839# endif
1798 1840
1799 return pt; 1841 return pt;
1800} 1842}
1801 1843
1802static pointer 1844ecb_cold static pointer
1803port_from_filename (SCHEME_P_ const char *fn, int prop) 1845port_from_filename (SCHEME_P_ const char *fn, int prop)
1804{ 1846{
1805 port *pt = port_rep_from_filename (SCHEME_A_ fn, prop); 1847 port *pt = port_rep_from_filename (SCHEME_A_ fn, prop);
1806 1848
1807 if (!pt && USE_ERROR_CHECKING) 1849 if (!pt && USE_ERROR_CHECKING)
1808 return NIL; 1850 return NIL;
1809 1851
1810 return mk_port (SCHEME_A_ pt); 1852 return mk_port (SCHEME_A_ pt);
1811} 1853}
1812 1854
1813static port * 1855ecb_cold static port *
1814port_rep_from_file (SCHEME_P_ int f, int prop) 1856port_rep_from_file (SCHEME_P_ int f, int prop)
1815{ 1857{
1816 port *pt = malloc (sizeof *pt); 1858 port *pt = malloc (sizeof *pt);
1817 1859
1818 if (!pt && USE_ERROR_CHECKING) 1860 if (!pt && USE_ERROR_CHECKING)
1823 pt->rep.stdio.file = f; 1865 pt->rep.stdio.file = f;
1824 pt->rep.stdio.closeit = 0; 1866 pt->rep.stdio.closeit = 0;
1825 return pt; 1867 return pt;
1826} 1868}
1827 1869
1828static pointer 1870ecb_cold static pointer
1829port_from_file (SCHEME_P_ int f, int prop) 1871port_from_file (SCHEME_P_ int f, int prop)
1830{ 1872{
1831 port *pt = port_rep_from_file (SCHEME_A_ f, prop); 1873 port *pt = port_rep_from_file (SCHEME_A_ f, prop);
1832 1874
1833 if (!pt && USE_ERROR_CHECKING) 1875 if (!pt && USE_ERROR_CHECKING)
1834 return NIL; 1876 return NIL;
1835 1877
1836 return mk_port (SCHEME_A_ pt); 1878 return mk_port (SCHEME_A_ pt);
1837} 1879}
1838 1880
1839static port * 1881ecb_cold static port *
1840port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) 1882port_rep_from_string (SCHEME_P_ char *start, char *past_the_end, int prop)
1841{ 1883{
1842 port *pt = malloc (sizeof (port)); 1884 port *pt = malloc (sizeof (port));
1843 1885
1844 if (!pt && USE_ERROR_CHECKING) 1886 if (!pt && USE_ERROR_CHECKING)
1850 pt->rep.string.curr = start; 1892 pt->rep.string.curr = start;
1851 pt->rep.string.past_the_end = past_the_end; 1893 pt->rep.string.past_the_end = past_the_end;
1852 return pt; 1894 return pt;
1853} 1895}
1854 1896
1855static pointer 1897ecb_cold static pointer
1856port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop) 1898port_from_string (SCHEME_P_ char *start, char *past_the_end, int prop)
1857{ 1899{
1858 port *pt = port_rep_from_string (SCHEME_A_ start, past_the_end, prop); 1900 port *pt = port_rep_from_string (SCHEME_A_ start, past_the_end, prop);
1859 1901
1860 if (!pt && USE_ERROR_CHECKING) 1902 if (!pt && USE_ERROR_CHECKING)
1863 return mk_port (SCHEME_A_ pt); 1905 return mk_port (SCHEME_A_ pt);
1864} 1906}
1865 1907
1866# define BLOCK_SIZE 256 1908# define BLOCK_SIZE 256
1867 1909
1868static port * 1910ecb_cold static port *
1869port_rep_from_scratch (SCHEME_P) 1911port_rep_from_scratch (SCHEME_P)
1870{ 1912{
1871 char *start; 1913 char *start;
1872 port *pt = malloc (sizeof (port)); 1914 port *pt = malloc (sizeof (port));
1873 1915
1887 pt->rep.string.curr = start; 1929 pt->rep.string.curr = start;
1888 pt->rep.string.past_the_end = start + BLOCK_SIZE - 1; 1930 pt->rep.string.past_the_end = start + BLOCK_SIZE - 1;
1889 return pt; 1931 return pt;
1890} 1932}
1891 1933
1892static pointer 1934ecb_cold static pointer
1893port_from_scratch (SCHEME_P) 1935port_from_scratch (SCHEME_P)
1894{ 1936{
1895 port *pt = port_rep_from_scratch (SCHEME_A); 1937 port *pt = port_rep_from_scratch (SCHEME_A);
1896 1938
1897 if (!pt && USE_ERROR_CHECKING) 1939 if (!pt && USE_ERROR_CHECKING)
1898 return NIL; 1940 return NIL;
1899 1941
1900 return mk_port (SCHEME_A_ pt); 1942 return mk_port (SCHEME_A_ pt);
1901} 1943}
1902 1944
1903static void 1945ecb_cold static void
1904port_close (SCHEME_P_ pointer p, int flag) 1946port_close (SCHEME_P_ pointer p, int flag)
1905{ 1947{
1906 port *pt = port (p); 1948 port *pt = port (p);
1907 1949
1908 pt->kind &= ~flag; 1950 pt->kind &= ~flag;
1928 } 1970 }
1929} 1971}
1930#endif 1972#endif
1931 1973
1932/* get new character from input file */ 1974/* get new character from input file */
1933static int 1975ecb_cold static int
1934inchar (SCHEME_P) 1976inchar (SCHEME_P)
1935{ 1977{
1936 int c; 1978 int c;
1937 port *pt = port (SCHEME_V->inport); 1979 port *pt = port (SCHEME_V->inport);
1938 1980
1952 } 1994 }
1953 1995
1954 return c; 1996 return c;
1955} 1997}
1956 1998
1957static int ungot = -1; 1999ecb_cold static int
1958
1959static int
1960basic_inchar (port *pt) 2000basic_inchar (port *pt)
1961{ 2001{
1962#if USE_PORTS
1963 if (pt->unget != -1) 2002 if (pt->unget != -1)
1964 { 2003 {
1965 int r = pt->unget; 2004 int r = pt->unget;
1966 pt->unget = -1; 2005 pt->unget = -1;
1967 return r; 2006 return r;
1968 } 2007 }
1969 2008
2009#if USE_PORTS
1970 if (pt->kind & port_file) 2010 if (pt->kind & port_file)
1971 { 2011 {
1972 char c; 2012 char c;
1973 2013
1974 if (!read (pt->rep.stdio.file, &c, 1)) 2014 if (!read (pt->rep.stdio.file, &c, 1))
1982 return EOF; 2022 return EOF;
1983 else 2023 else
1984 return *pt->rep.string.curr++; 2024 return *pt->rep.string.curr++;
1985 } 2025 }
1986#else 2026#else
1987 if (ungot == -1)
1988 {
1989 char c; 2027 char c;
1990 if (!read (0, &c, 1)) 2028
2029 if (!read (pt->rep.stdio.file, &c, 1))
1991 return EOF; 2030 return EOF;
1992 2031
1993 ungot = c;
1994 }
1995
1996 {
1997 int r = ungot;
1998 ungot = -1;
1999 return r; 2032 return c;
2000 }
2001#endif 2033#endif
2002} 2034}
2003 2035
2004/* back character to input buffer */ 2036/* back character to input buffer */
2005static void 2037ecb_cold static void
2006backchar (SCHEME_P_ int c) 2038backchar (SCHEME_P_ int c)
2007{ 2039{
2008#if USE_PORTS 2040 port *pt = port (SCHEME_V->inport);
2009 port *pt;
2010 2041
2011 if (c == EOF) 2042 if (c == EOF)
2012 return; 2043 return;
2013 2044
2014 pt = port (SCHEME_V->inport);
2015 pt->unget = c; 2045 pt->unget = c;
2016#else
2017 if (c == EOF)
2018 return;
2019
2020 ungot = c;
2021#endif
2022} 2046}
2023 2047
2024#if USE_PORTS 2048#if USE_PORTS
2025static int 2049ecb_cold static int
2026realloc_port_string (SCHEME_P_ port *p) 2050realloc_port_string (SCHEME_P_ port *p)
2027{ 2051{
2028 char *start = p->rep.string.start; 2052 char *start = p->rep.string.start;
2029 size_t new_size = p->rep.string.past_the_end - start + 1 + BLOCK_SIZE; 2053 size_t new_size = p->rep.string.past_the_end - start + 1 + BLOCK_SIZE;
2030 char *str = malloc (new_size); 2054 char *str = malloc (new_size);
2043 else 2067 else
2044 return 0; 2068 return 0;
2045} 2069}
2046#endif 2070#endif
2047 2071
2048INTERFACE void 2072ecb_cold static void
2049putstr (SCHEME_P_ const char *s) 2073putchars (SCHEME_P_ const char *s, int len)
2050{ 2074{
2075 port *pt = port (SCHEME_V->outport);
2076
2051#if USE_PORTS 2077#if USE_PORTS
2052 port *pt = port (SCHEME_V->outport);
2053
2054 if (pt->kind & port_file)
2055 write (pt->rep.stdio.file, s, strlen (s));
2056 else
2057 for (; *s; s++)
2058 if (pt->rep.string.curr != pt->rep.string.past_the_end)
2059 *pt->rep.string.curr++ = *s;
2060 else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt))
2061 *pt->rep.string.curr++ = *s;
2062
2063#else
2064 write (pt->rep.stdio.file, s, strlen (s));
2065#endif
2066}
2067
2068static void
2069putchars (SCHEME_P_ const char *s, int len)
2070{
2071#if USE_PORTS
2072 port *pt = port (SCHEME_V->outport);
2073
2074 if (pt->kind & port_file) 2078 if (pt->kind & port_file)
2075 write (pt->rep.stdio.file, s, len); 2079 write (pt->rep.stdio.file, s, len);
2076 else 2080 else
2077 { 2081 {
2078 for (; len; len--) 2082 for (; len; len--)
2083 *pt->rep.string.curr++ = *s++; 2087 *pt->rep.string.curr++ = *s++;
2084 } 2088 }
2085 } 2089 }
2086 2090
2087#else 2091#else
2088 write (1, s, len); 2092 write (1, s, len); // output not initialised
2089#endif 2093#endif
2094}
2095
2096INTERFACE void
2097putstr (SCHEME_P_ const char *s)
2098{
2099 putchars (SCHEME_A_ s, strlen (s));
2090} 2100}
2091 2101
2092INTERFACE void 2102INTERFACE void
2093putcharacter (SCHEME_P_ int c) 2103putcharacter (SCHEME_P_ int c)
2094{ 2104{
2095#if USE_PORTS
2096 port *pt = port (SCHEME_V->outport);
2097
2098 if (pt->kind & port_file)
2099 {
2100 char cc = c;
2101 write (pt->rep.stdio.file, &cc, 1);
2102 }
2103 else
2104 {
2105 if (pt->rep.string.curr != pt->rep.string.past_the_end)
2106 *pt->rep.string.curr++ = c;
2107 else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt))
2108 *pt->rep.string.curr++ = c;
2109 }
2110
2111#else
2112 char cc = c; 2105 char cc = c;
2113 write (1, &c, 1); 2106
2114#endif 2107 putchars (SCHEME_A_ &cc, 1);
2115} 2108}
2116 2109
2117/* read characters up to delimiter, but cater to character constants */ 2110/* read characters up to delimiter, but cater to character constants */
2118static char * 2111ecb_cold static char *
2119readstr_upto (SCHEME_P_ int skip, const char *delim) 2112readstr_upto (SCHEME_P_ int skip, const char *delim)
2120{ 2113{
2121 char *p = SCHEME_V->strbuff + skip; 2114 char *p = SCHEME_V->strbuff + skip;
2122 2115
2123 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A)))); 2116 while ((p - SCHEME_V->strbuff < sizeof (SCHEME_V->strbuff)) && !is_one_of (delim, (*p++ = inchar (SCHEME_A))));
2132 2125
2133 return SCHEME_V->strbuff; 2126 return SCHEME_V->strbuff;
2134} 2127}
2135 2128
2136/* read string expression "xxx...xxx" */ 2129/* read string expression "xxx...xxx" */
2137static pointer 2130ecb_cold static pointer
2138readstrexp (SCHEME_P_ char delim) 2131readstrexp (SCHEME_P_ char delim)
2139{ 2132{
2140 char *p = SCHEME_V->strbuff; 2133 char *p = SCHEME_V->strbuff;
2141 int c; 2134 int c;
2142 int c1 = 0; 2135 int c1 = 0;
2175 case '7': 2168 case '7':
2176 state = st_oct1; 2169 state = st_oct1;
2177 c1 = c - '0'; 2170 c1 = c - '0';
2178 break; 2171 break;
2179 2172
2173 case 'a': *p++ = '\a'; state = st_ok; break;
2174 case 'n': *p++ = '\n'; state = st_ok; break;
2175 case 'r': *p++ = '\r'; state = st_ok; break;
2176 case 't': *p++ = '\t'; state = st_ok; break;
2177
2178 // this overshoots the minimum requirements of r7rs
2179 case ' ':
2180 case '\t':
2181 case '\r':
2182 case '\n':
2183 skipspace (SCHEME_A);
2184 state = st_ok;
2185 break;
2186
2187 //TODO: x should end in ;, not two-digit hex
2180 case 'x': 2188 case 'x':
2181 case 'X': 2189 case 'X':
2182 state = st_x1; 2190 state = st_x1;
2183 c1 = 0; 2191 c1 = 0;
2184 break;
2185
2186 case 'n':
2187 *p++ = '\n';
2188 state = st_ok;
2189 break;
2190
2191 case 't':
2192 *p++ = '\t';
2193 state = st_ok;
2194 break;
2195
2196 case 'r':
2197 *p++ = '\r';
2198 state = st_ok;
2199 break; 2192 break;
2200 2193
2201 default: 2194 default:
2202 *p++ = c; 2195 *p++ = c;
2203 state = st_ok; 2196 state = st_ok;
2255 } 2248 }
2256 } 2249 }
2257} 2250}
2258 2251
2259/* check c is in chars */ 2252/* check c is in chars */
2260ecb_inline int 2253ecb_cold int
2261is_one_of (const char *s, int c) 2254is_one_of (const char *s, int c)
2262{ 2255{
2263 return c == EOF || !!strchr (s, c); 2256 return c == EOF || !!strchr (s, c);
2264} 2257}
2265 2258
2266/* skip white characters */ 2259/* skip white characters */
2267ecb_inline int 2260ecb_cold int
2268skipspace (SCHEME_P) 2261skipspace (SCHEME_P)
2269{ 2262{
2270 int c, curr_line = 0; 2263 int c, curr_line = 0;
2271 2264
2272 do 2265 do
2292 backchar (SCHEME_A_ c); 2285 backchar (SCHEME_A_ c);
2293 return 1; 2286 return 1;
2294} 2287}
2295 2288
2296/* get token */ 2289/* get token */
2297static int 2290ecb_cold static int
2298token (SCHEME_P) 2291token (SCHEME_P)
2299{ 2292{
2300 int c = skipspace (SCHEME_A); 2293 int c = skipspace (SCHEME_A);
2301 2294
2302 if (c == EOF) 2295 if (c == EOF)
2400} 2393}
2401 2394
2402/* ========== Routines for Printing ========== */ 2395/* ========== Routines for Printing ========== */
2403#define ok_abbrev(x) (is_pair(x) && cdr(x) == NIL) 2396#define ok_abbrev(x) (is_pair(x) && cdr(x) == NIL)
2404 2397
2405static void 2398ecb_cold static void
2406printslashstring (SCHEME_P_ char *p, int len) 2399printslashstring (SCHEME_P_ char *p, int len)
2407{ 2400{
2408 int i; 2401 int i;
2409 unsigned char *s = (unsigned char *) p; 2402 unsigned char *s = (unsigned char *) p;
2410 2403
2466 2459
2467 putcharacter (SCHEME_A_ '"'); 2460 putcharacter (SCHEME_A_ '"');
2468} 2461}
2469 2462
2470/* print atoms */ 2463/* print atoms */
2471static void 2464ecb_cold static void
2472printatom (SCHEME_P_ pointer l, int f) 2465printatom (SCHEME_P_ pointer l, int f)
2473{ 2466{
2474 char *p; 2467 char *p;
2475 int len; 2468 int len;
2476 2469
2477 atom2str (SCHEME_A_ l, f, &p, &len); 2470 atom2str (SCHEME_A_ l, f, &p, &len);
2478 putchars (SCHEME_A_ p, len); 2471 putchars (SCHEME_A_ p, len);
2479} 2472}
2480 2473
2481/* Uses internal buffer unless string pointer is already available */ 2474/* Uses internal buffer unless string pointer is already available */
2482static void 2475ecb_cold static void
2483atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen) 2476atom2str (SCHEME_P_ pointer l, int f, char **pp, int *plen)
2484{ 2477{
2485 char *p; 2478 char *p;
2486 2479
2487 if (l == NIL) 2480 if (l == NIL)
2620 } 2613 }
2621 else if (is_symbol (l)) 2614 else if (is_symbol (l))
2622 p = symname (l); 2615 p = symname (l);
2623 else if (is_proc (l)) 2616 else if (is_proc (l))
2624 { 2617 {
2618 p = (char *)procname (l); // ok with r7rs display, but not r7rs write
2619#if 0
2625#if USE_PRINTF 2620#if USE_PRINTF
2626 p = SCHEME_V->strbuff; 2621 p = SCHEME_V->strbuff;
2627 snprintf (p, STRBUFFSIZE, "#<%s PROCEDURE %ld>", procname (l), procnum (l)); 2622 snprintf (p, STRBUFFSIZE, " PROCEDURE %ld>", procname (l), procnum (l));
2628#else 2623#else
2629 p = "#<PROCEDURE>"; 2624 p = "#<PROCEDURE>";
2625#endif
2630#endif 2626#endif
2631 } 2627 }
2632 else if (is_macro (l)) 2628 else if (is_macro (l))
2633 p = "#<MACRO>"; 2629 p = "#<MACRO>";
2634 else if (is_closure (l)) 2630 else if (is_closure (l))
2694 return car (d); 2690 return car (d);
2695 2691
2696 p = cons (car (d), cdr (d)); 2692 p = cons (car (d), cdr (d));
2697 q = p; 2693 q = p;
2698 2694
2699 while (cdr (cdr (p)) != NIL) 2695 while (cddr (p) != NIL)
2700 { 2696 {
2701 d = cons (car (p), cdr (p)); 2697 d = cons (car (p), cdr (p));
2702 2698
2703 if (cdr (cdr (p)) != NIL) 2699 if (cddr (p) != NIL)
2704 p = cdr (d); 2700 p = cdr (d);
2705 } 2701 }
2706 2702
2707 set_cdr (p, car (cdr (p))); 2703 set_cdr (p, cadr (p));
2708 return q; 2704 return q;
2709} 2705}
2710 2706
2711/* reverse list -- produce new list */ 2707/* reverse list -- produce new list */
2712static pointer 2708ecb_hot static pointer
2713reverse (SCHEME_P_ pointer a) 2709reverse (SCHEME_P_ pointer a)
2714{ 2710{
2715 /* a must be checked by gc */ 2711 /* a must be checked by gc */
2716 pointer p = NIL; 2712 pointer p = NIL;
2717 2713
2720 2716
2721 return p; 2717 return p;
2722} 2718}
2723 2719
2724/* reverse list --- in-place */ 2720/* reverse list --- in-place */
2725static pointer 2721ecb_hot static pointer
2726reverse_in_place (SCHEME_P_ pointer term, pointer list) 2722reverse_in_place (SCHEME_P_ pointer term, pointer list)
2727{ 2723{
2728 pointer result = term; 2724 pointer result = term;
2729 pointer p = list; 2725 pointer p = list;
2730 2726
2738 2734
2739 return result; 2735 return result;
2740} 2736}
2741 2737
2742/* append list -- produce new list (in reverse order) */ 2738/* append list -- produce new list (in reverse order) */
2743static pointer 2739ecb_hot static pointer
2744revappend (SCHEME_P_ pointer a, pointer b) 2740revappend (SCHEME_P_ pointer a, pointer b)
2745{ 2741{
2746 pointer result = a; 2742 pointer result = a;
2747 pointer p = b; 2743 pointer p = b;
2748 2744
2757 2753
2758 return S_F; /* signal an error */ 2754 return S_F; /* signal an error */
2759} 2755}
2760 2756
2761/* equivalence of atoms */ 2757/* equivalence of atoms */
2762int 2758ecb_hot int
2763eqv (pointer a, pointer b) 2759eqv (pointer a, pointer b)
2764{ 2760{
2765 if (is_string (a)) 2761 if (is_string (a))
2766 { 2762 {
2767 if (is_string (b)) 2763 if (is_string (b))
2824{ 2820{
2825 pointer new_frame; 2821 pointer new_frame;
2826 2822
2827 /* The interaction-environment has about 300 variables in it. */ 2823 /* The interaction-environment has about 300 variables in it. */
2828 if (old_env == NIL) 2824 if (old_env == NIL)
2829 new_frame = mk_vector (SCHEME_A_ 461); 2825 new_frame = mk_vector (SCHEME_A_ 29); // was 461
2830 else 2826 else
2831 new_frame = NIL; 2827 new_frame = NIL;
2832 2828
2833 SCHEME_V->envir = immutable_cons (new_frame, old_env); 2829 SCHEME_V->envir = immutable_cons (new_frame, old_env);
2834 setenvironment (SCHEME_V->envir); 2830 setenvironment (SCHEME_V->envir);
2861 } 2857 }
2862 else 2858 else
2863 set_car (env, immutable_cons (slot, car (env))); 2859 set_car (env, immutable_cons (slot, car (env)));
2864} 2860}
2865 2861
2866static pointer 2862ecb_hot static pointer
2867find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) 2863find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all)
2868{ 2864{
2869 pointer x, y; 2865 pointer x, y;
2870 2866
2871 for (x = env; x != NIL; x = cdr (x)) 2867 for (x = env; x != NIL; x = cdr (x))
2892 return NIL; 2888 return NIL;
2893} 2889}
2894 2890
2895#else /* USE_ALIST_ENV */ 2891#else /* USE_ALIST_ENV */
2896 2892
2897ecb_inline void 2893static void
2898new_frame_in_env (SCHEME_P_ pointer old_env) 2894new_frame_in_env (SCHEME_P_ pointer old_env)
2899{ 2895{
2900 SCHEME_V->envir = immutable_cons (NIL, old_env); 2896 SCHEME_V->envir = immutable_cons (NIL, old_env);
2901 setenvironment (SCHEME_V->envir); 2897 setenvironment (SCHEME_V->envir);
2902} 2898}
2903 2899
2904ecb_inline void 2900static void
2905new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value) 2901new_slot_spec_in_env (SCHEME_P_ pointer env, pointer variable, pointer value)
2906{ 2902{
2907 set_car (env, immutable_cons (immutable_cons (variable, value), car (env))); 2903 set_car (env, immutable_cons (immutable_cons (variable, value), car (env)));
2908} 2904}
2909 2905
2910static pointer 2906ecb_hot static pointer
2911find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all) 2907find_slot_in_env (SCHEME_P_ pointer env, pointer hdl, int all)
2912{ 2908{
2913 pointer x, y; 2909 pointer x, y;
2914 2910
2915 for (x = env; x != NIL; x = cdr (x)) 2911 for (x = env; x != NIL; x = cdr (x))
2929 return NIL; 2925 return NIL;
2930} 2926}
2931 2927
2932#endif /* USE_ALIST_ENV else */ 2928#endif /* USE_ALIST_ENV else */
2933 2929
2934ecb_inline void 2930static void
2935new_slot_in_env (SCHEME_P_ pointer variable, pointer value) 2931new_slot_in_env (SCHEME_P_ pointer variable, pointer value)
2936{ 2932{
2937 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2 2933 assert (is_symbol (variable));//TODO: bug in current-ws/OP_LET2
2938 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value); 2934 new_slot_spec_in_env (SCHEME_A_ SCHEME_V->envir, variable, value);
2939} 2935}
2940 2936
2941ecb_inline void 2937static void
2942set_slot_in_env (SCHEME_P_ pointer slot, pointer value) 2938set_slot_in_env (SCHEME_P_ pointer slot, pointer value)
2943{ 2939{
2944 set_cdr (slot, value); 2940 set_cdr (slot, value);
2945} 2941}
2946 2942
2947ecb_inline pointer 2943static pointer
2948slot_value_in_env (pointer slot) 2944slot_value_in_env (pointer slot)
2949{ 2945{
2950 return cdr (slot); 2946 return cdr (slot);
2951} 2947}
2952 2948
2953/* ========== Evaluation Cycle ========== */ 2949/* ========== Evaluation Cycle ========== */
2954 2950
2955static int 2951ecb_cold static int
2956xError_1 (SCHEME_P_ const char *s, pointer a) 2952xError_1 (SCHEME_P_ const char *s, pointer a)
2957{ 2953{
2958#if USE_ERROR_HOOK
2959 pointer x;
2960 pointer hdl = SCHEME_V->ERROR_HOOK;
2961#endif
2962
2963#if USE_PRINTF 2954#if USE_PRINTF
2964#if SHOW_ERROR_LINE 2955#if SHOW_ERROR_LINE
2965 char sbuf[STRBUFFSIZE]; 2956 char sbuf[STRBUFFSIZE];
2966 2957
2967 /* make sure error is not in REPL */ 2958 /* make sure error is not in REPL */
2982 } 2973 }
2983#endif 2974#endif
2984#endif 2975#endif
2985 2976
2986#if USE_ERROR_HOOK 2977#if USE_ERROR_HOOK
2987 x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, hdl, 1); 2978 pointer x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->ERROR_HOOK, 1);
2988 2979
2989 if (x != NIL) 2980 if (x != NIL)
2990 { 2981 {
2991 pointer code = a 2982 pointer code = a
2992 ? cons (cons (SCHEME_V->QUOTE, cons (a, NIL)), NIL) 2983 ? cons (cons (SCHEME_V->QUOTE, cons (a, NIL)), NIL)
3036 pointer code; 3027 pointer code;
3037}; 3028};
3038 3029
3039# define STACK_GROWTH 3 3030# define STACK_GROWTH 3
3040 3031
3041static void 3032ecb_hot static void
3042s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) 3033s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code)
3043{ 3034{
3044 int nframes = (uintptr_t)SCHEME_V->dump; 3035 int nframes = (uintptr_t)SCHEME_V->dump;
3045 struct dump_stack_frame *next_frame; 3036 struct dump_stack_frame *next_frame;
3046 3037
3059 next_frame->code = code; 3050 next_frame->code = code;
3060 3051
3061 SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1); 3052 SCHEME_V->dump = (pointer)(uintptr_t)(nframes + 1);
3062} 3053}
3063 3054
3064static int 3055static ecb_hot int
3065xs_return (SCHEME_P_ pointer a) 3056xs_return (SCHEME_P_ pointer a)
3066{ 3057{
3067 int nframes = (uintptr_t)SCHEME_V->dump; 3058 int nframes = (uintptr_t)SCHEME_V->dump;
3068 struct dump_stack_frame *frame; 3059 struct dump_stack_frame *frame;
3069 3060
3080 SCHEME_V->dump = (pointer)(uintptr_t)nframes; 3071 SCHEME_V->dump = (pointer)(uintptr_t)nframes;
3081 3072
3082 return 0; 3073 return 0;
3083} 3074}
3084 3075
3085ecb_inline void 3076ecb_cold void
3086dump_stack_reset (SCHEME_P) 3077dump_stack_reset (SCHEME_P)
3087{ 3078{
3088 /* in this implementation, SCHEME_V->dump is the number of frames on the stack */ 3079 /* in this implementation, SCHEME_V->dump is the number of frames on the stack */
3089 SCHEME_V->dump = (pointer)+0; 3080 SCHEME_V->dump = (pointer)+0;
3090} 3081}
3091 3082
3092ecb_inline void 3083ecb_cold void
3093dump_stack_initialize (SCHEME_P) 3084dump_stack_initialize (SCHEME_P)
3094{ 3085{
3095 SCHEME_V->dump_size = 0; 3086 SCHEME_V->dump_size = 0;
3096 SCHEME_V->dump_base = 0; 3087 SCHEME_V->dump_base = 0;
3097 dump_stack_reset (SCHEME_A); 3088 dump_stack_reset (SCHEME_A);
3098} 3089}
3099 3090
3100static void 3091ecb_cold static void
3101dump_stack_free (SCHEME_P) 3092dump_stack_free (SCHEME_P)
3102{ 3093{
3103 free (SCHEME_V->dump_base); 3094 free (SCHEME_V->dump_base);
3104 SCHEME_V->dump_base = 0; 3095 SCHEME_V->dump_base = 0;
3105 SCHEME_V->dump = (pointer)0; 3096 SCHEME_V->dump = (pointer)0;
3106 SCHEME_V->dump_size = 0; 3097 SCHEME_V->dump_size = 0;
3107} 3098}
3108 3099
3109static void 3100ecb_cold static void
3110dump_stack_mark (SCHEME_P) 3101dump_stack_mark (SCHEME_P)
3111{ 3102{
3112 int nframes = (uintptr_t)SCHEME_V->dump; 3103 int nframes = (uintptr_t)SCHEME_V->dump;
3113 int i; 3104 int i;
3114 3105
3120 mark (frame->envir); 3111 mark (frame->envir);
3121 mark (frame->code); 3112 mark (frame->code);
3122 } 3113 }
3123} 3114}
3124 3115
3125static pointer 3116ecb_cold static pointer
3126ss_get_cont (SCHEME_P) 3117ss_get_cont (SCHEME_P)
3127{ 3118{
3128 int nframes = (uintptr_t)SCHEME_V->dump; 3119 int nframes = (uintptr_t)SCHEME_V->dump;
3129 int i; 3120 int i;
3130 3121
3142 } 3133 }
3143 3134
3144 return cont; 3135 return cont;
3145} 3136}
3146 3137
3147static void 3138ecb_cold static void
3148ss_set_cont (SCHEME_P_ pointer cont) 3139ss_set_cont (SCHEME_P_ pointer cont)
3149{ 3140{
3150 int i = 0; 3141 int i = 0;
3151 struct dump_stack_frame *frame = SCHEME_V->dump_base; 3142 struct dump_stack_frame *frame = SCHEME_V->dump_base;
3152 3143
3164 SCHEME_V->dump = (pointer)(uintptr_t)i; 3155 SCHEME_V->dump = (pointer)(uintptr_t)i;
3165} 3156}
3166 3157
3167#else 3158#else
3168 3159
3169ecb_inline void 3160ecb_cold void
3170dump_stack_reset (SCHEME_P) 3161dump_stack_reset (SCHEME_P)
3171{ 3162{
3172 SCHEME_V->dump = NIL; 3163 SCHEME_V->dump = NIL;
3173} 3164}
3174 3165
3175ecb_inline void 3166ecb_cold void
3176dump_stack_initialize (SCHEME_P) 3167dump_stack_initialize (SCHEME_P)
3177{ 3168{
3178 dump_stack_reset (SCHEME_A); 3169 dump_stack_reset (SCHEME_A);
3179} 3170}
3180 3171
3181static void 3172ecb_cold static void
3182dump_stack_free (SCHEME_P) 3173dump_stack_free (SCHEME_P)
3183{ 3174{
3184 SCHEME_V->dump = NIL; 3175 SCHEME_V->dump = NIL;
3185} 3176}
3186 3177
3187static int 3178ecb_hot static int
3188xs_return (SCHEME_P_ pointer a) 3179xs_return (SCHEME_P_ pointer a)
3189{ 3180{
3190 pointer dump = SCHEME_V->dump; 3181 pointer dump = SCHEME_V->dump;
3191 3182
3192 SCHEME_V->value = a; 3183 SCHEME_V->value = a;
3202 SCHEME_V->dump = dump; 3193 SCHEME_V->dump = dump;
3203 3194
3204 return 0; 3195 return 0;
3205} 3196}
3206 3197
3207static void 3198ecb_hot static void
3208s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code) 3199s_save (SCHEME_P_ enum scheme_opcodes op, pointer args, pointer code)
3209{ 3200{
3210 SCHEME_V->dump = cons (mk_integer (SCHEME_A_ op), 3201 SCHEME_V->dump = cons (mk_integer (SCHEME_A_ op),
3211 cons (args, 3202 cons (args,
3212 cons (SCHEME_V->envir, 3203 cons (SCHEME_V->envir,
3213 cons (code, 3204 cons (code,
3214 SCHEME_V->dump)))); 3205 SCHEME_V->dump))));
3215} 3206}
3216 3207
3217static void 3208ecb_cold static void
3218dump_stack_mark (SCHEME_P) 3209dump_stack_mark (SCHEME_P)
3219{ 3210{
3220 mark (SCHEME_V->dump); 3211 mark (SCHEME_V->dump);
3221} 3212}
3222 3213
3223static pointer 3214ecb_cold static pointer
3224ss_get_cont (SCHEME_P) 3215ss_get_cont (SCHEME_P)
3225{ 3216{
3226 return SCHEME_V->dump; 3217 return SCHEME_V->dump;
3227} 3218}
3228 3219
3229static void 3220ecb_cold static void
3230ss_set_cont (SCHEME_P_ pointer cont) 3221ss_set_cont (SCHEME_P_ pointer cont)
3231{ 3222{
3232 SCHEME_V->dump = cont; 3223 SCHEME_V->dump = cont;
3233} 3224}
3234 3225
3235#endif 3226#endif
3236 3227
3237#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3228#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3238 3229
3239#if EXPERIMENT 3230#if EXPERIMENT
3231
3240static int 3232static int
3241debug (SCHEME_P_ int indent, pointer x) 3233dtree (SCHEME_P_ int indent, pointer x)
3242{ 3234{
3243 int c; 3235 int c;
3244 3236
3245 if (is_syntax (x)) 3237 if (is_syntax (x))
3246 { 3238 {
3264 printf ("%*sS<%s>\n", indent, "", symname (x)); 3256 printf ("%*sS<%s>\n", indent, "", symname (x));
3265 return 24+8; 3257 return 24+8;
3266 3258
3267 case T_CLOSURE: 3259 case T_CLOSURE:
3268 printf ("%*sS<%s>\n", indent, "", "closure"); 3260 printf ("%*sS<%s>\n", indent, "", "closure");
3269 debug (SCHEME_A_ indent + 3, cdr(x)); 3261 dtree (SCHEME_A_ indent + 3, cdr(x));
3270 return 32 + debug (SCHEME_A_ indent + 3, car (x)); 3262 return 32 + dtree (SCHEME_A_ indent + 3, car (x));
3271 3263
3272 case T_PAIR: 3264 case T_PAIR:
3273 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); 3265 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3274 c = debug (SCHEME_A_ indent + 3, car (x)); 3266 c = dtree (SCHEME_A_ indent + 3, car (x));
3275 c += debug (SCHEME_A_ indent + 3, cdr (x)); 3267 c += dtree (SCHEME_A_ indent + 3, cdr (x));
3276 return c + 1; 3268 return c + 1;
3277 3269
3278 case T_PORT: 3270 case T_PORT:
3279 printf ("%*sS<%s>\n", indent, "", "port"); 3271 printf ("%*sS<%s>\n", indent, "", "port");
3280 return 24+8; 3272 return 24+8;
3283 printf ("%*sS<%s>\n", indent, "", "vector"); 3275 printf ("%*sS<%s>\n", indent, "", "vector");
3284 return 24+8; 3276 return 24+8;
3285 3277
3286 case T_ENVIRONMENT: 3278 case T_ENVIRONMENT:
3287 printf ("%*sS<%s>\n", indent, "", "environment"); 3279 printf ("%*sS<%s>\n", indent, "", "environment");
3288 return 0 + debug (SCHEME_A_ indent + 3, car (x)); 3280 return 0 + dtree (SCHEME_A_ indent + 3, car (x));
3289 3281
3290 default: 3282 default:
3291 printf ("unhandled type %d\n", type (x)); 3283 printf ("unhandled type %d\n", type (x));
3292 break; 3284 break;
3293 } 3285 }
3294} 3286}
3295#endif
3296 3287
3288#define DUMP(t) do { printf ("DUMP %s:%d\n", __FILE__, __LINE__); dtree (SCHEME_A_ 0, (t)); } while (0)
3289
3290typedef void *stream[1];
3291
3292#define stream_init() { 0 }
3293#define stream_data(s) ((char *)(s)[0] + sizeof (uint32_t) * 2)
3294#define stream_size(s) (((uint32_t *)(s)[0])[0] - sizeof (uint32_t) * 2)
3295#define stream_free(s) free (s[0])
3296
3297ecb_cold static void
3298stream_put (stream s, uint8_t byte)
3299{
3300 uint32_t *sp = *s;
3301 uint32_t size = sizeof (uint32_t) * 2;
3302 uint32_t offs = size;
3303
3304 if (ecb_expect_true (sp))
3305 {
3306 offs = sp[0];
3307 size = sp[1];
3308 }
3309
3310 if (ecb_expect_false (offs == size))
3311 {
3312 size *= 2;
3313 sp = realloc (sp, size);
3314 *s = sp;
3315 sp[1] = size;
3316
3317 }
3318
3319 ((uint8_t *)sp)[offs++] = byte;
3320 sp[0] = offs;
3321}
3322
3323ecb_cold static void
3324stream_put_v (stream s, uint32_t v)
3325{
3326 while (v > 0x7f)
3327 {
3328 stream_put (s, v | 0x80);
3329 v >>= 7;
3330 }
3331
3332 stream_put (s, v);
3333}
3334
3335ecb_cold static void
3336stream_put_tv (stream s, int bop, uint32_t v)
3337{
3338 printf ("put tv %d %d\n", bop, v);//D
3339 stream_put (s, bop);
3340 stream_put_v (s, v);
3341}
3342
3343ecb_cold static void
3344stream_put_stream (stream s, stream o)
3345{
3346 uint32_t i;
3347
3348 for (i = 0; i < stream_size (o); ++i)
3349 stream_put (s, stream_data (o)[i]);
3350
3351 stream_free (o);
3352}
3353
3354ecb_cold static uint32_t
3355cell_id (SCHEME_P_ pointer x)
3356{
3357 struct cell *p = CELL (x);
3358 int i;
3359
3360 for (i = SCHEME_V->last_cell_seg; i >= 0; --i)
3361 if (SCHEME_V->cell_seg[i] <= p && p < SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize[i])
3362 return i | ((p - SCHEME_V->cell_seg[i]) << CELL_NSEGMENT_LOG);
3363
3364 abort ();
3365}
3366
3367// calculates a (preferably small) integer that makes it possible to find
3368// the symbol again. if pointers were offsets into a memory area... until
3369// then, we return segment number in the low bits, and offset in the high
3370// bits.
3371// also, this function must never return 0.
3372ecb_cold static uint32_t
3373symbol_id (SCHEME_P_ pointer sym)
3374{
3375 return cell_id (SCHEME_A_ sym);
3376}
3377
3378enum byteop
3379{
3380 BOP_NIL,
3381 BOP_INTEGER,
3382 BOP_SYMBOL,
3383 BOP_DATUM,
3384 BOP_LIST_BEG,
3385 BOP_LIST_END,
3386 BOP_IF,
3387 BOP_AND,
3388 BOP_OR,
3389 BOP_CASE,
3390 BOP_COND,
3391 BOP_LET,
3392 BOP_LETAST,
3393 BOP_LETREC,
3394 BOP_DEFINE,
3395 BOP_MACRO,
3396 BOP_SET,
3397 BOP_BEGIN,
3398 BOP_LAMBDA,
3399 BOP_DELAY,
3400 BOP_OP,
3401};
3402
3403ecb_cold static void compile_expr (SCHEME_P_ stream s, pointer x);
3404
3405ecb_cold static void
3406compile_list (SCHEME_P_ stream s, pointer x)
3407{
3408 // TODO: improper list
3409
3410 for (; x != NIL; x = cdr (x))
3411 {
3412 stream t = stream_init ();
3413 compile_expr (SCHEME_A_ t, car (x));
3414 stream_put_v (s, stream_size (t));
3415 stream_put_stream (s, t);
3416 }
3417
3418 stream_put_v (s, 0);
3419}
3420
3421static void
3422compile_if (SCHEME_P_ stream s, pointer cond, pointer ift, pointer iff)
3423{
3424 stream sift = stream_init (); compile_expr (SCHEME_A_ sift, ift);
3425
3426 stream_put (s, BOP_IF);
3427 compile_expr (SCHEME_A_ s, cond);
3428 stream_put_v (s, stream_size (sift));
3429 stream_put_stream (s, sift);
3430 compile_expr (SCHEME_A_ s, iff);
3431}
3432
3433typedef uint32_t stream_fixup;
3434
3435static stream_fixup
3436stream_put_fixup (stream s)
3437{
3438 stream_put (s, 0);
3439 stream_put (s, 0);
3440
3441 return stream_size (s);
3442}
3443
3444static void
3445stream_fix_fixup (stream s, stream_fixup fixup, uint32_t target)
3446{
3447 target -= fixup;
3448 assert (target < (1 << 14));
3449 stream_data (s)[fixup - 2] = target | 0x80;
3450 stream_data (s)[fixup - 1] = target >> 7;
3451}
3452
3453static void
3454compile_and_or (SCHEME_P_ stream s, int and, pointer x)
3455{
3456 for (; cdr (x) != NIL; x = cdr (x))
3457 {
3458 stream t = stream_init ();
3459 compile_expr (SCHEME_A_ t, car (x));
3460 stream_put_v (s, stream_size (t));
3461 stream_put_stream (s, t);
3462 }
3463
3464 stream_put_v (s, 0);
3465}
3466
3467static void
3468compile_case (SCHEME_P_ stream s, pointer x)
3469{
3470 compile_expr (SCHEME_A_ s, caar (x));
3471
3472 for (;;)
3473 {
3474 x = cdr (x);
3475
3476 if (x == NIL)
3477 break;
3478
3479 compile_expr (SCHEME_A_ s, caar (x));
3480 stream t = stream_init (); compile_expr (SCHEME_A_ t, cdar (x));
3481 stream_put_v (s, stream_size (t));
3482 stream_put_stream (s, t);
3483 }
3484
3485 stream_put_v (s, 0);
3486}
3487
3488static void
3489compile_cond (SCHEME_P_ stream s, pointer x)
3490{
3491 for ( ; x != NIL; x = cdr (x))
3492 {
3493 compile_expr (SCHEME_A_ s, caar (x));
3494 stream t = stream_init (); compile_expr (SCHEME_A_ t, cdar (x));
3495 stream_put_v (s, stream_size (t));
3496 stream_put_stream (s, t);
3497 }
3498
3499 stream_put_v (s, 0);
3500}
3501
3297static int 3502static pointer
3503lookup (SCHEME_P_ pointer x)
3504{
3505 x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, x, 1);
3506
3507 if (x != NIL)
3508 x = slot_value_in_env (x);
3509
3510 return x;
3511}
3512
3513ecb_cold static void
3514compile_expr (SCHEME_P_ stream s, pointer x)
3515{
3516 if (x == NIL)
3517 {
3518 stream_put (s, BOP_NIL);
3519 return;
3520 }
3521
3522 if (is_pair (x))
3523 {
3524 pointer head = car (x);
3525
3526 if (is_syntax (head))
3527 {
3528 int syn = syntaxnum (head);
3529 x = cdr (x);
3530
3531 switch (syntaxnum (head))
3532 {
3533 case OP_IF0: /* if */
3534 stream_put_v (s, BOP_IF);
3535 compile_if (SCHEME_A_ s, car (x), cadr (x), caddr (x));
3536 break;
3537
3538 case OP_OR0: /* or */
3539 stream_put_v (s, BOP_OR);
3540 compile_and_or (SCHEME_A_ s, 0, x);
3541 break;
3542
3543 case OP_AND0: /* and */
3544 stream_put_v (s, BOP_AND);
3545 compile_and_or (SCHEME_A_ s, 1, x);
3546 break;
3547
3548 case OP_CASE0: /* case */
3549 stream_put_v (s, BOP_CASE);
3550 compile_case (SCHEME_A_ s, x);
3551 break;
3552
3553 case OP_COND0: /* cond */
3554 stream_put_v (s, BOP_COND);
3555 compile_cond (SCHEME_A_ s, x);
3556 break;
3557
3558 case OP_LET0: /* let */
3559 case OP_LET0AST: /* let* */
3560 case OP_LET0REC: /* letrec */
3561 switch (syn)
3562 {
3563 case OP_LET0: stream_put (s, BOP_LET ); break;
3564 case OP_LET0AST: stream_put (s, BOP_LETAST); break;
3565 case OP_LET0REC: stream_put (s, BOP_LETREC); break;
3566 }
3567
3568 {
3569 pointer bindings = car (x);
3570 pointer body = cadr (x);
3571
3572 for (x = bindings; x != NIL; x = cdr (x))
3573 {
3574 pointer init = NIL;
3575 pointer var = car (x);
3576
3577 if (is_pair (var))
3578 {
3579 init = cdr (var);
3580 var = car (var);
3581 }
3582
3583 stream_put_v (s, symbol_id (SCHEME_A_ var));
3584 compile_expr (SCHEME_A_ s, init);
3585 }
3586
3587 stream_put_v (s, 0);
3588 compile_expr (SCHEME_A_ s, body);
3589 }
3590 break;
3591
3592 case OP_DEF0: /* define */
3593 case OP_MACRO0: /* macro */
3594 stream_put (s, syntaxnum (head) == OP_DEF0 ? BOP_DEFINE : BOP_MACRO);
3595 stream_put_v (s, cell_id (SCHEME_A_ car (x)));
3596 compile_expr (SCHEME_A_ s, cadr (x));
3597 break;
3598
3599 case OP_SET0: /* set! */
3600 stream_put (s, BOP_SET);
3601 stream_put_v (s, symbol_id (SCHEME_A_ car (x)));
3602 compile_expr (SCHEME_A_ s, cadr (x));
3603 break;
3604
3605 case OP_BEGIN: /* begin */
3606 stream_put (s, BOP_BEGIN);
3607 compile_list (SCHEME_A_ s, x);
3608 return;
3609
3610 case OP_QUOTE: /* quote */
3611 stream_put_tv (s, BOP_DATUM, cell_id (SCHEME_A_ x));
3612 break;
3613
3614 case OP_DELAY: /* delay */
3615 stream_put (s, BOP_DELAY);
3616 compile_expr (SCHEME_A_ s, x);
3617 break;
3618
3619 case OP_LAMBDA: /* lambda */
3620 {
3621 pointer formals = car (x);
3622 pointer body = cadr (x);
3623
3624 stream_put (s, BOP_LAMBDA);
3625
3626 for (; is_pair (formals); formals = cdr (formals))
3627 stream_put_v (s, symbol_id (SCHEME_A_ car (formals)));
3628
3629 stream_put_v (s, 0);
3630 stream_put_v (s, formals == NIL ? 0 : symbol_id (SCHEME_A_ formals));
3631
3632 compile_expr (SCHEME_A_ s, body);
3633 }
3634 break;
3635
3636 case OP_C0STREAM:/* cons-stream */
3637 abort ();
3638 break;
3639 }
3640
3641 return;
3642 }
3643
3644 pointer m = lookup (SCHEME_A_ head);
3645
3646 if (is_macro (m))
3647 {
3648 s_save (SCHEME_A_ OP_DEBUG2, SCHEME_V->args, SCHEME_V->code);
3649 SCHEME_V->code = m;
3650 SCHEME_V->args = cons (x, NIL);
3651 Eval_Cycle (SCHEME_A_ OP_APPLY);
3652 x = SCHEME_V->value;
3653 compile_expr (SCHEME_A_ s, SCHEME_V->value);
3654 return;
3655 }
3656
3657 stream_put (s, BOP_LIST_BEG);
3658
3659 for (; x != NIL; x = cdr (x))
3660 compile_expr (SCHEME_A_ s, car (x));
3661
3662 stream_put (s, BOP_LIST_END);
3663 return;
3664 }
3665
3666 switch (type (x))
3667 {
3668 case T_INTEGER:
3669 {
3670 IVALUE iv = ivalue_unchecked (x);
3671 iv = iv < 0 ? ((~(uint32_t)iv) << 1) | 1 : (uint32_t)iv << 1;
3672 stream_put_tv (s, BOP_INTEGER, iv);
3673 }
3674 return;
3675
3676 case T_SYMBOL:
3677 if (0)
3678 {
3679 // no can do without more analysis
3680 pointer m = lookup (SCHEME_A_ x);
3681
3682 if (is_proc (m))
3683 {
3684 printf ("compile proc %s %d\n", procname(m), procnum(m));
3685 stream_put_tv (s, BOP_SYMBOL, BOP_OP + procnum (m));
3686 }
3687 else
3688 stream_put_tv (s, BOP_SYMBOL, symbol_id (SCHEME_A_ x));
3689 }
3690
3691 stream_put_tv (s, BOP_SYMBOL, symbol_id (SCHEME_A_ x));
3692 return;
3693
3694 default:
3695 stream_put_tv (s, BOP_DATUM, cell_id (SCHEME_A_ x));
3696 break;
3697 }
3698}
3699
3700ecb_cold static int
3701compile_closure (SCHEME_P_ pointer p)
3702{
3703 stream s = stream_init ();
3704
3705 compile_list (SCHEME_A_ s, cdar (p));
3706
3707 FILE *xxd = popen ("xxd", "we");
3708 fwrite (stream_data (s), 1, stream_size (s), xxd);
3709 fclose (xxd);
3710
3711 return stream_size (s);
3712}
3713
3714#endif
3715
3716/* syntax, eval, core, ... */
3717ecb_hot static int
3298opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3718opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3299{ 3719{
3300 pointer args = SCHEME_V->args; 3720 pointer args = SCHEME_V->args;
3301 pointer x, y; 3721 pointer x, y;
3302 3722
3303 switch (op) 3723 switch (op)
3304 { 3724 {
3305#if EXPERIMENT //D 3725#if EXPERIMENT //D
3306 case OP_DEBUG: 3726 case OP_DEBUG:
3307 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); 3727 {
3728 uint32_t len = compile_closure (SCHEME_A_ car (args));
3729 printf ("len = %d\n", len);
3308 printf ("\n"); 3730 printf ("\n");
3309 s_return (S_T); 3731 s_return (S_T);
3732 }
3733
3734 case OP_DEBUG2:
3735 return -1;
3310#endif 3736#endif
3737
3311 case OP_LOAD: /* load */ 3738 case OP_LOAD: /* load */
3312 if (file_interactive (SCHEME_A)) 3739 if (file_interactive (SCHEME_A))
3313 { 3740 {
3314 putstr (SCHEME_A_ "Loading "); putstr (SCHEME_A_ strvalue (car (args))); putstr (SCHEME_A_ "\n"); 3741 putstr (SCHEME_A_ "Loading ");
3315 //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); 3742 putstr (SCHEME_A_ strvalue (car (args)));
3743 putcharacter (SCHEME_A_ '\n');
3316 } 3744 }
3317 3745
3318 if (!file_push (SCHEME_A_ strvalue (car (args)))) 3746 if (!file_push (SCHEME_A_ strvalue (car (args))))
3319 Error_1 ("unable to open", car (args)); 3747 Error_1 ("unable to open", car (args));
3320 else 3748
3321 {
3322 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 3749 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
3323 s_goto (OP_T0LVL); 3750 s_goto (OP_T0LVL);
3324 }
3325 3751
3326 case OP_T0LVL: /* top level */ 3752 case OP_T0LVL: /* top level */
3327 3753
3328 /* If we reached the end of file, this loop is done. */ 3754 /* If we reached the end of file, this loop is done. */
3329 if (port (SCHEME_V->loadport)->kind & port_saw_EOF) 3755 if (port (SCHEME_V->loadport)->kind & port_saw_EOF)
3345 /* If interactive, be nice to user. */ 3771 /* If interactive, be nice to user. */
3346 if (file_interactive (SCHEME_A)) 3772 if (file_interactive (SCHEME_A))
3347 { 3773 {
3348 SCHEME_V->envir = SCHEME_V->global_env; 3774 SCHEME_V->envir = SCHEME_V->global_env;
3349 dump_stack_reset (SCHEME_A); 3775 dump_stack_reset (SCHEME_A);
3350 putstr (SCHEME_A_ "\n"); 3776 putcharacter (SCHEME_A_ '\n');
3777#if EXPERIMENT
3778 system ("ps v $PPID");
3779#endif
3351 putstr (SCHEME_A_ prompt); 3780 putstr (SCHEME_A_ prompt);
3352 } 3781 }
3353 3782
3354 /* Set up another iteration of REPL */ 3783 /* Set up another iteration of REPL */
3355 SCHEME_V->nesting = 0; 3784 SCHEME_V->nesting = 0;
3390 { 3819 {
3391 SCHEME_V->print_flag = 1; 3820 SCHEME_V->print_flag = 1;
3392 SCHEME_V->args = SCHEME_V->value; 3821 SCHEME_V->args = SCHEME_V->value;
3393 s_goto (OP_P0LIST); 3822 s_goto (OP_P0LIST);
3394 } 3823 }
3395 else 3824
3396 s_return (SCHEME_V->value); 3825 s_return (SCHEME_V->value);
3397 3826
3398 case OP_EVAL: /* main part of evaluation */ 3827 case OP_EVAL: /* main part of evaluation */
3399#if USE_TRACING 3828#if USE_TRACING
3400 if (SCHEME_V->tracing) 3829 if (SCHEME_V->tracing)
3401 { 3830 {
3434 /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */ 3863 /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */
3435 SCHEME_V->code = x; 3864 SCHEME_V->code = x;
3436 s_goto (OP_EVAL); 3865 s_goto (OP_EVAL);
3437 } 3866 }
3438 } 3867 }
3439 else 3868
3440 s_return (SCHEME_V->code); 3869 s_return (SCHEME_V->code);
3441 3870
3442 case OP_E0ARGS: /* eval arguments */ 3871 case OP_E0ARGS: /* eval arguments */
3443 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ 3872 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3444 { 3873 {
3445 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3874 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3446 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3875 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3447 SCHEME_V->code = SCHEME_V->value; 3876 SCHEME_V->code = SCHEME_V->value;
3448 s_goto (OP_APPLY); 3877 s_goto (OP_APPLY);
3449 } 3878 }
3450 else 3879
3451 {
3452 SCHEME_V->code = cdr (SCHEME_V->code); 3880 SCHEME_V->code = cdr (SCHEME_V->code);
3453 s_goto (OP_E1ARGS); 3881 s_goto (OP_E1ARGS);
3454 }
3455 3882
3456 case OP_E1ARGS: /* eval arguments */ 3883 case OP_E1ARGS: /* eval arguments */
3457 args = cons (SCHEME_V->value, args); 3884 args = cons (SCHEME_V->value, args);
3458 3885
3459 if (is_pair (SCHEME_V->code)) /* continue */ 3886 if (is_pair (SCHEME_V->code)) /* continue */
3470 SCHEME_V->args = cdr (args); 3897 SCHEME_V->args = cdr (args);
3471 s_goto (OP_APPLY); 3898 s_goto (OP_APPLY);
3472 } 3899 }
3473 3900
3474#if USE_TRACING 3901#if USE_TRACING
3475
3476 case OP_TRACING: 3902 case OP_TRACING:
3477 { 3903 {
3478 int tr = SCHEME_V->tracing; 3904 int tr = SCHEME_V->tracing;
3479 3905
3480 SCHEME_V->tracing = ivalue_unchecked (car (args)); 3906 SCHEME_V->tracing = ivalue_unchecked (car (args));
3481 s_return (mk_integer (SCHEME_A_ tr)); 3907 s_return (mk_integer (SCHEME_A_ tr));
3482 } 3908 }
3483
3484#endif 3909#endif
3485 3910
3486 case OP_APPLY: /* apply 'code' to 'args' */ 3911 case OP_APPLY: /* apply 'code' to 'args' */
3487#if USE_TRACING 3912#if USE_TRACING
3488 if (SCHEME_V->tracing) 3913 if (SCHEME_V->tracing)
3542 else if (is_continuation (SCHEME_V->code)) /* CONTINUATION */ 3967 else if (is_continuation (SCHEME_V->code)) /* CONTINUATION */
3543 { 3968 {
3544 ss_set_cont (SCHEME_A_ cont_dump (SCHEME_V->code)); 3969 ss_set_cont (SCHEME_A_ cont_dump (SCHEME_V->code));
3545 s_return (args != NIL ? car (args) : NIL); 3970 s_return (args != NIL ? car (args) : NIL);
3546 } 3971 }
3547 else 3972
3548 Error_0 ("illegal function"); 3973 Error_0 ("illegal function");
3549 3974
3550 case OP_DOMACRO: /* do macro */ 3975 case OP_DOMACRO: /* do macro */
3551 SCHEME_V->code = SCHEME_V->value; 3976 SCHEME_V->code = SCHEME_V->value;
3552 s_goto (OP_EVAL); 3977 s_goto (OP_EVAL);
3553 3978
3617 else 4042 else
3618 new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value); 4043 new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value);
3619 4044
3620 s_return (SCHEME_V->code); 4045 s_return (SCHEME_V->code);
3621 4046
3622
3623 case OP_DEFP: /* defined? */ 4047 case OP_DEFP: /* defined? */
3624 x = SCHEME_V->envir; 4048 x = SCHEME_V->envir;
3625 4049
3626 if (cdr (args) != NIL) 4050 if (cdr (args) != NIL)
3627 x = cadr (args); 4051 x = cadr (args);
3645 s_return (SCHEME_V->value); 4069 s_return (SCHEME_V->value);
3646 } 4070 }
3647 else 4071 else
3648 Error_1 ("set!: unbound variable:", SCHEME_V->code); 4072 Error_1 ("set!: unbound variable:", SCHEME_V->code);
3649 4073
3650
3651 case OP_BEGIN: /* begin */ 4074 case OP_BEGIN: /* begin */
3652 if (!is_pair (SCHEME_V->code)) 4075 if (!is_pair (SCHEME_V->code))
3653 s_return (SCHEME_V->code); 4076 s_return (SCHEME_V->code);
3654 4077
3655 if (cdr (SCHEME_V->code) != NIL) 4078 if (cdr (SCHEME_V->code) != NIL)
3666 case OP_IF1: /* if */ 4089 case OP_IF1: /* if */
3667 if (is_true (SCHEME_V->value)) 4090 if (is_true (SCHEME_V->value))
3668 SCHEME_V->code = car (SCHEME_V->code); 4091 SCHEME_V->code = car (SCHEME_V->code);
3669 else 4092 else
3670 SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */ 4093 SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */
4094
3671 s_goto (OP_EVAL); 4095 s_goto (OP_EVAL);
3672 4096
3673 case OP_LET0: /* let */ 4097 case OP_LET0: /* let */
3674 SCHEME_V->args = NIL; 4098 SCHEME_V->args = NIL;
3675 SCHEME_V->value = SCHEME_V->code; 4099 SCHEME_V->value = SCHEME_V->code;
3676 SCHEME_V->code = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code); 4100 SCHEME_V->code = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code);
3677 s_goto (OP_LET1); 4101 s_goto (OP_LET1);
3678 4102
3679 case OP_LET1: /* let (calculate parameters) */ 4103 case OP_LET1: /* let (calculate parameters) */
4104 case OP_LET1REC: /* letrec (calculate parameters) */
3680 args = cons (SCHEME_V->value, args); 4105 args = cons (SCHEME_V->value, args);
3681 4106
3682 if (is_pair (SCHEME_V->code)) /* continue */ 4107 if (is_pair (SCHEME_V->code)) /* continue */
3683 { 4108 {
3684 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code))) 4109 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code)))
3685 Error_1 ("Bad syntax of binding spec in let :", car (SCHEME_V->code)); 4110 Error_1 ("Bad syntax of binding spec in let/letrec:", car (SCHEME_V->code));
3686 4111
3687 s_save (SCHEME_A_ OP_LET1, args, cdr (SCHEME_V->code)); 4112 s_save (SCHEME_A_ op, args, cdr (SCHEME_V->code));
3688 SCHEME_V->code = cadar (SCHEME_V->code); 4113 SCHEME_V->code = cadar (SCHEME_V->code);
3689 SCHEME_V->args = NIL; 4114 SCHEME_V->args = NIL;
3690 s_goto (OP_EVAL); 4115 s_goto (OP_EVAL);
3691 } 4116 }
3692 else /* end */ 4117
3693 { 4118 /* end */
3694 args = reverse_in_place (SCHEME_A_ NIL, args); 4119 args = reverse_in_place (SCHEME_A_ NIL, args);
3695 SCHEME_V->code = car (args); 4120 SCHEME_V->code = car (args);
3696 SCHEME_V->args = cdr (args); 4121 SCHEME_V->args = cdr (args);
3697 s_goto (OP_LET2); 4122 s_goto (op == OP_LET1 ? OP_LET2 : OP_LET2REC);
3698 }
3699 4123
3700 case OP_LET2: /* let */ 4124 case OP_LET2: /* let */
3701 new_frame_in_env (SCHEME_A_ SCHEME_V->envir); 4125 new_frame_in_env (SCHEME_A_ SCHEME_V->envir);
3702 4126
3703 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args; 4127 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args;
3707 if (is_symbol (car (SCHEME_V->code))) /* named let */ 4131 if (is_symbol (car (SCHEME_V->code))) /* named let */
3708 { 4132 {
3709 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x)) 4133 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x))
3710 { 4134 {
3711 if (!is_pair (x)) 4135 if (!is_pair (x))
3712 Error_1 ("Bad syntax of binding in let :", x); 4136 Error_1 ("Bad syntax of binding in let:", x);
3713 4137
3714 if (!is_list (SCHEME_A_ car (x))) 4138 if (!is_list (SCHEME_A_ car (x)))
3715 Error_1 ("Bad syntax of binding in let :", car (x)); 4139 Error_1 ("Bad syntax of binding in let:", car (x));
3716 4140
3717 args = cons (caar (x), args); 4141 args = cons (caar (x), args);
3718 } 4142 }
3719 4143
3720 x = mk_closure (SCHEME_A_ cons (reverse_in_place (SCHEME_A_ NIL, args), cddr (SCHEME_V->code)), 4144 x = mk_closure (SCHEME_A_ cons (reverse_in_place (SCHEME_A_ NIL, args), cddr (SCHEME_V->code)),
3737 SCHEME_V->code = cdr (SCHEME_V->code); 4161 SCHEME_V->code = cdr (SCHEME_V->code);
3738 s_goto (OP_BEGIN); 4162 s_goto (OP_BEGIN);
3739 } 4163 }
3740 4164
3741 if (!is_pair (car (SCHEME_V->code)) || !is_pair (caar (SCHEME_V->code)) || !is_pair (cdaar (SCHEME_V->code))) 4165 if (!is_pair (car (SCHEME_V->code)) || !is_pair (caar (SCHEME_V->code)) || !is_pair (cdaar (SCHEME_V->code)))
3742 Error_1 ("Bad syntax of binding spec in let* :", car (SCHEME_V->code)); 4166 Error_1 ("Bad syntax of binding spec in let*:", car (SCHEME_V->code));
3743 4167
3744 s_save (SCHEME_A_ OP_LET1AST, cdr (SCHEME_V->code), car (SCHEME_V->code)); 4168 s_save (SCHEME_A_ OP_LET1AST, cdr (SCHEME_V->code), car (SCHEME_V->code));
3745 SCHEME_V->code = car (cdaar (SCHEME_V->code)); 4169 SCHEME_V->code = car (cdaar (SCHEME_V->code));
3746 s_goto (OP_EVAL); 4170 s_goto (OP_EVAL);
3747 4171
3758 s_save (SCHEME_A_ OP_LET2AST, args, SCHEME_V->code); 4182 s_save (SCHEME_A_ OP_LET2AST, args, SCHEME_V->code);
3759 SCHEME_V->code = cadar (SCHEME_V->code); 4183 SCHEME_V->code = cadar (SCHEME_V->code);
3760 SCHEME_V->args = NIL; 4184 SCHEME_V->args = NIL;
3761 s_goto (OP_EVAL); 4185 s_goto (OP_EVAL);
3762 } 4186 }
3763 else /* end */ 4187
4188 /* end */
3764 { 4189
3765 SCHEME_V->code = args; 4190 SCHEME_V->code = args;
3766 SCHEME_V->args = NIL; 4191 SCHEME_V->args = NIL;
3767 s_goto (OP_BEGIN); 4192 s_goto (OP_BEGIN);
3768 }
3769 4193
3770 case OP_LET0REC: /* letrec */ 4194 case OP_LET0REC: /* letrec */
3771 new_frame_in_env (SCHEME_A_ SCHEME_V->envir); 4195 new_frame_in_env (SCHEME_A_ SCHEME_V->envir);
3772 SCHEME_V->args = NIL; 4196 SCHEME_V->args = NIL;
3773 SCHEME_V->value = SCHEME_V->code; 4197 SCHEME_V->value = SCHEME_V->code;
3774 SCHEME_V->code = car (SCHEME_V->code); 4198 SCHEME_V->code = car (SCHEME_V->code);
3775 s_goto (OP_LET1REC); 4199 s_goto (OP_LET1REC);
3776 4200
3777 case OP_LET1REC: /* letrec (calculate parameters) */ 4201 /* OP_LET1REC handled by OP_LET1 */
3778 args = cons (SCHEME_V->value, args);
3779
3780 if (is_pair (SCHEME_V->code)) /* continue */
3781 {
3782 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code)))
3783 Error_1 ("Bad syntax of binding spec in letrec :", car (SCHEME_V->code));
3784
3785 s_save (SCHEME_A_ OP_LET1REC, args, cdr (SCHEME_V->code));
3786 SCHEME_V->code = cadar (SCHEME_V->code);
3787 SCHEME_V->args = NIL;
3788 s_goto (OP_EVAL);
3789 }
3790 else /* end */
3791 {
3792 args = reverse_in_place (SCHEME_A_ NIL, args);
3793 SCHEME_V->code = car (args);
3794 SCHEME_V->args = cdr (args);
3795 s_goto (OP_LET2REC);
3796 }
3797 4202
3798 case OP_LET2REC: /* letrec */ 4203 case OP_LET2REC: /* letrec */
3799 for (x = car (SCHEME_V->code), y = args; y != NIL; x = cdr (x), y = cdr (y)) 4204 for (x = car (SCHEME_V->code), y = args; y != NIL; x = cdr (x), y = cdr (y))
3800 new_slot_in_env (SCHEME_A_ caar (x), car (y)); 4205 new_slot_in_env (SCHEME_A_ caar (x), car (y));
3801 4206
3831 } 4236 }
3832 else 4237 else
3833 { 4238 {
3834 if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL) 4239 if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL)
3835 s_return (NIL); 4240 s_return (NIL);
3836 else 4241
3837 {
3838 s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code); 4242 s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code);
3839 SCHEME_V->code = caar (SCHEME_V->code); 4243 SCHEME_V->code = caar (SCHEME_V->code);
3840 s_goto (OP_EVAL); 4244 s_goto (OP_EVAL);
3841 }
3842 } 4245 }
3843 4246
3844 case OP_DELAY: /* delay */ 4247 case OP_DELAY: /* delay */
3845 x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir); 4248 x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir);
3846 set_typeflag (x, T_PROMISE); 4249 set_typeflag (x, T_PROMISE);
3857 case OP_AND1: /* and */ 4260 case OP_AND1: /* and */
3858 if (is_false (SCHEME_V->value)) 4261 if (is_false (SCHEME_V->value))
3859 s_return (SCHEME_V->value); 4262 s_return (SCHEME_V->value);
3860 else if (SCHEME_V->code == NIL) 4263 else if (SCHEME_V->code == NIL)
3861 s_return (SCHEME_V->value); 4264 s_return (SCHEME_V->value);
3862 else 4265
3863 {
3864 s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code)); 4266 s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code));
3865 SCHEME_V->code = car (SCHEME_V->code); 4267 SCHEME_V->code = car (SCHEME_V->code);
3866 s_goto (OP_EVAL); 4268 s_goto (OP_EVAL);
3867 }
3868 4269
3869 case OP_OR0: /* or */ 4270 case OP_OR0: /* or */
3870 if (SCHEME_V->code == NIL) 4271 if (SCHEME_V->code == NIL)
3871 s_return (S_F); 4272 s_return (S_F);
3872 4273
3877 case OP_OR1: /* or */ 4278 case OP_OR1: /* or */
3878 if (is_true (SCHEME_V->value)) 4279 if (is_true (SCHEME_V->value))
3879 s_return (SCHEME_V->value); 4280 s_return (SCHEME_V->value);
3880 else if (SCHEME_V->code == NIL) 4281 else if (SCHEME_V->code == NIL)
3881 s_return (SCHEME_V->value); 4282 s_return (SCHEME_V->value);
3882 else 4283
3883 {
3884 s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code)); 4284 s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code));
3885 SCHEME_V->code = car (SCHEME_V->code); 4285 SCHEME_V->code = car (SCHEME_V->code);
3886 s_goto (OP_EVAL); 4286 s_goto (OP_EVAL);
3887 }
3888 4287
3889 case OP_C0STREAM: /* cons-stream */ 4288 case OP_C0STREAM: /* cons-stream */
3890 s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code)); 4289 s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code));
3891 SCHEME_V->code = car (SCHEME_V->code); 4290 SCHEME_V->code = car (SCHEME_V->code);
3892 s_goto (OP_EVAL); 4291 s_goto (OP_EVAL);
3957 s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x)); 4356 s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x));
3958 SCHEME_V->code = caar (x); 4357 SCHEME_V->code = caar (x);
3959 s_goto (OP_EVAL); 4358 s_goto (OP_EVAL);
3960 } 4359 }
3961 } 4360 }
3962 else 4361
3963 s_return (NIL); 4362 s_return (NIL);
3964 4363
3965 case OP_CASE2: /* case */ 4364 case OP_CASE2: /* case */
3966 if (is_true (SCHEME_V->value)) 4365 if (is_true (SCHEME_V->value))
3967 s_goto (OP_BEGIN); 4366 s_goto (OP_BEGIN);
3968 else 4367
3969 s_return (NIL); 4368 s_return (NIL);
3970 4369
3971 case OP_PAPPLY: /* apply */ 4370 case OP_PAPPLY: /* apply */
3972 SCHEME_V->code = car (args); 4371 SCHEME_V->code = car (args);
3973 SCHEME_V->args = list_star (SCHEME_A_ cdr (args)); 4372 SCHEME_V->args = list_star (SCHEME_A_ cdr (args));
3974 /*SCHEME_V->args = cadr(args); */ 4373 /*SCHEME_V->args = cadr(args); */
3988 } 4387 }
3989 4388
3990 if (USE_ERROR_CHECKING) abort (); 4389 if (USE_ERROR_CHECKING) abort ();
3991} 4390}
3992 4391
3993static int 4392/* math, cxr */
4393ecb_hot static int
3994opexe_1 (SCHEME_P_ enum scheme_opcodes op) 4394opexe_1 (SCHEME_P_ enum scheme_opcodes op)
3995{ 4395{
3996 pointer args = SCHEME_V->args; 4396 pointer args = SCHEME_V->args;
3997 pointer x = car (args); 4397 pointer x = car (args);
3998 num v; 4398 num v;
4011 Error_1 ("inexact->exact: not integral:", x); 4411 Error_1 ("inexact->exact: not integral:", x);
4012 } 4412 }
4013 4413
4014 s_return (x); 4414 s_return (x);
4015 4415
4416 case OP_FLOOR: s_return (mk_real (SCHEME_A_ floor (rvalue (x))));
4417 case OP_CEILING: s_return (mk_real (SCHEME_A_ ceil (rvalue (x))));
4418 case OP_TRUNCATE: s_return (mk_real (SCHEME_A_ trunc (rvalue (x))));
4419 case OP_ROUND: s_return (mk_real (SCHEME_A_ nearbyint (rvalue (x))));
4420
4421 case OP_SQRT: s_return (mk_real (SCHEME_A_ sqrt (rvalue (x))));
4016 case OP_EXP: s_return (mk_real (SCHEME_A_ exp (rvalue (x)))); 4422 case OP_EXP: s_return (mk_real (SCHEME_A_ exp (rvalue (x))));
4017 case OP_LOG: s_return (mk_real (SCHEME_A_ log (rvalue (x)) 4423 case OP_LOG: s_return (mk_real (SCHEME_A_ log (rvalue (x))
4018 / (cadr (args) == NIL ? 1 : log (rvalue (cadr (args)))))); 4424 / (cadr (args) == NIL ? 1 : log (rvalue (cadr (args))))));
4019 case OP_SIN: s_return (mk_real (SCHEME_A_ sin (rvalue (x)))); 4425 case OP_SIN: s_return (mk_real (SCHEME_A_ sin (rvalue (x))));
4020 case OP_COS: s_return (mk_real (SCHEME_A_ cos (rvalue (x)))); 4426 case OP_COS: s_return (mk_real (SCHEME_A_ cos (rvalue (x))));
4026 s_return (mk_real (SCHEME_A_ 4432 s_return (mk_real (SCHEME_A_
4027 cdr (args) == NIL 4433 cdr (args) == NIL
4028 ? atan (rvalue (x)) 4434 ? atan (rvalue (x))
4029 : atan2 (rvalue (x), rvalue (cadr (args))))); 4435 : atan2 (rvalue (x), rvalue (cadr (args)))));
4030 4436
4031 case OP_SQRT:
4032 s_return (mk_real (SCHEME_A_ sqrt (rvalue (x))));
4033
4034 case OP_EXPT: 4437 case OP_EXPT:
4035 { 4438 {
4036 RVALUE result; 4439 RVALUE result;
4037 int real_result = 1; 4440 int real_result = 1;
4038 pointer y = cadr (args); 4441 pointer y = cadr (args);
4060 if (real_result) 4463 if (real_result)
4061 s_return (mk_real (SCHEME_A_ result)); 4464 s_return (mk_real (SCHEME_A_ result));
4062 else 4465 else
4063 s_return (mk_integer (SCHEME_A_ result)); 4466 s_return (mk_integer (SCHEME_A_ result));
4064 } 4467 }
4065
4066 case OP_FLOOR: s_return (mk_real (SCHEME_A_ floor (rvalue (x))));
4067 case OP_CEILING: s_return (mk_real (SCHEME_A_ ceil (rvalue (x))));
4068 case OP_TRUNCATE: s_return (mk_real (SCHEME_A_ trunc (rvalue (x))));
4069 case OP_ROUND: s_return (mk_real (SCHEME_A_ nearbyint (rvalue (x))));
4070#endif 4468#endif
4071 4469
4072 case OP_ADD: /* + */ 4470 case OP_ADD: /* + */
4073 v = num_zero; 4471 v = num_zero;
4074 4472
4376 memcpy (pos, strvalue (car (x)), strlength (car (x))); 4774 memcpy (pos, strvalue (car (x)), strlength (car (x)));
4377 4775
4378 s_return (newstr); 4776 s_return (newstr);
4379 } 4777 }
4380 4778
4381 case OP_SUBSTR: /* substring */ 4779 case OP_STRING_COPY: /* substring/string-copy */
4382 { 4780 {
4383 char *str = strvalue (x); 4781 char *str = strvalue (x);
4384 int index0 = ivalue_unchecked (cadr (args)); 4782 int index0 = cadr (args) == NIL ? 0 : ivalue_unchecked (cadr (args));
4385 int index1; 4783 int index1;
4386 int len; 4784 int len;
4387 4785
4388 if (index0 > strlength (x)) 4786 if (index0 > strlength (x))
4389 Error_1 ("substring: start out of bounds:", cadr (args)); 4787 Error_1 ("string->copy: start out of bounds:", cadr (args));
4390 4788
4391 if (cddr (args) != NIL) 4789 if (cddr (args) != NIL)
4392 { 4790 {
4393 index1 = ivalue_unchecked (caddr (args)); 4791 index1 = ivalue_unchecked (caddr (args));
4394 4792
4395 if (index1 > strlength (x) || index1 < index0) 4793 if (index1 > strlength (x) || index1 < index0)
4396 Error_1 ("substring: end out of bounds:", caddr (args)); 4794 Error_1 ("string->copy: end out of bounds:", caddr (args));
4397 } 4795 }
4398 else 4796 else
4399 index1 = strlength (x); 4797 index1 = strlength (x);
4400 4798
4401 len = index1 - index0; 4799 len = index1 - index0;
4402 x = mk_empty_string (SCHEME_A_ len, ' '); 4800 x = mk_counted_string (SCHEME_A_ str + index0, len);
4403 memcpy (strvalue (x), str + index0, len);
4404 strvalue (x)[len] = 0;
4405 4801
4406 s_return (x); 4802 s_return (x);
4407 } 4803 }
4408 4804
4409 case OP_VECTOR: /* vector */ 4805 case OP_VECTOR: /* vector */
4483 } 4879 }
4484 4880
4485 if (USE_ERROR_CHECKING) abort (); 4881 if (USE_ERROR_CHECKING) abort ();
4486} 4882}
4487 4883
4488static int 4884/* relational ops */
4885ecb_hot static int
4489opexe_2 (SCHEME_P_ enum scheme_opcodes op) 4886opexe_2 (SCHEME_P_ enum scheme_opcodes op)
4490{ 4887{
4491 pointer x = SCHEME_V->args; 4888 pointer x = SCHEME_V->args;
4492 4889
4493 for (;;) 4890 for (;;)
4514 } 4911 }
4515 4912
4516 s_return (S_T); 4913 s_return (S_T);
4517} 4914}
4518 4915
4519static int 4916/* predicates */
4917ecb_hot static int
4520opexe_3 (SCHEME_P_ enum scheme_opcodes op) 4918opexe_3 (SCHEME_P_ enum scheme_opcodes op)
4521{ 4919{
4522 pointer args = SCHEME_V->args; 4920 pointer args = SCHEME_V->args;
4523 pointer a = car (args); 4921 pointer a = car (args);
4524 pointer d = cdr (args); 4922 pointer d = cdr (args);
4571 } 4969 }
4572 4970
4573 s_retbool (r); 4971 s_retbool (r);
4574} 4972}
4575 4973
4576static int 4974/* promises, list ops, ports */
4975ecb_hot static int
4577opexe_4 (SCHEME_P_ enum scheme_opcodes op) 4976opexe_4 (SCHEME_P_ enum scheme_opcodes op)
4578{ 4977{
4579 pointer args = SCHEME_V->args; 4978 pointer args = SCHEME_V->args;
4580 pointer a = car (args); 4979 pointer a = car (args);
4581 pointer x, y; 4980 pointer x, y;
4598 case OP_SAVE_FORCED: /* Save forced value replacing promise */ 4997 case OP_SAVE_FORCED: /* Save forced value replacing promise */
4599 *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value); 4998 *CELL (SCHEME_V->code) = *CELL (SCHEME_V->value);
4600 s_return (SCHEME_V->value); 4999 s_return (SCHEME_V->value);
4601 5000
4602#if USE_PORTS 5001#if USE_PORTS
5002
5003 case OP_EOF_OBJECT: /* eof-object */
5004 s_return (S_EOF);
4603 5005
4604 case OP_WRITE: /* write */ 5006 case OP_WRITE: /* write */
4605 case OP_DISPLAY: /* display */ 5007 case OP_DISPLAY: /* display */
4606 case OP_WRITE_CHAR: /* write-char */ 5008 case OP_WRITE_CHAR: /* write-char */
4607 if (is_pair (cdr (SCHEME_V->args))) 5009 if (is_pair (cdr (SCHEME_V->args)))
4621 else 5023 else
4622 SCHEME_V->print_flag = 0; 5024 SCHEME_V->print_flag = 0;
4623 5025
4624 s_goto (OP_P0LIST); 5026 s_goto (OP_P0LIST);
4625 5027
5028 //TODO: move to scheme
4626 case OP_NEWLINE: /* newline */ 5029 case OP_NEWLINE: /* newline */
4627 if (is_pair (args)) 5030 if (is_pair (args))
4628 { 5031 {
4629 if (a != SCHEME_V->outport) 5032 if (a != SCHEME_V->outport)
4630 { 5033 {
4632 s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL); 5035 s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL);
4633 SCHEME_V->outport = a; 5036 SCHEME_V->outport = a;
4634 } 5037 }
4635 } 5038 }
4636 5039
4637 putstr (SCHEME_A_ "\n"); 5040 putcharacter (SCHEME_A_ '\n');
4638 s_return (S_T); 5041 s_return (S_T);
4639#endif 5042#endif
4640 5043
4641 case OP_ERR0: /* error */ 5044 case OP_ERR0: /* error */
4642 SCHEME_V->retcode = -1; 5045 SCHEME_V->retcode = -1;
4651 putstr (SCHEME_A_ strvalue (car (args))); 5054 putstr (SCHEME_A_ strvalue (car (args)));
4652 SCHEME_V->args = cdr (args); 5055 SCHEME_V->args = cdr (args);
4653 s_goto (OP_ERR1); 5056 s_goto (OP_ERR1);
4654 5057
4655 case OP_ERR1: /* error */ 5058 case OP_ERR1: /* error */
4656 putstr (SCHEME_A_ " "); 5059 putcharacter (SCHEME_A_ ' ');
4657 5060
4658 if (args != NIL) 5061 if (args != NIL)
4659 { 5062 {
4660 s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL); 5063 s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL);
4661 SCHEME_V->args = a; 5064 SCHEME_V->args = a;
4662 SCHEME_V->print_flag = 1; 5065 SCHEME_V->print_flag = 1;
4663 s_goto (OP_P0LIST); 5066 s_goto (OP_P0LIST);
4664 } 5067 }
4665 else 5068 else
4666 { 5069 {
4667 putstr (SCHEME_A_ "\n"); 5070 putcharacter (SCHEME_A_ '\n');
4668 5071
4669 if (SCHEME_V->interactive_repl) 5072 if (SCHEME_V->interactive_repl)
4670 s_goto (OP_T0LVL); 5073 s_goto (OP_T0LVL);
4671 else 5074 else
4672 return -1; 5075 return -1;
4880 } 5283 }
4881 5284
4882 if (USE_ERROR_CHECKING) abort (); 5285 if (USE_ERROR_CHECKING) abort ();
4883} 5286}
4884 5287
4885static int 5288/* reading */
5289ecb_cold static int
4886opexe_5 (SCHEME_P_ enum scheme_opcodes op) 5290opexe_5 (SCHEME_P_ enum scheme_opcodes op)
4887{ 5291{
4888 pointer args = SCHEME_V->args; 5292 pointer args = SCHEME_V->args;
4889 pointer x; 5293 pointer x;
4890 5294
4969 case OP_RDSEXPR: 5373 case OP_RDSEXPR:
4970 switch (SCHEME_V->tok) 5374 switch (SCHEME_V->tok)
4971 { 5375 {
4972 case TOK_EOF: 5376 case TOK_EOF:
4973 s_return (S_EOF); 5377 s_return (S_EOF);
4974 /* NOTREACHED */
4975 5378
4976 case TOK_VEC: 5379 case TOK_VEC:
4977 s_save (SCHEME_A_ OP_RDVEC, NIL, NIL); 5380 s_save (SCHEME_A_ OP_RDVEC, NIL, NIL);
4978 /* fall through */ 5381 /* fall through */
4979 5382
4982 5385
4983 if (SCHEME_V->tok == TOK_RPAREN) 5386 if (SCHEME_V->tok == TOK_RPAREN)
4984 s_return (NIL); 5387 s_return (NIL);
4985 else if (SCHEME_V->tok == TOK_DOT) 5388 else if (SCHEME_V->tok == TOK_DOT)
4986 Error_0 ("syntax error: illegal dot expression"); 5389 Error_0 ("syntax error: illegal dot expression");
4987 else 5390
4988 {
4989 SCHEME_V->nesting_stack[SCHEME_V->file_i]++; 5391 SCHEME_V->nesting_stack[SCHEME_V->file_i]++;
4990 s_save (SCHEME_A_ OP_RDLIST, NIL, NIL); 5392 s_save (SCHEME_A_ OP_RDLIST, NIL, NIL);
4991 s_goto (OP_RDSEXPR); 5393 s_goto (OP_RDSEXPR);
4992 }
4993 5394
4994 case TOK_QUOTE: 5395 case TOK_QUOTE:
4995 s_save (SCHEME_A_ OP_RDQUOTE, NIL, NIL); 5396 s_save (SCHEME_A_ OP_RDQUOTE, NIL, NIL);
4996 SCHEME_V->tok = token (SCHEME_A); 5397 SCHEME_V->tok = token (SCHEME_A);
4997 s_goto (OP_RDSEXPR); 5398 s_goto (OP_RDSEXPR);
5003 { 5404 {
5004 s_save (SCHEME_A_ OP_RDQQUOTEVEC, NIL, NIL); 5405 s_save (SCHEME_A_ OP_RDQQUOTEVEC, NIL, NIL);
5005 SCHEME_V->tok = TOK_LPAREN; 5406 SCHEME_V->tok = TOK_LPAREN;
5006 s_goto (OP_RDSEXPR); 5407 s_goto (OP_RDSEXPR);
5007 } 5408 }
5008 else 5409
5009 s_save (SCHEME_A_ OP_RDQQUOTE, NIL, NIL); 5410 s_save (SCHEME_A_ OP_RDQQUOTE, NIL, NIL);
5010
5011 s_goto (OP_RDSEXPR); 5411 s_goto (OP_RDSEXPR);
5012 5412
5013 case TOK_COMMA: 5413 case TOK_COMMA:
5014 s_save (SCHEME_A_ OP_RDUNQUOTE, NIL, NIL); 5414 s_save (SCHEME_A_ OP_RDUNQUOTE, NIL, NIL);
5015 SCHEME_V->tok = token (SCHEME_A); 5415 SCHEME_V->tok = token (SCHEME_A);
5026 case TOK_DOTATOM: 5426 case TOK_DOTATOM:
5027 SCHEME_V->strbuff[0] = '.'; 5427 SCHEME_V->strbuff[0] = '.';
5028 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); 5428 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5029 5429
5030 case TOK_STRATOM: 5430 case TOK_STRATOM:
5431 //TODO: haven't checked whether the garbage collector could interfere and free x
5432 gc (SCHEME_A_ NIL, NIL); //TODO: superheavyhanded
5031 x = readstrexp (SCHEME_A_ '|'); 5433 x = readstrexp (SCHEME_A_ '|');
5032 //TODO: haven't checked whether the garbage collector could interfere
5033 s_return (mk_atom (SCHEME_A_ strvalue (x))); 5434 s_return (mk_atom (SCHEME_A_ strvalue (x)));
5034 5435
5035 case TOK_DQUOTE: 5436 case TOK_DQUOTE:
5036 x = readstrexp (SCHEME_A_ '"'); 5437 x = readstrexp (SCHEME_A_ '"');
5037 5438
5045 { 5446 {
5046 pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->SHARP_HOOK, 1); 5447 pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->SHARP_HOOK, 1);
5047 5448
5048 if (f == NIL) 5449 if (f == NIL)
5049 Error_0 ("undefined sharp expression"); 5450 Error_0 ("undefined sharp expression");
5050 else 5451
5051 {
5052 SCHEME_V->code = cons (slot_value_in_env (f), NIL); 5452 SCHEME_V->code = cons (slot_value_in_env (f), NIL);
5053 s_goto (OP_EVAL); 5453 s_goto (OP_EVAL);
5054 }
5055 } 5454 }
5056 5455
5057 case TOK_SHARP_CONST: 5456 case TOK_SHARP_CONST:
5058 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL) 5457 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL)
5059 Error_0 ("undefined sharp expression"); 5458 Error_0 ("undefined sharp expression");
5060 else 5459
5061 s_return (x); 5460 s_return (x);
5062 5461
5063 default: 5462 default:
5064 Error_0 ("syntax error: illegal token"); 5463 Error_0 ("syntax error: illegal token");
5065 } 5464 }
5066 5465
5159 pointer b = cdr (args); 5558 pointer b = cdr (args);
5160 int ok_abbr = ok_abbrev (b); 5559 int ok_abbr = ok_abbrev (b);
5161 SCHEME_V->args = car (b); 5560 SCHEME_V->args = car (b);
5162 5561
5163 if (a == SCHEME_V->QUOTE && ok_abbr) 5562 if (a == SCHEME_V->QUOTE && ok_abbr)
5164 putstr (SCHEME_A_ "'"); 5563 putcharacter (SCHEME_A_ '\'');
5165 else if (a == SCHEME_V->QQUOTE && ok_abbr) 5564 else if (a == SCHEME_V->QQUOTE && ok_abbr)
5166 putstr (SCHEME_A_ "`"); 5565 putcharacter (SCHEME_A_ '`');
5167 else if (a == SCHEME_V->UNQUOTE && ok_abbr) 5566 else if (a == SCHEME_V->UNQUOTE && ok_abbr)
5168 putstr (SCHEME_A_ ","); 5567 putcharacter (SCHEME_A_ ',');
5169 else if (a == SCHEME_V->UNQUOTESP && ok_abbr) 5568 else if (a == SCHEME_V->UNQUOTESP && ok_abbr)
5170 putstr (SCHEME_A_ ",@"); 5569 putstr (SCHEME_A_ ",@");
5171 else 5570 else
5172 { 5571 {
5173 putstr (SCHEME_A_ "("); 5572 putcharacter (SCHEME_A_ '(');
5174 s_save (SCHEME_A_ OP_P1LIST, b, NIL); 5573 s_save (SCHEME_A_ OP_P1LIST, b, NIL);
5175 SCHEME_V->args = a; 5574 SCHEME_V->args = a;
5176 } 5575 }
5177 5576
5178 s_goto (OP_P0LIST); 5577 s_goto (OP_P0LIST);
5180 5579
5181 case OP_P1LIST: 5580 case OP_P1LIST:
5182 if (is_pair (args)) 5581 if (is_pair (args))
5183 { 5582 {
5184 s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL); 5583 s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL);
5185 putstr (SCHEME_A_ " "); 5584 putcharacter (SCHEME_A_ ' ');
5186 SCHEME_V->args = car (args); 5585 SCHEME_V->args = car (args);
5187 s_goto (OP_P0LIST); 5586 s_goto (OP_P0LIST);
5188 } 5587 }
5189 else if (is_vector (args)) 5588 else if (is_vector (args))
5190 { 5589 {
5198 { 5597 {
5199 putstr (SCHEME_A_ " . "); 5598 putstr (SCHEME_A_ " . ");
5200 printatom (SCHEME_A_ args, SCHEME_V->print_flag); 5599 printatom (SCHEME_A_ args, SCHEME_V->print_flag);
5201 } 5600 }
5202 5601
5203 putstr (SCHEME_A_ ")"); 5602 putcharacter (SCHEME_A_ ')');
5204 s_return (S_T); 5603 s_return (S_T);
5205 } 5604 }
5206 5605
5207 case OP_PVECFROM: 5606 case OP_PVECFROM:
5208 { 5607 {
5209 int i = ivalue_unchecked (cdr (args)); 5608 IVALUE i = ivalue_unchecked (cdr (args));
5210 pointer vec = car (args); 5609 pointer vec = car (args);
5211 int len = veclength (vec); 5610 uint32_t len = veclength (vec);
5212 5611
5213 if (i == len) 5612 if (i == len)
5214 { 5613 {
5215 putstr (SCHEME_A_ ")"); 5614 putcharacter (SCHEME_A_ ')');
5216 s_return (S_T); 5615 s_return (S_T);
5217 } 5616 }
5218 else 5617 else
5219 { 5618 {
5220 pointer elem = vector_get (vec, i); 5619 pointer elem = vector_get (vec, i);
5221 5620
5222 ivalue_unchecked (cdr (args)) = i + 1; 5621 set_cdr (args, mk_integer (SCHEME_A_ i + 1));
5223 s_save (SCHEME_A_ OP_PVECFROM, args, NIL); 5622 s_save (SCHEME_A_ OP_PVECFROM, args, NIL);
5224 SCHEME_V->args = elem; 5623 SCHEME_V->args = elem;
5225 5624
5226 if (i > 0) 5625 if (i > 0)
5227 putstr (SCHEME_A_ " "); 5626 putcharacter (SCHEME_A_ ' ');
5228 5627
5229 s_goto (OP_P0LIST); 5628 s_goto (OP_P0LIST);
5230 } 5629 }
5231 } 5630 }
5232 } 5631 }
5233 5632
5234 if (USE_ERROR_CHECKING) abort (); 5633 if (USE_ERROR_CHECKING) abort ();
5235} 5634}
5236 5635
5237static int 5636/* list ops */
5637ecb_hot static int
5238opexe_6 (SCHEME_P_ enum scheme_opcodes op) 5638opexe_6 (SCHEME_P_ enum scheme_opcodes op)
5239{ 5639{
5240 pointer args = SCHEME_V->args; 5640 pointer args = SCHEME_V->args;
5241 pointer a = car (args); 5641 pointer a = car (args);
5242 pointer x, y; 5642 pointer x, y;
5265 break; 5665 break;
5266 } 5666 }
5267 5667
5268 if (is_pair (y)) 5668 if (is_pair (y))
5269 s_return (car (y)); 5669 s_return (car (y));
5270 else 5670
5271 s_return (S_F); 5671 s_return (S_F);
5272
5273 5672
5274 case OP_GET_CLOSURE: /* get-closure-code *//* a.k */ 5673 case OP_GET_CLOSURE: /* get-closure-code *//* a.k */
5275 SCHEME_V->args = a; 5674 SCHEME_V->args = a;
5276 5675
5277 if (SCHEME_V->args == NIL) 5676 if (SCHEME_V->args == NIL)
5278 s_return (S_F); 5677 s_return (S_F);
5279 else if (is_closure (SCHEME_V->args)) 5678 else if (is_closure (SCHEME_V->args) || is_macro (SCHEME_V->args))
5280 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value))); 5679 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value)));
5281 else if (is_macro (SCHEME_V->args)) 5680
5282 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value)));
5283 else
5284 s_return (S_F); 5681 s_return (S_F);
5285 5682
5286 case OP_CLOSUREP: /* closure? */ 5683 case OP_CLOSUREP: /* closure? */
5287 /* 5684 /*
5288 * Note, macro object is also a closure. 5685 * Note, macro object is also a closure.
5289 * Therefore, (closure? <#MACRO>) ==> #t 5686 * Therefore, (closure? <#MACRO>) ==> #t
5300 5697
5301/* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */ 5698/* dispatch functions (opexe_x) return new opcode, or 0 for same opcode, or -1 to stop */
5302typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes); 5699typedef int (*dispatch_func)(SCHEME_P_ enum scheme_opcodes);
5303 5700
5304typedef int (*test_predicate)(pointer); 5701typedef int (*test_predicate)(pointer);
5305static int 5702
5703ecb_hot static int
5306tst_any (pointer p) 5704tst_any (pointer p)
5307{ 5705{
5308 return 1; 5706 return 1;
5309} 5707}
5310 5708
5311static int 5709ecb_hot static int
5312tst_inonneg (pointer p) 5710tst_inonneg (pointer p)
5313{ 5711{
5314 return is_integer (p) && ivalue_unchecked (p) >= 0; 5712 return is_integer (p) && ivalue_unchecked (p) >= 0;
5315} 5713}
5316 5714
5317static int 5715ecb_hot static int
5318tst_is_list (SCHEME_P_ pointer p) 5716tst_is_list (SCHEME_P_ pointer p)
5319{ 5717{
5320 return p == NIL || is_pair (p); 5718 return p == NIL || is_pair (p);
5321} 5719}
5322 5720
5365#define OP_DEF(func,name,minarity,maxarity,argtest,op) name "\x00" 5763#define OP_DEF(func,name,minarity,maxarity,argtest,op) name "\x00"
5366#include "opdefines.h" 5764#include "opdefines.h"
5367#undef OP_DEF 5765#undef OP_DEF
5368; 5766;
5369 5767
5370static const char * 5768ecb_cold static const char *
5371opname (int idx) 5769opname (int idx)
5372{ 5770{
5373 const char *name = opnames; 5771 const char *name = opnames;
5374 5772
5375 /* should do this at compile time, but would require external program, right? */ 5773 /* should do this at compile time, but would require external program, right? */
5377 name += strlen (name) + 1; 5775 name += strlen (name) + 1;
5378 5776
5379 return *name ? name : "ILLEGAL"; 5777 return *name ? name : "ILLEGAL";
5380} 5778}
5381 5779
5382static const char * 5780ecb_cold static const char *
5383procname (pointer x) 5781procname (pointer x)
5384{ 5782{
5385 return opname (procnum (x)); 5783 return opname (procnum (x));
5386} 5784}
5387 5785
5407#undef OP_DEF 5805#undef OP_DEF
5408 {0} 5806 {0}
5409}; 5807};
5410 5808
5411/* kernel of this interpreter */ 5809/* kernel of this interpreter */
5412static void ecb_hot 5810ecb_hot static void
5413Eval_Cycle (SCHEME_P_ enum scheme_opcodes op) 5811Eval_Cycle (SCHEME_P_ enum scheme_opcodes op)
5414{ 5812{
5415 SCHEME_V->op = op; 5813 SCHEME_V->op = op;
5416 5814
5417 for (;;) 5815 for (;;)
5508 } 5906 }
5509} 5907}
5510 5908
5511/* ========== Initialization of internal keywords ========== */ 5909/* ========== Initialization of internal keywords ========== */
5512 5910
5513static void 5911ecb_cold static void
5514assign_syntax (SCHEME_P_ const char *name) 5912assign_syntax (SCHEME_P_ const char *name)
5515{ 5913{
5516 pointer x = oblist_add_by_name (SCHEME_A_ name); 5914 pointer x = oblist_add_by_name (SCHEME_A_ name);
5517 set_typeflag (x, typeflag (x) | T_SYNTAX); 5915 set_typeflag (x, typeflag (x) | T_SYNTAX);
5518} 5916}
5519 5917
5520static void 5918ecb_cold static void
5521assign_proc (SCHEME_P_ enum scheme_opcodes op, const char *name) 5919assign_proc (SCHEME_P_ enum scheme_opcodes op, const char *name)
5522{ 5920{
5523 pointer x = mk_symbol (SCHEME_A_ name); 5921 pointer x = mk_symbol (SCHEME_A_ name);
5524 pointer y = mk_proc (SCHEME_A_ op); 5922 pointer y = mk_proc (SCHEME_A_ op);
5525 new_slot_in_env (SCHEME_A_ x, y); 5923 new_slot_in_env (SCHEME_A_ x, y);
5528static pointer 5926static pointer
5529mk_proc (SCHEME_P_ enum scheme_opcodes op) 5927mk_proc (SCHEME_P_ enum scheme_opcodes op)
5530{ 5928{
5531 pointer y = get_cell (SCHEME_A_ NIL, NIL); 5929 pointer y = get_cell (SCHEME_A_ NIL, NIL);
5532 set_typeflag (y, (T_PROC | T_ATOM)); 5930 set_typeflag (y, (T_PROC | T_ATOM));
5533 ivalue_unchecked (y) = op; 5931 set_ivalue (y, op);
5534 return y; 5932 return y;
5535} 5933}
5536 5934
5537/* Hard-coded for the given keywords. Remember to rewrite if more are added! */ 5935/* Hard-coded for the given keywords. Remember to rewrite if more are added! */
5538static int 5936ecb_hot static int
5539syntaxnum (pointer p) 5937syntaxnum (pointer p)
5540{ 5938{
5541 const char *s = strvalue (p); 5939 const char *s = strvalue (p);
5542 5940
5543 switch (strlength (p)) 5941 switch (strlength (p))
5622 6020
5623ecb_cold int 6021ecb_cold int
5624scheme_init (SCHEME_P) 6022scheme_init (SCHEME_P)
5625{ 6023{
5626 int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); 6024 int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]);
5627 pointer x;
5628 6025
5629 /* this memset is not strictly correct, as we assume (intcache) 6026 /* this memset is not strictly correct, as we assume (intcache)
5630 * that memset 0 will also set pointers to 0, but memset does 6027 * that memset 0 will also set pointers to 0, but memset does
5631 * of course not guarantee that. screw such systems. 6028 * of course not guarantee that. screw such systems.
5632 */ 6029 */
5660#endif 6057#endif
5661 } 6058 }
5662 6059
5663 SCHEME_V->gc_verbose = 0; 6060 SCHEME_V->gc_verbose = 0;
5664 dump_stack_initialize (SCHEME_A); 6061 dump_stack_initialize (SCHEME_A);
5665 SCHEME_V->code = NIL; 6062 SCHEME_V->code = NIL;
5666 SCHEME_V->args = NIL; 6063 SCHEME_V->args = NIL;
5667 SCHEME_V->envir = NIL; 6064 SCHEME_V->envir = NIL;
6065 SCHEME_V->value = NIL;
5668 SCHEME_V->tracing = 0; 6066 SCHEME_V->tracing = 0;
5669 6067
5670 /* init NIL */ 6068 /* init NIL */
5671 set_typeflag (NIL, T_ATOM | T_MARK); 6069 set_typeflag (NIL, T_SPECIAL | T_ATOM);
5672 set_car (NIL, NIL); 6070 set_car (NIL, NIL);
5673 set_cdr (NIL, NIL); 6071 set_cdr (NIL, NIL);
5674 /* init T */ 6072 /* init T */
5675 set_typeflag (S_T, T_ATOM | T_MARK); 6073 set_typeflag (S_T, T_SPECIAL | T_ATOM);
5676 set_car (S_T, S_T); 6074 set_car (S_T, S_T);
5677 set_cdr (S_T, S_T); 6075 set_cdr (S_T, S_T);
5678 /* init F */ 6076 /* init F */
5679 set_typeflag (S_F, T_ATOM | T_MARK); 6077 set_typeflag (S_F, T_SPECIAL | T_ATOM);
5680 set_car (S_F, S_F); 6078 set_car (S_F, S_F);
5681 set_cdr (S_F, S_F); 6079 set_cdr (S_F, S_F);
5682 /* init EOF_OBJ */ 6080 /* init EOF_OBJ */
5683 set_typeflag (S_EOF, T_ATOM | T_MARK); 6081 set_typeflag (S_EOF, T_SPECIAL | T_ATOM);
5684 set_car (S_EOF, S_EOF); 6082 set_car (S_EOF, S_EOF);
5685 set_cdr (S_EOF, S_EOF); 6083 set_cdr (S_EOF, S_EOF);
5686 /* init sink */ 6084 /* init sink */
5687 set_typeflag (S_SINK, T_PAIR | T_MARK); 6085 set_typeflag (S_SINK, T_PAIR);
5688 set_car (S_SINK, NIL); 6086 set_car (S_SINK, NIL);
5689 6087
5690 /* init c_nest */ 6088 /* init c_nest */
5691 SCHEME_V->c_nest = NIL; 6089 SCHEME_V->c_nest = NIL;
5692 6090
5693 SCHEME_V->oblist = oblist_initial_value (SCHEME_A); 6091 SCHEME_V->oblist = oblist_initial_value (SCHEME_A);
5694 /* init global_env */ 6092 /* init global_env */
5695 new_frame_in_env (SCHEME_A_ NIL); 6093 new_frame_in_env (SCHEME_A_ NIL);
5696 SCHEME_V->global_env = SCHEME_V->envir; 6094 SCHEME_V->global_env = SCHEME_V->envir;
5697 /* init else */ 6095 /* init else */
5698 x = mk_symbol (SCHEME_A_ "else"); 6096 new_slot_in_env (SCHEME_A_ mk_symbol (SCHEME_A_ "else"), S_T);
5699 new_slot_in_env (SCHEME_A_ x, S_T);
5700 6097
5701 { 6098 {
5702 static const char *syntax_names[] = { 6099 static const char *syntax_names[] = {
5703 "lambda", "quote", "define", "if", "begin", "set!", 6100 "lambda", "quote", "define", "if", "begin", "set!",
5704 "let", "let*", "letrec", "cond", "delay", "and", 6101 "let", "let*", "letrec", "cond", "delay", "and",
5728 6125
5729 return !SCHEME_V->no_memory; 6126 return !SCHEME_V->no_memory;
5730} 6127}
5731 6128
5732#if USE_PORTS 6129#if USE_PORTS
5733void 6130ecb_cold void
5734scheme_set_input_port_file (SCHEME_P_ int fin) 6131scheme_set_input_port_file (SCHEME_P_ int fin)
5735{ 6132{
5736 SCHEME_V->inport = port_from_file (SCHEME_A_ fin, port_input); 6133 SCHEME_V->inport = port_from_file (SCHEME_A_ fin, port_input);
5737} 6134}
5738 6135
5739void 6136ecb_cold void
5740scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end) 6137scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end)
5741{ 6138{
5742 SCHEME_V->inport = port_from_string (SCHEME_A_ start, past_the_end, port_input); 6139 SCHEME_V->inport = port_from_string (SCHEME_A_ start, past_the_end, port_input);
5743} 6140}
5744 6141
5745void 6142ecb_cold void
5746scheme_set_output_port_file (SCHEME_P_ int fout) 6143scheme_set_output_port_file (SCHEME_P_ int fout)
5747{ 6144{
5748 SCHEME_V->outport = port_from_file (SCHEME_A_ fout, port_output); 6145 SCHEME_V->outport = port_from_file (SCHEME_A_ fout, port_output);
5749} 6146}
5750 6147
5751void 6148ecb_cold void
5752scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end) 6149scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end)
5753{ 6150{
5754 SCHEME_V->outport = port_from_string (SCHEME_A_ start, past_the_end, port_output); 6151 SCHEME_V->outport = port_from_string (SCHEME_A_ start, past_the_end, port_output);
5755} 6152}
5756#endif 6153#endif
5757 6154
5758void 6155ecb_cold void
5759scheme_set_external_data (SCHEME_P_ void *p) 6156scheme_set_external_data (SCHEME_P_ void *p)
5760{ 6157{
5761 SCHEME_V->ext_data = p; 6158 SCHEME_V->ext_data = p;
5762} 6159}
5763 6160
5795 SCHEME_V->loadport = NIL; 6192 SCHEME_V->loadport = NIL;
5796 SCHEME_V->gc_verbose = 0; 6193 SCHEME_V->gc_verbose = 0;
5797 gc (SCHEME_A_ NIL, NIL); 6194 gc (SCHEME_A_ NIL, NIL);
5798 6195
5799 for (i = 0; i <= SCHEME_V->last_cell_seg; i++) 6196 for (i = 0; i <= SCHEME_V->last_cell_seg; i++)
5800 free (SCHEME_V->alloc_seg[i]); 6197 free (SCHEME_V->cell_seg[i]);
5801 6198
5802#if SHOW_ERROR_LINE 6199#if SHOW_ERROR_LINE
5803 for (i = 0; i <= SCHEME_V->file_i; i++) 6200 for (i = 0; i <= SCHEME_V->file_i; i++)
5804 {
5805 if (SCHEME_V->load_stack[i].kind & port_file) 6201 if (SCHEME_V->load_stack[i].kind & port_file)
5806 { 6202 {
5807 fname = SCHEME_V->load_stack[i].rep.stdio.filename; 6203 fname = SCHEME_V->load_stack[i].rep.stdio.filename;
5808 6204
5809 if (fname) 6205 if (fname)
5810 free (fname); 6206 free (fname);
5811 } 6207 }
5812 }
5813#endif 6208#endif
5814} 6209}
5815 6210
5816void 6211ecb_cold void
5817scheme_load_file (SCHEME_P_ int fin) 6212scheme_load_file (SCHEME_P_ int fin)
5818{ 6213{
5819 scheme_load_named_file (SCHEME_A_ fin, 0); 6214 scheme_load_named_file (SCHEME_A_ fin, 0);
5820} 6215}
5821 6216
5822void 6217ecb_cold void
5823scheme_load_named_file (SCHEME_P_ int fin, const char *filename) 6218scheme_load_named_file (SCHEME_P_ int fin, const char *filename)
5824{ 6219{
5825 dump_stack_reset (SCHEME_A); 6220 dump_stack_reset (SCHEME_A);
5826 SCHEME_V->envir = SCHEME_V->global_env; 6221 SCHEME_V->envir = SCHEME_V->global_env;
5827 SCHEME_V->file_i = 0; 6222 SCHEME_V->file_i = 0;
5828 SCHEME_V->load_stack[0].unget = -1; 6223 SCHEME_V->load_stack[0].unget = -1;
5829 SCHEME_V->load_stack[0].kind = port_input | port_file; 6224 SCHEME_V->load_stack[0].kind = port_input | port_file;
5830 SCHEME_V->load_stack[0].rep.stdio.file = fin; 6225 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); 6226 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack);
5833#endif
5834 SCHEME_V->retcode = 0; 6227 SCHEME_V->retcode = 0;
5835 6228
5836#if USE_PORTS
5837 if (fin == STDIN_FILENO) 6229 if (fin == STDIN_FILENO)
5838 SCHEME_V->interactive_repl = 1; 6230 SCHEME_V->interactive_repl = 1;
5839#endif
5840 6231
5841#if USE_PORTS 6232#if USE_PORTS
5842#if SHOW_ERROR_LINE 6233#if SHOW_ERROR_LINE
5843 SCHEME_V->load_stack[0].rep.stdio.curr_line = 0; 6234 SCHEME_V->load_stack[0].rep.stdio.curr_line = 0;
5844 6235
5848#endif 6239#endif
5849 6240
5850 SCHEME_V->inport = SCHEME_V->loadport; 6241 SCHEME_V->inport = SCHEME_V->loadport;
5851 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 6242 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
5852 Eval_Cycle (SCHEME_A_ OP_T0LVL); 6243 Eval_Cycle (SCHEME_A_ OP_T0LVL);
6244
5853 set_typeflag (SCHEME_V->loadport, T_ATOM); 6245 set_typeflag (SCHEME_V->loadport, T_ATOM);
5854 6246
5855 if (SCHEME_V->retcode == 0) 6247 if (SCHEME_V->retcode == 0)
5856 SCHEME_V->retcode = SCHEME_V->nesting != 0; 6248 SCHEME_V->retcode = SCHEME_V->nesting != 0;
5857} 6249}
5858 6250
5859void 6251ecb_cold void
5860scheme_load_string (SCHEME_P_ const char *cmd) 6252scheme_load_string (SCHEME_P_ const char *cmd)
5861{ 6253{
6254#if USE_PORTs
5862 dump_stack_reset (SCHEME_A); 6255 dump_stack_reset (SCHEME_A);
5863 SCHEME_V->envir = SCHEME_V->global_env; 6256 SCHEME_V->envir = SCHEME_V->global_env;
5864 SCHEME_V->file_i = 0; 6257 SCHEME_V->file_i = 0;
5865 SCHEME_V->load_stack[0].kind = port_input | port_string; 6258 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 */ 6259 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); 6260 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; 6261 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); 6262 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack);
5871#endif
5872 SCHEME_V->retcode = 0; 6263 SCHEME_V->retcode = 0;
5873 SCHEME_V->interactive_repl = 0; 6264 SCHEME_V->interactive_repl = 0;
5874 SCHEME_V->inport = SCHEME_V->loadport; 6265 SCHEME_V->inport = SCHEME_V->loadport;
5875 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 6266 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
5876 Eval_Cycle (SCHEME_A_ OP_T0LVL); 6267 Eval_Cycle (SCHEME_A_ OP_T0LVL);
5877 set_typeflag (SCHEME_V->loadport, T_ATOM); 6268 set_typeflag (SCHEME_V->loadport, T_ATOM);
5878 6269
5879 if (SCHEME_V->retcode == 0) 6270 if (SCHEME_V->retcode == 0)
5880 SCHEME_V->retcode = SCHEME_V->nesting != 0; 6271 SCHEME_V->retcode = SCHEME_V->nesting != 0;
6272#else
6273 abort ();
6274#endif
5881} 6275}
5882 6276
5883void 6277ecb_cold void
5884scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value) 6278scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value)
5885{ 6279{
5886 pointer x; 6280 pointer x;
5887 6281
5888 x = find_slot_in_env (SCHEME_A_ envir, symbol, 0); 6282 x = find_slot_in_env (SCHEME_A_ envir, symbol, 0);
5893 new_slot_spec_in_env (SCHEME_A_ envir, symbol, value); 6287 new_slot_spec_in_env (SCHEME_A_ envir, symbol, value);
5894} 6288}
5895 6289
5896#if !STANDALONE 6290#if !STANDALONE
5897 6291
5898void 6292ecb_cold void
5899scheme_register_foreign_func (scheme * sc, scheme_registerable * sr) 6293scheme_register_foreign_func (scheme * sc, scheme_registerable * sr)
5900{ 6294{
5901 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ sr->name), mk_foreign_func (SCHEME_A_ sr->f)); 6295 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ sr->name), mk_foreign_func (SCHEME_A_ sr->f));
5902} 6296}
5903 6297
5904void 6298ecb_cold void
5905scheme_register_foreign_func_list (scheme * sc, scheme_registerable * list, int count) 6299scheme_register_foreign_func_list (scheme * sc, scheme_registerable * list, int count)
5906{ 6300{
5907 int i; 6301 int i;
5908 6302
5909 for (i = 0; i < count; i++) 6303 for (i = 0; i < count; i++)
5910 scheme_register_foreign_func (SCHEME_A_ list + i); 6304 scheme_register_foreign_func (SCHEME_A_ list + i);
5911} 6305}
5912 6306
5913pointer 6307ecb_cold pointer
5914scheme_apply0 (SCHEME_P_ const char *procname) 6308scheme_apply0 (SCHEME_P_ const char *procname)
5915{ 6309{
5916 return scheme_eval (SCHEME_A_ cons (mk_symbol (SCHEME_A_ procname), NIL)); 6310 return scheme_eval (SCHEME_A_ cons (mk_symbol (SCHEME_A_ procname), NIL));
5917} 6311}
5918 6312
5919void 6313ecb_cold void
5920save_from_C_call (SCHEME_P) 6314save_from_C_call (SCHEME_P)
5921{ 6315{
5922 pointer saved_data = cons (car (S_SINK), 6316 pointer saved_data = cons (car (S_SINK),
5923 cons (SCHEME_V->envir, 6317 cons (SCHEME_V->envir,
5924 SCHEME_V->dump)); 6318 SCHEME_V->dump));
5928 /* Truncate the dump stack so TS will return here when done, not 6322 /* Truncate the dump stack so TS will return here when done, not
5929 directly resume pre-C-call operations. */ 6323 directly resume pre-C-call operations. */
5930 dump_stack_reset (SCHEME_A); 6324 dump_stack_reset (SCHEME_A);
5931} 6325}
5932 6326
5933void 6327ecb_cold void
5934restore_from_C_call (SCHEME_P) 6328restore_from_C_call (SCHEME_P)
5935{ 6329{
5936 set_car (S_SINK, caar (SCHEME_V->c_nest)); 6330 set_car (S_SINK, caar (SCHEME_V->c_nest));
5937 SCHEME_V->envir = cadar (SCHEME_V->c_nest); 6331 SCHEME_V->envir = cadar (SCHEME_V->c_nest);
5938 SCHEME_V->dump = cdr (cdar (SCHEME_V->c_nest)); 6332 SCHEME_V->dump = cdr (cdar (SCHEME_V->c_nest));
5939 /* Pop */ 6333 /* Pop */
5940 SCHEME_V->c_nest = cdr (SCHEME_V->c_nest); 6334 SCHEME_V->c_nest = cdr (SCHEME_V->c_nest);
5941} 6335}
5942 6336
5943/* "func" and "args" are assumed to be already eval'ed. */ 6337/* "func" and "args" are assumed to be already eval'ed. */
5944pointer 6338ecb_cold pointer
5945scheme_call (SCHEME_P_ pointer func, pointer args) 6339scheme_call (SCHEME_P_ pointer func, pointer args)
5946{ 6340{
5947 int old_repl = SCHEME_V->interactive_repl; 6341 int old_repl = SCHEME_V->interactive_repl;
5948 6342
5949 SCHEME_V->interactive_repl = 0; 6343 SCHEME_V->interactive_repl = 0;
5956 SCHEME_V->interactive_repl = old_repl; 6350 SCHEME_V->interactive_repl = old_repl;
5957 restore_from_C_call (SCHEME_A); 6351 restore_from_C_call (SCHEME_A);
5958 return SCHEME_V->value; 6352 return SCHEME_V->value;
5959} 6353}
5960 6354
5961pointer 6355ecb_cold pointer
5962scheme_eval (SCHEME_P_ pointer obj) 6356scheme_eval (SCHEME_P_ pointer obj)
5963{ 6357{
5964 int old_repl = SCHEME_V->interactive_repl; 6358 int old_repl = SCHEME_V->interactive_repl;
5965 6359
5966 SCHEME_V->interactive_repl = 0; 6360 SCHEME_V->interactive_repl = 0;
5978 6372
5979/* ========== Main ========== */ 6373/* ========== Main ========== */
5980 6374
5981#if STANDALONE 6375#if STANDALONE
5982 6376
5983int 6377ecb_cold int
5984main (int argc, char **argv) 6378main (int argc, char **argv)
5985{ 6379{
5986# if USE_MULTIPLICITY 6380# if USE_MULTIPLICITY
5987 scheme ssc; 6381 scheme ssc;
5988 scheme *const SCHEME_V = &ssc; 6382 scheme *const SCHEME_V = &ssc;
5990# endif 6384# endif
5991 int fin; 6385 int fin;
5992 char *file_name = InitFile; 6386 char *file_name = InitFile;
5993 int retcode; 6387 int retcode;
5994 int isfile = 1; 6388 int isfile = 1;
6389#if EXPERIMENT
5995 system ("ps v $PPID");//D 6390 system ("ps v $PPID");
6391#endif
5996 6392
5997 if (argc == 2 && strcmp (argv[1], "-?") == 0) 6393 if (argc == 2 && strcmp (argv[1], "-?") == 0)
5998 { 6394 {
5999 putstr (SCHEME_A_ "Usage: tinyscheme -?\n"); 6395 putstr (SCHEME_A_ "Usage: tinyscheme -?\n");
6000 putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n"); 6396 putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n");
6029 } 6425 }
6030#endif 6426#endif
6031 6427
6032 do 6428 do
6033 { 6429 {
6034#if USE_PORTS
6035 if (strcmp (file_name, "-") == 0) 6430 if (strcmp (file_name, "-") == 0)
6036 fin = STDIN_FILENO; 6431 fin = STDIN_FILENO;
6037 else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0) 6432 else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0)
6038 { 6433 {
6039 pointer args = NIL; 6434 pointer args = NIL;
6057 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args); 6452 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args);
6058 6453
6059 } 6454 }
6060 else 6455 else
6061 fin = open (file_name, O_RDONLY); 6456 fin = open (file_name, O_RDONLY);
6062#endif
6063 6457
6064 if (isfile && fin < 0) 6458 if (isfile && fin < 0)
6065 { 6459 {
6066 putstr (SCHEME_A_ "Could not open file "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); 6460 putstr (SCHEME_A_ "Could not open file ");
6461 putstr (SCHEME_A_ file_name);
6462 putcharacter (SCHEME_A_ '\n');
6067 } 6463 }
6068 else 6464 else
6069 { 6465 {
6070 if (isfile) 6466 if (isfile)
6071 scheme_load_named_file (SCHEME_A_ fin, file_name); 6467 scheme_load_named_file (SCHEME_A_ fin, file_name);
6072 else 6468 else
6073 scheme_load_string (SCHEME_A_ file_name); 6469 scheme_load_string (SCHEME_A_ file_name);
6074 6470
6075#if USE_PORTS
6076 if (!isfile || fin != STDIN_FILENO) 6471 if (!isfile || fin != STDIN_FILENO)
6077 { 6472 {
6078 if (SCHEME_V->retcode != 0) 6473 if (SCHEME_V->retcode != 0)
6079 { 6474 {
6080 putstr (SCHEME_A_ "Errors encountered reading "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); 6475 putstr (SCHEME_A_ "Errors encountered reading ");
6476 putstr (SCHEME_A_ file_name);
6477 putcharacter (SCHEME_A_ '\n');
6081 } 6478 }
6082 6479
6083 if (isfile) 6480 if (isfile)
6084 close (fin); 6481 close (fin);
6085 } 6482 }
6086#endif
6087 } 6483 }
6088 6484
6089 file_name = *argv++; 6485 file_name = *argv++;
6090 } 6486 }
6091 while (file_name != 0); 6487 while (file_name != 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines