basic namespace formatting

This commit is contained in:
dzaima 2021-08-04 22:02:21 +03:00
parent 2710786bf0
commit 65fe3d9aa2
2 changed files with 22 additions and 0 deletions

View File

@ -85,6 +85,7 @@ B ltack_c2(B t, B w, B x) { dec(x); return w; }
B rtack_c1(B t, B x) { return x; }
B rtack_c2(B t, B w, B x) { dec(w); return x; }
B nsFmt(B x);
#ifdef RT_WRAP
B rtWrap_unwrap(B x);
#endif
@ -103,6 +104,7 @@ B fmtF_c1(B t, B x) {
if (ty==t_fun_block) { dec(x); return m_str8l("(function block)"); }
if (ty==t_md1_block) { dec(x); return m_str8l("(1-modifier block)"); }
if (ty==t_md2_block) { dec(x); return m_str8l("(2-modifier block)"); }
if (ty==t_ns) return nsFmt(x);
return m_str32(U"(fmtF: not given a runtime primitive)");
}
dec(x);

View File

@ -1,5 +1,6 @@
#include "core.h"
#include "ns.h"
#include "utils/mut.h"
void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported) { // consumes nameList
if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information");
@ -133,6 +134,25 @@ static void ns_print(B x) {
}
putchar('}');
}
B nsFmt(B x) { // consumes
B s = emptyCVec();
ACHR('{');
NSDesc* desc = c(NS,x)->desc;
i32 am = desc->varAm;
BS2B getNameU = TI(desc->nameList,getU);
bool first = true;
for (i32 i = 0; i < am; i++) {
i32 id = desc->expIDs[i];
if (id>=0) {
if (first) first=false;
else ACHR(U'');
AFMT("%R", getNameU(desc->nameList, id));
}
}
AU("⇐}");
dec(x);
return s;
}
DEF_FREE(nsDesc) { decR(((NSDesc*)x)->nameList); }
static void nsDesc_visit(Value* x) { mm_visit(((NSDesc*)x)->nameList); }