introduce calls.h, move vec_addN and vec_join to core header
and remove a bunch of apparently unnecessary mut.h imports
This commit is contained in:
parent
c6aba44a11
commit
4daabd708a
@ -1,5 +1,6 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/each.h"
|
||||
#include "../utils/calls.h"
|
||||
|
||||
static NOINLINE void fillBits(u64* dst, u64 sz, bool v) {
|
||||
u64 x = 0-(u64)v;
|
||||
@ -48,28 +49,26 @@ CMP_REC(ne, ne, swapped=0;)
|
||||
#define gt_rec(S, W, X) lt_rec(!S, X, W)
|
||||
#undef CMP_REC
|
||||
|
||||
typedef void (*CmpAAFn)(u64*, void*, void*, u64);
|
||||
typedef void (*CmpASFn)(u64*, void*, u64, u64);
|
||||
#define CMPFN(A,F,S,T) A##_##F##S##_##T
|
||||
#define FN_LUT(B,A,F,S) static const Cmp##S##Fn B##_##F##S[] = {CMPFN(A,F,S,u1), CMPFN(A,F,S,i8), CMPFN(A,F,S,i16), CMPFN(A,F,S,i32), CMPFN(A,F,S,f64), CMPFN(A,F,S,u8), CMPFN(A,F,S,u16), CMPFN(A,F,S,u32)}
|
||||
#define FN_LUT(B,A,F,S) const Cmp##S##Fn B##_##F##S[] = {CMPFN(A,F,S,u1), CMPFN(A,F,S,i8), CMPFN(A,F,S,i16), CMPFN(A,F,S,i32), CMPFN(A,F,S,f64), CMPFN(A,F,S,u8), CMPFN(A,F,S,u16), CMPFN(A,F,S,u32)}
|
||||
|
||||
#if SINGELI
|
||||
#include "../singeli/c/cmp.c"
|
||||
#else
|
||||
#define CMP_AA0(N, T, BODY) void base_##N##AA##_##T(u64* r, void* w, void* x, u64 l) { BODY }
|
||||
#define CMP_AA1(N, T, OP) CMP_AA0(N, T, for (usz i=0; i<l; i++) bitp_set(r, i, ((T*)w)[i] OP ((T*)x)[i]);)
|
||||
#define CMP_AA(N, OP, BX) \
|
||||
#define CMP_AA_F(N, OP, BX) \
|
||||
CMP_AA0(N, u1, ({usz bia = BIT_N(l); for (usz i=0; i<bia; i++) { u64 wv=((u64*)w)[i], xv=((u64*)x)[i]; ((u64*)r)[i] = BX; }});) \
|
||||
CMP_AA1(N, i8, OP) CMP_AA1(N, i16, OP) CMP_AA1(N, i32, OP) CMP_AA1(N, f64, OP) \
|
||||
const CmpAAFn base_##N##AA##_u32 = base_##N##AA##_i32;
|
||||
|
||||
#define CMP_AA_C0(N, OP) const CmpAAFn base_##N##AA##_u8 = base_##N##AA##_i8; const CmpAAFn base_##N##AA##_u16 = base_##N##AA##_i16;
|
||||
#define CMP_AA_C1(N, OP) CMP_AA1(N, u8, OP) CMP_AA1(N, u16, OP)
|
||||
CMP_AA(eq, ==, ~wv ^ xv) CMP_AA_C0(eq, ==)
|
||||
CMP_AA(ne, !=, wv ^ xv) CMP_AA_C0(ne, !=)
|
||||
CMP_AA(gt, > , wv & ~xv) CMP_AA_C1(gt, > )
|
||||
CMP_AA(ge, >=, wv | ~xv) CMP_AA_C1(ge, >=)
|
||||
#undef CMP_AA
|
||||
CMP_AA_F(eq, ==, ~wv ^ xv) CMP_AA_C0(eq, ==)
|
||||
CMP_AA_F(ne, !=, wv ^ xv) CMP_AA_C0(ne, !=)
|
||||
CMP_AA_F(gt, > , wv & ~xv) CMP_AA_C1(gt, > )
|
||||
CMP_AA_F(ge, >=, wv | ~xv) CMP_AA_C1(ge, >=)
|
||||
#undef CMP_AA_F
|
||||
|
||||
|
||||
#define CMP_SLOW(T, GW) void cmp_slow_##T(void* r, void* w, B x, u64 l, BBB2B fn) { \
|
||||
@ -93,18 +92,18 @@ typedef void (*CmpASFn)(u64*, void*, u64, u64);
|
||||
}
|
||||
|
||||
#define CMP_SA1(N, T, Q, C, SLOW, OP) CMP_SA0(N, T, Q, SLOW, ({T xv = C(x); for (usz i=0; i<l; i++) bitp_set(r, i, ((T*)w)[i] OP xv);}))
|
||||
#define CMP_SA(N, OP, SLOW, BX) \
|
||||
#define CMP_SA_F(N, OP, SLOW, BX) \
|
||||
CMP_SA0(N, u1, bit, SLOW, ({usz bia = BIT_N(l); u64 xv=bitx(x); for (usz i=0; i<bia; i++) { u64 wv=((u64*)w)[i]; ((u64*)r)[i] = BX; }})) \
|
||||
CMP_SA1(N,i8,i8,o2iG,SLOW,OP) CMP_SA1(N,i16,i16,o2iG,SLOW,OP) CMP_SA1(N,i32,i32,o2iG,SLOW,OP) CMP_SA1(N,f64,f64,o2fG,SLOW,OP) \
|
||||
CMP_SA1(N,u8,c8,o2cG,SLOW,OP) CMP_SA1(N,u16,c16,o2cG,SLOW,OP) CMP_SA1(N,u32,c32,o2cG,SLOW,OP)
|
||||
|
||||
CMP_SA(eq, ==, CMP_TO_FILL, ~wv^xv)
|
||||
CMP_SA(ne, !=, CMP_TO_FILL, wv^xv)
|
||||
CMP_SA(le, <=, CMP_TO_SLOW, ~wv | xv)
|
||||
CMP_SA(ge, >=, CMP_TO_SLOW, wv | ~xv)
|
||||
CMP_SA(lt, < , CMP_TO_SLOW, ~wv & xv)
|
||||
CMP_SA(gt, > , CMP_TO_SLOW, wv & ~xv)
|
||||
#undef CMP_SA
|
||||
CMP_SA_F(eq, ==, CMP_TO_FILL, ~wv^xv)
|
||||
CMP_SA_F(ne, !=, CMP_TO_FILL, wv^xv)
|
||||
CMP_SA_F(le, <=, CMP_TO_SLOW, ~wv | xv)
|
||||
CMP_SA_F(ge, >=, CMP_TO_SLOW, wv | ~xv)
|
||||
CMP_SA_F(lt, < , CMP_TO_SLOW, ~wv & xv)
|
||||
CMP_SA_F(gt, > , CMP_TO_SLOW, wv & ~xv)
|
||||
#undef CMP_SA_F
|
||||
|
||||
FN_LUT(cmp_fns, base, eq, AS); FN_LUT(cmp_fns, base, eq, AA);
|
||||
FN_LUT(cmp_fns, base, ne, AS); FN_LUT(cmp_fns, base, ne, AA);
|
||||
@ -118,7 +117,7 @@ typedef void (*CmpASFn)(u64*, void*, u64, u64);
|
||||
|
||||
|
||||
#define AL(X) u64* rp; B r = m_bitarrc(&rp, X); usz ria=IA(r)
|
||||
#define CMP_AA(CN, CR, NAME, PRE) NOINLINE B NAME##_AA(i32 swapped, B w, B x) { PRE \
|
||||
#define CMP_AA_D(CN, CR, NAME, PRE) NOINLINE B NAME##_AA(i32 swapped, B w, B x) { PRE \
|
||||
u8 xe = TI(x, elType); if (xe==el_B) goto bad; \
|
||||
u8 we = TI(w, elType); if (we==el_B) goto bad; \
|
||||
if (RNK(w)==RNK(x)) { if (!eqShape(w, x)) thrF("%U: Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", swapped?CR:CN, swapped?x:w, swapped?w:x); \
|
||||
@ -133,18 +132,18 @@ typedef void (*CmpASFn)(u64*, void*, u64, u64);
|
||||
} \
|
||||
bad: return NAME##_rec(swapped, w, x); \
|
||||
}
|
||||
CMP_AA("≥", "≤", ge, )
|
||||
CMP_AA(">", "<", gt, )
|
||||
CMP_AA("=", "?", eq, swapped=0;)
|
||||
CMP_AA("≠", "?", ne, swapped=0;)
|
||||
CMP_AA_D("≥", "≤", ge, )
|
||||
CMP_AA_D(">", "<", gt, )
|
||||
CMP_AA_D("=", "?", eq, swapped=0;)
|
||||
CMP_AA_D("≠", "?", ne, swapped=0;)
|
||||
#define le_AA(T, W, X) ge_AA(!T, X, W)
|
||||
#define lt_AA(T, W, X) gt_AA(!T, X, W)
|
||||
#undef CMP_AA
|
||||
#undef CMP_AA_D
|
||||
|
||||
|
||||
|
||||
|
||||
#define CMP_SA(NAME, RNAME, PRE) B NAME##_SA(i32 swapped, B w, B x) { PRE \
|
||||
#define CMP_SA_D(NAME, RNAME, PRE) B NAME##_SA(i32 swapped, B w, B x) { PRE \
|
||||
u8 xe = TI(x, elType); if (xe==el_B) goto bad; \
|
||||
AL(x); \
|
||||
if (ria) cmp_fns_##RNAME##AS[xe](rp, tyany_ptr(x), w.u, ria); \
|
||||
@ -152,13 +151,13 @@ CMP_AA("≠", "?", ne, swapped=0;)
|
||||
decG(x); return r; \
|
||||
bad: return NAME##_rec(swapped, w, x); \
|
||||
}
|
||||
CMP_SA(eq, eq, swapped=0;)
|
||||
CMP_SA(ne, ne, swapped=0;)
|
||||
CMP_SA(le, ge, )
|
||||
CMP_SA(ge, le, )
|
||||
CMP_SA(lt, gt, )
|
||||
CMP_SA(gt, lt, )
|
||||
#undef CMP_SA
|
||||
CMP_SA_D(eq, eq, swapped=0;)
|
||||
CMP_SA_D(ne, ne, swapped=0;)
|
||||
CMP_SA_D(le, ge, )
|
||||
CMP_SA_D(ge, le, )
|
||||
CMP_SA_D(lt, gt, )
|
||||
CMP_SA_D(gt, lt, )
|
||||
#undef CMP_SA_D
|
||||
#undef AL
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/talloc.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../builtins.h"
|
||||
|
||||
extern B ud_c1(B, B);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../builtins.h"
|
||||
#include "../ns.h"
|
||||
@ -276,8 +275,10 @@ B eequal_c2(B t, B w, B x) {
|
||||
dec(w); dec(x);
|
||||
return m_i32(r);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST_BITCPY
|
||||
#include "../utils/mut.h"
|
||||
#endif
|
||||
B internalTemp_c1(B t, B x) {
|
||||
#ifdef TEST_BITCPY
|
||||
SGetU(x)
|
||||
@ -286,6 +287,9 @@ B internalTemp_c1(B t, B x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
#ifdef TEST_MUT
|
||||
#include "../utils/calls.h"
|
||||
#endif
|
||||
B internalTemp_c2(B t, B w, B x) {
|
||||
#ifdef TEST_MUT
|
||||
SGetU(x)
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
#include "../utils/each.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../utils/time.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../builtins.h"
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/hash.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/talloc.h"
|
||||
|
||||
#define C2(F,X,W) F##_c2(m_f64(0),X,W)
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/hash.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/talloc.h"
|
||||
|
||||
B not_c1(B t, B x);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "../core.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/calls.h"
|
||||
#include "../utils/talloc.h"
|
||||
#include "../builtins.h"
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include "../utils/hash.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../utils/wyhash.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/time.h"
|
||||
#include "../builtins.h"
|
||||
#include "../ns.h"
|
||||
|
||||
@ -151,6 +151,8 @@ static bool elInt(u8 x) {
|
||||
|
||||
// string stuff
|
||||
|
||||
B vec_addN(B w, B x); // consumes both; fills may be wrong
|
||||
B vec_join(B w, B x); // consumes both
|
||||
i32 num_fmt(char buf[30], f64 x);
|
||||
#define NUM_FMT_BUF(N,X) char N[30]; num_fmt(N, X);
|
||||
B append_fmt(B s, char* p, ...);
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "../ns.h"
|
||||
#include "../utils/file.h"
|
||||
#include "../utils/talloc.h"
|
||||
#include "../utils/mut.h"
|
||||
#include "../utils/wyhash.h"
|
||||
#include "../vm.h"
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "core.h"
|
||||
#include "utils/mut.h"
|
||||
#include "utils/file.h"
|
||||
#include "vm.h"
|
||||
#include "ns.h"
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#include "core.h"
|
||||
#include "h.h"
|
||||
#include "nfns.h"
|
||||
#include "utils/mut.h"
|
||||
|
||||
static u32 nfn_curr;
|
||||
static B nfn_list;
|
||||
|
||||
1
src/ns.c
1
src/ns.c
@ -1,7 +1,6 @@
|
||||
#include "core.h"
|
||||
#include "ns.h"
|
||||
#include "vm.h"
|
||||
#include "utils/mut.h"
|
||||
|
||||
void m_nsDesc(Body* body, bool imm, u8 ty, i32 actualVam, B nameList, B varIDs, B exported) { // doesn't consume nameList
|
||||
if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information");
|
||||
|
||||
29
src/utils/calls.h
Normal file
29
src/utils/calls.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
typedef void (*M_CopyF)(void*, usz, B, usz, usz);
|
||||
typedef void (*M_FillF)(void*, usz, B, usz);
|
||||
extern M_CopyF copyFns[el_MAX];
|
||||
extern M_FillF fillFns[el_MAX];
|
||||
#define COPY_TO(WHERE, ELT, MS, X, XS, LEN) copyFns[ELT](WHERE, MS, X, XS, LEN)
|
||||
#define FILL_TO(WHERE, ELT, MS, X, LEN) fillFns[ELT](WHERE, MS, X, LEN)
|
||||
|
||||
|
||||
typedef void (*CmpAAFn)(u64*, void*, void*, u64);
|
||||
typedef void (*CmpASFn)(u64*, void*, u64, u64);
|
||||
#define CMP_DEF(F, S) extern const Cmp##S##Fn cmp_fns_##F##S[];
|
||||
CMP_DEF(eq, AS); CMP_DEF(eq, AA);
|
||||
CMP_DEF(ne, AS); CMP_DEF(ne, AA);
|
||||
CMP_DEF(gt, AS); CMP_DEF(gt, AA);
|
||||
CMP_DEF(ge, AS); CMP_DEF(ge, AA);
|
||||
CMP_DEF(lt, AS);
|
||||
CMP_DEF(le, AS);
|
||||
|
||||
// will write up to 8×⌈len÷64 bytes to WHERE, i.e. whole u64-s
|
||||
#define CMP_AA_FN(FN, ELT) cmp_fns_##FN##AA[ELT]
|
||||
#define CMP_AS_FN(FN, ELT) cmp_fns_##FN##AS[ELT]
|
||||
|
||||
#define CMP_AA_CALL(FN, WHERE, WP, XP, LEN) FN(WHERE, WP, XP, LEN)
|
||||
#define CMP_AS_CALL(FN, WHERE, WP, X, LEN) FN(WHERE, WP, (X).u, LEN)
|
||||
|
||||
#define CMP_AA_IMM(FN, ELT, WHERE, WP, XP, LEN) CMP_AA_CALL(CMP_AA_FN(FN, ELT), WHERE, WP, XP, LEN)
|
||||
#define CMP_AS_IMM(FN, ELT, WHERE, WP, X, LEN) CMP_AS_CALL(CMP_AS_FN(FN, ELT), WHERE, WP, X, LEN)
|
||||
@ -3,7 +3,6 @@
|
||||
#include <errno.h>
|
||||
#include "../core.h"
|
||||
#include "file.h"
|
||||
#include "mut.h"
|
||||
#include "talloc.h"
|
||||
#include "cstr.h"
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "calls.h"
|
||||
|
||||
/* Usage:
|
||||
|
||||
@ -14,8 +15,6 @@ Methods ending with G expect that mut_init has been called with a type that can
|
||||
*/
|
||||
typedef struct Mut Mut;
|
||||
typedef struct MutFns MutFns;
|
||||
typedef void (*M_CopyF)(void*, usz, B, usz, usz);
|
||||
typedef void (*M_FillF)(void*, usz, B, usz);
|
||||
typedef void (*M_SetF)(void*, usz, B);
|
||||
typedef B (*M_GetF)(Mut*, usz);
|
||||
struct MutFns {
|
||||
@ -156,15 +155,8 @@ static void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) {
|
||||
#undef RDFo
|
||||
}
|
||||
|
||||
B vec_join(B w, B x); // consumes both
|
||||
|
||||
|
||||
extern M_CopyF copyFns[el_MAX];
|
||||
#define COPY_TO(WHERE, ELT, MS, X, XS, LEN) copyFns[ELT](WHERE, MS, X, XS, LEN)
|
||||
|
||||
extern M_FillF fillFns[el_MAX];
|
||||
#define FILL_TO(WHERE, ELT, MS, X, LEN) fillFns[ELT](WHERE, MS, X, LEN)
|
||||
|
||||
// if `consume==true`, consumes w,x and expects both args to be vectors
|
||||
// else, doesn't consume x, and decrements refcount of w iif *reusedW (won't free because the result will be w)
|
||||
FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) {
|
||||
@ -232,7 +224,6 @@ static inline bool inplace_add(B w, B x) { // consumes x if returns true; fails
|
||||
return true;
|
||||
}
|
||||
B vec_addF(B w, B x);
|
||||
B vec_addN(B w, B x); // vec_add but not inlined
|
||||
static B vec_add(B w, B x) { // consumes both; fills may be wrong
|
||||
if (inplace_add(w, x)) return w;
|
||||
return vec_addF(w, x);
|
||||
|
||||
5
src/vm.c
5
src/vm.c
@ -4,7 +4,6 @@
|
||||
#include "ns.h"
|
||||
#include "utils/utf.h"
|
||||
#include "utils/talloc.h"
|
||||
#include "utils/mut.h"
|
||||
#include "utils/interrupt.h"
|
||||
|
||||
#ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors
|
||||
@ -1599,6 +1598,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
|
||||
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
|
||||
// while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n");
|
||||
|
||||
if (!rethrow) envPrevHeight = envCurr-envStart + 1;
|
||||
#if CATCH_ERRORS
|
||||
if (cf>cfStart) { // something wants to catch errors
|
||||
cf--;
|
||||
@ -1606,7 +1606,6 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
|
||||
B* gStackNew = gStackStart + cf->gsDepth;
|
||||
assert(gStackNew<=gStack);
|
||||
while (gStack!=gStackNew) dec(*--gStack);
|
||||
if (!rethrow) envPrevHeight = envCurr-envStart + 1;
|
||||
unwindEnv(envStart + cf->envDepth - 1);
|
||||
|
||||
|
||||
@ -1617,7 +1616,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
|
||||
#endif
|
||||
assert(cf==cfStart);
|
||||
fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fputc('\n',stderr); fflush(stderr);
|
||||
Env* envEnd = envCurr+1;
|
||||
Env* envEnd = envStart+envPrevHeight;
|
||||
unwindEnv(envStart-1);
|
||||
vm_pst(envCurr+1, envEnd);
|
||||
#ifdef DEBUG
|
||||
|
||||
Loading…
Reference in New Issue
Block a user