diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index ef2d4020..39978dc2 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -407,29 +407,7 @@ B fbytes_c1(B d, B x) { } static NFnDesc* fLinesDesc; B flines_c1(B d, B x) { - TmpFile* tf = file_bytes(path_resolve(nfn_objU(d), x)); - usz ia = tf->ia; u8* p = (u8*)tf->a; - usz lineCount = 0; - for (usz i = 0; i < ia; i++) { - if (p[i]=='\n') lineCount++; - else if (p[i]=='\r') { - lineCount++; - if(i+1ia; + BS2B lget = TI(lines,get); + for (u64 i = 0; i < ia; i++) { + dec(gsc_exec_inline(lget(lines, i), inc(replPath), emptySVec())); + } + } + #endif case 'r': { startREPL = true; break; } case 's': { startREPL = true; silentREPL = true; break; } } @@ -158,7 +167,23 @@ int main(int argc, char* argv[]) { if (!silentREPL) printf(" "); i64 read = getline(&ln, &gl, stdin); if (read<=0 || ln[0]==0 || ln[0]==10) { if(!silentREPL) putchar('\n'); break; } - Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), emptySVec(), gsc, true); + B code; + bool output; + if (ln[0] == ')') { + if (ln[1]=='e'&ln[2]=='x'&ln[3]==' ') { + B path = fromUTF8(ln+4, strlen(ln+4)-1); + code = file_chars(path); + output = false; + } else { + printf("Unknown REPL command\n"); + free(ln); + continue; + } + } else { + code = fromUTF8(ln, strlen(ln)); + output = true; + } + Block* block = bqn_compSc(code, inc(replPath), emptySVec(), gsc, true); free(ln); ptr_dec(gsc->body); ptr_inc(block->bodies[0]); @@ -174,7 +199,7 @@ int main(int argc, char* argv[]) { #endif ptr_dec(block); - #ifndef PERF_TEST + if (output) { #if FORMATTER B resFmt = bqn_fmt(res); printRaw(resFmt); dec(resFmt); @@ -183,9 +208,7 @@ int main(int argc, char* argv[]) { print(res); putchar('\n'); fflush(stdout); dec(res); #endif - #else - dec(res); - #endif + } else dec(res); #ifdef HEAP_VERIFY heapVerify(); diff --git a/src/utils/file.c b/src/utils/file.c index 9ee6dd1c..a9f199c5 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -43,6 +43,33 @@ B file_chars(B path) { // consumes ptr_dec(c); return r; } +B file_lines(B path) { // consumes + TmpFile* tf = file_bytes(path); + usz ia = tf->ia; u8* p = (u8*)tf->a; + usz lineCount = 0; + for (usz i = 0; i < ia; i++) { + if (p[i]=='\n') lineCount++; + else if (p[i]=='\r') { + lineCount++; + if(i+1