@skillstech/thunderlang 1.8.0 → 2.0.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 +78 -1
- package/README.md +5 -0
- package/dist/core.cjs +73 -25
- package/dist/index.cjs +1230 -519
- package/dist/learn.cjs +89 -32
- package/package.json +17 -15
- package/src/cli-main.mjs +186 -151
- package/src/core/ThunderRuntime.cs +22 -1
- package/src/core/check.mjs +8 -0
- package/src/core/engine-core.mjs +7 -0
- package/src/core/engine-values.mjs +2 -0
- package/src/core/from-python.mjs +1 -1
- package/src/core/go-run.mjs +3 -1
- package/src/core/index.mjs +7 -2
- package/src/core/java/thunder/ThunderRuntime.java +1 -0
- package/src/core/kind.mjs +3 -0
- package/src/core/parser.mjs +22 -21
- package/src/core/project.mjs +21 -0
- package/src/core/runtime-go/thunder_runtime.go +41 -1
- package/src/core/rust/thunder_runtime.rs +1 -0
- package/src/core/target-csharp.mjs +14 -0
- package/src/core/target-go.mjs +14 -0
- package/src/core/target-java.mjs +14 -0
- package/src/core/target-python.mjs +8 -0
- package/src/core/target-rust.mjs +14 -0
- package/src/core/target-typescript.mjs +14 -0
- package/src/core-changes-fs.mjs +1 -1
- package/src/emit.mjs +3 -3
- package/src/evidence-words.d.mts +6 -0
- package/src/evidence-words.mjs +47 -0
- package/src/evidence.mjs +8 -1
- package/src/index.d.ts +15 -0
- package/src/index.mjs +4 -1
- package/src/learn-lessons.mjs +1 -1
- package/src/lsp.mjs +110 -0
- package/src/mcp.mjs +5 -9
- package/src/obligations.d.mts +5 -0
- package/src/obligations.mjs +30 -2
- package/src/program.d.mts +3 -0
- package/src/program.mjs +3 -0
- package/src/review.mjs +6 -3
- package/src/same.mjs +16 -6
- package/src/scan-queries.mjs +2 -1
- package/src/symbols.d.mts +23 -0
- package/src/symbols.mjs +351 -0
- package/src/template.d.mts +31 -0
- package/src/template.mjs +189 -0
package/dist/learn.cjs
CHANGED
|
@@ -17253,7 +17253,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
|
|
|
17253
17253
|
var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
|
|
17254
17254
|
|
|
17255
17255
|
// src/emit.mjs
|
|
17256
|
-
var COMPILER_VERSION = "
|
|
17256
|
+
var COMPILER_VERSION = "2.0.0";
|
|
17257
17257
|
|
|
17258
17258
|
// src/lift.mjs
|
|
17259
17259
|
var IR_SCHEMA_VERSION = "0.1.0";
|
|
@@ -34147,6 +34147,18 @@ ${model.settings.map((x) => ` Setting ${x.name}: ${settingWords(x, model)} (li
|
|
|
34147
34147
|
return { ...base2, ...about, language: member ?? thing ? member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null : model.files[0]?.language ?? null };
|
|
34148
34148
|
}
|
|
34149
34149
|
|
|
34150
|
+
// src/evidence-words.mjs
|
|
34151
|
+
var EVIDENCE_LEVELS = ["proven", "tested", "partial", "unverified", "violated"];
|
|
34152
|
+
function combineEvidence(levels) {
|
|
34153
|
+
const ls = [...levels].filter((l) => EVIDENCE_LEVELS.includes(l));
|
|
34154
|
+
if (!ls.length) return "unverified";
|
|
34155
|
+
if (ls.includes("violated")) return "violated";
|
|
34156
|
+
if (ls.every((l) => l === "proven")) return "proven";
|
|
34157
|
+
if (ls.every((l) => l === "proven" || l === "tested")) return "tested";
|
|
34158
|
+
if (ls.every((l) => l === "unverified")) return "unverified";
|
|
34159
|
+
return "partial";
|
|
34160
|
+
}
|
|
34161
|
+
|
|
34150
34162
|
// src/same.mjs
|
|
34151
34163
|
var SAME_SCHEMA = "thunder-same-v1";
|
|
34152
34164
|
var MAX_CASES = 4096;
|
|
@@ -34230,7 +34242,9 @@ function comparePlainRules(a, b) {
|
|
|
34230
34242
|
}
|
|
34231
34243
|
const bAsA = { ...b, inputs: b.inputs.map((i) => ({ ...i, id: toA.get(key(i)) })), rules: b.rules.map((r) => ({ ...r, conditions: r.conditions.map((c) => ({ ...c, input: toA.get(key(b.inputs.find((i) => i.id === c.input))) })) })) };
|
|
34232
34244
|
let tried = 0;
|
|
34233
|
-
|
|
34245
|
+
const axes = caseValues([a, bAsA]);
|
|
34246
|
+
const total = axes.reduce((n, [, vs]) => n * Math.max(1, vs.length), 1);
|
|
34247
|
+
for (const values of product(axes)) {
|
|
34234
34248
|
if (++tried > MAX_CASES) {
|
|
34235
34249
|
tried--;
|
|
34236
34250
|
break;
|
|
@@ -34238,7 +34252,7 @@ function comparePlainRules(a, b) {
|
|
|
34238
34252
|
const x = explainPlain(a, values).outcome, y = explainPlain(bAsA, values).outcome;
|
|
34239
34253
|
if (x !== y) return { same: false, tried, counterexample: { values: { ...values }, facts: a.inputs.map((i) => `${i.label} ${i.kind === "yesno" ? values[i.id] ? i.yes ?? "yes" : i.no ?? "no" : values[i.id]}`).join(", "), old: x, new: y } };
|
|
34240
34254
|
}
|
|
34241
|
-
return { same: true, tried };
|
|
34255
|
+
return { same: true, tried, total, ...total > tried ? { capped: true } : {} };
|
|
34242
34256
|
}
|
|
34243
34257
|
var SYNTAX = new Set("const let var val final auto def fn func function return await async new public private protected static self this my local export mut ref out in of for foreach if elif elsif while do then end each as range".split(" "));
|
|
34244
34258
|
var OPS4 = { "&&": "and", "||": "or", "!": "not", "===": "==", "!==": "!=", "<>": "!=", "**": "^", and: "and", or: "or", not: "not", is: "==", None: "null", nil: "null", undefined: "null", NULL: "null", nullptr: "null", True: "true", False: "false" };
|
|
@@ -34261,7 +34275,7 @@ function compareItems(o, n) {
|
|
|
34261
34275
|
if (o.kind === "decision") {
|
|
34262
34276
|
const r = compareRules(o, n);
|
|
34263
34277
|
if (!r) return { status: "cannot-check", reason: "One rule could not be drawn as a card, so its answers could not be compared.", ...where2 };
|
|
34264
|
-
if (r.same) return { status: "same", reason: `Same answer on all ${r.tried} edge cases.`, ...where2 };
|
|
34278
|
+
if (r.same) return { status: "same", reason: r.capped ? `Same answer on the first ${r.tried} of ${r.total} edge cases (the rest were not tried).` : `Same answer on all ${r.tried} edge cases.`, ...where2 };
|
|
34265
34279
|
if (r.counterexample) {
|
|
34266
34280
|
const facts = r.counterexample.facts;
|
|
34267
34281
|
return { status: "different", reason: `Different answer for ${facts}: ${r.counterexample.old} before, ${r.counterexample.new} after.`, counterexample: r.counterexample, ...where2 };
|
|
@@ -34294,9 +34308,13 @@ function sameMeaning(oldFiles, newFiles) {
|
|
|
34294
34308
|
}
|
|
34295
34309
|
for (const [key, n] of B.items) if (!used.has(key)) items.push({ name: n.name, status: "only-new", reason: "New: not in the old code.", new: { file: n.file, line: n.line, language: n.language } });
|
|
34296
34310
|
const counts = { same: 0, different: 0, "only-old": 0, "only-new": 0, "cannot-check": 0 };
|
|
34297
|
-
for (const it of items)
|
|
34311
|
+
for (const it of items) {
|
|
34312
|
+
counts[it.status]++;
|
|
34313
|
+
it.evidence = it.status === "same" ? /edge cases/.test(it.reason) ? "tested" : "partial" : it.status === "cannot-check" ? "unverified" : "violated";
|
|
34314
|
+
}
|
|
34298
34315
|
const verdict = counts.different || counts["only-old"] || counts["only-new"] ? "different" : counts["cannot-check"] ? "partly-checked" : "same";
|
|
34299
|
-
|
|
34316
|
+
const evidence = combineEvidence(items.map((it) => it.evidence));
|
|
34317
|
+
return { schema: SAME_SCHEMA, verdict, evidence, counts, items, unreadable: [...A.unreadable, ...B.unreadable] };
|
|
34300
34318
|
}
|
|
34301
34319
|
|
|
34302
34320
|
// src/learn-lessons.mjs
|
|
@@ -35259,7 +35277,7 @@ var WRITE_LESSONS = [
|
|
|
35259
35277
|
prompt: "Every test passed. Does the passport say the change works in production?",
|
|
35260
35278
|
choices: ["No: deployment is always listed as not verified", "Yes"],
|
|
35261
35279
|
expect: "No: deployment is always listed as not verified",
|
|
35262
|
-
explain: "Tests
|
|
35280
|
+
explain: "Tests show what they ran, on the machine they ran on. How it is deployed, real outside services, more than one machine, and heavy load are listed as not verified unless a claim covers them.",
|
|
35263
35281
|
check: ({ passport }) => passport.unknowns.notVerified.some((x) => /^Deployment/.test(x)) ? "No: deployment is always listed as not verified" : "Yes"
|
|
35264
35282
|
}
|
|
35265
35283
|
],
|
|
@@ -35883,7 +35901,7 @@ var ExprParser = class {
|
|
|
35883
35901
|
const ak = this.longest(run, (key) => this.names.alts.has(key));
|
|
35884
35902
|
if (ak && !this.longest(run, (key) => this.names.known.has(key))) {
|
|
35885
35903
|
s.i += ak;
|
|
35886
|
-
return wrap2({ k: "isAlt", e: l, alt: keyOf(run.slice(0, ak)), text: run.slice(0, ak).map((x) => x.text).join(" "), line });
|
|
35904
|
+
return wrap2({ k: "isAlt", e: l, alt: keyOf(run.slice(0, ak)), text: run.slice(0, ak).map((x) => x.text).join(" "), col: run[0].col, line });
|
|
35887
35905
|
}
|
|
35888
35906
|
}
|
|
35889
35907
|
return { k: "cmp", op: neg2 ? "!=" : "==", l, r: this.add(s, o), line };
|
|
@@ -35936,7 +35954,7 @@ var ExprParser = class {
|
|
|
35936
35954
|
if (!run.length) s.fail(`I expected a field name after "'s".`, null, "TC108");
|
|
35937
35955
|
const k = this.longest(run, (key) => this.names.fields.has(key)) || run.length;
|
|
35938
35956
|
s.i -= run.length - k;
|
|
35939
|
-
e = { k: "field", obj: e, name: keyOf(run.slice(0, k)), text: run.slice(0, k).map((w) => w.text).join(" "), line: s.line };
|
|
35957
|
+
e = { k: "field", obj: e, name: keyOf(run.slice(0, k)), text: run.slice(0, k).map((w) => w.text).join(" "), col: run[0].col, line: s.line };
|
|
35940
35958
|
} else if (isWord(t, "at") && !isWord(s.peek(1), "least") && !isWord(s.peek(1), "most")) {
|
|
35941
35959
|
s.next();
|
|
35942
35960
|
const key = this.unary(s, { ...o, noAnd: true });
|
|
@@ -36038,7 +36056,7 @@ var ExprParser = class {
|
|
|
36038
36056
|
if (!k) s.fail(`I don't know the kind of value "${run.map((x) => x.text).join(" ")}".`, 'Kinds: number, whole number, text, yes/no, money, date, list of \u2026, map of \u2026 to \u2026, optional \u2026, or a record you defined with "A \u2026 has:".', "TC306");
|
|
36039
36057
|
s.i -= run.length - k;
|
|
36040
36058
|
const key = keyOf(run.slice(0, k));
|
|
36041
|
-
return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, "") };
|
|
36059
|
+
return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, ""), col: run[0].col, line: s.line };
|
|
36042
36060
|
}
|
|
36043
36061
|
/** The fields a record is built with: with name "Ann" and balance $10 (none without "with"). */
|
|
36044
36062
|
recordFields(s, line) {
|
|
@@ -36203,14 +36221,14 @@ var ExprParser = class {
|
|
|
36203
36221
|
const rk = this.longest(run.slice(i), (key) => recs.includes(key));
|
|
36204
36222
|
if (!rk || i + rk !== run.length) continue;
|
|
36205
36223
|
s.i -= run.length - i - rk;
|
|
36206
|
-
const node = { k: "new", record: keyOf(run.slice(i, i + rk)), alt, altText: run.slice(0, i).map((x) => x.text).join(" "), fields: this.recordFields(s, line), line };
|
|
36224
|
+
const node = { k: "new", record: keyOf(run.slice(i, i + rk)), alt, altText: run.slice(0, i).map((x) => x.text).join(" "), altCol: run[0].col, recordCol: run[i].col, fields: this.recordFields(s, line), line };
|
|
36207
36225
|
return node;
|
|
36208
36226
|
}
|
|
36209
36227
|
for (let i = 1; i < run.length; i++) {
|
|
36210
36228
|
const rk = this.longest(run.slice(i), (key) => this.names.altsOf.has(key));
|
|
36211
36229
|
if (!rk || i + rk !== run.length) continue;
|
|
36212
36230
|
s.i -= run.length - i - rk;
|
|
36213
|
-
return { k: "new", record: keyOf(run.slice(i, i + rk)), alt: keyOf(run.slice(0, i)), altText: run.slice(0, i).map((x) => x.text).join(" "), fields: this.recordFields(s, line), line };
|
|
36231
|
+
return { k: "new", record: keyOf(run.slice(i, i + rk)), alt: keyOf(run.slice(0, i)), altText: run.slice(0, i).map((x) => x.text).join(" "), altCol: run[0].col, recordCol: run[i].col, fields: this.recordFields(s, line), line };
|
|
36214
36232
|
}
|
|
36215
36233
|
}
|
|
36216
36234
|
let off = run[0]?.lower === "new" && run.length > 1 ? 1 : 0;
|
|
@@ -36220,7 +36238,7 @@ var ExprParser = class {
|
|
|
36220
36238
|
s.i -= run.length - off - recK;
|
|
36221
36239
|
const name = keyOf(run.slice(off, off + recK));
|
|
36222
36240
|
const fields = this.recordFields(s, line);
|
|
36223
|
-
const node = { k: "new", record: name, fields, line };
|
|
36241
|
+
const node = { k: "new", record: name, recordCol: run[off].col, fields, line };
|
|
36224
36242
|
if (!fields.length && this.open) this.open.push(node);
|
|
36225
36243
|
return node;
|
|
36226
36244
|
}
|
|
@@ -36235,20 +36253,21 @@ var ExprParser = class {
|
|
|
36235
36253
|
const key = keyOf(run.slice(0, k));
|
|
36236
36254
|
const text2 = run.slice(0, k).map((x) => x.text).join(" ");
|
|
36237
36255
|
if (this.names.known.get(key) === "func") {
|
|
36238
|
-
|
|
36239
|
-
if (s.
|
|
36240
|
-
|
|
36256
|
+
const col = run[0].col;
|
|
36257
|
+
if (isSym(s.peek(), "(")) return { k: "call", name: key, text: text2, col, args: this.parenArgs(s), line };
|
|
36258
|
+
if (s.word("with")) return { k: "call", name: key, text: text2, col, args: this.withArgs(s), line };
|
|
36259
|
+
const node = { k: "call", name: key, text: text2, col, args: [], line, bare: true };
|
|
36241
36260
|
if (this.open) this.open.push(node);
|
|
36242
36261
|
return node;
|
|
36243
36262
|
}
|
|
36244
|
-
return { k: "name", name: key, text: text2, line };
|
|
36263
|
+
return { k: "name", name: key, text: text2, col: run[0].col, line };
|
|
36245
36264
|
}
|
|
36246
36265
|
const fk = this.longest(run, (key) => this.names.fields.has(key));
|
|
36247
36266
|
if (fk) {
|
|
36248
36267
|
s.i -= run.length - fk;
|
|
36249
|
-
return { k: "name", name: keyOf(run.slice(0, fk)), text: run.slice(0, fk).map((x) => x.text).join(" "), line, unknown: true };
|
|
36268
|
+
return { k: "name", name: keyOf(run.slice(0, fk)), text: run.slice(0, fk).map((x) => x.text).join(" "), col: run[0].col, line, unknown: true };
|
|
36250
36269
|
}
|
|
36251
|
-
return { k: "name", name: keyOf(run), text: run.map((x) => x.text).join(" "), line, unknown: true };
|
|
36270
|
+
return { k: "name", name: keyOf(run), text: run.map((x) => x.text).join(" "), col: run[0]?.col, line, unknown: true };
|
|
36252
36271
|
}
|
|
36253
36272
|
};
|
|
36254
36273
|
function parseCore(source, { seed = null } = {}) {
|
|
@@ -36369,7 +36388,7 @@ function nameWords2(ts, line, what) {
|
|
|
36369
36388
|
if (t.t !== "word") throw new CoreError(diag("TC105", line, `A name can only use words, but "${show(t)}" is not a word.`));
|
|
36370
36389
|
if (RESERVED2.has(t.lower)) throw new CoreError(diag("TC202", line, `A name can't contain the word "${t.text}", because it belongs to Thunder.`, `Try a name without "${t.text}".`));
|
|
36371
36390
|
}
|
|
36372
|
-
return { name: keyOf(words13), text: words13.map((x) => x.text).join(" ") };
|
|
36391
|
+
return { name: keyOf(words13), text: words13.map((x) => x.text).join(" "), col: words13[0].col };
|
|
36373
36392
|
}
|
|
36374
36393
|
function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
36375
36394
|
const ts = n.tokens;
|
|
@@ -36467,8 +36486,8 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36467
36486
|
otherwise = sub2;
|
|
36468
36487
|
continue;
|
|
36469
36488
|
}
|
|
36470
|
-
const { name, text: text2 } = nameWords2(ct.slice(0, -1), c.line, "A case");
|
|
36471
|
-
cases.push({ alt: name, text: text2, body: sub2, line: c.line });
|
|
36489
|
+
const { name, text: text2, col } = nameWords2(ct.slice(0, -1), c.line, "A case");
|
|
36490
|
+
cases.push({ alt: name, text: text2, col, body: sub2, line: c.line });
|
|
36472
36491
|
} catch (e2) {
|
|
36473
36492
|
if (e2 instanceof CoreError) diagnostics.push(e2.diagnostic);
|
|
36474
36493
|
else throw e2;
|
|
@@ -36518,7 +36537,7 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36518
36537
|
}
|
|
36519
36538
|
if (w0 === "to" && isSym(ts[ts.length - 1], ":")) {
|
|
36520
36539
|
if (!ctx.top) fail2("TC402", 'A "To" block (a function) must be written at the left edge, not inside another block.');
|
|
36521
|
-
const { name, text: text2 } = nameWords2(header().slice(1), line, '"To"');
|
|
36540
|
+
const { name, text: text2, col } = nameWords2(header().slice(1), line, '"To"');
|
|
36522
36541
|
const kids2 = n.children;
|
|
36523
36542
|
let params = [];
|
|
36524
36543
|
let bodyNodes = kids2;
|
|
@@ -36529,7 +36548,7 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36529
36548
|
r++;
|
|
36530
36549
|
}
|
|
36531
36550
|
bodyNodes = kids2.slice(r);
|
|
36532
|
-
return { k: "func", name, text: text2, params, body: parseBlock(bodyNodes, ep, names, diagnostics, { inFunc: true }), line };
|
|
36551
|
+
return { k: "func", name, text: text2, col, params, body: parseBlock(bodyNodes, ep, names, diagnostics, { inFunc: true }), line };
|
|
36533
36552
|
}
|
|
36534
36553
|
if (w0 === "receive") fail2("TC111", '"Receive" must be the first line inside a "To" block or a "Screen".');
|
|
36535
36554
|
if (w0 === "screen" && isSym(ts[ts.length - 1], ":")) {
|
|
@@ -36544,7 +36563,7 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36544
36563
|
if (w0 === "show") fail2("TC118", '"Show" is used inside a "Screen" (a screen shows things). In a program, write: Say \u2026');
|
|
36545
36564
|
if ((w0 === "a" || w0 === "an") && isOneOf(ts)) {
|
|
36546
36565
|
if (!ctx.top) fail2("TC402", 'A data type ("A \u2026 is one of:") must be written at the left edge, not inside another block.');
|
|
36547
|
-
const { name, text: text2 } = nameWords2(ts.slice(1, -4), line, "A data type");
|
|
36566
|
+
const { name, text: text2, col } = nameWords2(ts.slice(1, -4), line, "A data type");
|
|
36548
36567
|
const alts = [];
|
|
36549
36568
|
for (const c of n.children) {
|
|
36550
36569
|
try {
|
|
@@ -36567,11 +36586,11 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36567
36586
|
const opt2 = (t) => t.k === "optional" ? t : { k: "optional", of: t };
|
|
36568
36587
|
const fields = [{ name: "which", text: "which", type: { k: "text" }, line, hidden: true }];
|
|
36569
36588
|
for (const a of alts) for (const f of a.fields) if (!fields.some((x) => x.name === f.name)) fields.push({ ...f, type: opt2(f.type) });
|
|
36570
|
-
return { k: "record", name, text: text2, fields, rules: [], alts, line };
|
|
36589
|
+
return { k: "record", name, text: text2, col, fields, rules: [], alts, line };
|
|
36571
36590
|
}
|
|
36572
36591
|
if ((w0 === "a" || w0 === "an") && isWord(ts[ts.length - 2], "has") && isSym(ts[ts.length - 1], ":")) {
|
|
36573
36592
|
if (!ctx.top) fail2("TC402", 'A record ("A \u2026 has:") must be written at the left edge, not inside another block.');
|
|
36574
|
-
const { name, text: text2 } = nameWords2(ts.slice(1, -2), line, "A record");
|
|
36593
|
+
const { name, text: text2, col } = nameWords2(ts.slice(1, -2), line, "A record");
|
|
36575
36594
|
const fields = [], rules = [];
|
|
36576
36595
|
for (const c of n.children) {
|
|
36577
36596
|
try {
|
|
@@ -36587,7 +36606,7 @@ function parseStatement2(n, ep, names, diagnostics, ctx, siblings) {
|
|
|
36587
36606
|
else throw e2;
|
|
36588
36607
|
}
|
|
36589
36608
|
}
|
|
36590
|
-
return { k: "record", name, text: text2, fields, rules, line };
|
|
36609
|
+
return { k: "record", name, text: text2, col, fields, rules, line };
|
|
36591
36610
|
}
|
|
36592
36611
|
if (w0 === "expect") return { ...parseExpect(rest2, line, ep), raw: n.raw };
|
|
36593
36612
|
if (w0 === "never") return parseNever(ts, line, ep);
|
|
@@ -37527,6 +37546,10 @@ var Checker = class {
|
|
|
37527
37546
|
if (s.targetKind === "list" && known(tt.of) && known(te) && !compatible(tt.of, te)) this.err("TC303", line, `This list holds ${typeWords4(tt.of)}, so ${typeWords4(te)} can't be added to it.`);
|
|
37528
37547
|
if (s.k === "add" && s.targetKind === "list" && !known(tt.of) && known(te) && s.target.k === "name" && s.target.ref?.type?.k === "list") s.target.ref.type = T("list", { of: te });
|
|
37529
37548
|
this.afterAssign(s, s.target, sc);
|
|
37549
|
+
if (s.targetKind === "list" || s.targetKind === "map" && s.k === "remove") {
|
|
37550
|
+
const watched = s.target.k === "name" ? s.rules?.length > 0 : s.target.k === "field" && (this.records.get(s.target.record)?.rulesToCheck ?? []).some((r) => r.subject === s.target.name);
|
|
37551
|
+
if (watched && s.targetKind === "list") s.guard = true;
|
|
37552
|
+
}
|
|
37530
37553
|
return;
|
|
37531
37554
|
}
|
|
37532
37555
|
case "increase":
|
|
@@ -37922,6 +37945,7 @@ var Checker = class {
|
|
|
37922
37945
|
case "field": {
|
|
37923
37946
|
const ot = this.ex(e.obj, sc, o);
|
|
37924
37947
|
const r = ot.k === "record" ? this.records.get(ot.name) : null;
|
|
37948
|
+
if (r) e.record = r.name;
|
|
37925
37949
|
if (r?.altMap && e.name !== "which" && r.fieldMap.has(e.name)) {
|
|
37926
37950
|
const alt = this.narrowed(e.obj);
|
|
37927
37951
|
const a = alt ? r.altMap.get(alt) : null;
|
|
@@ -38814,6 +38838,14 @@ ${body2.join("\n").replace(/\n{4,}/g, "\n\n\n")}
|
|
|
38814
38838
|
case "remove": {
|
|
38815
38839
|
const v = this.x(s.e).c;
|
|
38816
38840
|
const target = this.lv(s.target);
|
|
38841
|
+
if (s.guard) {
|
|
38842
|
+
const copy = `_copy_${s.line}_`;
|
|
38843
|
+
this.emit(`${copy} = list(${target})`, L);
|
|
38844
|
+
this.emit(s.k === "add" ? `${copy}.append(${v})` : `${this.R("remove_from")}(${copy}, ${v})`, L);
|
|
38845
|
+
if (s.target.k === "name") this.assign(s, target, copy);
|
|
38846
|
+
else this.store(s.target, copy, L);
|
|
38847
|
+
return;
|
|
38848
|
+
}
|
|
38817
38849
|
if (s.targetKind === "list") this.emit(s.k === "add" ? `${target}.append(${v})` : `${this.R("remove_from")}(${target}, ${v})`, L);
|
|
38818
38850
|
else if (s.targetKind === "map") this.emit(`${this.R("remove_from")}(${target}, ${v})`, L);
|
|
38819
38851
|
else if (s.targetKind === "number") {
|
|
@@ -40360,8 +40392,8 @@ def run_tests(modules):
|
|
|
40360
40392
|
`;
|
|
40361
40393
|
|
|
40362
40394
|
// src/core/index.mjs
|
|
40363
|
-
function
|
|
40364
|
-
|
|
40395
|
+
function seedFrom(imported = []) {
|
|
40396
|
+
return imported.length ? {
|
|
40365
40397
|
known: imported.flatMap((r) => [...r.program.names.known].filter(([, kind]) => kind !== "var")),
|
|
40366
40398
|
fields: imported.flatMap((r) => [...r.program.names.fields]),
|
|
40367
40399
|
records: imported.flatMap((r) => [...r.program.names.records]),
|
|
@@ -40370,6 +40402,9 @@ function compileCore(source, { file = "main.thunder", imported = [], srcModules
|
|
|
40370
40402
|
alts: imported.flatMap((r) => [...r.program.names.alts ?? []]),
|
|
40371
40403
|
altsOf: imported.flatMap((r) => [...r.program.names.altsOf ?? []])
|
|
40372
40404
|
} : null;
|
|
40405
|
+
}
|
|
40406
|
+
function compileCore(source, { file = "main.thunder", imported = [], srcModules = [] } = {}) {
|
|
40407
|
+
const seed = seedFrom(imported);
|
|
40373
40408
|
const program = parseCore(source, { seed });
|
|
40374
40409
|
const { diagnostics, info } = checkCore(program, { imported: imported.map((r) => r.info) });
|
|
40375
40410
|
const ok = diagnostics.length === 0;
|
|
@@ -41330,6 +41365,14 @@ function addTo(target, value) {
|
|
|
41330
41365
|
}
|
|
41331
41366
|
return add(target, value);
|
|
41332
41367
|
}
|
|
41368
|
+
function copyList(target) {
|
|
41369
|
+
if (!Array.isArray(target)) throw attrErr(target, "append");
|
|
41370
|
+
return [...target];
|
|
41371
|
+
}
|
|
41372
|
+
function appendTo(target, value) {
|
|
41373
|
+
if (!Array.isArray(target)) throw attrErr(target, "append");
|
|
41374
|
+
target.push(value);
|
|
41375
|
+
}
|
|
41333
41376
|
function removeFrom(target, value) {
|
|
41334
41377
|
if (target instanceof PyDict) {
|
|
41335
41378
|
if (!target.has(value)) throw MissingValue(`There is no entry for ${show2(value)} to remove.`);
|
|
@@ -42127,6 +42170,14 @@ var Engine = class {
|
|
|
42127
42170
|
const isName2 = s.target.k === "name";
|
|
42128
42171
|
const target = this.x(s.target, env);
|
|
42129
42172
|
const py2 = isName2 ? s.target.ref?.py ?? "unknown" : null;
|
|
42173
|
+
if (s.guard) {
|
|
42174
|
+
const copy = copyList(target);
|
|
42175
|
+
if (s.k === "add") appendTo(copy, v);
|
|
42176
|
+
else this.removeFrom(copy, v);
|
|
42177
|
+
if (isName2) this.assign(s, py2, copy, env);
|
|
42178
|
+
else this.store(s.target, copy, env);
|
|
42179
|
+
return;
|
|
42180
|
+
}
|
|
42130
42181
|
if (s.targetKind === "list") {
|
|
42131
42182
|
if (s.k === "add") {
|
|
42132
42183
|
if (!Array.isArray(target)) throw attrErr(target, "append");
|
|
@@ -43124,7 +43175,7 @@ var FunctionPrinter = class {
|
|
|
43124
43175
|
if (f === "sum" && one) return `the sum of ${paren(this.value(one, item3))}`;
|
|
43125
43176
|
if (f === "min" && one) return `the smallest of ${paren(this.value(one, item3))}`;
|
|
43126
43177
|
if (f === "max" && one) return `the largest of ${paren(this.value(one, item3))}`;
|
|
43127
|
-
if (f === "round") nt("Python round() rounds halves to even; Thunder rounds
|
|
43178
|
+
if (f === "round") nt("Python round() rounds halves to even; Thunder rounds halves away from zero");
|
|
43128
43179
|
if (f === "sorted") return this.sorted(e, item3);
|
|
43129
43180
|
if (f === "abs" && one) return `the absolute value of ${paren(this.value(one, item3))}`;
|
|
43130
43181
|
if ((f === "max" || f === "min") && args.length >= 2) {
|
|
@@ -45129,7 +45180,13 @@ function compareMember(o, n, items, { extracted = false } = {}) {
|
|
|
45129
45180
|
if (o.m.rule && n.m.rule && !o.m.rule.partial && !n.m.rule.partial) {
|
|
45130
45181
|
const r = comparePlainRules(o.m.rule, n.m.rule);
|
|
45131
45182
|
if (r.same) {
|
|
45132
|
-
|
|
45183
|
+
items.push(item2(
|
|
45184
|
+
renamedOrMoved.length ? moveKind : "form",
|
|
45185
|
+
"form",
|
|
45186
|
+
subject,
|
|
45187
|
+
whereOf2(n),
|
|
45188
|
+
`${renamedOrMoved.length ? `${cap5(renamedOrMoved.join(" and "))}. ` : ""}The code changed, but the answers are the same: Tested on ${r.capped ? `the first ${r.tried} of ${r.total}` : `all ${r.tried}`} edge cases, run on both versions (not every input).`
|
|
45189
|
+
));
|
|
45133
45190
|
return "form";
|
|
45134
45191
|
}
|
|
45135
45192
|
noteMove();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Thunder™, the human programming language:
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Thunder™, the human programming language: write programs in plain words and run them as Python, TypeScript, C#, Java, Go, or Rust. The deterministic ThunderLang™ compiler, CLI, and Language Server also read code in seventeen languages as Thunder, explain it in plain English, change TypeScript, JavaScript, Python, and Go code from Thunder with a proof, and review what a change does. No AI required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
@@ -83,27 +83,29 @@
|
|
|
83
83
|
},
|
|
84
84
|
"keywords": [
|
|
85
85
|
"thunder",
|
|
86
|
+
"thunderlang",
|
|
86
87
|
"thunder-programming-language",
|
|
87
88
|
"programming-language",
|
|
89
|
+
"human-readable-code",
|
|
88
90
|
"human-native-programming",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
91
|
+
"visual-programming",
|
|
92
|
+
"programming-education",
|
|
93
|
+
"design-recipe",
|
|
94
|
+
"cross-language",
|
|
92
95
|
"compiler",
|
|
96
|
+
"transpiler",
|
|
97
|
+
"code-generation",
|
|
98
|
+
"code-explanation",
|
|
99
|
+
"python",
|
|
100
|
+
"typescript",
|
|
101
|
+
"java",
|
|
102
|
+
"csharp",
|
|
103
|
+
"golang",
|
|
104
|
+
"rust",
|
|
93
105
|
"cli",
|
|
94
106
|
"language-server",
|
|
95
107
|
"lsp",
|
|
96
|
-
"runtime",
|
|
97
|
-
"executable",
|
|
98
108
|
"verification",
|
|
99
|
-
"contract",
|
|
100
|
-
"proof",
|
|
101
|
-
"decision",
|
|
102
|
-
"dmn",
|
|
103
|
-
"bpmn",
|
|
104
|
-
"openapi",
|
|
105
|
-
"json-schema",
|
|
106
|
-
"intent-graph",
|
|
107
109
|
"ai"
|
|
108
110
|
],
|
|
109
111
|
"homepage": "https://thunderlang.dev",
|