forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoExportRuntime.debug.js
More file actions
170 lines (170 loc) · 6.15 KB
/
noExportRuntime.debug.js
File metadata and controls
170 lines (170 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
async function instantiate(module, imports = {}) {
const adaptedImports = {
env: Object.setPrototypeOf({
abort(message, fileName, lineNumber, columnNumber) {
// ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
message = __liftString(message >>> 0);
fileName = __liftString(fileName >>> 0);
lineNumber = lineNumber >>> 0;
columnNumber = columnNumber >>> 0;
(() => {
// @external.js
throw Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
})();
},
}, Object.assign(Object.create(globalThis), imports.env || {})),
};
const { exports } = await WebAssembly.instantiate(module, adaptedImports);
const memory = exports.memory || imports.env.memory;
const adaptedExports = Object.setPrototypeOf({
isString: {
// bindings/noExportRuntime/isString: ~lib/string/String
valueOf() { return this.value; },
get value() {
return __liftString(exports.isString.value >>> 0);
}
},
returnsString() {
// bindings/noExportRuntime/returnsString() => ~lib/string/String
return __liftString(exports.returnsString() >>> 0);
},
isBuffer: {
// bindings/noExportRuntime/isBuffer: ~lib/arraybuffer/ArrayBuffer
valueOf() { return this.value; },
get value() {
return __liftBuffer(exports.isBuffer.value >>> 0);
}
},
returnsBuffer() {
// bindings/noExportRuntime/returnsBuffer() => ~lib/arraybuffer/ArrayBuffer
return __liftBuffer(exports.returnsBuffer() >>> 0);
},
isTypedArray: {
// bindings/noExportRuntime/isTypedArray: ~lib/typedarray/Int32Array
valueOf() { return this.value; },
get value() {
return __liftTypedArray(Int32Array, exports.isTypedArray.value >>> 0);
}
},
returnsTypedArray() {
// bindings/noExportRuntime/returnsTypedArray() => ~lib/typedarray/Int32Array
return __liftTypedArray(Int32Array, exports.returnsTypedArray() >>> 0);
},
isArrayOfBasic: {
// bindings/noExportRuntime/isArrayOfBasic: ~lib/array/Array<i32>
valueOf() { return this.value; },
get value() {
return __liftArray(__getI32, 2, exports.isArrayOfBasic.value >>> 0);
}
},
returnsArrayOfBasic() {
// bindings/noExportRuntime/returnsArrayOfBasic() => ~lib/array/Array<i32>
return __liftArray(__getI32, 2, exports.returnsArrayOfBasic() >>> 0);
},
isArrayOfArray: {
// bindings/noExportRuntime/isArrayOfArray: ~lib/array/Array<~lib/array/Array<i32>>
valueOf() { return this.value; },
get value() {
return __liftArray(pointer => __liftArray(__getI32, 2, __getU32(pointer)), 2, exports.isArrayOfArray.value >>> 0);
}
},
returnsArrayOfArray() {
// bindings/noExportRuntime/returnsArrayOfArray() => ~lib/array/Array<~lib/array/Array<i32>>
return __liftArray(pointer => __liftArray(__getI32, 2, __getU32(pointer)), 2, exports.returnsArrayOfArray() >>> 0);
},
takesNonPlainObject(obj) {
// bindings/noExportRuntime/takesNonPlainObject(bindings/noExportRuntime/NonPlainObject) => void
obj = __lowerInternref(obj) || __notnull();
exports.takesNonPlainObject(obj);
},
takesFunction(fn) {
// bindings/noExportRuntime/takesFunction(() => void) => void
fn = __lowerInternref(fn) || __notnull();
exports.takesFunction(fn);
},
}, exports);
function __liftBuffer(pointer) {
if (!pointer) return null;
return memory.buffer.slice(pointer, pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2]);
}
function __liftString(pointer) {
if (!pointer) return null;
const
end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1,
memoryU16 = new Uint16Array(memory.buffer);
let
start = pointer >>> 1,
string = "";
while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
return string + String.fromCharCode(...memoryU16.subarray(start, end));
}
function __liftArray(liftElement, align, pointer) {
if (!pointer) return null;
const
dataStart = __getU32(pointer + 4),
length = __dataview.getUint32(pointer + 12, true),
values = new Array(length);
for (let i = 0; i < length; ++i) values[i] = liftElement(dataStart + (i << align >>> 0));
return values;
}
function __liftTypedArray(constructor, pointer) {
if (!pointer) return null;
return new constructor(
memory.buffer,
__getU32(pointer + 4),
__dataview.getUint32(pointer + 8, true) / constructor.BYTES_PER_ELEMENT
).slice();
}
class Internref extends Number {}
function __lowerInternref(value) {
if (value == null) return 0;
if (value instanceof Internref) return value.valueOf();
throw TypeError("internref expected");
}
function __notnull() {
throw TypeError("value must not be null");
}
let __dataview = new DataView(memory.buffer);
function __getI32(pointer) {
try {
return __dataview.getInt32(pointer, true);
} catch {
__dataview = new DataView(memory.buffer);
return __dataview.getInt32(pointer, true);
}
}
function __getU32(pointer) {
try {
return __dataview.getUint32(pointer, true);
} catch {
__dataview = new DataView(memory.buffer);
return __dataview.getUint32(pointer, true);
}
}
exports._start();
return adaptedExports;
}
export const {
memory,
isBasic,
takesReturnsBasic,
isString,
returnsString,
isBuffer,
returnsBuffer,
isTypedArray,
returnsTypedArray,
isArrayOfBasic,
returnsArrayOfBasic,
isArrayOfArray,
returnsArrayOfArray,
takesNonPlainObject,
takesFunction,
} = await (async url => instantiate(
await (async () => {
const isNodeOrBun = typeof process != "undefined" && process.versions != null && (process.versions.node != null || process.versions.bun != null);
if (isNodeOrBun) { return globalThis.WebAssembly.compile(await (await import("node:fs/promises")).readFile(url)); }
else { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); }
})(), {
}
))(new URL("noExportRuntime.debug.wasm", import.meta.url));