Abandoned
This commit is contained in:
parent
56eb452649
commit
0d05ab954c
|
@ -1,9 +1,9 @@
|
||||||
# Package
|
# Package
|
||||||
version = "20240425"
|
version = "20240522"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Syndicate bindings for the Min language"
|
description = "Syndicate bindings for the Min language"
|
||||||
license = "unlicense"
|
license = "unlicense"
|
||||||
bin = @["mindicate"]
|
bin = @["mindicate"]
|
||||||
srcDir = "pkg"
|
srcDir = "pkg"
|
||||||
|
|
||||||
requires "min >= 0.40.0", "http://git.syndicate-lang.org/ehmry/syndicate-nim.git >= 20240422"
|
requires "http://git.syndicate-lang.org/ehmry/syndicate-nim.git >= 20240422", "checksums", "minline >= 0.1.1 & < 0.2.0", "nimquery >= 2.0.1 & < 3.0.0", "zippy >= 0.5.6 & < 0.6.0"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import
|
import
|
||||||
std/critbits,
|
std/[critbits, sequtils],
|
||||||
min,
|
min,
|
||||||
preserves
|
preserves
|
||||||
|
|
||||||
|
@ -98,6 +98,12 @@ proc toPreserves*(i: In; val: MinValue): Value =
|
||||||
of minBool:
|
of minBool:
|
||||||
result = val.boolVal.toPreserves
|
result = val.boolVal.toPreserves
|
||||||
|
|
||||||
|
proc newRecord(i: In; label: MinValue; fields: varargs[MinValue]): MinValue =
|
||||||
|
result = i.scope.newDict
|
||||||
|
result.objType = recordType
|
||||||
|
result = i.dset(result, "label", label)
|
||||||
|
result = i.dset(result, "fields", fields.toSeq.newVal)
|
||||||
|
|
||||||
proc preserves_module*(i: In) =
|
proc preserves_module*(i: In) =
|
||||||
let def = i.define()
|
let def = i.define()
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,14 @@ import
|
||||||
const
|
const
|
||||||
capType* = "syndicate-cap"
|
capType* = "syndicate-cap"
|
||||||
dictCapType = "dict:" & capType
|
dictCapType = "dict:" & capType
|
||||||
|
patternType* = "syndicate-pattern"
|
||||||
|
dictPatternType* = "dict:" & patternType
|
||||||
|
|
||||||
proc discardTurn(turn: var Turn) = discard
|
proc runForObj(q: MinValue) =
|
||||||
|
while q.obj.isNil:
|
||||||
|
syndicate.runOnce()
|
||||||
|
|
||||||
|
proc discardTurn(turn: Turn) = discard
|
||||||
|
|
||||||
proc newCapDict(i: In): MinValue =
|
proc newCapDict(i: In): MinValue =
|
||||||
result = i.scope.newDict
|
result = i.scope.newDict
|
||||||
|
@ -21,12 +27,50 @@ proc getCap(q: MinValue): Cap =
|
||||||
assert q.objType == capType
|
assert q.objType == capType
|
||||||
cast[Cap](q.obj)
|
cast[Cap](q.obj)
|
||||||
|
|
||||||
proc setCap(q: MinValue; cap: Cap) =
|
proc set(q: MinValue; cap: Cap) =
|
||||||
|
assert q.objType == capType
|
||||||
q.obj = addr cap[]
|
q.obj = addr cap[]
|
||||||
|
|
||||||
proc runForObj(q: MinValue) =
|
proc newDict(i: In; cap: Cap): MinValue =
|
||||||
while q.obj.isNil:
|
result = i.newCapDict
|
||||||
syndicate.runOnce()
|
result.set cap
|
||||||
|
|
||||||
|
proc newDict(i: In; pat: Pattern): MinValue =
|
||||||
|
result = i.scope.newDict
|
||||||
|
result.objType = patternType
|
||||||
|
result.obj = addr pat[]
|
||||||
|
|
||||||
|
type
|
||||||
|
MinEntity = ref object of syndicate.Entity
|
||||||
|
itr: ptr MinInterpreter
|
||||||
|
# unsafe if turns are running while the interpreter is not!
|
||||||
|
handlers: MinValue
|
||||||
|
|
||||||
|
proc push(me: MinEntity; elems: varargs[MinValue]) =
|
||||||
|
for e in elems: me.itr[].push e
|
||||||
|
|
||||||
|
method publish(me: MinEntity; turn: Turn; ass: AssertionRef; h: Handle) =
|
||||||
|
var
|
||||||
|
v = me.itr[].toMin ass.value
|
||||||
|
q = me.itr[].dget(me.handlers, "publish")
|
||||||
|
me.push v, h.newVal, q
|
||||||
|
|
||||||
|
method retract(me: MinEntity; turn: Turn; h: Handle) =
|
||||||
|
var q = me.itr[].dget(me.handlers, "retract")
|
||||||
|
me.push h.newVal, q
|
||||||
|
|
||||||
|
method message(me: MinEntity; turn: Turn; ass: AssertionRef) =
|
||||||
|
var
|
||||||
|
v = me.itr[].toMin ass.value
|
||||||
|
q = me.itr[].dget(me.handlers, "message")
|
||||||
|
me.push v, q
|
||||||
|
|
||||||
|
method sync(me: MinEntity; turn: Turn; peer: Cap) =
|
||||||
|
var
|
||||||
|
p = me.itr[].newDict peer
|
||||||
|
q = me.itr[].dget(me.handlers, "sync")
|
||||||
|
me.push p, q
|
||||||
|
echo "MinEntity pushes sync onto stack"
|
||||||
|
|
||||||
proc syndicate_module*(i: In) =
|
proc syndicate_module*(i: In) =
|
||||||
let def = i.define()
|
let def = i.define()
|
||||||
|
@ -35,8 +79,8 @@ proc syndicate_module*(i: In) =
|
||||||
let
|
let
|
||||||
vals = i.expect("dict")
|
vals = i.expect("dict")
|
||||||
dict = i.newCapDict
|
dict = i.newCapDict
|
||||||
bootActor("dataspace") do (turn: var Turn):
|
bootActor("dataspace") do (turn: Turn):
|
||||||
dict.setCap turn.newDataspace
|
dict.set turn.newDataspace
|
||||||
runForObj dict
|
runForObj dict
|
||||||
i.push dict
|
i.push dict
|
||||||
|
|
||||||
|
@ -46,7 +90,7 @@ proc syndicate_module*(i: In) =
|
||||||
cap = vals[0].getCap
|
cap = vals[0].getCap
|
||||||
pr = i.toPreserves vals[1]
|
pr = i.toPreserves vals[1]
|
||||||
h = newVal 0
|
h = newVal 0
|
||||||
cap.relay.queueTurn do (turn: var Turn):
|
cap.relay.queueTurn do (turn: Turn):
|
||||||
h.intVal = publish(turn, cap, pr)
|
h.intVal = publish(turn, cap, pr)
|
||||||
while h.intVal == 0:
|
while h.intVal == 0:
|
||||||
syndicate.runOnce()
|
syndicate.runOnce()
|
||||||
|
@ -57,7 +101,7 @@ proc syndicate_module*(i: In) =
|
||||||
vals = i.expect(dictCapType, "int")
|
vals = i.expect(dictCapType, "int")
|
||||||
cap = vals[0].getCap
|
cap = vals[0].getCap
|
||||||
h = Handle vals[1].intVal
|
h = Handle vals[1].intVal
|
||||||
cap.relay.queueTurn do (turn: var Turn):
|
cap.relay.queueTurn do (turn: Turn):
|
||||||
retract(turn, h)
|
retract(turn, h)
|
||||||
|
|
||||||
def.symbol("message") do (i: In):
|
def.symbol("message") do (i: In):
|
||||||
|
@ -65,7 +109,7 @@ proc syndicate_module*(i: In) =
|
||||||
var
|
var
|
||||||
cap = vals[0].getCap
|
cap = vals[0].getCap
|
||||||
pr = i.toPreserves vals[1]
|
pr = i.toPreserves vals[1]
|
||||||
cap.relay.queueTurn do (turn: var Turn):
|
cap.relay.queueTurn do (turn: Turn):
|
||||||
message(turn, cap, pr)
|
message(turn, cap, pr)
|
||||||
|
|
||||||
def.symbol("sync") do (i: In):
|
def.symbol("sync") do (i: In):
|
||||||
|
@ -73,11 +117,55 @@ proc syndicate_module*(i: In) =
|
||||||
vals = i.expect(dictCapType)
|
vals = i.expect(dictCapType)
|
||||||
cap = vals[0].getCap
|
cap = vals[0].getCap
|
||||||
var pending = true
|
var pending = true
|
||||||
cap.relay.queueTurn do (turn: var Turn):
|
cap.relay.queueTurn do (turn: Turn):
|
||||||
sync(turn, cap) do (turn: var Turn):
|
sync(turn, cap) do (turn: Turn):
|
||||||
pending = false
|
pending = false
|
||||||
while pending:
|
while pending:
|
||||||
|
echo "run a turn for sync"
|
||||||
if not syndicate.runOnce():
|
if not syndicate.runOnce():
|
||||||
raiseInvalid("failed to make sync progress")
|
raiseInvalid("failed to make sync progress")
|
||||||
|
|
||||||
|
def.symbol("to-cap") do (i: In):
|
||||||
|
let
|
||||||
|
vals = i.expect("dict")
|
||||||
|
capDict = i.newCapDict
|
||||||
|
entity = MinEntity(itr: addr i, handlers: vals[0])
|
||||||
|
bootActor("name") do (turn: Turn):
|
||||||
|
capDict.set:
|
||||||
|
turn.newCap entity
|
||||||
|
runForObj capDict
|
||||||
|
i.push capDict
|
||||||
|
|
||||||
|
#[
|
||||||
|
def.symbol("pattern-discard") do (i: In):
|
||||||
|
i.push:
|
||||||
|
i.toMin Pattern(orKind: PatternKind.`discard`).toPreserves
|
||||||
|
]#
|
||||||
|
|
||||||
|
#[
|
||||||
|
def.symbol("pattern-bind") do (i: In):
|
||||||
|
let vals = i.expect("'sym", "a")
|
||||||
|
var
|
||||||
|
pr = i.toPreserves vals[1]
|
||||||
|
pat = grab pr
|
||||||
|
i.push:
|
||||||
|
i.toMin pat.toPreserves
|
||||||
|
]#
|
||||||
|
|
||||||
|
#[
|
||||||
|
def.symbol("pattern-any") do (i: In):
|
||||||
|
var rec = i.newRecord("_".newVal)
|
||||||
|
i.push rec
|
||||||
|
|
||||||
|
def.symbol("pattern-bind") do (i: In):
|
||||||
|
let vals = i.expect("'sym", "a")
|
||||||
|
]#
|
||||||
|
|
||||||
|
#[
|
||||||
|
def.symbol("on-message") do (i: In):
|
||||||
|
let
|
||||||
|
vals = i.expect(dictCapType, "quot")
|
||||||
|
cap = vals[0].getCap
|
||||||
|
]#
|
||||||
|
|
||||||
def.finalize("syndicate")
|
def.finalize("syndicate")
|
||||||
|
|
Reference in New Issue