gdp-wired 0.50.2 → 0.50.3
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/README.md +4 -2
- package/dist/core/cli.d.ts +12 -1
- package/dist/core/cli.js +62 -25
- package/dist/core/discover.d.ts +6 -1
- package/dist/core/discover.js +54 -7
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +26 -2
- package/dist/core/dsl.d.ts +3 -1
- package/dist/core/dsl.js +93 -30
- package/dist/core/effect.d.ts +12 -0
- package/dist/core/effect.js +26 -9
- package/dist/core/ex/harness.exs +171 -5
- package/dist/core/extract-c.js +63 -6
- package/dist/core/extract-check.d.ts +5 -1
- package/dist/core/extract-check.js +28 -10
- package/dist/core/extract-go-check.js +127 -1
- package/dist/core/extract-go.js +8 -2
- package/dist/core/extract-jvm.js +2 -2
- package/dist/core/extract-rs.js +51 -5
- package/dist/core/extract-step.js +40 -6
- package/dist/core/extract-swift.js +47 -3
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/infer.d.ts +8 -0
- package/dist/core/infer.js +133 -16
- package/dist/core/jvm/Harness.java +135 -3
- package/dist/core/jvm/Rt.java +66 -4
- package/dist/core/laws.js +51 -10
- package/dist/core/native-law.d.ts +3 -1
- package/dist/core/native-law.js +126 -14
- package/dist/core/native-observations.d.ts +20 -0
- package/dist/core/native-observations.js +41 -0
- package/dist/core/native-wire.d.ts +1 -0
- package/dist/core/native-wire.js +16 -2
- package/dist/core/py/harness.py +21 -4
- package/dist/core/rb/harness.rb +178 -9
- package/dist/core/search-termination.d.ts +35 -0
- package/dist/core/search-termination.js +13 -0
- package/dist/core/search-watchdog.d.ts +8 -0
- package/dist/core/search-watchdog.js +34 -0
- package/dist/core/source-check.d.ts +3 -0
- package/dist/core/swift/Harness.swift +65 -4
- package/dist/core/swift/Main.swift +27 -4
- package/dist/core/wall.d.ts +3 -1
- package/dist/core/wall.js +7 -4
- package/dist/core/work-refusal.d.ts +3 -0
- package/dist/core/work-refusal.js +8 -0
- package/dist/kernel/prove.d.ts +2 -0
- package/dist/kernel/prove.js +13 -5
- package/package.json +1 -1
package/dist/core/extract-c.js
CHANGED
|
@@ -238,6 +238,32 @@ export function harnessC(file, c, read, opts, cpp) {
|
|
|
238
238
|
set.push(`if ((v = gdp_key(st, ${k}))) { if (!strncmp(v, "true", 4)) ${a} = ${T(l.t).nullflag ? '(void *)1' : '1'}; else if (!strncmp(v, "false", 5)) ${a} = 0; else return "${l.name}: not a boolean"; }`);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
+
const nativeTree = { children: new Map() };
|
|
242
|
+
for (const leaf of read.leaves)
|
|
243
|
+
if (['int', 'bool', 'list'].includes(leaf.kind)) {
|
|
244
|
+
let node = nativeTree;
|
|
245
|
+
for (const f of leaf.path) {
|
|
246
|
+
if (!node.children.has(f))
|
|
247
|
+
node.children.set(f, { children: new Map() });
|
|
248
|
+
node = node.children.get(f);
|
|
249
|
+
}
|
|
250
|
+
node.leaf = leaf;
|
|
251
|
+
}
|
|
252
|
+
const emit = (s) => `gdp_putf("%s", ${q(s)});`;
|
|
253
|
+
const nativeInt = (a, t) => T(t).signed === false ? `gdp_putf("%llu", (unsigned long long)(${a}));` : `gdp_putf("%lld", (long long)(${a}));`;
|
|
254
|
+
const nativeNode = (node, path) => {
|
|
255
|
+
const a = path.length ? acc(path) : '(*o)', l = node.leaf;
|
|
256
|
+
if (l?.kind === 'int')
|
|
257
|
+
return nativeInt(a, l.t);
|
|
258
|
+
if (l?.kind === 'bool')
|
|
259
|
+
return T(l.t).nullflag ? `if (${a}) gdp_native_bad = "unsupported native pointer field"; gdp_putf("null");` : `gdp_putf("%s", ${a} ? "true" : "false");`;
|
|
260
|
+
if (l?.kind === 'list') {
|
|
261
|
+
const t = T(l.t), et = T(t.elem);
|
|
262
|
+
return `${emit('{"kind":"array","id":"')} gdp_putf("%llu", gdp_native_id((const void *)&${a}, ${q(`array:${path.join('.')}`)})); ${emit('","items":[')} for (int ni = 0; ni < ${t.len}; ni++) { if (ni) gdp_putf(","); ${et.k === 'int' ? nativeInt(`${a}[ni]`, t.elem) : `gdp_putf("%s", ${a}[ni] ? "true" : "false");`} } ${emit(']}')}`;
|
|
263
|
+
}
|
|
264
|
+
return `${emit('{"kind":"object","id":"')} gdp_putf("%llu", gdp_native_id((const void *)&${a}, ${q(`object:${path.join('.')}`)})); ${emit('","items":[')} ${[...node.children].map(([f, child], i) => `${emit(`${i ? ',' : ''}[${q(f)},`)} ${nativeNode(child, [...path, f])} ${emit(']')}`).join(' ')} ${emit(']}')}`;
|
|
265
|
+
};
|
|
266
|
+
const nativeState = nativeNode(nativeTree, []);
|
|
241
267
|
const frames = read.leaves.filter(l => l.kind === 'frame' && !T(l.t).mutex);
|
|
242
268
|
// (a field left out that points to an object other code owns, a buffer: a zeroed one of its own, as the code's setup
|
|
243
269
|
// would give)
|
|
@@ -277,6 +303,16 @@ export function harnessC(file, c, read, opts, cpp) {
|
|
|
277
303
|
else
|
|
278
304
|
lines.push(`return "an argument the harness can't make";`);
|
|
279
305
|
});
|
|
306
|
+
const nativeArgs = meth.params.map((pa, i) => {
|
|
307
|
+
const t = T(pa.t), a = `a${i}`;
|
|
308
|
+
const scalar = (v, ty) => T(ty).k === 'int' ? nativeInt(v, ty) : T(ty).k === 'bool' ? `gdp_putf("%s", ${v} ? "true" : "false");` : 'gdp_native_bad = "unsupported native parameter type"; gdp_putf("null");';
|
|
309
|
+
const body = pa.arg.k === 'input' ? scalar(a, pa.t) : pa.arg.k === 'rec'
|
|
310
|
+
? `${emit('{"kind":"object","id":"')} gdp_putf("%llu", ++gdp_native_next); ${emit('","items":[')} ${(t.k === 'ptr' && T(t.elem).box ? [['value', T(t.elem).fields[0].t, a]] : pa.arg.fields.map(([f]) => { const st = t.k === 'ptr' ? T(t.elem) : t; return [f, st.fields.find(g => g.name === f).t, `${a}.${f}`]; })).map(([f, ft, v], j) => `${emit(`${j ? ',' : ''}[${q(f)},`)} ${scalar(v, ft)} ${emit(']')}`).join(' ')} ${emit(']}')}`
|
|
311
|
+
: 'gdp_native_bad = "unsupported native parameter shape"; gdp_putf("null");';
|
|
312
|
+
return `${emit(`${i ? ',' : ''}[${q(pa.name)},`)} ${body} ${emit(']')}`;
|
|
313
|
+
}).join(' ');
|
|
314
|
+
// These are the converted native locals BEFORE invocation/reassignment.
|
|
315
|
+
const bindings = `${emit(',"nativeBindings":{"snapshot":{"version":1,"root":{"kind":"object","id":"')} gdp_putf("%llu", ++gdp_native_next); ${emit('","items":[')} ${nativeArgs} ${emit(']}}')} if (gdp_native_bad) { ${emit(',"error":"')} gdp_putf("%s", gdp_native_bad); ${emit('"')} } ${emit('}')}`;
|
|
280
316
|
const rt = meth.results[0], fails = opts.fails?.[meth.name]?.trim();
|
|
281
317
|
const callee = G ? `${meth.name}(${args.slice(1).join(', ')})` : cpp ? `o->${meth.name}(${args.slice(1).join(', ')})` : `${meth.name}(${args.join(', ')})`;
|
|
282
318
|
const invoke = rt === undefined ? `${callee};` : `${cpp ? 'auto' : T(rt).go} r0 = ${callee}; gdp_has = 1; ${T(rt).k === 'int' ? `gdp_outv = ${T(rt).signed === false ? '(long long)' : ''}r0; gdp_outu = ${T(rt).signed === false ? 1 : 0};` : 'gdp_outb = r0; gdp_isb = 1;'}`;
|
|
@@ -284,7 +320,7 @@ export function harnessC(file, c, read, opts, cpp) {
|
|
|
284
320
|
// (with out-parameters, the result is a record: the value returned and what each holds)
|
|
285
321
|
const rec = outs.length ? `gdp_rec = 1; gdp_putf(",\\"out\\":{"); ${[...(rt !== undefined ? [['result', 'r0', rt]] : []), ...outs].map(([n, v, et], j) => `gdp_putf("${j ? ',' : ''}\\"${n}\\":"); ${T(et).k === 'int' ? `gdp_putf(${T(et).signed === false ? '"%llu", (unsigned long long)' : '"%lld", (long long)'}(${v}))` : `gdp_putf("%s", ${v} ? "true" : "false")`};`).join(' ')} gdp_putf("},\\"hasOut\\":true");` : '';
|
|
286
322
|
const load = G ? `gdp_load(o); ${given.map(([n, a]) => `memcpy((void *)&${n}, (const void *)&${a}, sizeof ${n});`).join(' ')}\n ` : '';
|
|
287
|
-
return `if (!strcmp(m, ${q(meth.name)})) {\n ${lines.join('\n ')}\n memcpy(gdp_pre, (void *)o, sizeof(gdp_T));\n ${load}int sg = sigsetjmp(gdp_jb, 1);\n if (!sg) { gdp_armed = 1; gdp_watch(1); ${cpp ? 'try { ' : ''}${invoke} ${failed} gdp_watch(0); gdp_armed = 0; ${rec}${cpp ? ' } catch (...) { gdp_watch(0); gdp_armed = 0; gdp_sig = SIGUSR2; }' : ''} } else { gdp_watch(0); gdp_sig = sg; }\n ${G ? 'gdp_store(o);\n ' : ''}return gdp_after(o);\n }`;
|
|
323
|
+
return `if (!strcmp(m, ${q(meth.name)})) {\n ${lines.join('\n ')}\n ${bindings}\n memcpy(gdp_pre, (void *)o, sizeof(gdp_T));\n ${load}int sg = sigsetjmp(gdp_jb, 1);\n if (!sg) { gdp_armed = 1; gdp_watch(1); ${cpp ? 'try { ' : ''}${invoke} ${failed} gdp_watch(0); gdp_armed = 0; ${rec}${cpp ? ' } catch (...) { gdp_watch(0); gdp_armed = 0; gdp_sig = SIGUSR2; }' : ''} } else { gdp_watch(0); gdp_sig = sg; }\n ${G ? 'gdp_store(o);\n ' : ''}return gdp_after(o);\n }`;
|
|
288
324
|
});
|
|
289
325
|
const frameLines = frames.map(l => { const e = acc(l.path); return `if (memcmp((char *)&${e}, (char *)gdp_pre + ((char *)&${e} - (char *)o), sizeof ${e})) return ${q(l.path.join('.'))};`; });
|
|
290
326
|
// The object, made as the code makes it: C's zeroed; C++'s constructed (in zeroed memory) with the rule's parameters.
|
|
@@ -329,9 +365,22 @@ static unsigned char gdp_pre[sizeof(gdp_T)];
|
|
|
329
365
|
${robs.length ? `template <typename Tag, auto M> struct gdp_rob { friend auto gdp_ptr(Tag) { return M; } };\n${robs.map((k, i) => `struct gdp_tag${i} { friend auto gdp_ptr(gdp_tag${i}); };\ntemplate struct gdp_rob<gdp_tag${i}, ${k}>;`).join('\n')}` : ''}
|
|
330
366
|
static char *gdp_buf; static size_t gdp_n, gdp_cap;
|
|
331
367
|
static void gdp_putf(const char *f, ...) {
|
|
332
|
-
va_list ap; va_start(ap, f);
|
|
333
|
-
if (
|
|
334
|
-
|
|
368
|
+
va_list ap, copy; va_start(ap, f); va_copy(copy, ap); int k = vsnprintf(0, 0, f, copy); va_end(copy);
|
|
369
|
+
if (k < 0 || gdp_n > (size_t)-1 - (size_t)k - 1) abort();
|
|
370
|
+
size_t need = gdp_n + (size_t)k + 1;
|
|
371
|
+
if (need > gdp_cap) { gdp_cap = need <= (size_t)-1 / 2 ? need * 2 : need; char *next = (char *)realloc(gdp_buf, gdp_cap); if (!next) abort(); gdp_buf = next; }
|
|
372
|
+
vsnprintf(gdp_buf + gdp_n, gdp_cap - gdp_n, f, ap); va_end(ap); gdp_n += (size_t)k;
|
|
373
|
+
}
|
|
374
|
+
// Stable identities for original native storage and typed field views.
|
|
375
|
+
static unsigned long long gdp_native_next;
|
|
376
|
+
static const char *gdp_native_bad;
|
|
377
|
+
struct gdp_native_ident { const void *address; const char *view; unsigned long long id; };
|
|
378
|
+
static struct gdp_native_ident *gdp_native_ids; static size_t gdp_native_count;
|
|
379
|
+
static unsigned long long gdp_native_id(const void *address, const char *view) {
|
|
380
|
+
for (size_t i = 0; i < gdp_native_count; i++) if (gdp_native_ids[i].address == address && !strcmp(gdp_native_ids[i].view, view)) return gdp_native_ids[i].id;
|
|
381
|
+
if (gdp_native_count >= 100000) { gdp_native_bad = "native identity bound exceeded"; return 1; }
|
|
382
|
+
gdp_native_ids = (struct gdp_native_ident *)realloc(gdp_native_ids, (gdp_native_count + 1) * sizeof *gdp_native_ids);
|
|
383
|
+
struct gdp_native_ident *entry = &gdp_native_ids[gdp_native_count++]; entry->address = address; entry->view = view; entry->id = ++gdp_native_next; return entry->id;
|
|
335
384
|
}
|
|
336
385
|
static const char *gdp_ws(const char *p) { while (*p == ' ' || *p == '\\t' || *p == '\\n' || *p == '\\r') p++; return p; }
|
|
337
386
|
static const char *gdp_skip(const char *p) {
|
|
@@ -372,6 +421,12 @@ static void gdp_get(gdp_T *o) {
|
|
|
372
421
|
${get.join('\n ')}
|
|
373
422
|
gdp_putf("}");
|
|
374
423
|
}
|
|
424
|
+
static void gdp_native(gdp_T *o) {
|
|
425
|
+
gdp_native_bad = 0;
|
|
426
|
+
${emit('{"snapshot":{"version":1,"root":')} ${nativeState} ${emit('}')}
|
|
427
|
+
if (gdp_native_bad) { ${emit(',"error":"')} gdp_putf("%s", gdp_native_bad); ${emit('"')} }
|
|
428
|
+
${emit('}')}
|
|
429
|
+
}
|
|
375
430
|
static const char *gdp_set(gdp_T *o, const char *st) {
|
|
376
431
|
const char *v; (void)v; (void)o; (void)st;
|
|
377
432
|
${set.join('\n ')}
|
|
@@ -403,7 +458,7 @@ static const char *gdp_after(gdp_T *o) {
|
|
|
403
458
|
${make}
|
|
404
459
|
static const char *gdp_call(gdp_T *o, const char *m, const char *a) {
|
|
405
460
|
const char *v; (void)v; (void)a;
|
|
406
|
-
gdp_sig = gdp_err = gdp_has = gdp_outu = gdp_isb = gdp_rec = 0; gdp_outv = 0;
|
|
461
|
+
gdp_sig = gdp_err = gdp_has = gdp_outu = gdp_isb = gdp_rec = 0; gdp_outv = 0; gdp_native_bad = 0;
|
|
407
462
|
${calls.join('\n ')}
|
|
408
463
|
return "no such function";
|
|
409
464
|
}
|
|
@@ -425,7 +480,9 @@ int main(int argc, char **argv) {
|
|
|
425
480
|
const char *op = gdp_key(line, "op"), *id = gdp_key(line, "id");
|
|
426
481
|
long long k = 0; unsigned long long ku; if (id) gdp_int(id, 64, 1, &k, &ku);
|
|
427
482
|
gdp_n = 0;
|
|
428
|
-
if (op && !strncmp(op, "
|
|
483
|
+
if (op && !strncmp(op + 1, "hello", 5) && op[6] == '"') { ${emit('{"nativeSnapshot":1,"nativeBindings":1,"nativeEquality":"scalar"}')} }
|
|
484
|
+
else if (op && !strncmp(op + 1, "native", 6) && op[7] == '"') { gdp_native(objs[k - 1]); }
|
|
485
|
+
else if (op && !strncmp(op, "\\"new\\"", 5)) { const char *bad = 0; gdp_T *o = gdp_make(line, &bad); if (!o) gdp_putf("{\\"bad\\":\\"%s\\"}", bad); else { objs = (gdp_T **)realloc(objs, ++nobj * sizeof *objs); objs[nobj - 1] = o; gdp_putf("{\\"id\\":%zu}", nobj); } }
|
|
429
486
|
else if (op && !strncmp(op, "\\"at\\"", 4)) {
|
|
430
487
|
const char *bad = 0; gdp_T *o = gdp_make(line, &bad); const char *st = gdp_key(line, "state");
|
|
431
488
|
if (o) bad = st ? gdp_set(o, st) : "no state";
|
|
@@ -6,6 +6,7 @@ import * as I from './extract-ir.js';
|
|
|
6
6
|
import type { B, N } from './extract-ir.js';
|
|
7
7
|
import type { Sorts } from './extract-print.js';
|
|
8
8
|
import { type NativeInputs } from './native-domain.js';
|
|
9
|
+
import { type NativeExecutionObservation } from './native-observations.js';
|
|
9
10
|
type Raw = number | boolean | string;
|
|
10
11
|
export type Arm = {
|
|
11
12
|
label: string;
|
|
@@ -49,7 +50,7 @@ export declare function instrument(code: string, file: string, tail?: string, ex
|
|
|
49
50
|
export type Sandbox = {
|
|
50
51
|
ctx: Context;
|
|
51
52
|
counts: number[];
|
|
52
|
-
call: (f: string, self: unknown, args: unknown[]) => {
|
|
53
|
+
call: (f: string, self: unknown, args: unknown[], housekeeping?: boolean) => {
|
|
53
54
|
ok: true;
|
|
54
55
|
value: unknown;
|
|
55
56
|
} | {
|
|
@@ -59,6 +60,7 @@ export type Sandbox = {
|
|
|
59
60
|
setNow: (n: number) => void;
|
|
60
61
|
get: (name: string) => unknown;
|
|
61
62
|
bindings: (method: string) => Record<string, unknown> | undefined;
|
|
63
|
+
observations: () => NativeExecutionObservation;
|
|
62
64
|
};
|
|
63
65
|
export declare function sandbox(code: string, file: string, expose: string[], modules?: Record<string, unknown>, init?: string, files?: Record<string, string>, extra?: [number, string][], nativeMethods?: string[]): Sandbox & {
|
|
64
66
|
arms: Arm[];
|
|
@@ -125,6 +127,8 @@ export type CodeSide = {
|
|
|
125
127
|
coverage: () => Coverage;
|
|
126
128
|
nativeState?: (self: unknown, snap: Snap, params: Record<string, Raw>) => unknown;
|
|
127
129
|
nativeBindings?: (event: Ev) => Record<string, unknown> | undefined;
|
|
130
|
+
nativeObservations?: (event: Ev) => NativeExecutionObservation | undefined;
|
|
131
|
+
nativeEquality?: 'scalar';
|
|
128
132
|
nativeInputs?: NativeInputs;
|
|
129
133
|
input?: (v: Var, x: Raw, rand: Rand) => Raw;
|
|
130
134
|
drawSnap?: (rand: Rand) => Snap;
|
|
@@ -24,6 +24,7 @@ import { normalize, resolveIn, sameLazyRoot, scriptKind } from "./extract-read.j
|
|
|
24
24
|
import * as I from "./extract-ir.js";
|
|
25
25
|
import { nativeSnapshot, rememberNative } from "./source-check.js";
|
|
26
26
|
import { nativeCaptureEdits, nativeInputs } from "./native-domain.js";
|
|
27
|
+
import { validateNativeObservations } from "./native-observations.js";
|
|
27
28
|
// The check's own failure, not the code's: a request past its time, the harness's transport (anvil's JSON-RPC) failing,
|
|
28
29
|
// the harness gone. Never a difference and never a pass: the whole check runs once more, from a fresh harness, and a
|
|
29
30
|
// second failure is the check's outcome (Evidence.harness).
|
|
@@ -98,7 +99,7 @@ export function sandbox(code, file, expose, modules = {}, init, files = {}, extr
|
|
|
98
99
|
const { js, arms } = instrument(code, file, init ? `\n;(globalThis as any).__gdpInit = () => (${init});\n` : '', [...nativeCaptureEdits(code, file, nativeMethods), ...extra]);
|
|
99
100
|
const captured = new Map(), captureErrors = new Map();
|
|
100
101
|
const counts = arms.map(() => 0);
|
|
101
|
-
let now = 0;
|
|
102
|
+
let now = 0, invocation = 0, observedClock, observing = false;
|
|
102
103
|
const stub = (name) => new Proxy({}, {
|
|
103
104
|
get: (_, k) => { if (k === '__esModule' || typeof k === 'symbol')
|
|
104
105
|
return undefined; throw new Error(`the check loads no module ${name} (its ${String(k)} was read)`); },
|
|
@@ -106,7 +107,8 @@ export function sandbox(code, file, expose, modules = {}, init, files = {}, extr
|
|
|
106
107
|
});
|
|
107
108
|
const module = { exports: {} };
|
|
108
109
|
const ctx = vm.createContext({
|
|
109
|
-
__cov: (i) => { counts[i]++; }, __now: () =>
|
|
110
|
+
__cov: (i) => { counts[i]++; }, __now: () => { if (observing)
|
|
111
|
+
observedClock = now; return now; }, module, exports: module.exports,
|
|
110
112
|
__gdp_native_capture: (name, value) => {
|
|
111
113
|
if (captured.has(name) || captureErrors.has(name))
|
|
112
114
|
return;
|
|
@@ -156,12 +158,16 @@ export function sandbox(code, file, expose, modules = {}, init, files = {}, extr
|
|
|
156
158
|
vm.runInContext(`${js}\n;globalThis.__gdp = {${expose.map(n => { if (n === 'default')
|
|
157
159
|
return 'default: module.exports.default'; const [h, ...rest] = n.split('.'); return `${JSON.stringify(n)}: (typeof ${h} !== 'undefined' ? ${h} : module.exports.${h})${rest.map(x => `.${x}`).join('')}`; }).join(', ')}};`, ctx, { timeout: 2000, filename: file });
|
|
158
160
|
const script = new vm.Script('globalThis.__r = (() => { try { return {ok: true, value: __gdp[__f].apply(__self, __args)} } catch (e) { return {ok: false, error: String(e && e.message || e)} } })()');
|
|
159
|
-
const call = (f, self, args) => {
|
|
161
|
+
const call = (f, self, args, housekeeping = false) => {
|
|
160
162
|
// Reading/restoring a factory's closure is harness work, not a new request.
|
|
161
|
-
|
|
163
|
+
const request = !housekeeping;
|
|
164
|
+
if (request) {
|
|
162
165
|
captured.clear();
|
|
163
166
|
captureErrors.clear();
|
|
167
|
+
invocation++;
|
|
168
|
+
observedClock = undefined;
|
|
164
169
|
}
|
|
170
|
+
observing = request;
|
|
165
171
|
Object.assign(ctx, { __f: f, __self: self, __args: args });
|
|
166
172
|
try {
|
|
167
173
|
script.runInContext(ctx, { timeout: 1000 });
|
|
@@ -171,9 +177,12 @@ export function sandbox(code, file, expose, modules = {}, init, files = {}, extr
|
|
|
171
177
|
throw new HarnessFailure(`a request ran past the check's 1000 ms (${e.message})`);
|
|
172
178
|
throw e;
|
|
173
179
|
}
|
|
180
|
+
finally {
|
|
181
|
+
observing = false;
|
|
182
|
+
}
|
|
174
183
|
return ctx.__r;
|
|
175
184
|
};
|
|
176
|
-
return { ctx, counts, arms, call, setNow: n => { now = n; }, get: name => vm.runInContext(`__gdp[${JSON.stringify(name)}]`, ctx),
|
|
185
|
+
return { ctx, counts, arms, call, observations: () => validateNativeObservations({ invocation, calls: {}, ...(observedClock === undefined ? {} : { clock: observedClock }) }, new Set()), setNow: n => { now = n; }, get: name => vm.runInContext(`__gdp[${JSON.stringify(name)}]`, ctx),
|
|
177
186
|
bindings: method => { if (captureErrors.has(method))
|
|
178
187
|
throw new Error(captureErrors.get(method)); return captured.get(method); } };
|
|
179
188
|
}
|
|
@@ -442,7 +451,7 @@ function checkOnce(code, file, m, r, sorts, opts) {
|
|
|
442
451
|
}
|
|
443
452
|
// An object a factory makes: its state is what its functions close over, read and set through the two functions the
|
|
444
453
|
// check added to it.
|
|
445
|
-
const stateOf = (self) => (m.factory ? box.call('$get', self, []).value : self);
|
|
454
|
+
const stateOf = (self) => (m.factory ? box.call('$get', self, [], true).value : self);
|
|
446
455
|
const evalAt = (env) => (t) => evalTerm(t, env);
|
|
447
456
|
// The arms of the code the step reads (the entry, its methods, the functions it inlines; a class's constructor too).
|
|
448
457
|
const inSpan = (a) => !m.spans || m.spans.some(([s0, e0]) => a.pos >= s0 && a.pos < e0);
|
|
@@ -461,6 +470,7 @@ function checkOnce(code, file, m, r, sorts, opts) {
|
|
|
461
470
|
const side = {
|
|
462
471
|
nativeState: (self, snap, params) => standalone ? {} : isClass ? stateOf(self) : valueOf(snap, m.layout, m, evalAt(params), box.ctx),
|
|
463
472
|
nativeBindings: e => box.bindings(e.call),
|
|
473
|
+
nativeObservations: () => box.observations(),
|
|
464
474
|
...(standalone ? { nativeInputs: nativeInputs(code, file, m.entry, opts.files) } : {}),
|
|
465
475
|
make: params => {
|
|
466
476
|
const now0 = m.params.find(v => v.note?.startsWith('Date.now()'));
|
|
@@ -469,7 +479,7 @@ function checkOnce(code, file, m, r, sorts, opts) {
|
|
|
469
479
|
// A Map the constructor is given: an empty one, made in the code's realm.
|
|
470
480
|
return box.call('$new', undefined, (m.ctorArgs ?? []).filter(n => n !== now0?.name).map(n => ctorValue(n, params)));
|
|
471
481
|
},
|
|
472
|
-
at: (snap, params) => (box.call('$at', undefined, [valueOf(snap, m.layout, m, evalAt(params), box.ctx), ctorValues(params)]).ok ? box.ctx.__r.value : (() => { throw new Error(`could not make the object: ${box.ctx.__r.error}`); })()),
|
|
482
|
+
at: (snap, params) => (box.call('$at', undefined, [valueOf(snap, m.layout, m, evalAt(params), box.ctx), ctorValues(params)], true).ok ? box.ctx.__r.value : (() => { throw new Error(`could not make the object: ${box.ctx.__r.error}`); })()),
|
|
473
483
|
snapOf: (self, params) => snapOf(stateOf(self), m.layout, m, evalAt(params)),
|
|
474
484
|
call: (self, e, args) => {
|
|
475
485
|
if (standalone)
|
|
@@ -548,7 +558,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
548
558
|
const recordInitial = (side, params) => {
|
|
549
559
|
const state = capture(() => nativeState(side, params));
|
|
550
560
|
if (journal.enabled && !journal.reason)
|
|
551
|
-
journal.observations.push({ where: 'initial native state', before: state, after: state, params: { ...params }, inputs: {}, bindings: {}, args: [], result: undefined, failed: false });
|
|
561
|
+
journal.observations.push({ where: 'initial native state', before: state, after: state, params: { ...params }, inputs: {}, bindings: {}, args: [], result: undefined, failed: false, ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}) });
|
|
552
562
|
};
|
|
553
563
|
const paramKinds = m.params.map(v => [v, kindOfVar(v, sorts)]), inputKinds = m.inputs.map(v => [v, kindOfVar(v, sorts)]);
|
|
554
564
|
const fail = (what) => { ev.mismatch = what; return finish(); };
|
|
@@ -766,6 +776,9 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
766
776
|
const bindings = capture(() => code.nativeBindings?.(e));
|
|
767
777
|
if (code.nativeBindings && !bindings)
|
|
768
778
|
journal.reason ??= `native parameter capture unavailable for ${e.call}`;
|
|
779
|
+
const observed = capture(() => code.nativeObservations ? nativeSnapshot(code.nativeObservations(e)) : undefined);
|
|
780
|
+
if (code.nativeObservations && !observed)
|
|
781
|
+
journal.reason ??= `native execution observations unavailable for ${e.call}`;
|
|
769
782
|
const fallback = Object.create(null);
|
|
770
783
|
e.names?.forEach((n, i) => {
|
|
771
784
|
const value = nativeArgs?.[i];
|
|
@@ -776,7 +789,7 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
776
789
|
});
|
|
777
790
|
const rk = m.results?.[e.call];
|
|
778
791
|
journal.observations.push({ where, method: e.call, before, after, params: { ...params }, inputs: { ...inputs }, bindings: bindings ?? fallback,
|
|
779
|
-
args: nativeArgs ?? [], result, failed: false, legacyResult: !standalone && rk?.k === 'rec' && rk.fields.some(([field]) => field === 'value') });
|
|
792
|
+
args: nativeArgs ?? [], result, failed: false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}), legacyResult: !standalone && rk?.k === 'rec' && rk.fields.some(([field]) => field === 'value') });
|
|
780
793
|
}
|
|
781
794
|
next.side = afterSide;
|
|
782
795
|
next.st = rule.st;
|
|
@@ -1035,9 +1048,14 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
1035
1048
|
return;
|
|
1036
1049
|
}
|
|
1037
1050
|
const result = capture(() => nativeSnapshot(returned.value)), savedArgs = capture(() => nativeSnapshot(args));
|
|
1051
|
+
const observed = capture(() => code.nativeObservations ? nativeSnapshot(code.nativeObservations(event)) : undefined);
|
|
1052
|
+
if (code.nativeObservations && !observed) {
|
|
1053
|
+
journal.reason ??= 'independent native execution observations unavailable';
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1038
1056
|
if (!journal.reason)
|
|
1039
1057
|
journal.observations.push({ where: `exhaustive native input ${++ordinal}`, method: event.call,
|
|
1040
|
-
before: {}, after: {}, params: {}, inputs: {}, bindings, args: savedArgs, result, failed: false });
|
|
1058
|
+
before: {}, after: {}, params: {}, inputs: {}, bindings, args: savedArgs, result, failed: false, ...(observed ? { observed } : {}), ...(code.nativeEquality ? { nativeEquality: code.nativeEquality } : {}) });
|
|
1041
1059
|
return;
|
|
1042
1060
|
}
|
|
1043
1061
|
for (const value of finite[at])
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Outside, constantsOf, draw, drive, evalTerm } from "./extract-check.js";
|
|
2
2
|
import { buildCheck, builtEvidence, compileLimit, openHarness, stopped, stubbed } from "./extract-step.js";
|
|
3
3
|
import { node } from "./extract-go.js";
|
|
4
|
+
import { nativeWireDecoder, snapshotNativeBindings } from "./native-wire.js";
|
|
4
5
|
// --- the harness ------------------------------------------------------------------------------------------------------
|
|
5
6
|
// Go source beside the package: a state set from JSON and read back as JSON, leaf by leaf; each method called with its
|
|
6
7
|
// arguments made from JSON; a panic recovered; the left-out fields compared before and after.
|
|
@@ -67,6 +68,24 @@ function harness(pkg, read, m, discard) {
|
|
|
67
68
|
case 'sink': break;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
71
|
+
const nativeTree = { children: new Map(), leaf: false };
|
|
72
|
+
for (const l of read.leaves)
|
|
73
|
+
if (!['bignil', 'mapnil', 'frame', 'sink'].includes(l.kind)) {
|
|
74
|
+
let node = nativeTree;
|
|
75
|
+
for (const f of l.path) {
|
|
76
|
+
if (!node.children.has(f))
|
|
77
|
+
node.children.set(f, { children: new Map(), leaf: false });
|
|
78
|
+
node = node.children.get(f);
|
|
79
|
+
}
|
|
80
|
+
node.leaf = true;
|
|
81
|
+
}
|
|
82
|
+
const nativeNode = (node, path) => {
|
|
83
|
+
const value = path.length ? `o.${path.join('.')}` : 'o';
|
|
84
|
+
if (node.leaf)
|
|
85
|
+
return `e.value(reflect.ValueOf(${value}))`;
|
|
86
|
+
return `e.record(reflect.ValueOf(${path.length ? `&${value}` : value}), func() []any { return []any{${[...node.children].map(([f, child]) => `[]any{${JSON.stringify(f)}, ${nativeNode(child, [...path, f])}}`).join(', ')}} })`;
|
|
87
|
+
};
|
|
88
|
+
const nativeState = nativeNode(nativeTree, []);
|
|
70
89
|
const frames = read.leaves.filter(l => l.kind === 'frame');
|
|
71
90
|
// The methods: their arguments made from JSON (a struct the caller gives: a fresh one with the fields given).
|
|
72
91
|
const calls = [];
|
|
@@ -113,7 +132,8 @@ function harness(pkg, read, m, discard) {
|
|
|
113
132
|
const recv = meth.ptr ? 'o' : '(*o)';
|
|
114
133
|
const invoke = outs.length ? `${outs.join(', ')} := ${recv}.${meth.name}(${argList})` : `${recv}.${meth.name}(${argList})`;
|
|
115
134
|
const keptOut = kept.length ? (T(kept[0]).k === 'int' ? `res.Out = ${intGet('r0', kept[0])}; res.HasOut = true` : 'res.Out = r0; res.HasOut = true') : '';
|
|
116
|
-
|
|
135
|
+
const bindings = `gdpNativeFrame(func(e *gdpNativeEncoder) any { return e.record(reflect.Value{}, func() []any { return []any{${meth.params.map((pa, i) => `[]any{${JSON.stringify(pa.name)}, e.value(reflect.ValueOf(a${i}))}`).join(', ')}} }) })`;
|
|
136
|
+
calls.push(`case ${JSON.stringify(meth.name)}:\n\t\t${lines.join('\n\t\t')}\n\t\tbindings := ${bindings}\n\t\treturn func(res *gdpRes) { res.NativeBindings = bindings; ${invoke}; ${keptOut}${meth.err ? '; if err != nil { res.Err = err.Error() }' : ''} }, nil`);
|
|
117
137
|
}
|
|
118
138
|
const code = `// Generated by gdp-wired's Go check (core/extract-go-check.ts): the package's code is called as it is.
|
|
119
139
|
package ${pkg.package}
|
|
@@ -165,7 +185,93 @@ func gdpAnswer[T any](name string, _ ...any) T {
|
|
|
165
185
|
return v
|
|
166
186
|
}
|
|
167
187
|
` : ''}
|
|
188
|
+
// Native observations are independent of gdpGet's flattened model projection.
|
|
189
|
+
// Keep actual typed values and storage identities alive for the whole harness.
|
|
190
|
+
type gdpNativeKey struct { Type reflect.Type; Kind reflect.Kind; Address uintptr; Len int; Cap int }
|
|
191
|
+
var gdpNativeNext uint64
|
|
192
|
+
var gdpNativeIDs = map[gdpNativeKey]string{}
|
|
193
|
+
var gdpNativeKeep []reflect.Value
|
|
194
|
+
type gdpNativeEncoder struct { seen map[string]bool; nodes int }
|
|
195
|
+
func (e *gdpNativeEncoder) tick() {
|
|
196
|
+
e.nodes++; if e.nodes > 10000 { panic("native snapshot exceeds node bound") }
|
|
197
|
+
}
|
|
198
|
+
func (e *gdpNativeEncoder) identity(v reflect.Value) string {
|
|
199
|
+
var key gdpNativeKey
|
|
200
|
+
if v.IsValid() {
|
|
201
|
+
key.Type, key.Kind = v.Type(), v.Kind()
|
|
202
|
+
switch v.Kind() {
|
|
203
|
+
case reflect.Map: key.Address = uintptr(v.UnsafePointer())
|
|
204
|
+
case reflect.Slice: key.Address, key.Len, key.Cap = v.Pointer(), v.Len(), v.Cap()
|
|
205
|
+
case reflect.Struct, reflect.Array: if v.CanAddr() { key.Address = v.Addr().Pointer() }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if key.Address != 0 { if id, ok := gdpNativeIDs[key]; ok { return id } }
|
|
209
|
+
if len(gdpNativeKeep) >= 100000 || gdpNativeNext >= 1000000 { panic("native snapshot exceeds identity bound") }
|
|
210
|
+
gdpNativeNext++; id := strconv.FormatUint(gdpNativeNext, 10)
|
|
211
|
+
if key.Address != 0 { gdpNativeIDs[key] = id; gdpNativeKeep = append(gdpNativeKeep, v) }
|
|
212
|
+
return id
|
|
213
|
+
}
|
|
214
|
+
func (e *gdpNativeEncoder) container(v reflect.Value, kind string, items func() []any) any {
|
|
215
|
+
id := e.identity(v)
|
|
216
|
+
if e.seen[id] { return map[string]any{"kind":"ref", "id":id} }
|
|
217
|
+
e.seen[id] = true
|
|
218
|
+
return map[string]any{"kind":kind, "id":id, "items":items()}
|
|
219
|
+
}
|
|
220
|
+
func (e *gdpNativeEncoder) record(v reflect.Value, fields func() []any) any {
|
|
221
|
+
e.tick()
|
|
222
|
+
for v.IsValid() && (v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface) { if v.IsNil() { return nil }; v = v.Elem() }
|
|
223
|
+
return e.container(v, "object", fields)
|
|
224
|
+
}
|
|
225
|
+
func (e *gdpNativeEncoder) value(v reflect.Value) any {
|
|
226
|
+
e.tick()
|
|
227
|
+
if !v.IsValid() { return nil }
|
|
228
|
+
if v.Kind() == reflect.Interface { if v.IsNil() { return nil }; return e.value(v.Elem()) }
|
|
229
|
+
if v.Kind() == reflect.Ptr {
|
|
230
|
+
if v.IsNil() { return nil }
|
|
231
|
+
// The exact standard big.Int implementation, never an arbitrary Stringer.
|
|
232
|
+
if v.Type() == reflect.TypeOf((*big.Int)(nil)) {
|
|
233
|
+
n, err := strconv.ParseInt((*big.Int)(v.UnsafePointer()).String(), 10, 64)
|
|
234
|
+
if err != nil || n < -9007199254740991 || n > 9007199254740991 { panic("native big.Int outside exact integer range") }; return n
|
|
235
|
+
}
|
|
236
|
+
return e.value(v.Elem())
|
|
237
|
+
}
|
|
238
|
+
switch v.Kind() {
|
|
239
|
+
case reflect.Bool: return v.Bool()
|
|
240
|
+
case reflect.String: return v.String()
|
|
241
|
+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
242
|
+
n := v.Int(); if n < -9007199254740991 || n > 9007199254740991 { panic("native integer outside exact integer range") }; return n
|
|
243
|
+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
|
244
|
+
n := v.Uint(); if n > 9007199254740991 { panic("native integer outside exact integer range") }; return n
|
|
245
|
+
case reflect.Struct:
|
|
246
|
+
return e.container(v, "object", func() []any {
|
|
247
|
+
items := []any{}; for i := 0; i < v.NumField(); i++ { items = append(items, []any{v.Type().Field(i).Name, e.value(v.Field(i))}) }; return items
|
|
248
|
+
})
|
|
249
|
+
case reflect.Array, reflect.Slice:
|
|
250
|
+
if v.Kind() == reflect.Slice && v.IsNil() { return nil }
|
|
251
|
+
return e.container(v, "array", func() []any {
|
|
252
|
+
items := []any{}; for i := 0; i < v.Len(); i++ { items = append(items, e.value(v.Index(i))) }; return items
|
|
253
|
+
})
|
|
254
|
+
case reflect.Map:
|
|
255
|
+
if v.IsNil() { return nil }
|
|
256
|
+
return e.container(v, "map", func() []any {
|
|
257
|
+
items := []any{}; iter := v.MapRange(); for iter.Next() {
|
|
258
|
+
k := iter.Key(); if k.Kind() != reflect.String && (k.Kind() < reflect.Int || k.Kind() > reflect.Uintptr) { panic("unsupported native map key") }
|
|
259
|
+
items = append(items, []any{e.value(k), e.value(iter.Value())})
|
|
260
|
+
}; return items
|
|
261
|
+
})
|
|
262
|
+
default: panic("unsupported native snapshot kind: " + v.Kind().String())
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
func gdpNativeFrame(root func(*gdpNativeEncoder) any) (frame map[string]any) {
|
|
266
|
+
defer func() { if r := recover(); r != nil { frame = map[string]any{"error":fmt.Sprint(r)} } }()
|
|
267
|
+
e := &gdpNativeEncoder{seen:map[string]bool{}}
|
|
268
|
+
return map[string]any{"snapshot":map[string]any{"version":1, "root":root(e)}}
|
|
269
|
+
}
|
|
270
|
+
func gdpNativeState(o *${read.entry}) map[string]any {
|
|
271
|
+
return gdpNativeFrame(func(e *gdpNativeEncoder) any { return ${nativeState} })
|
|
272
|
+
}
|
|
168
273
|
type gdpRes struct {
|
|
274
|
+
NativeBindings map[string]any \`json:"nativeBindings,omitempty"\`
|
|
169
275
|
State map[string]any \`json:"state,omitempty"\`
|
|
170
276
|
Out any \`json:"out,omitempty"\`
|
|
171
277
|
HasOut bool \`json:"hasOut,omitempty"\`
|
|
@@ -273,6 +379,8 @@ func GdpHarnessMain(in, out string) {
|
|
|
273
379
|
panic(err)
|
|
274
380
|
}
|
|
275
381
|
switch c.Op {
|
|
382
|
+
case "hello": res = map[string]any{"nativeSnapshot":1, "nativeBindings":1, "nativeEquality":"scalar"}
|
|
383
|
+
case "native": res = gdpNativeState(objs[c.ID])
|
|
276
384
|
case "new":
|
|
277
385
|
objs[len(objs)+1] = new(${read.entry})
|
|
278
386
|
res = map[string]any{"id": len(objs)}
|
|
@@ -436,6 +544,11 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
436
544
|
throw new Error('the harness stopped');
|
|
437
545
|
return stopped(JSON.parse(l));
|
|
438
546
|
};
|
|
547
|
+
// Capability-gated transport of independently captured native values. Older
|
|
548
|
+
// harnesses retain their old replay/refusal behavior, never fabricated bindings.
|
|
549
|
+
const capabilities = ask({ op: 'hello' });
|
|
550
|
+
const decode = capabilities.nativeSnapshot === 1 || capabilities.nativeBindings === 1 ? nativeWireDecoder() : undefined;
|
|
551
|
+
let bindings;
|
|
439
552
|
// A state from the harness as a snapshot (a number past the safe integers: the code leaves the rule's numbers).
|
|
440
553
|
const toSnap = (s) => {
|
|
441
554
|
const leaves = {}, maps = {}, lists = {};
|
|
@@ -502,6 +615,7 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
502
615
|
let now = 0;
|
|
503
616
|
const r0 = performance.now();
|
|
504
617
|
const side = {
|
|
618
|
+
...(capabilities.nativeEquality === 'scalar' ? { nativeEquality: 'scalar' } : {}),
|
|
505
619
|
// (a constructor's arguments, C++'s: the rule's parameters)
|
|
506
620
|
make: params => { const res = ask({ op: 'new', ...ctorArgs(params) }); return res.bad ? { ok: false, error: `the code can't be made with it (${res.bad})` } : { ok: true, value: res.id }; },
|
|
507
621
|
at: (s, params) => { const res = ask({ op: 'at', state: snapJson(s), ...ctorArgs(params) }); return res.bad ? undefined : res.id; },
|
|
@@ -515,6 +629,7 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
515
629
|
throw new Outside(`${a.key} answers ${String(x)}, outside its type`); return [a.key, a.inputs.none && v[a.inputs.none] === true ? { none: true } : { in: x }]; }));
|
|
516
630
|
}
|
|
517
631
|
const res = ask({ op: 'call', id: self, m: e.call, now, a: args, ...(answers ? { answers } : {}) });
|
|
632
|
+
bindings = res.nativeBindings;
|
|
518
633
|
if (res.frame)
|
|
519
634
|
throw new Error(`the code changes ${res.frame}, a field the rule leaves out`);
|
|
520
635
|
if (res.bad)
|
|
@@ -523,6 +638,17 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
523
638
|
return { ok: false, error: res.err !== undefined ? `error: ${res.err}` : `panic: ${res.panic}` };
|
|
524
639
|
return { ok: true, value: typeof res.out === 'string' && /^-?\d+$/.test(res.out) && m.results?.[e.call] && m.state.find(v => v.name === m.results[e.call].name)?.sort.k === 'num' ? Number(res.out) : res.out };
|
|
525
640
|
},
|
|
641
|
+
...(capabilities.nativeSnapshot === 1 && decode ? { nativeState: (self) => {
|
|
642
|
+
const res = ask({ op: 'native', id: self });
|
|
643
|
+
if (res.error !== undefined && res.error !== null)
|
|
644
|
+
throw new Error(`native snapshot: ${typeof res.error === 'string' ? res.error : 'invalid non-string error payload'}`);
|
|
645
|
+
return decode(res.snapshot);
|
|
646
|
+
} } : {}),
|
|
647
|
+
...(capabilities.nativeBindings === 1 && decode ? { nativeBindings: () => {
|
|
648
|
+
if (bindings?.error)
|
|
649
|
+
throw new Error(`native parameter capture: ${bindings.error}`);
|
|
650
|
+
return bindings?.snapshot ? snapshotNativeBindings(decode, bindings.snapshot) : undefined;
|
|
651
|
+
} } : {}),
|
|
526
652
|
args: (inputs, e) => e.args.map(a => argJson(a, inputs)),
|
|
527
653
|
setNow: n => { if (!Number.isSafeInteger(n))
|
|
528
654
|
throw new Outside('Go clock outside the exact integer range'); now = n; },
|
package/dist/core/extract-go.js
CHANGED
|
@@ -1160,6 +1160,10 @@ export function goNames(read) {
|
|
|
1160
1160
|
else
|
|
1161
1161
|
out.push({ code, rule: '', role: 'state', none: l.name });
|
|
1162
1162
|
}
|
|
1163
|
+
else if (l.kind === 'list') {
|
|
1164
|
+
const declaration = m.lists?.find(d => d.name === l.name);
|
|
1165
|
+
out.push({ code, rule: l.name, role: 'state', list: { scalar: true, ...(declaration?.len === undefined ? {} : { length: declaration.len }) } });
|
|
1166
|
+
}
|
|
1163
1167
|
else if (l.kind === 'int' || l.kind === 'bool' || l.kind === 'str' || l.kind === 'big')
|
|
1164
1168
|
out.push({ code, rule: l.name, role: 'state' });
|
|
1165
1169
|
}
|
|
@@ -1176,13 +1180,15 @@ export function goNames(read) {
|
|
|
1176
1180
|
for (const pa of mt.params)
|
|
1177
1181
|
arg(pa.arg, pa.name, 'input', mt.name);
|
|
1178
1182
|
for (const a of read.answers ?? [])
|
|
1179
|
-
out.push({ code: a.key, rule: a.inputs.name, role: 'answer', ...(a.inputs.none ? { none: a.inputs.none } : {}) });
|
|
1183
|
+
out.push({ code: a.key, rule: a.inputs.name, role: 'answer', native: { kind: 'answer', key: a.key }, ...(a.inputs.none ? { none: a.inputs.none } : {}) });
|
|
1180
1184
|
for (const [method, r] of Object.entries(m.results ?? {})) {
|
|
1181
1185
|
if (r.k === 'scalar')
|
|
1182
1186
|
out.push({ code: 'result', rule: r.name, role: 'result', method });
|
|
1183
1187
|
else if (r.k === 'rec')
|
|
1184
|
-
for (const [f, n] of r.fields)
|
|
1188
|
+
for (const [f, n] of r.fields) {
|
|
1185
1189
|
out.push({ code: f === 'result' ? 'result' : f, rule: n, role: 'result', method });
|
|
1190
|
+
out.push({ code: `result.${f}`, rule: n, role: 'result', method });
|
|
1191
|
+
}
|
|
1186
1192
|
}
|
|
1187
1193
|
if (m.event)
|
|
1188
1194
|
out.push({ code: 'method', rule: m.event, role: 'method' });
|
package/dist/core/extract-jvm.js
CHANGED
|
@@ -167,10 +167,10 @@ function compiled(lang, mod, read, o, made) {
|
|
|
167
167
|
const build = (file, out, srcDir) => {
|
|
168
168
|
if (kotlin) {
|
|
169
169
|
const kt = kotlinLib(o);
|
|
170
|
-
cp.execFileSync(jdk(o).java, ['-Xss8m', '-cp', `${kt}/kotlin-compiler.jar`, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', '-kotlin-home', path.dirname(kt), '-nowarn', '-no-reflect', '-d', out, '-cp', [t, extra].filter(Boolean).join(':'), file, ...(o.sources ?? []).map(f => path.resolve(f))], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
170
|
+
cp.execFileSync(jdk(o).java, ['-Xss8m', '-cp', `${kt}/kotlin-compiler.jar`, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', '-kotlin-home', path.dirname(kt), '-nowarn', '-no-reflect', '-java-parameters', '-d', out, '-cp', [t, extra].filter(Boolean).join(':'), file, ...(o.sources ?? []).map(f => path.resolve(f))], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
171
171
|
return [out, `${kt}/kotlin-stdlib.jar`];
|
|
172
172
|
}
|
|
173
|
-
cp.execFileSync(jdk(o).javac, ['-nowarn', '-Xlint:none', '-proc:none', '-implicit:class', '-d', out, '-sourcepath', `${srcDir}:${mod.root}`, '-cp', [t, extra].filter(Boolean).join(':'), file], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
173
|
+
cp.execFileSync(jdk(o).javac, ['-nowarn', '-Xlint:none', '-proc:none', '-implicit:class', '-parameters', '-d', out, '-sourcepath', `${srcDir}:${mod.root}`, '-cp', [t, extra].filter(Boolean).join(':'), file], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
174
174
|
return [out];
|
|
175
175
|
};
|
|
176
176
|
// What the compiler says is wrong with the code (its error lines), none where it crashed, was killed or timed out.
|