@fluffylabs/anan-as 1.2.0-ef04361 → 1.3.0-1ebcf8f

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 (85) hide show
  1. package/dist/bin/index.js +138 -5
  2. package/dist/bin/src/fuzz.js +2 -2
  3. package/dist/bin/src/test-json.js +2 -6
  4. package/dist/bin/src/trace-parse.js +1 -0
  5. package/dist/bin/src/trace-replay.js +14 -9
  6. package/dist/bin/src/tracer.js +16 -13
  7. package/dist/bin/src/utils.js +2 -2
  8. package/dist/build/compiler-inline.js +1 -1
  9. package/dist/build/compiler.d.ts +17 -13
  10. package/dist/build/compiler.js +13 -21
  11. package/dist/build/compiler.wasm +0 -0
  12. package/dist/build/debug-inline.js +1 -1
  13. package/dist/build/debug-raw-inline.js +1 -1
  14. package/dist/build/debug-raw.d.ts +34 -32
  15. package/dist/build/debug-raw.js +62 -69
  16. package/dist/build/debug-raw.wasm +0 -0
  17. package/dist/build/debug.d.ts +34 -32
  18. package/dist/build/debug.js +63 -70
  19. package/dist/build/debug.wasm +0 -0
  20. package/dist/build/js/assembly/api-debugger.d.ts +4 -4
  21. package/dist/build/js/assembly/api-debugger.js +6 -6
  22. package/dist/build/js/assembly/api-internal.d.ts +1 -1
  23. package/dist/build/js/assembly/api-internal.js +2 -3
  24. package/dist/build/js/assembly/api-types.d.ts +4 -4
  25. package/dist/build/js/assembly/api-types.js +3 -4
  26. package/dist/build/js/assembly/api-utils.d.ts +14 -6
  27. package/dist/build/js/assembly/api-utils.js +28 -13
  28. package/dist/build/js/assembly/arguments.d.ts +4 -4
  29. package/dist/build/js/assembly/arguments.js +10 -10
  30. package/dist/build/js/assembly/gas.d.ts +8 -13
  31. package/dist/build/js/assembly/gas.js +17 -7
  32. package/dist/build/js/assembly/instructions/bit.js +22 -22
  33. package/dist/build/js/assembly/instructions/branch.js +56 -56
  34. package/dist/build/js/assembly/instructions/jump.js +10 -10
  35. package/dist/build/js/assembly/instructions/load.js +41 -41
  36. package/dist/build/js/assembly/instructions/logic.js +20 -20
  37. package/dist/build/js/assembly/instructions/math.js +105 -105
  38. package/dist/build/js/assembly/instructions/misc.js +10 -10
  39. package/dist/build/js/assembly/instructions/mov.js +16 -16
  40. package/dist/build/js/assembly/instructions/outcome.d.ts +7 -7
  41. package/dist/build/js/assembly/instructions/outcome.js +63 -38
  42. package/dist/build/js/assembly/instructions/rot.js +18 -18
  43. package/dist/build/js/assembly/instructions/set.js +18 -18
  44. package/dist/build/js/assembly/instructions/shift.js +59 -59
  45. package/dist/build/js/assembly/instructions/store.js +29 -29
  46. package/dist/build/js/assembly/instructions/utils.d.ts +6 -4
  47. package/dist/build/js/assembly/instructions/utils.js +32 -16
  48. package/dist/build/js/assembly/instructions.d.ts +2 -3
  49. package/dist/build/js/assembly/instructions.js +4 -4
  50. package/dist/build/js/assembly/interpreter.d.ts +0 -1
  51. package/dist/build/js/assembly/interpreter.js +30 -38
  52. package/dist/build/js/assembly/math.d.ts +6 -8
  53. package/dist/build/js/assembly/math.js +21 -13
  54. package/dist/build/js/assembly/memory-page.d.ts +2 -4
  55. package/dist/build/js/assembly/memory-page.js +13 -7
  56. package/dist/build/js/assembly/memory.d.ts +1 -0
  57. package/dist/build/js/assembly/memory.js +119 -23
  58. package/dist/build/js/assembly/portable.js +1 -0
  59. package/dist/build/js/assembly/program-build.js +4 -4
  60. package/dist/build/js/assembly/program.d.ts +15 -8
  61. package/dist/build/js/assembly/program.js +95 -39
  62. package/dist/build/js/assembly/spi.d.ts +1 -1
  63. package/dist/build/js/assembly/spi.js +2 -2
  64. package/dist/build/js/portable/bootstrap.js +1 -0
  65. package/dist/build/js/portable-bundle.js +829 -641
  66. package/dist/build/release-inline.js +1 -1
  67. package/dist/build/release-mini-inline.js +1 -1
  68. package/dist/build/release-mini.d.ts +34 -32
  69. package/dist/build/release-mini.js +63 -70
  70. package/dist/build/release-mini.wasm +0 -0
  71. package/dist/build/release-stub-inline.js +1 -1
  72. package/dist/build/release-stub.d.ts +34 -32
  73. package/dist/build/release-stub.js +63 -70
  74. package/dist/build/release-stub.wasm +0 -0
  75. package/dist/build/release.d.ts +34 -32
  76. package/dist/build/release.js +63 -70
  77. package/dist/build/release.wasm +0 -0
  78. package/dist/build/test-inline.js +1 -1
  79. package/dist/build/test.wasm +0 -0
  80. package/dist/test/test-gas-cost.js +2 -3
  81. package/dist/test/test-trace-format.js +166 -0
  82. package/dist/test/test-w3f-common.js +1 -2
  83. package/package.json +14 -10
  84. package/dist/build/js/assembly/gas-costs.d.ts +0 -6
  85. package/dist/build/js/assembly/gas-costs.js +0 -39
@@ -5,7 +5,7 @@ export declare const memory: WebAssembly.Memory;
5
5
  * @param p `assembly/program/Program`
6
6
  * @returns `~lib/string/String`
7
7
  */
8
- export declare function getAssembly(p: __Internref28): string;
8
+ export declare function getAssembly(p: __Internref35): string;
9
9
  /**
10
10
  * assembly/program-build/wrapAsProgram
11
11
  * @param bytecode `~lib/typedarray/Uint8Array`
@@ -16,29 +16,32 @@ export declare function wrapAsProgram(bytecode: Uint8Array): Uint8Array;
16
16
  * assembly/api-debugger/resetJAM
17
17
  * @param program `~lib/array/Array<u8>`
18
18
  * @param pc `u32`
19
- * @param initialGas `i64`
19
+ * @param initialGas `u64`
20
20
  * @param args `~lib/array/Array<u8>`
21
21
  * @param hasMetadata `bool`
22
+ * @param useBlockGas `bool`
22
23
  */
23
- export declare function resetJAM(program: Array<number>, pc: number, initialGas: bigint, args: Array<number>, hasMetadata?: boolean): void;
24
+ export declare function resetJAM(program: Array<number>, pc: number, initialGas: bigint, args: Array<number>, hasMetadata?: boolean, useBlockGas?: boolean): void;
24
25
  /**
25
26
  * assembly/api-debugger/resetGeneric
26
27
  * @param program `~lib/array/Array<u8>`
27
28
  * @param flatRegisters `~lib/array/Array<u8>`
28
- * @param initialGas `i64`
29
+ * @param initialGas `u64`
29
30
  * @param hasMetadata `bool`
31
+ * @param useBlockGas `bool`
30
32
  */
31
- export declare function resetGeneric(program: Array<number>, flatRegisters: Array<number>, initialGas: bigint, hasMetadata?: boolean): void;
33
+ export declare function resetGeneric(program: Array<number>, flatRegisters: Array<number>, initialGas: bigint, hasMetadata?: boolean, useBlockGas?: boolean): void;
32
34
  /**
33
35
  * assembly/api-debugger/resetGenericWithMemory
34
36
  * @param program `~lib/array/Array<u8>`
35
37
  * @param flatRegisters `~lib/array/Array<u8>`
36
38
  * @param pageMap `~lib/typedarray/Uint8Array`
37
39
  * @param chunks `~lib/typedarray/Uint8Array`
38
- * @param initialGas `i64`
40
+ * @param initialGas `u64`
39
41
  * @param hasMetadata `bool`
42
+ * @param useBlockGas `bool`
40
43
  */
41
- export declare function resetGenericWithMemory(program: Array<number>, flatRegisters: Array<number>, pageMap: Uint8Array, chunks: Uint8Array, initialGas: bigint, hasMetadata?: boolean): void;
44
+ export declare function resetGenericWithMemory(program: Array<number>, flatRegisters: Array<number>, pageMap: Uint8Array, chunks: Uint8Array, initialGas: bigint, hasMetadata?: boolean, useBlockGas?: boolean): void;
42
45
  /**
43
46
  * assembly/api-debugger/nextStep
44
47
  * @returns `bool`
@@ -77,7 +80,7 @@ export declare function getExitArg(): number;
77
80
  export declare function getGasLeft(): bigint;
78
81
  /**
79
82
  * assembly/api-debugger/setGasLeft
80
- * @param gas `i64`
83
+ * @param gas `u64`
81
84
  */
82
85
  export declare function setGasLeft(gas: bigint): void;
83
86
  /**
@@ -131,13 +134,13 @@ export declare enum HasMetadata {
131
134
  No,
132
135
  }
133
136
  /**
134
- * assembly/api-utils/getGasCosts
137
+ * assembly/api-utils/getBlockGasCosts
135
138
  * @param input `~lib/array/Array<u8>`
136
139
  * @param kind `i32`
137
140
  * @param withMetadata `i32`
138
- * @returns `~lib/array/Array<assembly/gas-costs/BlockGasCost>`
141
+ * @returns `~lib/array/Array<assembly/api-utils/BlockGasCost>`
139
142
  */
140
- export declare function getGasCosts(input: Array<number>, kind: number, withMetadata: number): Array<__Record53<never>>;
143
+ export declare function getBlockGasCosts(input: Array<number>, kind: number, withMetadata: number): Array<__Record58<never>>;
141
144
  /**
142
145
  * assembly/api-utils/disassemble
143
146
  * @param input `~lib/array/Array<u8>`
@@ -156,33 +159,32 @@ export declare function disassemble(input: Array<number>, kind: number, withMeta
156
159
  * @param initialMemory `~lib/array/Array<assembly/api-types/InitialChunk>`
157
160
  * @param args `~lib/array/Array<u8>`
158
161
  * @param preallocateMemoryPages `u32`
162
+ * @param useBlockGas `bool`
159
163
  * @returns `assembly/spi/StandardProgram`
160
164
  */
161
- export declare function prepareProgram(kind: number, hasMetadata: number, program: Array<number>, initialRegisters: Array<bigint>, initialPageMap: Array<__Record49<undefined>>, initialMemory: Array<__Record51<undefined>>, args: Array<number>, preallocateMemoryPages: number): __Internref45;
165
+ export declare function prepareProgram(kind: number, hasMetadata: number, program: Array<number>, initialRegisters: Array<bigint>, initialPageMap: Array<__Record54<undefined>>, initialMemory: Array<__Record56<undefined>>, args: Array<number>, preallocateMemoryPages: number, useBlockGas: boolean): __Internref51;
162
166
  /**
163
167
  * assembly/api-utils/runProgram
164
168
  * @param program `assembly/spi/StandardProgram`
165
169
  * @param initialGas `i64`
166
170
  * @param programCounter `u32`
167
171
  * @param logs `bool`
168
- * @param useSbrkGas `bool`
169
172
  * @param dumpMemory `bool`
170
173
  * @returns `assembly/api-types/VmOutput`
171
174
  */
172
- export declare function runProgram(program: __Internref45, initialGas?: bigint, programCounter?: number, logs?: boolean, useSbrkGas?: boolean, dumpMemory?: boolean): __Record58<never>;
175
+ export declare function runProgram(program: __Internref51, initialGas?: bigint, programCounter?: number, logs?: boolean, dumpMemory?: boolean): __Record62<never>;
173
176
  /**
174
177
  * assembly/api-utils/pvmStart
175
178
  * @param program `assembly/spi/StandardProgram`
176
- * @param useSbrkGas `bool`
177
179
  * @returns `u32`
178
180
  */
179
- export declare function pvmStart(program: __Internref45, useSbrkGas?: boolean): number;
181
+ export declare function pvmStart(program: __Internref51): number;
180
182
  /**
181
183
  * assembly/api-utils/pvmDestroy
182
184
  * @param pvmId `u32`
183
185
  * @returns `assembly/api-types/VmOutput | null`
184
186
  */
185
- export declare function pvmDestroy(pvmId: number): __Record58<never> | null;
187
+ export declare function pvmDestroy(pvmId: number): __Record62<never> | null;
186
188
  /**
187
189
  * assembly/api-utils/pvmSetRegisters
188
190
  * @param pvmId `u32`
@@ -215,26 +217,26 @@ export declare function pvmWriteMemory(pvmId: number, address: number, data: Uin
215
217
  /**
216
218
  * assembly/api-utils/pvmResume
217
219
  * @param pvmId `u32`
218
- * @param gas `i64`
220
+ * @param gas `u64`
219
221
  * @param pc `u32`
220
222
  * @param logs `bool`
221
223
  * @returns `assembly/api-types/VmPause | null`
222
224
  */
223
- export declare function pvmResume(pvmId: number, gas: bigint, pc: number, logs?: boolean): __Record64<never> | null;
225
+ export declare function pvmResume(pvmId: number, gas: bigint, pc: number, logs?: boolean): __Record68<never> | null;
224
226
  /** assembly/program/Program */
225
- declare class __Internref28 extends Number {
226
- private __nominal28: symbol;
227
+ declare class __Internref35 extends Number {
228
+ private __nominal35: symbol;
227
229
  private __nominal0: symbol;
228
230
  }
229
- /** assembly/gas-costs/BlockGasCost */
230
- declare interface __Record53<TOmittable> {
231
+ /** assembly/api-utils/BlockGasCost */
232
+ declare interface __Record58<TOmittable> {
231
233
  /** @type `u32` */
232
234
  pc: number | TOmittable;
233
235
  /** @type `u64` */
234
236
  gas: bigint | TOmittable;
235
237
  }
236
238
  /** assembly/api-types/InitialPage */
237
- declare interface __Record49<TOmittable> {
239
+ declare interface __Record54<TOmittable> {
238
240
  /** @type `u32` */
239
241
  address: number | TOmittable;
240
242
  /** @type `u32` */
@@ -243,36 +245,36 @@ declare interface __Record49<TOmittable> {
243
245
  access: number | TOmittable;
244
246
  }
245
247
  /** assembly/api-types/InitialChunk */
246
- declare interface __Record51<TOmittable> {
248
+ declare interface __Record56<TOmittable> {
247
249
  /** @type `u32` */
248
250
  address: number | TOmittable;
249
251
  /** @type `~lib/array/Array<u8>` */
250
252
  data: Array<number>;
251
253
  }
252
254
  /** assembly/spi/StandardProgram */
253
- declare class __Internref45 extends Number {
254
- private __nominal45: symbol;
255
+ declare class __Internref51 extends Number {
256
+ private __nominal51: symbol;
255
257
  private __nominal0: symbol;
256
258
  }
257
259
  /** assembly/api-types/VmOutput */
258
- declare interface __Record58<TOmittable> {
260
+ declare interface __Record62<TOmittable> {
259
261
  /** @type `i32` */
260
262
  status: number | TOmittable;
261
263
  /** @type `u32` */
262
264
  exitCode: number | TOmittable;
263
265
  /** @type `u32` */
264
266
  pc: number | TOmittable;
265
- /** @type `i64` */
267
+ /** @type `u64` */
266
268
  gas: bigint | TOmittable;
267
269
  /** @type `~lib/array/Array<u8>` */
268
270
  result: Array<number>;
269
271
  /** @type `~lib/array/Array<u64>` */
270
272
  registers: Array<bigint>;
271
273
  /** @type `~lib/array/Array<assembly/api-types/InitialChunk>` */
272
- memory: Array<__Record51<never>>;
274
+ memory: Array<__Record56<never>>;
273
275
  }
274
276
  /** assembly/api-types/VmPause */
275
- declare interface __Record64<TOmittable> {
277
+ declare interface __Record68<TOmittable> {
276
278
  /** @type `i32` */
277
279
  status: number | TOmittable;
278
280
  /** @type `u32` */
@@ -281,7 +283,7 @@ declare interface __Record64<TOmittable> {
281
283
  pc: number | TOmittable;
282
284
  /** @type `u32` */
283
285
  nextPc: number | TOmittable;
284
- /** @type `i64` */
286
+ /** @type `u64` */
285
287
  gas: bigint | TOmittable;
286
288
  /** @type `~lib/array/Array<u64>` */
287
289
  registers: Array<bigint>;
@@ -29,46 +29,49 @@ async function instantiate(module, imports = {}) {
29
29
  },
30
30
  wrapAsProgram(bytecode) {
31
31
  // assembly/program-build/wrapAsProgram(~lib/typedarray/Uint8Array) => ~lib/typedarray/Uint8Array
32
- bytecode = __lowerTypedArray(Uint8Array, 12, 0, bytecode) || __notnull();
32
+ bytecode = __lowerTypedArray(Uint8Array, 15, 0, bytecode) || __notnull();
33
33
  return __liftTypedArray(Uint8Array, exports.wrapAsProgram(bytecode) >>> 0);
34
34
  },
35
- resetJAM(program, pc, initialGas, args, hasMetadata) {
36
- // assembly/api-debugger/resetJAM(~lib/array/Array<u8>, u32, i64, ~lib/array/Array<u8>, bool?) => void
37
- program = __retain(__lowerArray(__setU8, 7, 0, program) || __notnull());
35
+ resetJAM(program, pc, initialGas, args, hasMetadata, useBlockGas) {
36
+ // assembly/api-debugger/resetJAM(~lib/array/Array<u8>, u32, u64, ~lib/array/Array<u8>, bool?, bool?) => void
37
+ program = __retain(__lowerArray(__setU8, 32, 0, program) || __notnull());
38
38
  initialGas = initialGas || 0n;
39
- args = __lowerArray(__setU8, 7, 0, args) || __notnull();
39
+ args = __lowerArray(__setU8, 32, 0, args) || __notnull();
40
40
  hasMetadata = hasMetadata ? 1 : 0;
41
+ useBlockGas = useBlockGas ? 1 : 0;
41
42
  try {
42
43
  exports.__setArgumentsLength(arguments.length);
43
- exports.resetJAM(program, pc, initialGas, args, hasMetadata);
44
+ exports.resetJAM(program, pc, initialGas, args, hasMetadata, useBlockGas);
44
45
  } finally {
45
46
  __release(program);
46
47
  }
47
48
  },
48
- resetGeneric(program, flatRegisters, initialGas, hasMetadata) {
49
- // assembly/api-debugger/resetGeneric(~lib/array/Array<u8>, ~lib/array/Array<u8>, i64, bool?) => void
50
- program = __retain(__lowerArray(__setU8, 7, 0, program) || __notnull());
51
- flatRegisters = __lowerArray(__setU8, 7, 0, flatRegisters) || __notnull();
49
+ resetGeneric(program, flatRegisters, initialGas, hasMetadata, useBlockGas) {
50
+ // assembly/api-debugger/resetGeneric(~lib/array/Array<u8>, ~lib/array/Array<u8>, u64, bool?, bool?) => void
51
+ program = __retain(__lowerArray(__setU8, 32, 0, program) || __notnull());
52
+ flatRegisters = __lowerArray(__setU8, 32, 0, flatRegisters) || __notnull();
52
53
  initialGas = initialGas || 0n;
53
54
  hasMetadata = hasMetadata ? 1 : 0;
55
+ useBlockGas = useBlockGas ? 1 : 0;
54
56
  try {
55
57
  exports.__setArgumentsLength(arguments.length);
56
- exports.resetGeneric(program, flatRegisters, initialGas, hasMetadata);
58
+ exports.resetGeneric(program, flatRegisters, initialGas, hasMetadata, useBlockGas);
57
59
  } finally {
58
60
  __release(program);
59
61
  }
60
62
  },
61
- resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata) {
62
- // assembly/api-debugger/resetGenericWithMemory(~lib/array/Array<u8>, ~lib/array/Array<u8>, ~lib/typedarray/Uint8Array, ~lib/typedarray/Uint8Array, i64, bool?) => void
63
- program = __retain(__lowerArray(__setU8, 7, 0, program) || __notnull());
64
- flatRegisters = __retain(__lowerArray(__setU8, 7, 0, flatRegisters) || __notnull());
65
- pageMap = __retain(__lowerTypedArray(Uint8Array, 12, 0, pageMap) || __notnull());
66
- chunks = __lowerTypedArray(Uint8Array, 12, 0, chunks) || __notnull();
63
+ resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata, useBlockGas) {
64
+ // assembly/api-debugger/resetGenericWithMemory(~lib/array/Array<u8>, ~lib/array/Array<u8>, ~lib/typedarray/Uint8Array, ~lib/typedarray/Uint8Array, u64, bool?, bool?) => void
65
+ program = __retain(__lowerArray(__setU8, 32, 0, program) || __notnull());
66
+ flatRegisters = __retain(__lowerArray(__setU8, 32, 0, flatRegisters) || __notnull());
67
+ pageMap = __retain(__lowerTypedArray(Uint8Array, 15, 0, pageMap) || __notnull());
68
+ chunks = __lowerTypedArray(Uint8Array, 15, 0, chunks) || __notnull();
67
69
  initialGas = initialGas || 0n;
68
70
  hasMetadata = hasMetadata ? 1 : 0;
71
+ useBlockGas = useBlockGas ? 1 : 0;
69
72
  try {
70
73
  exports.__setArgumentsLength(arguments.length);
71
- exports.resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata);
74
+ exports.resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata, useBlockGas);
72
75
  } finally {
73
76
  __release(program);
74
77
  __release(flatRegisters);
@@ -92,7 +95,7 @@ async function instantiate(module, imports = {}) {
92
95
  return exports.getExitArg() >>> 0;
93
96
  },
94
97
  setGasLeft(gas) {
95
- // assembly/api-debugger/setGasLeft(i64) => void
98
+ // assembly/api-debugger/setGasLeft(u64) => void
96
99
  gas = gas || 0n;
97
100
  exports.setGasLeft(gas);
98
101
  },
@@ -102,7 +105,7 @@ async function instantiate(module, imports = {}) {
102
105
  },
103
106
  setRegisters(flatRegisters) {
104
107
  // assembly/api-debugger/setRegisters(~lib/array/Array<u8>) => void
105
- flatRegisters = __lowerArray(__setU8, 7, 0, flatRegisters) || __notnull();
108
+ flatRegisters = __lowerArray(__setU8, 32, 0, flatRegisters) || __notnull();
106
109
  exports.setRegisters(flatRegisters);
107
110
  },
108
111
  getPageDump(index) {
@@ -119,7 +122,7 @@ async function instantiate(module, imports = {}) {
119
122
  },
120
123
  setMemory(address, data) {
121
124
  // assembly/api-debugger/setMemory(u32, ~lib/typedarray/Uint8Array) => bool
122
- data = __lowerTypedArray(Uint8Array, 12, 0, data) || __notnull();
125
+ data = __lowerTypedArray(Uint8Array, 15, 0, data) || __notnull();
123
126
  return exports.setMemory(address, data) != 0;
124
127
  },
125
128
  InputKind: (values => (
@@ -134,25 +137,26 @@ async function instantiate(module, imports = {}) {
134
137
  values[values.No = exports["HasMetadata.No"].valueOf()] = "No",
135
138
  values
136
139
  ))({}),
137
- getGasCosts(input, kind, withMetadata) {
138
- // assembly/api-utils/getGasCosts(~lib/array/Array<u8>, i32, i32) => ~lib/array/Array<assembly/gas-costs/BlockGasCost>
139
- input = __lowerArray(__setU8, 7, 0, input) || __notnull();
140
- return __liftArray(pointer => __liftRecord53(__getU32(pointer)), 2, exports.getGasCosts(input, kind, withMetadata) >>> 0);
140
+ getBlockGasCosts(input, kind, withMetadata) {
141
+ // assembly/api-utils/getBlockGasCosts(~lib/array/Array<u8>, i32, i32) => ~lib/array/Array<assembly/api-utils/BlockGasCost>
142
+ input = __lowerArray(__setU8, 32, 0, input) || __notnull();
143
+ return __liftArray(pointer => __liftRecord58(__getU32(pointer)), 2, exports.getBlockGasCosts(input, kind, withMetadata) >>> 0);
141
144
  },
142
145
  disassemble(input, kind, withMetadata) {
143
146
  // assembly/api-utils/disassemble(~lib/array/Array<u8>, i32, i32) => ~lib/string/String
144
- input = __lowerArray(__setU8, 7, 0, input) || __notnull();
147
+ input = __lowerArray(__setU8, 32, 0, input) || __notnull();
145
148
  return __liftString(exports.disassemble(input, kind, withMetadata) >>> 0);
146
149
  },
147
- prepareProgram(kind, hasMetadata, program, initialRegisters, initialPageMap, initialMemory, args, preallocateMemoryPages) {
148
- // assembly/api-utils/prepareProgram(i32, i32, ~lib/array/Array<u8>, ~lib/array/Array<u64>, ~lib/array/Array<assembly/api-types/InitialPage>, ~lib/array/Array<assembly/api-types/InitialChunk>, ~lib/array/Array<u8>, u32) => assembly/spi/StandardProgram
149
- program = __retain(__lowerArray(__setU8, 7, 0, program) || __notnull());
150
- initialRegisters = __retain(__lowerArray(__setU64, 55, 3, initialRegisters) || __notnull());
151
- initialPageMap = __retain(__lowerArray((pointer, value) => { __setU32(pointer, __lowerRecord49(value) || __notnull()); }, 50, 2, initialPageMap) || __notnull());
152
- initialMemory = __retain(__lowerArray((pointer, value) => { __setU32(pointer, __lowerRecord51(value) || __notnull()); }, 52, 2, initialMemory) || __notnull());
153
- args = __lowerArray(__setU8, 7, 0, args) || __notnull();
150
+ prepareProgram(kind, hasMetadata, program, initialRegisters, initialPageMap, initialMemory, args, preallocateMemoryPages, useBlockGas) {
151
+ // assembly/api-utils/prepareProgram(i32, i32, ~lib/array/Array<u8>, ~lib/array/Array<u64>, ~lib/array/Array<assembly/api-types/InitialPage>, ~lib/array/Array<assembly/api-types/InitialChunk>, ~lib/array/Array<u8>, u32, bool) => assembly/spi/StandardProgram
152
+ program = __retain(__lowerArray(__setU8, 32, 0, program) || __notnull());
153
+ initialRegisters = __retain(__lowerArray(__setU64, 60, 3, initialRegisters) || __notnull());
154
+ initialPageMap = __retain(__lowerArray((pointer, value) => { __setU32(pointer, __lowerRecord54(value) || __notnull()); }, 55, 2, initialPageMap) || __notnull());
155
+ initialMemory = __retain(__lowerArray((pointer, value) => { __setU32(pointer, __lowerRecord56(value) || __notnull()); }, 57, 2, initialMemory) || __notnull());
156
+ args = __lowerArray(__setU8, 32, 0, args) || __notnull();
157
+ useBlockGas = useBlockGas ? 1 : 0;
154
158
  try {
155
- return __liftInternref(exports.prepareProgram(kind, hasMetadata, program, initialRegisters, initialPageMap, initialMemory, args, preallocateMemoryPages) >>> 0);
159
+ return __liftInternref(exports.prepareProgram(kind, hasMetadata, program, initialRegisters, initialPageMap, initialMemory, args, preallocateMemoryPages, useBlockGas) >>> 0);
156
160
  } finally {
157
161
  __release(program);
158
162
  __release(initialRegisters);
@@ -160,30 +164,27 @@ async function instantiate(module, imports = {}) {
160
164
  __release(initialMemory);
161
165
  }
162
166
  },
163
- runProgram(program, initialGas, programCounter, logs, useSbrkGas, dumpMemory) {
164
- // assembly/api-utils/runProgram(assembly/spi/StandardProgram, i64?, u32?, bool?, bool?, bool?) => assembly/api-types/VmOutput
167
+ runProgram(program, initialGas, programCounter, logs, dumpMemory) {
168
+ // assembly/api-utils/runProgram(assembly/spi/StandardProgram, i64?, u32?, bool?, bool?) => assembly/api-types/VmOutput
165
169
  program = __lowerInternref(program) || __notnull();
166
170
  initialGas = initialGas || 0n;
167
171
  logs = logs ? 1 : 0;
168
- useSbrkGas = useSbrkGas ? 1 : 0;
169
172
  dumpMemory = dumpMemory ? 1 : 0;
170
173
  exports.__setArgumentsLength(arguments.length);
171
- return __liftRecord58(exports.runProgram(program, initialGas, programCounter, logs, useSbrkGas, dumpMemory) >>> 0);
174
+ return __liftRecord62(exports.runProgram(program, initialGas, programCounter, logs, dumpMemory) >>> 0);
172
175
  },
173
- pvmStart(program, useSbrkGas) {
174
- // assembly/api-utils/pvmStart(assembly/spi/StandardProgram, bool?) => u32
176
+ pvmStart(program) {
177
+ // assembly/api-utils/pvmStart(assembly/spi/StandardProgram) => u32
175
178
  program = __lowerInternref(program) || __notnull();
176
- useSbrkGas = useSbrkGas ? 1 : 0;
177
- exports.__setArgumentsLength(arguments.length);
178
- return exports.pvmStart(program, useSbrkGas) >>> 0;
179
+ return exports.pvmStart(program) >>> 0;
179
180
  },
180
181
  pvmDestroy(pvmId) {
181
182
  // assembly/api-utils/pvmDestroy(u32) => assembly/api-types/VmOutput | null
182
- return __liftRecord58(exports.pvmDestroy(pvmId) >>> 0);
183
+ return __liftRecord62(exports.pvmDestroy(pvmId) >>> 0);
183
184
  },
184
185
  pvmSetRegisters(pvmId, registers) {
185
186
  // assembly/api-utils/pvmSetRegisters(u32, ~lib/array/Array<u64>) => void
186
- registers = __lowerArray(__setU64, 55, 3, registers) || __notnull();
187
+ registers = __lowerArray(__setU64, 60, 3, registers) || __notnull();
187
188
  exports.pvmSetRegisters(pvmId, registers);
188
189
  },
189
190
  pvmReadMemory(pvmId, address, length) {
@@ -196,19 +197,19 @@ async function instantiate(module, imports = {}) {
196
197
  },
197
198
  pvmWriteMemory(pvmId, address, data) {
198
199
  // assembly/api-utils/pvmWriteMemory(u32, u32, ~lib/typedarray/Uint8Array) => bool
199
- data = __lowerTypedArray(Uint8Array, 12, 0, data) || __notnull();
200
+ data = __lowerTypedArray(Uint8Array, 15, 0, data) || __notnull();
200
201
  return exports.pvmWriteMemory(pvmId, address, data) != 0;
201
202
  },
202
203
  pvmResume(pvmId, gas, pc, logs) {
203
- // assembly/api-utils/pvmResume(u32, i64, u32, bool?) => assembly/api-types/VmPause | null
204
+ // assembly/api-utils/pvmResume(u32, u64, u32, bool?) => assembly/api-types/VmPause | null
204
205
  gas = gas || 0n;
205
206
  logs = logs ? 1 : 0;
206
207
  exports.__setArgumentsLength(arguments.length);
207
- return __liftRecord64(exports.pvmResume(pvmId, gas, pc, logs) >>> 0);
208
+ return __liftRecord68(exports.pvmResume(pvmId, gas, pc, logs) >>> 0);
208
209
  },
209
210
  }, exports);
210
- function __liftRecord53(pointer) {
211
- // assembly/gas-costs/BlockGasCost
211
+ function __liftRecord58(pointer) {
212
+ // assembly/api-utils/BlockGasCost
212
213
  // Hint: Opt-out from lifting as a record by providing an empty constructor
213
214
  if (!pointer) return null;
214
215
  return {
@@ -216,28 +217,28 @@ async function instantiate(module, imports = {}) {
216
217
  gas: __getU64(pointer + 8),
217
218
  };
218
219
  }
219
- function __lowerRecord49(value) {
220
+ function __lowerRecord54(value) {
220
221
  // assembly/api-types/InitialPage
221
222
  // Hint: Opt-out from lowering as a record by providing an empty constructor
222
223
  if (value == null) return 0;
223
- const pointer = exports.__pin(exports.__new(12, 49));
224
+ const pointer = exports.__pin(exports.__new(12, 54));
224
225
  __setU32(pointer + 0, value.address);
225
226
  __setU32(pointer + 4, value.length);
226
227
  __setU32(pointer + 8, value.access);
227
228
  exports.__unpin(pointer);
228
229
  return pointer;
229
230
  }
230
- function __lowerRecord51(value) {
231
+ function __lowerRecord56(value) {
231
232
  // assembly/api-types/InitialChunk
232
233
  // Hint: Opt-out from lowering as a record by providing an empty constructor
233
234
  if (value == null) return 0;
234
- const pointer = exports.__pin(exports.__new(8, 51));
235
+ const pointer = exports.__pin(exports.__new(8, 56));
235
236
  __setU32(pointer + 0, value.address);
236
- __setU32(pointer + 4, __lowerArray(__setU8, 7, 0, value.data) || __notnull());
237
+ __setU32(pointer + 4, __lowerArray(__setU8, 32, 0, value.data) || __notnull());
237
238
  exports.__unpin(pointer);
238
239
  return pointer;
239
240
  }
240
- function __liftRecord51(pointer) {
241
+ function __liftRecord56(pointer) {
241
242
  // assembly/api-types/InitialChunk
242
243
  // Hint: Opt-out from lifting as a record by providing an empty constructor
243
244
  if (!pointer) return null;
@@ -246,7 +247,7 @@ async function instantiate(module, imports = {}) {
246
247
  data: __liftArray(__getU8, 0, __getU32(pointer + 4)),
247
248
  };
248
249
  }
249
- function __liftRecord58(pointer) {
250
+ function __liftRecord62(pointer) {
250
251
  // assembly/api-types/VmOutput
251
252
  // Hint: Opt-out from lifting as a record by providing an empty constructor
252
253
  if (!pointer) return null;
@@ -254,13 +255,13 @@ async function instantiate(module, imports = {}) {
254
255
  status: __getI32(pointer + 0),
255
256
  exitCode: __getU32(pointer + 4),
256
257
  pc: __getU32(pointer + 8),
257
- gas: __getI64(pointer + 16),
258
+ gas: __getU64(pointer + 16),
258
259
  result: __liftArray(__getU8, 0, __getU32(pointer + 24)),
259
260
  registers: __liftArray(pointer => BigInt.asUintN(64, __getU64(pointer)), 3, __getU32(pointer + 28)),
260
- memory: __liftArray(pointer => __liftRecord51(__getU32(pointer)), 2, __getU32(pointer + 32)),
261
+ memory: __liftArray(pointer => __liftRecord56(__getU32(pointer)), 2, __getU32(pointer + 32)),
261
262
  };
262
263
  }
263
- function __liftRecord64(pointer) {
264
+ function __liftRecord68(pointer) {
264
265
  // assembly/api-types/VmPause
265
266
  // Hint: Opt-out from lifting as a record by providing an empty constructor
266
267
  if (!pointer) return null;
@@ -269,7 +270,7 @@ async function instantiate(module, imports = {}) {
269
270
  exitCode: __getU32(pointer + 4),
270
271
  pc: __getU32(pointer + 8),
271
272
  nextPc: __getU32(pointer + 12),
272
- gas: __getI64(pointer + 16),
273
+ gas: __getU64(pointer + 16),
273
274
  registers: __liftArray(pointer => BigInt.asUintN(64, __getU64(pointer)), 3, __getU32(pointer + 24)),
274
275
  };
275
276
  }
@@ -411,14 +412,6 @@ async function instantiate(module, imports = {}) {
411
412
  return __dataview.getUint32(pointer, true);
412
413
  }
413
414
  }
414
- function __getI64(pointer) {
415
- try {
416
- return __dataview.getBigInt64(pointer, true);
417
- } catch {
418
- __dataview = new DataView(memory.buffer);
419
- return __dataview.getBigInt64(pointer, true);
420
- }
421
- }
422
415
  function __getU64(pointer) {
423
416
  try {
424
417
  return __dataview.getBigUint64(pointer, true);
@@ -452,7 +445,7 @@ export const {
452
445
  setMemory,
453
446
  InputKind,
454
447
  HasMetadata,
455
- getGasCosts,
448
+ getBlockGasCosts,
456
449
  disassemble,
457
450
  prepareProgram,
458
451
  runProgram,
Binary file
@@ -1,7 +1,7 @@
1
1
  import { Gas } from "./gas";
2
- export declare function resetJAM(program: u8[], pc: u32, initialGas: Gas, args: u8[], hasMetadata?: boolean): void;
3
- export declare function resetGeneric(program: u8[], flatRegisters: u8[], initialGas: Gas, hasMetadata?: boolean): void;
4
- export declare function resetGenericWithMemory(program: u8[], flatRegisters: u8[], pageMap: Uint8Array, chunks: Uint8Array, initialGas: Gas, hasMetadata?: boolean): void;
2
+ export declare function resetJAM(program: u8[], pc: u32, initialGas: Gas, args: u8[], hasMetadata?: boolean, useBlockGas?: boolean): void;
3
+ export declare function resetGeneric(program: u8[], flatRegisters: u8[], initialGas: Gas, hasMetadata?: boolean, useBlockGas?: boolean): void;
4
+ export declare function resetGenericWithMemory(program: u8[], flatRegisters: u8[], pageMap: Uint8Array, chunks: Uint8Array, initialGas: Gas, hasMetadata?: boolean, useBlockGas?: boolean): void;
5
5
  export declare function nextStep(): boolean;
6
6
  export declare function nSteps(steps: u32): boolean;
7
7
  export declare function getProgramCounter(): u32;
@@ -9,7 +9,7 @@ export declare function setNextProgramCounter(pc: u32): void;
9
9
  export declare function getStatus(): u8;
10
10
  export declare function getExitArg(): u32;
11
11
  export declare function getGasLeft(): i64;
12
- export declare function setGasLeft(gas: i64): void;
12
+ export declare function setGasLeft(gas: Gas): void;
13
13
  export declare function getRegisters(): Uint8Array;
14
14
  export declare function setRegisters(flatRegisters: u8[]): void;
15
15
  export declare function getPageDump(index: u32): Uint8Array;
@@ -8,9 +8,9 @@ import { deblob, extractCodeAndMetadata, liftBytes } from "./program";
8
8
  import { NO_OF_REGISTERS, newRegisters, REG_SIZE_BYTES } from "./registers";
9
9
  import { decodeSpi } from "./spi";
10
10
  let interpreter = null;
11
- export function resetJAM(program, pc, initialGas, args, hasMetadata = false) {
11
+ export function resetJAM(program, pc, initialGas, args, hasMetadata = false, useBlockGas = false) {
12
12
  const code = hasMetadata ? extractCodeAndMetadata(liftBytes(program)).code : liftBytes(program);
13
- const p = decodeSpi(code, liftBytes(args), 128);
13
+ const p = decodeSpi(code, liftBytes(args), 128, useBlockGas);
14
14
  const int = new Interpreter(p.program, p.registers, p.memory);
15
15
  int.nextPc = pc;
16
16
  int.gas.set(initialGas);
@@ -19,9 +19,9 @@ export function resetJAM(program, pc, initialGas, args, hasMetadata = false) {
19
19
  }
20
20
  interpreter = int;
21
21
  }
22
- export function resetGeneric(program, flatRegisters, initialGas, hasMetadata = false) {
22
+ export function resetGeneric(program, flatRegisters, initialGas, hasMetadata = false, useBlockGas = false) {
23
23
  const code = hasMetadata ? extractCodeAndMetadata(liftBytes(program)).code : liftBytes(program);
24
- const p = deblob(code);
24
+ const p = deblob(code, useBlockGas);
25
25
  const registers = newRegisters();
26
26
  fillRegisters(registers, flatRegisters);
27
27
  const int = new Interpreter(p, registers);
@@ -31,9 +31,9 @@ export function resetGeneric(program, flatRegisters, initialGas, hasMetadata = f
31
31
  }
32
32
  interpreter = int;
33
33
  }
34
- export function resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata = false) {
34
+ export function resetGenericWithMemory(program, flatRegisters, pageMap, chunks, initialGas, hasMetadata = false, useBlockGas = false) {
35
35
  const code = hasMetadata ? extractCodeAndMetadata(liftBytes(program)).code : liftBytes(program);
36
- const p = deblob(code);
36
+ const p = deblob(code, useBlockGas);
37
37
  const registers = newRegisters();
38
38
  fillRegisters(registers, flatRegisters);
39
39
  const builder = new MemoryBuilder();
@@ -5,7 +5,7 @@ import { Program } from "./program";
5
5
  export declare function getAssembly(p: Program): string;
6
6
  export declare function buildMemory(builder: MemoryBuilder, pages: InitialPage[], chunks: InitialChunk[]): Memory;
7
7
  /** Initialize new VM for execution. */
8
- export declare function vmInit(input: VmInput, useSbrkGas?: boolean): Interpreter;
8
+ export declare function vmInit(input: VmInput): Interpreter;
9
9
  /** Initialize & run & destroy a VM in a single go. */
10
10
  export declare function vmRunOnce(input: VmInput, options: VmRunOptions): VmOutput;
11
11
  export declare function vmExecute(int: Interpreter, logs?: boolean): void;
@@ -60,16 +60,15 @@ export function buildMemory(builder, pages, chunks) {
60
60
  return builder.build(sbrkIndex);
61
61
  }
62
62
  /** Initialize new VM for execution. */
63
- export function vmInit(input, useSbrkGas = false) {
63
+ export function vmInit(input) {
64
64
  const int = new Interpreter(input.program, input.registers, input.memory);
65
- int.useSbrkGas = useSbrkGas;
66
65
  int.nextPc = input.pc;
67
66
  int.gas.set(input.gas);
68
67
  return int;
69
68
  }
70
69
  /** Initialize & run & destroy a VM in a single go. */
71
70
  export function vmRunOnce(input, options) {
72
- const int = vmInit(input, options.useSbrkGas);
71
+ const int = vmInit(input);
73
72
  vmExecute(int, options.logs);
74
73
  return vmDestroy(int, options.dumpMemory);
75
74
  }
@@ -1,4 +1,5 @@
1
1
  /** We split out type definitions, because they can't be exported from WASM. */
2
+ import { Gas } from "./gas";
2
3
  import { Status } from "./interpreter";
3
4
  import { Memory } from "./memory";
4
5
  import { Access } from "./memory-page";
@@ -14,7 +15,6 @@ export declare class InitialChunk {
14
15
  data: u8[];
15
16
  }
16
17
  export declare class VmRunOptions {
17
- useSbrkGas: boolean;
18
18
  logs: boolean;
19
19
  dumpMemory: boolean;
20
20
  }
@@ -23,7 +23,7 @@ export declare class VmInput {
23
23
  readonly memory: Memory;
24
24
  readonly registers: Registers;
25
25
  pc: u32;
26
- gas: i64;
26
+ gas: Gas;
27
27
  constructor(program: Program, memory: Memory, registers: Registers);
28
28
  }
29
29
  export declare class VmPause {
@@ -31,14 +31,14 @@ export declare class VmPause {
31
31
  exitCode: u32;
32
32
  pc: u32;
33
33
  nextPc: u32;
34
- gas: i64;
34
+ gas: Gas;
35
35
  registers: u64[];
36
36
  }
37
37
  export declare class VmOutput {
38
38
  status: Status;
39
39
  exitCode: u32;
40
40
  pc: u32;
41
- gas: i64;
41
+ gas: Gas;
42
42
  result: u8[];
43
43
  registers: u64[];
44
44
  memory: InitialChunk[];
@@ -16,7 +16,6 @@ export class InitialChunk {
16
16
  }
17
17
  export class VmRunOptions {
18
18
  constructor() {
19
- this.useSbrkGas = false;
20
19
  this.logs = false;
21
20
  this.dumpMemory = false;
22
21
  }
@@ -27,7 +26,7 @@ export class VmInput {
27
26
  this.memory = memory;
28
27
  this.registers = registers;
29
28
  this.pc = 0;
30
- this.gas = i64(0);
29
+ this.gas = u64(0);
31
30
  }
32
31
  }
33
32
  export class VmPause {
@@ -36,7 +35,7 @@ export class VmPause {
36
35
  this.exitCode = 0;
37
36
  this.pc = 0;
38
37
  this.nextPc = 0;
39
- this.gas = i64(0);
38
+ this.gas = u64(0);
40
39
  this.registers = [];
41
40
  }
42
41
  }
@@ -45,7 +44,7 @@ export class VmOutput {
45
44
  this.status = Status.OK;
46
45
  this.exitCode = 0;
47
46
  this.pc = 0;
48
- this.gas = i64(0);
47
+ this.gas = u64(0);
49
48
  this.result = [];
50
49
  this.registers = [];
51
50
  this.memory = [];