simpler atom-array arith on length 0 inputs
This commit is contained in:
parent
311aa74303
commit
a90e7de997
@ -163,6 +163,7 @@ struct DyTableSA {
|
|||||||
EntSA ents[el_B];
|
EntSA ents[el_B];
|
||||||
BBB2B mainFn;
|
BBB2B mainFn;
|
||||||
char* repr;
|
char* repr;
|
||||||
|
u8 fill[2][2]; // 0:none 1:int 2:char
|
||||||
DyTableSA* chrAtom;
|
DyTableSA* chrAtom;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -186,11 +187,47 @@ B dyArith_SA(DyTableSA* table, B w, B x) {
|
|||||||
usz ia = IA(x);
|
usz ia = IA(x);
|
||||||
u8 xe = TI(x,elType);
|
u8 xe = TI(x,elType);
|
||||||
|
|
||||||
u8 width, type; // when one argument is a number, both + and - have character array result iif the other argument is a character array; therefore result type doesn't need a lookup
|
u8 width, type; // the currently supported character functions (+ and -) have the result type be character when left xor right is character, so it can be hard-coded
|
||||||
u64 wa;
|
u64 wa;
|
||||||
|
|
||||||
EntSA* e;
|
EntSA* e;
|
||||||
|
|
||||||
|
if (ia==0) {
|
||||||
|
u8 fillVal;
|
||||||
|
bool charX;
|
||||||
|
if (xe!=el_B) {
|
||||||
|
charX = elChr(xe);
|
||||||
|
} else {
|
||||||
|
B xf = getFillQ(x);
|
||||||
|
if (isNum(xf)) charX=0;
|
||||||
|
else if (isC32(xf)) charX=1;
|
||||||
|
else if (noFill(xf)) { fillVal=0; goto fillSel; }
|
||||||
|
else { dec(xf); goto rec; } // whatever
|
||||||
|
}
|
||||||
|
bool charW;
|
||||||
|
if (isNum(w)) charW=0;
|
||||||
|
else if (isC32(w)) charW=1;
|
||||||
|
else goto rec;
|
||||||
|
|
||||||
|
fillVal = table->fill[charW][charX];
|
||||||
|
fillSel:
|
||||||
|
if (RNK(x)==1) {
|
||||||
|
decG(x);
|
||||||
|
if (fillVal==1) return emptyIVec();
|
||||||
|
if (fillVal==0) return emptyHVec();
|
||||||
|
assert(fillVal==2);
|
||||||
|
return emptyCVec();
|
||||||
|
} else {
|
||||||
|
Arr* r;
|
||||||
|
if (fillVal==1) { u64* rp; r = m_bitarrp(&rp, 0); }
|
||||||
|
else if (fillVal==0) { r = (Arr*) m_harrUp(0).c; }
|
||||||
|
else { assert(fillVal==2); u8* rp; r = m_c8arrp (&rp, 0); }
|
||||||
|
arr_shCopy(r, x);
|
||||||
|
decG(x);
|
||||||
|
return taga(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isF64(w)) {
|
if (!isF64(w)) {
|
||||||
if (!isC32(w)) goto rec;
|
if (!isC32(w)) goto rec;
|
||||||
DyTableSA* t2 = table->chrAtom;
|
DyTableSA* t2 = table->chrAtom;
|
||||||
|
|||||||
@ -156,6 +156,7 @@ def arithAA{mode, F, W, X, R} = {
|
|||||||
# mode: 0:overflow-checked, needed; 1:overflow-erroring; 2: overflow-checked, not needed
|
# mode: 0:overflow-checked, needed; 1:overflow-erroring; 2: overflow-checked, not needed
|
||||||
arithSAf{vw, mode, F, swap, W, X, R}(r:*u8, w:u64, x:*u8, len:u64) : u64 = {
|
arithSAf{vw, mode, F, swap, W, X, R}(r:*u8, w:u64, x:*u8, len:u64) : u64 = {
|
||||||
# show{fmt_op{F}, swap, mode, W, X, R}
|
# show{fmt_op{F}, swap, mode, W, X, R}
|
||||||
|
assert{len>0}
|
||||||
def bulk = vw / max{width{W}, width{R}}
|
def bulk = vw / max{width{W}, width{R}}
|
||||||
def TY = [bulk]R
|
def TY = [bulk]R
|
||||||
def overflow = tern{mode==1, {i}=>return{1}, {i}=>return{i}}
|
def overflow = tern{mode==1, {i}=>return{1}, {i}=>return{i}}
|
||||||
|
|||||||
@ -133,17 +133,19 @@ Make ← {𝕊ns:
|
|||||||
tyi ← ⟨@, "i8","i16","i32","f64", "i8","i16","i32"⟩
|
tyi ← ⟨@, "i8","i16","i32","f64", "i8","i16","i32"⟩
|
||||||
tyc ← ⟨@, "c8","c16","c32",@, "c8","c16","c32"⟩
|
tyc ← ⟨@, "c8","c16","c32",@, "c8","c16","c32"⟩
|
||||||
isc ← ⟨0, 0, 0, 0, 0, 1, 1, 1⟩
|
isc ← ⟨0, 0, 0, 0, 0, 1, 1, 1⟩
|
||||||
{ 𝕊 swap‿get:
|
{ 𝕊 swap:
|
||||||
choices ← ns.sa
|
choices ← ⌽⍟swap⌾(2⊸↑)¨ ns.sa
|
||||||
hadChrArr ← 0
|
hadChrArr ← 0
|
||||||
|
ResMap ← {{(2⊑¨𝕩)⌾((2↑¨𝕩)⊸⊑) 2‿2⥊@} 'c'=𝕩}
|
||||||
{
|
{
|
||||||
0≡≠𝕩? @;
|
0≡≠𝕩? @;
|
||||||
charAtm ← 'c' ≡ ⊑⊑𝕩
|
charAtm ← 'c' ≡ ⊑⊑𝕩
|
||||||
hasNumArr ← ⊑'i' ∊ 1⊑¨𝕩
|
hasNumArr ← ⊑'i' ∊ 1⊑¨𝕩
|
||||||
hasChrArr ← ⊑'c' ∊ 1⊑¨𝕩
|
hasChrArr ← ⊑'c' ∊ 1⊑¨𝕩
|
||||||
resChr ← {(2⊑¨𝕩)⌾((2↑¨𝕩)⊸⊑) 2‿2⥊@} 'c'=𝕩
|
resChr ← ResMap 𝕩
|
||||||
argarr ← ⌽⍟swap "SA"
|
argarr ← ⌽⍟swap "SA"
|
||||||
canOverflow ← "f64"⊸≢¨ tyName
|
canOverflow ← "f64"⊸≢¨ tyName
|
||||||
|
P ← {∾⟨"{",𝕨,",",𝕩,"}"⟩}´
|
||||||
|
|
||||||
cSrc∾↩ ∾⟨
|
cSrc∾↩ ∾⟨
|
||||||
"static DyTableSA ", cbqn,"DyTable", ⌽⍟swap (charAtm⊑"NC")∾"A", " = {", nl
|
"static DyTableSA ", cbqn,"DyTable", ⌽⍟swap (charAtm⊑"NC")∾"A", " = {", nl
|
||||||
@ -173,13 +175,14 @@ Make ← {𝕊ns:
|
|||||||
" },", nl
|
" },", nl
|
||||||
" .chrAtom = ", hadChrArr◶"NULL"‿{𝕊: ∾⟨"&",cbqn,"DyTable", ⌽⍟swap "CA"⟩} @, ",", nl
|
" .chrAtom = ", hadChrArr◶"NULL"‿{𝕊: ∾⟨"&",cbqn,"DyTable", ⌽⍟swap "CA"⟩} @, ",", nl
|
||||||
" .mainFn = ", cbqn, "_c2", swap/"R", ",", nl
|
" .mainFn = ", cbqn, "_c2", swap/"R", ",", nl
|
||||||
|
" .fill = ", P P¨ <˘ '0'+@‿0‿1⊐ResMap choices, ",", nl
|
||||||
" .repr = """, repr, """", nl
|
" .repr = """, repr, """", nl
|
||||||
"};", nl
|
"};", nl
|
||||||
⟩
|
⟩
|
||||||
|
|
||||||
hadChrArr∨↩ charAtm
|
hadChrArr∨↩ charAtm
|
||||||
}¨ 2↑(("ci"⊐⊑¨)⊔⊢) ⌽⍟swap⌾(2⊸↑)¨ choices
|
}¨ 2↑(("ci"⊐⊑¨)⊔⊢) choices
|
||||||
}¨ (2-commutative)↑ ⟨0‿{𝕩.sa} ⋄ 1‿{𝕩.as}⟩
|
}¨ ↕2-commutative
|
||||||
|
|
||||||
siSrc∾↩ nl
|
siSrc∾↩ nl
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user