porffor 0.28.11 → 0.28.13

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.
@@ -825,10 +825,38 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
825
825
  ];
826
826
  };
827
827
 
828
- const falsy = (scope, wasm, type, intIn = false, intOut = false) => {
828
+ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode = undefined) => {
829
829
  const useTmp = knownType(scope, type) == null;
830
830
  const tmp = useTmp && localTmp(scope, `#logicinner_tmp${intIn ? '_int' : ''}`, intIn ? Valtype.i32 : valtypeBinary);
831
831
 
832
+ const def = (truthyMode => {
833
+ if (truthyMode === 'full') return [
834
+ // if value == 0 or NaN
835
+ ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
836
+ ...(intIn ? [] : [ Opcodes.i32_to ]),
837
+
838
+ [ Opcodes.i32_eqz ],
839
+
840
+ ...(intOut ? [] : [ Opcodes.i32_from ]),
841
+ ];
842
+
843
+ if (truthyMode === 'no_negative') return [
844
+ // if value == 0 or NaN, non-binary output. negative numbers not truthy :/
845
+ ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
846
+ ...(intIn ? [] : [ Opcodes.i32_to ]),
847
+ [ Opcodes.i32_eqz ],
848
+ ...(intOut ? [] : [ Opcodes.i32_from ])
849
+ ];
850
+
851
+ if (truthyMode === 'no_nan_negative') return [
852
+ // simpler and faster but makes NaN truthy and negative numbers not truthy,
853
+ // plus non-binary output
854
+ ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
855
+ ...(intIn ? [ [ Opcodes.i32_eqz ] ] : [ ...Opcodes.eqz ]),
856
+ ...(intOut ? [] : [ Opcodes.i32_from_u ])
857
+ ];
858
+ })(forceTruthyMode ?? Prefs.truthy ?? 'full');
859
+
832
860
  return [
833
861
  ...wasm,
834
862
  ...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
@@ -856,13 +884,7 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false) => {
856
884
  [ Opcodes.i32_eqz ],
857
885
  ...(intOut ? [] : [ Opcodes.i32_from_u ])
858
886
  ],
859
- default: [
860
- // if value == 0
861
- ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
862
-
863
- ...(intIn ? [ [ Opcodes.i32_eqz ] ] : [ ...Opcodes.eqz ]),
864
- ...(intOut ? [] : [ Opcodes.i32_from_u ])
865
- ]
887
+ default: def
866
888
  }, intOut ? Valtype.i32 : valtypeBinary)
867
889
  ];
868
890
  };
@@ -3647,7 +3669,7 @@ const generateUnary = (scope, decl) => {
3647
3669
  const arg = decl.argument;
3648
3670
  if (arg.type === 'UnaryExpression' && arg.operator === '!') {
3649
3671
  // opt: !!x -> is x truthy
3650
- return truthy(scope, generate(scope, arg.argument), getNodeType(scope, arg.argument), false, false);
3672
+ return truthy(scope, generate(scope, arg.argument), getNodeType(scope, arg.argument), false, false, 'full');
3651
3673
  }
3652
3674
 
3653
3675
  // !=
@@ -5814,16 +5836,6 @@ const internalConstrs = {
5814
5836
  notConstr: true
5815
5837
  },
5816
5838
 
5817
- Boolean: {
5818
- generate: (scope, decl) => {
5819
- // todo: boolean object when used as constructor
5820
- const arg = decl.arguments[0] ?? DEFAULT_VALUE();
5821
- return truthy(scope, generate(scope, arg), getNodeType(scope, arg), false, false, 'full');
5822
- },
5823
- type: TYPES.boolean,
5824
- length: 1
5825
- },
5826
-
5827
5839
  __Math_max: {
5828
5840
  generate: (scope, decl) => {
5829
5841
  const out = [
@@ -5864,7 +5876,7 @@ const internalConstrs = {
5864
5876
  length: 2
5865
5877
  },
5866
5878
 
5867
- printStatic: {
5879
+ __Porffor_printStatic: {
5868
5880
  generate: (scope, decl) => {
5869
5881
  const str = decl.arguments[0].value;
5870
5882
  return printStaticStr(str);
package/compiler/opt.js CHANGED
@@ -4,7 +4,10 @@ import { read_signedLEB128, read_ieee754_binary64 } from './encoding.js';
4
4
  import { log } from './log.js';
5
5
  import Prefs from './prefs.js';
6
6
 
7
+ const forceRemoveTypes = new Set(Prefs.forceRemoveTypes?.split?.(','));
7
8
  const hasType = (funcs, pages, type) => {
9
+ if (forceRemoveTypes.has(type)) return false;
10
+
8
11
  switch (type) {
9
12
  case 'Array':
10
13
  return pages.hasArray;
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.28.11+95f766485",
4
+ "version": "0.28.13+8740b6511",
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.28.11+95f766485';
3
+ globalThis.version = '0.28.13+8740b6511';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {