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.
@@ -884,30 +884,40 @@ const knownNullish = decl => {
884
884
 
885
885
  const generateBinaryExp = (scope, decl, _global, _name) => {
886
886
  if (decl.operator === 'instanceof') {
887
- // very hacky basic instanceof
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 (!rightName) return todo(scope, 'instanceof dynamic right-hand side is not supported yet', true);
895
-
896
- const checkType = TYPES[rightName.toLowerCase()];
897
- if (checkType == null || rightName !== TYPE_NAMES[checkType] || checkType === TYPES.undefined) return todo(scope, 'instanceof right-hand side type unsupported', true);
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
- if ([TYPES.number, TYPES.boolean, TYPES.string, TYPES.symbol, TYPES.object].includes(checkType)) {
900
- out.push(...number(0));
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 out;
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.35.2+e15887a34",
4
+ "version": "0.35.3+30564a39f",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.35.2+e15887a34';
3
+ globalThis.version = '0.35.3+30564a39f';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {