diff --git a/src/file.c b/src/file.c index d0a60bd6..45738b67 100644 --- a/src/file.c +++ b/src/file.c @@ -49,10 +49,13 @@ B path_resolve(B base, B rel) { // consumes rel; may error; assumes base is a ch } B path_dir(B path) { // consumes; returns directory part of file path, with trailing slash; may error + assert(isArr(path) || isNothing(path)); + if (isNothing(path)) return path; BS2B pgetU = TI(path).getU; usz pia = a(path)->ia; + if (pia==0) thrM("Empty file path"); for (usz i = 0; i < pia; i++) if (!isC32(pgetU(path, i))) thrM("Paths must be character vectors"); - for (usz i = pia-1; i >= 0; i--) { + for (i64 i = (i64)pia-1; i >= 0; i--) { if (o2cu(pgetU(path, i))=='/') { B r = TI(path).slice(path, 0); arr_shVec(r, i+1); diff --git a/src/load.c b/src/load.c index d1bc90c5..0d032dff 100644 --- a/src/load.c +++ b/src/load.c @@ -24,7 +24,7 @@ B bqn_fmt(B x) { // consumes #endif void load_gcFn() { mm_visit(comp_currPath); } -Block* bqn_comp(B str, B path) { // consumes +Block* bqn_comp(B str, B path) { // consumes both comp_currPath = path; Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str); dec(path); diff --git a/src/main.c b/src/main.c index 4f635afa..055b7a99 100644 --- a/src/main.c +++ b/src/main.c @@ -88,12 +88,13 @@ int main(int argc, char* argv[]) { vm_pst(envCurr, envStart+envPrevHeight); dec(catchMessage); } + B replPath = m_str32(U"REPL"); gc_add(replPath); 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)), bi_N); + Block* block = bqn_comp(fromUTF8(ln, strlen(ln)), replPath); free(ln); #ifdef TIME