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

Comparing cvsroot/microscheme/scheme.c (file contents):
Revision 1.60 by root, Wed Dec 2 02:59:36 2015 UTC vs.
Revision 1.66 by root, Mon Dec 7 18:10:57 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 \
131 136
132 xnum (buf, n); 137 xnum (buf, n);
133 putstr (SCHEME_A_ buf); 138 putstr (SCHEME_A_ buf);
134} 139}
135 140
136ecb_cold static char 141#if USE_CHAR_CLASSIFIERS
142#include <ctype.h>
143#else
144
145static char
137xtoupper (char c) 146xtoupper (char c)
138{ 147{
139 if (c >= 'a' && c <= 'z') 148 if (c >= 'a' && c <= 'z')
140 c -= 'a' - 'A'; 149 c -= 'a' - 'A';
141 150
142 return c; 151 return c;
143} 152}
144 153
145ecb_cold static char 154static char
146xtolower (char c) 155xtolower (char c)
147{ 156{
148 if (c >= 'A' && c <= 'Z') 157 if (c >= 'A' && c <= 'Z')
149 c += 'a' - 'A'; 158 c += 'a' - 'A';
150 159
151 return c; 160 return c;
152} 161}
153 162
154ecb_cold static int 163static int
155xisdigit (char c) 164xisdigit (char c)
156{ 165{
157 return c >= '0' && c <= '9'; 166 return c >= '0' && c <= '9';
158} 167}
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
165ecb_cold static 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;
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
200 T_STRING, 211 T_STRING,
201 T_SYMBOL, 212 T_SYMBOL,
202 T_PROC, 213 T_PROC,
203 T_PAIR, /* also used for free cells */ 214 T_PAIR, /* also used for free cells */
204 T_CLOSURE, 215 T_CLOSURE,
216 T_BYTECODE, // temp
205 T_MACRO, 217 T_MACRO,
206 T_CONTINUATION, 218 T_CONTINUATION,
207 T_FOREIGN, 219 T_FOREIGN,
208 T_PORT, 220 T_PORT,
209 T_VECTOR, 221 T_VECTOR,
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;
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;
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}
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);
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 {
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 */
1048ecb_hot pointer 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}
1083
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)
1063 1094
1064ecb_cold static pointer 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);
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;
1178 return SCHEME_V->oblist; 1209 return SCHEME_V->oblist;
1179} 1210}
1180 1211
1181#endif 1212#endif
1182 1213
1183#if USE_PORTS
1184ecb_cold static 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
1196ecb_cold pointer 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);
1722/* ========== Routines for Reading ========== */ 1751/* ========== Routines for Reading ========== */
1723 1752
1724ecb_cold static int 1753ecb_cold static int
1725file_push (SCHEME_P_ const char *fname) 1754file_push (SCHEME_P_ const char *fname)
1726{ 1755{
1727#if USE_PORTS
1728 int fin; 1756 int fin;
1729 1757
1730 if (SCHEME_V->file_i == MAXFIL - 1) 1758 if (SCHEME_V->file_i == MAXFIL - 1)
1731 return 0; 1759 return 0;
1732 1760
1749 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);
1750#endif 1778#endif
1751 } 1779 }
1752 1780
1753 return fin >= 0; 1781 return fin >= 0;
1754
1755#else
1756 return 1;
1757#endif
1758} 1782}
1759 1783
1760ecb_cold static void 1784ecb_cold static void
1761file_pop (SCHEME_P) 1785file_pop (SCHEME_P)
1762{ 1786{
1946 } 1970 }
1947} 1971}
1948#endif 1972#endif
1949 1973
1950/* get new character from input file */ 1974/* get new character from input file */
1951static int 1975ecb_cold static int
1952inchar (SCHEME_P) 1976inchar (SCHEME_P)
1953{ 1977{
1954 int c; 1978 int c;
1955 port *pt = port (SCHEME_V->inport); 1979 port *pt = port (SCHEME_V->inport);
1956 1980
1970 } 1994 }
1971 1995
1972 return c; 1996 return c;
1973} 1997}
1974 1998
1975static int ungot = -1; 1999ecb_cold static int
1976
1977static int
1978basic_inchar (port *pt) 2000basic_inchar (port *pt)
1979{ 2001{
1980#if USE_PORTS
1981 if (pt->unget != -1) 2002 if (pt->unget != -1)
1982 { 2003 {
1983 int r = pt->unget; 2004 int r = pt->unget;
1984 pt->unget = -1; 2005 pt->unget = -1;
1985 return r; 2006 return r;
1986 } 2007 }
1987 2008
2009#if USE_PORTS
1988 if (pt->kind & port_file) 2010 if (pt->kind & port_file)
1989 { 2011 {
1990 char c; 2012 char c;
1991 2013
1992 if (!read (pt->rep.stdio.file, &c, 1)) 2014 if (!read (pt->rep.stdio.file, &c, 1))
2000 return EOF; 2022 return EOF;
2001 else 2023 else
2002 return *pt->rep.string.curr++; 2024 return *pt->rep.string.curr++;
2003 } 2025 }
2004#else 2026#else
2005 if (ungot == -1)
2006 {
2007 char c; 2027 char c;
2008 if (!read (0, &c, 1)) 2028
2029 if (!read (pt->rep.stdio.file, &c, 1))
2009 return EOF; 2030 return EOF;
2010 2031
2011 ungot = c;
2012 }
2013
2014 {
2015 int r = ungot;
2016 ungot = -1;
2017 return r; 2032 return c;
2018 }
2019#endif 2033#endif
2020} 2034}
2021 2035
2022/* back character to input buffer */ 2036/* back character to input buffer */
2023static void 2037ecb_cold static void
2024backchar (SCHEME_P_ int c) 2038backchar (SCHEME_P_ int c)
2025{ 2039{
2026#if USE_PORTS 2040 port *pt = port (SCHEME_V->inport);
2027 port *pt;
2028 2041
2029 if (c == EOF) 2042 if (c == EOF)
2030 return; 2043 return;
2031 2044
2032 pt = port (SCHEME_V->inport);
2033 pt->unget = c; 2045 pt->unget = c;
2034#else
2035 if (c == EOF)
2036 return;
2037
2038 ungot = c;
2039#endif
2040} 2046}
2041 2047
2042#if USE_PORTS 2048#if USE_PORTS
2043ecb_cold static int 2049ecb_cold static int
2044realloc_port_string (SCHEME_P_ port *p) 2050realloc_port_string (SCHEME_P_ port *p)
2061 else 2067 else
2062 return 0; 2068 return 0;
2063} 2069}
2064#endif 2070#endif
2065 2071
2066ecb_cold INTERFACE void
2067putstr (SCHEME_P_ const char *s)
2068{
2069#if USE_PORTS
2070 port *pt = port (SCHEME_V->outport);
2071
2072 if (pt->kind & port_file)
2073 write (pt->rep.stdio.file, s, strlen (s));
2074 else
2075 for (; *s; s++)
2076 if (pt->rep.string.curr != pt->rep.string.past_the_end)
2077 *pt->rep.string.curr++ = *s;
2078 else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt))
2079 *pt->rep.string.curr++ = *s;
2080
2081#else
2082 write (pt->rep.stdio.file, s, strlen (s));
2083#endif
2084}
2085
2086ecb_cold static void 2072ecb_cold static void
2087putchars (SCHEME_P_ const char *s, int len) 2073putchars (SCHEME_P_ const char *s, int len)
2088{ 2074{
2075 port *pt = port (SCHEME_V->outport);
2076
2089#if USE_PORTS 2077#if USE_PORTS
2090 port *pt = port (SCHEME_V->outport);
2091
2092 if (pt->kind & port_file) 2078 if (pt->kind & port_file)
2093 write (pt->rep.stdio.file, s, len); 2079 write (pt->rep.stdio.file, s, len);
2094 else 2080 else
2095 { 2081 {
2096 for (; len; len--) 2082 for (; len; len--)
2101 *pt->rep.string.curr++ = *s++; 2087 *pt->rep.string.curr++ = *s++;
2102 } 2088 }
2103 } 2089 }
2104 2090
2105#else 2091#else
2106 write (1, s, len); 2092 write (1, s, len); // output not initialised
2107#endif 2093#endif
2108} 2094}
2109 2095
2110ecb_cold INTERFACE void 2096INTERFACE void
2097putstr (SCHEME_P_ const char *s)
2098{
2099 putchars (SCHEME_A_ s, strlen (s));
2100}
2101
2102INTERFACE void
2111putcharacter (SCHEME_P_ int c) 2103putcharacter (SCHEME_P_ int c)
2112{ 2104{
2113#if USE_PORTS
2114 port *pt = port (SCHEME_V->outport);
2115
2116 if (pt->kind & port_file)
2117 {
2118 char cc = c;
2119 write (pt->rep.stdio.file, &cc, 1);
2120 }
2121 else
2122 {
2123 if (pt->rep.string.curr != pt->rep.string.past_the_end)
2124 *pt->rep.string.curr++ = c;
2125 else if (pt->kind & port_srfi6 && realloc_port_string (SCHEME_A_ pt))
2126 *pt->rep.string.curr++ = c;
2127 }
2128
2129#else
2130 char cc = c; 2105 char cc = c;
2131 write (1, &c, 1); 2106
2132#endif 2107 putchars (SCHEME_A_ &cc, 1);
2133} 2108}
2134 2109
2135/* read characters up to delimiter, but cater to character constants */ 2110/* read characters up to delimiter, but cater to character constants */
2136ecb_cold static char * 2111ecb_cold static char *
2137readstr_upto (SCHEME_P_ int skip, const char *delim) 2112readstr_upto (SCHEME_P_ int skip, const char *delim)
2198 case 'a': *p++ = '\a'; state = st_ok; break; 2173 case 'a': *p++ = '\a'; state = st_ok; break;
2199 case 'n': *p++ = '\n'; state = st_ok; break; 2174 case 'n': *p++ = '\n'; state = st_ok; break;
2200 case 'r': *p++ = '\r'; state = st_ok; break; 2175 case 'r': *p++ = '\r'; state = st_ok; break;
2201 case 't': *p++ = '\t'; state = st_ok; break; 2176 case 't': *p++ = '\t'; state = st_ok; break;
2202 2177
2203 //TODO: \whitespace eol whitespace 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;
2204 2186
2205 //TODO: x should end in ;, not two-digit hex 2187 //TODO: x should end in ;, not two-digit hex
2206 case 'x': 2188 case 'x':
2207 case 'X': 2189 case 'X':
2208 state = st_x1; 2190 state = st_x1;
2964/* ========== Evaluation Cycle ========== */ 2946/* ========== Evaluation Cycle ========== */
2965 2947
2966ecb_cold static int 2948ecb_cold static int
2967xError_1 (SCHEME_P_ const char *s, pointer a) 2949xError_1 (SCHEME_P_ const char *s, pointer a)
2968{ 2950{
2969#if USE_ERROR_HOOK
2970 pointer x;
2971 pointer hdl = SCHEME_V->ERROR_HOOK;
2972#endif
2973
2974#if USE_PRINTF 2951#if USE_PRINTF
2975#if SHOW_ERROR_LINE 2952#if SHOW_ERROR_LINE
2976 char sbuf[STRBUFFSIZE]; 2953 char sbuf[STRBUFFSIZE];
2977 2954
2978 /* make sure error is not in REPL */ 2955 /* make sure error is not in REPL */
2993 } 2970 }
2994#endif 2971#endif
2995#endif 2972#endif
2996 2973
2997#if USE_ERROR_HOOK 2974#if USE_ERROR_HOOK
2998 x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, hdl, 1); 2975 pointer x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->ERROR_HOOK, 1);
2999 2976
3000 if (x != NIL) 2977 if (x != NIL)
3001 { 2978 {
3002 pointer code = a 2979 pointer code = a
3003 ? cons (cons (SCHEME_V->QUOTE, cons (a, NIL)), NIL) 2980 ? cons (cons (SCHEME_V->QUOTE, cons (a, NIL)), NIL)
3246#endif 3223#endif
3247 3224
3248#define s_retbool(tf) s_return ((tf) ? S_T : S_F) 3225#define s_retbool(tf) s_return ((tf) ? S_T : S_F)
3249 3226
3250#if EXPERIMENT 3227#if EXPERIMENT
3228
3251static int 3229static int
3252debug (SCHEME_P_ int indent, pointer x) 3230dtree (SCHEME_P_ int indent, pointer x)
3253{ 3231{
3254 int c; 3232 int c;
3255 3233
3256 if (is_syntax (x)) 3234 if (is_syntax (x))
3257 { 3235 {
3275 printf ("%*sS<%s>\n", indent, "", symname (x)); 3253 printf ("%*sS<%s>\n", indent, "", symname (x));
3276 return 24+8; 3254 return 24+8;
3277 3255
3278 case T_CLOSURE: 3256 case T_CLOSURE:
3279 printf ("%*sS<%s>\n", indent, "", "closure"); 3257 printf ("%*sS<%s>\n", indent, "", "closure");
3280 debug (SCHEME_A_ indent + 3, cdr(x)); 3258 dtree (SCHEME_A_ indent + 3, cdr(x));
3281 return 32 + debug (SCHEME_A_ indent + 3, car (x)); 3259 return 32 + dtree (SCHEME_A_ indent + 3, car (x));
3282 3260
3283 case T_PAIR: 3261 case T_PAIR:
3284 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x)); 3262 printf ("%*spair %p %p\n", indent, "", car(x),cdr(x));
3285 c = debug (SCHEME_A_ indent + 3, car (x)); 3263 c = dtree (SCHEME_A_ indent + 3, car (x));
3286 c += debug (SCHEME_A_ indent + 3, cdr (x)); 3264 c += dtree (SCHEME_A_ indent + 3, cdr (x));
3287 return c + 1; 3265 return c + 1;
3288 3266
3289 case T_PORT: 3267 case T_PORT:
3290 printf ("%*sS<%s>\n", indent, "", "port"); 3268 printf ("%*sS<%s>\n", indent, "", "port");
3291 return 24+8; 3269 return 24+8;
3294 printf ("%*sS<%s>\n", indent, "", "vector"); 3272 printf ("%*sS<%s>\n", indent, "", "vector");
3295 return 24+8; 3273 return 24+8;
3296 3274
3297 case T_ENVIRONMENT: 3275 case T_ENVIRONMENT:
3298 printf ("%*sS<%s>\n", indent, "", "environment"); 3276 printf ("%*sS<%s>\n", indent, "", "environment");
3299 return 0 + debug (SCHEME_A_ indent + 3, car (x)); 3277 return 0 + dtree (SCHEME_A_ indent + 3, car (x));
3300 3278
3301 default: 3279 default:
3302 printf ("unhandled type %d\n", type (x)); 3280 printf ("unhandled type %d\n", type (x));
3303 break; 3281 break;
3304 } 3282 }
3305} 3283}
3284
3285#define DUMP(t) do { printf ("DUMP %s:%d\n", __FILE__, __LINE__); dtree (SCHEME_A_ 0, (t)); } while (0)
3286
3287typedef void *stream[1];
3288
3289#define stream_init() { 0 }
3290#define stream_data(s) ((char *)(s)[0] + sizeof (uint32_t) * 2)
3291#define stream_size(s) (((uint32_t *)(s)[0])[0] - sizeof (uint32_t) * 2)
3292#define stream_free(s) free (s[0])
3293
3294ecb_cold static void
3295stream_put (stream s, uint8_t byte)
3296{
3297 uint32_t *sp = *s;
3298 uint32_t size = sizeof (uint32_t) * 2;
3299 uint32_t offs = size;
3300
3301 if (ecb_expect_true (sp))
3302 {
3303 offs = sp[0];
3304 size = sp[1];
3305 }
3306
3307 if (ecb_expect_false (offs == size))
3308 {
3309 size *= 2;
3310 sp = realloc (sp, size);
3311 *s = sp;
3312 sp[1] = size;
3313
3314 }
3315
3316 ((uint8_t *)sp)[offs++] = byte;
3317 sp[0] = offs;
3318}
3319
3320ecb_cold static void
3321stream_put_v (stream s, uint32_t v)
3322{
3323 while (v > 0x7f)
3324 {
3325 stream_put (s, v | 0x80);
3326 v >>= 7;
3327 }
3328
3329 stream_put (s, v);
3330}
3331
3332ecb_cold static void
3333stream_put_tv (stream s, int bop, uint32_t v)
3334{
3335 printf ("put tv %d %d\n", bop, v);//D
3336 stream_put (s, bop);
3337 stream_put_v (s, v);
3338}
3339
3340ecb_cold static void
3341stream_put_stream (stream s, stream o)
3342{
3343 uint32_t i;
3344
3345 for (i = 0; i < stream_size (o); ++i)
3346 stream_put (s, stream_data (o)[i]);
3347
3348 stream_free (o);
3349}
3350
3351ecb_cold static uint32_t
3352cell_id (SCHEME_P_ pointer x)
3353{
3354 struct cell *p = CELL (x);
3355 int i;
3356
3357 for (i = SCHEME_V->last_cell_seg; i >= 0; --i)
3358 if (SCHEME_V->cell_seg[i] <= p && p < SCHEME_V->cell_seg[i] + SCHEME_V->cell_segsize[i])
3359 return i | ((p - SCHEME_V->cell_seg[i]) << CELL_NSEGMENT_LOG);
3360
3361 abort ();
3362}
3363
3364// calculates a (preferably small) integer that makes it possible to find
3365// the symbol again. if pointers were offsets into a memory area... until
3366// then, we return segment number in the low bits, and offset in the high
3367// bits.
3368// also, this function must never return 0.
3369ecb_cold static uint32_t
3370symbol_id (SCHEME_P_ pointer sym)
3371{
3372 return cell_id (SCHEME_A_ sym);
3373}
3374
3375enum byteop
3376{
3377 BOP_NIL,
3378 BOP_INTEGER,
3379 BOP_SYMBOL,
3380 BOP_DATUM,
3381 BOP_LIST_BEG,
3382 BOP_LIST_END,
3383 BOP_IF,
3384 BOP_AND,
3385 BOP_OR,
3386 BOP_CASE,
3387 BOP_COND,
3388 BOP_LET,
3389 BOP_LETAST,
3390 BOP_LETREC,
3391 BOP_DEFINE,
3392 BOP_MACRO,
3393 BOP_SET,
3394 BOP_BEGIN,
3395 BOP_LAMBDA,
3396 BOP_OP,
3397};
3398
3399ecb_cold static void compile_expr (SCHEME_P_ stream s, pointer x);
3400
3401ecb_cold static void
3402compile_list (SCHEME_P_ stream s, pointer x)
3403{
3404 // TODO: improper list
3405
3406 for (; x != NIL; x = cdr (x))
3407 {
3408 stream t = stream_init ();
3409 compile_expr (SCHEME_A_ t, car (x));
3410 stream_put_v (s, stream_size (t));
3411 stream_put_stream (s, t);
3412 }
3413
3414 stream_put_v (s, 0);
3415}
3416
3417static void
3418compile_if (SCHEME_P_ stream s, pointer cond, pointer ift, pointer iff)
3419{
3420 stream sift = stream_init (); compile_expr (SCHEME_A_ sift, ift);
3421
3422 stream_put (s, BOP_IF);
3423 compile_expr (SCHEME_A_ s, cond);
3424 stream_put_v (s, stream_size (sift));
3425 stream_put_stream (s, sift);
3426 compile_expr (SCHEME_A_ s, iff);
3427}
3428
3429typedef uint32_t stream_fixup;
3430
3431static stream_fixup
3432stream_put_fixup (stream s)
3433{
3434 stream_put (s, 0);
3435 stream_put (s, 0);
3436
3437 return stream_size (s);
3438}
3439
3440static void
3441stream_fix_fixup (stream s, stream_fixup fixup, uint32_t target)
3442{
3443 target -= fixup;
3444 assert (target < (1 << 14));
3445 stream_data (s)[fixup - 2] = target | 0x80;
3446 stream_data (s)[fixup - 1] = target >> 7;
3447}
3448
3449static void
3450compile_and_or (SCHEME_P_ stream s, int and, pointer x)
3451{
3452 for (; cdr (x) != NIL; x = cdr (x))
3453 {
3454 stream t = stream_init ();
3455 compile_expr (SCHEME_A_ t, car (x));
3456 stream_put_v (s, stream_size (t));
3457 stream_put_stream (s, t);
3458 }
3459
3460 stream_put_v (s, 0);
3461}
3462
3463static void
3464compile_case (SCHEME_P_ stream s, pointer x)
3465{
3466 compile_expr (SCHEME_A_ s, caar (x));
3467
3468 for (;;)
3469 {
3470 x = cdr (x);
3471
3472 if (x == NIL)
3473 break;
3474
3475 compile_expr (SCHEME_A_ s, caar (x));
3476 stream t = stream_init (); compile_expr (SCHEME_A_ t, cdar (x));
3477 stream_put_v (s, stream_size (t));
3478 stream_put_stream (s, t);
3479 }
3480
3481 stream_put_v (s, 0);
3482}
3483
3484static void
3485compile_cond (SCHEME_P_ stream s, pointer x)
3486{
3487 for ( ; x != NIL; x = cdr (x))
3488 {
3489 compile_expr (SCHEME_A_ s, caar (x));
3490 stream t = stream_init (); compile_expr (SCHEME_A_ t, cdar (x));
3491 stream_put_v (s, stream_size (t));
3492 stream_put_stream (s, t);
3493 }
3494
3495 stream_put_v (s, 0);
3496}
3497
3498static pointer
3499lookup (SCHEME_P_ pointer x)
3500{
3501 x = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, x, 1);
3502
3503 if (x != NIL)
3504 x = slot_value_in_env (x);
3505
3506 return x;
3507}
3508
3509ecb_cold static void
3510compile_expr (SCHEME_P_ stream s, pointer x)
3511{
3512 if (x == NIL)
3513 {
3514 stream_put (s, BOP_NIL);
3515 return;
3516 }
3517
3518 if (is_pair (x))
3519 {
3520 pointer head = car (x);
3521
3522 if (is_syntax (head))
3523 {
3524 x = cdr (x);
3525
3526 switch (syntaxnum (head))
3527 {
3528 case OP_IF0: /* if */
3529 stream_put_v (s, BOP_IF);
3530 compile_if (SCHEME_A_ s, car (x), cadr (x), caddr (x));
3531 break;
3532
3533 case OP_OR0: /* or */
3534 stream_put_v (s, BOP_OR);
3535 compile_and_or (SCHEME_A_ s, 0, x);
3536 break;
3537
3538 case OP_AND0: /* and */
3539 stream_put_v (s, BOP_AND);
3540 compile_and_or (SCHEME_A_ s, 1, x);
3541 break;
3542
3543 case OP_CASE0: /* case */
3544 stream_put_v (s, BOP_CASE);
3545 compile_case (SCHEME_A_ s, x);
3546 break;
3547
3548 case OP_COND0: /* cond */
3549 stream_put_v (s, BOP_COND);
3550 compile_cond (SCHEME_A_ s, x);
3551 break;
3552
3553 case OP_LET0: /* let */
3554 case OP_LET0AST: /* let* */
3555 case OP_LET0REC: /* letrec */
3556 switch (syntaxnum (head))
3557 {
3558 case OP_LET0: stream_put (s, BOP_LET ); break;
3559 case OP_LET0AST: stream_put (s, BOP_LETAST); break;
3560 case OP_LET0REC: stream_put (s, BOP_LETREC); break;
3561 }
3562
3563 {
3564 pointer bindings = car (x);
3565 pointer body = cadr (x);
3566
3567 for (x = bindings; x != NIL; x = cdr (x))
3568 {
3569 pointer init = NIL;
3570 pointer var = car (x);
3571
3572 if (is_pair (var))
3573 {
3574 init = cdr (var);
3575 var = car (var);
3576 }
3577
3578 stream_put_v (s, symbol_id (SCHEME_A_ var));
3579 compile_expr (SCHEME_A_ s, init);
3580 }
3581
3582 stream_put_v (s, 0);
3583 compile_expr (SCHEME_A_ s, body);
3584 }
3585 break;
3586
3587 case OP_DEF0: /* define */
3588 case OP_MACRO0: /* macro */
3589 stream_put (s, syntaxnum (head) == OP_DEF0 ? BOP_DEFINE : BOP_MACRO);
3590 stream_put_v (s, cell_id (SCHEME_A_ car (x)));
3591 compile_expr (SCHEME_A_ s, cadr (x));
3592 break;
3593
3594 case OP_SET0: /* set! */
3595 stream_put (s, BOP_SET);
3596 stream_put_v (s, symbol_id (SCHEME_A_ car (x)));
3597 compile_expr (SCHEME_A_ s, cadr (x));
3598 break;
3599
3600 case OP_BEGIN: /* begin */
3601 stream_put (s, BOP_BEGIN);
3602 compile_list (SCHEME_A_ s, x);
3603 return;
3604
3605 case OP_DELAY: /* delay */
3606 abort ();
3607 break;
3608
3609 case OP_QUOTE: /* quote */
3610 stream_put_tv (s, BOP_DATUM, cell_id (SCHEME_A_ x));
3611 break;
3612
3613 case OP_LAMBDA: /* lambda */
3614 {
3615 pointer formals = car (x);
3616 pointer body = cadr (x);
3617
3618 stream_put (s, BOP_LAMBDA);
3619
3620 for (; is_pair (formals); formals = cdr (formals))
3621 stream_put_v (s, symbol_id (SCHEME_A_ car (formals)));
3622
3623 stream_put_v (s, 0);
3624 stream_put_v (s, formals == NIL ? 0 : symbol_id (SCHEME_A_ formals));
3625
3626 compile_expr (SCHEME_A_ s, body);
3627 }
3628 break;
3629
3630 case OP_C0STREAM:/* cons-stream */
3631 abort ();
3632 break;
3633 }
3634
3635 return;
3636 }
3637
3638 pointer m = lookup (SCHEME_A_ head);
3639
3640 if (is_macro (m))
3641 {
3642 s_save (SCHEME_A_ OP_DEBUG2, SCHEME_V->args, SCHEME_V->code);
3643 SCHEME_V->code = m;
3644 SCHEME_V->args = cons (x, NIL);
3645 Eval_Cycle (SCHEME_A_ OP_APPLY);
3646 x = SCHEME_V->value;
3647 compile_expr (SCHEME_A_ s, SCHEME_V->value);
3648 return;
3649 }
3650
3651 stream_put (s, BOP_LIST_BEG);
3652
3653 for (; x != NIL; x = cdr (x))
3654 compile_expr (SCHEME_A_ s, car (x));
3655
3656 stream_put (s, BOP_LIST_END);
3657 return;
3658 }
3659
3660 switch (type (x))
3661 {
3662 case T_INTEGER:
3663 {
3664 IVALUE iv = ivalue_unchecked (x);
3665 iv = iv < 0 ? ((~(uint32_t)iv) << 1) | 1 : (uint32_t)iv << 1;
3666 stream_put_tv (s, BOP_INTEGER, iv);
3667 }
3668 return;
3669
3670 case T_SYMBOL:
3671 if (0)
3672 {
3673 // no can do without more analysis
3674 pointer m = lookup (SCHEME_A_ x);
3675
3676 if (is_proc (m))
3677 {
3678 printf ("compile proc %s %d\n", procname(m), procnum(m));
3679 stream_put_tv (s, BOP_SYMBOL, BOP_OP + procnum (m));
3680 }
3681 else
3682 stream_put_tv (s, BOP_SYMBOL, symbol_id (SCHEME_A_ x));
3683 }
3684
3685 stream_put_tv (s, BOP_SYMBOL, symbol_id (SCHEME_A_ x));
3686 return;
3687
3688 default:
3689 stream_put_tv (s, BOP_DATUM, cell_id (SCHEME_A_ x));
3690 break;
3691 }
3692}
3693
3694ecb_cold static int
3695compile_closure (SCHEME_P_ pointer p)
3696{
3697 stream s = stream_init ();
3698
3699 compile_list (SCHEME_A_ s, cdar (p));
3700
3701 FILE *xxd = popen ("xxd", "we");
3702 fwrite (stream_data (s), 1, stream_size (s), xxd);
3703 fclose (xxd);
3704
3705 return stream_size (s);
3706}
3707
3306#endif 3708#endif
3307 3709
3308/* syntax, eval, core, ... */ 3710/* syntax, eval, core, ... */
3309ecb_hot static int 3711ecb_hot static int
3310opexe_0 (SCHEME_P_ enum scheme_opcodes op) 3712opexe_0 (SCHEME_P_ enum scheme_opcodes op)
3314 3716
3315 switch (op) 3717 switch (op)
3316 { 3718 {
3317#if EXPERIMENT //D 3719#if EXPERIMENT //D
3318 case OP_DEBUG: 3720 case OP_DEBUG:
3319 printf ("len = %d\n", debug (SCHEME_A_ 0, args) / 8); 3721 {
3722 uint32_t len = compile_closure (SCHEME_A_ car (args));
3723 printf ("len = %d\n", len);
3320 printf ("\n"); 3724 printf ("\n");
3321 s_return (S_T); 3725 s_return (S_T);
3726 }
3727
3728 case OP_DEBUG2:
3729 return -1;
3322#endif 3730#endif
3731
3323 case OP_LOAD: /* load */ 3732 case OP_LOAD: /* load */
3324 if (file_interactive (SCHEME_A)) 3733 if (file_interactive (SCHEME_A))
3325 { 3734 {
3326 putstr (SCHEME_A_ "Loading "); putstr (SCHEME_A_ strvalue (car (args))); putstr (SCHEME_A_ "\n"); 3735 putstr (SCHEME_A_ "Loading ");
3327 //D fprintf (port (SCHEME_V->outport)->rep.stdio.file, "Loading %s\n", strvalue (car (args))); 3736 putstr (SCHEME_A_ strvalue (car (args)));
3737 putcharacter (SCHEME_A_ '\n');
3328 } 3738 }
3329 3739
3330 if (!file_push (SCHEME_A_ strvalue (car (args)))) 3740 if (!file_push (SCHEME_A_ strvalue (car (args))))
3331 Error_1 ("unable to open", car (args)); 3741 Error_1 ("unable to open", car (args));
3332 else 3742
3333 {
3334 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 3743 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
3335 s_goto (OP_T0LVL); 3744 s_goto (OP_T0LVL);
3336 }
3337 3745
3338 case OP_T0LVL: /* top level */ 3746 case OP_T0LVL: /* top level */
3339 3747
3340 /* If we reached the end of file, this loop is done. */ 3748 /* If we reached the end of file, this loop is done. */
3341 if (port (SCHEME_V->loadport)->kind & port_saw_EOF) 3749 if (port (SCHEME_V->loadport)->kind & port_saw_EOF)
3357 /* If interactive, be nice to user. */ 3765 /* If interactive, be nice to user. */
3358 if (file_interactive (SCHEME_A)) 3766 if (file_interactive (SCHEME_A))
3359 { 3767 {
3360 SCHEME_V->envir = SCHEME_V->global_env; 3768 SCHEME_V->envir = SCHEME_V->global_env;
3361 dump_stack_reset (SCHEME_A); 3769 dump_stack_reset (SCHEME_A);
3362 putstr (SCHEME_A_ "\n"); 3770 putcharacter (SCHEME_A_ '\n');
3771#if EXPERIMENT
3772 system ("ps v $PPID");
3773#endif
3363 putstr (SCHEME_A_ prompt); 3774 putstr (SCHEME_A_ prompt);
3364 } 3775 }
3365 3776
3366 /* Set up another iteration of REPL */ 3777 /* Set up another iteration of REPL */
3367 SCHEME_V->nesting = 0; 3778 SCHEME_V->nesting = 0;
3402 { 3813 {
3403 SCHEME_V->print_flag = 1; 3814 SCHEME_V->print_flag = 1;
3404 SCHEME_V->args = SCHEME_V->value; 3815 SCHEME_V->args = SCHEME_V->value;
3405 s_goto (OP_P0LIST); 3816 s_goto (OP_P0LIST);
3406 } 3817 }
3407 else 3818
3408 s_return (SCHEME_V->value); 3819 s_return (SCHEME_V->value);
3409 3820
3410 case OP_EVAL: /* main part of evaluation */ 3821 case OP_EVAL: /* main part of evaluation */
3411#if USE_TRACING 3822#if USE_TRACING
3412 if (SCHEME_V->tracing) 3823 if (SCHEME_V->tracing)
3413 { 3824 {
3446 /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */ 3857 /* If no macros => s_save(SCHEME_A_ OP_E1ARGS, NIL, cdr(SCHEME_V->code)); */
3447 SCHEME_V->code = x; 3858 SCHEME_V->code = x;
3448 s_goto (OP_EVAL); 3859 s_goto (OP_EVAL);
3449 } 3860 }
3450 } 3861 }
3451 else 3862
3452 s_return (SCHEME_V->code); 3863 s_return (SCHEME_V->code);
3453 3864
3454 case OP_E0ARGS: /* eval arguments */ 3865 case OP_E0ARGS: /* eval arguments */
3455 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */ 3866 if (ecb_expect_false (is_macro (SCHEME_V->value))) /* macro expansion */
3456 { 3867 {
3457 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL); 3868 s_save (SCHEME_A_ OP_DOMACRO, NIL, NIL);
3458 SCHEME_V->args = cons (SCHEME_V->code, NIL); 3869 SCHEME_V->args = cons (SCHEME_V->code, NIL);
3459 SCHEME_V->code = SCHEME_V->value; 3870 SCHEME_V->code = SCHEME_V->value;
3460 s_goto (OP_APPLY); 3871 s_goto (OP_APPLY);
3461 } 3872 }
3462 else 3873
3463 {
3464 SCHEME_V->code = cdr (SCHEME_V->code); 3874 SCHEME_V->code = cdr (SCHEME_V->code);
3465 s_goto (OP_E1ARGS); 3875 s_goto (OP_E1ARGS);
3466 }
3467 3876
3468 case OP_E1ARGS: /* eval arguments */ 3877 case OP_E1ARGS: /* eval arguments */
3469 args = cons (SCHEME_V->value, args); 3878 args = cons (SCHEME_V->value, args);
3470 3879
3471 if (is_pair (SCHEME_V->code)) /* continue */ 3880 if (is_pair (SCHEME_V->code)) /* continue */
3482 SCHEME_V->args = cdr (args); 3891 SCHEME_V->args = cdr (args);
3483 s_goto (OP_APPLY); 3892 s_goto (OP_APPLY);
3484 } 3893 }
3485 3894
3486#if USE_TRACING 3895#if USE_TRACING
3487
3488 case OP_TRACING: 3896 case OP_TRACING:
3489 { 3897 {
3490 int tr = SCHEME_V->tracing; 3898 int tr = SCHEME_V->tracing;
3491 3899
3492 SCHEME_V->tracing = ivalue_unchecked (car (args)); 3900 SCHEME_V->tracing = ivalue_unchecked (car (args));
3493 s_return (mk_integer (SCHEME_A_ tr)); 3901 s_return (mk_integer (SCHEME_A_ tr));
3494 } 3902 }
3495
3496#endif 3903#endif
3497 3904
3498 case OP_APPLY: /* apply 'code' to 'args' */ 3905 case OP_APPLY: /* apply 'code' to 'args' */
3499#if USE_TRACING 3906#if USE_TRACING
3500 if (SCHEME_V->tracing) 3907 if (SCHEME_V->tracing)
3554 else if (is_continuation (SCHEME_V->code)) /* CONTINUATION */ 3961 else if (is_continuation (SCHEME_V->code)) /* CONTINUATION */
3555 { 3962 {
3556 ss_set_cont (SCHEME_A_ cont_dump (SCHEME_V->code)); 3963 ss_set_cont (SCHEME_A_ cont_dump (SCHEME_V->code));
3557 s_return (args != NIL ? car (args) : NIL); 3964 s_return (args != NIL ? car (args) : NIL);
3558 } 3965 }
3559 else 3966
3560 Error_0 ("illegal function"); 3967 Error_0 ("illegal function");
3561 3968
3562 case OP_DOMACRO: /* do macro */ 3969 case OP_DOMACRO: /* do macro */
3563 SCHEME_V->code = SCHEME_V->value; 3970 SCHEME_V->code = SCHEME_V->value;
3564 s_goto (OP_EVAL); 3971 s_goto (OP_EVAL);
3565 3972
3629 else 4036 else
3630 new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value); 4037 new_slot_in_env (SCHEME_A_ SCHEME_V->code, SCHEME_V->value);
3631 4038
3632 s_return (SCHEME_V->code); 4039 s_return (SCHEME_V->code);
3633 4040
3634
3635 case OP_DEFP: /* defined? */ 4041 case OP_DEFP: /* defined? */
3636 x = SCHEME_V->envir; 4042 x = SCHEME_V->envir;
3637 4043
3638 if (cdr (args) != NIL) 4044 if (cdr (args) != NIL)
3639 x = cadr (args); 4045 x = cadr (args);
3657 s_return (SCHEME_V->value); 4063 s_return (SCHEME_V->value);
3658 } 4064 }
3659 else 4065 else
3660 Error_1 ("set!: unbound variable:", SCHEME_V->code); 4066 Error_1 ("set!: unbound variable:", SCHEME_V->code);
3661 4067
3662
3663 case OP_BEGIN: /* begin */ 4068 case OP_BEGIN: /* begin */
3664 if (!is_pair (SCHEME_V->code)) 4069 if (!is_pair (SCHEME_V->code))
3665 s_return (SCHEME_V->code); 4070 s_return (SCHEME_V->code);
3666 4071
3667 if (cdr (SCHEME_V->code) != NIL) 4072 if (cdr (SCHEME_V->code) != NIL)
3678 case OP_IF1: /* if */ 4083 case OP_IF1: /* if */
3679 if (is_true (SCHEME_V->value)) 4084 if (is_true (SCHEME_V->value))
3680 SCHEME_V->code = car (SCHEME_V->code); 4085 SCHEME_V->code = car (SCHEME_V->code);
3681 else 4086 else
3682 SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */ 4087 SCHEME_V->code = cadr (SCHEME_V->code); /* (if #f 1) ==> () because * car(NIL) = NIL */
4088
3683 s_goto (OP_EVAL); 4089 s_goto (OP_EVAL);
3684 4090
3685 case OP_LET0: /* let */ 4091 case OP_LET0: /* let */
3686 SCHEME_V->args = NIL; 4092 SCHEME_V->args = NIL;
3687 SCHEME_V->value = SCHEME_V->code; 4093 SCHEME_V->value = SCHEME_V->code;
3688 SCHEME_V->code = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code); 4094 SCHEME_V->code = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code);
3689 s_goto (OP_LET1); 4095 s_goto (OP_LET1);
3690 4096
3691 case OP_LET1: /* let (calculate parameters) */ 4097 case OP_LET1: /* let (calculate parameters) */
4098 case OP_LET1REC: /* letrec (calculate parameters) */
3692 args = cons (SCHEME_V->value, args); 4099 args = cons (SCHEME_V->value, args);
3693 4100
3694 if (is_pair (SCHEME_V->code)) /* continue */ 4101 if (is_pair (SCHEME_V->code)) /* continue */
3695 { 4102 {
3696 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code))) 4103 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code)))
3697 Error_1 ("Bad syntax of binding spec in let :", car (SCHEME_V->code)); 4104 Error_1 ("Bad syntax of binding spec in let/letrec:", car (SCHEME_V->code));
3698 4105
3699 s_save (SCHEME_A_ OP_LET1, args, cdr (SCHEME_V->code)); 4106 s_save (SCHEME_A_ op, args, cdr (SCHEME_V->code));
3700 SCHEME_V->code = cadar (SCHEME_V->code); 4107 SCHEME_V->code = cadar (SCHEME_V->code);
3701 SCHEME_V->args = NIL; 4108 SCHEME_V->args = NIL;
3702 s_goto (OP_EVAL); 4109 s_goto (OP_EVAL);
3703 } 4110 }
3704 else /* end */ 4111
3705 { 4112 /* end */
3706 args = reverse_in_place (SCHEME_A_ NIL, args); 4113 args = reverse_in_place (SCHEME_A_ NIL, args);
3707 SCHEME_V->code = car (args); 4114 SCHEME_V->code = car (args);
3708 SCHEME_V->args = cdr (args); 4115 SCHEME_V->args = cdr (args);
3709 s_goto (OP_LET2); 4116 s_goto (op == OP_LET1 ? OP_LET2 : OP_LET2REC);
3710 }
3711 4117
3712 case OP_LET2: /* let */ 4118 case OP_LET2: /* let */
3713 new_frame_in_env (SCHEME_A_ SCHEME_V->envir); 4119 new_frame_in_env (SCHEME_A_ SCHEME_V->envir);
3714 4120
3715 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args; 4121 for (x = is_symbol (car (SCHEME_V->code)) ? cadr (SCHEME_V->code) : car (SCHEME_V->code), y = args;
3719 if (is_symbol (car (SCHEME_V->code))) /* named let */ 4125 if (is_symbol (car (SCHEME_V->code))) /* named let */
3720 { 4126 {
3721 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x)) 4127 for (x = cadr (SCHEME_V->code), args = NIL; x != NIL; x = cdr (x))
3722 { 4128 {
3723 if (!is_pair (x)) 4129 if (!is_pair (x))
3724 Error_1 ("Bad syntax of binding in let :", x); 4130 Error_1 ("Bad syntax of binding in let:", x);
3725 4131
3726 if (!is_list (SCHEME_A_ car (x))) 4132 if (!is_list (SCHEME_A_ car (x)))
3727 Error_1 ("Bad syntax of binding in let :", car (x)); 4133 Error_1 ("Bad syntax of binding in let:", car (x));
3728 4134
3729 args = cons (caar (x), args); 4135 args = cons (caar (x), args);
3730 } 4136 }
3731 4137
3732 x = mk_closure (SCHEME_A_ cons (reverse_in_place (SCHEME_A_ NIL, args), cddr (SCHEME_V->code)), 4138 x = mk_closure (SCHEME_A_ cons (reverse_in_place (SCHEME_A_ NIL, args), cddr (SCHEME_V->code)),
3749 SCHEME_V->code = cdr (SCHEME_V->code); 4155 SCHEME_V->code = cdr (SCHEME_V->code);
3750 s_goto (OP_BEGIN); 4156 s_goto (OP_BEGIN);
3751 } 4157 }
3752 4158
3753 if (!is_pair (car (SCHEME_V->code)) || !is_pair (caar (SCHEME_V->code)) || !is_pair (cdaar (SCHEME_V->code))) 4159 if (!is_pair (car (SCHEME_V->code)) || !is_pair (caar (SCHEME_V->code)) || !is_pair (cdaar (SCHEME_V->code)))
3754 Error_1 ("Bad syntax of binding spec in let* :", car (SCHEME_V->code)); 4160 Error_1 ("Bad syntax of binding spec in let*:", car (SCHEME_V->code));
3755 4161
3756 s_save (SCHEME_A_ OP_LET1AST, cdr (SCHEME_V->code), car (SCHEME_V->code)); 4162 s_save (SCHEME_A_ OP_LET1AST, cdr (SCHEME_V->code), car (SCHEME_V->code));
3757 SCHEME_V->code = car (cdaar (SCHEME_V->code)); 4163 SCHEME_V->code = car (cdaar (SCHEME_V->code));
3758 s_goto (OP_EVAL); 4164 s_goto (OP_EVAL);
3759 4165
3770 s_save (SCHEME_A_ OP_LET2AST, args, SCHEME_V->code); 4176 s_save (SCHEME_A_ OP_LET2AST, args, SCHEME_V->code);
3771 SCHEME_V->code = cadar (SCHEME_V->code); 4177 SCHEME_V->code = cadar (SCHEME_V->code);
3772 SCHEME_V->args = NIL; 4178 SCHEME_V->args = NIL;
3773 s_goto (OP_EVAL); 4179 s_goto (OP_EVAL);
3774 } 4180 }
3775 else /* end */ 4181
4182 /* end */
3776 { 4183
3777 SCHEME_V->code = args; 4184 SCHEME_V->code = args;
3778 SCHEME_V->args = NIL; 4185 SCHEME_V->args = NIL;
3779 s_goto (OP_BEGIN); 4186 s_goto (OP_BEGIN);
3780 }
3781 4187
3782 case OP_LET0REC: /* letrec */ 4188 case OP_LET0REC: /* letrec */
3783 new_frame_in_env (SCHEME_A_ SCHEME_V->envir); 4189 new_frame_in_env (SCHEME_A_ SCHEME_V->envir);
3784 SCHEME_V->args = NIL; 4190 SCHEME_V->args = NIL;
3785 SCHEME_V->value = SCHEME_V->code; 4191 SCHEME_V->value = SCHEME_V->code;
3786 SCHEME_V->code = car (SCHEME_V->code); 4192 SCHEME_V->code = car (SCHEME_V->code);
3787 s_goto (OP_LET1REC); 4193 s_goto (OP_LET1REC);
3788 4194
3789 case OP_LET1REC: /* letrec (calculate parameters) */ 4195 /* OP_LET1REC handled by OP_LET1 */
3790 args = cons (SCHEME_V->value, args);
3791
3792 if (is_pair (SCHEME_V->code)) /* continue */
3793 {
3794 if (!is_pair (car (SCHEME_V->code)) || !is_pair (cdar (SCHEME_V->code)))
3795 Error_1 ("Bad syntax of binding spec in letrec :", car (SCHEME_V->code));
3796
3797 s_save (SCHEME_A_ OP_LET1REC, args, cdr (SCHEME_V->code));
3798 SCHEME_V->code = cadar (SCHEME_V->code);
3799 SCHEME_V->args = NIL;
3800 s_goto (OP_EVAL);
3801 }
3802 else /* end */
3803 {
3804 args = reverse_in_place (SCHEME_A_ NIL, args);
3805 SCHEME_V->code = car (args);
3806 SCHEME_V->args = cdr (args);
3807 s_goto (OP_LET2REC);
3808 }
3809 4196
3810 case OP_LET2REC: /* letrec */ 4197 case OP_LET2REC: /* letrec */
3811 for (x = car (SCHEME_V->code), y = args; y != NIL; x = cdr (x), y = cdr (y)) 4198 for (x = car (SCHEME_V->code), y = args; y != NIL; x = cdr (x), y = cdr (y))
3812 new_slot_in_env (SCHEME_A_ caar (x), car (y)); 4199 new_slot_in_env (SCHEME_A_ caar (x), car (y));
3813 4200
3843 } 4230 }
3844 else 4231 else
3845 { 4232 {
3846 if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL) 4233 if ((SCHEME_V->code = cdr (SCHEME_V->code)) == NIL)
3847 s_return (NIL); 4234 s_return (NIL);
3848 else 4235
3849 {
3850 s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code); 4236 s_save (SCHEME_A_ OP_COND1, NIL, SCHEME_V->code);
3851 SCHEME_V->code = caar (SCHEME_V->code); 4237 SCHEME_V->code = caar (SCHEME_V->code);
3852 s_goto (OP_EVAL); 4238 s_goto (OP_EVAL);
3853 }
3854 } 4239 }
3855 4240
3856 case OP_DELAY: /* delay */ 4241 case OP_DELAY: /* delay */
3857 x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir); 4242 x = mk_closure (SCHEME_A_ cons (NIL, SCHEME_V->code), SCHEME_V->envir);
3858 set_typeflag (x, T_PROMISE); 4243 set_typeflag (x, T_PROMISE);
3869 case OP_AND1: /* and */ 4254 case OP_AND1: /* and */
3870 if (is_false (SCHEME_V->value)) 4255 if (is_false (SCHEME_V->value))
3871 s_return (SCHEME_V->value); 4256 s_return (SCHEME_V->value);
3872 else if (SCHEME_V->code == NIL) 4257 else if (SCHEME_V->code == NIL)
3873 s_return (SCHEME_V->value); 4258 s_return (SCHEME_V->value);
3874 else 4259
3875 {
3876 s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code)); 4260 s_save (SCHEME_A_ OP_AND1, NIL, cdr (SCHEME_V->code));
3877 SCHEME_V->code = car (SCHEME_V->code); 4261 SCHEME_V->code = car (SCHEME_V->code);
3878 s_goto (OP_EVAL); 4262 s_goto (OP_EVAL);
3879 }
3880 4263
3881 case OP_OR0: /* or */ 4264 case OP_OR0: /* or */
3882 if (SCHEME_V->code == NIL) 4265 if (SCHEME_V->code == NIL)
3883 s_return (S_F); 4266 s_return (S_F);
3884 4267
3889 case OP_OR1: /* or */ 4272 case OP_OR1: /* or */
3890 if (is_true (SCHEME_V->value)) 4273 if (is_true (SCHEME_V->value))
3891 s_return (SCHEME_V->value); 4274 s_return (SCHEME_V->value);
3892 else if (SCHEME_V->code == NIL) 4275 else if (SCHEME_V->code == NIL)
3893 s_return (SCHEME_V->value); 4276 s_return (SCHEME_V->value);
3894 else 4277
3895 {
3896 s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code)); 4278 s_save (SCHEME_A_ OP_OR1, NIL, cdr (SCHEME_V->code));
3897 SCHEME_V->code = car (SCHEME_V->code); 4279 SCHEME_V->code = car (SCHEME_V->code);
3898 s_goto (OP_EVAL); 4280 s_goto (OP_EVAL);
3899 }
3900 4281
3901 case OP_C0STREAM: /* cons-stream */ 4282 case OP_C0STREAM: /* cons-stream */
3902 s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code)); 4283 s_save (SCHEME_A_ OP_C1STREAM, NIL, cdr (SCHEME_V->code));
3903 SCHEME_V->code = car (SCHEME_V->code); 4284 SCHEME_V->code = car (SCHEME_V->code);
3904 s_goto (OP_EVAL); 4285 s_goto (OP_EVAL);
3969 s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x)); 4350 s_save (SCHEME_A_ OP_CASE2, NIL, cdar (x));
3970 SCHEME_V->code = caar (x); 4351 SCHEME_V->code = caar (x);
3971 s_goto (OP_EVAL); 4352 s_goto (OP_EVAL);
3972 } 4353 }
3973 } 4354 }
3974 else 4355
3975 s_return (NIL); 4356 s_return (NIL);
3976 4357
3977 case OP_CASE2: /* case */ 4358 case OP_CASE2: /* case */
3978 if (is_true (SCHEME_V->value)) 4359 if (is_true (SCHEME_V->value))
3979 s_goto (OP_BEGIN); 4360 s_goto (OP_BEGIN);
3980 else 4361
3981 s_return (NIL); 4362 s_return (NIL);
3982 4363
3983 case OP_PAPPLY: /* apply */ 4364 case OP_PAPPLY: /* apply */
3984 SCHEME_V->code = car (args); 4365 SCHEME_V->code = car (args);
3985 SCHEME_V->args = list_star (SCHEME_A_ cdr (args)); 4366 SCHEME_V->args = list_star (SCHEME_A_ cdr (args));
3986 /*SCHEME_V->args = cadr(args); */ 4367 /*SCHEME_V->args = cadr(args); */
4636 else 5017 else
4637 SCHEME_V->print_flag = 0; 5018 SCHEME_V->print_flag = 0;
4638 5019
4639 s_goto (OP_P0LIST); 5020 s_goto (OP_P0LIST);
4640 5021
5022 //TODO: move to scheme
4641 case OP_NEWLINE: /* newline */ 5023 case OP_NEWLINE: /* newline */
4642 if (is_pair (args)) 5024 if (is_pair (args))
4643 { 5025 {
4644 if (a != SCHEME_V->outport) 5026 if (a != SCHEME_V->outport)
4645 { 5027 {
4647 s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL); 5029 s_save (SCHEME_A_ OP_SET_OUTPORT, x, NIL);
4648 SCHEME_V->outport = a; 5030 SCHEME_V->outport = a;
4649 } 5031 }
4650 } 5032 }
4651 5033
4652 putstr (SCHEME_A_ "\n"); 5034 putcharacter (SCHEME_A_ '\n');
4653 s_return (S_T); 5035 s_return (S_T);
4654#endif 5036#endif
4655 5037
4656 case OP_ERR0: /* error */ 5038 case OP_ERR0: /* error */
4657 SCHEME_V->retcode = -1; 5039 SCHEME_V->retcode = -1;
4666 putstr (SCHEME_A_ strvalue (car (args))); 5048 putstr (SCHEME_A_ strvalue (car (args)));
4667 SCHEME_V->args = cdr (args); 5049 SCHEME_V->args = cdr (args);
4668 s_goto (OP_ERR1); 5050 s_goto (OP_ERR1);
4669 5051
4670 case OP_ERR1: /* error */ 5052 case OP_ERR1: /* error */
4671 putstr (SCHEME_A_ " "); 5053 putcharacter (SCHEME_A_ ' ');
4672 5054
4673 if (args != NIL) 5055 if (args != NIL)
4674 { 5056 {
4675 s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL); 5057 s_save (SCHEME_A_ OP_ERR1, cdr (args), NIL);
4676 SCHEME_V->args = a; 5058 SCHEME_V->args = a;
4677 SCHEME_V->print_flag = 1; 5059 SCHEME_V->print_flag = 1;
4678 s_goto (OP_P0LIST); 5060 s_goto (OP_P0LIST);
4679 } 5061 }
4680 else 5062 else
4681 { 5063 {
4682 putstr (SCHEME_A_ "\n"); 5064 putcharacter (SCHEME_A_ '\n');
4683 5065
4684 if (SCHEME_V->interactive_repl) 5066 if (SCHEME_V->interactive_repl)
4685 s_goto (OP_T0LVL); 5067 s_goto (OP_T0LVL);
4686 else 5068 else
4687 return -1; 5069 return -1;
4985 case OP_RDSEXPR: 5367 case OP_RDSEXPR:
4986 switch (SCHEME_V->tok) 5368 switch (SCHEME_V->tok)
4987 { 5369 {
4988 case TOK_EOF: 5370 case TOK_EOF:
4989 s_return (S_EOF); 5371 s_return (S_EOF);
4990 /* NOTREACHED */
4991 5372
4992 case TOK_VEC: 5373 case TOK_VEC:
4993 s_save (SCHEME_A_ OP_RDVEC, NIL, NIL); 5374 s_save (SCHEME_A_ OP_RDVEC, NIL, NIL);
4994 /* fall through */ 5375 /* fall through */
4995 5376
4998 5379
4999 if (SCHEME_V->tok == TOK_RPAREN) 5380 if (SCHEME_V->tok == TOK_RPAREN)
5000 s_return (NIL); 5381 s_return (NIL);
5001 else if (SCHEME_V->tok == TOK_DOT) 5382 else if (SCHEME_V->tok == TOK_DOT)
5002 Error_0 ("syntax error: illegal dot expression"); 5383 Error_0 ("syntax error: illegal dot expression");
5003 else 5384
5004 {
5005 SCHEME_V->nesting_stack[SCHEME_V->file_i]++; 5385 SCHEME_V->nesting_stack[SCHEME_V->file_i]++;
5006 s_save (SCHEME_A_ OP_RDLIST, NIL, NIL); 5386 s_save (SCHEME_A_ OP_RDLIST, NIL, NIL);
5007 s_goto (OP_RDSEXPR); 5387 s_goto (OP_RDSEXPR);
5008 }
5009 5388
5010 case TOK_QUOTE: 5389 case TOK_QUOTE:
5011 s_save (SCHEME_A_ OP_RDQUOTE, NIL, NIL); 5390 s_save (SCHEME_A_ OP_RDQUOTE, NIL, NIL);
5012 SCHEME_V->tok = token (SCHEME_A); 5391 SCHEME_V->tok = token (SCHEME_A);
5013 s_goto (OP_RDSEXPR); 5392 s_goto (OP_RDSEXPR);
5019 { 5398 {
5020 s_save (SCHEME_A_ OP_RDQQUOTEVEC, NIL, NIL); 5399 s_save (SCHEME_A_ OP_RDQQUOTEVEC, NIL, NIL);
5021 SCHEME_V->tok = TOK_LPAREN; 5400 SCHEME_V->tok = TOK_LPAREN;
5022 s_goto (OP_RDSEXPR); 5401 s_goto (OP_RDSEXPR);
5023 } 5402 }
5024 else 5403
5025 s_save (SCHEME_A_ OP_RDQQUOTE, NIL, NIL); 5404 s_save (SCHEME_A_ OP_RDQQUOTE, NIL, NIL);
5026
5027 s_goto (OP_RDSEXPR); 5405 s_goto (OP_RDSEXPR);
5028 5406
5029 case TOK_COMMA: 5407 case TOK_COMMA:
5030 s_save (SCHEME_A_ OP_RDUNQUOTE, NIL, NIL); 5408 s_save (SCHEME_A_ OP_RDUNQUOTE, NIL, NIL);
5031 SCHEME_V->tok = token (SCHEME_A); 5409 SCHEME_V->tok = token (SCHEME_A);
5042 case TOK_DOTATOM: 5420 case TOK_DOTATOM:
5043 SCHEME_V->strbuff[0] = '.'; 5421 SCHEME_V->strbuff[0] = '.';
5044 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS))); 5422 s_return (mk_atom (SCHEME_A_ readstr_upto (SCHEME_A_ 1, DELIMITERS)));
5045 5423
5046 case TOK_STRATOM: 5424 case TOK_STRATOM:
5425 //TODO: haven't checked whether the garbage collector could interfere and free x
5426 gc (SCHEME_A_ NIL, NIL); //TODO: superheavyhanded
5047 x = readstrexp (SCHEME_A_ '|'); 5427 x = readstrexp (SCHEME_A_ '|');
5048 //TODO: haven't checked whether the garbage collector could interfere
5049 s_return (mk_atom (SCHEME_A_ strvalue (x))); 5428 s_return (mk_atom (SCHEME_A_ strvalue (x)));
5050 5429
5051 case TOK_DQUOTE: 5430 case TOK_DQUOTE:
5052 x = readstrexp (SCHEME_A_ '"'); 5431 x = readstrexp (SCHEME_A_ '"');
5053 5432
5061 { 5440 {
5062 pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->SHARP_HOOK, 1); 5441 pointer f = find_slot_in_env (SCHEME_A_ SCHEME_V->envir, SCHEME_V->SHARP_HOOK, 1);
5063 5442
5064 if (f == NIL) 5443 if (f == NIL)
5065 Error_0 ("undefined sharp expression"); 5444 Error_0 ("undefined sharp expression");
5066 else 5445
5067 {
5068 SCHEME_V->code = cons (slot_value_in_env (f), NIL); 5446 SCHEME_V->code = cons (slot_value_in_env (f), NIL);
5069 s_goto (OP_EVAL); 5447 s_goto (OP_EVAL);
5070 }
5071 } 5448 }
5072 5449
5073 case TOK_SHARP_CONST: 5450 case TOK_SHARP_CONST:
5074 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL) 5451 if ((x = mk_sharp_const (SCHEME_A_ readstr_upto (SCHEME_A_ 0, DELIMITERS))) == NIL)
5075 Error_0 ("undefined sharp expression"); 5452 Error_0 ("undefined sharp expression");
5076 else 5453
5077 s_return (x); 5454 s_return (x);
5078 5455
5079 default: 5456 default:
5080 Error_0 ("syntax error: illegal token"); 5457 Error_0 ("syntax error: illegal token");
5081 } 5458 }
5082 5459
5175 pointer b = cdr (args); 5552 pointer b = cdr (args);
5176 int ok_abbr = ok_abbrev (b); 5553 int ok_abbr = ok_abbrev (b);
5177 SCHEME_V->args = car (b); 5554 SCHEME_V->args = car (b);
5178 5555
5179 if (a == SCHEME_V->QUOTE && ok_abbr) 5556 if (a == SCHEME_V->QUOTE && ok_abbr)
5180 putstr (SCHEME_A_ "'"); 5557 putcharacter (SCHEME_A_ '\'');
5181 else if (a == SCHEME_V->QQUOTE && ok_abbr) 5558 else if (a == SCHEME_V->QQUOTE && ok_abbr)
5182 putstr (SCHEME_A_ "`"); 5559 putcharacter (SCHEME_A_ '`');
5183 else if (a == SCHEME_V->UNQUOTE && ok_abbr) 5560 else if (a == SCHEME_V->UNQUOTE && ok_abbr)
5184 putstr (SCHEME_A_ ","); 5561 putcharacter (SCHEME_A_ ',');
5185 else if (a == SCHEME_V->UNQUOTESP && ok_abbr) 5562 else if (a == SCHEME_V->UNQUOTESP && ok_abbr)
5186 putstr (SCHEME_A_ ",@"); 5563 putstr (SCHEME_A_ ",@");
5187 else 5564 else
5188 { 5565 {
5189 putstr (SCHEME_A_ "("); 5566 putcharacter (SCHEME_A_ '(');
5190 s_save (SCHEME_A_ OP_P1LIST, b, NIL); 5567 s_save (SCHEME_A_ OP_P1LIST, b, NIL);
5191 SCHEME_V->args = a; 5568 SCHEME_V->args = a;
5192 } 5569 }
5193 5570
5194 s_goto (OP_P0LIST); 5571 s_goto (OP_P0LIST);
5196 5573
5197 case OP_P1LIST: 5574 case OP_P1LIST:
5198 if (is_pair (args)) 5575 if (is_pair (args))
5199 { 5576 {
5200 s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL); 5577 s_save (SCHEME_A_ OP_P1LIST, cdr (args), NIL);
5201 putstr (SCHEME_A_ " "); 5578 putcharacter (SCHEME_A_ ' ');
5202 SCHEME_V->args = car (args); 5579 SCHEME_V->args = car (args);
5203 s_goto (OP_P0LIST); 5580 s_goto (OP_P0LIST);
5204 } 5581 }
5205 else if (is_vector (args)) 5582 else if (is_vector (args))
5206 { 5583 {
5214 { 5591 {
5215 putstr (SCHEME_A_ " . "); 5592 putstr (SCHEME_A_ " . ");
5216 printatom (SCHEME_A_ args, SCHEME_V->print_flag); 5593 printatom (SCHEME_A_ args, SCHEME_V->print_flag);
5217 } 5594 }
5218 5595
5219 putstr (SCHEME_A_ ")"); 5596 putcharacter (SCHEME_A_ ')');
5220 s_return (S_T); 5597 s_return (S_T);
5221 } 5598 }
5222 5599
5223 case OP_PVECFROM: 5600 case OP_PVECFROM:
5224 { 5601 {
5226 pointer vec = car (args); 5603 pointer vec = car (args);
5227 int len = veclength (vec); 5604 int len = veclength (vec);
5228 5605
5229 if (i == len) 5606 if (i == len)
5230 { 5607 {
5231 putstr (SCHEME_A_ ")"); 5608 putcharacter (SCHEME_A_ ')');
5232 s_return (S_T); 5609 s_return (S_T);
5233 } 5610 }
5234 else 5611 else
5235 { 5612 {
5236 pointer elem = vector_get (vec, i); 5613 pointer elem = vector_get (vec, i);
5238 ivalue_unchecked (cdr (args)) = i + 1; 5615 ivalue_unchecked (cdr (args)) = i + 1;
5239 s_save (SCHEME_A_ OP_PVECFROM, args, NIL); 5616 s_save (SCHEME_A_ OP_PVECFROM, args, NIL);
5240 SCHEME_V->args = elem; 5617 SCHEME_V->args = elem;
5241 5618
5242 if (i > 0) 5619 if (i > 0)
5243 putstr (SCHEME_A_ " "); 5620 putcharacter (SCHEME_A_ ' ');
5244 5621
5245 s_goto (OP_P0LIST); 5622 s_goto (OP_P0LIST);
5246 } 5623 }
5247 } 5624 }
5248 } 5625 }
5282 break; 5659 break;
5283 } 5660 }
5284 5661
5285 if (is_pair (y)) 5662 if (is_pair (y))
5286 s_return (car (y)); 5663 s_return (car (y));
5287 else 5664
5288 s_return (S_F); 5665 s_return (S_F);
5289
5290 5666
5291 case OP_GET_CLOSURE: /* get-closure-code *//* a.k */ 5667 case OP_GET_CLOSURE: /* get-closure-code *//* a.k */
5292 SCHEME_V->args = a; 5668 SCHEME_V->args = a;
5293 5669
5294 if (SCHEME_V->args == NIL) 5670 if (SCHEME_V->args == NIL)
5295 s_return (S_F); 5671 s_return (S_F);
5296 else if (is_closure (SCHEME_V->args)) 5672 else if (is_closure (SCHEME_V->args) || is_macro (SCHEME_V->args))
5297 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value))); 5673 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value)));
5298 else if (is_macro (SCHEME_V->args)) 5674
5299 s_return (cons (SCHEME_V->LAMBDA, closure_code (SCHEME_V->value)));
5300 else
5301 s_return (S_F); 5675 s_return (S_F);
5302 5676
5303 case OP_CLOSUREP: /* closure? */ 5677 case OP_CLOSUREP: /* closure? */
5304 /* 5678 /*
5305 * Note, macro object is also a closure. 5679 * Note, macro object is also a closure.
5306 * Therefore, (closure? <#MACRO>) ==> #t 5680 * Therefore, (closure? <#MACRO>) ==> #t
5640 6014
5641ecb_cold int 6015ecb_cold int
5642scheme_init (SCHEME_P) 6016scheme_init (SCHEME_P)
5643{ 6017{
5644 int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]); 6018 int i, n = sizeof (dispatch_table) / sizeof (dispatch_table[0]);
5645 pointer x;
5646 6019
5647 /* this memset is not strictly correct, as we assume (intcache) 6020 /* this memset is not strictly correct, as we assume (intcache)
5648 * that memset 0 will also set pointers to 0, but memset does 6021 * that memset 0 will also set pointers to 0, but memset does
5649 * of course not guarantee that. screw such systems. 6022 * of course not guarantee that. screw such systems.
5650 */ 6023 */
5678#endif 6051#endif
5679 } 6052 }
5680 6053
5681 SCHEME_V->gc_verbose = 0; 6054 SCHEME_V->gc_verbose = 0;
5682 dump_stack_initialize (SCHEME_A); 6055 dump_stack_initialize (SCHEME_A);
5683 SCHEME_V->code = NIL; 6056 SCHEME_V->code = NIL;
5684 SCHEME_V->args = NIL; 6057 SCHEME_V->args = NIL;
5685 SCHEME_V->envir = NIL; 6058 SCHEME_V->envir = NIL;
6059 SCHEME_V->value = NIL;
5686 SCHEME_V->tracing = 0; 6060 SCHEME_V->tracing = 0;
5687 6061
5688 /* init NIL */ 6062 /* init NIL */
5689 set_typeflag (NIL, T_ATOM | T_MARK); 6063 set_typeflag (NIL, T_SPECIAL | T_ATOM);
5690 set_car (NIL, NIL); 6064 set_car (NIL, NIL);
5691 set_cdr (NIL, NIL); 6065 set_cdr (NIL, NIL);
5692 /* init T */ 6066 /* init T */
5693 set_typeflag (S_T, T_ATOM | T_MARK); 6067 set_typeflag (S_T, T_SPECIAL | T_ATOM);
5694 set_car (S_T, S_T); 6068 set_car (S_T, S_T);
5695 set_cdr (S_T, S_T); 6069 set_cdr (S_T, S_T);
5696 /* init F */ 6070 /* init F */
5697 set_typeflag (S_F, T_ATOM | T_MARK); 6071 set_typeflag (S_F, T_SPECIAL | T_ATOM);
5698 set_car (S_F, S_F); 6072 set_car (S_F, S_F);
5699 set_cdr (S_F, S_F); 6073 set_cdr (S_F, S_F);
5700 /* init EOF_OBJ */ 6074 /* init EOF_OBJ */
5701 set_typeflag (S_EOF, T_ATOM | T_MARK); 6075 set_typeflag (S_EOF, T_SPECIAL | T_ATOM);
5702 set_car (S_EOF, S_EOF); 6076 set_car (S_EOF, S_EOF);
5703 set_cdr (S_EOF, S_EOF); 6077 set_cdr (S_EOF, S_EOF);
5704 /* init sink */ 6078 /* init sink */
5705 set_typeflag (S_SINK, T_PAIR | T_MARK); 6079 set_typeflag (S_SINK, T_PAIR);
5706 set_car (S_SINK, NIL); 6080 set_car (S_SINK, NIL);
5707 6081
5708 /* init c_nest */ 6082 /* init c_nest */
5709 SCHEME_V->c_nest = NIL; 6083 SCHEME_V->c_nest = NIL;
5710 6084
5711 SCHEME_V->oblist = oblist_initial_value (SCHEME_A); 6085 SCHEME_V->oblist = oblist_initial_value (SCHEME_A);
5712 /* init global_env */ 6086 /* init global_env */
5713 new_frame_in_env (SCHEME_A_ NIL); 6087 new_frame_in_env (SCHEME_A_ NIL);
5714 SCHEME_V->global_env = SCHEME_V->envir; 6088 SCHEME_V->global_env = SCHEME_V->envir;
5715 /* init else */ 6089 /* init else */
5716 x = mk_symbol (SCHEME_A_ "else"); 6090 new_slot_in_env (SCHEME_A_ mk_symbol (SCHEME_A_ "else"), S_T);
5717 new_slot_in_env (SCHEME_A_ x, S_T);
5718 6091
5719 { 6092 {
5720 static const char *syntax_names[] = { 6093 static const char *syntax_names[] = {
5721 "lambda", "quote", "define", "if", "begin", "set!", 6094 "lambda", "quote", "define", "if", "begin", "set!",
5722 "let", "let*", "letrec", "cond", "delay", "and", 6095 "let", "let*", "letrec", "cond", "delay", "and",
5813 SCHEME_V->loadport = NIL; 6186 SCHEME_V->loadport = NIL;
5814 SCHEME_V->gc_verbose = 0; 6187 SCHEME_V->gc_verbose = 0;
5815 gc (SCHEME_A_ NIL, NIL); 6188 gc (SCHEME_A_ NIL, NIL);
5816 6189
5817 for (i = 0; i <= SCHEME_V->last_cell_seg; i++) 6190 for (i = 0; i <= SCHEME_V->last_cell_seg; i++)
5818 free (SCHEME_V->alloc_seg[i]); 6191 free (SCHEME_V->cell_seg[i]);
5819 6192
5820#if SHOW_ERROR_LINE 6193#if SHOW_ERROR_LINE
5821 for (i = 0; i <= SCHEME_V->file_i; i++) 6194 for (i = 0; i <= SCHEME_V->file_i; i++)
5822 {
5823 if (SCHEME_V->load_stack[i].kind & port_file) 6195 if (SCHEME_V->load_stack[i].kind & port_file)
5824 { 6196 {
5825 fname = SCHEME_V->load_stack[i].rep.stdio.filename; 6197 fname = SCHEME_V->load_stack[i].rep.stdio.filename;
5826 6198
5827 if (fname) 6199 if (fname)
5828 free (fname); 6200 free (fname);
5829 } 6201 }
5830 }
5831#endif 6202#endif
5832} 6203}
5833 6204
5834ecb_cold void 6205ecb_cold void
5835scheme_load_file (SCHEME_P_ int fin) 6206scheme_load_file (SCHEME_P_ int fin)
5844 SCHEME_V->envir = SCHEME_V->global_env; 6215 SCHEME_V->envir = SCHEME_V->global_env;
5845 SCHEME_V->file_i = 0; 6216 SCHEME_V->file_i = 0;
5846 SCHEME_V->load_stack[0].unget = -1; 6217 SCHEME_V->load_stack[0].unget = -1;
5847 SCHEME_V->load_stack[0].kind = port_input | port_file; 6218 SCHEME_V->load_stack[0].kind = port_input | port_file;
5848 SCHEME_V->load_stack[0].rep.stdio.file = fin; 6219 SCHEME_V->load_stack[0].rep.stdio.file = fin;
5849#if USE_PORTS
5850 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); 6220 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack);
5851#endif
5852 SCHEME_V->retcode = 0; 6221 SCHEME_V->retcode = 0;
5853 6222
5854#if USE_PORTS
5855 if (fin == STDIN_FILENO) 6223 if (fin == STDIN_FILENO)
5856 SCHEME_V->interactive_repl = 1; 6224 SCHEME_V->interactive_repl = 1;
5857#endif
5858 6225
5859#if USE_PORTS 6226#if USE_PORTS
5860#if SHOW_ERROR_LINE 6227#if SHOW_ERROR_LINE
5861 SCHEME_V->load_stack[0].rep.stdio.curr_line = 0; 6228 SCHEME_V->load_stack[0].rep.stdio.curr_line = 0;
5862 6229
5866#endif 6233#endif
5867 6234
5868 SCHEME_V->inport = SCHEME_V->loadport; 6235 SCHEME_V->inport = SCHEME_V->loadport;
5869 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 6236 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
5870 Eval_Cycle (SCHEME_A_ OP_T0LVL); 6237 Eval_Cycle (SCHEME_A_ OP_T0LVL);
6238
5871 set_typeflag (SCHEME_V->loadport, T_ATOM); 6239 set_typeflag (SCHEME_V->loadport, T_ATOM);
5872 6240
5873 if (SCHEME_V->retcode == 0) 6241 if (SCHEME_V->retcode == 0)
5874 SCHEME_V->retcode = SCHEME_V->nesting != 0; 6242 SCHEME_V->retcode = SCHEME_V->nesting != 0;
5875} 6243}
5876 6244
5877ecb_cold void 6245ecb_cold void
5878scheme_load_string (SCHEME_P_ const char *cmd) 6246scheme_load_string (SCHEME_P_ const char *cmd)
5879{ 6247{
6248#if USE_PORTs
5880 dump_stack_reset (SCHEME_A); 6249 dump_stack_reset (SCHEME_A);
5881 SCHEME_V->envir = SCHEME_V->global_env; 6250 SCHEME_V->envir = SCHEME_V->global_env;
5882 SCHEME_V->file_i = 0; 6251 SCHEME_V->file_i = 0;
5883 SCHEME_V->load_stack[0].kind = port_input | port_string; 6252 SCHEME_V->load_stack[0].kind = port_input | port_string;
5884 SCHEME_V->load_stack[0].rep.string.start = (char *)cmd; /* This func respects const */ 6253 SCHEME_V->load_stack[0].rep.string.start = (char *)cmd; /* This func respects const */
5885 SCHEME_V->load_stack[0].rep.string.past_the_end = (char *)cmd + strlen (cmd); 6254 SCHEME_V->load_stack[0].rep.string.past_the_end = (char *)cmd + strlen (cmd);
5886 SCHEME_V->load_stack[0].rep.string.curr = (char *)cmd; 6255 SCHEME_V->load_stack[0].rep.string.curr = (char *)cmd;
5887#if USE_PORTS
5888 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack); 6256 SCHEME_V->loadport = mk_port (SCHEME_A_ SCHEME_V->load_stack);
5889#endif
5890 SCHEME_V->retcode = 0; 6257 SCHEME_V->retcode = 0;
5891 SCHEME_V->interactive_repl = 0; 6258 SCHEME_V->interactive_repl = 0;
5892 SCHEME_V->inport = SCHEME_V->loadport; 6259 SCHEME_V->inport = SCHEME_V->loadport;
5893 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i); 6260 SCHEME_V->args = mk_integer (SCHEME_A_ SCHEME_V->file_i);
5894 Eval_Cycle (SCHEME_A_ OP_T0LVL); 6261 Eval_Cycle (SCHEME_A_ OP_T0LVL);
5895 set_typeflag (SCHEME_V->loadport, T_ATOM); 6262 set_typeflag (SCHEME_V->loadport, T_ATOM);
5896 6263
5897 if (SCHEME_V->retcode == 0) 6264 if (SCHEME_V->retcode == 0)
5898 SCHEME_V->retcode = SCHEME_V->nesting != 0; 6265 SCHEME_V->retcode = SCHEME_V->nesting != 0;
6266#else
6267 abort ();
6268#endif
5899} 6269}
5900 6270
5901ecb_cold void 6271ecb_cold void
5902scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value) 6272scheme_define (SCHEME_P_ pointer envir, pointer symbol, pointer value)
5903{ 6273{
6008# endif 6378# endif
6009 int fin; 6379 int fin;
6010 char *file_name = InitFile; 6380 char *file_name = InitFile;
6011 int retcode; 6381 int retcode;
6012 int isfile = 1; 6382 int isfile = 1;
6383#if EXPERIMENT
6013 system ("ps v $PPID");//D 6384 system ("ps v $PPID");
6385#endif
6014 6386
6015 if (argc == 2 && strcmp (argv[1], "-?") == 0) 6387 if (argc == 2 && strcmp (argv[1], "-?") == 0)
6016 { 6388 {
6017 putstr (SCHEME_A_ "Usage: tinyscheme -?\n"); 6389 putstr (SCHEME_A_ "Usage: tinyscheme -?\n");
6018 putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n"); 6390 putstr (SCHEME_A_ "or: tinyscheme [<file1> <file2> ...]\n");
6047 } 6419 }
6048#endif 6420#endif
6049 6421
6050 do 6422 do
6051 { 6423 {
6052#if USE_PORTS
6053 if (strcmp (file_name, "-") == 0) 6424 if (strcmp (file_name, "-") == 0)
6054 fin = STDIN_FILENO; 6425 fin = STDIN_FILENO;
6055 else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0) 6426 else if (strcmp (file_name, "-1") == 0 || strcmp (file_name, "-c") == 0)
6056 { 6427 {
6057 pointer args = NIL; 6428 pointer args = NIL;
6075 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args); 6446 scheme_define (SCHEME_A_ SCHEME_V->global_env, mk_symbol (SCHEME_A_ "*args*"), args);
6076 6447
6077 } 6448 }
6078 else 6449 else
6079 fin = open (file_name, O_RDONLY); 6450 fin = open (file_name, O_RDONLY);
6080#endif
6081 6451
6082 if (isfile && fin < 0) 6452 if (isfile && fin < 0)
6083 { 6453 {
6084 putstr (SCHEME_A_ "Could not open file "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); 6454 putstr (SCHEME_A_ "Could not open file ");
6455 putstr (SCHEME_A_ file_name);
6456 putcharacter (SCHEME_A_ '\n');
6085 } 6457 }
6086 else 6458 else
6087 { 6459 {
6088 if (isfile) 6460 if (isfile)
6089 scheme_load_named_file (SCHEME_A_ fin, file_name); 6461 scheme_load_named_file (SCHEME_A_ fin, file_name);
6090 else 6462 else
6091 scheme_load_string (SCHEME_A_ file_name); 6463 scheme_load_string (SCHEME_A_ file_name);
6092 6464
6093#if USE_PORTS
6094 if (!isfile || fin != STDIN_FILENO) 6465 if (!isfile || fin != STDIN_FILENO)
6095 { 6466 {
6096 if (SCHEME_V->retcode != 0) 6467 if (SCHEME_V->retcode != 0)
6097 { 6468 {
6098 putstr (SCHEME_A_ "Errors encountered reading "); putstr (SCHEME_A_ file_name); putstr (SCHEME_A_ "\n"); 6469 putstr (SCHEME_A_ "Errors encountered reading ");
6470 putstr (SCHEME_A_ file_name);
6471 putcharacter (SCHEME_A_ '\n');
6099 } 6472 }
6100 6473
6101 if (isfile) 6474 if (isfile)
6102 close (fin); 6475 close (fin);
6103 } 6476 }
6104#endif
6105 } 6477 }
6106 6478
6107 file_name = *argv++; 6479 file_name = *argv++;
6108 } 6480 }
6109 while (file_name != 0); 6481 while (file_name != 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines