@fluffylabs/anan-as 1.2.0-e8a5af8 → 1.2.0-ef04361

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 (102) hide show
  1. package/dist/bin/src/trace-replay.js +2 -2
  2. package/dist/build/compiler-inline.js +1 -1
  3. package/dist/build/compiler.wasm +0 -0
  4. package/dist/build/debug-inline.js +1 -1
  5. package/dist/build/debug-raw-inline.js +1 -1
  6. package/dist/build/debug-raw.d.ts +34 -98
  7. package/dist/build/debug-raw.js +51 -105
  8. package/dist/build/debug-raw.wasm +0 -0
  9. package/dist/build/debug.d.ts +34 -98
  10. package/dist/build/debug.js +53 -112
  11. package/dist/build/debug.wasm +0 -0
  12. package/dist/build/js/assembly/api-debugger.d.ts +55 -0
  13. package/dist/build/js/assembly/api-debugger.js +245 -0
  14. package/dist/build/js/assembly/api-internal.d.ts +13 -0
  15. package/dist/build/js/assembly/api-internal.js +192 -0
  16. package/dist/build/js/assembly/api-types.d.ts +45 -0
  17. package/dist/build/js/assembly/api-types.js +53 -0
  18. package/dist/build/js/assembly/api-utils.d.ts +71 -0
  19. package/dist/build/js/assembly/api-utils.js +206 -0
  20. package/dist/build/js/assembly/arguments.d.ts +44 -0
  21. package/dist/build/js/assembly/arguments.js +164 -0
  22. package/dist/build/js/assembly/codec.d.ts +24 -0
  23. package/dist/build/js/assembly/codec.js +139 -0
  24. package/dist/build/js/assembly/gas-costs.d.ts +6 -0
  25. package/dist/build/js/assembly/gas-costs.js +39 -0
  26. package/dist/build/js/assembly/gas.d.ts +16 -0
  27. package/dist/build/js/assembly/gas.js +23 -0
  28. package/dist/build/js/assembly/index-shared.d.ts +4 -0
  29. package/dist/build/js/assembly/index-shared.js +4 -0
  30. package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
  31. package/dist/build/js/assembly/instructions/bit.js +53 -0
  32. package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
  33. package/dist/build/js/assembly/instructions/branch.js +120 -0
  34. package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
  35. package/dist/build/js/assembly/instructions/jump.js +21 -0
  36. package/dist/build/js/assembly/instructions/load.d.ts +17 -0
  37. package/dist/build/js/assembly/instructions/load.js +134 -0
  38. package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
  39. package/dist/build/js/assembly/instructions/logic.js +47 -0
  40. package/dist/build/js/assembly/instructions/math.d.ts +28 -0
  41. package/dist/build/js/assembly/instructions/math.js +225 -0
  42. package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
  43. package/dist/build/js/assembly/instructions/misc.js +22 -0
  44. package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
  45. package/dist/build/js/assembly/instructions/mov.js +35 -0
  46. package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
  47. package/dist/build/js/assembly/instructions/outcome.js +63 -0
  48. package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
  49. package/dist/build/js/assembly/instructions/rot.js +66 -0
  50. package/dist/build/js/assembly/instructions/set.d.ts +7 -0
  51. package/dist/build/js/assembly/instructions/set.js +36 -0
  52. package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
  53. package/dist/build/js/assembly/instructions/shift.js +121 -0
  54. package/dist/build/js/assembly/instructions/store.d.ts +17 -0
  55. package/dist/build/js/assembly/instructions/store.js +101 -0
  56. package/dist/build/js/assembly/instructions/utils.d.ts +23 -0
  57. package/dist/build/js/assembly/instructions/utils.js +75 -0
  58. package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
  59. package/dist/build/js/assembly/instructions-exe.js +245 -0
  60. package/dist/build/js/assembly/instructions.d.ts +11 -0
  61. package/dist/build/js/assembly/instructions.js +252 -0
  62. package/dist/build/js/assembly/interpreter.d.ts +29 -0
  63. package/dist/build/js/assembly/interpreter.js +229 -0
  64. package/dist/build/js/assembly/math.d.ts +8 -0
  65. package/dist/build/js/assembly/math.js +14 -0
  66. package/dist/build/js/assembly/memory-page.d.ts +38 -0
  67. package/dist/build/js/assembly/memory-page.js +68 -0
  68. package/dist/build/js/assembly/memory.d.ts +82 -0
  69. package/dist/build/js/assembly/memory.js +386 -0
  70. package/dist/build/js/assembly/portable.d.ts +24 -0
  71. package/dist/build/js/assembly/portable.js +362 -0
  72. package/dist/build/js/assembly/program-build.d.ts +2 -0
  73. package/dist/build/js/assembly/program-build.js +104 -0
  74. package/dist/build/js/assembly/program.d.ts +78 -0
  75. package/dist/build/js/assembly/program.js +284 -0
  76. package/dist/build/js/assembly/registers.d.ts +6 -0
  77. package/dist/build/js/assembly/registers.js +9 -0
  78. package/dist/build/js/assembly/spi.d.ts +92 -0
  79. package/dist/build/js/assembly/spi.js +152 -0
  80. package/dist/build/js/portable/bootstrap.d.ts +1 -0
  81. package/dist/build/js/portable/bootstrap.js +5 -0
  82. package/dist/build/js/portable/index.d.ts +4 -0
  83. package/dist/build/js/portable/index.js +6 -0
  84. package/dist/build/js/portable-bundle.js +4309 -0
  85. package/dist/build/release-inline.js +1 -1
  86. package/dist/build/release-mini-inline.js +1 -1
  87. package/dist/build/release-mini.d.ts +34 -98
  88. package/dist/build/release-mini.js +53 -112
  89. package/dist/build/release-mini.wasm +0 -0
  90. package/dist/build/release-stub-inline.js +1 -1
  91. package/dist/build/release-stub.d.ts +34 -98
  92. package/dist/build/release-stub.js +53 -112
  93. package/dist/build/release-stub.wasm +0 -0
  94. package/dist/build/release.d.ts +34 -98
  95. package/dist/build/release.js +53 -112
  96. package/dist/build/release.wasm +0 -0
  97. package/dist/build/test-inline.js +1 -1
  98. package/dist/build/test.wasm +0 -0
  99. package/dist/test/test-w3f-common.js +126 -0
  100. package/dist/test/test-w3f-portable.js +5 -0
  101. package/dist/test/test-w3f.js +3 -120
  102. package/package.json +11 -4
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.2.0-e8a5af8",
4
+ "version": "1.2.0-ef04361",
5
5
  "main": "./dist/bin/index.js",
6
6
  "bin": {
7
7
  "anan-as": "./dist/bin/index.js"
@@ -33,8 +33,10 @@
33
33
  "qa-fix": "npm run format; npm run lint",
34
34
  "start": "tsx ./bin/index.ts",
35
35
  "test": "npm run asbuild:test && tsx ./test/test-as.ts && tsx ./test/test-trace-replay.ts",
36
- "tsbuild": "tsc",
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
42
  "web": "npx live-server ./web"
@@ -47,10 +49,11 @@
47
49
  "node": ">=18.3.0"
48
50
  },
49
51
  "devDependencies": {
50
- "@biomejs/biome": "^2.3.11",
52
+ "@biomejs/biome": "^2.4.3",
51
53
  "@typeberry/lib": "^0.5.1",
52
54
  "@types/node": "^25.0.0",
53
55
  "assemblyscript": "^0.28.8",
56
+ "esbuild": "^0.27.0",
54
57
  "json-bigint-patch": "^0.0.8",
55
58
  "tsx": "^4.20.6",
56
59
  "typescript": "^5.9.3"
@@ -111,6 +114,10 @@
111
114
  "./release.wasm": "./dist/build/release.wasm",
112
115
  "./release-mini.wasm": "./dist/build/release-mini.wasm",
113
116
  "./release-stub.wasm": "./dist/build/release-stub.wasm",
114
- "./compiler.wasm": "./dist/build/compiler.wasm"
117
+ "./compiler.wasm": "./dist/build/compiler.wasm",
118
+ "./js": {
119
+ "import": "./dist/build/js/portable-bundle.js",
120
+ "types": "./dist/build/js/portable/index.d.ts"
121
+ }
115
122
  }
116
123
  }