summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-08 16:03:10 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-08 16:03:10 +0000
commitc6e1c83f93f63a061f0804821ed29c656da38f28 (patch)
tree8f3b8863d9db2d79722a4ec104bb2eeb807f87e0 /functions.c
parent511ae2c1879676568b2f11312c38a66b2caa21c0 (diff)
Add work in progress concurrency. Might break stuff!
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/functions.c b/functions.c
index b1003fa..46f9782 100644
--- a/functions.c
+++ b/functions.c
@@ -4,7 +4,7 @@
#include "apl9.h"
-Rune primfuncnames[] = L"+-×÷*⍟⌹○!?|⌈⌊⊥⊤⊣⊢=≠≤<>≥≡≢∨∧⍲⍱↑↓⊂⊃⊆⌷⍋⍒⍳⍸∊⍷∪∩~,⍪⍴⌽⊖⍉⍎⍕∇";
+Rune primfuncnames[] = L"+-×÷*⍟⌹○!?|⌈⌊⊥⊤⊣⊢=≠≤<>≥≡≢∨∧⍲⍱↑↓⊂⊃⊆⌷⍋⍒⍳⍸∊⍷∪∩~,⍪⍴⌽⊖⍉⍎⍕∇⍈";
fnmonad monadfunctiondefs[] = {
fnSame, /* + */
@@ -60,6 +60,7 @@ fnmonad monadfunctiondefs[] = {
fnExecute, /* ⍎ */
fnFormat, /* ⍕ */
fnSelfReference1, /* ∇ */
+ 0, /* ⍈ */
};
fndyad dyadfunctiondefs[] = {
@@ -116,6 +117,7 @@ fndyad dyadfunctiondefs[] = {
0, /* ⍎ */
0, /* ⍕ */
fnSelfReference2, /* ∇ */
+ fnSend, /* ⍈ */
};
vlong gcd_int(vlong, vlong);
@@ -445,7 +447,7 @@ fnFloor(Array *right)
Array *
fnSame(Array *right)
{
- incref(right);
+ incarrayref(right);
return right;
}
@@ -533,10 +535,10 @@ fnMix(Array *right)
result->arraydata[i*commonsize] = a->arraydata[0];
else
result->arraydata[i*commonsize] = a;
- incref(result->arraydata[i*commonsize]);
+ incarrayref(result->arraydata[i*commonsize]);
for(j = 1; j < commonsize; j++){
result->arraydata[i*commonsize+j] = fill;
- incref(fill);
+ incarrayref(fill);
}
}else{
for(j = 0; j < commonrank; j++)
@@ -546,7 +548,7 @@ fnMix(Array *right)
int nfill = commonshape->intdata[commonrank-1-k] - a->shape[a->rank-1-k];
while(nfill--){
result->arraydata[i*commonsize+offset] = fill;
- incref(fill);
+ incarrayref(fill);
offset++;
}
index[commonrank-1-k] = 0;
@@ -558,7 +560,7 @@ fnMix(Array *right)
index[commonrank-1]++;
}else if(offset < commonsize){
result->arraydata[i*commonsize+offset] = fill;
- incref(fill);
+ incarrayref(fill);
offset++;
}
}
@@ -580,7 +582,7 @@ fnSplit(Array *right)
Array *
fnEnclose(Array *right)
{
- incref(right);
+ incarrayref(right);
if(simplescalar(right))
return right;
else{
@@ -1148,7 +1150,7 @@ Array *
fnLeft(Array *left, Array *right)
{
USED(right);
- incref(left);
+ incarrayref(left);
return left;
}
@@ -1156,7 +1158,7 @@ Array *
fnRight(Array *left, Array *right)
{
USED(left);
- incref(right);
+ incarrayref(right);
return right;
}
@@ -1352,7 +1354,7 @@ fnTake(Array *left, Array *right)
memcpy(result->rawdata + i*datasizes[result->type],
fill->rawdata, datasizes[result->type]);
if(result->type == AtypeArray)
- incref(result->arraydata[i]);
+ incarrayref(result->arraydata[i]);
index[left->size-1]++;
}
@@ -1530,7 +1532,7 @@ fnIndex(Array *left, Array *right)
throwerror(nil, EIndex);
}
left->arraydata[i] = oldleft->arraydata[i];
- incref(left->arraydata[i]);
+ incarrayref(left->arraydata[i]);
}
}
@@ -1575,7 +1577,7 @@ fnIndex(Array *left, Array *right)
right->rawdata + from * datasizes[result->type],
datasizes[result->type]);
if(result->type == AtypeArray)
- incref(result->arraydata[i]);
+ incarrayref(result->arraydata[i]);
leftindex[left->size-1]++;
}
free(leftindex);
@@ -1626,7 +1628,7 @@ fnFind(Array *left, Array *right)
memcpy(newleft->rawdata, left->rawdata, datasizes[left->type] * left->size);
if(left->type == AtypeArray)
for(i = 0; i < left->size; i++)
- incref(newleft->arraydata[i]);
+ incarrayref(newleft->arraydata[i]);
left = newleft;
}else
left = fnSame(left);
@@ -1746,7 +1748,7 @@ fnCatenateFirst(Array *left, Array *right)
for(i = 0, j = 0; i < leftarr->size; i++, j++){
if(type == AtypeArray && leftarr->type == AtypeArray){
result->arraydata[j] = leftarr->arraydata[i];
- incref(result->arraydata[j]);
+ incarrayref(result->arraydata[j]);
}else if(type == AtypeArray && leftarr->type != AtypeArray){
result->arraydata[j] = arrayitem(leftarr, i);
}else{
@@ -1761,7 +1763,7 @@ fnCatenateFirst(Array *left, Array *right)
for(i = 0; i < rightarr->size; i++, j++){
if(type == AtypeArray && rightarr->type == AtypeArray){
result->arraydata[j] = rightarr->arraydata[i];
- incref(result->arraydata[j]);
+ incarrayref(result->arraydata[j]);
}else if(type == AtypeArray && rightarr->type != AtypeArray){
result->arraydata[j] = arrayitem(rightarr, i);
}else{
@@ -1795,7 +1797,7 @@ fnReshape(Array *left, Array *right)
memcpy(p, right->rawdata + (datasizes[res->type] * (i % right->size)), datasizes[res->type]);
if(res->type == AtypeArray)
for(i = 0; i < res->size; i++)
- incref(res->arraydata[i]);
+ incarrayref(res->arraydata[i]);
return res;
}
@@ -1862,6 +1864,17 @@ fnSelfReference2(Array *left, Array *right)
}
}
+Array *
+fnSend(Array *left, Array *right)
+{
+ if(right->size != 1)
+ throwerror(nil, ELength);
+ if(right->type != AtypeInt)
+ throwerror(nil, EType);
+ messagesend(left, right->intdata[0]);
+ return fnSame(left);
+}
+
/* helper functions */
vlong
gcd_int(vlong a, vlong b)