@ai-ecoverse/slicc-kernel 1.8.0 → 1.8.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.
package/dist/node.js CHANGED
@@ -5248,6 +5248,109 @@ function importedMemory(bytes) {
5248
5248
  }
5249
5249
  return void 0;
5250
5250
  }
5251
+ var RESERVED_NAMESPACES = /* @__PURE__ */ new Set([
5252
+ "wasi_snapshot_preview1",
5253
+ "wasix_32v1",
5254
+ "wasi",
5255
+ "env"
5256
+ ]);
5257
+ var RESULTS = {
5258
+ 127: "i32",
5259
+ 126: "i64",
5260
+ 125: "f32",
5261
+ 124: "f64"
5262
+ };
5263
+ function resultOf(results) {
5264
+ if (results.length === 0) return "none";
5265
+ return results.length === 1 && RESULTS[results[0]] || "other";
5266
+ }
5267
+ var Reader = class {
5268
+ at = 8;
5269
+ bytes;
5270
+ constructor(bytes) {
5271
+ this.bytes = bytes;
5272
+ }
5273
+ byte() {
5274
+ return this.bytes[this.at++];
5275
+ }
5276
+ u32() {
5277
+ let result = 0;
5278
+ let shift = 0;
5279
+ for (; ; ) {
5280
+ const b = this.byte();
5281
+ result |= (b & 127) << shift;
5282
+ if (!(b & 128)) return result >>> 0;
5283
+ shift += 7;
5284
+ }
5285
+ }
5286
+ name() {
5287
+ const len = this.u32();
5288
+ const s = new TextDecoder().decode(this.bytes.subarray(this.at, this.at + len));
5289
+ this.at += len;
5290
+ return s;
5291
+ }
5292
+ valtype() {
5293
+ const code = this.byte();
5294
+ if (code === 99 || code === 100) this.u32();
5295
+ return code;
5296
+ }
5297
+ limits() {
5298
+ const flags = this.byte();
5299
+ this.u32();
5300
+ if (flags & 1) this.u32();
5301
+ }
5302
+ };
5303
+ function readTypes(r) {
5304
+ const types = [];
5305
+ for (let i = r.u32(); i > 0; i--) {
5306
+ if (r.byte() !== 96) return void 0;
5307
+ for (let n = r.u32(); n > 0; n--) r.valtype();
5308
+ const results = [];
5309
+ for (let n = r.u32(); n > 0; n--) results.push(r.valtype());
5310
+ types.push(resultOf(results));
5311
+ }
5312
+ return types;
5313
+ }
5314
+ function skipImport(r, kind) {
5315
+ if (kind === 1) {
5316
+ r.valtype();
5317
+ r.limits();
5318
+ } else if (kind === 2) r.limits();
5319
+ else if (kind === 3) {
5320
+ r.valtype();
5321
+ r.byte();
5322
+ } else {
5323
+ r.byte();
5324
+ r.u32();
5325
+ }
5326
+ }
5327
+ function readImports(r, types) {
5328
+ const foreign = {};
5329
+ for (let i = r.u32(); i > 0; i--) {
5330
+ const module = r.name();
5331
+ const field = r.name();
5332
+ const kind = r.byte();
5333
+ if (kind !== 0) skipImport(r, kind);
5334
+ else {
5335
+ const type = types[r.u32()] ?? "other";
5336
+ if (!RESERVED_NAMESPACES.has(module)) (foreign[module] ??= {})[field] = type;
5337
+ }
5338
+ }
5339
+ return foreign;
5340
+ }
5341
+ function foreignImports(bytes) {
5342
+ const r = new Reader(bytes);
5343
+ let types = [];
5344
+ while (r.at < bytes.length) {
5345
+ const id = r.byte();
5346
+ const end = r.u32() + r.at;
5347
+ if (id === 1) types = readTypes(r);
5348
+ if (!types) return void 0;
5349
+ if (id === 2) return readImports(r, types);
5350
+ r.at = end;
5351
+ }
5352
+ return {};
5353
+ }
5251
5354
 
5252
5355
  // src/launcher.ts
5253
5356
  var COMMAND2 = /^\/(?:usr\/)?bin\/([^/]+)$/;
@@ -5435,8 +5538,13 @@ var Launcher = class {
5435
5538
  if (!module) {
5436
5539
  module = this.base.readFileBuffer(path).then(async (bytes) => {
5437
5540
  const memory = importedMemory(bytes);
5541
+ const foreign = foreignImports(bytes);
5438
5542
  const compiled = await WebAssembly.compile(bytes);
5439
- return { module: compiled, ...memory ? { memory } : {} };
5543
+ return {
5544
+ module: compiled,
5545
+ ...memory ? { memory } : {},
5546
+ foreign
5547
+ };
5440
5548
  });
5441
5549
  this.compiled.set(key, module);
5442
5550
  module.catch(() => this.compiled.delete(key));
@@ -5461,7 +5569,7 @@ var Launcher = class {
5461
5569
  ]);
5462
5570
  return { glue, module: module2 };
5463
5571
  }
5464
- const { module, memory } = await this.module(target.wasm);
5572
+ const { module, memory, foreign } = await this.module(target.wasm);
5465
5573
  const names = env.SLICC_WASM_BACKTRACE === "1" ? await this.names(target.wasm, module) : void 0;
5466
5574
  const imports = target.imports ? await this.base.readFile(target.imports) : void 0;
5467
5575
  return {
@@ -5469,6 +5577,7 @@ var Launcher = class {
5469
5577
  glue: "",
5470
5578
  module,
5471
5579
  ...memory ? { memory } : {},
5580
+ foreign,
5472
5581
  ...names ? { names } : {},
5473
5582
  ...imports !== void 0 ? { imports } : {}
5474
5583
  };