refactor •internal.Temp

This commit is contained in:
dzaima 2025-05-28 03:42:23 +03:00
parent 879a3e2007
commit 59923b25df
7 changed files with 107 additions and 79 deletions

View File

@ -293,7 +293,14 @@ B indistinguishable_c2(B t, B w, B x) {
return m_i32(r);
}
#ifdef TEST_BITCPY
B internalTemp_c1(B t, B x) {
return x;
}
#if DEBUG && !defined(TEST_UTILS)
#define TEST_UTILS 1
#endif
#ifdef TEST_UTILS
#include "../utils/mut.h"
#endif
#if NATIVE_COMPILER
@ -304,16 +311,61 @@ B indistinguishable_c2(B t, B w, B x) {
extern i32 fullCellFills;
extern i32 cellFillErrored;
#endif
#if TEST_RANGE
#include "../utils/calls.h"
#endif
#if TEST_GROUP_STAT
#if TEST_UTILS && SINGELI
extern void (*const si_group_statistics_i8)(void*,usz,uint8_t*,usz*,uint8_t*,usz*,int8_t*);
extern void (*const si_group_statistics_i16)(void*,usz,uint8_t*,usz*,uint8_t*,usz*,int16_t*);
extern void (*const si_group_statistics_i32)(void*,usz,uint8_t*,usz*,uint8_t*,usz*,int32_t*);
#endif
B internalTemp_c1(B t, B x) {
#if TEST_GROUP_STAT
B internalTemp_c2(B t, B w, B x) {
i32 o = o2i(w);
B r;
switch (o) {
case 0: {
printI(x);
return x;
}
#if NATIVE_COMPILER
case 100: {
SGet(x)
r = c2(native_comp, Get(x,0), Get(x,1));
goto dec_ret;
}
case 101: {
switchComp();
B r = bqn_exec(x, bi_N);
switchComp();
return r;
}
#endif
#if TEST_UTILS
case 201: { // test/mut.bqn
SGetU(x)
FILL_TO(tyarr_ptr(GetU(x,4)), o2s(GetU(x,0)), o2s(GetU(x,1)), GetU(x,2), o2s(GetU(x,3)));
return x;
}
case 202: { // test/bitcpy.bqn
SGetU(x)
bit_cpyN(bitarr_ptr(GetU(x,0)), o2s(GetU(x,1)), bitany_ptr(GetU(x,2)), o2s(GetU(x,3)), o2s(GetU(x,4)));
return x;
}
case 203: { // test/cases/build-specific/test_range.bqn
i64 buf[2];
bool b = getRange_fns[TI(x,elType)](tyany_ptr(x), buf, IA(x));
decG(x);
f64* rp;
B r = m_f64arrv(&rp, 3);
rp[0] = buf[0];
rp[1] = buf[1];
rp[2] = b;
return r;
}
#endif
#if TEST_UTILS && SINGELI
case 298: { // test/cases/build-specific/test_group_stat.bqn
u8 bad; usz neg; u8 sort; usz change; i32 max;
#define CASE(T) \
if (TI(x,elType)==el_##T) { T max_t; si_group_statistics_##T(tyany_ptr(x), IA(x), &bad, &neg, &sort, &change, &max_t); max = max_t; } \
@ -325,47 +377,26 @@ B internalTemp_c1(B t, B x) {
f64* rp; B r = m_f64arrv(&rp, 5);
rp[0] = bad; rp[1] = neg; rp[2] = sort; rp[3] = change; rp[4] = max;
return r;
}
#endif
#if TEST_RANGE
i64 buf[2];
bool b = getRange_fns[TI(x,elType)](tyany_ptr(x), buf, IA(x));
decG(x);
f64* rp;
B r = m_f64arrv(&rp, 3);
rp[0] = buf[0];
rp[1] = buf[1];
rp[2] = b;
return r;
#endif
#if TEST_CELL_FILLS
case 299: { // test/cells.bqn
if (isNum(x)) fullCellFills = o2iG(x);
B r = m_i32(cellFillErrored);
cellFillErrored = 0;
return r;
#endif
#if NATIVE_COMPILER
switchComp();
B r = bqn_exec(x, bi_N);
switchComp();
return r;
#endif
#ifdef TEST_BITCPY
SGetU(x)
bit_cpyN(bitarr_ptr(GetU(x,0)), o2s(GetU(x,1)), bitany_ptr(GetU(x,2)), o2s(GetU(x,3)), o2s(GetU(x,4)));
#endif
return x;
}
#endif
B internalTemp_c2(B t, B w, B x) {
#if NATIVE_COMPILER
return c2(native_comp, w, x);
#endif
#ifdef TEST_MUT
SGetU(x)
FILL_TO(tyarr_ptr(w), o2s(GetU(x,0)), o2s(GetU(x,1)), GetU(x,2), o2s(GetU(x,3)));
dec(w);
#endif
return x;
default:
thrF("Unknown/unsupported •internal.Temp mode: %i", o);
}
thrM("•internal.Temp: shouldn't break!");
dec_ret: MAYBE_UNUSED;
dec(x);
return r;
}
B heapDump_c1(B t, B x) {

View File

@ -1,6 +1,6 @@
## Tests
Must be run from the projects root directory.
Must be run from the projects root directory. Some tests require `-DTEST_UTILS` (enabled by default in debug builds)
``` C
test/mainCfgs.sh path/to/mlochbaum/BQN // run the test suite for a couple primary configurations
@ -10,9 +10,9 @@ test/run.bqn // run tests in test/cases/
./BQN test/cmp.bqn // fuzz-test scalar comparison functions =≠<≤>≥
./BQN test/equal.bqn // fuzz-test 𝕨≡𝕩
./BQN test/copy.bqn // fuzz-test creating new arrays with elements copied from another
./BQN test/bitcpy.bqn // fuzz-test bit_cpy; requires -DTEST_BITCPY
./BQN test/bitcpy.bqn // fuzz-test bit_cpy
./BQN test/bit.bqn // fuzz-test •bit functions
./BQN test/mut.bqn // fuzz-test mut.h (currently just bitarr fill); requires -DTEST_MUT
./BQN test/mut.bqn // fuzz-test mut.h (currently just bitarr fill)
./BQN test/hash.bqn // fuzz-test hashing
./BQN test/squeezeValid.bqn // fuzz-test squeezing giving a correct result
./BQN test/squeezeExact.bqn // fuzz-test squeezing giving the exact smallest result
@ -41,7 +41,7 @@ tests:
# the '(' and ')' lines must have no other characters in them
)
# flags addable anywhere in code:
# flags addable anywhere in code to restrict when it's run:
%SLOW # enable only if 'slow' argument present
%!DEBUG # disable if 'debug' argument present
%!HEAPVERIFY # disable if 'heapverify' argument present

View File

@ -1,4 +1,3 @@
# make o3-singeli f=-DTEST_BITCPY && ./BQN test/bitcpy.bqn
Temp, Type, Unshare, Squeeze, Info, Variation •internal
u 100×(•UnixTime+1|100וMonoTime)@
# u ↩ 123
@ -21,7 +20,7 @@ Do ← { 𝕊:
i bl
exp ((bs+i)b)((as+i)) a
aC Unshare a
Temp aC, as, b, bs, bl
202 Temp aC, as, b, bs, bl
aC exp?
•Out "Fail:"
F {(¬ ·` ' '=)/ ' '˘˜ 64 '0'+𝕩}

View File

@ -1,7 +1,6 @@
# needs: Singeli & -DTEST_GROUP_STAT
"basic test doesn't work; are you on a -DTEST_GROUP_STAT build?" ! 001109 •internal.Temp 10
298 •internal.Temp 10 %% 001109
%DEF tvar AllEq{v𝕩 {𝕩v?1;!𝕩v}¨ 𝕩 v} _tvar {Sel _𝕣 a: AllEq {Sel •internal.Temp 𝕩•internal.Variation a}¨ "Ai8""Ai16""Ai32"/ •internal.ListVariations •internal.Squeeze a}
%DEF tvar AllEq{v𝕩 {𝕩v?1;!𝕩v}¨ 𝕩 v} _tvar {Sel _𝕣 a: AllEq {Sel 298 •internal.Temp 𝕩•internal.Variation a}¨ "Ai8""Ai16""Ai32"/ •internal.ListVariations •internal.Squeeze a}
%USE tvar _tvar 10 %% 001109
%USE tvar AllEq {a𝕩0 AllEq {_tvar ¯2(𝕩) a}¨ 𝕩}¨ 1+40 %% 1

View File

@ -1,12 +1,11 @@
# needs: -DTEST_RANGE
"basic test doesn't work; are you on a -DTEST_RANGE build?" ! 191 •internal.Temp 314159
203 •internal.Temp 314159 %% 191
%DEF invalid Invalid {··0: 1; se1: (s<-252) e>252}•internal.Temp
%DEF invalid Invalid {··0: 1; se1: (s<-252) e>252} 203•internal.Temp
(091,10 ¯5¯31 ¯5¯3¯4¯4¯4¯4¯4{¯2,𝕩-3,1,¯2+𝕩}¨1+100) {expa𝕊𝕩: exp (!) •internal.Temp 𝕩•internal.Variation a} "Ai8""Ai16""Ai32""Af64"
T ! ·•internal.Temp "Ab"•internal.Variation {𝕊n: 111 T 𝕩1 001 T 𝕩0 01 {011 T (¬𝕨)(𝕩) n𝕨}¨(n>1) 2•rand.Range n}¨1+500
(091,10 ¯5¯31 ¯5¯3¯4¯4¯4¯4¯4{¯2,𝕩-3,1,¯2+𝕩}¨1+100) {expa𝕊𝕩: exp (!) 203•internal.Temp 𝕩•internal.Variation a} "Ai8""Ai16""Ai32""Af64"
T ! 203•internal.Temp "Ab"•internal.Variation {𝕊n: 111 T 𝕩1 001 T 𝕩0 01 {011 T (¬𝕨)(𝕩) n𝕨}¨(n>1) 2•rand.Range n}¨1+500
%USE invalid Invalid¨ 4, - 250, π×4, 10260 %% 0011
%USE invalid 263, 1.5, 0÷0 {𝕨!Invalid 𝕨(𝕩) 200} 20
%USE invalid p1+2-52, 1-2-53 {𝕩!Invalid 𝕩(10) 200}¨ , ¯∞, 0.1, ¯0.1 ((1p) × - 254+12) p × 270
{! 001 •internal.Temp 𝕩(𝕩0)100÷0}¨ 1+10
{𝕩!0= 2•internal.Temp (0÷0)¨((𝕩)) 100}¨ 101010
{! 001 203•internal.Temp 𝕩(𝕩0)100÷0}¨ 1+10
{𝕩!0= 2 203•internal.Temp (0÷0)¨((𝕩)) 100}¨ 101010

View File

@ -125,9 +125,9 @@ RunTests ← {
HTests { 𝕊:
okTests ok/tests
hasFill 0=ok/valid
cbqni.Temp 2 f1 RunTests okTests /˜ hasFill
cbqni.Temp 1 f0 RunTests okTests /˜ ¬hasFill
cbqni.Temp 0
299 cbqni.Temp 2 f1 RunTests okTests /˜ hasFill
299 cbqni.Temp 1 f0 RunTests okTests /˜ ¬hasFill
299 cbqni.Temp 0
(hasFill) f0f1
}
hCBQNFile •FChars •Repr HTests(ok/) "err"¨ tests
@ -137,7 +137,7 @@ RunTests ← {
tests GetTests@
•Out "Running ", •Repr tests, " tests on base CBQN.."
cfefo <˘>{cbqni.Temp@ (cbqni.Temp@) RunTests 𝕩}¨ tests
cfefo <˘>{299 cbqni.Temp@ (299 cbqni.Temp@) RunTests 𝕩}¨ tests
validFile •FChars '0'+ 2 cfe + 2×"err"¨ fo # 2: errored; 1: invalid fill; 0: valid fill
{ 𝕊:

View File

@ -7,7 +7,7 @@ Do ← {𝕊:
mut "Ab"•internal.Variation orig
l Range (1+orig)-s
v Range 2
mut •internal.Temp 0,s,0,l
201 •internal.Temp 0,s,0,l,mut
exp 0¨((s+l)) orig
mut exp?
•Show '0'+orig