@fluffylabs/anan-as 1.1.6 → 1.2.0-41e43f6

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 (103) hide show
  1. package/dist/bin/index.js +50 -49
  2. package/dist/bin/src/trace-replay.js +2 -2
  3. package/dist/build/compiler-inline.js +1 -1
  4. package/dist/build/compiler.wasm +0 -0
  5. package/dist/build/debug-inline.js +1 -1
  6. package/dist/build/debug-raw-inline.js +1 -1
  7. package/dist/build/debug-raw.d.ts +54 -105
  8. package/dist/build/debug-raw.js +66 -120
  9. package/dist/build/debug-raw.wasm +0 -0
  10. package/dist/build/debug.d.ts +54 -105
  11. package/dist/build/debug.js +70 -127
  12. package/dist/build/debug.wasm +0 -0
  13. package/dist/build/js/assembly/api-debugger.d.ts +55 -0
  14. package/dist/build/js/assembly/api-debugger.js +245 -0
  15. package/dist/build/js/assembly/api-internal.d.ts +13 -0
  16. package/dist/build/js/assembly/api-internal.js +192 -0
  17. package/dist/build/js/assembly/api-types.d.ts +46 -0
  18. package/dist/build/js/assembly/api-types.js +53 -0
  19. package/dist/build/js/assembly/api-utils.d.ts +72 -0
  20. package/dist/build/js/assembly/api-utils.js +206 -0
  21. package/dist/build/js/assembly/arguments.d.ts +44 -0
  22. package/dist/build/js/assembly/arguments.js +164 -0
  23. package/dist/build/js/assembly/codec.d.ts +24 -0
  24. package/dist/build/js/assembly/codec.js +139 -0
  25. package/dist/build/js/assembly/gas-costs.d.ts +6 -0
  26. package/dist/build/js/assembly/gas-costs.js +39 -0
  27. package/dist/build/js/assembly/gas.d.ts +11 -0
  28. package/dist/build/js/assembly/gas.js +32 -0
  29. package/dist/build/js/assembly/index-shared.d.ts +4 -0
  30. package/dist/build/js/assembly/index-shared.js +4 -0
  31. package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
  32. package/dist/build/js/assembly/instructions/bit.js +53 -0
  33. package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
  34. package/dist/build/js/assembly/instructions/branch.js +120 -0
  35. package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
  36. package/dist/build/js/assembly/instructions/jump.js +21 -0
  37. package/dist/build/js/assembly/instructions/load.d.ts +17 -0
  38. package/dist/build/js/assembly/instructions/load.js +134 -0
  39. package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
  40. package/dist/build/js/assembly/instructions/logic.js +47 -0
  41. package/dist/build/js/assembly/instructions/math.d.ts +28 -0
  42. package/dist/build/js/assembly/instructions/math.js +225 -0
  43. package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
  44. package/dist/build/js/assembly/instructions/misc.js +22 -0
  45. package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
  46. package/dist/build/js/assembly/instructions/mov.js +35 -0
  47. package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
  48. package/dist/build/js/assembly/instructions/outcome.js +61 -0
  49. package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
  50. package/dist/build/js/assembly/instructions/rot.js +66 -0
  51. package/dist/build/js/assembly/instructions/set.d.ts +7 -0
  52. package/dist/build/js/assembly/instructions/set.js +36 -0
  53. package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
  54. package/dist/build/js/assembly/instructions/shift.js +121 -0
  55. package/dist/build/js/assembly/instructions/store.d.ts +17 -0
  56. package/dist/build/js/assembly/instructions/store.js +101 -0
  57. package/dist/build/js/assembly/instructions/utils.d.ts +23 -0
  58. package/dist/build/js/assembly/instructions/utils.js +75 -0
  59. package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
  60. package/dist/build/js/assembly/instructions-exe.js +245 -0
  61. package/dist/build/js/assembly/instructions.d.ts +11 -0
  62. package/dist/build/js/assembly/instructions.js +252 -0
  63. package/dist/build/js/assembly/interpreter.d.ts +29 -0
  64. package/dist/build/js/assembly/interpreter.js +228 -0
  65. package/dist/build/js/assembly/math.d.ts +8 -0
  66. package/dist/build/js/assembly/math.js +14 -0
  67. package/dist/build/js/assembly/memory-page.d.ts +36 -0
  68. package/dist/build/js/assembly/memory-page.js +74 -0
  69. package/dist/build/js/assembly/memory.d.ts +83 -0
  70. package/dist/build/js/assembly/memory.js +480 -0
  71. package/dist/build/js/assembly/portable.d.ts +24 -0
  72. package/dist/build/js/assembly/portable.js +362 -0
  73. package/dist/build/js/assembly/program-build.d.ts +2 -0
  74. package/dist/build/js/assembly/program-build.js +104 -0
  75. package/dist/build/js/assembly/program.d.ts +78 -0
  76. package/dist/build/js/assembly/program.js +290 -0
  77. package/dist/build/js/assembly/registers.d.ts +6 -0
  78. package/dist/build/js/assembly/registers.js +9 -0
  79. package/dist/build/js/assembly/spi.d.ts +92 -0
  80. package/dist/build/js/assembly/spi.js +152 -0
  81. package/dist/build/js/portable/bootstrap.d.ts +1 -0
  82. package/dist/build/js/portable/bootstrap.js +5 -0
  83. package/dist/build/js/portable/index.d.ts +4 -0
  84. package/dist/build/js/portable/index.js +6 -0
  85. package/dist/build/js/portable-bundle.js +4409 -0
  86. package/dist/build/release-inline.js +1 -1
  87. package/dist/build/release-mini-inline.js +1 -1
  88. package/dist/build/release-mini.d.ts +54 -105
  89. package/dist/build/release-mini.js +70 -127
  90. package/dist/build/release-mini.wasm +0 -0
  91. package/dist/build/release-stub-inline.js +1 -1
  92. package/dist/build/release-stub.d.ts +54 -105
  93. package/dist/build/release-stub.js +70 -127
  94. package/dist/build/release-stub.wasm +0 -0
  95. package/dist/build/release.d.ts +54 -105
  96. package/dist/build/release.js +70 -127
  97. package/dist/build/release.wasm +0 -0
  98. package/dist/build/test-inline.js +1 -1
  99. package/dist/build/test.wasm +0 -0
  100. package/dist/test/test-w3f-common.js +126 -0
  101. package/dist/test/test-w3f-portable.js +5 -0
  102. package/dist/test/test-w3f.js +3 -120
  103. package/package.json +20 -8
Binary file
@@ -0,0 +1,126 @@
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
+ useSbrkGas: false,
24
+ };
25
+ run((data, opts, filePath) => processW3f(pvm, data, opts, filePath), options);
26
+ }
27
+ function processW3f(pvm, data, options, _filePath) {
28
+ if (options.isDebug) {
29
+ console.debug(`🤖 Running ${data.name}`);
30
+ }
31
+ if (ignored.includes(data.name)) {
32
+ if (options.isDebug) {
33
+ console.info(`⏭️ Skipping ${data.name}`);
34
+ }
35
+ return data;
36
+ }
37
+ // input
38
+ const input = {
39
+ registers: read(data, "initial-regs").map((x) => BigInt(x)),
40
+ pc: read(data, "initial-pc"),
41
+ pageMap: asPageMap(read(data, "initial-page-map")),
42
+ memory: asChunks(read(data, "initial-memory")),
43
+ gas: BigInt(read(data, "initial-gas")),
44
+ program: read(data, "program"),
45
+ };
46
+ if (options.isDebug) {
47
+ const assembly = pvm.disassemble(input.program, pvm.InputKind.Generic, pvm.HasMetadata.No);
48
+ console.info("===========");
49
+ console.info(assembly);
50
+ console.info("\n^^^^^^^^^^^\n");
51
+ }
52
+ const exe = pvm.prepareProgram(pvm.InputKind.Generic, pvm.HasMetadata.No, input.program, input.registers, input.pageMap, input.memory, [], 16);
53
+ const result = pvm.runProgram(exe, input.gas, input.pc, options.isDebug, options.useSbrkGas, true);
54
+ const status = statusAsString(result.status);
55
+ // Normalize registers to plain unsigned BigInt array for comparison.
56
+ // The portable build may store signed BigInts or plain numbers in registers.
57
+ result.registers = Array.from(result.registers).map((v) => typeof v === "bigint" ? BigInt.asUintN(64, v) : BigInt(v));
58
+ result.gas = typeof result.gas === "bigint" ? result.gas : BigInt(result.gas);
59
+ // Normalize memory chunks to plain objects for comparison.
60
+ // The portable build returns class instances; WASM returns plain objects.
61
+ result.memory = result.memory.map((chunk) => ({
62
+ address: chunk.address,
63
+ data: Array.from(chunk.data),
64
+ }));
65
+ // silent mode - just put our vals into expected (comparison done externally)
66
+ if (options.isSilent) {
67
+ data["expected-pc"] = result.pc;
68
+ data["expected-gas"] = result.gas;
69
+ data["expected-status"] = status;
70
+ data["expected-regs"] = result.registers;
71
+ data["expected-page-fault-address"] = result.exitCode;
72
+ return data;
73
+ }
74
+ // compare with expected values
75
+ const expected = {
76
+ // just copy JAM-output result field
77
+ result: result.result,
78
+ status: read(data, "expected-status"),
79
+ registers: read(data, "expected-regs").map((x) => BigInt(x)),
80
+ pc: read(data, "expected-pc"),
81
+ memory: asChunks(read(data, "expected-memory")),
82
+ gas: BigInt(read(data, "expected-gas")),
83
+ exitCode: read(data, "expected-page-fault-address", 0),
84
+ };
85
+ try {
86
+ assert.deepStrictEqual({
87
+ ...result,
88
+ status,
89
+ }, expected);
90
+ console.log(`${OK} ${data.name}`);
91
+ }
92
+ catch (e) {
93
+ console.log(`${ERR} ${data.name}`);
94
+ throw e;
95
+ }
96
+ return data;
97
+ }
98
+ function asChunks(chunks) {
99
+ return chunks.map((chunk) => {
100
+ chunk.data = read(chunk, "contents");
101
+ delete chunk.contents;
102
+ return chunk;
103
+ });
104
+ }
105
+ var Access;
106
+ (function (Access) {
107
+ Access[Access["Read"] = 1] = "Read";
108
+ Access[Access["Write"] = 2] = "Write";
109
+ })(Access || (Access = {}));
110
+ function asPageMap(pages) {
111
+ return pages.map((page) => {
112
+ page.access = read(page, "is-writable") ? Access.Write : Access.Read;
113
+ return page;
114
+ });
115
+ }
116
+ function statusAsString(status) {
117
+ const map = {
118
+ 255: "ok",
119
+ 0: "halt",
120
+ 1: "panic",
121
+ 2: "page-fault",
122
+ 3: "host",
123
+ 4: "oog",
124
+ };
125
+ return map[status] || `unknown(${status})`;
126
+ }
@@ -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-41e43f6",
5
5
  "main": "./dist/bin/index.js",
6
6
  "bin": {
7
7
  "anan-as": "./dist/bin/index.js"
@@ -32,25 +32,33 @@
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",
56
+ "@biomejs/biome": "^2.4.3",
48
57
  "@typeberry/lib": "^0.5.1",
49
- "@types/minimist": "^1.2.5",
50
58
  "@types/node": "^25.0.0",
51
59
  "assemblyscript": "^0.28.8",
60
+ "esbuild": "^0.27.0",
52
61
  "json-bigint-patch": "^0.0.8",
53
- "minimist": "^1.2.8",
54
62
  "tsx": "^4.20.6",
55
63
  "typescript": "^5.9.3"
56
64
  },
@@ -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
  }