Debug-dumping of skeleton structure
This commit is contained in:
parent
c9da4fcf26
commit
ffee492fec
|
@ -1,7 +1,7 @@
|
|||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
/// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||
|
||||
import { IdentityMap } from '@preserves/core';
|
||||
import { IdentityMap, stringify } from '@preserves/core';
|
||||
import { Index } from './skeleton.js';
|
||||
import { Assertion, Entity, Facet, Handle, LocalAction, Ref, Turn } from './actor.js';
|
||||
import { fromObserve, Observe, toObserve } from '../gen/dataspace.js';
|
||||
|
@ -12,11 +12,13 @@ export class Dataspace implements Partial<Entity> {
|
|||
readonly handleMap = new IdentityMap<Handle, [Assertion, Observe | undefined]>();
|
||||
|
||||
assert(v: Assertion, handle: Handle): void {
|
||||
// console.log('+', stringify(v));
|
||||
this.index.addAssertion(v);
|
||||
const o = toObserve(v);
|
||||
if (o !== void 0) {
|
||||
this.index.addObserver(o.pattern, o.observer);
|
||||
}
|
||||
// this.index.dump();
|
||||
this.handleMap.set(handle, [v, o]);
|
||||
}
|
||||
|
||||
|
@ -24,13 +26,16 @@ export class Dataspace implements Partial<Entity> {
|
|||
const entry = this.handleMap.get(handle);
|
||||
if (entry === void 0) return;
|
||||
const [v, o] = entry;
|
||||
// console.log('-', stringify(v));
|
||||
if (o !== void 0) {
|
||||
this.index.removeObserver(o.pattern, o.observer);
|
||||
}
|
||||
this.index.removeAssertion(v);
|
||||
// this.index.dump();
|
||||
}
|
||||
|
||||
message(v: Assertion): void {
|
||||
// console.log('!', stringify(v));
|
||||
this.index.deliverMessage(v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
/// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||
|
||||
import { Set, Dictionary, KeyedDictionary, IdentityMap } from '@preserves/core';
|
||||
import { Set, Dictionary, KeyedDictionary, IdentityMap, stringify, Value, embed } from '@preserves/core';
|
||||
import { AnyValue, Assertion, Handle, Ref, Turn } from './actor.js';
|
||||
import { Bag, ChangeDescription } from './bag.js';
|
||||
import * as Stack from './stack.js';
|
||||
|
@ -16,6 +16,8 @@ enum EventType {
|
|||
|
||||
const _nop = function() {};
|
||||
|
||||
const INDENT = ' ';
|
||||
|
||||
export class Index {
|
||||
readonly allAssertions: Bag<Ref> = new Bag();
|
||||
readonly root: Node = new Node(new Continuation(new Set()));
|
||||
|
@ -127,6 +129,25 @@ export class Index {
|
|||
this.root.modify(EventType.MESSAGE, v, _nop, leafCallback, (h, vs) =>
|
||||
h.observers.forEach((_captureMap, observer) => Turn.active.message(observer, vs)));
|
||||
}
|
||||
|
||||
dump() {
|
||||
console.log('INDEX');
|
||||
// console.log('allAssertions:');
|
||||
// dumpBag(this.allAssertions, 4);
|
||||
console.log('tree:');
|
||||
this.root.dump(INDENT);
|
||||
console.log();
|
||||
}
|
||||
}
|
||||
|
||||
function dumpBag<T, V extends Value<T>>(b: Bag<T, V>, indent: string) {
|
||||
for (const [v, count] of b.entries()) {
|
||||
console.log(indent + stringify(v) + ' = ' + count);
|
||||
}
|
||||
}
|
||||
|
||||
function dumpSet<V>(s: Set<V>, indent: string) {
|
||||
s.forEach(v => console.log(indent + stringify(v)));
|
||||
}
|
||||
|
||||
type Selector = [number, AnyValue];
|
||||
|
@ -224,6 +245,18 @@ class Node {
|
|||
|
||||
walkNode(this, Stack.push([outerValue], Stack.empty()));
|
||||
}
|
||||
|
||||
dump(indent: string) {
|
||||
this.continuation.dump(indent);
|
||||
this.edges.forEach((shapeMap, selector) => {
|
||||
const [popCount, stepIndex] = selector;
|
||||
console.log(indent + `popCount ${popCount} stepIndex ${stringify(stepIndex)} -->`);
|
||||
for (const shape in shapeMap) {
|
||||
console.log(indent + INDENT + stringify(shape));
|
||||
shapeMap[shape].dump(indent + INDENT + INDENT);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Continuation {
|
||||
|
@ -233,6 +266,16 @@ class Continuation {
|
|||
constructor(cachedAssertions: Set<Ref>) {
|
||||
this.cachedAssertions = cachedAssertions;
|
||||
}
|
||||
|
||||
dump(indent: string) {
|
||||
dumpSet(this.cachedAssertions, indent);
|
||||
this.leafMap.forEach((valueMap, paths) => {
|
||||
valueMap.forEach((leaf, values) => {
|
||||
console.log(indent + `when ${stringify(paths)} == ${stringify(values)} -->`);
|
||||
leaf.dump(indent + INDENT);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Leaf {
|
||||
|
@ -242,6 +285,13 @@ class Leaf {
|
|||
isEmpty(): boolean {
|
||||
return this.cachedAssertions.size === 0 && this.observerGroups.size === 0;
|
||||
}
|
||||
|
||||
dump(indent: string) {
|
||||
dumpSet(this.cachedAssertions, indent);
|
||||
this.observerGroups.forEach((observerGroup, paths) => {
|
||||
observerGroup.dump(paths, indent);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class ObserverGroup {
|
||||
|
@ -251,6 +301,16 @@ class ObserverGroup {
|
|||
constructor(cachedCaptures: Bag<Ref, Array<AnyValue>>) {
|
||||
this.cachedCaptures = cachedCaptures;
|
||||
}
|
||||
|
||||
dump(paths: Path[], indent: string) {
|
||||
dumpBag(this.cachedCaptures, indent);
|
||||
this.observers.forEach((valueMap, observer) => {
|
||||
console.log(indent + `${stringify(embed(observer))} projecting ${stringify(paths)}`);
|
||||
valueMap.forEach((handle, values) => {
|
||||
console.log(indent + INDENT + `captured ${stringify(values)} handle ${handle}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Total by assumption that path is valid for v
|
||||
|
|
Loading…
Reference in New Issue