skeletons: implement assertion removal

This commit is contained in:
Emery Hemingway 2023-07-24 08:55:49 +01:00
parent 16cc5aaf98
commit 4e0a36ef31
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
## https://git.syndicate-lang.org/syndicate-lang/syndicate-rkt/src/commit/90c4c60699069b496491b81ee63b5a45ffd638cb/syndicate/HOWITWORKS.md
import std/[hashes, lists, options, sets, tables]
import preserves
import ./actors, ./bags, ./patterns
@ -146,14 +148,21 @@ proc modify(node: Node; turn: var Turn; outerValue: Value; event: EventKind;
of addedEvent, messageEvent:
let leaf = constValMap.getLeaf(get constVals)
modLeaf(leaf, outerValue)
assert not leaf.isEmpty
for capturePaths, observerGroup in leaf.observerGroups.pairs:
let captures = projectPaths(outerValue, capturePaths)
if captures.isSome:
modObs(turn, observerGroup, get captures)
else:
raiseAssert $event & " not handled"
# TODO: cleanup dead leaves
of removedEvent:
let leaf = constValMap.getOrDefault(get constVals)
if not leaf.isNil:
modLeaf(leaf, outerValue)
for capturePaths, observerGroup in leaf.observerGroups.pairs:
let captures = projectPaths(outerValue, capturePaths)
if captures.isSome:
modObs(turn, observerGroup, get captures)
if leaf.isEmpty:
constValMap.del(get constVals)
proc walk(node: Node; turn: var Turn; termStack: TermStack) =
walk(node.continuation, turn)
@ -168,6 +177,8 @@ proc modify(node: Node; turn: var Turn; outerValue: Value; event: EventKind;
let nextNode = table.getOrDefault(nextClass)
if not nextNode.isNil:
walk(nextNode, turn, push(nextStack, get nextValue))
if event == removedEvent and nextNode.isEmpty:
table.del(nextClass)
walk(node, turn, @[@[outerValue].toPreserve(Ref)])

View File

@ -1,6 +1,6 @@
# Package
version = "20230723"
version = "20230725"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"