porffor 0.35.2 → 0.35.3
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 +26 -2
- package/compiler/builtins_precompiled.js +25 -20
- package/compiler/codegen.js +30 -20
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -884,30 +884,40 @@ const knownNullish = decl => {
|
|
884
884
|
|
885
885
|
const generateBinaryExp = (scope, decl, _global, _name) => {
|
886
886
|
if (decl.operator === 'instanceof') {
|
887
|
-
//
|
888
|
-
// todo: support dynamic right-hand side
|
889
|
-
|
890
|
-
const out = generate(scope, decl.left);
|
891
|
-
disposeLeftover(out);
|
892
|
-
|
887
|
+
// try hacky version for built-ins first
|
893
888
|
const rightName = decl.right.name;
|
894
|
-
if (
|
895
|
-
|
896
|
-
|
897
|
-
|
889
|
+
if (rightName) {
|
890
|
+
const checkType = TYPES[rightName.toLowerCase()];
|
891
|
+
if (checkType != null && rightName === TYPE_NAMES[checkType]) {
|
892
|
+
const out = generate(scope, decl.left);
|
893
|
+
disposeLeftover(out);
|
894
|
+
|
895
|
+
if ([TYPES.number, TYPES.boolean, TYPES.string].includes(checkType)) {
|
896
|
+
out.push(...number(0));
|
897
|
+
} else {
|
898
|
+
out.push(
|
899
|
+
...getNodeType(scope, decl.left),
|
900
|
+
...number(checkType, Valtype.i32),
|
901
|
+
[ Opcodes.i32_eq ],
|
902
|
+
Opcodes.i32_from_u
|
903
|
+
);
|
904
|
+
}
|
898
905
|
|
899
|
-
|
900
|
-
|
901
|
-
} else {
|
902
|
-
out.push(
|
903
|
-
...getNodeType(scope, decl.left),
|
904
|
-
...number(checkType, Valtype.i32),
|
905
|
-
[ Opcodes.i32_eq ],
|
906
|
-
Opcodes.i32_from_u
|
907
|
-
);
|
906
|
+
return out;
|
907
|
+
}
|
908
908
|
}
|
909
909
|
|
910
|
-
return
|
910
|
+
return generate(scope, {
|
911
|
+
type: 'CallExpression',
|
912
|
+
callee: {
|
913
|
+
type: 'Identifier',
|
914
|
+
name: '__Porffor_object_instanceof'
|
915
|
+
},
|
916
|
+
arguments: [
|
917
|
+
decl.left,
|
918
|
+
decl.right
|
919
|
+
]
|
920
|
+
});
|
911
921
|
}
|
912
922
|
|
913
923
|
if (decl.operator === 'in') {
|
package/package.json
CHANGED