support calling explain for an expression
This commit is contained in:
parent
1fd88c1749
commit
0314f55a78
3
cc.bqn
3
cc.bqn
@ -54,12 +54,13 @@ RT ← {
|
|||||||
CArg ← {J (¯5⊸↓∾𝕩˙)⌾⊑ FLines "c.bqn"}
|
CArg ← {J (¯5⊸↓∾𝕩˙)⌾⊑ FLines "c.bqn"}
|
||||||
SVG ← {∾⟨"Modify←GetHighlights←⊢⋄"⟩∾ FChars∘∾⟜".bqn"¨ "../svg"‿𝕩}
|
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"⊐⊏)◶⟨
|
||||||
RT∘2, RT∘0, RT∘1
|
RT∘2, RT∘0, RT∘1
|
||||||
{𝕩⋄LFC CArg "⟨"∾"⟩"«∾","⊸∾¨'"'(⊣∾∾˜)¨glyphs}
|
{𝕩⋄LFC CArg "⟨"∾"⟩"«∾","⊸∾¨'"'(⊣∾∾˜)¨glyphs}
|
||||||
{𝕩⋄LFC "{"∾"}"∾˜CArg"𝕩"}
|
{𝕩⋄LFC "{"∾"}"∾˜CArg"𝕩"}
|
||||||
{𝕩⋄LFC FChars "f.bqn"}
|
{𝕩⋄LFC FChars "f.bqn"}
|
||||||
{𝕩⋄LFC SVG "e"}
|
{𝕩⋄LFC SVG "e"}
|
||||||
|
{𝕩⋄LFC FChars "eu.bqn"}
|
||||||
{𝕩⋄LFC SVG "p"}
|
{𝕩⋄LFC SVG "p"}
|
||||||
∾LFC¨
|
∾LFC¨
|
||||||
# ¯1 ↓ · J L∘Fout∘Comp¨
|
# ¯1 ↓ · J L∘Fout∘Comp¨
|
||||||
|
|||||||
@ -9,4 +9,5 @@ CC ← {𝕨 •FChars ⟨1,path,𝕩⟩ •Import "cc.bqn"}
|
|||||||
"src/gen/runtime0"CC"r0"
|
"src/gen/runtime0"CC"r0"
|
||||||
"src/gen/runtime1"CC"r1"
|
"src/gen/runtime1"CC"r1"
|
||||||
"src/gen/formatter"CC"f"
|
"src/gen/formatter"CC"f"
|
||||||
|
"src/gen/explain"CC"eu"
|
||||||
"src/gen/customRuntime"•FChars""
|
"src/gen/customRuntime"•FChars""
|
||||||
|
|||||||
1
src/h.h
1
src/h.h
@ -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_exec(B str, B path, B args); // consumes all
|
||||||
B bqn_execFile(B path, B args); // consumes
|
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_fmt(B x); // consumes
|
||||||
B bqn_repr(B x); // consumes
|
B bqn_repr(B x); // consumes
|
||||||
|
|
||||||
|
|||||||
16
src/load.c
16
src/load.c
@ -130,6 +130,7 @@ B load_compgen;
|
|||||||
B load_rtObj;
|
B load_rtObj;
|
||||||
B load_compArg;
|
B load_compArg;
|
||||||
B load_glyphs;
|
B load_glyphs;
|
||||||
|
B load_explain;
|
||||||
|
|
||||||
#if FORMATTER
|
#if FORMATTER
|
||||||
B load_fmt, load_repr;
|
B load_fmt, load_repr;
|
||||||
@ -169,6 +170,15 @@ void load_gcFn() {
|
|||||||
i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart; \
|
i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart; \
|
||||||
if (CATCH) { POP_COMP; rethrow(); }
|
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
|
static NOINLINE Block* bqn_compc(B str, B path, B args, B comp, B compArg) { // consumes str,path,args
|
||||||
PUSH_COMP;
|
PUSH_COMP;
|
||||||
Block* r = load_compObj(c2(comp, incG(compArg), inc(str)), str, path, NULL);
|
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);
|
load_repr = Get(fmtR, 1); gc_add(load_repr);
|
||||||
decG(fmtR);
|
decG(fmtR);
|
||||||
#endif
|
#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();
|
gc_enable();
|
||||||
#endif // PRECOMP
|
#endif // PRECOMP
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main.c
10
src/main.c
@ -179,6 +179,16 @@ void cbqn_runLine0(char* ln, i64 read) {
|
|||||||
} else if (isCmd(cmdS, &cmdE, "internalPrint ")) {
|
} else if (isCmd(cmdS, &cmdE, "internalPrint ")) {
|
||||||
code = utf8Decode0(cmdE);
|
code = utf8Decode0(cmdE);
|
||||||
output = 2;
|
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 {
|
} else {
|
||||||
printf("Unknown REPL command\n");
|
printf("Unknown REPL command\n");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user