42 lines
1.3 KiB
Nim
42 lines
1.3 KiB
Nim
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
import std/[hashes, options, tables]
|
|
import pkg/cps
|
|
import preserves
|
|
import ./actors, ./protocols/dataspace, ./skeletons
|
|
|
|
from ./protocols/protocol import Handle
|
|
from ./protocols/dataspace import Observe
|
|
|
|
type
|
|
Dataspace {.final.} = ref object of Entity
|
|
index: Index
|
|
handleMap: Table[Handle, Value]
|
|
|
|
method publish(ds: Dataspace; turn: Turn; a: AssertionRef; h: Handle) {.gcsafe.} =
|
|
if add(ds.index, turn, a.value):
|
|
var obs = a.value.preservesTo(Observe)
|
|
if obs.isSome and obs.get.observer of Cap:
|
|
ds.index.add(turn, obs.get.pattern, Cap(obs.get.observer))
|
|
ds.handleMap[h] = a.value
|
|
|
|
method retract(ds: Dataspace; turn: Turn; h: Handle) {.gcsafe.} =
|
|
let v = ds.handleMap[h]
|
|
if remove(ds.index, turn, v):
|
|
ds.handleMap.del h
|
|
var obs = v.preservesTo(Observe)
|
|
if obs.isSome and obs.get.observer of Cap:
|
|
ds.index.remove(turn, obs.get.pattern, Cap(obs.get.observer))
|
|
|
|
method message(ds: Dataspace; turn: Turn; a: AssertionRef) {.gcsafe.} =
|
|
ds.index.deliverMessage(turn, a.value)
|
|
|
|
proc newDataspace*(f: Facet): Cap =
|
|
newCap(f, Dataspace(index: initIndex()))
|
|
|
|
type BootProc = proc (ds: Cap)
|
|
|
|
proc newDataspace*(): Cap {.syndicate.} =
|
|
activeFacet().newDataspace()
|