native «
This commit is contained in:
parent
494c13f3d8
commit
14e12ea544
@ -42,6 +42,14 @@ B getFill(B x) { // consumes; can return bi_noFill
|
||||
dec(x);
|
||||
return defZero? m_f64(0) : bi_noFill;
|
||||
}
|
||||
B getFillE(B x) { // errors if there's no fill
|
||||
B xf = getFill(x);
|
||||
if (noFill(xf)) {
|
||||
if (PROPER_FILLS) thrM("No fill found");
|
||||
else return m_f64(0);
|
||||
}
|
||||
return xf;
|
||||
}
|
||||
bool noFill(B x) { return x.u == bi_noFill.u; }
|
||||
|
||||
typedef struct FillSlice {
|
||||
@ -147,11 +155,31 @@ B withFill(B x, B fill) { // consumes both
|
||||
}
|
||||
break;
|
||||
}
|
||||
B r = m_arr(fsizeof(FillArr,a,B,a(x)->ia), t_fillarr);
|
||||
usz ia = a(x)->ia;
|
||||
// if (isNum(fill)) {
|
||||
// B r = m_f64arrc(x); f64* rp = f64arr_ptr(r);
|
||||
// BS2B xgetU = TI(x).getU;
|
||||
// for (usz i = 0; i < ia; i++) {
|
||||
// B c = xgetU(x, i);
|
||||
// if (!q_f64(c)) { dec(r); goto base; }
|
||||
// rp[i] = o2f(c);
|
||||
// }
|
||||
// return r;
|
||||
// } else if (isC32(fill)) {
|
||||
// B r = m_c32arrc(x); u32* rp = c32arr_ptr(r);
|
||||
// BS2B xgetU = TI(x).getU;
|
||||
// for (usz i = 0; i < ia; i++) {
|
||||
// B c = xgetU(x, i);
|
||||
// if (!isC32(c)) { dec(r); goto base; }
|
||||
// rp[i] = o2c(c);
|
||||
// }
|
||||
// return r;
|
||||
// }
|
||||
// base:
|
||||
B r = m_arr(fsizeof(FillArr,a,B,ia), t_fillarr);
|
||||
arr_shCopy(r, x);
|
||||
c(FillArr,r)->fill = fill;
|
||||
B* a = c(FillArr,r)->a;
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xget = TI(x).get;
|
||||
for (usz i = 0; i < ia; i++) a[i] = xget(x,i);
|
||||
dec(x);
|
||||
|
||||
6
src/h.h
6
src/h.h
@ -90,8 +90,8 @@ char* format_type(u8 u) {
|
||||
case t_md2BI:return"md2_def"; case t_md2_block:return"md2_block";
|
||||
case t_fork:return"fork"; case t_atop:return"atop";
|
||||
case t_md1D:return"md1D"; case t_md2D:return"md2D"; case t_md2H:return"md2H";
|
||||
case t_harr :return"harr" ; case t_i32arr :return"i32arr" ; case t_fillarr :return"fillarr" ; case t_c32arr :return"c32arr" ;
|
||||
case t_hslice:return"hslice"; case t_i32slice:return"i32slice"; case t_fillslice:return"fillslice"; case t_c32slice:return"c32slice";
|
||||
case t_harr :return"harr" ; case t_i32arr :return"i32arr" ; case t_fillarr :return"fillarr" ; case t_c32arr :return"c32arr" ; case t_f64arr :return"f64arr" ;
|
||||
case t_hslice:return"hslice"; case t_i32slice:return"i32slice"; case t_fillslice:return"fillslice"; case t_c32slice:return"c32slice"; case t_f64slice:return"f64slice";
|
||||
case t_comp:return"comp"; case t_block:return"block"; case t_body:return"body"; case t_scope:return"scope";
|
||||
case t_freed:return"(freed by GC)";
|
||||
}
|
||||
@ -101,7 +101,7 @@ char* format_type(u8 u) {
|
||||
/*arith.c*/ F(add,"+") F(sub,"-") F(mul,"×") F(div,"÷") F(pow,"⋆") F(floor,"⌊") F(ceil,"⌈") F(stile,"|") F(eq,"=") \
|
||||
/*arith.c*/ F(ne,"≠") F(le,"≤") F(ge,"≥") F(lt,"<") F(gt,">") F(and,"∧") F(or,"∨") F(not,"¬") F(log,"⋆⁼") \
|
||||
/*fns.c*/ F(ud,"↕") F(fne,"≢") F(feq,"≡") F(ltack,"⊣") F(rtack,"⊢") F(fmtF,"•FmtF") F(fmtN,"•FmtN") \
|
||||
/*sfns.c*/ F(shape,"⥊") F(pick,"⊑") F(pair,"{𝕨‿𝕩}") F(select,"⊏") F(slash,"/") F(join,"∾") F(shiftb,"»") F(take,"↑") F(drop,"↓") \
|
||||
/*sfns.c*/ F(shape,"⥊") F(pick,"⊑") F(pair,"{𝕨‿𝕩}") F(select,"⊏") F(slash,"/") F(join,"∾") F(shiftb,"»") F(shifta,"«") F(take,"↑") F(drop,"↓") \
|
||||
/*derv.c*/ F(fork,"(fork)") F(atop,"(atop)") F(md1d,"(derived 1-modifier)") F(md2d,"(derived 2-modifier)") \
|
||||
/*sysfn.c*/ F(type,"•Type") F(decp,"•Decompose") F(primInd,"•PrimInd") F(glyph,"•Glyph") F(fill,"•FillFn") \
|
||||
/*sysfn.c*/ F(grLen,"•GroupLen") F(grOrd,"•groupOrd") F(asrt,"!") F(sys,"•getsys") F(internal,"•Internal") F(show,"•Show") F(out,"•Out")
|
||||
|
||||
@ -34,10 +34,10 @@
|
||||
#include "heap.c"
|
||||
#include "mm_buddy.c"
|
||||
#include "harr.c"
|
||||
#include "fillarr.c"
|
||||
#include "i32arr.c"
|
||||
#include "c32arr.c"
|
||||
#include "f64arr.c"
|
||||
#include "fillarr.c"
|
||||
#include "mut.c"
|
||||
#include "utf.c"
|
||||
#include "derv.c"
|
||||
@ -114,7 +114,7 @@ int main() {
|
||||
B fruntime[] = {
|
||||
/* +-×÷⋆√⌊⌈|¬ */ bi_add , bi_sub , bi_mul , bi_div , bi_pow , bi_N , bi_floor, bi_ceil, bi_stile , bi_not,
|
||||
/* ∧∨<>≠=≤≥≡≢ */ bi_and , bi_or , bi_lt , bi_gt , bi_ne , bi_eq , bi_le , bi_ge , bi_feq , bi_fne,
|
||||
/* ⊣⊢⥊∾≍↑↓↕«» */ bi_ltack, bi_rtack , bi_shape, bi_join , bi_N , bi_take , bi_drop , bi_ud , bi_N , bi_shiftb,
|
||||
/* ⊣⊢⥊∾≍↑↓↕«» */ bi_ltack, bi_rtack , bi_shape, bi_join , bi_N , bi_take , bi_drop , bi_ud , bi_shifta, bi_shiftb,
|
||||
/* ⌽⍉/⍋⍒⊏⊑⊐⊒∊ */ bi_N , bi_N , bi_slash, bi_N , bi_N , bi_select, bi_pick , bi_N , bi_N , bi_N,
|
||||
/* ⍷⊔!˙˜˘¨⌜⁼´ */ bi_N , bi_N , bi_asrt , bi_const, bi_swap , bi_N , bi_each , bi_tbl , bi_N , bi_fold,
|
||||
/* ˝`∘○⊸⟜⌾⊘◶⎉ */ bi_N , bi_scan , bi_atop , bi_over , bi_before, bi_after , bi_N , bi_val , bi_cond , bi_N,
|
||||
@ -123,7 +123,7 @@ int main() {
|
||||
bool rtComplete[] = {
|
||||
/* +-×÷⋆√⌊⌈|¬ */ 1,1,1,1,1,0,1,1,1,1,
|
||||
/* ∧∨<>≠=≤≥≡≢ */ 1,1,1,1,1,1,1,1,1,1,
|
||||
/* ⊣⊢⥊∾≍↑↓↕«» */ 1,1,0,1,0,0,0,0,0,1,
|
||||
/* ⊣⊢⥊∾≍↑↓↕«» */ 1,1,0,1,0,0,0,0,1,1,
|
||||
/* ⌽⍉/⍋⍒⊏⊑⊐⊒∊ */ 0,0,1,0,0,1,0,0,0,0,
|
||||
/* ⍷⊔!˙˜˘¨⌜⁼´ */ 0,0,1,1,1,0,1,1,0,1,
|
||||
/* ˝`∘○⊸⟜⌾⊘◶⎉ */ 0,1,1,1,1,1,0,1,0,0,
|
||||
|
||||
@ -25,7 +25,7 @@ static NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbag
|
||||
}
|
||||
if (cb >= 20) {
|
||||
u64 sz = BSZ(cb);
|
||||
gc_maybeGC();
|
||||
// gc_maybeGC();
|
||||
c = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_NORESERVE|MAP_PRIVATE|MAP_ANON, -1, 0);
|
||||
if (alSize+1>=alCap) {
|
||||
alCap = alCap? alCap*2 : 1024;
|
||||
@ -48,7 +48,7 @@ static NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbag
|
||||
EmptyValue* b = (EmptyValue*) (BSZ(cb) + (u8*)c);
|
||||
b->type = t_empty;
|
||||
b->mmInfo = MMI(cb);
|
||||
b->next = 0; assert(buckets[cb]==0);
|
||||
b->next = buckets[cb];
|
||||
buckets[cb] = b;
|
||||
}
|
||||
return c;
|
||||
|
||||
74
src/sfns.c
74
src/sfns.c
@ -389,36 +389,34 @@ B join_c2(B t, B w, B x) {
|
||||
return qWithFill(rb, f);
|
||||
}
|
||||
|
||||
B shiftb_c1(B t, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar");
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
B xf = getFill(inc(x));
|
||||
if (noFill(xf)) {
|
||||
if (PROPER_FILLS) thrM("»: Argument didn't have a fill");
|
||||
else xf = m_f64(0);
|
||||
}
|
||||
usz csz = arr_csz(x);
|
||||
|
||||
MAKE_MUT(r, ia);
|
||||
mut_copy(r, csz, x, 0, ia-csz);
|
||||
mut_fill(r, 0, xf, csz);
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
|
||||
void shift_check(B w, B x) {
|
||||
static void shift_check(B w, B x) {
|
||||
ur wr = rnk(w); usz* wsh = a(w)->sh;
|
||||
ur xr = rnk(x); usz* xsh = a(x)->sh;
|
||||
if (wr+1!=xr & wr!=xr) thrM("shift: =𝕨 must be =𝕩 or ¯1+=𝕩");
|
||||
for (i32 i = 1; i < xr; i++) if (wsh[i+wr-xr] != xsh[i]) thrM("shift: Lengths not matchable");
|
||||
}
|
||||
|
||||
B shiftb_c1(B t, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar");
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(inc(x));
|
||||
usz csz = arr_csz(x);
|
||||
|
||||
MAKE_MUT(r, ia); mut_to(r, TI(x).elType);
|
||||
mut_copy(r, csz, x, 0, ia-csz);
|
||||
mut_fill(r, 0, xf, csz);
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
B shiftb_c2(B t, B w, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM("»: 𝕩 cannot be a scalar");
|
||||
if (!isArr(w)) w = m_hunit(w); usz wia = a(w)->ia;
|
||||
if (!isArr(x)) x = m_hunit(x); usz xia = a(x)->ia;
|
||||
B f = fill_both(w, x);
|
||||
if (!isArr(w)) w = m_hunit(w);
|
||||
shift_check(w, x);
|
||||
MAKE_MUT(r, xia);
|
||||
B f = fill_both(w, x);
|
||||
usz wia = a(w)->ia;
|
||||
usz xia = a(x)->ia;
|
||||
MAKE_MUT(r, xia); mut_to(r, el_or(TI(w).elType, TI(x).elType));
|
||||
int mid = wia<xia? wia : xia;
|
||||
mut_copy(r, 0 , w, 0, mid);
|
||||
mut_copy(r, mid, x, 0, xia-mid);
|
||||
@ -426,12 +424,42 @@ B shiftb_c2(B t, B w, B x) {
|
||||
return qWithFill(mut_fcd(r, x), f);
|
||||
}
|
||||
|
||||
B shifta_c1(B t, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM("«: Argument cannot be a scalar");
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(inc(x));
|
||||
usz csz = arr_csz(x);
|
||||
MAKE_MUT(r, ia); mut_to(r, TI(x).elType);
|
||||
mut_copy(r, 0, x, csz, ia-csz);
|
||||
mut_fill(r, ia-csz, xf, csz);
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
B shifta_c2(B t, B w, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM("«: 𝕩 cannot be a scalar");
|
||||
if (!isArr(w)) w = m_hunit(w);
|
||||
shift_check(w, x);
|
||||
B f = fill_both(w, x);
|
||||
usz wia = a(w)->ia;
|
||||
usz xia = a(x)->ia;
|
||||
MAKE_MUT(r, xia); mut_to(r, el_or(TI(w).elType, TI(x).elType));
|
||||
if (wia < xia) {
|
||||
usz m = xia-wia;
|
||||
mut_copy(r, 0, x, wia, m);
|
||||
mut_copy(r, m, w, 0, wia);
|
||||
} else {
|
||||
mut_copy(r, 0, w, wia-xia, xia);
|
||||
}
|
||||
dec(w);
|
||||
return qWithFill(mut_fcd(r, x), f);
|
||||
}
|
||||
|
||||
#define ba(N) bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); c(Fun,bi_##N)->c2 = N##_c2 ;c(Fun,bi_##N)->c1 = N##_c1 ; c(Fun,bi_##N)->extra=pf_##N; c(BFn,bi_##N)->ident=bi_N; gc_add(bi_##N);
|
||||
#define bd(N) bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); c(Fun,bi_##N)->c2 = N##_c2 ;c(Fun,bi_##N)->c1 = c1_invalid; c(Fun,bi_##N)->extra=pf_##N; c(BFn,bi_##N)->ident=bi_N; gc_add(bi_##N);
|
||||
#define bm(N) bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); c(Fun,bi_##N)->c2 = c2_invalid;c(Fun,bi_##N)->c1 = N##_c1 ; c(Fun,bi_##N)->extra=pf_##N; c(BFn,bi_##N)->ident=bi_N; gc_add(bi_##N);
|
||||
|
||||
B bi_shape, bi_pick, bi_pair, bi_select, bi_slash, bi_join, bi_shiftb, /*bi_shifta,*/ bi_take, bi_drop;
|
||||
static inline void sfns_init() { ba(shape) ba(pick) ba(pair) ba(select) ba(slash) ba(join) ba(shiftb) /*ba(shifta)*/ bd(take) bd(drop)
|
||||
B bi_shape, bi_pick, bi_pair, bi_select, bi_slash, bi_join, bi_shiftb, bi_shifta, bi_take, bi_drop;
|
||||
static inline void sfns_init() { ba(shape) ba(pick) ba(pair) ba(select) ba(slash) ba(join) ba(shiftb) ba(shifta) bd(take) bd(drop)
|
||||
}
|
||||
|
||||
#undef ba
|
||||
|
||||
@ -33,12 +33,7 @@ B glyph_c1(B t, B x) {
|
||||
}
|
||||
|
||||
B fill_c1(B t, B x) {
|
||||
B f = getFill(x);
|
||||
if (noFill(f)) {
|
||||
if (!PROPER_FILLS) return m_f64(0);
|
||||
thrM("No fill found");
|
||||
}
|
||||
return f;
|
||||
return getFillE(x);
|
||||
}
|
||||
B fill_c2(B t, B w, B x) { // TODO not set fill for typed arrays
|
||||
if (isArr(x)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user