@turing-machine-js/machine 7.0.0-alpha.3 → 7.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/README.md +75 -6
- package/dist/classes/State.d.ts +128 -2
- package/dist/classes/TapeBlock.d.ts +25 -0
- package/dist/classes/TuringMachine.d.ts +23 -0
- package/dist/index.cjs +1031 -546
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1031 -546
- package/dist/utilities/stateGraph.d.ts +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import State from '../classes/State';
|
|
2
|
+
import TapeBlock from '../classes/TapeBlock';
|
|
3
|
+
import { type Graph } from './graph';
|
|
4
|
+
/**
|
|
5
|
+
* Walks the reachable graph from `initialState` and returns a serializable
|
|
6
|
+
* `Graph`. The walk is a BFS that visits each State exactly once (keyed by
|
|
7
|
+
* the State's internal id) and emits one `GraphNode` per State plus
|
|
8
|
+
* synthetic halt-marker nodes per callable-subtree frame.
|
|
9
|
+
*
|
|
10
|
+
* Round-trips losslessly with `fromGraph` in the sense that running the
|
|
11
|
+
* rebuilt machine on the same input produces the same output — but State
|
|
12
|
+
* instance identities are NOT preserved across the cycle.
|
|
13
|
+
*
|
|
14
|
+
* See `classes/State.ts` for the runtime model these graph nodes describe;
|
|
15
|
+
* see `utilities/graphFormats.ts` for the Mermaid-flavored serialization
|
|
16
|
+
* built on top of `Graph`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toGraph(initialState: State, tapeBlock: TapeBlock): Graph;
|
|
19
|
+
/**
|
|
20
|
+
* Inverse of `toGraph`: rebuilds a State graph (and a fresh TapeBlock with
|
|
21
|
+
* the graph's alphabets) from a serialized Graph. Round-trips with `toGraph`
|
|
22
|
+
* in the sense that running the rebuilt machine on the same input gives the
|
|
23
|
+
* same output, but the rebuilt State instances have *new* internal IDs.
|
|
24
|
+
*
|
|
25
|
+
* Under the v7 callable-subtree model (#174), graph nodes split into:
|
|
26
|
+
* - Wrapper nodes (`isWrapper: true`, no transitions) — reconstructed via
|
|
27
|
+
* `bareStates[bareStateId].withOverriddenHaltState(finalStates[overriddenHaltStateId])`.
|
|
28
|
+
* - Bare/regular nodes — constructed as normal States with transitions.
|
|
29
|
+
* - Halt + halt-marker nodes — collapse to the singleton `haltState`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fromGraph(graph: Graph): {
|
|
32
|
+
start: State;
|
|
33
|
+
tapeBlock: TapeBlock;
|
|
34
|
+
states: Record<number, State>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* One entry in the `StateMap` returned by `collectStates` (#195).
|
|
38
|
+
*
|
|
39
|
+
* - `state`: the live `State` instance for this Graph node. For the halt
|
|
40
|
+
* singleton at id `0`, this is the engine-wide `haltState` — toggling
|
|
41
|
+
* `state.debug` on that entry affects every machine in the process.
|
|
42
|
+
* - `transitionSymbols`: per-pattern Symbols in `#symbolToDataMap` insertion
|
|
43
|
+
* order, aligned positionally with `GraphTransition.id` patternIx. For
|
|
44
|
+
* wrappers and the halt singleton this is `[]` (no own transitions).
|
|
45
|
+
*/
|
|
46
|
+
export type StateMapEntry = {
|
|
47
|
+
state: State;
|
|
48
|
+
transitionSymbols: symbol[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Numeric `GraphNode.id` → `StateMapEntry`. Returned by `collectStates`
|
|
52
|
+
* (#195). Halt markers (synthetic nodes with `id = -frameId`) are NOT
|
|
53
|
+
* included — they're visualization-only and all collapse to the
|
|
54
|
+
* `haltState` singleton already exposed at id `0`.
|
|
55
|
+
*/
|
|
56
|
+
export type StateMap = Map<number, StateMapEntry>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a `Map<number, {state, transitionSymbols}>` keyed by engine
|
|
59
|
+
* `GraphNode.id`, giving downstream tooling direct access to the `State`
|
|
60
|
+
* instance + per-pattern Symbol references for breakpoint setup (#195).
|
|
61
|
+
*
|
|
62
|
+
* **Positional alignment contract.** For any `GraphTransition` whose id
|
|
63
|
+
* is `${N}.${K}` (#205 changed the separator from `-` to `.`),
|
|
64
|
+
* `result.get(N)!.transitionSymbols[K]` is the Symbol
|
|
65
|
+
* the transition fires on (reference equality, not structural). The K-th
|
|
66
|
+
* entry is the K-th key from the source State's `#symbolToDataMap` in
|
|
67
|
+
* insertion order, including `ifOtherSymbol` when the user wrote one.
|
|
68
|
+
* Consumers filtering the catch-all path identity-compare against the
|
|
69
|
+
* engine-exported `ifOtherSymbol`.
|
|
70
|
+
*
|
|
71
|
+
* **Unbound-`Reference` slots.** `toGraph` increments `patternIx` even
|
|
72
|
+
* when a transition's `nextState` is an unresolved `Reference` (it
|
|
73
|
+
* `continue`s without pushing the GraphTransition). In that case
|
|
74
|
+
* `transitionSymbols[K]` is still set to the K-th Map key, but no
|
|
75
|
+
* `Graph.nodes[N].transitions` entry exists with id `${N}.${K}`. Sparse
|
|
76
|
+
* on the Graph side, dense on the `transitionSymbols` side — same
|
|
77
|
+
* indexing.
|
|
78
|
+
*
|
|
79
|
+
* **Coverage.** Map keys are the State-backed subset of `graph.nodes`:
|
|
80
|
+
* regulars + bares + wrappers + the halt singleton (id `0`). Synthetic
|
|
81
|
+
* halt markers (id `-frameId`) are excluded — they all reach the same
|
|
82
|
+
* `haltState` object at runtime, and the named consumer
|
|
83
|
+
* ([machines-demo#37](https://github.com/mellonis/machines-demo/issues/37))
|
|
84
|
+
* surfaces halt-pause via a separate UI control, not via clicks on
|
|
85
|
+
* halt glyphs. If a future consumer needs uniform-by-id lookup, the
|
|
86
|
+
* helper can be extended additively.
|
|
87
|
+
*
|
|
88
|
+
* **Halt-singleton warning.** `result.get(0)!.state === haltState` — the
|
|
89
|
+
* process-wide halt. Toggling `.debug` on that entry affects every
|
|
90
|
+
* machine in the runtime, not just the one this map was built from.
|
|
91
|
+
*/
|
|
92
|
+
export declare function collectStates(initialState: State, tapeBlock: TapeBlock): StateMap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turing-machine-js/machine",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.5",
|
|
4
4
|
"description": "A convenient Turing machine",
|
|
5
5
|
"engines": {
|
|
6
6
|
"npm": ">=7.0.0"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"default": "./dist/index.mjs"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "4838b823c5b93f74a783d8652746787436b431e4"
|
|
42
42
|
}
|