@turing-machine-js/machine 7.0.0-alpha.3 → 7.0.0-alpha.4

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.
@@ -0,0 +1,91 @@
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}`, `result.get(N)!.transitionSymbols[K]` is the Symbol
64
+ * the transition fires on (reference equality, not structural). The K-th
65
+ * entry is the K-th key from the source State's `#symbolToDataMap` in
66
+ * insertion order, including `ifOtherSymbol` when the user wrote one.
67
+ * Consumers filtering the catch-all path identity-compare against the
68
+ * engine-exported `ifOtherSymbol`.
69
+ *
70
+ * **Unbound-`Reference` slots.** `toGraph` increments `patternIx` even
71
+ * when a transition's `nextState` is an unresolved `Reference` (it
72
+ * `continue`s without pushing the GraphTransition). In that case
73
+ * `transitionSymbols[K]` is still set to the K-th Map key, but no
74
+ * `Graph.nodes[N].transitions` entry exists with id `${N}-${K}`. Sparse
75
+ * on the Graph side, dense on the `transitionSymbols` side — same
76
+ * indexing.
77
+ *
78
+ * **Coverage.** Map keys are the State-backed subset of `graph.nodes`:
79
+ * regulars + bares + wrappers + the halt singleton (id `0`). Synthetic
80
+ * halt markers (id `-frameId`) are excluded — they all reach the same
81
+ * `haltState` object at runtime, and the named consumer
82
+ * ([machines-demo#37](https://github.com/mellonis/machines-demo/issues/37))
83
+ * surfaces halt-pause via a separate UI control, not via clicks on
84
+ * halt glyphs. If a future consumer needs uniform-by-id lookup, the
85
+ * helper can be extended additively.
86
+ *
87
+ * **Halt-singleton warning.** `result.get(0)!.state === haltState` — the
88
+ * process-wide halt. Toggling `.debug` on that entry affects every
89
+ * machine in the runtime, not just the one this map was built from.
90
+ */
91
+ 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",
3
+ "version": "7.0.0-alpha.4",
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": "d0c25d94e1f3caca1c68dd08072a3e21685e2428"
41
+ "gitHead": "0183c78ea7f7212ce983e99c846fc8e1fec5e56b"
42
42
  }