summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorglenda <glenda@cirno>2022-09-18 14:55:48 +0000
committerglenda <glenda@cirno>2022-09-18 14:55:48 +0000
commit269c81f0217999367b4180e6a795142cbb2d02e7 (patch)
tree5b9299a3a7a2304ebc4259c1570c378e17f1e28f /runtime
parent6430127cc4503e2e7e40f86ccc68594ced055274 (diff)
Implement remote message passing via pipes!
Diffstat (limited to 'runtime')
-rw-r--r--runtime/remote.apl28
1 files changed, 28 insertions, 0 deletions
diff --git a/runtime/remote.apl b/runtime/remote.apl
new file mode 100644
index 0000000..f696a15
--- /dev/null
+++ b/runtime/remote.apl
@@ -0,0 +1,28 @@
+REMOTE←{
+ fd←⎕PIPE ⍵
+ out←{
+ msg←{1(2⊃⍵)}⍇⍬
+ raw←0 ⎕SERIAL msg
+ len←(4⍴255)⊤≢raw
+ _←fd ⎕WRITE len,raw
+ ∇⍵
+ }
+ in←{
+ m←1 ⎕serial fd ⎕read (4⍴255)⊥fd ⎕read 4
+ _←m⍈⍵
+ ∇⍵
+ }
+ remote←{
+ 0≡≢⍵: ⍺∇out&'remote out'⊢⎕self ⍝ Spawn out thread
+ 1≡≢⍵: ⍺∇⍵,in&'remote in'⊢⎕self ⍝ Spawn in thread
+ (outid inid)←⍵
+ master←⍺
+ (from msg)←{1 ⍵}⍇⍬
+ _←{
+ from≡master: msg⍈outid
+ from≢master: msg⍈master
+ }⍬
+ ⍺∇⍵
+ }
+ ⎕self remote&'remote'⊢⍬
+}