@fluffylabs/anan-as 1.1.6 → 1.2.0-1c29182

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.
Files changed (106) hide show
  1. package/dist/bin/index.js +186 -53
  2. package/dist/bin/src/fuzz.js +1 -1
  3. package/dist/bin/src/test-json.js +2 -6
  4. package/dist/bin/src/trace-replay.js +8 -4
  5. package/dist/build/compiler-inline.js +1 -1
  6. package/dist/build/compiler.d.ts +17 -13
  7. package/dist/build/compiler.js +13 -21
  8. package/dist/build/compiler.wasm +0 -0
  9. package/dist/build/debug-inline.js +1 -1
  10. package/dist/build/debug-raw-inline.js +1 -1
  11. package/dist/build/debug-raw.d.ts +63 -112
  12. package/dist/build/debug-raw.js +86 -139
  13. package/dist/build/debug-raw.wasm +0 -0
  14. package/dist/build/debug.d.ts +63 -112
  15. package/dist/build/debug.js +91 -147
  16. package/dist/build/debug.wasm +0 -0
  17. package/dist/build/js/assembly/api-debugger.d.ts +55 -0
  18. package/dist/build/js/assembly/api-debugger.js +245 -0
  19. package/dist/build/js/assembly/api-internal.d.ts +13 -0
  20. package/dist/build/js/assembly/api-internal.js +191 -0
  21. package/dist/build/js/assembly/api-types.d.ts +45 -0
  22. package/dist/build/js/assembly/api-types.js +52 -0
  23. package/dist/build/js/assembly/api-utils.d.ts +79 -0
  24. package/dist/build/js/assembly/api-utils.js +221 -0
  25. package/dist/build/js/assembly/arguments.d.ts +44 -0
  26. package/dist/build/js/assembly/arguments.js +164 -0
  27. package/dist/build/js/assembly/codec.d.ts +24 -0
  28. package/dist/build/js/assembly/codec.js +139 -0
  29. package/dist/build/js/assembly/gas.d.ts +11 -0
  30. package/dist/build/js/assembly/gas.js +33 -0
  31. package/dist/build/js/assembly/index-shared.d.ts +4 -0
  32. package/dist/build/js/assembly/index-shared.js +4 -0
  33. package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
  34. package/dist/build/js/assembly/instructions/bit.js +53 -0
  35. package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
  36. package/dist/build/js/assembly/instructions/branch.js +120 -0
  37. package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
  38. package/dist/build/js/assembly/instructions/jump.js +21 -0
  39. package/dist/build/js/assembly/instructions/load.d.ts +17 -0
  40. package/dist/build/js/assembly/instructions/load.js +134 -0
  41. package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
  42. package/dist/build/js/assembly/instructions/logic.js +47 -0
  43. package/dist/build/js/assembly/instructions/math.d.ts +28 -0
  44. package/dist/build/js/assembly/instructions/math.js +225 -0
  45. package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
  46. package/dist/build/js/assembly/instructions/misc.js +22 -0
  47. package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
  48. package/dist/build/js/assembly/instructions/mov.js +35 -0
  49. package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
  50. package/dist/build/js/assembly/instructions/outcome.js +88 -0
  51. package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
  52. package/dist/build/js/assembly/instructions/rot.js +66 -0
  53. package/dist/build/js/assembly/instructions/set.d.ts +7 -0
  54. package/dist/build/js/assembly/instructions/set.js +36 -0
  55. package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
  56. package/dist/build/js/assembly/instructions/shift.js +121 -0
  57. package/dist/build/js/assembly/instructions/store.d.ts +17 -0
  58. package/dist/build/js/assembly/instructions/store.js +101 -0
  59. package/dist/build/js/assembly/instructions/utils.d.ts +25 -0
  60. package/dist/build/js/assembly/instructions/utils.js +91 -0
  61. package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
  62. package/dist/build/js/assembly/instructions-exe.js +245 -0
  63. package/dist/build/js/assembly/instructions.d.ts +10 -0
  64. package/dist/build/js/assembly/instructions.js +252 -0
  65. package/dist/build/js/assembly/interpreter.d.ts +28 -0
  66. package/dist/build/js/assembly/interpreter.js +221 -0
  67. package/dist/build/js/assembly/math.d.ts +6 -0
  68. package/dist/build/js/assembly/math.js +22 -0
  69. package/dist/build/js/assembly/memory-page.d.ts +36 -0
  70. package/dist/build/js/assembly/memory-page.js +74 -0
  71. package/dist/build/js/assembly/memory.d.ts +83 -0
  72. package/dist/build/js/assembly/memory.js +482 -0
  73. package/dist/build/js/assembly/portable.d.ts +24 -0
  74. package/dist/build/js/assembly/portable.js +363 -0
  75. package/dist/build/js/assembly/program-build.d.ts +2 -0
  76. package/dist/build/js/assembly/program-build.js +104 -0
  77. package/dist/build/js/assembly/program.d.ts +85 -0
  78. package/dist/build/js/assembly/program.js +340 -0
  79. package/dist/build/js/assembly/registers.d.ts +6 -0
  80. package/dist/build/js/assembly/registers.js +9 -0
  81. package/dist/build/js/assembly/spi.d.ts +92 -0
  82. package/dist/build/js/assembly/spi.js +152 -0
  83. package/dist/build/js/portable/bootstrap.d.ts +1 -0
  84. package/dist/build/js/portable/bootstrap.js +5 -0
  85. package/dist/build/js/portable/index.d.ts +4 -0
  86. package/dist/build/js/portable/index.js +6 -0
  87. package/dist/build/js/portable-bundle.js +4496 -0
  88. package/dist/build/release-inline.js +1 -1
  89. package/dist/build/release-mini-inline.js +1 -1
  90. package/dist/build/release-mini.d.ts +63 -112
  91. package/dist/build/release-mini.js +91 -147
  92. package/dist/build/release-mini.wasm +0 -0
  93. package/dist/build/release-stub-inline.js +1 -1
  94. package/dist/build/release-stub.d.ts +63 -112
  95. package/dist/build/release-stub.js +91 -147
  96. package/dist/build/release-stub.wasm +0 -0
  97. package/dist/build/release.d.ts +63 -112
  98. package/dist/build/release.js +91 -147
  99. package/dist/build/release.wasm +0 -0
  100. package/dist/build/test-inline.js +1 -1
  101. package/dist/build/test.wasm +0 -0
  102. package/dist/test/test-gas-cost.js +2 -3
  103. package/dist/test/test-w3f-common.js +125 -0
  104. package/dist/test/test-w3f-portable.js +5 -0
  105. package/dist/test/test-w3f.js +3 -120
  106. package/package.json +24 -12
Binary file
@@ -2,7 +2,7 @@
2
2
  import "json-bigint-patch";
3
3
  import * as assert from "node:assert";
4
4
  import { ERR, OK, read, run } from "../bin/src/test-json.js";
5
- import { disassemble, getGasCosts, HasMetadata, InputKind } from "../build/release.js";
5
+ import { disassemble, getBlockGasCosts, HasMetadata, InputKind } from "../build/release.js";
6
6
  // Run the CLI application
7
7
  main();
8
8
  // Main function
@@ -10,7 +10,6 @@ function main() {
10
10
  const options = {
11
11
  isDebug: false,
12
12
  isSilent: false,
13
- useSbrkGas: false,
14
13
  };
15
14
  run(processGasCost, options);
16
15
  }
@@ -29,7 +28,7 @@ function processGasCost(data, options, filePath) {
29
28
  console.info(assembly);
30
29
  console.info("\n^^^^^^^^^^^\n");
31
30
  }
32
- const result = asMap(getGasCosts(input.program, InputKind.Generic, HasMetadata.No));
31
+ const result = asMap(getBlockGasCosts(input.program, InputKind.Generic, HasMetadata.No));
33
32
  // silent mode - just put our vals into expected (comparison done externally)
34
33
  if (options.isSilent) {
35
34
  data.block_gas_costs = result;
@@ -0,0 +1,125 @@
1
+ import "json-bigint-patch";
2
+ import * as assert from "node:assert";
3
+ import { ERR, OK, read, run } from "../bin/src/test-json.js";
4
+ const ignored = [
5
+ "inst_load_u8_nok",
6
+ "inst_store_imm_indirect_u16_with_offset_nok",
7
+ "inst_store_imm_indirect_u32_with_offset_nok",
8
+ "inst_store_imm_indirect_u64_with_offset_nok",
9
+ "inst_store_imm_indirect_u8_with_offset_nok",
10
+ "inst_store_imm_u8_trap_inaccessible",
11
+ "inst_store_imm_u8_trap_read_only",
12
+ "inst_store_indirect_u16_with_offset_nok",
13
+ "inst_store_indirect_u32_with_offset_nok",
14
+ "inst_store_indirect_u64_with_offset_nok",
15
+ "inst_store_indirect_u8_with_offset_nok",
16
+ "inst_store_u8_trap_inaccessible",
17
+ "inst_store_u8_trap_read_only",
18
+ ];
19
+ export function runW3fTests(pvm) {
20
+ const options = {
21
+ isDebug: false,
22
+ isSilent: false,
23
+ };
24
+ run((data, opts, filePath) => processW3f(pvm, data, opts, filePath), options);
25
+ }
26
+ function processW3f(pvm, data, options, _filePath) {
27
+ if (options.isDebug) {
28
+ console.debug(`🤖 Running ${data.name}`);
29
+ }
30
+ if (ignored.includes(data.name)) {
31
+ if (options.isDebug) {
32
+ console.info(`⏭️ Skipping ${data.name}`);
33
+ }
34
+ return data;
35
+ }
36
+ // input
37
+ const input = {
38
+ registers: read(data, "initial-regs").map((x) => BigInt(x)),
39
+ pc: read(data, "initial-pc"),
40
+ pageMap: asPageMap(read(data, "initial-page-map")),
41
+ memory: asChunks(read(data, "initial-memory")),
42
+ gas: BigInt(read(data, "initial-gas")),
43
+ program: read(data, "program"),
44
+ };
45
+ if (options.isDebug) {
46
+ const assembly = pvm.disassemble(input.program, pvm.InputKind.Generic, pvm.HasMetadata.No);
47
+ console.info("===========");
48
+ console.info(assembly);
49
+ console.info("\n^^^^^^^^^^^\n");
50
+ }
51
+ const exe = pvm.prepareProgram(pvm.InputKind.Generic, pvm.HasMetadata.No, input.program, input.registers, input.pageMap, input.memory, [], 16);
52
+ const result = pvm.runProgram(exe, input.gas, input.pc, options.isDebug, true);
53
+ const status = statusAsString(result.status);
54
+ // Normalize registers to plain unsigned BigInt array for comparison.
55
+ // The portable build may store signed BigInts or plain numbers in registers.
56
+ result.registers = Array.from(result.registers).map((v) => typeof v === "bigint" ? BigInt.asUintN(64, v) : BigInt(v));
57
+ result.gas = typeof result.gas === "bigint" ? result.gas : BigInt(result.gas);
58
+ // Normalize memory chunks to plain objects for comparison.
59
+ // The portable build returns class instances; WASM returns plain objects.
60
+ result.memory = result.memory.map((chunk) => ({
61
+ address: chunk.address,
62
+ data: Array.from(chunk.data),
63
+ }));
64
+ // silent mode - just put our vals into expected (comparison done externally)
65
+ if (options.isSilent) {
66
+ data["expected-pc"] = result.pc;
67
+ data["expected-gas"] = result.gas;
68
+ data["expected-status"] = status;
69
+ data["expected-regs"] = result.registers;
70
+ data["expected-page-fault-address"] = result.exitCode;
71
+ return data;
72
+ }
73
+ // compare with expected values
74
+ const expected = {
75
+ // just copy JAM-output result field
76
+ result: result.result,
77
+ status: read(data, "expected-status"),
78
+ registers: read(data, "expected-regs").map((x) => BigInt(x)),
79
+ pc: read(data, "expected-pc"),
80
+ memory: asChunks(read(data, "expected-memory")),
81
+ gas: BigInt(read(data, "expected-gas")),
82
+ exitCode: read(data, "expected-page-fault-address", 0),
83
+ };
84
+ try {
85
+ assert.deepStrictEqual({
86
+ ...result,
87
+ status,
88
+ }, expected);
89
+ console.log(`${OK} ${data.name}`);
90
+ }
91
+ catch (e) {
92
+ console.log(`${ERR} ${data.name}`);
93
+ throw e;
94
+ }
95
+ return data;
96
+ }
97
+ function asChunks(chunks) {
98
+ return chunks.map((chunk) => {
99
+ chunk.data = read(chunk, "contents");
100
+ delete chunk.contents;
101
+ return chunk;
102
+ });
103
+ }
104
+ var Access;
105
+ (function (Access) {
106
+ Access[Access["Read"] = 1] = "Read";
107
+ Access[Access["Write"] = 2] = "Write";
108
+ })(Access || (Access = {}));
109
+ function asPageMap(pages) {
110
+ return pages.map((page) => {
111
+ page.access = read(page, "is-writable") ? Access.Write : Access.Read;
112
+ return page;
113
+ });
114
+ }
115
+ function statusAsString(status) {
116
+ const map = {
117
+ 255: "ok",
118
+ 0: "halt",
119
+ 1: "panic",
120
+ 2: "page-fault",
121
+ 3: "host",
122
+ 4: "oog",
123
+ };
124
+ return map[status] || `unknown(${status})`;
125
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // @ts-expect-error: portable bundle has no TS declarations for direct import
3
+ import * as pvm from "../dist/build/js/portable-bundle.js";
4
+ import { runW3fTests } from "./test-w3f-common.js";
5
+ runW3fTests(pvm);
@@ -1,121 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import "json-bigint-patch";
3
- import * as assert from "node:assert";
4
- import { ERR, OK, read, run } from "../bin/src/test-json.js";
5
- import { disassemble, HasMetadata, InputKind, prepareProgram, runProgram } from "../build/release.js";
6
- const ignored = [
7
- "inst_load_u8_nok",
8
- "inst_store_imm_indirect_u16_with_offset_nok",
9
- "inst_store_imm_indirect_u32_with_offset_nok",
10
- "inst_store_imm_indirect_u64_with_offset_nok",
11
- "inst_store_imm_indirect_u8_with_offset_nok",
12
- "inst_store_imm_u8_trap_inaccessible",
13
- "inst_store_imm_u8_trap_read_only",
14
- "inst_store_indirect_u16_with_offset_nok",
15
- "inst_store_indirect_u32_with_offset_nok",
16
- "inst_store_indirect_u64_with_offset_nok",
17
- "inst_store_indirect_u8_with_offset_nok",
18
- "inst_store_u8_trap_inaccessible",
19
- "inst_store_u8_trap_read_only",
20
- ];
21
- // Run the CLI application
22
- main();
23
- // Main function
24
- function main() {
25
- const options = {
26
- isDebug: false,
27
- isSilent: false,
28
- useSbrkGas: false,
29
- };
30
- run(processW3f, options);
31
- }
32
- function processW3f(data, options) {
33
- if (options.isDebug) {
34
- console.debug(`🤖 Running ${data.name}`);
35
- }
36
- if (ignored.includes(data.name)) {
37
- if (options.isDebug) {
38
- console.info(`⏭️ Skipping ${data.name}`);
39
- }
40
- return data;
41
- }
42
- // input
43
- const input = {
44
- registers: read(data, "initial-regs").map((x) => BigInt(x)),
45
- pc: read(data, "initial-pc"),
46
- pageMap: asPageMap(read(data, "initial-page-map")),
47
- memory: asChunks(read(data, "initial-memory")),
48
- gas: BigInt(read(data, "initial-gas")),
49
- program: read(data, "program"),
50
- };
51
- if (options.isDebug) {
52
- const assembly = disassemble(input.program, InputKind.Generic, HasMetadata.No);
53
- console.info("===========");
54
- console.info(assembly);
55
- console.info("\n^^^^^^^^^^^\n");
56
- }
57
- const exe = prepareProgram(InputKind.Generic, HasMetadata.No, input.program, input.registers, input.pageMap, input.memory, [], 16);
58
- const result = runProgram(exe, input.gas, input.pc, options.isDebug, options.useSbrkGas, true);
59
- const status = statusAsString(result.status);
60
- // silent mode - just put our vals into expected (comparison done externally)
61
- if (options.isSilent) {
62
- data["expected-pc"] = result.pc;
63
- data["expected-gas"] = result.gas;
64
- data["expected-status"] = status;
65
- data["expected-regs"] = result.registers;
66
- data["expected-page-fault-address"] = result.exitCode;
67
- return data;
68
- }
69
- // compare with expected values
70
- const expected = {
71
- // just copy JAM-output result field
72
- result: result.result,
73
- status: read(data, "expected-status"),
74
- registers: read(data, "expected-regs").map((x) => BigInt(x)),
75
- pc: read(data, "expected-pc"),
76
- memory: asChunks(read(data, "expected-memory")),
77
- gas: BigInt(read(data, "expected-gas")),
78
- exitCode: read(data, "expected-page-fault-address", 0),
79
- };
80
- try {
81
- assert.deepStrictEqual({
82
- ...result,
83
- status,
84
- }, expected);
85
- console.log(`${OK} ${data.name}`);
86
- }
87
- catch (e) {
88
- console.log(`${ERR} ${data.name}`);
89
- throw e;
90
- }
91
- return data;
92
- }
93
- function asChunks(chunks) {
94
- return chunks.map((chunk) => {
95
- chunk.data = read(chunk, "contents");
96
- delete chunk.contents;
97
- return chunk;
98
- });
99
- }
100
- var Access;
101
- (function (Access) {
102
- Access[Access["Read"] = 1] = "Read";
103
- Access[Access["Write"] = 2] = "Write";
104
- })(Access || (Access = {}));
105
- function asPageMap(pages) {
106
- return pages.map((page) => {
107
- page.access = read(page, "is-writable") ? Access.Write : Access.Read;
108
- return page;
109
- });
110
- }
111
- function statusAsString(status) {
112
- const map = {
113
- 255: "ok",
114
- 0: "halt",
115
- 1: "panic",
116
- 2: "page-fault",
117
- 3: "host",
118
- 4: "oog",
119
- };
120
- return map[status] || `unknown(${status})`;
121
- }
2
+ import * as pvm from "../build/release.js";
3
+ import { runW3fTests } from "./test-w3f-common.js";
4
+ runW3fTests(pvm);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fluffylabs/anan-as",
3
3
  "description": "AssemblyScript PVM interpreter.",
4
- "version": "1.1.6",
4
+ "version": "1.2.0-1c29182",
5
5
  "main": "./dist/bin/index.js",
6
6
  "bin": {
7
7
  "anan-as": "./dist/bin/index.js"
@@ -32,26 +32,34 @@
32
32
  "qa": "biome ci",
33
33
  "qa-fix": "npm run format; npm run lint",
34
34
  "start": "tsx ./bin/index.ts",
35
- "test": "npm run asbuild:test && tsx ./test/test-as.ts && tsx ./test/test-trace-replay.ts",
36
- "tsbuild": "tsc",
35
+ "test": "npm run asbuild:test && tsx ./test/test-as.ts && tsx ./test/test-trace-replay.ts",
36
+ "tsbuild": "tsc && npm run tsbuild:portable",
37
+ "tsbuild:portable": "tsc --project portable/tsconfig.json && esbuild dist/build/js/portable/index.js --bundle --format=esm --platform=node --outfile=dist/build/js/portable-bundle.js",
37
38
  "test:w3f": "tsx ./test/test-w3f.ts",
39
+ "test:w3f-portable": "tsx ./test/test-w3f-portable.ts",
38
40
  "test:gas-cost": "tsx ./test/test-gas-cost.ts",
39
41
  "update-version": "tsx ./web/bump-version.ts $GITHUB_SHA",
40
- "web": "npx live-server ./web"
42
+ "web": "npx live-server ./web",
43
+ "bench": "tsx bench/run.ts --traces ./bench/traces --iterations 5 --warmup 1",
44
+ "bench:ci": "tsx bench/run.ts --traces ./bench/traces --iterations 5 --warmup 1 --output ./bench/results.json",
45
+ "bench:baseline": "tsx bench/run.ts --traces ./bench/traces --iterations 5 --warmup 1 --output ./bench/baseline.json",
46
+ "bench:compare": "tsx bench/compare.ts"
41
47
  },
42
48
  "type": "module",
43
49
  "keywords": [],
44
50
  "author": "Fluffy Labs",
45
51
  "license": "MPL-2.0",
52
+ "engines": {
53
+ "node": ">=18.3.0"
54
+ },
46
55
  "devDependencies": {
47
- "@biomejs/biome": "^2.3.11",
48
- "@typeberry/lib": "^0.5.1",
49
- "@types/minimist": "^1.2.5",
50
- "@types/node": "^25.0.0",
51
- "assemblyscript": "^0.28.8",
56
+ "@biomejs/biome": "^2.4.5",
57
+ "@typeberry/lib": "^0.5.8",
58
+ "@types/node": "^25.3.3",
59
+ "assemblyscript": "^0.28.9",
60
+ "esbuild": "^0.27.3",
52
61
  "json-bigint-patch": "^0.0.8",
53
- "minimist": "^1.2.8",
54
- "tsx": "^4.20.6",
62
+ "tsx": "^4.21.0",
55
63
  "typescript": "^5.9.3"
56
64
  },
57
65
  "files": [
@@ -110,6 +118,10 @@
110
118
  "./release.wasm": "./dist/build/release.wasm",
111
119
  "./release-mini.wasm": "./dist/build/release-mini.wasm",
112
120
  "./release-stub.wasm": "./dist/build/release-stub.wasm",
113
- "./compiler.wasm": "./dist/build/compiler.wasm"
121
+ "./compiler.wasm": "./dist/build/compiler.wasm",
122
+ "./js": {
123
+ "import": "./dist/build/js/portable-bundle.js",
124
+ "types": "./dist/build/js/portable/index.d.ts"
125
+ }
114
126
  }
115
127
  }