@fluffylabs/anan-as 1.0.0 → 1.1.0

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/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@fluffylabs/anan-as",
3
3
  "description": "AssemblyScript PVM interpreter.",
4
- "version": "1.0.0",
5
- "main": "./bin/index.js",
4
+ "version": "1.1.0",
5
+ "main": "./bin/index.ts",
6
+ "repository": {
7
+ "url": "https://github.com/tomusdrw/anan-as"
8
+ },
6
9
  "scripts": {
7
- "asbuild": "npm run asbuild:debug && npm run asbuild:release && npm run asbuild:raw && npm run asbuild:release-mini",
10
+ "asbuild": "npm run asbuild:debug && npm run asbuild:release",
11
+ "asbuild:all": "npm run asbuild:debug && npm run asbuild:release && npm run asbuild:raw && npm run asbuild:release-mini && npm run asbuild:release-stub",
8
12
  "asbuild:debug": "asc assembly/index.ts --target debug",
9
13
  "asbuild:release": "asc assembly/index.ts --uncheckedBehavior=always --target release",
10
14
  "asbuild:release-mini": "asc assembly/index.ts --uncheckedBehavior=always --target release-mini",
15
+ "asbuild:release-stub": "asc assembly/index.ts --uncheckedBehavior=always --target release-stub",
11
16
  "asbuild:raw": "asc assembly/index.ts --target raw",
12
17
  "asbuild:test": "asc assembly/test-run.ts --target test",
13
- "build": "npm run asbuild && npm run cp-build",
18
+ "build": "npm run asbuild:all && npm run asbuild:test && npm run tsbuild && npm run build:inline && npm run cp-build",
19
+ "build:inline": "tsx ./bin/build-inline.ts",
14
20
  "cp-build": "rm -rf ./web/build; cp -r ./build ./web/",
15
21
  "format": "biome format --write",
16
- "fuzz": "npx @jazzer.js/core --sync ./bin/fuzz",
22
+ "fuzz": "tsx ./bin/fuzz.ts",
17
23
  "lint": "biome lint --write; biome check --write",
18
24
  "prestart": "npm run build",
19
25
  "pretest:w3f": "npm run build",
@@ -21,11 +27,12 @@
21
27
  "preweb": "npm run build",
22
28
  "qa": "biome ci",
23
29
  "qa-fix": "npm run format; npm run lint",
24
- "start": "node ./bin/index.js",
25
- "test": "npm run asbuild:test && node ./bin/test.js",
26
- "test:w3f": "node ./bin/test-w3f.js",
27
- "test:gas-cost": "node ./bin/test-gas-cost.js",
28
- "update-version": "node ./web/bump-version.js $GITHUB_SHA",
30
+ "start": "tsx ./bin/index.ts",
31
+ "test": "npm run asbuild:test && tsx ./bin/test.ts",
32
+ "tsbuild": "tsc",
33
+ "test:w3f": "tsx ./bin/test-w3f.ts",
34
+ "test:gas-cost": "tsx ./bin/test-gas-cost.ts",
35
+ "update-version": "tsx ./web/bump-version.ts $GITHUB_SHA",
29
36
  "web": "npx live-server ./web"
30
37
  },
31
38
  "type": "module",
@@ -34,7 +41,10 @@
34
41
  "license": "MPL-2.0",
35
42
  "devDependencies": {
36
43
  "@biomejs/biome": "^2.2.6",
37
- "assemblyscript": "^0.28.8"
44
+ "@types/node": "^24.8.1",
45
+ "assemblyscript": "^0.28.8",
46
+ "tsx": "^4.20.6",
47
+ "typescript": "^5.9.3"
38
48
  },
39
49
  "files": [
40
50
  "build/**/*.wasm",
@@ -57,16 +67,26 @@
57
67
  "types": "./build/release.d.ts"
58
68
  },
59
69
  "./release-mini": {
60
- "import": "./build/release.js",
61
- "types": "./build/release.d.ts"
70
+ "import": "./build/release-mini.js",
71
+ "types": "./build/release-mini.d.ts"
72
+ },
73
+ "./release-stub": {
74
+ "import": "./build/release-stub.js",
75
+ "types": "./build/release-stub.d.ts"
62
76
  },
63
77
  "./raw": {
64
78
  "import": "./build/debug-raw.js",
65
79
  "types": "./build/debug-raw.d.ts"
66
80
  },
67
81
  "./debug.wasm": "./build/debug.wasm",
82
+ "./debug-inline.js": "./build/debug-inline.js",
68
83
  "./release.wasm": "./build/release.wasm",
69
- "./release-mini.wasm": "./build/release-mini.wasm"
84
+ "./release-inline.js": "./build/release-inline.js",
85
+ "./release-mini.wasm": "./build/release-mini.wasm",
86
+ "./release-mini-inline.js": "./build/release-mini-inline.js",
87
+ "./release-stub.wasm": "./build/release-stub.wasm",
88
+ "./release-stub-inline.js": "./build/release-stub-inline.js"
89
+
70
90
  },
71
91
  "dependencies": {
72
92
  "@typeberry/lib": "^0.2.0",
@@ -1,210 +0,0 @@
1
- declare namespace __AdaptedExports {
2
- /** Exported memory */
3
- export const memory: WebAssembly.Memory;
4
- /**
5
- * assembly/api-internal/getAssembly
6
- * @param p `assembly/program/Program`
7
- * @returns `~lib/string/String`
8
- */
9
- export function getAssembly(p: __Internref26): string;
10
- /**
11
- * assembly/program-build/wrapAsProgram
12
- * @param bytecode `~lib/typedarray/Uint8Array`
13
- * @returns `~lib/typedarray/Uint8Array`
14
- */
15
- export function wrapAsProgram(bytecode: Uint8Array): Uint8Array;
16
- /**
17
- * assembly/api-debugger/resetJAM
18
- * @param program `~lib/array/Array<u8>`
19
- * @param pc `f64`
20
- * @param initialGas `i64`
21
- * @param args `~lib/array/Array<u8>`
22
- * @param hasMetadata `bool`
23
- */
24
- export function resetJAM(program: Array<number>, pc: number, initialGas: bigint, args: Array<number>, hasMetadata?: boolean): void;
25
- /**
26
- * assembly/api-debugger/resetGeneric
27
- * @param program `~lib/array/Array<u8>`
28
- * @param flatRegisters `~lib/array/Array<u8>`
29
- * @param initialGas `i64`
30
- * @param hasMetadata `bool`
31
- */
32
- export function resetGeneric(program: Array<number>, flatRegisters: Array<number>, initialGas: bigint, hasMetadata?: boolean): void;
33
- /**
34
- * assembly/api-debugger/resetGenericWithMemory
35
- * @param program `~lib/array/Array<u8>`
36
- * @param flatRegisters `~lib/array/Array<u8>`
37
- * @param pageMap `~lib/typedarray/Uint8Array`
38
- * @param chunks `~lib/typedarray/Uint8Array`
39
- * @param initialGas `i64`
40
- * @param hasMetadata `bool`
41
- */
42
- export function resetGenericWithMemory(program: Array<number>, flatRegisters: Array<number>, pageMap: Uint8Array, chunks: Uint8Array, initialGas: bigint, hasMetadata?: boolean): void;
43
- /**
44
- * assembly/api-debugger/nextStep
45
- * @returns `bool`
46
- */
47
- export function nextStep(): boolean;
48
- /**
49
- * assembly/api-debugger/nSteps
50
- * @param steps `u32`
51
- * @returns `bool`
52
- */
53
- export function nSteps(steps: number): boolean;
54
- /**
55
- * assembly/api-debugger/getProgramCounter
56
- * @returns `u32`
57
- */
58
- export function getProgramCounter(): number;
59
- /**
60
- * assembly/api-debugger/setNextProgramCounter
61
- * @param pc `u32`
62
- */
63
- export function setNextProgramCounter(pc: number): void;
64
- /**
65
- * assembly/api-debugger/getStatus
66
- * @returns `u8`
67
- */
68
- export function getStatus(): number;
69
- /**
70
- * assembly/api-debugger/getExitArg
71
- * @returns `u32`
72
- */
73
- export function getExitArg(): number;
74
- /**
75
- * assembly/api-debugger/getGasLeft
76
- * @returns `i64`
77
- */
78
- export function getGasLeft(): bigint;
79
- /**
80
- * assembly/api-debugger/setGasLeft
81
- * @param gas `i64`
82
- */
83
- export function setGasLeft(gas: bigint): void;
84
- /**
85
- * assembly/api-debugger/getRegisters
86
- * @returns `~lib/typedarray/Uint8Array`
87
- */
88
- export function getRegisters(): Uint8Array;
89
- /**
90
- * assembly/api-debugger/setRegisters
91
- * @param flatRegisters `~lib/array/Array<u8>`
92
- */
93
- export function setRegisters(flatRegisters: Array<number>): void;
94
- /**
95
- * assembly/api-debugger/getPageDump
96
- * @param index `u32`
97
- * @returns `~lib/typedarray/Uint8Array`
98
- */
99
- export function getPageDump(index: number): Uint8Array;
100
- /**
101
- * assembly/api-debugger/setMemory
102
- * @param address `u32`
103
- * @param data `~lib/typedarray/Uint8Array`
104
- */
105
- export function setMemory(address: number, data: Uint8Array): void;
106
- /** assembly/api-utils/InputKind */
107
- export enum InputKind {
108
- /** @type `i32` */
109
- Generic,
110
- /** @type `i32` */
111
- SPI,
112
- }
113
- /** assembly/api-utils/HasMetadata */
114
- export enum HasMetadata {
115
- /** @type `i32` */
116
- Yes,
117
- /** @type `i32` */
118
- No,
119
- }
120
- /**
121
- * assembly/api-utils/getGasCosts
122
- * @param input `~lib/array/Array<u8>`
123
- * @param kind `i32`
124
- * @param withMetadata `i32`
125
- * @returns `~lib/array/Array<assembly/gas-costs/BlockGasCost>`
126
- */
127
- export function getGasCosts(input: Array<number>, kind: number, withMetadata: number): Array<__Record50<never>>;
128
- /**
129
- * assembly/api-utils/disassemble
130
- * @param input `~lib/array/Array<u8>`
131
- * @param kind `i32`
132
- * @param withMetadata `i32`
133
- * @returns `~lib/string/String`
134
- */
135
- export function disassemble(input: Array<number>, kind: number, withMetadata: number): string;
136
- /**
137
- * assembly/api-utils/prepareProgram
138
- * @param kind `i32`
139
- * @param hasMetadata `i32`
140
- * @param program `~lib/array/Array<u8>`
141
- * @param initialRegisters `~lib/array/Array<u64>`
142
- * @param initialPageMap `~lib/array/Array<assembly/api-internal/InitialPage>`
143
- * @param initialMemory `~lib/array/Array<assembly/api-internal/InitialChunk>`
144
- * @param args `~lib/array/Array<u8>`
145
- * @returns `assembly/spi/StandardProgram`
146
- */
147
- export function prepareProgram(kind: number, hasMetadata: number, program: Array<number>, initialRegisters: Array<bigint>, initialPageMap: Array<__Record46<undefined>>, initialMemory: Array<__Record48<undefined>>, args: Array<number>): __Internref42;
148
- /**
149
- * assembly/api-utils/runProgram
150
- * @param program `assembly/spi/StandardProgram`
151
- * @param initialGas `i64`
152
- * @param programCounter `u32`
153
- * @param logs `bool`
154
- * @param useSbrkGas `bool`
155
- * @returns `assembly/api-internal/VmOutput`
156
- */
157
- export function runProgram(program: __Internref42, initialGas?: bigint, programCounter?: number, logs?: boolean, useSbrkGas?: boolean): __Record55<never>;
158
- }
159
- /** assembly/program/Program */
160
- declare class __Internref26 extends Number {
161
- private __nominal26: symbol;
162
- private __nominal0: symbol;
163
- }
164
- /** assembly/gas-costs/BlockGasCost */
165
- declare interface __Record50<TOmittable> {
166
- /** @type `u32` */
167
- pc: number | TOmittable;
168
- /** @type `u64` */
169
- gas: bigint | TOmittable;
170
- }
171
- /** assembly/api-internal/InitialPage */
172
- declare interface __Record46<TOmittable> {
173
- /** @type `u32` */
174
- address: number | TOmittable;
175
- /** @type `u32` */
176
- length: number | TOmittable;
177
- /** @type `i32` */
178
- access: number | TOmittable;
179
- }
180
- /** assembly/api-internal/InitialChunk */
181
- declare interface __Record48<TOmittable> {
182
- /** @type `u32` */
183
- address: number | TOmittable;
184
- /** @type `~lib/array/Array<u8>` */
185
- data: Array<number>;
186
- }
187
- /** assembly/spi/StandardProgram */
188
- declare class __Internref42 extends Number {
189
- private __nominal42: symbol;
190
- private __nominal0: symbol;
191
- }
192
- /** assembly/api-internal/VmOutput */
193
- declare interface __Record55<TOmittable> {
194
- /** @type `i32` */
195
- status: number | TOmittable;
196
- /** @type `~lib/array/Array<u64>` */
197
- registers: Array<bigint>;
198
- /** @type `u32` */
199
- pc: number | TOmittable;
200
- /** @type `~lib/array/Array<assembly/api-internal/InitialChunk>` */
201
- memory: Array<__Record48<never>>;
202
- /** @type `i64` */
203
- gas: bigint | TOmittable;
204
- /** @type `u32` */
205
- exitCode: number | TOmittable;
206
- }
207
- /** Instantiates the compiled WebAssembly module with the given imports. */
208
- export declare function instantiate(module: WebAssembly.Module, imports: {
209
- env: unknown,
210
- }): Promise<typeof __AdaptedExports>;
Binary file
package/build/tests.d.ts DELETED
@@ -1,24 +0,0 @@
1
- /** Exported memory */
2
- export declare const memory: WebAssembly.Memory;
3
- /**
4
- * assembly/tests/test
5
- * @param name `~lib/string/String`
6
- * @param cb `() => void`
7
- */
8
- export declare function test(name: string, cb: __Internref21): void;
9
- /**
10
- * assembly/tests/assertEqual<u64>
11
- * @param a `u64`
12
- * @param b `u64`
13
- * @param msg `~lib/string/String`
14
- */
15
- export declare function assertEqual(a: bigint, b: bigint, msg?: string): void;
16
- /**
17
- * assembly/tests/runTests
18
- */
19
- export declare function runTests(): void;
20
- /** ~lib/function/Function<%28%29=>void> */
21
- declare class __Internref21 extends Number {
22
- private __nominal21: symbol;
23
- private __nominal0: symbol;
24
- }
package/build/tests.js DELETED
@@ -1,104 +0,0 @@
1
- async function instantiate(module, imports = {}) {
2
- const adaptedImports = {
3
- env: Object.assign(Object.create(globalThis), imports.env || {}, {
4
- abort(message, fileName, lineNumber, columnNumber) {
5
- // ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
6
- message = __liftString(message >>> 0);
7
- fileName = __liftString(fileName >>> 0);
8
- lineNumber = lineNumber >>> 0;
9
- columnNumber = columnNumber >>> 0;
10
- (() => {
11
- // @external.js
12
- throw Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
13
- })();
14
- },
15
- "console.log"(text) {
16
- // ~lib/bindings/dom/console.log(~lib/string/String) => void
17
- text = __liftString(text >>> 0);
18
- console.log(text);
19
- },
20
- }),
21
- };
22
- const { exports } = await WebAssembly.instantiate(module, adaptedImports);
23
- const memory = exports.memory || imports.env.memory;
24
- const adaptedExports = Object.setPrototypeOf({
25
- test(name, cb) {
26
- // assembly/tests/test(~lib/string/String, () => void) => void
27
- name = __retain(__lowerString(name) || __notnull());
28
- cb = __lowerInternref(cb) || __notnull();
29
- try {
30
- exports.test(name, cb);
31
- } finally {
32
- __release(name);
33
- }
34
- },
35
- assertEqual(a, b, msg) {
36
- // assembly/tests/assertEqual<u64>(u64, u64, ~lib/string/String?) => void
37
- a = a || 0n;
38
- b = b || 0n;
39
- msg = __lowerString(msg) || __notnull();
40
- exports.__setArgumentsLength(arguments.length);
41
- exports.assertEqual(a, b, msg);
42
- },
43
- }, exports);
44
- function __liftString(pointer) {
45
- if (!pointer) return null;
46
- const
47
- end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1,
48
- memoryU16 = new Uint16Array(memory.buffer);
49
- let
50
- start = pointer >>> 1,
51
- string = "";
52
- while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
53
- return string + String.fromCharCode(...memoryU16.subarray(start, end));
54
- }
55
- function __lowerString(value) {
56
- if (value == null) return 0;
57
- const
58
- length = value.length,
59
- pointer = exports.__new(length << 1, 2) >>> 0,
60
- memoryU16 = new Uint16Array(memory.buffer);
61
- for (let i = 0; i < length; ++i) memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
62
- return pointer;
63
- }
64
- class Internref extends Number {}
65
- function __lowerInternref(value) {
66
- if (value == null) return 0;
67
- if (value instanceof Internref) return value.valueOf();
68
- throw TypeError("internref expected");
69
- }
70
- const refcounts = new Map();
71
- function __retain(pointer) {
72
- if (pointer) {
73
- const refcount = refcounts.get(pointer);
74
- if (refcount) refcounts.set(pointer, refcount + 1);
75
- else refcounts.set(exports.__pin(pointer), 1);
76
- }
77
- return pointer;
78
- }
79
- function __release(pointer) {
80
- if (pointer) {
81
- const refcount = refcounts.get(pointer);
82
- if (refcount === 1) exports.__unpin(pointer), refcounts.delete(pointer);
83
- else if (refcount) refcounts.set(pointer, refcount - 1);
84
- else throw Error(`invalid refcount '${refcount}' for reference '${pointer}'`);
85
- }
86
- }
87
- function __notnull() {
88
- throw TypeError("value must not be null");
89
- }
90
- return adaptedExports;
91
- }
92
- export const {
93
- memory,
94
- test,
95
- assertEqual,
96
- runTests,
97
- } = await (async url => instantiate(
98
- await (async () => {
99
- const isNodeOrBun = typeof process != "undefined" && process.versions != null && (process.versions.node != null || process.versions.bun != null);
100
- if (isNodeOrBun) { return globalThis.WebAssembly.compile(await (await import("node:fs/promises")).readFile(url)); }
101
- else { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); }
102
- })(), {
103
- }
104
- ))(new URL("tests.wasm", import.meta.url));
package/build/tests.wasm DELETED
Binary file