Print the prompt when it makes sense only.
Unified · Split
| @@ -424,12 +424,12 @@ · 423 unmodified lines | ||
| 424 | 424 | #fn(ash)) ref-s32-LE) |
| 425 | 425 | remprop #fn("n220711q5386;3F042286052;3:042386062:" #(#fn(get) *properties* #fn(has?) |
| 426 | 426 | #fn(del!)) remprop) |
| 427 | − repl #fn("n0IIb4b5208421_5142085228485>2_51485<5047360:" #(#0# | |
| 428 | − #fn("n07050421725142324{257651S;3Z04778451788551360q@=079855147:5047;85w<61:" #(*prompt* | |
| 429 | − #fn(io-flush) *io-out* #fn("n02060:" #(#fn(read))) | |
| 430 | − #fn("n1207151422061:" #(#fn(io-discardbuffer) *io-in* #fn(raise))) | |
| 431 | − #fn(io-eof?) *io-in* load-process void? print newline void that) prompt) | |
| 432 | − #fn("n020A>121{370F<60:q:" #(#fn("n0A<60:") | |
| 427 | + repl #fn("n0IIb4b5705042172514238424_5142385258485>2_51485<5047660:" #(*prompt* #fn(io-flush) | |
| 428 | + *io-out* #0# | |
| 429 | + #fn("n02021{227351S;3q047484517585513M07584513@076504277851@30q@=079855147:5047;85w<61:" #(#fn("n02071D62:" #(#fn(read) | |
| 430 | + *io-in*)) #fn("n1207151422061:" #(#fn(io-discardbuffer) *io-in* #fn(raise))) | |
| 431 | + #fn(io-eof?) *io-in* load-process void? *prompt* #fn(io-flush) *io-out* print newline void that) prompt) | |
| 432 | + #fn("n020A>121{370F<60:q:" #(#fn("n0A<60:") | |
| 433 | 433 | #fn("n1700514D:" #(top-level-exception-handler))) reploop) newline) repl) |
| 434 | 434 | revappend #fn("n2701062:" #(reverse-) revappend) reverse |
| 435 | 435 | #fn("n170q062:" #(reverse-) reverse) reverse! #fn("n170q062:" #(reverse!-) reverse!) |
| @@ -147,10 +147,10 @@ BUILTIN("buffer", buffer) · 146 unmodified lines | ||
| 147 | 147 | BUILTIN("read", read) |
| 148 | 148 | { |
| 149 | 149 | if(nargs > 1) |
| 150 | − argcount(nargs, 1); | |
| 150 | + argcount(nargs, 2); | |
| 151 | 151 | sl_v a = nargs == 0 ? sym_value(sl_ioinsym) : args[0]; |
| 152 | 152 | sl_gc_handle(&a); |
| 153 | − sl_v v = sl_read_sexpr(a); | |
| 153 | + sl_v v = sl_read_sexpr(a, nargs > 1 && args[1] == sl_t); | |
| 154 | 154 | sl_free_gc_handles(1); |
| 155 | 155 | return ios_eof(toio(a)) ? sl_eof : v; |
| 156 | 156 | } |
| @@ -16,9 +16,10 @@ enum { · 15 unmodified lines | ||
| 16 | 16 | typedef struct Rctx Rctx; |
| 17 | 17 | |
| 18 | 18 | struct Rctx { |
| 19 | − u32int toktype; | |
| 20 | 19 | sl_v tokval; |
| 21 | 20 | sl_loc loc; |
| 21 | + u32int toktype; | |
| 22 | + bool ws; | |
| 22 | 23 | char buf[1024]; |
| 23 | 24 | }; |
| 24 | 25 | |
| @@ -91,26 +92,25 @@ sl_read_numtok(const char *tok, sl_v *pval, int base) · 66 unmodified lines | ||
| 91 | 92 | } |
| 92 | 93 | |
| 93 | 94 | static char |
| 94 | −nextchar(void) | |
| 95 | +nextchar(Rctx *ctx) | |
| 95 | 96 | { |
| 96 | − int ch; | |
| 97 | − char c; | |
| 97 | + int c; | |
| 98 | 98 | sl_ios *f = RS; |
| 99 | 99 | |
| 100 | 100 | do{ |
| 101 | − ch = ios_getc(RS); | |
| 102 | − if(ch == IOS_EOF) | |
| 101 | + c = ios_getc(RS); | |
| 102 | + if(c == IOS_EOF) | |
| 103 | 103 | return 0; |
| 104 | − c = ch; | |
| 105 | 104 | if(c == ';'){ |
| 106 | 105 | // single-line comment |
| 107 | 106 | do{ |
| 108 | − ch = ios_getc(f); | |
| 109 | − if(ch == IOS_EOF) | |
| 107 | + c = ios_getc(f); | |
| 108 | + if(c == IOS_EOF) | |
| 110 | 109 | return 0; |
| 111 | − }while(ch != '\n'); | |
| 112 | − c = ch; | |
| 110 | + }while(c != '\n'); | |
| 113 | 111 | } |
| 112 | + if(c == '\n' && ctx->ws) | |
| 113 | + return '\n'; | |
| 114 | 114 | }while(c == ' ' || isspace(c)); |
| 115 | 115 | return c; |
| 116 | 116 | } |
| @@ -206,9 +206,10 @@ peek(Rctx *ctx) · 89 unmodified lines | ||
| 206 | 206 | |
| 207 | 207 | if(ctx->toktype != TOK_NONE) |
| 208 | 208 | return ctx->toktype; |
| 209 | − c = nextchar(); | |
| 209 | + c = nextchar(ctx); | |
| 210 | 210 | ctx->loc = RS->loc; |
| 211 | − if(ios_eof(RS)) | |
| 211 | + ctx->ws = false; | |
| 212 | + if(ios_eof(RS) || isspace(c)) | |
| 212 | 213 | return TOK_NONE; |
| 213 | 214 | if(c == '(') |
| 214 | 215 | ctx->toktype = TOK_OPEN; |
| @@ -320,7 +321,6 @@ peek(Rctx *ctx) · 105 unmodified lines | ||
| 320 | 321 | goto hashpipe_gotc; |
| 321 | 322 | } |
| 322 | 323 | } |
| 323 | − // this was whitespace, so keep peeking | |
| 324 | 324 | return peek(ctx); |
| 325 | 325 | }else if(c == ';'){ |
| 326 | 326 | // datum comment |
| @@ -699,7 +699,7 @@ do_read_sexpr(Rctx *ctx, sl_v label) · 372 unmodified lines | ||
| 699 | 699 | case TOK_SHARPSYM: |
| 700 | 700 | sym = ctx->tokval; |
| 701 | 701 | // constructor notation |
| 702 | − c = nextchar(); | |
| 702 | + c = nextchar(ctx); | |
| 703 | 703 | ctx->loc = RS->loc; |
| 704 | 704 | if(c != '('){ |
| 705 | 705 | take(ctx); |
| @@ -767,7 +767,7 @@ do_read_sexpr(Rctx *ctx, sl_v label) · 61 unmodified lines | ||
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | sl_v |
| 770 | −sl_read_sexpr(sl_v f) | |
| 770 | +sl_read_sexpr(sl_v f, bool ws) | |
| 771 | 771 | { |
| 772 | 772 | sl_readstate state; |
| 773 | 773 | state.prev = sl.readstate; |
| @@ -777,6 +777,7 @@ sl_read_sexpr(sl_v f) · 3 unmodified lines | ||
| 777 | 777 | sl.readstate = &state; |
| 778 | 778 | Rctx ctx; |
| 779 | 779 | ctx.toktype = TOK_NONE; |
| 780 | + ctx.ws = ws; | |
| 780 | 781 | sl_gc_handle(&ctx.tokval); |
| 781 | 782 | |
| 782 | 783 | sl_v v = do_read_sexpr(&ctx, UNBOUND); |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | #pragma once |
| 2 | 2 | |
| 3 | −sl_v sl_read_sexpr(sl_v f); | |
| 3 | +sl_v sl_read_sexpr(sl_v f, bool ws); | |
| 4 | 4 | bool sl_read_numtok(const char *tok, sl_v *pval, int base); |
| 5 | 5 | |
| 6 | 6 | // defines which characters are ordinary symbol characters. |
| @@ -1355,7 +1355,7 @@ sl_load_system_image(sl_v sys_image_io) · 1354 unmodified lines | ||
| 1355 | 1355 | SL_TRY{ |
| 1356 | 1356 | while(1){ |
| 1357 | 1357 | sl.sp = saveSP; |
| 1358 | − sl_v e = sl_read_sexpr(sl.sp[-1]); | |
| 1358 | + sl_v e = sl_read_sexpr(sl.sp[-1], false); | |
| 1359 | 1359 | if(ios_eof(value2c(sl_ios*, sl.sp[-1]))) |
| 1360 | 1360 | break; |
| 1361 | 1361 | if(isfn(e)){ |
| @@ -1,3 +1,4 @@ | ||
| 1 | + | |
| 1 | 2 | ; StreetLISP standard library |
| 2 | 3 | ; by Jeff Bezanson (C) 2009 |
| 3 | 4 | ; Distributed under the BSD License |
| @@ -1342,15 +1343,20 @@ · 1338 unmodified lines | ||
| 1342 | 1343 | (raise `(load-error ,filename ,e)))))) |
| 1343 | 1344 | |
| 1344 | 1345 | (def (repl) |
| 1346 | + (*prompt*) | |
| 1347 | + (io-flush *io-out*) | |
| 1345 | 1348 | (def (prompt) |
| 1346 | − (*prompt*) | |
| 1347 | − (io-flush *io-out*) | |
| 1348 | − (let ((v (trycatch (read) | |
| 1349 | + (let ((v (trycatch (read *io-in* T) | |
| 1349 | 1350 | (λ (e) (io-discardbuffer *io-in*) |
| 1350 | 1351 | (raise e))))) |
| 1351 | 1352 | (and (not (io-eof? *io-in*)) |
| 1352 | 1353 | (let ((V (load-process v))) |
| 1353 | − (unless (void? V) (print V) (newline)) | |
| 1354 | + (if (void? V) | |
| 1355 | + (when (void? v) | |
| 1356 | + (*prompt*) | |
| 1357 | + (io-flush *io-out*)) | |
| 1358 | + (begin (print V) | |
| 1359 | + (newline))) | |
| 1354 | 1360 | (void (set! that V)))))) |
| 1355 | 1361 | (def (reploop) |
| 1356 | 1362 | (when (trycatch (prompt) |