porffor 0.17.0-a1f691e30 → 0.17.0-a818353a5
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/codegen.js +6 -43
- package/package.json +1 -1
package/compiler/codegen.js
CHANGED
@@ -72,9 +72,6 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
72
72
|
case 'ExpressionStatement':
|
73
73
|
return generateExp(scope, decl);
|
74
74
|
|
75
|
-
case 'SequenceExpression':
|
76
|
-
return generateSequence(scope, decl);
|
77
|
-
|
78
75
|
case 'CallExpression':
|
79
76
|
return generateCall(scope, decl, global, name, valueUnused);
|
80
77
|
|
@@ -979,33 +976,6 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
979
976
|
};
|
980
977
|
|
981
978
|
const generateBinaryExp = (scope, decl, _global, _name) => {
|
982
|
-
if (decl.operator === 'instanceof') {
|
983
|
-
// very hacky basic instanceof
|
984
|
-
// todo: support dynamic right-hand side
|
985
|
-
|
986
|
-
const out = generate(scope, decl.left);
|
987
|
-
disposeLeftover(out);
|
988
|
-
|
989
|
-
const rightName = decl.right.name;
|
990
|
-
if (!rightName) return todo(scope, 'instanceof dynamic right-hand side is not supported yet', true);
|
991
|
-
|
992
|
-
const checkType = TYPES[rightName.toLowerCase()];
|
993
|
-
if (checkType == null || rightName !== TYPE_NAMES[checkType] || checkType === TYPES.undefined) return todo(scope, 'instanceof right-hand side type unsupported', true);
|
994
|
-
|
995
|
-
if ([TYPES.number, TYPES.boolean, TYPES.string, TYPES.symbol, TYPES.object].includes(checkType)) {
|
996
|
-
out.push(...number(0));
|
997
|
-
} else {
|
998
|
-
out.push(
|
999
|
-
...getNodeType(scope, decl.left),
|
1000
|
-
...number(checkType, Valtype.i32),
|
1001
|
-
[ Opcodes.i32_eq ],
|
1002
|
-
Opcodes.i32_from_u
|
1003
|
-
);
|
1004
|
-
}
|
1005
|
-
|
1006
|
-
return out;
|
1007
|
-
}
|
1008
|
-
|
1009
979
|
const out = performOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right), _global, _name);
|
1010
980
|
|
1011
981
|
if (valtype !== 'i32' && ['==', '===', '!=', '!==', '>', '>=', '<', '<='].includes(decl.operator)) out.push(Opcodes.i32_from_u);
|
@@ -1312,7 +1282,7 @@ const getNodeType = (scope, node) => {
|
|
1312
1282
|
}
|
1313
1283
|
|
1314
1284
|
if (node.type === 'BinaryExpression') {
|
1315
|
-
if (['==', '===', '!=', '!==', '>', '>=', '<', '<='
|
1285
|
+
if (['==', '===', '!=', '!==', '>', '>=', '<', '<='].includes(node.operator)) return TYPES.boolean;
|
1316
1286
|
if (node.operator !== '+') return TYPES.number;
|
1317
1287
|
|
1318
1288
|
const knownLeft = knownType(scope, getNodeType(scope, node.left));
|
@@ -1457,18 +1427,6 @@ const generateExp = (scope, decl) => {
|
|
1457
1427
|
return out;
|
1458
1428
|
};
|
1459
1429
|
|
1460
|
-
const generateSequence = (scope, decl) => {
|
1461
|
-
let out = [];
|
1462
|
-
|
1463
|
-
const exprs = decl.expressions;
|
1464
|
-
for (let i = 0; i < exprs.length; i++) {
|
1465
|
-
if (i > 0) disposeLeftover(out);
|
1466
|
-
out.push(...generate(scope, exprs[i]));
|
1467
|
-
}
|
1468
|
-
|
1469
|
-
return out;
|
1470
|
-
};
|
1471
|
-
|
1472
1430
|
const CTArrayUtil = {
|
1473
1431
|
getLengthI32: pointer => [
|
1474
1432
|
...number(0, Valtype.i32),
|
@@ -2344,6 +2302,11 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2344
2302
|
const { type, name } = decl.left;
|
2345
2303
|
const [ local, isGlobal ] = lookupName(scope, name);
|
2346
2304
|
|
2305
|
+
if (type === 'ObjectPattern') {
|
2306
|
+
// hack: ignore object parts of `var a = {} = 2`
|
2307
|
+
return generate(scope, decl.right);
|
2308
|
+
}
|
2309
|
+
|
2347
2310
|
if (isFuncType(decl.right.type)) {
|
2348
2311
|
// hack for a = function () { ... }
|
2349
2312
|
decl.right.id = { name };
|
package/package.json
CHANGED