From c6e1c83f93f63a061f0804821ed29c656da38f28 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Tue, 8 Feb 2022 16:03:10 +0000 Subject: Add work in progress concurrency. Might break stuff! --- operators.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'operators.c') diff --git a/operators.c b/operators.c index f6066d9..a06b0d6 100644 --- a/operators.c +++ b/operators.c @@ -4,7 +4,7 @@ #include "apl9.h" -Rune primmonopnames[] = L"¨⍨⌸⌶&⌾∆"; +Rune primmonopnames[] = L"¨⍨⌸⌶&⌾∆⍇"; Rune primdyadopnames[] = L"⍣.∘⍤⍥@⍠⌺⍢⍫⍙"; opmonad monadoperatordefs[] = { @@ -12,9 +12,10 @@ opmonad monadoperatordefs[] = { opSwitch, /* ⍨ */ opKey, /* ⌸ */ 0, /* ⌶ */ - 0, /* & */ + opSpawn, /* & */ opOuterProduct, /* ⌾ */ opSelfReference1, /* ∆ */ + opReceive, /* ⍇ */ }; opdyad dyadoperatordefs[] = { @@ -68,7 +69,7 @@ Array * opSwitch(Datum *lefto, Array *left, Array *right) { if(lefto->tag == ArrayTag){ - incref(lefto->array); + incarrayref(lefto->array); return lefto->array; }else if(lefto->tag == FunctionTag){ if(left) @@ -90,6 +91,15 @@ opKey(Datum *lefto, Array *left, Array *right) return rundfn(L"⍵⍶⌸⍳≢⍵", lefto, nil, left, right); } +Array * +opSpawn(Datum *lefto, Array *left, Array *right) +{ + if(lefto->tag != FunctionTag) + throwerror(L"Can only spawn functions", EType); + int id = spawnthread(lefto->func, left, right); + return mkscalarint(id); +} + Array * opOuterProduct(Datum *lefto, Array *left, Array *right) { @@ -140,6 +150,19 @@ opSelfReference1(Datum *lefto, Array *left, Array *right) } } +Array * +opReceive(Datum *lefto, Array *left, Array *right) +{ + if(lefto->tag != FunctionTag) + throwerror(nil, EType); + if(right->type != AtypeInt) + throwerror(nil, EType); + if(right->size != 1) + throwerror(nil, ELength); + USED(left); + return messagerecv(lefto->func, right->intdata[0]); +} + /* Dyadic operators */ Array * opPower(Datum *lefto, Datum *righto, Array *left, Array *right) -- cgit v1.2.3