execute argument file
This commit is contained in:
parent
77531e2d8f
commit
ca090efd07
@ -153,4 +153,8 @@ static inline void load_init() {
|
||||
#endif
|
||||
gc_enable();
|
||||
#endif // NO_COMP
|
||||
}
|
||||
|
||||
B bqn_execFile(B path) {
|
||||
return bqn_exec(file_chars(path));
|
||||
}
|
||||
85
src/main.c
85
src/main.c
@ -50,7 +50,7 @@
|
||||
#include "rtPerf.c"
|
||||
#include "load.c"
|
||||
|
||||
int main() {
|
||||
int main(int argc, char* argv[]) {
|
||||
cbqn_init();
|
||||
|
||||
// expects a copy of mlochbaum/BQN/src/c.bqn to be at the execution directory (with •args replaced with the array in glyphs.bqn)
|
||||
@ -81,48 +81,51 @@ int main() {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
while (CATCH) {
|
||||
printf("Error: "); print(catchMessage); putchar('\n');
|
||||
vm_pst(envCurr, envStart+envPrevHeight);
|
||||
dec(catchMessage);
|
||||
}
|
||||
while (true) { // exit by evaluating an empty expression
|
||||
char* ln = NULL;
|
||||
size_t gl = 0;
|
||||
getline(&ln, &gl, stdin);
|
||||
if (ln[0]==0 || ln[0]==10) break;
|
||||
Block* block = bqn_comp(fromUTF8(ln, strlen(ln)));
|
||||
free(ln);
|
||||
|
||||
#ifdef TIME
|
||||
u64 sns = nsTime();
|
||||
B res = m_funBlock(block, 0);
|
||||
u64 ens = nsTime();
|
||||
printf("%fms\n", (ens-sns)/1e6);
|
||||
#else
|
||||
B res = m_funBlock(block, 0);
|
||||
#endif
|
||||
ptr_dec(block);
|
||||
|
||||
#ifdef FORMATTER
|
||||
B resFmt = bqn_fmt(res);
|
||||
printRaw(resFmt); dec(resFmt);
|
||||
printf("\n");
|
||||
#else
|
||||
print(res); putchar('\n'); fflush(stdout);
|
||||
dec(res);
|
||||
#endif
|
||||
|
||||
#ifdef HEAP_VERIFY
|
||||
heapVerify();
|
||||
#endif
|
||||
gc_maybeGC();
|
||||
#ifdef DEBUG
|
||||
#endif
|
||||
if (argc==1) {
|
||||
while (CATCH) {
|
||||
printf("Error: "); print(catchMessage); putchar('\n');
|
||||
vm_pst(envCurr, envStart+envPrevHeight);
|
||||
dec(catchMessage);
|
||||
}
|
||||
while (true) { // exit by evaluating an empty expression
|
||||
char* ln = NULL;
|
||||
size_t gl = 0;
|
||||
getline(&ln, &gl, stdin);
|
||||
if (ln[0]==0 || ln[0]==10) break;
|
||||
Block* block = bqn_comp(fromUTF8(ln, strlen(ln)));
|
||||
free(ln);
|
||||
|
||||
#ifdef TIME
|
||||
u64 sns = nsTime();
|
||||
B res = m_funBlock(block, 0);
|
||||
u64 ens = nsTime();
|
||||
printf("%fms\n", (ens-sns)/1e6);
|
||||
#else
|
||||
B res = m_funBlock(block, 0);
|
||||
#endif
|
||||
ptr_dec(block);
|
||||
|
||||
#ifdef FORMATTER
|
||||
B resFmt = bqn_fmt(res);
|
||||
printRaw(resFmt); dec(resFmt);
|
||||
printf("\n");
|
||||
#else
|
||||
print(res); putchar('\n'); fflush(stdout);
|
||||
dec(res);
|
||||
#endif
|
||||
|
||||
#ifdef HEAP_VERIFY
|
||||
heapVerify();
|
||||
#endif
|
||||
gc_maybeGC();
|
||||
#ifdef DEBUG
|
||||
#endif
|
||||
}
|
||||
popCatch();
|
||||
} else {
|
||||
bqn_execFile(m_str8(strlen(argv[1]), argv[1]));
|
||||
}
|
||||
rtPerf_print();
|
||||
popCatch();
|
||||
CTR_FOR(CTR_PRINT)
|
||||
// printf("done\n");fflush(stdout); while(1);
|
||||
printAllocStats();
|
||||
|
||||
13
src/sysfn.c
13
src/sysfn.c
@ -151,7 +151,7 @@ typedef struct TmpFile { // to be turned into a proper I8Arr
|
||||
i8 a[];
|
||||
} TmpFile;
|
||||
|
||||
TmpFile* readFile(B path) { // consumes
|
||||
TmpFile* file_bytes(B path) { // consumes; may throw
|
||||
u64 plen = utf8lenB(path);
|
||||
char p[plen+1];
|
||||
toUTF8(path, p);
|
||||
@ -168,15 +168,18 @@ TmpFile* readFile(B path) { // consumes
|
||||
dec(path);
|
||||
return src;
|
||||
}
|
||||
|
||||
B fchars_c1(B t, B x) {
|
||||
TmpFile* c = readFile(x);
|
||||
B file_chars(B path) { // consumes; may throw
|
||||
TmpFile* c = file_bytes(path);
|
||||
B r = fromUTF8((char*)c->a, c->ia);
|
||||
ptr_dec(c);
|
||||
return r;
|
||||
}
|
||||
|
||||
B fchars_c1(B t, B x) {
|
||||
return file_chars(x);
|
||||
}
|
||||
B fbytes_c1(B t, B x) {
|
||||
TmpFile* f = readFile(x); usz ia = f->ia; u8* p = (u8*)f->a;
|
||||
TmpFile* f = file_bytes(x); usz ia = f->ia; u8* p = (u8*)f->a;
|
||||
u32* rp; B r = m_c32arrv(&rp, ia);
|
||||
for (i64 i = 0; i < ia; i++) rp[i] = p[i];
|
||||
ptr_dec(f);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user