@ai-ecoverse/slicc-kernel 1.140.0 → 1.140.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.
@@ -2775,7 +2775,7 @@ var KERNEL_VERSION, OS_RELEASE;
2775
2775
  var init_version = __esm({
2776
2776
  "src/version.ts"() {
2777
2777
  "use strict";
2778
- KERNEL_VERSION = true ? "1.140.0" : "0.0.0-dev";
2778
+ KERNEL_VERSION = true ? "1.140.1" : "0.0.0-dev";
2779
2779
  OS_RELEASE = "6.0.0-slicc";
2780
2780
  }
2781
2781
  });
@@ -14538,7 +14538,29 @@ function nameFrame(line, module, name2) {
14538
14538
  const found = name2(Number(m[4]));
14539
14539
  return found === void 0 ? line : `${m[1]}${found} (${m[2]})`;
14540
14540
  }
14541
- function sidecarNames(read2, path) {
14541
+ function definedFunctions(bytes) {
14542
+ let at = 8;
14543
+ const leb = () => {
14544
+ let value2 = 0;
14545
+ let shift = 0;
14546
+ let byte;
14547
+ do {
14548
+ if (at >= bytes.length) throw new RangeError("truncated module");
14549
+ byte = bytes[at++];
14550
+ value2 += (byte & 127) * 2 ** shift;
14551
+ shift += 7;
14552
+ } while (byte & 128);
14553
+ return value2;
14554
+ };
14555
+ while (at < bytes.length) {
14556
+ const id = bytes[at++];
14557
+ const size = leb();
14558
+ if (id === 3) return leb();
14559
+ at += size;
14560
+ }
14561
+ return 0;
14562
+ }
14563
+ function sidecarNames(read2, path, fit) {
14542
14564
  let names;
14543
14565
  return (index3) => {
14544
14566
  if (!names) {
@@ -14547,6 +14569,20 @@ function sidecarNames(read2, path) {
14547
14569
  } catch {
14548
14570
  names = /* @__PURE__ */ new Map();
14549
14571
  }
14572
+ let want = names.size;
14573
+ try {
14574
+ if (fit) want = fit.functions();
14575
+ } catch {
14576
+ fit?.warn(`${path} can't be checked against the module, so the frames show raw indices`);
14577
+ names = /* @__PURE__ */ new Map();
14578
+ return void 0;
14579
+ }
14580
+ if (fit && names.size !== want) {
14581
+ fit.warn(
14582
+ `${path} names ${names.size} functions, but the module has ${want}: it doesn't fit, so the frames show raw indices`
14583
+ );
14584
+ names = /* @__PURE__ */ new Map();
14585
+ }
14550
14586
  }
14551
14587
  return names.get(index3);
14552
14588
  };
@@ -15037,7 +15073,7 @@ async function runWasiProcess(init, port2) {
15037
15073
  if (e instanceof WasiExit) return e.code;
15038
15074
  if (!(e instanceof WebAssembly.RuntimeError)) throw e;
15039
15075
  try {
15040
- say(trapMessage(e, init.env, "", programNames(host, init.program)));
15076
+ say(trapReport(e, init, host, ""));
15041
15077
  } catch {
15042
15078
  throw new Error(`${init.argv0}: wasm trap: ${e.message}`);
15043
15079
  }
@@ -15056,9 +15092,21 @@ function trapMessage(e, env, where = "", name2) {
15056
15092
  return frames.length ? `${head}
15057
15093
  ${frames.join("\n")}` : head;
15058
15094
  }
15059
- function programNames(host, program) {
15095
+ function trapReport(e, init, host, where) {
15096
+ const warned = [];
15097
+ const message2 = trapMessage(e, init.env, where, programNames(host, init.program, warned));
15098
+ return [...warned, message2].join(`
15099
+ ${init.argv0}: `);
15100
+ }
15101
+ function programNames(host, program, warned) {
15060
15102
  const path = program.names;
15061
- return path === void 0 ? void 0 : sidecarNames((p) => host.o.fs.readFile(p), path);
15103
+ if (path === void 0) return void 0;
15104
+ const read2 = (p) => host.o.fs.readFile(p);
15105
+ const imported = WebAssembly.Module.imports(program.module).filter((i) => i.kind === "function");
15106
+ return sidecarNames(read2, path, {
15107
+ functions: () => imported.length + definedFunctions(read2(program.path)),
15108
+ warn: (line) => warned.push(line)
15109
+ });
15062
15110
  }
15063
15111
  async function programImports(program, host, transport, tid) {
15064
15112
  if (program.imports === void 0) return void 0;
@@ -15139,7 +15187,7 @@ async function runWasiThread(init, port2) {
15139
15187
  }
15140
15188
  if (e instanceof WebAssembly.RuntimeError) {
15141
15189
  try {
15142
- say(trapMessage(e, init.env, ` in thread ${thread.tid}`, programNames(host, init.program)));
15190
+ say(trapReport(e, init, host, ` in thread ${thread.tid}`));
15143
15191
  } catch {
15144
15192
  }
15145
15193
  port2.postMessage({ type: WASM_PROCESS_EXIT, code: TRAPPED });