diff options
author | glenda <glenda@9front> | 2022-10-22 16:45:32 +0000 |
---|---|---|
committer | glenda <glenda@9front> | 2022-10-22 16:45:32 +0000 |
commit | a82186dab48c234c507693b166acd7c13433864a (patch) | |
tree | eb6db255c93b1e6278e0e833e915c4c85372c84f /operators.c | |
parent | a3b635de1753ed4ce73dabdc7e2c24dfdf77891e (diff) |
Atomic reference counting
Diffstat (limited to 'operators.c')
-rw-r--r-- | operators.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/operators.c b/operators.c index 20c8611..8f644ad 100644 --- a/operators.c +++ b/operators.c @@ -1,6 +1,7 @@ #include <u.h> #include <libc.h> #include <bio.h> +#include <thread.h> #include "apl9.h" @@ -52,10 +53,10 @@ opEach(Datum *lefto, Array *left, Array *right) /* TODO handle empty arrays by applying the function to their prototype */ - Array *result = allocarray(AtypeArray, GetRank(rightarr), GetSize(rightarr)); + Array *result = allocarray(AtypeArray, GetRank(rightarr), rightarr->size); for(i = 0; i < GetRank(rightarr); i++) result->shape[i] = rightarr->shape[i]; - for(i = 0; i < GetSize(rightarr); i++){ + for(i = 0; i < rightarr->size; i++){ Array *elem1 = leftarr ? arrayitem(leftarr, i) : nil; Array *elem2 = arrayitem(rightarr, i); result->arraydata[i] = runfunc(lefto->func, elem1, elem2); @@ -71,7 +72,7 @@ Array * opSwitch(Datum *lefto, Array *left, Array *right) { if(lefto->tag == ArrayTag){ - incarrayref(lefto->array); + incref(lefto->array); return lefto->array; }else if(lefto->tag == FunctionTag){ if(left) @@ -117,9 +118,9 @@ opOuterProduct(Datum *lefto, Array *left, Array *right) for(i = 0; i < rank; i++) result->shape[i] = shape[i]; - for(int leftindex = 0; leftindex < GetSize(left); leftindex++){ - for(int rightindex = 0; rightindex < GetSize(right); rightindex++){ - i = leftindex * GetSize(right) + rightindex; + for(int leftindex = 0; leftindex < left->size; leftindex++){ + for(int rightindex = 0; rightindex < right->size; rightindex++){ + i = leftindex * right->size + rightindex; Array *leftitem = arrayitem(left, leftindex); Array *rightitem = arrayitem(right, rightindex); result->arraydata[i] = runfunc(lefto->func, leftitem, rightitem); @@ -151,17 +152,17 @@ opReceive(Datum *lefto, Array *left, Array *right) throwerror(nil, ESyntax); if(GetType(right) != AtypeInt && GetType(right) != AtypeFloat) throwerror(nil, EDomain); - if(GetSize(right) != 1 && GetSize(right) != 0) + if(right->size != 1 && right->size != 0) throwerror(nil, ELength); int timeout = 0; - if(GetSize(right) == 0) + if(right->size == 0) timeout = -1; else if(GetType(right) == AtypeInt) timeout = right->intdata[0]*1000; else if(GetType(right) == AtypeFloat) timeout = right->floatdata[0]*1000; - if(GetSize(right) == 1 && timeout < 0) + if(right->size == 1 && timeout < 0) throwerror(L"Timeout must be non-negative", EDomain); return messagerecv(lefto->func, timeout); @@ -180,7 +181,7 @@ opPower(Datum *lefto, Datum *righto, Array *left, Array *right) else code = L"next←⍶⍵ ⋄ next⍹⍵:⍵ ⋄ ∇next"; }else if(righto->tag == ArrayTag){ - if(GetType(righto->array) != AtypeInt || GetRank(righto->array) != 0 || GetSize(righto->array) != 1) + if(GetType(righto->array) != AtypeInt || GetRank(righto->array) != 0 || righto->array->size != 1) throwerror(L"right operand to ⍣", EDomain); vlong times = righto->array->intdata[0]; if(times < 0){ @@ -254,10 +255,10 @@ opAtop(Datum *lefto, Datum *righto, Array *left, Array *right) throwerror(nil, ERank); if(GetType(ranks) != AtypeInt) throwerror(nil, EDomain); - if(GetSize(ranks) < 1 || GetSize(ranks) > 3) + if(ranks->size < 1 || ranks->size > 3) throwerror(nil, ELength); int p,q,r; - switch(GetSize(ranks)){ + switch(ranks->size){ case 1: p = q = r = ranks->intdata[0]; break; case 2: q = ranks->intdata[0]; |