virtual-machine 0.0.0-rc1

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.
@@ -0,0 +1,672 @@
1
+ // pkg/riscv_vm.js
2
+ var wasm;
3
+ function isLikeNone(x) {
4
+ return x === void 0 || x === null;
5
+ }
6
+ function debugString(val) {
7
+ const type = typeof val;
8
+ if (type == "number" || type == "boolean" || val == null) {
9
+ return `${val}`;
10
+ }
11
+ if (type == "string") {
12
+ return `"${val}"`;
13
+ }
14
+ if (type == "symbol") {
15
+ const description = val.description;
16
+ if (description == null) {
17
+ return "Symbol";
18
+ } else {
19
+ return `Symbol(${description})`;
20
+ }
21
+ }
22
+ if (type == "function") {
23
+ const name = val.name;
24
+ if (typeof name == "string" && name.length > 0) {
25
+ return `Function(${name})`;
26
+ } else {
27
+ return "Function";
28
+ }
29
+ }
30
+ if (Array.isArray(val)) {
31
+ const length = val.length;
32
+ let debug = "[";
33
+ if (length > 0) {
34
+ debug += debugString(val[0]);
35
+ }
36
+ for (let i = 1; i < length; i++) {
37
+ debug += ", " + debugString(val[i]);
38
+ }
39
+ debug += "]";
40
+ return debug;
41
+ }
42
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
43
+ let className;
44
+ if (builtInMatches && builtInMatches.length > 1) {
45
+ className = builtInMatches[1];
46
+ } else {
47
+ return toString.call(val);
48
+ }
49
+ if (className == "Object") {
50
+ try {
51
+ return "Object(" + JSON.stringify(val) + ")";
52
+ } catch (_) {
53
+ return "Object";
54
+ }
55
+ }
56
+ if (val instanceof Error) {
57
+ return `${val.name}: ${val.message}
58
+ ${val.stack}`;
59
+ }
60
+ return className;
61
+ }
62
+ var WASM_VECTOR_LEN = 0;
63
+ var cachedUint8ArrayMemory0 = null;
64
+ function getUint8ArrayMemory0() {
65
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
66
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
67
+ }
68
+ return cachedUint8ArrayMemory0;
69
+ }
70
+ var cachedTextEncoder = new TextEncoder();
71
+ if (!("encodeInto" in cachedTextEncoder)) {
72
+ cachedTextEncoder.encodeInto = function(arg, view) {
73
+ const buf = cachedTextEncoder.encode(arg);
74
+ view.set(buf);
75
+ return {
76
+ read: arg.length,
77
+ written: buf.length
78
+ };
79
+ };
80
+ }
81
+ function passStringToWasm0(arg, malloc, realloc) {
82
+ if (realloc === void 0) {
83
+ const buf = cachedTextEncoder.encode(arg);
84
+ const ptr2 = malloc(buf.length, 1) >>> 0;
85
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
86
+ WASM_VECTOR_LEN = buf.length;
87
+ return ptr2;
88
+ }
89
+ let len = arg.length;
90
+ let ptr = malloc(len, 1) >>> 0;
91
+ const mem = getUint8ArrayMemory0();
92
+ let offset = 0;
93
+ for (; offset < len; offset++) {
94
+ const code = arg.charCodeAt(offset);
95
+ if (code > 127) break;
96
+ mem[ptr + offset] = code;
97
+ }
98
+ if (offset !== len) {
99
+ if (offset !== 0) {
100
+ arg = arg.slice(offset);
101
+ }
102
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
103
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
104
+ const ret = cachedTextEncoder.encodeInto(arg, view);
105
+ offset += ret.written;
106
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
107
+ }
108
+ WASM_VECTOR_LEN = offset;
109
+ return ptr;
110
+ }
111
+ var cachedDataViewMemory0 = null;
112
+ function getDataViewMemory0() {
113
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
114
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
115
+ }
116
+ return cachedDataViewMemory0;
117
+ }
118
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
119
+ cachedTextDecoder.decode();
120
+ var MAX_SAFARI_DECODE_BYTES = 2146435072;
121
+ var numBytesDecoded = 0;
122
+ function decodeText(ptr, len) {
123
+ numBytesDecoded += len;
124
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
125
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
126
+ cachedTextDecoder.decode();
127
+ numBytesDecoded = len;
128
+ }
129
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
130
+ }
131
+ function getStringFromWasm0(ptr, len) {
132
+ ptr = ptr >>> 0;
133
+ return decodeText(ptr, len);
134
+ }
135
+ function addToExternrefTable0(obj) {
136
+ const idx = wasm.__externref_table_alloc();
137
+ wasm.__wbindgen_externrefs.set(idx, obj);
138
+ return idx;
139
+ }
140
+ function handleError(f, args) {
141
+ try {
142
+ return f.apply(this, args);
143
+ } catch (e) {
144
+ const idx = addToExternrefTable0(e);
145
+ wasm.__wbindgen_exn_store(idx);
146
+ }
147
+ }
148
+ function getArrayU8FromWasm0(ptr, len) {
149
+ ptr = ptr >>> 0;
150
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
151
+ }
152
+ var CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
153
+ }, unregister: () => {
154
+ } } : new FinalizationRegistry((state) => state.dtor(state.a, state.b));
155
+ function makeMutClosure(arg0, arg1, dtor, f) {
156
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
157
+ const real = (...args) => {
158
+ state.cnt++;
159
+ const a = state.a;
160
+ state.a = 0;
161
+ try {
162
+ return f(a, state.b, ...args);
163
+ } finally {
164
+ state.a = a;
165
+ real._wbg_cb_unref();
166
+ }
167
+ };
168
+ real._wbg_cb_unref = () => {
169
+ if (--state.cnt === 0) {
170
+ state.dtor(state.a, state.b);
171
+ state.a = 0;
172
+ CLOSURE_DTORS.unregister(state);
173
+ }
174
+ };
175
+ CLOSURE_DTORS.register(real, state, state);
176
+ return real;
177
+ }
178
+ function takeFromExternrefTable0(idx) {
179
+ const value = wasm.__wbindgen_externrefs.get(idx);
180
+ wasm.__externref_table_dealloc(idx);
181
+ return value;
182
+ }
183
+ function passArray8ToWasm0(arg, malloc) {
184
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
185
+ getUint8ArrayMemory0().set(arg, ptr / 1);
186
+ WASM_VECTOR_LEN = arg.length;
187
+ return ptr;
188
+ }
189
+ function wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4(arg0, arg1) {
190
+ wasm.wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4(arg0, arg1);
191
+ }
192
+ function wasm_bindgen__convert__closures_____invoke__h5116ef40c5ca7cd6(arg0, arg1, arg2) {
193
+ wasm.wasm_bindgen__convert__closures_____invoke__h5116ef40c5ca7cd6(arg0, arg1, arg2);
194
+ }
195
+ function wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b(arg0, arg1, arg2) {
196
+ wasm.wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b(arg0, arg1, arg2);
197
+ }
198
+ var NetworkStatus = Object.freeze({
199
+ Disconnected: 0,
200
+ "0": "Disconnected",
201
+ Connecting: 1,
202
+ "1": "Connecting",
203
+ Connected: 2,
204
+ "2": "Connected",
205
+ Error: 3,
206
+ "3": "Error"
207
+ });
208
+ var __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
209
+ var WasmVmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
210
+ }, unregister: () => {
211
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_wasmvm_free(ptr >>> 0, 1));
212
+ var WasmVm = class {
213
+ __destroy_into_raw() {
214
+ const ptr = this.__wbg_ptr;
215
+ this.__wbg_ptr = 0;
216
+ WasmVmFinalization.unregister(this);
217
+ return ptr;
218
+ }
219
+ free() {
220
+ const ptr = this.__destroy_into_raw();
221
+ wasm.__wbg_wasmvm_free(ptr, 0);
222
+ }
223
+ /**
224
+ * Get a byte from the UART output buffer, if available.
225
+ * @returns {number | undefined}
226
+ */
227
+ get_output() {
228
+ const ret = wasm.wasmvm_get_output(this.__wbg_ptr);
229
+ return ret === 16777215 ? void 0 : ret;
230
+ }
231
+ /**
232
+ * Get the current network connection status.
233
+ * @returns {NetworkStatus}
234
+ */
235
+ network_status() {
236
+ const ret = wasm.wasmvm_network_status(this.__wbg_ptr);
237
+ return ret;
238
+ }
239
+ /**
240
+ * Connect to a WebSocket relay server for networking.
241
+ * The URL should be like "ws://localhost:8765".
242
+ * @param {string} ws_url
243
+ */
244
+ connect_network(ws_url) {
245
+ const ptr0 = passStringToWasm0(ws_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
246
+ const len0 = WASM_VECTOR_LEN;
247
+ const ret = wasm.wasmvm_connect_network(this.__wbg_ptr, ptr0, len0);
248
+ if (ret[1]) {
249
+ throw takeFromExternrefTable0(ret[0]);
250
+ }
251
+ }
252
+ /**
253
+ * Get current memory usage (DRAM size) in bytes.
254
+ * @returns {bigint}
255
+ */
256
+ get_memory_usage() {
257
+ const ret = wasm.wasmvm_get_memory_usage(this.__wbg_ptr);
258
+ return BigInt.asUintN(64, ret);
259
+ }
260
+ /**
261
+ * Disconnect from the network.
262
+ */
263
+ disconnect_network() {
264
+ wasm.wasmvm_disconnect_network(this.__wbg_ptr);
265
+ }
266
+ /**
267
+ * Connect to a WebTransport relay server.
268
+ * @param {string} url
269
+ * @param {string | null} [cert_hash]
270
+ */
271
+ connect_webtransport(url, cert_hash) {
272
+ const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
273
+ const len0 = WASM_VECTOR_LEN;
274
+ var ptr1 = isLikeNone(cert_hash) ? 0 : passStringToWasm0(cert_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
275
+ var len1 = WASM_VECTOR_LEN;
276
+ const ret = wasm.wasmvm_connect_webtransport(this.__wbg_ptr, ptr0, len0, ptr1, len1);
277
+ if (ret[1]) {
278
+ throw takeFromExternrefTable0(ret[0]);
279
+ }
280
+ }
281
+ /**
282
+ * Create a new VM instance and load a kernel (ELF or raw binary).
283
+ * @param {Uint8Array} kernel
284
+ */
285
+ constructor(kernel) {
286
+ const ptr0 = passArray8ToWasm0(kernel, wasm.__wbindgen_malloc);
287
+ const len0 = WASM_VECTOR_LEN;
288
+ const ret = wasm.wasmvm_new(ptr0, len0);
289
+ if (ret[2]) {
290
+ throw takeFromExternrefTable0(ret[1]);
291
+ }
292
+ this.__wbg_ptr = ret[0] >>> 0;
293
+ WasmVmFinalization.register(this, this.__wbg_ptr, this);
294
+ return this;
295
+ }
296
+ /**
297
+ * Execute a single instruction.
298
+ */
299
+ step() {
300
+ wasm.wasmvm_step(this.__wbg_ptr);
301
+ }
302
+ /**
303
+ * Push an input byte to the UART.
304
+ * @param {number} byte
305
+ */
306
+ input(byte) {
307
+ wasm.wasmvm_input(this.__wbg_ptr, byte);
308
+ }
309
+ /**
310
+ * Load a disk image and attach it as a VirtIO block device.
311
+ * This should be called before starting execution if the kernel needs a filesystem.
312
+ * @param {Uint8Array} disk_image
313
+ */
314
+ load_disk(disk_image) {
315
+ const ptr0 = passArray8ToWasm0(disk_image, wasm.__wbindgen_malloc);
316
+ const len0 = WASM_VECTOR_LEN;
317
+ wasm.wasmvm_load_disk(this.__wbg_ptr, ptr0, len0);
318
+ }
319
+ };
320
+ if (Symbol.dispose) WasmVm.prototype[Symbol.dispose] = WasmVm.prototype.free;
321
+ var EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
322
+ async function __wbg_load(module, imports) {
323
+ if (typeof Response === "function" && module instanceof Response) {
324
+ if (typeof WebAssembly.instantiateStreaming === "function") {
325
+ try {
326
+ return await WebAssembly.instantiateStreaming(module, imports);
327
+ } catch (e) {
328
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
329
+ if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
330
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
331
+ } else {
332
+ throw e;
333
+ }
334
+ }
335
+ }
336
+ const bytes = await module.arrayBuffer();
337
+ return await WebAssembly.instantiate(bytes, imports);
338
+ } else {
339
+ const instance = await WebAssembly.instantiate(module, imports);
340
+ if (instance instanceof WebAssembly.Instance) {
341
+ return { instance, module };
342
+ } else {
343
+ return instance;
344
+ }
345
+ }
346
+ }
347
+ function __wbg_get_imports() {
348
+ const imports = {};
349
+ imports.wbg = {};
350
+ imports.wbg.__wbg___wbindgen_boolean_get_6d5a1ee65bab5f68 = function(arg0) {
351
+ const v = arg0;
352
+ const ret = typeof v === "boolean" ? v : void 0;
353
+ return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
354
+ };
355
+ imports.wbg.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function(arg0, arg1) {
356
+ const ret = debugString(arg1);
357
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
358
+ const len1 = WASM_VECTOR_LEN;
359
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
360
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
361
+ };
362
+ imports.wbg.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
363
+ const ret = typeof arg0 === "function";
364
+ return ret;
365
+ };
366
+ imports.wbg.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
367
+ const ret = arg0 === void 0;
368
+ return ret;
369
+ };
370
+ imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
371
+ throw new Error(getStringFromWasm0(arg0, arg1));
372
+ };
373
+ imports.wbg.__wbg__wbg_cb_unref_2454a539ea5790d9 = function(arg0) {
374
+ arg0._wbg_cb_unref();
375
+ };
376
+ imports.wbg.__wbg_buffer_ccc4520b36d3ccf4 = function(arg0) {
377
+ const ret = arg0.buffer;
378
+ return ret;
379
+ };
380
+ imports.wbg.__wbg_call_e762c39fa8ea36bf = function() {
381
+ return handleError(function(arg0, arg1) {
382
+ const ret = arg0.call(arg1);
383
+ return ret;
384
+ }, arguments);
385
+ };
386
+ imports.wbg.__wbg_code_20d453b11b200026 = function(arg0) {
387
+ const ret = arg0.code;
388
+ return ret;
389
+ };
390
+ imports.wbg.__wbg_data_ee4306d069f24f2d = function(arg0) {
391
+ const ret = arg0.data;
392
+ return ret;
393
+ };
394
+ imports.wbg.__wbg_datagrams_d3815636dcdca421 = function(arg0) {
395
+ const ret = arg0.datagrams;
396
+ return ret;
397
+ };
398
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
399
+ let deferred0_0;
400
+ let deferred0_1;
401
+ try {
402
+ deferred0_0 = arg0;
403
+ deferred0_1 = arg1;
404
+ console.error(getStringFromWasm0(arg0, arg1));
405
+ } finally {
406
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
407
+ }
408
+ };
409
+ imports.wbg.__wbg_getReader_15e2d3098e32c359 = function(arg0) {
410
+ const ret = arg0.getReader();
411
+ return ret;
412
+ };
413
+ imports.wbg.__wbg_getWriter_c891ce50cc187493 = function() {
414
+ return handleError(function(arg0) {
415
+ const ret = arg0.getWriter();
416
+ return ret;
417
+ }, arguments);
418
+ };
419
+ imports.wbg.__wbg_get_efcb449f58ec27c2 = function() {
420
+ return handleError(function(arg0, arg1) {
421
+ const ret = Reflect.get(arg0, arg1);
422
+ return ret;
423
+ }, arguments);
424
+ };
425
+ imports.wbg.__wbg_instanceof_ArrayBuffer_70beb1189ca63b38 = function(arg0) {
426
+ let result;
427
+ try {
428
+ result = arg0 instanceof ArrayBuffer;
429
+ } catch (_) {
430
+ result = false;
431
+ }
432
+ const ret = result;
433
+ return ret;
434
+ };
435
+ imports.wbg.__wbg_length_69bca3cb64fc8748 = function(arg0) {
436
+ const ret = arg0.length;
437
+ return ret;
438
+ };
439
+ imports.wbg.__wbg_message_3abccea43568e0bd = function(arg0, arg1) {
440
+ const ret = arg1.message;
441
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
442
+ const len1 = WASM_VECTOR_LEN;
443
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
444
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
445
+ };
446
+ imports.wbg.__wbg_new_1acc0b6eea89d040 = function() {
447
+ const ret = new Object();
448
+ return ret;
449
+ };
450
+ imports.wbg.__wbg_new_5a79be3ab53b8aa5 = function(arg0) {
451
+ const ret = new Uint8Array(arg0);
452
+ return ret;
453
+ };
454
+ imports.wbg.__wbg_new_881c4fe631eee9ad = function() {
455
+ return handleError(function(arg0, arg1) {
456
+ const ret = new WebSocket(getStringFromWasm0(arg0, arg1));
457
+ return ret;
458
+ }, arguments);
459
+ };
460
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
461
+ const ret = new Error();
462
+ return ret;
463
+ };
464
+ imports.wbg.__wbg_new_e17d9f43105b08be = function() {
465
+ const ret = new Array();
466
+ return ret;
467
+ };
468
+ imports.wbg.__wbg_new_from_slice_92f4d78ca282a2d2 = function(arg0, arg1) {
469
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
470
+ return ret;
471
+ };
472
+ imports.wbg.__wbg_new_no_args_ee98eee5275000a4 = function(arg0, arg1) {
473
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
474
+ return ret;
475
+ };
476
+ imports.wbg.__wbg_new_with_options_9965f8e85fa9c22f = function() {
477
+ return handleError(function(arg0, arg1, arg2) {
478
+ const ret = new WebTransport(getStringFromWasm0(arg0, arg1), arg2);
479
+ return ret;
480
+ }, arguments);
481
+ };
482
+ imports.wbg.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
483
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
484
+ };
485
+ imports.wbg.__wbg_push_df81a39d04db858c = function(arg0, arg1) {
486
+ const ret = arg0.push(arg1);
487
+ return ret;
488
+ };
489
+ imports.wbg.__wbg_queueMicrotask_34d692c25c47d05b = function(arg0) {
490
+ const ret = arg0.queueMicrotask;
491
+ return ret;
492
+ };
493
+ imports.wbg.__wbg_queueMicrotask_9d76cacb20c84d58 = function(arg0) {
494
+ queueMicrotask(arg0);
495
+ };
496
+ imports.wbg.__wbg_read_48f1593df542f968 = function(arg0) {
497
+ const ret = arg0.read();
498
+ return ret;
499
+ };
500
+ imports.wbg.__wbg_readable_86145f8eb068e7c2 = function(arg0) {
501
+ const ret = arg0.readable;
502
+ return ret;
503
+ };
504
+ imports.wbg.__wbg_ready_310519d62d77aaae = function(arg0) {
505
+ const ret = arg0.ready;
506
+ return ret;
507
+ };
508
+ imports.wbg.__wbg_reason_1cced37e3a93763e = function(arg0, arg1) {
509
+ const ret = arg1.reason;
510
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
511
+ const len1 = WASM_VECTOR_LEN;
512
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
513
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
514
+ };
515
+ imports.wbg.__wbg_resolve_caf97c30b83f7053 = function(arg0) {
516
+ const ret = Promise.resolve(arg0);
517
+ return ret;
518
+ };
519
+ imports.wbg.__wbg_send_25caa2dbdb78318d = function() {
520
+ return handleError(function(arg0, arg1) {
521
+ arg0.send(arg1);
522
+ }, arguments);
523
+ };
524
+ imports.wbg.__wbg_set_algorithm_8f54a80aa7f1ccb1 = function(arg0, arg1, arg2) {
525
+ arg0.algorithm = getStringFromWasm0(arg1, arg2);
526
+ };
527
+ imports.wbg.__wbg_set_binaryType_9d839cea8fcdc5c3 = function(arg0, arg1) {
528
+ arg0.binaryType = __wbindgen_enum_BinaryType[arg1];
529
+ };
530
+ imports.wbg.__wbg_set_onclose_c09e4f7422de8dae = function(arg0, arg1) {
531
+ arg0.onclose = arg1;
532
+ };
533
+ imports.wbg.__wbg_set_onerror_337a3a2db9517378 = function(arg0, arg1) {
534
+ arg0.onerror = arg1;
535
+ };
536
+ imports.wbg.__wbg_set_onmessage_8661558551a89792 = function(arg0, arg1) {
537
+ arg0.onmessage = arg1;
538
+ };
539
+ imports.wbg.__wbg_set_onopen_efccb9305427b907 = function(arg0, arg1) {
540
+ arg0.onopen = arg1;
541
+ };
542
+ imports.wbg.__wbg_set_server_certificate_hashes_0936192963851de7 = function(arg0, arg1) {
543
+ arg0.serverCertificateHashes = arg1;
544
+ };
545
+ imports.wbg.__wbg_set_value_49be14618c9b991a = function(arg0, arg1) {
546
+ arg0.value = arg1;
547
+ };
548
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
549
+ const ret = arg1.stack;
550
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
551
+ const len1 = WASM_VECTOR_LEN;
552
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
553
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
554
+ };
555
+ imports.wbg.__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e = function() {
556
+ const ret = typeof global === "undefined" ? null : global;
557
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
558
+ };
559
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac = function() {
560
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
561
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
562
+ };
563
+ imports.wbg.__wbg_static_accessor_SELF_6fdf4b64710cc91b = function() {
564
+ const ret = typeof self === "undefined" ? null : self;
565
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
566
+ };
567
+ imports.wbg.__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2 = function() {
568
+ const ret = typeof window === "undefined" ? null : window;
569
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
570
+ };
571
+ imports.wbg.__wbg_then_4f46f6544e6b4a28 = function(arg0, arg1) {
572
+ const ret = arg0.then(arg1);
573
+ return ret;
574
+ };
575
+ imports.wbg.__wbg_then_70d05cf780a18d77 = function(arg0, arg1, arg2) {
576
+ const ret = arg0.then(arg1, arg2);
577
+ return ret;
578
+ };
579
+ imports.wbg.__wbg_writable_9ade33d14ef66806 = function(arg0) {
580
+ const ret = arg0.writable;
581
+ return ret;
582
+ };
583
+ imports.wbg.__wbg_write_5f693b62e780062e = function(arg0, arg1) {
584
+ const ret = arg0.write(arg1);
585
+ return ret;
586
+ };
587
+ imports.wbg.__wbindgen_cast_188ff5bafa3120b4 = function(arg0, arg1) {
588
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h158587509e69fed9, wasm_bindgen__convert__closures_____invoke__hcf26143a2d2b8df4);
589
+ return ret;
590
+ };
591
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
592
+ const ret = getStringFromWasm0(arg0, arg1);
593
+ return ret;
594
+ };
595
+ imports.wbg.__wbindgen_cast_5b09fbeec74be75e = function(arg0, arg1) {
596
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hb2f3fe1158f30bc9, wasm_bindgen__convert__closures_____invoke__h6fd3101b14d9814b);
597
+ return ret;
598
+ };
599
+ imports.wbg.__wbindgen_cast_7a6407ddad05d376 = function(arg0, arg1) {
600
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h158587509e69fed9, wasm_bindgen__convert__closures_____invoke__h5116ef40c5ca7cd6);
601
+ return ret;
602
+ };
603
+ imports.wbg.__wbindgen_cast_93ac3bab887248d1 = function(arg0, arg1) {
604
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h158587509e69fed9, wasm_bindgen__convert__closures_____invoke__h5116ef40c5ca7cd6);
605
+ return ret;
606
+ };
607
+ imports.wbg.__wbindgen_cast_c68dd2eba48505aa = function(arg0, arg1) {
608
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h158587509e69fed9, wasm_bindgen__convert__closures_____invoke__h5116ef40c5ca7cd6);
609
+ return ret;
610
+ };
611
+ imports.wbg.__wbindgen_init_externref_table = function() {
612
+ const table = wasm.__wbindgen_externrefs;
613
+ const offset = table.grow(4);
614
+ table.set(0, void 0);
615
+ table.set(offset + 0, void 0);
616
+ table.set(offset + 1, null);
617
+ table.set(offset + 2, true);
618
+ table.set(offset + 3, false);
619
+ ;
620
+ };
621
+ return imports;
622
+ }
623
+ function __wbg_finalize_init(instance, module) {
624
+ wasm = instance.exports;
625
+ __wbg_init.__wbindgen_wasm_module = module;
626
+ cachedDataViewMemory0 = null;
627
+ cachedUint8ArrayMemory0 = null;
628
+ wasm.__wbindgen_start();
629
+ return wasm;
630
+ }
631
+ function initSync(module) {
632
+ if (wasm !== void 0) return wasm;
633
+ if (typeof module !== "undefined") {
634
+ if (Object.getPrototypeOf(module) === Object.prototype) {
635
+ ({ module } = module);
636
+ } else {
637
+ console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
638
+ }
639
+ }
640
+ const imports = __wbg_get_imports();
641
+ if (!(module instanceof WebAssembly.Module)) {
642
+ module = new WebAssembly.Module(module);
643
+ }
644
+ const instance = new WebAssembly.Instance(module, imports);
645
+ return __wbg_finalize_init(instance, module);
646
+ }
647
+ async function __wbg_init(module_or_path) {
648
+ if (wasm !== void 0) return wasm;
649
+ if (typeof module_or_path !== "undefined") {
650
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
651
+ ({ module_or_path } = module_or_path);
652
+ } else {
653
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
654
+ }
655
+ }
656
+ if (typeof module_or_path === "undefined") {
657
+ module_or_path = new URL("riscv_vm_bg.wasm", import.meta.url);
658
+ }
659
+ const imports = __wbg_get_imports();
660
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
661
+ module_or_path = fetch(module_or_path);
662
+ }
663
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
664
+ return __wbg_finalize_init(instance, module);
665
+ }
666
+ var riscv_vm_default = __wbg_init;
667
+ export {
668
+ NetworkStatus,
669
+ WasmVm,
670
+ riscv_vm_default as default,
671
+ initSync
672
+ };
package/build.sh ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ set -e # Exit on any error
3
+
4
+ is_mac() {
5
+ [[ "$OSTYPE" == "darwin"* ]]
6
+ }
7
+
8
+
9
+ PACKAGEJSON=./pkg/package.json
10
+ IMPORTFILE=./pkg/riscv_vm.js
11
+
12
+ echo "Building the rust library"
13
+ RUSTFLAGS=--cfg=web_sys_unstable_apis npx wasm-pack build --target web
14
+
15
+ if is_mac; then
16
+ sed -i '' 's/"module": "riscv_vm.js",/"main": "riscv_vm.js",/' $PACKAGEJSON
17
+ sed -i '' "/if (typeof input === 'undefined') {/,/}/d" $IMPORTFILE
18
+ else
19
+ sed -i 's/"module": "riscv_vm.js",/"main": "riscv_vm.js",/' $PACKAGEJSON
20
+ sed -i "/if (typeof input === 'undefined') {/,/}/d" $IMPORTFILE
21
+ fi
22
+
23
+ npx tsup --config tsup/tsup.cli.ts
24
+ npx tsup --config tsup/tsup.core.cjs.ts
25
+ npx tsup --config tsup/tsup.core.esm.ts
26
+ npx tsup --config tsup/tsup.core.cjs.ts --dts-only