@noir-lang/noir_wasm 0.20.0-f904ae1.nightly → 0.21.0-dc100f2.nightly

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.
@@ -11,6 +11,16 @@ export function acir_read_bytes(bytes: Uint8Array): any;
11
11
  */
12
12
  export function acir_write_bytes(acir: any): Uint8Array;
13
13
  /**
14
+ * This is a method that exposes the same API as `compile`
15
+ * But uses the Context based APi internally
16
+ * @param {string} entry_point
17
+ * @param {boolean | undefined} contracts
18
+ * @param {DependencyGraph | undefined} dependency_graph
19
+ * @param {PathToFileSourceMap} file_source_map
20
+ * @returns {CompileResult}
21
+ */
22
+ export function compile_(entry_point: string, contracts: boolean | undefined, dependency_graph: DependencyGraph | undefined, file_source_map: PathToFileSourceMap): CompileResult;
23
+ /**
14
24
  * @param {string} level
15
25
  */
16
26
  export function init_log_level(level: string): void;
@@ -22,9 +32,10 @@ export function build_info(): any;
22
32
  * @param {string} entry_point
23
33
  * @param {boolean | undefined} contracts
24
34
  * @param {DependencyGraph | undefined} dependency_graph
35
+ * @param {PathToFileSourceMap} file_source_map
25
36
  * @returns {CompileResult}
26
37
  */
27
- export function compile(entry_point: string, contracts?: boolean, dependency_graph?: DependencyGraph): CompileResult;
38
+ export function compile(entry_point: string, contracts: boolean | undefined, dependency_graph: DependencyGraph | undefined, file_source_map: PathToFileSourceMap): CompileResult;
28
39
 
29
40
  export type Diagnostic = {
30
41
  message: string;
@@ -51,14 +62,12 @@ export type DependencyGraph = {
51
62
  export type CompiledContract = {
52
63
  noir_version: string;
53
64
  name: string;
54
- backend: string;
55
65
  functions: Array<any>;
56
66
  events: Array<any>;
57
67
  };
58
68
 
59
69
  export type CompiledProgram = {
60
70
  noir_version: string;
61
- backend: string;
62
71
  abi: any;
63
72
  bytecode: string;
64
73
  }
@@ -81,3 +90,60 @@ export type CompileResult = (
81
90
  );
82
91
 
83
92
 
93
+ /**
94
+ * This is a wrapper class that is wasm-bindgen compatible
95
+ * We do not use js_name and rename it like CrateId because
96
+ * then the impl block is not picked up in javascript.
97
+ */
98
+ export class CompilerContext {
99
+ free(): void;
100
+ /**
101
+ * @param {PathToFileSourceMap} source_map
102
+ */
103
+ constructor(source_map: PathToFileSourceMap);
104
+ /**
105
+ * @param {string} path_to_crate
106
+ * @returns {CrateId}
107
+ */
108
+ process_root_crate(path_to_crate: string): CrateId;
109
+ /**
110
+ * @param {string} path_to_crate
111
+ * @returns {CrateId}
112
+ */
113
+ process_dependency_crate(path_to_crate: string): CrateId;
114
+ /**
115
+ * @param {string} crate_name
116
+ * @param {CrateId} from
117
+ * @param {CrateId} to
118
+ */
119
+ add_dependency_edge(crate_name: string, from: CrateId, to: CrateId): void;
120
+ /**
121
+ * @param {number} program_width
122
+ * @returns {CompileResult}
123
+ */
124
+ compile_program(program_width: number): CompileResult;
125
+ /**
126
+ * @param {number} program_width
127
+ * @returns {CompileResult}
128
+ */
129
+ compile_contract(program_width: number): CompileResult;
130
+ }
131
+ /**
132
+ */
133
+ export class CrateId {
134
+ free(): void;
135
+ }
136
+ /**
137
+ */
138
+ export class PathToFileSourceMap {
139
+ free(): void;
140
+ /**
141
+ */
142
+ constructor();
143
+ /**
144
+ * @param {string} path
145
+ * @param {string} source_code
146
+ * @returns {boolean}
147
+ */
148
+ add_source_code(path: string, source_code: string): boolean;
149
+ }
@@ -1,7 +1,6 @@
1
1
  let imports = {};
2
2
  imports['__wbindgen_placeholder__'] = module.exports;
3
3
  let wasm;
4
- const { read_file } = require(`@noir-lang/source-resolver`);
5
4
  const { TextDecoder, TextEncoder } = require(`util`);
6
5
 
7
6
  const heap = new Array(128).fill(undefined);
@@ -223,6 +222,41 @@ module.exports.acir_write_bytes = function(acir) {
223
222
  }
224
223
  };
225
224
 
225
+ function _assertClass(instance, klass) {
226
+ if (!(instance instanceof klass)) {
227
+ throw new Error(`expected instance of ${klass.name}`);
228
+ }
229
+ return instance.ptr;
230
+ }
231
+ /**
232
+ * This is a method that exposes the same API as `compile`
233
+ * But uses the Context based APi internally
234
+ * @param {string} entry_point
235
+ * @param {boolean | undefined} contracts
236
+ * @param {DependencyGraph | undefined} dependency_graph
237
+ * @param {PathToFileSourceMap} file_source_map
238
+ * @returns {CompileResult}
239
+ */
240
+ module.exports.compile_ = function(entry_point, contracts, dependency_graph, file_source_map) {
241
+ try {
242
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
243
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
244
+ const len0 = WASM_VECTOR_LEN;
245
+ _assertClass(file_source_map, PathToFileSourceMap);
246
+ var ptr1 = file_source_map.__destroy_into_raw();
247
+ wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
248
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
249
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
250
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
251
+ if (r2) {
252
+ throw takeObject(r1);
253
+ }
254
+ return takeObject(r0);
255
+ } finally {
256
+ wasm.__wbindgen_add_to_stack_pointer(16);
257
+ }
258
+ };
259
+
226
260
  /**
227
261
  * @param {string} level
228
262
  */
@@ -244,14 +278,17 @@ module.exports.build_info = function() {
244
278
  * @param {string} entry_point
245
279
  * @param {boolean | undefined} contracts
246
280
  * @param {DependencyGraph | undefined} dependency_graph
281
+ * @param {PathToFileSourceMap} file_source_map
247
282
  * @returns {CompileResult}
248
283
  */
249
- module.exports.compile = function(entry_point, contracts, dependency_graph) {
284
+ module.exports.compile = function(entry_point, contracts, dependency_graph, file_source_map) {
250
285
  try {
251
286
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
252
287
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
253
288
  const len0 = WASM_VECTOR_LEN;
254
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph));
289
+ _assertClass(file_source_map, PathToFileSourceMap);
290
+ var ptr1 = file_source_map.__destroy_into_raw();
291
+ wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
255
292
  var r0 = getInt32Memory0()[retptr / 4 + 0];
256
293
  var r1 = getInt32Memory0()[retptr / 4 + 1];
257
294
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -271,12 +308,190 @@ function handleError(f, args) {
271
308
  wasm.__wbindgen_export_3(addHeapObject(e));
272
309
  }
273
310
  }
311
+ /**
312
+ * This is a wrapper class that is wasm-bindgen compatible
313
+ * We do not use js_name and rename it like CrateId because
314
+ * then the impl block is not picked up in javascript.
315
+ */
316
+ class CompilerContext {
317
+
318
+ static __wrap(ptr) {
319
+ ptr = ptr >>> 0;
320
+ const obj = Object.create(CompilerContext.prototype);
321
+ obj.__wbg_ptr = ptr;
322
+
323
+ return obj;
324
+ }
325
+
326
+ __destroy_into_raw() {
327
+ const ptr = this.__wbg_ptr;
328
+ this.__wbg_ptr = 0;
329
+
330
+ return ptr;
331
+ }
332
+
333
+ free() {
334
+ const ptr = this.__destroy_into_raw();
335
+ wasm.__wbg_compilercontext_free(ptr);
336
+ }
337
+ /**
338
+ * @param {PathToFileSourceMap} source_map
339
+ */
340
+ constructor(source_map) {
341
+ _assertClass(source_map, PathToFileSourceMap);
342
+ var ptr0 = source_map.__destroy_into_raw();
343
+ const ret = wasm.compilercontext_new(ptr0);
344
+ return CompilerContext.__wrap(ret);
345
+ }
346
+ /**
347
+ * @param {string} path_to_crate
348
+ * @returns {CrateId}
349
+ */
350
+ process_root_crate(path_to_crate) {
351
+ const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
352
+ const len0 = WASM_VECTOR_LEN;
353
+ const ret = wasm.compilercontext_process_root_crate(this.__wbg_ptr, ptr0, len0);
354
+ return CrateId.__wrap(ret);
355
+ }
356
+ /**
357
+ * @param {string} path_to_crate
358
+ * @returns {CrateId}
359
+ */
360
+ process_dependency_crate(path_to_crate) {
361
+ const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
362
+ const len0 = WASM_VECTOR_LEN;
363
+ const ret = wasm.compilercontext_process_dependency_crate(this.__wbg_ptr, ptr0, len0);
364
+ return CrateId.__wrap(ret);
365
+ }
366
+ /**
367
+ * @param {string} crate_name
368
+ * @param {CrateId} from
369
+ * @param {CrateId} to
370
+ */
371
+ add_dependency_edge(crate_name, from, to) {
372
+ const ptr0 = passStringToWasm0(crate_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
373
+ const len0 = WASM_VECTOR_LEN;
374
+ _assertClass(from, CrateId);
375
+ _assertClass(to, CrateId);
376
+ wasm.compilercontext_add_dependency_edge(this.__wbg_ptr, ptr0, len0, from.__wbg_ptr, to.__wbg_ptr);
377
+ }
378
+ /**
379
+ * @param {number} program_width
380
+ * @returns {CompileResult}
381
+ */
382
+ compile_program(program_width) {
383
+ try {
384
+ const ptr = this.__destroy_into_raw();
385
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
386
+ wasm.compilercontext_compile_program(retptr, ptr, program_width);
387
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
388
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
389
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
390
+ if (r2) {
391
+ throw takeObject(r1);
392
+ }
393
+ return takeObject(r0);
394
+ } finally {
395
+ wasm.__wbindgen_add_to_stack_pointer(16);
396
+ }
397
+ }
398
+ /**
399
+ * @param {number} program_width
400
+ * @returns {CompileResult}
401
+ */
402
+ compile_contract(program_width) {
403
+ try {
404
+ const ptr = this.__destroy_into_raw();
405
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
406
+ wasm.compilercontext_compile_contract(retptr, ptr, program_width);
407
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
408
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
409
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
410
+ if (r2) {
411
+ throw takeObject(r1);
412
+ }
413
+ return takeObject(r0);
414
+ } finally {
415
+ wasm.__wbindgen_add_to_stack_pointer(16);
416
+ }
417
+ }
418
+ }
419
+ module.exports.CompilerContext = CompilerContext;
420
+ /**
421
+ */
422
+ class CrateId {
423
+
424
+ static __wrap(ptr) {
425
+ ptr = ptr >>> 0;
426
+ const obj = Object.create(CrateId.prototype);
427
+ obj.__wbg_ptr = ptr;
428
+
429
+ return obj;
430
+ }
431
+
432
+ __destroy_into_raw() {
433
+ const ptr = this.__wbg_ptr;
434
+ this.__wbg_ptr = 0;
435
+
436
+ return ptr;
437
+ }
438
+
439
+ free() {
440
+ const ptr = this.__destroy_into_raw();
441
+ wasm.__wbg_crateid_free(ptr);
442
+ }
443
+ }
444
+ module.exports.CrateId = CrateId;
445
+ /**
446
+ */
447
+ class PathToFileSourceMap {
448
+
449
+ static __wrap(ptr) {
450
+ ptr = ptr >>> 0;
451
+ const obj = Object.create(PathToFileSourceMap.prototype);
452
+ obj.__wbg_ptr = ptr;
453
+
454
+ return obj;
455
+ }
456
+
457
+ __destroy_into_raw() {
458
+ const ptr = this.__wbg_ptr;
459
+ this.__wbg_ptr = 0;
460
+
461
+ return ptr;
462
+ }
463
+
464
+ free() {
465
+ const ptr = this.__destroy_into_raw();
466
+ wasm.__wbg_pathtofilesourcemap_free(ptr);
467
+ }
468
+ /**
469
+ */
470
+ constructor() {
471
+ const ret = wasm.pathtofilesourcemap_new();
472
+ return PathToFileSourceMap.__wrap(ret);
473
+ }
474
+ /**
475
+ * @param {string} path
476
+ * @param {string} source_code
477
+ * @returns {boolean}
478
+ */
479
+ add_source_code(path, source_code) {
480
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
481
+ const len0 = WASM_VECTOR_LEN;
482
+ const ptr1 = passStringToWasm0(source_code, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
483
+ const len1 = WASM_VECTOR_LEN;
484
+ const ret = wasm.pathtofilesourcemap_add_source_code(this.__wbg_ptr, ptr0, len0, ptr1, len1);
485
+ return ret !== 0;
486
+ }
487
+ }
488
+ module.exports.PathToFileSourceMap = PathToFileSourceMap;
274
489
 
275
490
  module.exports.__wbindgen_object_drop_ref = function(arg0) {
276
491
  takeObject(arg0);
277
492
  };
278
493
 
279
- module.exports.__wbg_constructor_2f52aa89ce97ba46 = function(arg0) {
494
+ module.exports.__wbg_constructor_35233efb35960b52 = function(arg0) {
280
495
  const ret = new Error(takeObject(arg0));
281
496
  return addHeapObject(ret);
282
497
  };
@@ -286,19 +501,11 @@ module.exports.__wbindgen_is_undefined = function(arg0) {
286
501
  return ret;
287
502
  };
288
503
 
289
- module.exports.__wbg_constructor_1292ee4141d8f79d = function() {
504
+ module.exports.__wbg_constructor_0fbcf25c6da50731 = function() {
290
505
  const ret = new Object();
291
506
  return addHeapObject(ret);
292
507
  };
293
508
 
294
- module.exports.__wbg_readfile_698fcfe83a414130 = function() { return handleError(function (arg0, arg1, arg2) {
295
- const ret = read_file(getStringFromWasm0(arg1, arg2));
296
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
297
- const len1 = WASM_VECTOR_LEN;
298
- getInt32Memory0()[arg0 / 4 + 1] = len1;
299
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
300
- }, arguments) };
301
-
302
509
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
303
510
  const ret = getStringFromWasm0(arg0, arg1);
304
511
  return addHeapObject(ret);
Binary file
@@ -3,9 +3,21 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export function acir_read_bytes(a: number, b: number): number;
5
5
  export function acir_write_bytes(a: number, b: number): void;
6
+ export function __wbg_compilercontext_free(a: number): void;
7
+ export function __wbg_crateid_free(a: number): void;
8
+ export function compilercontext_new(a: number): number;
9
+ export function compilercontext_process_root_crate(a: number, b: number, c: number): number;
10
+ export function compilercontext_process_dependency_crate(a: number, b: number, c: number): number;
11
+ export function compilercontext_add_dependency_edge(a: number, b: number, c: number, d: number, e: number): void;
12
+ export function compilercontext_compile_program(a: number, b: number, c: number): void;
13
+ export function compilercontext_compile_contract(a: number, b: number, c: number): void;
14
+ export function compile_(a: number, b: number, c: number, d: number, e: number, f: number): void;
6
15
  export function init_log_level(a: number, b: number): void;
7
16
  export function build_info(): number;
8
- export function compile(a: number, b: number, c: number, d: number, e: number): void;
17
+ export function __wbg_pathtofilesourcemap_free(a: number): void;
18
+ export function pathtofilesourcemap_new(): number;
19
+ export function pathtofilesourcemap_add_source_code(a: number, b: number, c: number, d: number, e: number): number;
20
+ export function compile(a: number, b: number, c: number, d: number, e: number, f: number): void;
9
21
  export function __wbindgen_export_0(a: number): number;
10
22
  export function __wbindgen_export_1(a: number, b: number, c: number): number;
11
23
  export function __wbindgen_add_to_stack_pointer(a: number): number;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "The Noir Team <team@noir-lang.org>"
5
5
  ],
6
- "version": "0.20.0-f904ae1.nightly",
6
+ "version": "0.21.0-dc100f2.nightly",
7
7
  "license": "(MIT OR Apache-2.0)",
8
8
  "main": "./nodejs/noir_wasm.js",
9
9
  "types": "./web/noir_wasm.d.ts",
@@ -30,9 +30,6 @@
30
30
  "build:nix": "nix build -L .#noir_wasm",
31
31
  "install:from:nix": "yarn clean && yarn build:nix && cp -rL ./result/noir_wasm/nodejs ./ && cp -rL ./result/noir_wasm/web ./"
32
32
  },
33
- "peerDependencies": {
34
- "@noir-lang/source-resolver": "0.20.0-f904ae1.nightly"
35
- },
36
33
  "devDependencies": {
37
34
  "@esm-bundle/chai": "^4.3.4-fix.0",
38
35
  "@web/dev-server-esbuild": "^0.3.6",
@@ -11,6 +11,16 @@ export function acir_read_bytes(bytes: Uint8Array): any;
11
11
  */
12
12
  export function acir_write_bytes(acir: any): Uint8Array;
13
13
  /**
14
+ * This is a method that exposes the same API as `compile`
15
+ * But uses the Context based APi internally
16
+ * @param {string} entry_point
17
+ * @param {boolean | undefined} contracts
18
+ * @param {DependencyGraph | undefined} dependency_graph
19
+ * @param {PathToFileSourceMap} file_source_map
20
+ * @returns {CompileResult}
21
+ */
22
+ export function compile_(entry_point: string, contracts: boolean | undefined, dependency_graph: DependencyGraph | undefined, file_source_map: PathToFileSourceMap): CompileResult;
23
+ /**
14
24
  * @param {string} level
15
25
  */
16
26
  export function init_log_level(level: string): void;
@@ -22,9 +32,10 @@ export function build_info(): any;
22
32
  * @param {string} entry_point
23
33
  * @param {boolean | undefined} contracts
24
34
  * @param {DependencyGraph | undefined} dependency_graph
35
+ * @param {PathToFileSourceMap} file_source_map
25
36
  * @returns {CompileResult}
26
37
  */
27
- export function compile(entry_point: string, contracts?: boolean, dependency_graph?: DependencyGraph): CompileResult;
38
+ export function compile(entry_point: string, contracts: boolean | undefined, dependency_graph: DependencyGraph | undefined, file_source_map: PathToFileSourceMap): CompileResult;
28
39
 
29
40
  export type Diagnostic = {
30
41
  message: string;
@@ -51,14 +62,12 @@ export type DependencyGraph = {
51
62
  export type CompiledContract = {
52
63
  noir_version: string;
53
64
  name: string;
54
- backend: string;
55
65
  functions: Array<any>;
56
66
  events: Array<any>;
57
67
  };
58
68
 
59
69
  export type CompiledProgram = {
60
70
  noir_version: string;
61
- backend: string;
62
71
  abi: any;
63
72
  bytecode: string;
64
73
  }
@@ -81,6 +90,63 @@ export type CompileResult = (
81
90
  );
82
91
 
83
92
 
93
+ /**
94
+ * This is a wrapper class that is wasm-bindgen compatible
95
+ * We do not use js_name and rename it like CrateId because
96
+ * then the impl block is not picked up in javascript.
97
+ */
98
+ export class CompilerContext {
99
+ free(): void;
100
+ /**
101
+ * @param {PathToFileSourceMap} source_map
102
+ */
103
+ constructor(source_map: PathToFileSourceMap);
104
+ /**
105
+ * @param {string} path_to_crate
106
+ * @returns {CrateId}
107
+ */
108
+ process_root_crate(path_to_crate: string): CrateId;
109
+ /**
110
+ * @param {string} path_to_crate
111
+ * @returns {CrateId}
112
+ */
113
+ process_dependency_crate(path_to_crate: string): CrateId;
114
+ /**
115
+ * @param {string} crate_name
116
+ * @param {CrateId} from
117
+ * @param {CrateId} to
118
+ */
119
+ add_dependency_edge(crate_name: string, from: CrateId, to: CrateId): void;
120
+ /**
121
+ * @param {number} program_width
122
+ * @returns {CompileResult}
123
+ */
124
+ compile_program(program_width: number): CompileResult;
125
+ /**
126
+ * @param {number} program_width
127
+ * @returns {CompileResult}
128
+ */
129
+ compile_contract(program_width: number): CompileResult;
130
+ }
131
+ /**
132
+ */
133
+ export class CrateId {
134
+ free(): void;
135
+ }
136
+ /**
137
+ */
138
+ export class PathToFileSourceMap {
139
+ free(): void;
140
+ /**
141
+ */
142
+ constructor();
143
+ /**
144
+ * @param {string} path
145
+ * @param {string} source_code
146
+ * @returns {boolean}
147
+ */
148
+ add_source_code(path: string, source_code: string): boolean;
149
+ }
84
150
 
85
151
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
86
152
 
@@ -88,9 +154,21 @@ export interface InitOutput {
88
154
  readonly memory: WebAssembly.Memory;
89
155
  readonly acir_read_bytes: (a: number, b: number) => number;
90
156
  readonly acir_write_bytes: (a: number, b: number) => void;
157
+ readonly __wbg_compilercontext_free: (a: number) => void;
158
+ readonly __wbg_crateid_free: (a: number) => void;
159
+ readonly compilercontext_new: (a: number) => number;
160
+ readonly compilercontext_process_root_crate: (a: number, b: number, c: number) => number;
161
+ readonly compilercontext_process_dependency_crate: (a: number, b: number, c: number) => number;
162
+ readonly compilercontext_add_dependency_edge: (a: number, b: number, c: number, d: number, e: number) => void;
163
+ readonly compilercontext_compile_program: (a: number, b: number, c: number) => void;
164
+ readonly compilercontext_compile_contract: (a: number, b: number, c: number) => void;
165
+ readonly compile_: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
91
166
  readonly init_log_level: (a: number, b: number) => void;
92
167
  readonly build_info: () => number;
93
- readonly compile: (a: number, b: number, c: number, d: number, e: number) => void;
168
+ readonly __wbg_pathtofilesourcemap_free: (a: number) => void;
169
+ readonly pathtofilesourcemap_new: () => number;
170
+ readonly pathtofilesourcemap_add_source_code: (a: number, b: number, c: number, d: number, e: number) => number;
171
+ readonly compile: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
94
172
  readonly __wbindgen_export_0: (a: number) => number;
95
173
  readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
96
174
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
package/web/noir_wasm.js CHANGED
@@ -1,5 +1,3 @@
1
- import { read_file } from '@noir-lang/source-resolver';
2
-
3
1
  let wasm;
4
2
 
5
3
  const heap = new Array(128).fill(undefined);
@@ -221,6 +219,41 @@ export function acir_write_bytes(acir) {
221
219
  }
222
220
  }
223
221
 
222
+ function _assertClass(instance, klass) {
223
+ if (!(instance instanceof klass)) {
224
+ throw new Error(`expected instance of ${klass.name}`);
225
+ }
226
+ return instance.ptr;
227
+ }
228
+ /**
229
+ * This is a method that exposes the same API as `compile`
230
+ * But uses the Context based APi internally
231
+ * @param {string} entry_point
232
+ * @param {boolean | undefined} contracts
233
+ * @param {DependencyGraph | undefined} dependency_graph
234
+ * @param {PathToFileSourceMap} file_source_map
235
+ * @returns {CompileResult}
236
+ */
237
+ export function compile_(entry_point, contracts, dependency_graph, file_source_map) {
238
+ try {
239
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
240
+ const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ _assertClass(file_source_map, PathToFileSourceMap);
243
+ var ptr1 = file_source_map.__destroy_into_raw();
244
+ wasm.compile_(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
245
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
246
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
247
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
248
+ if (r2) {
249
+ throw takeObject(r1);
250
+ }
251
+ return takeObject(r0);
252
+ } finally {
253
+ wasm.__wbindgen_add_to_stack_pointer(16);
254
+ }
255
+ }
256
+
224
257
  /**
225
258
  * @param {string} level
226
259
  */
@@ -242,14 +275,17 @@ export function build_info() {
242
275
  * @param {string} entry_point
243
276
  * @param {boolean | undefined} contracts
244
277
  * @param {DependencyGraph | undefined} dependency_graph
278
+ * @param {PathToFileSourceMap} file_source_map
245
279
  * @returns {CompileResult}
246
280
  */
247
- export function compile(entry_point, contracts, dependency_graph) {
281
+ export function compile(entry_point, contracts, dependency_graph, file_source_map) {
248
282
  try {
249
283
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
250
284
  const ptr0 = passStringToWasm0(entry_point, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
251
285
  const len0 = WASM_VECTOR_LEN;
252
- wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph));
286
+ _assertClass(file_source_map, PathToFileSourceMap);
287
+ var ptr1 = file_source_map.__destroy_into_raw();
288
+ wasm.compile(retptr, ptr0, len0, isLikeNone(contracts) ? 0xFFFFFF : contracts ? 1 : 0, isLikeNone(dependency_graph) ? 0 : addHeapObject(dependency_graph), ptr1);
253
289
  var r0 = getInt32Memory0()[retptr / 4 + 0];
254
290
  var r1 = getInt32Memory0()[retptr / 4 + 1];
255
291
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -269,6 +305,181 @@ function handleError(f, args) {
269
305
  wasm.__wbindgen_export_3(addHeapObject(e));
270
306
  }
271
307
  }
308
+ /**
309
+ * This is a wrapper class that is wasm-bindgen compatible
310
+ * We do not use js_name and rename it like CrateId because
311
+ * then the impl block is not picked up in javascript.
312
+ */
313
+ export class CompilerContext {
314
+
315
+ static __wrap(ptr) {
316
+ ptr = ptr >>> 0;
317
+ const obj = Object.create(CompilerContext.prototype);
318
+ obj.__wbg_ptr = ptr;
319
+
320
+ return obj;
321
+ }
322
+
323
+ __destroy_into_raw() {
324
+ const ptr = this.__wbg_ptr;
325
+ this.__wbg_ptr = 0;
326
+
327
+ return ptr;
328
+ }
329
+
330
+ free() {
331
+ const ptr = this.__destroy_into_raw();
332
+ wasm.__wbg_compilercontext_free(ptr);
333
+ }
334
+ /**
335
+ * @param {PathToFileSourceMap} source_map
336
+ */
337
+ constructor(source_map) {
338
+ _assertClass(source_map, PathToFileSourceMap);
339
+ var ptr0 = source_map.__destroy_into_raw();
340
+ const ret = wasm.compilercontext_new(ptr0);
341
+ return CompilerContext.__wrap(ret);
342
+ }
343
+ /**
344
+ * @param {string} path_to_crate
345
+ * @returns {CrateId}
346
+ */
347
+ process_root_crate(path_to_crate) {
348
+ const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
349
+ const len0 = WASM_VECTOR_LEN;
350
+ const ret = wasm.compilercontext_process_root_crate(this.__wbg_ptr, ptr0, len0);
351
+ return CrateId.__wrap(ret);
352
+ }
353
+ /**
354
+ * @param {string} path_to_crate
355
+ * @returns {CrateId}
356
+ */
357
+ process_dependency_crate(path_to_crate) {
358
+ const ptr0 = passStringToWasm0(path_to_crate, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
359
+ const len0 = WASM_VECTOR_LEN;
360
+ const ret = wasm.compilercontext_process_dependency_crate(this.__wbg_ptr, ptr0, len0);
361
+ return CrateId.__wrap(ret);
362
+ }
363
+ /**
364
+ * @param {string} crate_name
365
+ * @param {CrateId} from
366
+ * @param {CrateId} to
367
+ */
368
+ add_dependency_edge(crate_name, from, to) {
369
+ const ptr0 = passStringToWasm0(crate_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
370
+ const len0 = WASM_VECTOR_LEN;
371
+ _assertClass(from, CrateId);
372
+ _assertClass(to, CrateId);
373
+ wasm.compilercontext_add_dependency_edge(this.__wbg_ptr, ptr0, len0, from.__wbg_ptr, to.__wbg_ptr);
374
+ }
375
+ /**
376
+ * @param {number} program_width
377
+ * @returns {CompileResult}
378
+ */
379
+ compile_program(program_width) {
380
+ try {
381
+ const ptr = this.__destroy_into_raw();
382
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
383
+ wasm.compilercontext_compile_program(retptr, ptr, program_width);
384
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
385
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
386
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
387
+ if (r2) {
388
+ throw takeObject(r1);
389
+ }
390
+ return takeObject(r0);
391
+ } finally {
392
+ wasm.__wbindgen_add_to_stack_pointer(16);
393
+ }
394
+ }
395
+ /**
396
+ * @param {number} program_width
397
+ * @returns {CompileResult}
398
+ */
399
+ compile_contract(program_width) {
400
+ try {
401
+ const ptr = this.__destroy_into_raw();
402
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
403
+ wasm.compilercontext_compile_contract(retptr, ptr, program_width);
404
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
405
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
406
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
407
+ if (r2) {
408
+ throw takeObject(r1);
409
+ }
410
+ return takeObject(r0);
411
+ } finally {
412
+ wasm.__wbindgen_add_to_stack_pointer(16);
413
+ }
414
+ }
415
+ }
416
+ /**
417
+ */
418
+ export class CrateId {
419
+
420
+ static __wrap(ptr) {
421
+ ptr = ptr >>> 0;
422
+ const obj = Object.create(CrateId.prototype);
423
+ obj.__wbg_ptr = ptr;
424
+
425
+ return obj;
426
+ }
427
+
428
+ __destroy_into_raw() {
429
+ const ptr = this.__wbg_ptr;
430
+ this.__wbg_ptr = 0;
431
+
432
+ return ptr;
433
+ }
434
+
435
+ free() {
436
+ const ptr = this.__destroy_into_raw();
437
+ wasm.__wbg_crateid_free(ptr);
438
+ }
439
+ }
440
+ /**
441
+ */
442
+ export class PathToFileSourceMap {
443
+
444
+ static __wrap(ptr) {
445
+ ptr = ptr >>> 0;
446
+ const obj = Object.create(PathToFileSourceMap.prototype);
447
+ obj.__wbg_ptr = ptr;
448
+
449
+ return obj;
450
+ }
451
+
452
+ __destroy_into_raw() {
453
+ const ptr = this.__wbg_ptr;
454
+ this.__wbg_ptr = 0;
455
+
456
+ return ptr;
457
+ }
458
+
459
+ free() {
460
+ const ptr = this.__destroy_into_raw();
461
+ wasm.__wbg_pathtofilesourcemap_free(ptr);
462
+ }
463
+ /**
464
+ */
465
+ constructor() {
466
+ const ret = wasm.pathtofilesourcemap_new();
467
+ return PathToFileSourceMap.__wrap(ret);
468
+ }
469
+ /**
470
+ * @param {string} path
471
+ * @param {string} source_code
472
+ * @returns {boolean}
473
+ */
474
+ add_source_code(path, source_code) {
475
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
476
+ const len0 = WASM_VECTOR_LEN;
477
+ const ptr1 = passStringToWasm0(source_code, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
478
+ const len1 = WASM_VECTOR_LEN;
479
+ const ret = wasm.pathtofilesourcemap_add_source_code(this.__wbg_ptr, ptr0, len0, ptr1, len1);
480
+ return ret !== 0;
481
+ }
482
+ }
272
483
 
273
484
  async function __wbg_load(module, imports) {
274
485
  if (typeof Response === 'function' && module instanceof Response) {
@@ -307,7 +518,7 @@ function __wbg_get_imports() {
307
518
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
308
519
  takeObject(arg0);
309
520
  };
310
- imports.wbg.__wbg_constructor_2f52aa89ce97ba46 = function(arg0) {
521
+ imports.wbg.__wbg_constructor_35233efb35960b52 = function(arg0) {
311
522
  const ret = new Error(takeObject(arg0));
312
523
  return addHeapObject(ret);
313
524
  };
@@ -315,17 +526,10 @@ function __wbg_get_imports() {
315
526
  const ret = getObject(arg0) === undefined;
316
527
  return ret;
317
528
  };
318
- imports.wbg.__wbg_constructor_1292ee4141d8f79d = function() {
529
+ imports.wbg.__wbg_constructor_0fbcf25c6da50731 = function() {
319
530
  const ret = new Object();
320
531
  return addHeapObject(ret);
321
532
  };
322
- imports.wbg.__wbg_readfile_698fcfe83a414130 = function() { return handleError(function (arg0, arg1, arg2) {
323
- const ret = read_file(getStringFromWasm0(arg1, arg2));
324
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
325
- const len1 = WASM_VECTOR_LEN;
326
- getInt32Memory0()[arg0 / 4 + 1] = len1;
327
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
328
- }, arguments) };
329
533
  imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
330
534
  const ret = getStringFromWasm0(arg0, arg1);
331
535
  return addHeapObject(ret);
Binary file
@@ -3,9 +3,21 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export function acir_read_bytes(a: number, b: number): number;
5
5
  export function acir_write_bytes(a: number, b: number): void;
6
+ export function __wbg_compilercontext_free(a: number): void;
7
+ export function __wbg_crateid_free(a: number): void;
8
+ export function compilercontext_new(a: number): number;
9
+ export function compilercontext_process_root_crate(a: number, b: number, c: number): number;
10
+ export function compilercontext_process_dependency_crate(a: number, b: number, c: number): number;
11
+ export function compilercontext_add_dependency_edge(a: number, b: number, c: number, d: number, e: number): void;
12
+ export function compilercontext_compile_program(a: number, b: number, c: number): void;
13
+ export function compilercontext_compile_contract(a: number, b: number, c: number): void;
14
+ export function compile_(a: number, b: number, c: number, d: number, e: number, f: number): void;
6
15
  export function init_log_level(a: number, b: number): void;
7
16
  export function build_info(): number;
8
- export function compile(a: number, b: number, c: number, d: number, e: number): void;
17
+ export function __wbg_pathtofilesourcemap_free(a: number): void;
18
+ export function pathtofilesourcemap_new(): number;
19
+ export function pathtofilesourcemap_add_source_code(a: number, b: number, c: number, d: number, e: number): number;
20
+ export function compile(a: number, b: number, c: number, d: number, e: number, f: number): void;
9
21
  export function __wbindgen_export_0(a: number): number;
10
22
  export function __wbindgen_export_1(a: number, b: number, c: number): number;
11
23
  export function __wbindgen_add_to_stack_pointer(a: number): number;