•internal namespace
This commit is contained in:
parent
a2d90a2595
commit
038b27072f
@ -38,7 +38,7 @@ utils: utf.o hash.o file.o
|
|||||||
@echo $< | cut -c 11-
|
@echo $< | cut -c 11-
|
||||||
@$(CMD) $@.d -c $<
|
@$(CMD) $@.d -c $<
|
||||||
|
|
||||||
builtins: arithm.o arithd.o cmp.o sfns.o sort.o md1.o md2.o fns.o sysfn.o
|
builtins: arithm.o arithd.o cmp.o sfns.o sort.o md1.o md2.o fns.o sysfn.o internal.o
|
||||||
%.o: ../../src/builtins/%.c
|
%.o: ../../src/builtins/%.c
|
||||||
@echo $< | cut -c 11-
|
@echo $< | cut -c 11-
|
||||||
@$(CMD) $@.d -c $<
|
@$(CMD) $@.d -c $<
|
||||||
|
|||||||
64
src/builtins/internal.c
Normal file
64
src/builtins/internal.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "../core.h"
|
||||||
|
#include "../utils/mut.h"
|
||||||
|
|
||||||
|
B itype_c1(B t, B x) {
|
||||||
|
B r;
|
||||||
|
if(isVal(x)) {
|
||||||
|
r = m_str8l(format_type(v(x)->type));
|
||||||
|
} else {
|
||||||
|
if (isF64(x)) r = m_str32(U"tagged f64");
|
||||||
|
else if (isI32(x)) r = m_str32(U"tagged i32");
|
||||||
|
else if (isC32(x)) r = m_str32(U"tagged c32");
|
||||||
|
else if (isTag(x)) r = m_str32(U"tagged tag");
|
||||||
|
else if (isVar(x)) r = m_str32(U"tagged var");
|
||||||
|
else if (isExt(x)) r = m_str32(U"tagged extvar");
|
||||||
|
else r = m_str32(U"tagged unknown");
|
||||||
|
}
|
||||||
|
dec(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
B refc_c1(B t, B x) {
|
||||||
|
B r = isVal(x)? m_i32(v(x)->refc) : m_str32(U"(not heap-allocated)");
|
||||||
|
dec(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
B squeeze_c1(B t, B x) {
|
||||||
|
return bqn_squeeze(x);
|
||||||
|
}
|
||||||
|
B isPure_c1(B t, B x) {
|
||||||
|
B r = m_f64(isPureFn(x));
|
||||||
|
dec(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
B info_c1(B t, B x) {
|
||||||
|
B s = inc(bi_emptyCVec);
|
||||||
|
AFMT("%xl: ", x.u);
|
||||||
|
if (isVal(x)) {
|
||||||
|
Value* xv = v(x);
|
||||||
|
AFMT("refc:%i ", xv->refc);
|
||||||
|
AFMT("mmInfo:%i ", xv->mmInfo);
|
||||||
|
AFMT("flags:%i ", xv->flags);
|
||||||
|
AFMT("extra:%i ", xv->extra);
|
||||||
|
AFMT("type:%i=%S ", xv->type, format_type(xv->type));
|
||||||
|
AFMT("alloc:%l", mm_size(xv));
|
||||||
|
dec(x);
|
||||||
|
} else {
|
||||||
|
A8("not heap-allocated");
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static B internalNS;
|
||||||
|
B getInternalNS() {
|
||||||
|
if (internalNS.u == 0) {
|
||||||
|
#define F(X) inc(bi_##X),
|
||||||
|
B fn = bqn_exec(m_str32(U"{ Type, Refc, Squeeze, IsPure, Info⟩⇐𝕩}"), inc(bi_emptyHVec), inc(bi_emptyHVec));
|
||||||
|
B arg = m_caB(7, (B[]){F(itype)F(refc)F(squeeze)F(isPure)F(info)});
|
||||||
|
#undef F
|
||||||
|
internalNS = c1(fn,arg);
|
||||||
|
gc_add(internalNS);
|
||||||
|
dec(fn);
|
||||||
|
}
|
||||||
|
return inc(internalNS);
|
||||||
|
}
|
||||||
@ -119,30 +119,6 @@ B asrt_c2(B t, B w, B x) {
|
|||||||
thr(w);
|
thr(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPureFn(B x);
|
|
||||||
B internal_c2(B t, B w, B x) {
|
|
||||||
B r;
|
|
||||||
i32 id = o2i(w);
|
|
||||||
if(id==0) {
|
|
||||||
if(isVal(x)) { char* c = format_type(v(x)->type); r = m_str8(strlen(c), c); }
|
|
||||||
else {
|
|
||||||
if (isF64(x)) r = m_str32(U"tagged f64");
|
|
||||||
else if (isI32(x)) r = m_str32(U"tagged i32");
|
|
||||||
else if (isC32(x)) r = m_str32(U"tagged c32");
|
|
||||||
else if (isTag(x)) r = m_str32(U"tagged tag");
|
|
||||||
else if (isVar(x)) r = m_str32(U"tagged var");
|
|
||||||
else if (isExt(x)) r = m_str32(U"tagged extvar");
|
|
||||||
else r = m_str32(U"tagged unknown");
|
|
||||||
}
|
|
||||||
} else if(id==1) { r = isVal(x)? m_i32(v(x)->mmInfo & 0x7f) : m_str32(U"(not heap-allocated)"); }
|
|
||||||
else if(id==2) { r = isVal(x)? m_i32(v(x)->refc) : m_str32(U"(not heap-allocated)"); }
|
|
||||||
else if(id==3) { printf("%p\n", (void*)x.u); r = inc(x); }
|
|
||||||
else if(id==4) { r = m_f64(isPureFn(x)); }
|
|
||||||
else if(id==5) { r = bqn_squeeze(inc(x)); }
|
|
||||||
else { dec(x); thrF("•Internal: 𝕨≡%i is invalid", id); }
|
|
||||||
dec(x);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
B sys_c1(B t, B x);
|
B sys_c1(B t, B x);
|
||||||
B out_c1(B t, B x) { printRaw(x); putchar('\n'); return x; }
|
B out_c1(B t, B x) { printRaw(x); putchar('\n'); return x; }
|
||||||
B show_c1(B t, B x) {
|
B show_c1(B t, B x) {
|
||||||
@ -195,6 +171,8 @@ static B makeRel(B md) { // doesn't consume
|
|||||||
return m1_d(inc(md), path_dir(inc(comp_currPath)));
|
return m1_d(inc(md), path_dir(inc(comp_currPath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
B getInternalNS();
|
||||||
|
|
||||||
B sys_c1(B t, B x) {
|
B sys_c1(B t, B x) {
|
||||||
assert(isArr(x));
|
assert(isArr(x));
|
||||||
usz i = 0;
|
usz i = 0;
|
||||||
@ -204,7 +182,7 @@ B sys_c1(B t, B x) {
|
|||||||
B c = xgetU(x,i);
|
B c = xgetU(x,i);
|
||||||
if (eqStr(c, U"out")) r.a[i] = inc(bi_out);
|
if (eqStr(c, U"out")) r.a[i] = inc(bi_out);
|
||||||
else if (eqStr(c, U"show")) r.a[i] = inc(bi_show);
|
else if (eqStr(c, U"show")) r.a[i] = inc(bi_show);
|
||||||
else if (eqStr(c, U"internal")) r.a[i] = inc(bi_internal);
|
else if (eqStr(c, U"internal")) r.a[i] = getInternalNS();
|
||||||
else if (eqStr(c, U"type")) r.a[i] = inc(bi_type);
|
else if (eqStr(c, U"type")) r.a[i] = inc(bi_type);
|
||||||
else if (eqStr(c, U"decompose")) r.a[i] = inc(bi_decp);
|
else if (eqStr(c, U"decompose")) r.a[i] = inc(bi_decp);
|
||||||
else if (eqStr(c, U"primind")) r.a[i] = inc(bi_primInd);
|
else if (eqStr(c, U"primind")) r.a[i] = inc(bi_primInd);
|
||||||
|
|||||||
17
src/h.h
17
src/h.h
@ -155,17 +155,18 @@ enum ElType { // a⌈b shall return the type that can store both, if possible; a
|
|||||||
char* format_type(u8 u);
|
char* format_type(u8 u);
|
||||||
|
|
||||||
#define FOR_PFN(A,M,D) \
|
#define FOR_PFN(A,M,D) \
|
||||||
/*arith.c*/ A(add,"+") A(sub,"-") A(mul,"×") A(div,"÷") A(pow,"⋆") A(floor,"⌊") A(ceil,"⌈") A(stile,"|") A(eq,"=") \
|
/* arith.c*/A(add,"+") A(sub,"-") A(mul,"×") A(div,"÷") A(pow,"⋆") A(floor,"⌊") A(ceil,"⌈") A(stile,"|") A(eq,"=") \
|
||||||
/*arith.c*/ A(ne,"≠") D(le,"≤") D(ge,"≥") A(lt,"<") A(gt,">") A(and,"∧") A(or,"∨") A(not,"¬") A(log,"⋆⁼") \
|
/* arith.c*/A(ne,"≠") D(le,"≤") D(ge,"≥") A(lt,"<") A(gt,">") A(and,"∧") A(or,"∨") A(not,"¬") A(log,"⋆⁼") \
|
||||||
/*fns.c*/ A(ud,"↕") A(fne,"≢") A(feq,"≡") A(ltack,"⊣") A(rtack,"⊢") M(fmtF,"•FmtF") A(indexOf,"⊐") A(memberOf,"∊") A(find,"⍷") A(count,"⊒") \
|
/* fns.c*/A(ud,"↕") A(fne,"≢") A(feq,"≡") A(ltack,"⊣") A(rtack,"⊢") M(fmtF,"•FmtF") A(indexOf,"⊐") A(memberOf,"∊") A(find,"⍷") A(count,"⊒") \
|
||||||
/*sfns.c*/ A(shape,"⥊") A(pick,"⊑") A(pair,"{𝕨‿𝕩}") A(select,"⊏") A(slash,"/") A(join,"∾") A(couple,"≍") A(shiftb,"»") A(shifta,"«") A(take,"↑") A(drop,"↓") A(group,"⊔") A(reverse,"⌽") \
|
/* sfns.c*/A(shape,"⥊") A(pick,"⊑") A(pair,"{𝕨‿𝕩}") A(select,"⊏") A(slash,"/") A(join,"∾") A(couple,"≍") A(shiftb,"»") A(shifta,"«") A(take,"↑") A(drop,"↓") A(group,"⊔") A(reverse,"⌽") \
|
||||||
/*sort.c*/ A(gradeUp,"⍋") A(gradeDown,"⍒") \
|
/* sort.c*/A(gradeUp,"⍋") A(gradeDown,"⍒") \
|
||||||
/*sysfn.c*/ M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") M(repr,"•Repr") A(fill,"•FillFn") \
|
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•groupOrd") \
|
||||||
/*sysfn.c*/ A(grLen,"•GroupLen") D(grOrd,"•groupOrd") A(asrt,"!") M(out,"•Out") M(show,"•Show") M(sys,"•getsys") M(bqn,"•BQN") D(cmp,"•Cmp") D(internal,"•Internal") A(hash,"•Hash") \
|
/* sysfn.c*/M(repr,"•Repr") A(asrt,"!") M(out,"•Out") M(show,"•Show") M(bqn,"•BQN") D(cmp,"•Cmp") A(hash,"•Hash") \
|
||||||
|
/*internal.c*/M(itype,"•internal.Type") M(refc,"•internal.Refc") M(squeeze,"•internal.Squeeze") M(isPure,"•internal.IsPure") M(info,"•internal.Info")
|
||||||
|
|
||||||
#define FOR_PM1(A,M,D) \
|
#define FOR_PM1(A,M,D) \
|
||||||
/*md1.c*/ A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") \
|
/*md1.c*/ A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") \
|
||||||
/*md1.c*/ A(timed,"•_timed") A(fchars,"•FChars") M(fbytes,"•FBytes") M(flines,"•FLines") A(import,"•Import")
|
/*md1.c*/ A(timed,"•_timed") A(fchars,"•FChars") M(fbytes,"•FBytes") M(flines,"•FLines") A(import,"•Import") \
|
||||||
|
|
||||||
#define FOR_PM2(A,M,D) \
|
#define FOR_PM2(A,M,D) \
|
||||||
/*md2.c*/ A(val,"⊘") A(repeat,"⍟") A(fillBy,"•_fillBy_") A(catch,"⎊") \
|
/*md2.c*/ A(val,"⊘") A(repeat,"⍟") A(fillBy,"•_fillBy_") A(catch,"⎊") \
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#include "../builtins/cmp.c"
|
#include "../builtins/cmp.c"
|
||||||
#include "../builtins/md1.c"
|
#include "../builtins/md1.c"
|
||||||
#include "../builtins/md2.c"
|
#include "../builtins/md2.c"
|
||||||
|
#include "../builtins/internal.c"
|
||||||
#include "../vm.c"
|
#include "../vm.c"
|
||||||
#include "../ns.c"
|
#include "../ns.c"
|
||||||
#include "../rtwrap.c"
|
#include "../rtwrap.c"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user