porffor 0.22.6 → 0.22.7
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.
- package/compiler/assemble.js +21 -2
- package/compiler/builtins/_internal_object.ts +0 -2
- package/compiler/builtins/reflect.ts +113 -15
- package/compiler/codegen.js +3 -4
- package/compiler/generated_builtins.js +56 -15
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/tmp.txt +423 -0
package/compiler/assemble.js
CHANGED
@@ -230,7 +230,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
230
230
|
// };
|
231
231
|
// }
|
232
232
|
|
233
|
-
const exports = funcs.filter(x => x.export).map((x, i) => [ ...encodeString(x.name === 'main' ? 'm' : x.name), ExportDesc.func, x.index ]);
|
233
|
+
const exports = funcs.filter(x => x.export).map((x, i) => [ ...encodeString(x.name === 'main' ? 'm' : x.name), ExportDesc.func, ...unsignedLEB128(x.index) ]);
|
234
234
|
|
235
235
|
if (Prefs.alwaysMemory && pages.size === 0) pages.set('--always-memory', 0);
|
236
236
|
if (optLevel === 0) pages.set('O0 precaution', 0);
|
@@ -276,7 +276,26 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
276
276
|
|
277
277
|
if (typeCount !== 0) localDecl.push(encodeLocal(typeCount, lastType));
|
278
278
|
|
279
|
-
|
279
|
+
// todo: move const, call transforms here too?
|
280
|
+
|
281
|
+
const wasm = [];
|
282
|
+
for (let i = 0; i < x.wasm.length; i++) {
|
283
|
+
let o = x.wasm[i];
|
284
|
+
|
285
|
+
if (
|
286
|
+
(o[0] === Opcodes.local_get || o[0] === Opcodes.local_set || o[0] === Opcodes.local_tee || o[0] === Opcodes.global_get || o[0] === Opcodes.global_set) &&
|
287
|
+
o[1] > 127
|
288
|
+
) {
|
289
|
+
const n = o[1];
|
290
|
+
o = [...o];
|
291
|
+
o.pop();
|
292
|
+
unsignedLEB128_into(n, o);
|
293
|
+
}
|
294
|
+
|
295
|
+
wasm.push(...o);
|
296
|
+
}
|
297
|
+
|
298
|
+
return encodeVector([ ...encodeVector(localDecl), ...wasm.flat().filter(x => x != null && x <= 0xff), Opcodes.end ]);
|
280
299
|
}))
|
281
300
|
);
|
282
301
|
|
@@ -325,7 +325,6 @@ export const __Porffor_object_isObject = (arg: any): boolean => {
|
|
325
325
|
return Porffor.fastAnd(
|
326
326
|
arg != 0, // null
|
327
327
|
t > 0x05,
|
328
|
-
t != Porffor.TYPES.undefined,
|
329
328
|
t != Porffor.TYPES.string,
|
330
329
|
t != Porffor.TYPES.bytestring,
|
331
330
|
);
|
@@ -336,7 +335,6 @@ export const __Porffor_object_isObjectOrSymbol = (arg: any): boolean => {
|
|
336
335
|
return Porffor.fastAnd(
|
337
336
|
arg != 0, // null
|
338
337
|
t > 0x04,
|
339
|
-
t != Porffor.TYPES.undefined,
|
340
338
|
t != Porffor.TYPES.string,
|
341
339
|
t != Porffor.TYPES.bytestring,
|
342
340
|
);
|
@@ -1,34 +1,132 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
// todo: support receiver
|
4
|
-
export const __Reflect_get = (target: any,
|
4
|
+
export const __Reflect_get = (target: any, prop: any) => {
|
5
5
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
6
6
|
|
7
|
-
|
7
|
+
return target[prop];
|
8
|
+
};
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
// todo: support receiver
|
11
|
+
export const __Reflect_set = (target: any, prop: any, value: any) => {
|
12
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
13
|
+
|
14
|
+
try {
|
15
|
+
target[prop] = value;
|
16
|
+
return true;
|
17
|
+
} catch {
|
18
|
+
return false;
|
12
19
|
}
|
20
|
+
};
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
if (idx == -1) return undefined;
|
22
|
+
export const __Reflect_has = (target: any, prop: any) => {
|
23
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
17
24
|
|
18
|
-
|
19
|
-
return vals[idx];
|
25
|
+
return prop in target;
|
20
26
|
};
|
21
27
|
|
22
|
-
export const
|
28
|
+
export const __Reflect_defineProperty = (target: any, prop: any, descriptor: any) => {
|
23
29
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
30
|
+
if (!Porffor.object.isObject(descriptor)) throw new TypeError('Descriptor is a non-object');
|
24
31
|
|
25
|
-
|
32
|
+
try {
|
33
|
+
Object.defineProperty(target, prop, descriptor);
|
34
|
+
return true;
|
35
|
+
} catch {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
|
40
|
+
export const __Reflect_deleteProperty = (target: any, prop: any) => {
|
41
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
42
|
+
|
43
|
+
return delete target[prop];
|
44
|
+
};
|
45
|
+
|
46
|
+
export const __Reflect_getOwnPropertyDescriptor = (target: any, prop: any) => {
|
47
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
48
|
+
|
49
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
50
|
+
};
|
51
|
+
|
52
|
+
export const __Reflect_isExtensible = (target: any) => {
|
53
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
54
|
+
|
55
|
+
return Object.isExtensible(target);
|
56
|
+
};
|
57
|
+
|
58
|
+
export const __Reflect_preventExtensions = (target: any) => {
|
59
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
60
|
+
|
61
|
+
try {
|
62
|
+
Object.preventExtensions(target);
|
63
|
+
return true;
|
64
|
+
} catch {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
export const __Reflect_ownKeys = (target: any) => {
|
70
|
+
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
71
|
+
|
72
|
+
const out: any[] = Porffor.allocate();
|
26
73
|
|
27
74
|
const t: i32 = Porffor.rawType(target);
|
28
75
|
if (t == Porffor.TYPES.object) {
|
29
|
-
|
76
|
+
let ptr: i32 = Porffor.wasm`local.get ${target}` + 5;
|
77
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load(target, 0, 0) * 14;
|
78
|
+
|
79
|
+
let i: i32 = 0;
|
80
|
+
for (; ptr < endPtr; ptr += 14) {
|
81
|
+
let key: any;
|
82
|
+
Porffor.wasm`local raw i32
|
83
|
+
local msb i32
|
84
|
+
local.get ${ptr}
|
85
|
+
i32.to_u
|
86
|
+
i32.load 0 0
|
87
|
+
local.set raw
|
88
|
+
|
89
|
+
local.get raw
|
90
|
+
i32.const 30
|
91
|
+
i32.shr_u
|
92
|
+
local.tee msb
|
93
|
+
if 127
|
94
|
+
i32.const 5 ;; symbol
|
95
|
+
i32.const 67 ;; string
|
96
|
+
local.get msb
|
97
|
+
i32.const 3
|
98
|
+
i32.eq
|
99
|
+
select
|
100
|
+
local.set ${key+1}
|
101
|
+
|
102
|
+
local.get raw
|
103
|
+
i32.const 1073741823
|
104
|
+
i32.and ;; unset 2 MSBs
|
105
|
+
else
|
106
|
+
i32.const 195
|
107
|
+
local.set ${key+1}
|
108
|
+
|
109
|
+
local.get raw
|
110
|
+
end
|
111
|
+
i32.from_u
|
112
|
+
local.set ${key}`;
|
113
|
+
|
114
|
+
out[i++] = key;
|
115
|
+
}
|
116
|
+
|
117
|
+
out.length = i;
|
118
|
+
} else if (Porffor.fastOr(
|
119
|
+
t == Porffor.TYPES.array,
|
120
|
+
t == Porffor.TYPES.bytestring,
|
121
|
+
t == Porffor.TYPES.string
|
122
|
+
)) {
|
123
|
+
const len: i32 = target.length;
|
124
|
+
out.length = len;
|
125
|
+
|
126
|
+
for (let i: i32 = 0; i < len; i++) {
|
127
|
+
out[i] = __Number_prototype_toString(i);
|
128
|
+
}
|
30
129
|
}
|
31
130
|
|
32
|
-
|
33
|
-
return __Array_prototype_includes(keys, p);
|
131
|
+
return out;
|
34
132
|
};
|
package/compiler/codegen.js
CHANGED
@@ -39,7 +39,7 @@ const todo = (scope, msg, expectsValue = undefined) => {
|
|
39
39
|
const isFuncType = type =>
|
40
40
|
type === 'FunctionDeclaration' || type === 'FunctionExpression' || type === 'ArrowFunctionExpression';
|
41
41
|
const hasFuncWithName = name =>
|
42
|
-
Object.hasOwn(funcIndex, name)
|
42
|
+
Object.hasOwn(funcIndex, name) || Object.hasOwn(builtinFuncs, name) || Object.hasOwn(importedFuncs, name) || Object.hasOwn(internalConstrs, name);
|
43
43
|
|
44
44
|
const astCache = new WeakMap();
|
45
45
|
const cacheAst = (decl, wasm) => {
|
@@ -164,6 +164,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
164
164
|
return cacheAst(decl, generateMember(scope, decl, global, name));
|
165
165
|
|
166
166
|
case 'ExportNamedDeclaration':
|
167
|
+
if (!decl.declaration) return todo(scope, 'unsupported export declaration');
|
168
|
+
|
167
169
|
const funcsBefore = funcs.map(x => x.name);
|
168
170
|
generate(scope, decl.declaration);
|
169
171
|
|
@@ -2835,9 +2837,6 @@ const generateVar = (scope, decl) => {
|
|
2835
2837
|
scope.globalInits[name] = newOut;
|
2836
2838
|
}
|
2837
2839
|
}
|
2838
|
-
|
2839
|
-
// hack: this follows spec properly but is mostly unneeded 😅
|
2840
|
-
// out.push(...setType(scope, name, x.init ? getNodeType(scope, x.init) : TYPES.undefined));
|
2841
2840
|
}
|
2842
2841
|
|
2843
2842
|
return out;
|