porffor 0.20.6 → 0.20.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/builtins/object.ts +28 -0
- package/compiler/builtins/set.ts +1 -4
- package/compiler/builtins/weakref.ts +1 -1
- package/compiler/builtins/z_map.ts +2 -4
- package/compiler/builtins/z_weakmap.ts +3 -5
- package/compiler/builtins/z_weakset.ts +2 -5
- package/compiler/codegen.js +15 -16
- package/compiler/generated_builtins.js +132 -119
- package/compiler/types.js +10 -16
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -83,6 +83,17 @@ export const __Object_entries = (obj: any): any[] => {
|
|
83
83
|
return out;
|
84
84
|
};
|
85
85
|
|
86
|
+
export const __Object_fromEntries = (iterable: any): object => {
|
87
|
+
const out: object = {};
|
88
|
+
|
89
|
+
for (const x of iterable) {
|
90
|
+
if (Porffor.rawType(x) < 0x06) throw new TypeError('Iterator contains non-object');
|
91
|
+
out[ecma262.ToPropertyKey(x[0])] = x[1];
|
92
|
+
}
|
93
|
+
|
94
|
+
return out;
|
95
|
+
};
|
96
|
+
|
86
97
|
|
87
98
|
export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
88
99
|
const p: any = ecma262.ToPropertyKey(prop);
|
@@ -103,6 +114,23 @@ export const __Object_hasOwn = (obj: any, prop: any) => {
|
|
103
114
|
};
|
104
115
|
|
105
116
|
|
117
|
+
export const __Object_assign = (target: any, ...sources: any[]) => {
|
118
|
+
if (target == null) throw new TypeError('Argument is nullish, expected object');
|
119
|
+
|
120
|
+
for (const x of sources) {
|
121
|
+
const keys: any[] = __Object_keys(x);
|
122
|
+
const vals: any[] = __Object_values(x);
|
123
|
+
|
124
|
+
const len: i32 = keys.length;
|
125
|
+
for (let i: i32 = 0; i < len; i++) {
|
126
|
+
target[keys[i]] = vals[i];
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
return target;
|
131
|
+
};
|
132
|
+
|
133
|
+
|
106
134
|
export const __Object_prototype_toString = (_this: object) => {
|
107
135
|
let out: bytestring = '[object Object]';
|
108
136
|
return out;
|
package/compiler/builtins/set.ts
CHANGED
@@ -184,10 +184,7 @@ export const Set = function (iterable: any): Set {
|
|
184
184
|
|
185
185
|
const out: Set = __Porffor_allocate();
|
186
186
|
|
187
|
-
if (
|
188
|
-
Porffor.rawType(iterable) != Porffor.TYPES.undefined,
|
189
|
-
iterable !== null
|
190
|
-
)) for (const x of iterable) {
|
187
|
+
if (iterable != null) for (const x of iterable) {
|
191
188
|
__Set_prototype_add(out, x);
|
192
189
|
}
|
193
190
|
|
@@ -3,7 +3,7 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const WeakRef = function (target: any): WeakRef {
|
4
4
|
if (!new.target) throw new TypeError("Constructor WeakRef requires 'new'");
|
5
5
|
|
6
|
-
if (Porffor.rawType(target) <
|
6
|
+
if (Porffor.rawType(target) < 0x05) throw new TypeError('Target for WeakRef needs to be an object or symbol');
|
7
7
|
|
8
8
|
const out: WeakRef = Porffor.allocateBytes(9);
|
9
9
|
|
@@ -97,10 +97,8 @@ export const Map = function (iterable: any): Map {
|
|
97
97
|
const vals: any[] = Porffor.allocate();
|
98
98
|
Porffor.wasm.i32.store(out, vals, 0, 4);
|
99
99
|
|
100
|
-
if (
|
101
|
-
Porffor.rawType(
|
102
|
-
iterable !== null
|
103
|
-
)) for (const x of iterable) {
|
100
|
+
if (iterable != null) for (const x of iterable) {
|
101
|
+
if (Porffor.rawType(x) < 0x06) throw new TypeError('Iterator contains non-object');
|
104
102
|
__Map_prototype_set(out, x[0], x[1]);
|
105
103
|
}
|
106
104
|
|
@@ -3,7 +3,7 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const __WeakMap_prototype_has = (_this: WeakMap, key: any) => __Map_prototype_has(_this, key);
|
4
4
|
|
5
5
|
export const __WeakMap_prototype_set = (_this: WeakMap, key: any, value: any) => {
|
6
|
-
if (Porffor.rawType(key) <
|
6
|
+
if (Porffor.rawType(key) < 0x05) throw new TypeError('Value in WeakSet needs to be an object or symbol');
|
7
7
|
|
8
8
|
__Map_prototype_set(_this, key, value);
|
9
9
|
return _this;
|
@@ -22,10 +22,8 @@ export const WeakMap = function (iterable: any): WeakMap {
|
|
22
22
|
const vals: any[] = Porffor.allocate();
|
23
23
|
Porffor.wasm.i32.store(out, vals, 0, 4);
|
24
24
|
|
25
|
-
if (
|
26
|
-
Porffor.rawType(
|
27
|
-
iterable !== null
|
28
|
-
)) for (const x of iterable) {
|
25
|
+
if (iterable != null) for (const x of iterable) {
|
26
|
+
if (Porffor.rawType(x) < 0x06) throw new TypeError('Iterator contains non-object');
|
29
27
|
__WeakMap_prototype_set(out, x[0], x[1]);
|
30
28
|
}
|
31
29
|
|
@@ -3,7 +3,7 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const __WeakSet_prototype_has = (_this: WeakSet, value: any) => __Set_prototype_has(_this, value);
|
4
4
|
|
5
5
|
export const __WeakSet_prototype_add = (_this: WeakSet, value: any) => {
|
6
|
-
if (Porffor.rawType(value) <
|
6
|
+
if (Porffor.rawType(value) < 0x05) throw new TypeError('Value in WeakSet needs to be an object or symbol');
|
7
7
|
|
8
8
|
__Set_prototype_add(_this, value);
|
9
9
|
return _this;
|
@@ -16,10 +16,7 @@ export const WeakSet = function (iterable: any): WeakSet {
|
|
16
16
|
|
17
17
|
const out: WeakSet = __Porffor_allocate();
|
18
18
|
|
19
|
-
if (
|
20
|
-
Porffor.rawType(iterable) != Porffor.TYPES.undefined,
|
21
|
-
iterable !== null
|
22
|
-
)) for (const x of iterable) {
|
19
|
+
if (iterable != null) for (const x of iterable) {
|
23
20
|
__WeakSet_prototype_add(out, x);
|
24
21
|
}
|
25
22
|
|
package/compiler/codegen.js
CHANGED
@@ -1332,7 +1332,7 @@ const isExistingProtoFunc = name => {
|
|
1332
1332
|
const getType = (scope, _name) => {
|
1333
1333
|
const name = mapName(_name);
|
1334
1334
|
|
1335
|
-
|
1335
|
+
if (Object.hasOwn(builtinVars, name)) return number(builtinVars[name].type ?? TYPES.number, Valtype.i32);
|
1336
1336
|
|
1337
1337
|
if (typedInput && scope.locals[name]?.metadata?.type != null) return number(scope.locals[name].metadata.type, Valtype.i32);
|
1338
1338
|
if (Object.hasOwn(scope.locals, name)) return [ [ Opcodes.local_get, scope.locals[name + '#type'].idx ] ];
|
@@ -1340,13 +1340,13 @@ const getType = (scope, _name) => {
|
|
1340
1340
|
if (typedInput && globals[name]?.metadata?.type != null) return number(globals[name].metadata.type, Valtype.i32);
|
1341
1341
|
if (Object.hasOwn(globals, name)) return [ [ Opcodes.global_get, globals[name + '#type'].idx ] ];
|
1342
1342
|
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1343
|
+
if (Object.hasOwn(builtinFuncs, name) || Object.hasOwn(importedFuncs, name) ||
|
1344
|
+
Object.hasOwn(funcIndex, name) || Object.hasOwn(internalConstrs, name))
|
1345
|
+
return number(TYPES.function, Valtype.i32);
|
1346
1346
|
|
1347
|
-
if (isExistingProtoFunc(name))
|
1347
|
+
if (isExistingProtoFunc(name)) return number(TYPES.function, Valtype.i32);
|
1348
1348
|
|
1349
|
-
return number(
|
1349
|
+
return number(TYPES.undefined, Valtype.i32);
|
1350
1350
|
};
|
1351
1351
|
|
1352
1352
|
const setType = (scope, _name, type) => {
|
@@ -3430,16 +3430,22 @@ const generateForOf = (scope, decl) => {
|
|
3430
3430
|
// get length
|
3431
3431
|
[ Opcodes.local_get, pointer ],
|
3432
3432
|
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
3433
|
-
[ Opcodes.
|
3433
|
+
[ Opcodes.local_tee, length ],
|
3434
|
+
|
3435
|
+
[ Opcodes.if, Blocktype.void ]
|
3434
3436
|
);
|
3435
3437
|
|
3438
|
+
depth.push('if');
|
3436
3439
|
depth.push('forof');
|
3440
|
+
depth.push('block');
|
3441
|
+
depth.push('block');
|
3437
3442
|
|
3438
3443
|
// setup local for left
|
3439
3444
|
generate(scope, decl.left);
|
3440
3445
|
|
3441
3446
|
let leftName = decl.left.declarations?.[0]?.id?.name;
|
3442
3447
|
if (!leftName && decl.left.name) {
|
3448
|
+
// todo: should be sloppy mode only
|
3443
3449
|
leftName = decl.left.name;
|
3444
3450
|
|
3445
3451
|
generateVar(scope, { kind: 'var', _bare: true, declarations: [ { id: { name: leftName } } ] })
|
@@ -3450,9 +3456,6 @@ const generateForOf = (scope, decl) => {
|
|
3450
3456
|
const [ local, isGlobal ] = lookupName(scope, leftName);
|
3451
3457
|
if (!local) return todo(scope, 'for of failed to get left local (probably destructure)');
|
3452
3458
|
|
3453
|
-
depth.push('block');
|
3454
|
-
depth.push('block');
|
3455
|
-
|
3456
3459
|
// // todo: we should only do this for strings but we don't know at compile-time :(
|
3457
3460
|
// hack: this is naughty and will break things!
|
3458
3461
|
let newOut = number(0, Valtype.i32), newPointer = number(0, Valtype.i32);
|
@@ -3595,12 +3598,6 @@ const generateForOf = (scope, decl) => {
|
|
3595
3598
|
...generate(scope, decl.body),
|
3596
3599
|
[ Opcodes.end ],
|
3597
3600
|
|
3598
|
-
// increment iter pointer
|
3599
|
-
// [ Opcodes.local_get, pointer ],
|
3600
|
-
// ...number(1, Valtype.i32),
|
3601
|
-
// [ Opcodes.i32_add ],
|
3602
|
-
// [ Opcodes.local_set, pointer ],
|
3603
|
-
|
3604
3601
|
// increment counter by 1
|
3605
3602
|
[ Opcodes.local_get, counter ],
|
3606
3603
|
...number(1, Valtype.i32),
|
@@ -3758,6 +3755,8 @@ const generateForOf = (scope, decl) => {
|
|
3758
3755
|
default: internalThrow(scope, 'TypeError', `Tried for..of on non-iterable type`)
|
3759
3756
|
}, Blocktype.void));
|
3760
3757
|
|
3758
|
+
out.push([ Opcodes.end ]); // end if
|
3759
|
+
|
3761
3760
|
depth.pop();
|
3762
3761
|
depth.pop();
|
3763
3762
|
depth.pop();
|