everystate 0.1.0 → 0.3.1

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.
Files changed (55) hide show
  1. package/README.md +121 -86
  2. package/bin/everystate.mjs +35 -0
  3. package/native/darwin-arm64/everystate +0 -0
  4. package/native/darwin-x64/everystate +0 -0
  5. package/native/linux-arm64/everystate +0 -0
  6. package/native/linux-x64/everystate +0 -0
  7. package/native/win32-x64/everystate.exe +0 -0
  8. package/package.json +29 -24
  9. package/skills/formal-verification/SKILL.md +115 -0
  10. package/skills/formal-verification/example/Charge.cfg +7 -0
  11. package/skills/formal-verification/example/Charge.tla +61 -0
  12. package/skills/formal-verification/example/ChargeBroken.cfg +7 -0
  13. package/wasm/cli.mjs +26 -0
  14. package/wasm/everystate.d.ts +33 -0
  15. package/wasm/everystate.mjs +112 -0
  16. package/wasm/everystate.wasm +0 -0
  17. package/CONFORMANCE.md +0 -64
  18. package/dist/bundled.d.ts +0 -1
  19. package/dist/bundled.js +0 -2
  20. package/dist/cfg.d.ts +0 -24
  21. package/dist/cfg.js +0 -252
  22. package/dist/checker.d.ts +0 -96
  23. package/dist/checker.js +0 -520
  24. package/dist/cli.d.ts +0 -2
  25. package/dist/cli.js +0 -4
  26. package/dist/community.d.ts +0 -17
  27. package/dist/community.js +0 -1381
  28. package/dist/entry.d.ts +0 -2
  29. package/dist/entry.js +0 -39
  30. package/dist/eval.d.ts +0 -119
  31. package/dist/eval.js +0 -1533
  32. package/dist/index.d.ts +0 -33
  33. package/dist/index.js +0 -24
  34. package/dist/java.d.ts +0 -2
  35. package/dist/java.js +0 -6
  36. package/dist/lexer.d.ts +0 -17
  37. package/dist/lexer.js +0 -255
  38. package/dist/liveness.d.ts +0 -80
  39. package/dist/liveness.js +0 -855
  40. package/dist/main.d.ts +0 -40
  41. package/dist/main.js +0 -494
  42. package/dist/model.d.ts +0 -56
  43. package/dist/model.js +0 -582
  44. package/dist/modules.d.ts +0 -91
  45. package/dist/modules.js +0 -649
  46. package/dist/node-host.d.ts +0 -2
  47. package/dist/node-host.js +0 -25
  48. package/dist/parser.d.ts +0 -30
  49. package/dist/parser.js +0 -1114
  50. package/dist/pprint.d.ts +0 -7
  51. package/dist/pprint.js +0 -647
  52. package/dist/stdlib.d.ts +0 -14
  53. package/dist/stdlib.js +0 -588
  54. package/dist/values.d.ts +0 -150
  55. package/dist/values.js +0 -822
package/dist/index.d.ts DELETED
@@ -1,33 +0,0 @@
1
- export { runCli, runJavaShim, runXmlExporter, stateText, actionLabel, VERSION } from './main.ts';
2
- export type { Host } from './main.ts';
3
- export { parseConfig } from './cfg.ts';
4
- export type { Config } from './cfg.ts';
5
- export { buildModel } from './model.ts';
6
- export type { Model, Action, Pred } from './model.ts';
7
- export { modelCheck } from './liveness.ts';
8
- export { Checker } from './checker.ts';
9
- export type { CheckResult, CheckOptions, TraceStep, State } from './checker.ts';
10
- export { parseModule, parseExpression } from './parser.ts';
11
- export { fmt } from './values.ts';
12
- export { ppr } from './pprint.ts';
13
- export { TlaError } from './lexer.ts';
14
- export { BUNDLED } from './bundled.ts';
15
- import type { CheckResult } from './checker.ts';
16
- import type { Model } from './model.ts';
17
- export interface CheckInput {
18
- /** Name of the root module. */
19
- root: string;
20
- /** Module sources by module name (the root and any modules it EXTENDS/INSTANCEs that are not bundled). */
21
- modules: Record<string, string>;
22
- /** Contents of the TLC configuration (.cfg) file. */
23
- config: string;
24
- /** Check for deadlock (default: true unless the config says CHECK_DEADLOCK FALSE). */
25
- deadlock?: boolean;
26
- /** Receives output of Print/PrintT. */
27
- print?: (line: string) => void;
28
- }
29
- /** Model-check a specification held in memory. Works in any JavaScript runtime (no file system needed). */
30
- export declare function check(input: CheckInput): {
31
- result: CheckResult;
32
- model: Model;
33
- };
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- // Programmatic API.
2
- export { runCli, runJavaShim, runXmlExporter, stateText, actionLabel, VERSION } from "./main.js";
3
- export { parseConfig } from "./cfg.js";
4
- export { buildModel } from "./model.js";
5
- export { modelCheck } from "./liveness.js";
6
- export { Checker } from "./checker.js";
7
- export { parseModule, parseExpression } from "./parser.js";
8
- export { fmt } from "./values.js";
9
- export { ppr } from "./pprint.js";
10
- export { TlaError } from "./lexer.js";
11
- export { BUNDLED } from "./bundled.js";
12
- import { parseConfig } from "./cfg.js";
13
- import { buildModel } from "./model.js";
14
- import { modelCheck } from "./liveness.js";
15
- import { BUNDLED } from "./bundled.js";
16
- import { resetInterning } from "./values.js";
17
- /** Model-check a specification held in memory. Works in any JavaScript runtime (no file system needed). */
18
- export function check(input) {
19
- resetInterning();
20
- const cfg = parseConfig(input.config);
21
- const model = buildModel(input.root, name => input.modules[name] ?? BUNDLED[name] ?? null, cfg, { print: input.print ?? (() => { }) });
22
- const { result } = modelCheck(model, { checkDeadlock: (input.deadlock ?? true) && model.checkDeadlock });
23
- return { result, model };
24
- }
package/dist/java.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/java.js DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- // Drop-in stand-in for the `java` binary when the only thing being run is the TLA+ tools
3
- // (`java -cp tla2tools.jar tlc2.TLC ...`): point JAVA at this script, or put it on PATH as `java`.
4
- import { runJavaShim } from "./main.js";
5
- import { runEntry } from "./entry.js";
6
- runEntry(import.meta.url, runJavaShim);
package/dist/lexer.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export type Loc = [number, number, number, number];
2
- export declare class TlaError extends Error {
3
- loc?: Loc;
4
- module?: string;
5
- kind: string;
6
- constructor(msg: string, loc?: Loc, module?: string, kind?: string);
7
- }
8
- export type TokType = 'id' | 'num' | 'str' | 'op' | 'kw' | 'step' | 'sep' | 'end' | 'eof' | 'bad';
9
- export interface Tok {
10
- t: TokType;
11
- v: string;
12
- line: number;
13
- col: number;
14
- ec: number;
15
- n?: number;
16
- }
17
- export declare function lex(src: string, moduleName?: string, intern?: (s: string) => void): Tok[];
package/dist/lexer.js DELETED
@@ -1,255 +0,0 @@
1
- // TLA+ lexer. Produces a flat token array for one source file.
2
- export class TlaError extends Error {
3
- loc;
4
- module;
5
- kind;
6
- constructor(msg, loc, module, kind = 'error') {
7
- super(msg);
8
- this.loc = loc;
9
- this.module = module;
10
- this.kind = kind;
11
- }
12
- }
13
- const KEYWORDS = new Set([
14
- 'ASSUME', 'ASSUMPTION', 'AXIOM', 'CASE', 'CHOOSE', 'CONSTANT', 'CONSTANTS', 'DOMAIN', 'ELSE', 'ENABLED',
15
- 'EXCEPT', 'EXTENDS', 'IF', 'IN', 'INSTANCE', 'LET', 'LOCAL', 'MODULE', 'OTHER', 'SUBSET', 'THEN', 'THEOREM',
16
- 'UNCHANGED', 'UNION', 'VARIABLE', 'VARIABLES', 'WITH', 'LAMBDA', 'RECURSIVE', 'PROPOSITION', 'LEMMA',
17
- 'COROLLARY', 'BY', 'OBVIOUS', 'OMITTED', 'PROOF', 'QED', 'HAVE', 'TAKE', 'WITNESS', 'PICK', 'SUFFICES',
18
- 'PROVE', 'DEFINE', 'DEF', 'DEFS', 'USE', 'HIDE', 'ONLY', 'NEW', 'STATE', 'ACTION', 'TEMPORAL', 'TRUE', 'FALSE',
19
- ]);
20
- // Symbol tokens, longest first.
21
- const SYMBOLS = [
22
- '-+->', '(\\X)', '<=>', '...', '::=', '|->', '(+)', '(-)', '(.)', '(/)', '>>_',
23
- '=>', '~>', '->', '<-', '==', '=<', '<=', '>=', '/=', '/\\', '..', ':=', '::', ':>', '<:', '@@', '!!', '##',
24
- '$$', '??', '%%', '&&', '**', '++', '--', '//', '^^', '||', '|-', '|=', '-|', '=|', '<<', '>>', ']_', '[]',
25
- '<>', '^+', '^*', '^#', '-.',
26
- '~', '=', '<', '>', '#', '$', '%', '&', '*', '+', '-', '/', '^', '|', '(', ')', '[', ']', '{', '}', ',', ':',
27
- ';', '.', '!', '@', '_', "'",
28
- ];
29
- const SYM_BY_CHAR = new Map();
30
- for (const s of SYMBOLS) {
31
- const l = SYM_BY_CHAR.get(s[0]) ?? [];
32
- l.push(s);
33
- SYM_BY_CHAR.set(s[0], l);
34
- }
35
- // Canonical spellings for operator synonyms.
36
- const CANON = {
37
- '\\land': '/\\', '\\lor': '\\/', '\\lnot': '~', '\\neg': '~', '\\equiv': '<=>', '#': '/=', '\\neq': '/=',
38
- '=<': '<=', '\\leq': '<=', '\\geq': '>=', '\\union': '\\cup', '\\intersect': '\\cap', '\\times': '\\X',
39
- '\\circ': '\\o', '(+)': '\\oplus', '(-)': '\\ominus', '(.)': '\\odot', '(/)': '\\oslash', '(\\X)': '\\otimes',
40
- '\\notin': '\\notin', '\\forall': '\\A', '\\exists': '\\E',
41
- };
42
- const UNICODE = {
43
- '∧': '/\\', '∨': '\\/', '¬': '~', '∈': '\\in', '∉': '\\notin', '⇒': '=>', '≡': '<=>', '⇔': '<=>', '≠': '/=', '≤': '<=',
44
- '≥': '>=', '∪': '\\cup', '∩': '\\cap', '⊆': '\\subseteq', '×': '\\X', '∀': '\\A', '∃': '\\E', '□': '[]', '◇': '<>',
45
- '↦': '|->', '→': '->', '←': '<-', '≜': '==', '⟨': '<<', '⟩': '>>', '∘': '\\o', '÷': '\\div', '⊂': '\\subset',
46
- '⊃': '\\supset', '⊇': '\\supseteq', '↝': '~>', '‥': '..', '⋅': '\\cdot',
47
- };
48
- const isAlpha = (c) => (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
49
- const isDigit = (c) => c >= 48 && c <= 57;
50
- const isIdChar = (c) => isAlpha(c) || isDigit(c) || c === 95;
51
- export function lex(src, moduleName, intern) {
52
- const toks = [];
53
- if (src.includes('\t')) {
54
- // expand tabs to 8-column tab stops so that junction-list alignment works
55
- src = src.split('\n').map(l => {
56
- if (!l.includes('\t'))
57
- return l;
58
- let o = '';
59
- for (const ch of l)
60
- o += ch === '\t' ? ' '.repeat(8 - (o.length % 8)) : ch;
61
- return o;
62
- }).join('\n');
63
- }
64
- let i = 0;
65
- let line = 1;
66
- let lineStart = 0;
67
- const n = src.length;
68
- // Skip any prelude before the first module header.
69
- const m = /-{4,}[ \t]*MODULE\b/.exec(src);
70
- if (m) {
71
- for (let k = 0; k < m.index; k++)
72
- if (src.charCodeAt(k) === 10) {
73
- line++;
74
- lineStart = k + 1;
75
- }
76
- i = m.index;
77
- }
78
- const push = (t, v, start, end, num) => {
79
- toks.push({ t, v, line, col: start - lineStart + 1, ec: end - lineStart, n: num });
80
- };
81
- while (i < n) {
82
- const c = src.charCodeAt(i);
83
- if (c === 10) {
84
- i++;
85
- line++;
86
- lineStart = i;
87
- continue;
88
- }
89
- if (c === 32 || c === 9 || c === 13 || c === 12) {
90
- i++;
91
- continue;
92
- }
93
- const ch = src[i];
94
- // comments
95
- if (ch === '\\' && src[i + 1] === '*') {
96
- while (i < n && src.charCodeAt(i) !== 10)
97
- i++;
98
- continue;
99
- }
100
- if (ch === '(' && src[i + 1] === '*') {
101
- let depth = 1;
102
- i += 2;
103
- while (i < n && depth > 0) {
104
- const d = src.charCodeAt(i);
105
- if (d === 10) {
106
- line++;
107
- lineStart = i + 1;
108
- i++;
109
- }
110
- else if (d === 40 && src[i + 1] === '*') {
111
- depth++;
112
- i += 2;
113
- }
114
- else if (d === 42 && src[i + 1] === ')') {
115
- depth--;
116
- i += 2;
117
- }
118
- else
119
- i++;
120
- }
121
- continue;
122
- }
123
- const start = i;
124
- // separators / end
125
- if (ch === '-' && src.startsWith('----', i)) {
126
- while (i < n && src[i] === '-')
127
- i++;
128
- push('sep', '----', start, i);
129
- continue;
130
- }
131
- if (ch === '=' && src.startsWith('====', i)) {
132
- while (i < n && src[i] === '=')
133
- i++;
134
- push('end', '====', start, i);
135
- continue;
136
- }
137
- // strings
138
- if (ch === '"') {
139
- i++;
140
- let s = '';
141
- while (i < n && src[i] !== '"') {
142
- if (src[i] === '\\') {
143
- const e = src[i + 1];
144
- s += e === 'n' ? '\n' : e === 't' ? '\t' : e === 'r' ? '\r' : e === 'f' ? '\f' : e;
145
- i += 2;
146
- }
147
- else if (src.charCodeAt(i) === 10) {
148
- throw new TlaError('Unterminated string', [line, start - lineStart + 1, line, i - lineStart], moduleName, 'parse');
149
- }
150
- else
151
- s += src[i++];
152
- }
153
- i++;
154
- push('str', s, start, i);
155
- continue;
156
- }
157
- // numbers and identifiers
158
- if (isIdChar(c)) {
159
- while (i < n && isIdChar(src.charCodeAt(i)))
160
- i++;
161
- let word = src.slice(start, i);
162
- if (/^\d+$/.test(word)) {
163
- // decimal?
164
- if (src[i] === '.' && isDigit(src.charCodeAt(i + 1))) {
165
- i++;
166
- while (i < n && isDigit(src.charCodeAt(i)))
167
- i++;
168
- word = src.slice(start, i);
169
- push('num', word, start, i, Number(word));
170
- }
171
- else
172
- push('num', word, start, i, Number(word));
173
- continue;
174
- }
175
- if ((word.startsWith('WF_') || word.startsWith('SF_'))) {
176
- i = start + 3;
177
- push('kw', word.slice(0, 3), start, i);
178
- continue;
179
- }
180
- if (word === '_') {
181
- push('op', '_', start, i);
182
- continue;
183
- }
184
- if (intern)
185
- intern(word);
186
- push(KEYWORDS.has(word) ? 'kw' : 'id', word, start, i);
187
- continue;
188
- }
189
- if (ch === '\\') {
190
- const nx = src[i + 1];
191
- if (nx === '/') {
192
- i += 2;
193
- push('op', '\\/', start, i);
194
- continue;
195
- }
196
- if ((nx === 'b' || nx === 'B' || nx === 'o' || nx === 'O' || nx === 'h' || nx === 'H') && /[0-9a-fA-F]/.test(src[i + 2] ?? '')) {
197
- const radix = nx === 'b' || nx === 'B' ? 2 : nx === 'o' || nx === 'O' ? 8 : 16;
198
- const re = radix === 2 ? /[01]/ : radix === 8 ? /[0-7]/ : /[0-9a-fA-F]/;
199
- let j = i + 2;
200
- while (j < n && re.test(src[j]))
201
- j++;
202
- if (j > i + 2 && !isIdChar(src.charCodeAt(j))) {
203
- const v = parseInt(src.slice(i + 2, j), radix);
204
- i = j;
205
- push('num', String(v), start, i, v);
206
- continue;
207
- }
208
- }
209
- if (nx && isAlpha(nx.charCodeAt(0))) {
210
- i++;
211
- while (i < n && isAlpha(src.charCodeAt(i)))
212
- i++;
213
- const w = src.slice(start, i);
214
- push('op', CANON[w] ?? w, start, i);
215
- continue;
216
- }
217
- i++;
218
- push('op', '\\', start, i);
219
- continue;
220
- }
221
- // proof step tokens: <1>, <1>2., <*>, <+>
222
- if (ch === '<') {
223
- const sm = /^<(\d+|\*|\+)>[A-Za-z0-9_]*\.*/.exec(src.slice(i, i + 80));
224
- if (sm) {
225
- i += sm[0].length;
226
- push('step', sm[0], start, i);
227
- continue;
228
- }
229
- }
230
- const cands = SYM_BY_CHAR.get(ch);
231
- let matched = false;
232
- if (cands) {
233
- for (const s of cands) {
234
- if (src.startsWith(s, i)) {
235
- i += s.length;
236
- push('op', CANON[s] ?? s, start, i);
237
- matched = true;
238
- break;
239
- }
240
- }
241
- }
242
- if (matched)
243
- continue;
244
- const u = UNICODE[ch];
245
- if (u) {
246
- i++;
247
- push('op', u, start, i);
248
- continue;
249
- }
250
- i++;
251
- push('bad', ch, start, i);
252
- }
253
- toks.push({ t: 'eof', v: '<EOF>', line, col: 0, ec: 0 });
254
- return toks;
255
- }
@@ -1,80 +0,0 @@
1
- import type { Node } from './parser.ts';
2
- import type { Model } from './model.ts';
3
- import { Checker } from './checker.ts';
4
- import type { CheckResult, CheckOptions } from './checker.ts';
5
- import type { Ctx } from './eval.ts';
6
- interface LE {
7
- t: 'bool' | 'atom' | 'not' | 'and' | 'or' | 'always' | 'eventually';
8
- lvl: number;
9
- v?: boolean;
10
- e?: Node;
11
- ctx?: Ctx | null;
12
- id?: number;
13
- as?: LE[];
14
- a?: LE;
15
- }
16
- export declare class Liveness {
17
- model: Model;
18
- checker: Checker;
19
- atomIds: Map<Node, Map<Ctx | null, number>>;
20
- atoms: LE[];
21
- constructor(model: Model, checker: Checker);
22
- atom(e: Node, ctx: Ctx | null, lvl: number): LE;
23
- toLive(e: Node, ctx: Ctx | null): LE;
24
- pushNeg(x: LE, neg: boolean): LE;
25
- simp(x: LE): LE;
26
- dnf(x: LE): LE[][];
27
- key(x: LE): string;
28
- S: number;
29
- eStart: Int32Array;
30
- eTo: Int32Array;
31
- eAct: Int32Array;
32
- eState: (any[] | undefined)[] | null;
33
- stateCache: Map<string, Uint8Array<ArrayBufferLike>>;
34
- edgeCache: Map<string, Uint8Array<ArrayBufferLike>>;
35
- buildGraph(): void;
36
- evalLE(x: LE, s: number, e: number): boolean;
37
- groups: Map<string, {
38
- tf: LE;
39
- pems: {
40
- aeState: LE[];
41
- aeAction: LE[];
42
- ea: LE[];
43
- }[];
44
- }> | null;
45
- prepare(): number;
46
- tautology: boolean;
47
- check(): CheckResult | null;
48
- hasAction(x: LE): boolean;
49
- buildTableau(tf: LE): {
50
- init: number[];
51
- parts: {
52
- preds: LE[];
53
- succ: number[];
54
- set: Set<number>;
55
- }[];
56
- promises: {
57
- ev: number;
58
- body: number;
59
- }[];
60
- };
61
- checkGroup(tf: LE, pems: {
62
- aeState: LE[];
63
- aeAction: LE[];
64
- ea: LE[];
65
- }[]): CheckResult | null;
66
- checkComponent(members: number[], comp: Int32Array, cid: number, pems: {
67
- aeState: LE[];
68
- aeAction: LE[];
69
- ea: LE[];
70
- }[], edgeOk: (n: number, j: number) => boolean, tb: ReturnType<Liveness['buildTableau']>, nState: number[], nPart: number[], adj: number[][], adjEdge: number[][], initNodes: number[]): CheckResult | null;
71
- counterexample(members: number[], comp: Int32Array, cid: number, targets: {
72
- node: number;
73
- edge: number;
74
- }[], edgeOk: (n: number, j: number) => boolean, nState: number[], adj: number[][], adjEdge: number[][], initNodes: number[]): CheckResult;
75
- }
76
- export declare function modelCheck(model: Model, opts: CheckOptions): {
77
- result: CheckResult;
78
- checker: Checker;
79
- };
80
- export {};