From aef9702b7b664e3c3a0dcf2cbb9322394928f16f Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 6 Jul 2021 19:30:07 +0300 Subject: [PATCH] =?UTF-8?q?list-of-structs=20=E2=86=92=20struct-of-lists?= =?UTF-8?q?=20for=20TypeInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/h.h | 60 ++++++++++++++++++++++++++++-------------------------- src/load.c | 4 +++- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/h.h b/src/h.h index b51f3b13..901721cd 100644 --- a/src/h.h +++ b/src/h.h @@ -365,35 +365,37 @@ typedef B (* BBBB2B)(B, B, B, B); typedef B (* BBBBB2B)(B, B, B, B, B); typedef B (*BBBBBB2B)(B, B, B, B, B, B); -typedef struct TypeInfo { - V2v free; // expects refc==0, type may be cleared to t_empty for garbage collection - BS2B get; // increments result, doesn't consume arg; TODO figure out if this should never allocate, so GC wouldn't happen - BS2B getU; // like get, but doesn't increment result (mostly equivalent to `B t=get(…); dec(t); t`) - BB2B m1_d; // consume all args; (m, f) - BBB2B m2_d; // consume all args; (m, f, g) - BS2A slice; // consumes; create slice from given starting position; add ia, rank, shape yourself; may not actually be a Slice object; preserves fill - B2B identity; // return identity element of this function; doesn't consume - - BBB2B fn_uc1; // t,o, x→r; r≡O⌾( T ) x; consumes x - BBBB2B fn_ucw; // t,o, w,x→r; r≡O⌾(w⊸ T ) x; consumes w,x - BBBB2B m1_uc1; // t,o,f, x→r; r≡O⌾( F _T ) x; consumes x - BBBBB2B m1_ucw; // t,o,f, w,x→r; r≡O⌾(w⊸(F _T )) x; consumes w,x - BBBBB2B m2_uc1; // t,o,f,g, x→r; r≡O⌾( F _T_ G ) x; consumes x - BBBBBB2B m2_ucw; // t,o,f,g,w,x→r; r≡O⌾(w⊸(F _T_ G)) x; consumes w,x - - B2b canStore; // doesn't consume - u8 elType; // guarantees that the corresponding i32any_ptr/f64any_ptr/c32any_ptr/… always succeeds - - B2v print; // doesn't consume - V2v visit; // call mm_visit for all referents - B2B decompose; // consumes; must return a HArr - bool isArr; - bool arrD1; // is always an array with depth 1 -} TypeInfo; -extern TypeInfo ti[t_COUNT]; -#define TIi(X,V) (ti[X].V) -#define TIv(X,V) (ti[(X)->type].V) -#define TI(X,V) (ti[v(X)->type].V) +#define FOR_TI(F) \ + F(V2v, free) /* expects refc==0, type may be cleared to t_empty for garbage collection */ \ + F(BS2B, get) /* increments result, doesn't consume arg; TODO figure out if this should never allocate, so GC wouldn't happen */ \ + F(BS2B, getU) /* like get, but doesn't increment result (mostly equivalent to `B t=get(…); dec(t); t`) */ \ + F(BB2B, m1_d) /* consume all args; (m, f) */ \ + F(BBB2B, m2_d) /* consume all args; (m, f, g) */ \ + F(BS2A, slice) /* consumes; create slice from given starting position; add ia, rank, shape yourself; may not actually be a Slice object; preserves fill */ \ + F(B2B, identity) /* return identity element of this function; doesn't consume */ \ + \ + F( BBB2B, fn_uc1) /* t,o, x→r; r≡O⌾( T ) x; consumes x */ \ + F( BBBB2B, fn_ucw) /* t,o, w,x→r; r≡O⌾(w⊸ T ) x; consumes w,x */ \ + F( BBBB2B, m1_uc1) /* t,o,f, x→r; r≡O⌾( F _T ) x; consumes x */ \ + F( BBBBB2B, m1_ucw) /* t,o,f, w,x→r; r≡O⌾(w⊸(F _T )) x; consumes w,x */ \ + F( BBBBB2B, m2_uc1) /* t,o,f,g, x→r; r≡O⌾( F _T_ G ) x; consumes x */ \ + F(BBBBBB2B, m2_ucw) /* t,o,f,g,w,x→r; r≡O⌾(w⊸(F _T_ G)) x; consumes w,x */ \ + \ + F(B2b, canStore) /* doesn't consume */ \ + F(u8, elType) /* guarantees that the corresponding i32any_ptr/f64any_ptr/c32any_ptr/… always succeeds */ \ + \ + F(B2v, print) /* doesn't consume */ \ + F(V2v, visit) /* call mm_visit for all referents */ \ + F(B2B, decompose) /* consumes; must return a HArr */ \ + F(bool, isArr) /* whether this type would have an ARR_TAG tag, in cases where the tag is unknown */ \ + F(bool, arrD1) /* is always an array with depth 1 */ \ + +#define F(TY,N) extern TY ti_##N[t_COUNT]; + FOR_TI(F) +#undef F +#define TIi(X,V) (ti_##V[X]) +#define TIv(X,V) (ti_##V[(X)->type]) +#define TI(X,V) (ti_##V[v(X)->type]) static bool isNothing(B b) { return b.u==bi_N.u; } diff --git a/src/load.c b/src/load.c index e75df5f4..28f57dd8 100644 --- a/src/load.c +++ b/src/load.c @@ -47,7 +47,9 @@ char* format_pm2(u8 u) { -TypeInfo ti[t_COUNT]; +#define F(TY,N) TY ti_##N[t_COUNT]; + FOR_TI(F) +#undef F B r1Objs[rtLen]; B rtWrap_wrap(B x); // consumes