fix path_dir, allow REPL to load relative files
This commit is contained in:
parent
87138ee523
commit
721017f6c0
@ -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
|
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;
|
BS2B pgetU = TI(path).getU;
|
||||||
usz pia = a(path)->ia;
|
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 = 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))=='/') {
|
if (o2cu(pgetU(path, i))=='/') {
|
||||||
B r = TI(path).slice(path, 0);
|
B r = TI(path).slice(path, 0);
|
||||||
arr_shVec(r, i+1);
|
arr_shVec(r, i+1);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ B bqn_fmt(B x) { // consumes
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void load_gcFn() { mm_visit(comp_currPath); }
|
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;
|
comp_currPath = path;
|
||||||
Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str);
|
Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str);
|
||||||
dec(path);
|
dec(path);
|
||||||
|
|||||||
@ -88,12 +88,13 @@ int main(int argc, char* argv[]) {
|
|||||||
vm_pst(envCurr, envStart+envPrevHeight);
|
vm_pst(envCurr, envStart+envPrevHeight);
|
||||||
dec(catchMessage);
|
dec(catchMessage);
|
||||||
}
|
}
|
||||||
|
B replPath = m_str32(U"REPL"); gc_add(replPath);
|
||||||
while (true) { // exit by evaluating an empty expression
|
while (true) { // exit by evaluating an empty expression
|
||||||
char* ln = NULL;
|
char* ln = NULL;
|
||||||
size_t gl = 0;
|
size_t gl = 0;
|
||||||
getline(&ln, &gl, stdin);
|
getline(&ln, &gl, stdin);
|
||||||
if (ln[0]==0 || ln[0]==10) break;
|
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);
|
free(ln);
|
||||||
|
|
||||||
#ifdef TIME
|
#ifdef TIME
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user