@swf2es/codegen 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,308 @@
1
+ export async function instantiate(module, imports = {}) {
2
+ const adaptedImports = {
3
+ env: Object.setPrototypeOf({
4
+ abort(message, fileName, lineNumber, columnNumber) {
5
+ // ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
6
+ message = __liftString(message >>> 0);
7
+ fileName = __liftString(fileName >>> 0);
8
+ lineNumber = lineNumber >>> 0;
9
+ columnNumber = columnNumber >>> 0;
10
+ (() => {
11
+ // @external.js
12
+ throw Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
13
+ })();
14
+ },
15
+ }, Object.assign(Object.create(globalThis), imports.env || {})),
16
+ };
17
+ const { exports } = await WebAssembly.instantiate(module, adaptedImports);
18
+ const memory = exports.memory || imports.env.memory;
19
+ const adaptedExports = Object.setPrototypeOf({
20
+ compilerVersion() {
21
+ // assembly/index/compilerVersion() => ~lib/string/String
22
+ return __liftString(exports.compilerVersion() >>> 0);
23
+ },
24
+ abcVersion(abc) {
25
+ // assembly/index/abcVersion(~lib/typedarray/Uint8Array) => i32
26
+ abc = __lowerTypedArray(Uint8Array, 27, 0, abc) || __notnull();
27
+ return exports.abcVersion(abc);
28
+ },
29
+ actionsEmitEach(swf, offsets, lengths, version, blocks, reuse) {
30
+ // assembly/avm1/compile/actionsEmitEach(~lib/typedarray/Uint8Array, ~lib/typedarray/Int32Array, ~lib/typedarray/Int32Array, i32, ~lib/string/String, bool) => ~lib/string/String
31
+ swf = __retain(__lowerTypedArray(Uint8Array, 27, 0, swf) || __notnull());
32
+ offsets = __retain(__lowerTypedArray(Int32Array, 31, 2, offsets) || __notnull());
33
+ lengths = __retain(__lowerTypedArray(Int32Array, 31, 2, lengths) || __notnull());
34
+ blocks = __lowerString(blocks) || __notnull();
35
+ reuse = reuse ? 1 : 0;
36
+ try {
37
+ return __liftString(exports.actionsEmitEach(swf, offsets, lengths, version, blocks, reuse) >>> 0);
38
+ } finally {
39
+ __release(swf);
40
+ __release(offsets);
41
+ __release(lengths);
42
+ }
43
+ },
44
+ actionsEmitEachBytes(swf, offsets, lengths, version, blocks, reuse) {
45
+ // assembly/avm1/compile/actionsEmitEachBytes(~lib/typedarray/Uint8Array, ~lib/typedarray/Int32Array, ~lib/typedarray/Int32Array, i32, ~lib/string/String, bool) => usize
46
+ swf = __retain(__lowerTypedArray(Uint8Array, 27, 0, swf) || __notnull());
47
+ offsets = __retain(__lowerTypedArray(Int32Array, 31, 2, offsets) || __notnull());
48
+ lengths = __retain(__lowerTypedArray(Int32Array, 31, 2, lengths) || __notnull());
49
+ blocks = __lowerString(blocks) || __notnull();
50
+ reuse = reuse ? 1 : 0;
51
+ try {
52
+ return exports.actionsEmitEachBytes(swf, offsets, lengths, version, blocks, reuse) >>> 0;
53
+ } finally {
54
+ __release(swf);
55
+ __release(offsets);
56
+ __release(lengths);
57
+ }
58
+ },
59
+ actionsHeldEmitEachBytes(handle, version, blocks) {
60
+ // assembly/avm1/compile/actionsHeldEmitEachBytes(i32, i32, ~lib/string/String) => usize
61
+ blocks = __lowerString(blocks) || __notnull();
62
+ return exports.actionsHeldEmitEachBytes(handle, version, blocks) >>> 0;
63
+ },
64
+ actionsHeldUnitBytes(handle, version, at, end, bound, five) {
65
+ // assembly/avm1/compile/actionsHeldUnitBytes(i32, i32, i32, i32, i32, bool) => usize
66
+ five = five ? 1 : 0;
67
+ return exports.actionsHeldUnitBytes(handle, version, at, end, bound, five) >>> 0;
68
+ },
69
+ actionsHold(handle, swf, offsets, lengths) {
70
+ // assembly/avm1/compile/actionsHold(i32, ~lib/typedarray/Uint8Array, ~lib/typedarray/Int32Array, ~lib/typedarray/Int32Array) => void
71
+ swf = __retain(__lowerTypedArray(Uint8Array, 27, 0, swf) || __notnull());
72
+ offsets = __retain(__lowerTypedArray(Int32Array, 31, 2, offsets) || __notnull());
73
+ lengths = __lowerTypedArray(Int32Array, 31, 2, lengths) || __notnull();
74
+ try {
75
+ exports.actionsHold(handle, swf, offsets, lengths);
76
+ } finally {
77
+ __release(swf);
78
+ __release(offsets);
79
+ }
80
+ },
81
+ actionsModuleBytes(swf, offsets, lengths, version, keep) {
82
+ // assembly/avm1/compile/actionsModuleBytes(~lib/typedarray/Uint8Array, ~lib/typedarray/Int32Array, ~lib/typedarray/Int32Array, i32, bool?) => usize
83
+ swf = __retain(__lowerTypedArray(Uint8Array, 27, 0, swf) || __notnull());
84
+ offsets = __retain(__lowerTypedArray(Int32Array, 31, 2, offsets) || __notnull());
85
+ lengths = __lowerTypedArray(Int32Array, 31, 2, lengths) || __notnull();
86
+ keep = keep ? 1 : 0;
87
+ try {
88
+ exports.__setArgumentsLength(arguments.length);
89
+ return exports.actionsModuleBytes(swf, offsets, lengths, version, keep) >>> 0;
90
+ } finally {
91
+ __release(swf);
92
+ __release(offsets);
93
+ }
94
+ },
95
+ actionsModuleEntries() {
96
+ // assembly/avm1/compile/actionsModuleEntries() => ~lib/string/String
97
+ return __liftString(exports.actionsModuleEntries() >>> 0);
98
+ },
99
+ actionsModuleUnits() {
100
+ // assembly/avm1/compile/actionsModuleUnits() => ~lib/string/String
101
+ return __liftString(exports.actionsModuleUnits() >>> 0);
102
+ },
103
+ actionsUnitBytes(swf, offsets, lengths, version, at, end, bound, five) {
104
+ // assembly/avm1/compile/actionsUnitBytes(~lib/typedarray/Uint8Array, ~lib/typedarray/Int32Array, ~lib/typedarray/Int32Array, i32, i32, i32, i32, bool) => usize
105
+ swf = __retain(__lowerTypedArray(Uint8Array, 27, 0, swf) || __notnull());
106
+ offsets = __retain(__lowerTypedArray(Int32Array, 31, 2, offsets) || __notnull());
107
+ lengths = __lowerTypedArray(Int32Array, 31, 2, lengths) || __notnull();
108
+ five = five ? 1 : 0;
109
+ try {
110
+ return exports.actionsUnitBytes(swf, offsets, lengths, version, at, end, bound, five) >>> 0;
111
+ } finally {
112
+ __release(swf);
113
+ __release(offsets);
114
+ }
115
+ },
116
+ actionsUnitLimits() {
117
+ // assembly/avm1/compile/actionsUnitLimits() => ~lib/typedarray/Float64Array
118
+ return __liftTypedArray(Float64Array, exports.actionsUnitLimits() >>> 0);
119
+ },
120
+ domainAdd(bytes, builtin, appDomain) {
121
+ // assembly/compile/domainAdd(~lib/typedarray/Uint8Array, bool, i32?) => i32
122
+ bytes = __lowerTypedArray(Uint8Array, 27, 0, bytes) || __notnull();
123
+ builtin = builtin ? 1 : 0;
124
+ exports.__setArgumentsLength(arguments.length);
125
+ return exports.domainAdd(bytes, builtin, appDomain);
126
+ },
127
+ domainCompact() {
128
+ // assembly/compile/domainCompact() => bool
129
+ return exports.domainCompact() != 0;
130
+ },
131
+ domainContext(index, after, upTo) {
132
+ // assembly/compile/domainContext(i32?, i32?, i32?) => ~lib/string/String
133
+ exports.__setArgumentsLength(arguments.length);
134
+ return __liftString(exports.domainContext(index, after, upTo) >>> 0);
135
+ },
136
+ domainEmitEach(bodies, reuse, which) {
137
+ // assembly/compile/domainEmitEach(~lib/string/String, bool, i32?) => ~lib/string/String
138
+ bodies = __lowerString(bodies) || __notnull();
139
+ reuse = reuse ? 1 : 0;
140
+ exports.__setArgumentsLength(arguments.length);
141
+ return __liftString(exports.domainEmitEach(bodies, reuse, which) >>> 0);
142
+ },
143
+ domainEmitEachBytes(bodies, reuse, which) {
144
+ // assembly/compile/domainEmitEachBytes(~lib/string/String, bool, i32?) => usize
145
+ bodies = __lowerString(bodies) || __notnull();
146
+ reuse = reuse ? 1 : 0;
147
+ exports.__setArgumentsLength(arguments.length);
148
+ return exports.domainEmitEachBytes(bodies, reuse, which) >>> 0;
149
+ },
150
+ domainFound(appDomain, nsKind, uri, name, abc, asType) {
151
+ // assembly/compile/domainFound(i32, i32, ~lib/string/String, ~lib/string/String, i32, bool) => void
152
+ uri = __retain(__lowerString(uri) || __notnull());
153
+ name = __lowerString(name) || __notnull();
154
+ asType = asType ? 1 : 0;
155
+ try {
156
+ exports.domainFound(appDomain, nsKind, uri, name, abc, asType);
157
+ } finally {
158
+ __release(uri);
159
+ }
160
+ },
161
+ domainLazyModuleBytes(hashes, index) {
162
+ // assembly/compile/domainLazyModuleBytes(~lib/string/String?, i32?) => usize
163
+ hashes = __lowerString(hashes) || __notnull();
164
+ exports.__setArgumentsLength(arguments.length);
165
+ return exports.domainLazyModuleBytes(hashes, index) >>> 0;
166
+ },
167
+ domainLinked(index) {
168
+ // assembly/compile/domainLinked(i32?) => ~lib/string/String
169
+ exports.__setArgumentsLength(arguments.length);
170
+ return __liftString(exports.domainLinked(index) >>> 0);
171
+ },
172
+ domainLogSince(mark, index) {
173
+ // assembly/compile/domainLogSince(i32, i32?) => ~lib/string/String
174
+ exports.__setArgumentsLength(arguments.length);
175
+ return __liftString(exports.domainLogSince(mark, index) >>> 0);
176
+ },
177
+ domainModule(hashes, index, keep, linkedOnly) {
178
+ // assembly/compile/domainModule(~lib/string/String?, i32?, bool?, bool?) => ~lib/string/String
179
+ hashes = __lowerString(hashes) || __notnull();
180
+ keep = keep ? 1 : 0;
181
+ linkedOnly = linkedOnly ? 1 : 0;
182
+ exports.__setArgumentsLength(arguments.length);
183
+ return __liftString(exports.domainModule(hashes, index, keep, linkedOnly) >>> 0);
184
+ },
185
+ domainModuleBytes(hashes, index, keep, linkedOnly) {
186
+ // assembly/compile/domainModuleBytes(~lib/string/String?, i32?, bool?, bool?) => usize
187
+ hashes = __lowerString(hashes) || __notnull();
188
+ keep = keep ? 1 : 0;
189
+ linkedOnly = linkedOnly ? 1 : 0;
190
+ exports.__setArgumentsLength(arguments.length);
191
+ return exports.domainModuleBytes(hashes, index, keep, linkedOnly) >>> 0;
192
+ },
193
+ domainModuleEntries() {
194
+ // assembly/compile/domainModuleEntries() => ~lib/string/String
195
+ return __liftString(exports.domainModuleEntries() >>> 0);
196
+ },
197
+ domainReplay(log, index) {
198
+ // assembly/compile/domainReplay(~lib/string/String, i32?) => bool
199
+ log = __lowerString(log) || __notnull();
200
+ exports.__setArgumentsLength(arguments.length);
201
+ return exports.domainReplay(log, index) != 0;
202
+ },
203
+ domainRestore(index, bytes) {
204
+ // assembly/compile/domainRestore(i32, ~lib/typedarray/Uint8Array) => i32
205
+ bytes = __lowerTypedArray(Uint8Array, 27, 0, bytes) || __notnull();
206
+ return exports.domainRestore(index, bytes);
207
+ },
208
+ domainRevision() {
209
+ // assembly/compile/domainRevision() => ~lib/string/String
210
+ return __liftString(exports.domainRevision() >>> 0);
211
+ },
212
+ domainSourceMap() {
213
+ // assembly/compile/domainSourceMap() => ~lib/string/String
214
+ return __liftString(exports.domainSourceMap() >>> 0);
215
+ },
216
+ domainUsage() {
217
+ // assembly/compile/domainUsage() => ~lib/string/String
218
+ return __liftString(exports.domainUsage() >>> 0);
219
+ },
220
+ domainWantsCompact() {
221
+ // assembly/compile/domainWantsCompact() => bool
222
+ return exports.domainWantsCompact() != 0;
223
+ },
224
+ outputLength() {
225
+ // assembly/output/outputLength() => u32
226
+ return exports.outputLength() >>> 0;
227
+ },
228
+ }, exports);
229
+ function __liftString(pointer) {
230
+ if (!pointer) return null;
231
+ const
232
+ end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1,
233
+ memoryU16 = new Uint16Array(memory.buffer);
234
+ let
235
+ start = pointer >>> 1,
236
+ string = "";
237
+ while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
238
+ return string + String.fromCharCode(...memoryU16.subarray(start, end));
239
+ }
240
+ function __lowerString(value) {
241
+ if (value == null) return 0;
242
+ const
243
+ length = value.length,
244
+ pointer = exports.__new(length << 1, 2) >>> 0,
245
+ memoryU16 = new Uint16Array(memory.buffer);
246
+ for (let i = 0; i < length; ++i) memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
247
+ return pointer;
248
+ }
249
+ function __liftTypedArray(constructor, pointer) {
250
+ if (!pointer) return null;
251
+ return new constructor(
252
+ memory.buffer,
253
+ __getU32(pointer + 4),
254
+ __dataview.getUint32(pointer + 8, true) / constructor.BYTES_PER_ELEMENT
255
+ ).slice();
256
+ }
257
+ function __lowerTypedArray(constructor, id, align, values) {
258
+ if (values == null) return 0;
259
+ const
260
+ length = values.length,
261
+ buffer = exports.__pin(exports.__new(length << align, 1)) >>> 0,
262
+ header = exports.__new(12, id) >>> 0;
263
+ __setU32(header + 0, buffer);
264
+ __dataview.setUint32(header + 4, buffer, true);
265
+ __dataview.setUint32(header + 8, length << align, true);
266
+ new constructor(memory.buffer, buffer, length).set(values);
267
+ exports.__unpin(buffer);
268
+ return header;
269
+ }
270
+ const refcounts = new Map();
271
+ function __retain(pointer) {
272
+ if (pointer) {
273
+ const refcount = refcounts.get(pointer);
274
+ if (refcount) refcounts.set(pointer, refcount + 1);
275
+ else refcounts.set(exports.__pin(pointer), 1);
276
+ }
277
+ return pointer;
278
+ }
279
+ function __release(pointer) {
280
+ if (pointer) {
281
+ const refcount = refcounts.get(pointer);
282
+ if (refcount === 1) exports.__unpin(pointer), refcounts.delete(pointer);
283
+ else if (refcount) refcounts.set(pointer, refcount - 1);
284
+ else throw Error(`invalid refcount '${refcount}' for reference '${pointer}'`);
285
+ }
286
+ }
287
+ function __notnull() {
288
+ throw TypeError("value must not be null");
289
+ }
290
+ let __dataview = new DataView(memory.buffer);
291
+ function __setU32(pointer, value) {
292
+ try {
293
+ __dataview.setUint32(pointer, value, true);
294
+ } catch {
295
+ __dataview = new DataView(memory.buffer);
296
+ __dataview.setUint32(pointer, value, true);
297
+ }
298
+ }
299
+ function __getU32(pointer) {
300
+ try {
301
+ return __dataview.getUint32(pointer, true);
302
+ } catch {
303
+ __dataview = new DataView(memory.buffer);
304
+ return __dataview.getUint32(pointer, true);
305
+ }
306
+ }
307
+ return adaptedExports;
308
+ }
Binary file