more proper PERF_TEST, )ex
This commit is contained in:
parent
c00834cf15
commit
1f5cfbe766
@ -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+1<ia && p[i+1]=='\n') i++;
|
||||
}
|
||||
}
|
||||
if (ia && (p[ia-1]!='\n' && p[ia-1]!='\r')) lineCount++;
|
||||
usz i = 0;
|
||||
HArr_p r = m_harrs(lineCount, &i);
|
||||
usz pos = 0;
|
||||
while (i < lineCount) {
|
||||
usz spos = pos;
|
||||
while(pos<ia && p[pos]!='\n' && p[pos]!='\r') pos++;
|
||||
r.a[i++] = fromUTF8((char*)p+spos, pos-spos);
|
||||
if (p[pos]=='\r' && pos+1<ia && p[pos+1]=='\n') pos+= 2;
|
||||
else pos++;
|
||||
}
|
||||
ptr_dec(tf);
|
||||
return harr_fv(r);
|
||||
return file_lines(path_resolve(nfn_objU(d), x));
|
||||
}
|
||||
static NFnDesc* importDesc;
|
||||
B import_c1(B d, B x) { return bqn_execFile(path_resolve(nfn_objU(d), x), emptySVec()); }
|
||||
|
||||
39
src/main.c
39
src/main.c
@ -1,6 +1,7 @@
|
||||
#include "core.h"
|
||||
#include "vm.h"
|
||||
#include "utils/utf.h"
|
||||
#include "utils/file.h"
|
||||
|
||||
static B replPath;
|
||||
static Scope* gsc;
|
||||
@ -55,9 +56,6 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
bool startREPL = argc==1;
|
||||
bool silentREPL = false;
|
||||
#ifdef PERF_TEST
|
||||
silentREPL = true;
|
||||
#endif
|
||||
if (!startREPL) {
|
||||
i32 i = 1;
|
||||
while (i!=argc) {
|
||||
@ -117,6 +115,17 @@ int main(int argc, char* argv[]) {
|
||||
mm_heapMax = am*1024*1024;
|
||||
break;
|
||||
}
|
||||
#ifdef PERF_TEST
|
||||
case 'R': { repl_init(); REQARG(R);
|
||||
B path = fromUTF8l(argv[i++]);
|
||||
B lines = file_lines(path);
|
||||
usz ia = a(lines)->ia;
|
||||
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();
|
||||
|
||||
@ -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<ia && p[i+1]=='\n') i++;
|
||||
}
|
||||
}
|
||||
if (ia && (p[ia-1]!='\n' && p[ia-1]!='\r')) lineCount++;
|
||||
usz i = 0;
|
||||
HArr_p r = m_harrs(lineCount, &i);
|
||||
usz pos = 0;
|
||||
while (i < lineCount) {
|
||||
usz spos = pos;
|
||||
while(pos<ia && p[pos]!='\n' && p[pos]!='\r') pos++;
|
||||
r.a[i++] = fromUTF8((char*)p+spos, pos-spos);
|
||||
if (p[pos]=='\r' && pos+1<ia && p[pos+1]=='\n') pos+= 2;
|
||||
else pos++;
|
||||
}
|
||||
ptr_dec(tf);
|
||||
return harr_fv(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
B path_resolve(B base, B rel) { // consumes rel; assumes base is a char vector or bi_N
|
||||
assert((isArr(base) || isNothing(base)) && isArr(rel));
|
||||
|
||||
@ -12,6 +12,7 @@ B path_dir(B path); // consumes; returns directory part of file path, with trail
|
||||
FILE* file_open(B path, char* desc, char* mode); // doesn't consume path
|
||||
TmpFile* file_bytes(B path); // consumes
|
||||
B file_chars(B path); // consumes
|
||||
B file_lines(B path); // consumes
|
||||
|
||||
void file_wChars(B path, B x); // consumes path
|
||||
void file_wBytes(B path, B x); // consumes path
|
||||
|
||||
Loading…
Reference in New Issue
Block a user