@skillstech/thunderlang 1.2.0 → 1.4.0
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 +190 -0
- package/dist/core.cjs +6718 -1232
- package/dist/index.cjs +17490 -12204
- package/dist/learn.cjs +5866 -497
- package/package.json +6 -2
- package/src/cli-home.mjs +1 -1
- package/src/cli.mjs +54 -6
- package/src/core/ThunderRuntime.cs +1367 -0
- package/src/core/check.mjs +158 -2
- package/src/core/cli.mjs +148 -8
- package/src/core/csharp-run.mjs +184 -0
- package/src/core/diagnostics.mjs +13 -1
- package/src/core/engine-core.mjs +285 -2
- package/src/core/engine-values.mjs +1 -1
- package/src/core/format.mjs +191 -3
- package/src/core/go-run.mjs +106 -0
- package/src/core/index.mjs +2 -1
- package/src/core/java/thunder/T.java +6 -0
- package/src/core/java/thunder/ThunderRuntime.java +1374 -0
- package/src/core/java-run.mjs +89 -0
- package/src/core/parser.mjs +331 -5
- package/src/core/project.mjs +31 -6
- package/src/core/react-run.mjs +96 -0
- package/src/core/runtime-go/thunder_runtime.go +3038 -0
- package/src/core/runtime-react.mjs +133 -0
- package/src/core/rust/thunder_runtime.rs +1645 -0
- package/src/core/rust-run.mjs +192 -0
- package/src/core/screen-values.mjs +30 -0
- package/src/core/target-csharp.mjs +484 -0
- package/src/core/target-go.mjs +555 -0
- package/src/core/target-java.mjs +587 -0
- package/src/core/target-react.mjs +270 -0
- package/src/core/target-rust.mjs +534 -0
- package/src/core/target-typescript.mjs +2 -2
- package/src/core.d.ts +59 -0
- package/src/core.mjs +14 -0
- package/src/emit.mjs +1 -1
- package/src/faithful.mjs +34 -1
- package/src/flow/access.mjs +1451 -0
- package/src/flow/ts-parse.mjs +772 -0
- package/src/index.d.ts +3 -0
- package/src/index.mjs +3 -0
- package/src/libraries.mjs +32 -4
- package/src/model.mjs +72 -9
- package/src/passport-cli.mjs +101 -0
- package/src/passport-fs.d.mts +9 -0
- package/src/passport-fs.mjs +180 -0
- package/src/passport.d.mts +46 -0
- package/src/passport.mjs +255 -0
- package/src/program.d.mts +31 -0
- package/src/program.mjs +14 -0
- package/src/read-level.mjs +48 -2
- package/src/read-repo-fs.mjs +3 -1
- package/src/read.mjs +64 -5
- package/src/replay-cli.mjs +123 -0
- package/src/review.mjs +31 -3
- package/src/say-less.mjs +168 -13
- package/src/screens.mjs +833 -0
- package/src/steps.mjs +443 -20
- package/src/term.mjs +43 -0
- package/src/things-langs.mjs +20 -3
- package/src/write-across-cli.mjs +143 -0
- package/src/write-across.mjs +168 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// thunder_runtime.mjs for compiled React, and its declarations (thunder_runtime.d.mts).
|
|
2
|
+
//
|
|
3
|
+
// One meaning of Thunder: the engine's value code (engine-values.mjs) and the engine's screen code (screen-values.mjs),
|
|
4
|
+
// byte for byte, followed by a small browser part: call frames for error lines, a press (copies in, all or nothing),
|
|
5
|
+
// typing into a box, and the message shown when the app cannot be shown. No Node APIs: it runs in a browser.
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import * as VALUES from './engine-values.mjs';
|
|
8
|
+
import * as SCREEN from './screen-values.mjs';
|
|
9
|
+
|
|
10
|
+
const VALUES_SOURCE = readFileSync(new URL('./engine-values.mjs', import.meta.url), 'utf8');
|
|
11
|
+
// (Its import line names what engine-values.mjs already defined above it.)
|
|
12
|
+
const SCREEN_SOURCE = readFileSync(new URL('./screen-values.mjs', import.meta.url), 'utf8').replace(/^import [^\n]*\n/m, '');
|
|
13
|
+
|
|
14
|
+
const BROWSER_PART = `
|
|
15
|
+
// ── Running compiled React: frames (for error lines), presses, typing, and the app's problems ────────────────────
|
|
16
|
+
import { Component, createElement } from 'react';
|
|
17
|
+
|
|
18
|
+
const frames = [];
|
|
19
|
+
const snapshot = () => frames.map((f) => ({ file: f.file, line: f.line }));
|
|
20
|
+
|
|
21
|
+
/** A frame for a screen being shown, a press, or a kept value. */
|
|
22
|
+
export function enterFrame(file, line) {
|
|
23
|
+
if (frames.length >= MAX_FRAMES) throw new PyErr('RecursionError', 'maximum recursion depth exceeded');
|
|
24
|
+
const f = { file, line };
|
|
25
|
+
frames.push(f);
|
|
26
|
+
return f;
|
|
27
|
+
}
|
|
28
|
+
/** A frame for a call; \`first\` is the Thunder line the function starts on (where Python stops when it is too deep). */
|
|
29
|
+
export function enterCall(file, line, first) {
|
|
30
|
+
if (frames.length >= MAX_FRAMES) {
|
|
31
|
+
const err = new PyErr('RecursionError', 'maximum recursion depth exceeded');
|
|
32
|
+
if (first != null) err.where = [...snapshot(), { file, line: first }];
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
const f = { file, line };
|
|
36
|
+
frames.push(f);
|
|
37
|
+
return f;
|
|
38
|
+
}
|
|
39
|
+
export function leave() { frames.pop(); }
|
|
40
|
+
export function topFrame() { return frames[frames.length - 1]; }
|
|
41
|
+
export function fail(e) { const err = asPyErr(e); if (!err.where) err.where = snapshot(); return err; }
|
|
42
|
+
function withFrame(frame, fn) {
|
|
43
|
+
if (frames.length >= MAX_FRAMES) throw new PyErr('RecursionError', 'maximum recursion depth exceeded');
|
|
44
|
+
frames.push(frame);
|
|
45
|
+
try { return fn(); } catch (e) { throw fail(e); } finally { frames.pop(); }
|
|
46
|
+
}
|
|
47
|
+
export function keyAt(F, get) { const frame = { file: F.file, line: F.line }; return (item) => withFrame(frame, () => get(item)); }
|
|
48
|
+
|
|
49
|
+
/** Say, from a function a screen calls: a screen shows things instead, so it goes to the browser's console. */
|
|
50
|
+
export function say(text) { console.log(text); }
|
|
51
|
+
export function readText(path) { return readTextVia(null, '.', path); }
|
|
52
|
+
|
|
53
|
+
export function recordKind(py, fields, rules = {}) { return { isRecord: true, py, fields, rules }; }
|
|
54
|
+
export function setAttr(obj, name, value) {
|
|
55
|
+
setAttrWith((rec) => { for (const r of rec.cls.rules[name] ?? []) never(r.cond(value), r.text, r.line, value); }, obj, name, value);
|
|
56
|
+
}
|
|
57
|
+
export function setField(obj, key, value) { setFieldWith(setAttr, obj, key, value); }
|
|
58
|
+
export function newRecord(cls, pairs) { return newRecordWith(setAttr, cls, new Map(pairs)); }
|
|
59
|
+
|
|
60
|
+
let startProblem = null;
|
|
61
|
+
/** Work out a file's kept values; if one fails, the app shows why instead of its screen. */
|
|
62
|
+
export function init(file, fn) {
|
|
63
|
+
if (startProblem) return;
|
|
64
|
+
const F = { file, line: 0 };
|
|
65
|
+
try { withFrame(F, () => fn(F)); } catch (e) { startProblem = describeError(asPyErr(e)); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A press: \`steps\` runs on copies of the remembered values (in \`values\`), in its own frame. If every step works, each
|
|
70
|
+
* value is kept (with its setter) and the screen's problem is cleared, then the screen it opened (if any) is shown.
|
|
71
|
+
* If a step fails, nothing is kept and the screen says why.
|
|
72
|
+
*/
|
|
73
|
+
export function press(file, line, setProblem, open, values, setters, steps) {
|
|
74
|
+
let opened = null;
|
|
75
|
+
let next;
|
|
76
|
+
try {
|
|
77
|
+
next = withFrame({ file, line }, () => steps(topFrame(), (screen) => { opened = screen; }, ...values.map(copyValue)));
|
|
78
|
+
} catch (e) {
|
|
79
|
+
setProblem(problemText(e));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setters.forEach((set, k) => set(next[k]));
|
|
83
|
+
setProblem(null);
|
|
84
|
+
if (opened !== null) open(opened);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Typing into a text box: the box's value is the text. */
|
|
88
|
+
export function typeText(text, set, setProblem) { set(String(text)); setProblem(null); }
|
|
89
|
+
/** Typing into a number box: the box's value is the number, or the screen says why the text is not one. */
|
|
90
|
+
export function typeNumber(text, kind, set, setProblem) {
|
|
91
|
+
let v;
|
|
92
|
+
try { v = typedNumber(text, kind); } catch (e) { setProblem(problemText(e)); return; }
|
|
93
|
+
set(v);
|
|
94
|
+
setProblem(null);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Around the app: when a screen can't be shown, it says why (the same message thunder run gives). */
|
|
98
|
+
export class ShowsProblems extends Component {
|
|
99
|
+
constructor(props) { super(props); this.state = { failed: null }; }
|
|
100
|
+
static getDerivedStateFromError(error) { return { failed: describeError(asPyErr(error)) }; }
|
|
101
|
+
componentDidCatch() {}
|
|
102
|
+
render() {
|
|
103
|
+
const failed = startProblem ?? this.state.failed;
|
|
104
|
+
if (failed !== null) return createElement('p', { role: 'alert', className: 'thunder-failed' }, failed);
|
|
105
|
+
return this.props.children;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const BROWSER_EXPORTS = ['enterFrame', 'enterCall', 'leave', 'topFrame', 'fail', 'keyAt', 'say', 'readText', 'recordKind', 'setAttr', 'setField', 'newRecord', 'init', 'press', 'typeText', 'typeNumber'];
|
|
111
|
+
|
|
112
|
+
const HEADER = `// thunder_runtime.mjs: written by the Thunder compiler next to compiled React. It needs only React.
|
|
113
|
+
// The values, rules, and screen behavior here are the Thunder engine's own (engine-values.mjs and screen-values.mjs),
|
|
114
|
+
// so the React app and the Thunder engine show the same screen and change it the same way.
|
|
115
|
+
`;
|
|
116
|
+
|
|
117
|
+
export const REACT_RUNTIME = `${HEADER}\n${VALUES_SOURCE.trimEnd()}\n\n// ── Screens (screen-values.mjs) ──\n${SCREEN_SOURCE.trimEnd()}\n${BROWSER_PART}`;
|
|
118
|
+
|
|
119
|
+
const isClass = (v) => typeof v === 'function' && /^class\b/.test(Function.prototype.toString.call(v));
|
|
120
|
+
|
|
121
|
+
function declarations() {
|
|
122
|
+
const L = ['// thunder_runtime.d.mts: types for thunder_runtime.mjs (written by the Thunder compiler).', '// Thunder values are checked when the program runs; to TypeScript they are of any kind.', ''];
|
|
123
|
+
for (const [name, v] of Object.entries({ ...VALUES, ...SCREEN }).sort(([a], [b]) => a.localeCompare(b))) {
|
|
124
|
+
if (isClass(v)) L.push(`export declare class ${name} { constructor(...args: any[]); [key: string]: any; static [key: string]: any; }`);
|
|
125
|
+
else if (typeof v === 'function') L.push(`export declare function ${name}(...args: any[]): any;`);
|
|
126
|
+
else L.push(`export declare const ${name}: any;`);
|
|
127
|
+
}
|
|
128
|
+
for (const f of BROWSER_EXPORTS) L.push(`export declare function ${f}(...args: any[]): any;`);
|
|
129
|
+
L.push('export declare const ShowsProblems: any;');
|
|
130
|
+
return `${L.join('\n')}\n`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const REACT_RUNTIME_DTS = declarations();
|