support calling explain for an expression

This commit is contained in:
Antti Keränen 2022-06-16 12:06:46 +03:00
parent 1fd88c1749
commit 0314f55a78
5 changed files with 30 additions and 1 deletions

3
cc.bqn
View File

@ -54,12 +54,13 @@ RT ← {
CArg {J (¯5𝕩˙) FLines "c.bqn"}
SVG {"Modify←GetHighlights←⊢⋄" FChars".bqn"¨ "../svg"𝕩}
(@+10)˜ •Out(¬return) ("r""r0""r1""c""cc""f""e""p")
(@+10)˜ •Out(¬return) ("r""r0""r1""c""cc""f""e""eu""p")
RT2, RT0, RT1
{𝕩LFC CArg "⟨""⟩"«","¨'"'(˜)¨glyphs}
{𝕩LFC "{""}"˜CArg"𝕩"}
{𝕩LFC FChars "f.bqn"}
{𝕩LFC SVG "e"}
{𝕩LFC FChars "eu.bqn"}
{𝕩LFC SVG "p"}
LFC¨
# ¯1 ↓ · J L∘Fout∘Comp¨

View File

@ -9,4 +9,5 @@ CC ← {𝕨 •FChars ⟨1,path,𝕩⟩ •Import "cc.bqn"}
"src/gen/runtime0"CC"r0"
"src/gen/runtime1"CC"r1"
"src/gen/formatter"CC"f"
"src/gen/explain"CC"eu"
"src/gen/customRuntime"•FChars""

View File

@ -346,6 +346,7 @@ B m_str32(u32* s); // meant to be used as m_str32(U"{𝕨‿𝕩}"), so doesn't
B bqn_exec(B str, B path, B args); // consumes all
B bqn_execFile(B path, B args); // consumes
B bqn_explain(B str, B path); // consumes str
B bqn_fmt(B x); // consumes
B bqn_repr(B x); // consumes

View File

@ -130,6 +130,7 @@ B load_compgen;
B load_rtObj;
B load_compArg;
B load_glyphs;
B load_explain;
#if FORMATTER
B load_fmt, load_repr;
@ -169,6 +170,15 @@ void load_gcFn() {
i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart; \
if (CATCH) { POP_COMP; rethrow(); }
B bqn_explain(B str, B path) {
B args = bi_N;
PUSH_COMP;
B c = c2(load_comp, incG(load_compArg), inc(str));
POP_COMP;
B ret = c2(load_explain, c, str);
return ret;
}
static NOINLINE Block* bqn_compc(B str, B path, B args, B comp, B compArg) { // consumes str,path,args
PUSH_COMP;
Block* r = load_compObj(c2(comp, incG(compArg), inc(str)), str, path, NULL);
@ -479,6 +489,12 @@ void load_init() { // very last init function
load_repr = Get(fmtR, 1); gc_add(load_repr);
decG(fmtR);
#endif
Block* expl_b = load_compImport("(explain)",
#include "gen/explain"
);
load_explain = evalFunBlock(expl_b, 0); ptr_dec(expl_b);
gc_add(load_explain);
gc_enable();
#endif // PRECOMP
}

View File

@ -179,6 +179,16 @@ void cbqn_runLine0(char* ln, i64 read) {
} else if (isCmd(cmdS, &cmdE, "internalPrint ")) {
code = utf8Decode0(cmdE);
output = 2;
} else if (isCmd(cmdS, &cmdE, "e ") || isCmd(cmdS, &cmdE, "explain ")) {
B expl = bqn_explain(utf8Decode0(cmdE), inc(replPath));
HArr* expla = toHArr(expl);
usz ia=expla->ia;
for(usz i=0; i<ia; i++) {
printRaw(expla->a[i]);
putchar('\n');
}
dec(expl);
return;
} else {
printf("Unknown REPL command\n");
return;