execute argument file

This commit is contained in:
dzaima 2021-05-15 12:39:12 +03:00
parent 77531e2d8f
commit ca090efd07
3 changed files with 56 additions and 46 deletions

View File

@ -154,3 +154,7 @@ static inline void load_init() {
gc_enable();
#endif // NO_COMP
}
B bqn_execFile(B path) {
return bqn_exec(file_chars(path));
}

View File

@ -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,7 +81,7 @@ int main() {
}
#endif
if (argc==1) {
while (CATCH) {
printf("Error: "); print(catchMessage); putchar('\n');
vm_pst(envCurr, envStart+envPrevHeight);
@ -121,8 +121,11 @@ int main() {
#ifdef DEBUG
#endif
}
rtPerf_print();
popCatch();
} else {
bqn_execFile(m_str8(strlen(argv[1]), argv[1]));
}
rtPerf_print();
CTR_FOR(CTR_PRINT)
// printf("done\n");fflush(stdout); while(1);
printAllocStats();

View File

@ -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);