porffor 0.55.21 → 0.55.22

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.
@@ -10,14 +10,6 @@ import { log } from './log.js';
10
10
  import { allocPage, allocStr } from './allocator.js';
11
11
  import './prefs.js';
12
12
 
13
- let globals = {};
14
- let tags = [];
15
- let funcs = [];
16
- let exceptions = [];
17
- let funcIndex = {};
18
- let currentFuncIndex = importedFuncs.length;
19
- let builtinFuncs = {}, builtinVars = {}, prototypeFuncs = {};
20
-
21
13
  class TodoError extends Error {
22
14
  constructor(message) {
23
15
  super(message);
@@ -46,7 +38,6 @@ const cacheAst = (decl, wasm) => {
46
38
  return wasm;
47
39
  };
48
40
 
49
- let indirectFuncs = [];
50
41
  let doNotMarkFuncRef = false;
51
42
  const funcRef = func => {
52
43
  if (!doNotMarkFuncRef) func.referenced = true;
@@ -1393,7 +1384,6 @@ const isExistingProtoFunc = name => {
1393
1384
  return false;
1394
1385
  };
1395
1386
 
1396
- let globalInfer;
1397
1387
  const getInferred = (scope, name, global = false) => {
1398
1388
  if (global) {
1399
1389
  if (globalInfer.has(name)) return globalInfer.get(name);
@@ -2907,8 +2897,7 @@ const brTable = (input, bc, returns) => {
2907
2897
  for (let i = offset; i <= max; i++) {
2908
2898
  // if branch for this num, go to that block
2909
2899
  if (bc[i]) {
2910
- table.push(br);
2911
- br++;
2900
+ table.push(br++);
2912
2901
  continue;
2913
2902
  }
2914
2903
 
@@ -2945,9 +2934,6 @@ const brTable = (input, bc, returns) => {
2945
2934
  return out;
2946
2935
  };
2947
2936
 
2948
- let typeswitchDepth = 0;
2949
-
2950
- let usedTypes = new Set();
2951
2937
  const typeUsed = (scope, x) => {
2952
2938
  if (x == null) return;
2953
2939
  usedTypes.add(x);
@@ -3103,7 +3089,7 @@ const typeIsNotOneOf = (type, types, valtype = Valtype.i32) => {
3103
3089
  return out;
3104
3090
  };
3105
3091
 
3106
- const allocVar = (scope, name, global = false, type = true, redecl = false) => {
3092
+ const allocVar = (scope, name, global = false, type = true, redecl = false, i32 = false) => {
3107
3093
  const target = global ? globals : scope.locals;
3108
3094
 
3109
3095
  // already declared
@@ -3118,7 +3104,7 @@ const allocVar = (scope, name, global = false, type = true, redecl = false) => {
3118
3104
  }
3119
3105
 
3120
3106
  let idx = global ? globals['#ind']++ : scope.localInd++;
3121
- target[name] = { idx, type: valtypeBinary };
3107
+ target[name] = { idx, type: i32 ? Valtype.i32 : valtypeBinary };
3122
3108
 
3123
3109
  if (type) {
3124
3110
  let typeIdx = global ? globals['#ind']++ : scope.localInd++;
@@ -3600,7 +3586,6 @@ const memberTmpNames = scope => {
3600
3586
  };
3601
3587
 
3602
3588
  // COCTC: cross-object compile-time cache
3603
- let coctc = new Map();
3604
3589
  const coctcOffset = prop => {
3605
3590
  if (typeof prop === 'object') {
3606
3591
  if (
@@ -4427,7 +4412,6 @@ const generateConditional = (scope, decl) => {
4427
4412
  return out;
4428
4413
  };
4429
4414
 
4430
- let depth = [];
4431
4415
  const generateFor = (scope, decl) => {
4432
4416
  const out = [];
4433
4417
 
@@ -5364,9 +5348,6 @@ const generateMeta = (scope, decl) => {
5364
5348
  return todo(scope, `meta property object ${decl.meta.name} is not supported yet`, true);
5365
5349
  };
5366
5350
 
5367
- let pages = new Map();
5368
- let data = [];
5369
-
5370
5351
  const compileBytes = (val, itemType) => {
5371
5352
  switch (itemType) {
5372
5353
  case 'i8': return [ val % 256 ];
@@ -6220,18 +6201,6 @@ const generateClass = (scope, decl) => {
6220
6201
  // default value to undefined
6221
6202
  value ??= DEFAULT_VALUE();
6222
6203
 
6223
- let outArr = out, outOp = 'push', outScope = scope;
6224
- if (type === 'PropertyDefinition' && !_static) {
6225
- // define in construction instead
6226
- outArr = func.wasm;
6227
- outOp = 'unshift';
6228
- object = {
6229
- type: 'ThisExpression',
6230
- _noGlobalThis: true
6231
- };
6232
- outScope = func;
6233
- }
6234
-
6235
6204
  if (isFuncType(value.type)) {
6236
6205
  let id = value.id;
6237
6206
 
@@ -6249,19 +6218,60 @@ const generateClass = (scope, decl) => {
6249
6218
  };
6250
6219
  }
6251
6220
 
6252
- outArr[outOp](
6253
- ...generate(outScope, object),
6254
- Opcodes.i32_to_u,
6255
- ...getNodeType(outScope, object),
6221
+ if (type === 'PropertyDefinition' && !_static) {
6222
+ // define in construction instead
6223
+ object = {
6224
+ type: 'ThisExpression',
6225
+ _noGlobalThis: true
6226
+ };
6256
6227
 
6257
- ...toPropertyKey(outScope, generate(outScope, k), getNodeType(outScope, k), computed, true),
6228
+ let computedTmp;
6229
+ if (computed) {
6230
+ // compute now, reference in construction
6231
+ computedTmp = allocVar(scope, `#class_computed_prop${uniqId()}`, true, true, false, true);
6258
6232
 
6259
- ...generate(outScope, value),
6260
- ...(initKind !== 'value' && initKind !== 'method' ? [ Opcodes.i32_to_u ] : []),
6261
- ...getNodeType(outScope, value),
6233
+ out.push(
6234
+ ...toPropertyKey(scope, generate(scope, k), getNodeType(scope, k), computed, true),
6235
+ [ Opcodes.global_set, computedTmp + 1 ],
6236
+ [ Opcodes.global_set, computedTmp ]
6237
+ );
6238
+ }
6262
6239
 
6263
- [ Opcodes.call, includeBuiltin(outScope, `__Porffor_object_class_${initKind}`).index ]
6264
- );
6240
+ func.wasm.unshift(
6241
+ ...generate(func, object),
6242
+ Opcodes.i32_to_u,
6243
+ ...getNodeType(func, object),
6244
+
6245
+ ...(computed ? [
6246
+ [ Opcodes.global_get, computedTmp ],
6247
+ [ Opcodes.global_get, computedTmp + 1 ],
6248
+ ] : [
6249
+ ...generate(func, k),
6250
+ Opcodes.i32_to_u,
6251
+ ...getNodeType(func, k)
6252
+ ]),
6253
+
6254
+ ...generate(func, value),
6255
+ ...(initKind !== 'value' && initKind !== 'method' ? [ Opcodes.i32_to_u ] : []),
6256
+ ...getNodeType(func, value),
6257
+
6258
+ [ Opcodes.call, includeBuiltin(func, `__Porffor_object_class_${initKind}`).index ]
6259
+ );
6260
+ } else {
6261
+ out.push(
6262
+ ...generate(scope, object),
6263
+ Opcodes.i32_to_u,
6264
+ ...getNodeType(scope, object),
6265
+
6266
+ ...toPropertyKey(scope, generate(scope, k), getNodeType(scope, k), computed, true),
6267
+
6268
+ ...generate(scope, value),
6269
+ ...(initKind !== 'value' && initKind !== 'method' ? [ Opcodes.i32_to_u ] : []),
6270
+ ...getNodeType(scope, value),
6271
+
6272
+ [ Opcodes.call, includeBuiltin(scope, `__Porffor_object_class_${initKind}`).index ]
6273
+ );
6274
+ }
6265
6275
  }
6266
6276
 
6267
6277
  delete scope.overrideThis;
@@ -6784,7 +6794,6 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
6784
6794
  return [ func, out ];
6785
6795
  };
6786
6796
 
6787
- let largestBlockBody = 0;
6788
6797
  const generateBlock = (scope, decl) => {
6789
6798
  let out = [];
6790
6799
 
@@ -6792,10 +6801,8 @@ const generateBlock = (scope, decl) => {
6792
6801
  scope.inferTree.push(decl);
6793
6802
 
6794
6803
  let len = decl.body.length, j = 0;
6795
- if (len > largestBlockBody) largestBlockBody = len;
6796
6804
  for (let i = 0; i < len; i++) {
6797
6805
  const x = decl.body[i];
6798
- if (len >= largestBlockBody) globalThis.progress?.(`${i}/${len}`);
6799
6806
  if (isEmptyNode(x)) continue;
6800
6807
 
6801
6808
  if (j++ > 0) out.push([ Opcodes.drop ]);
@@ -6958,10 +6965,9 @@ const internalConstrs = {
6958
6965
  }
6959
6966
  };
6960
6967
 
6968
+ let globals, tags, exceptions, funcs, indirectFuncs, funcIndex, currentFuncIndex, depth, pages, data, typeswitchDepth, usedTypes, coctc, globalInfer, builtinFuncs, builtinVars, prototypeFuncs;
6961
6969
  export default program => {
6962
- globals = {
6963
- ['#ind']: 0
6964
- };
6970
+ globals = { ['#ind']: 0 };
6965
6971
  tags = [];
6966
6972
  exceptions = [];
6967
6973
  funcs = []; indirectFuncs = [];
@@ -6971,26 +6977,22 @@ export default program => {
6971
6977
  data = [];
6972
6978
  currentFuncIndex = importedFuncs.length;
6973
6979
  typeswitchDepth = 0;
6974
- largestBlockBody = 0;
6975
6980
  usedTypes = new Set([ TYPES.empty, TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ]);
6976
6981
  coctc = new Map();
6977
6982
  globalInfer = new Map();
6978
6983
 
6979
- const valtypeInd = ['i32', 'i64', 'f64'].indexOf(valtype);
6980
-
6981
6984
  // set generic opcodes for current valtype
6985
+ const valtypeInd = ['i32', 'i64', 'f64'].indexOf(valtype);
6982
6986
  Opcodes.const = [ Opcodes.i32_const, Opcodes.i64_const, Opcodes.f64_const ][valtypeInd];
6983
6987
  Opcodes.eq = [ Opcodes.i32_eq, Opcodes.i64_eq, Opcodes.f64_eq ][valtypeInd];
6984
6988
  Opcodes.eqz = [ [ [ Opcodes.i32_eqz ] ], [ [ Opcodes.i64_eqz ] ], [ number(0), [ Opcodes.f64_eq ] ] ][valtypeInd];
6985
6989
  Opcodes.mul = [ Opcodes.i32_mul, Opcodes.i64_mul, Opcodes.f64_mul ][valtypeInd];
6986
6990
  Opcodes.add = [ Opcodes.i32_add, Opcodes.i64_add, Opcodes.f64_add ][valtypeInd];
6987
6991
  Opcodes.sub = [ Opcodes.i32_sub, Opcodes.i64_sub, Opcodes.f64_sub ][valtypeInd];
6988
-
6989
6992
  Opcodes.i32_to = [ [], [ Opcodes.i32_wrap_i64 ], Opcodes.i32_trunc_sat_f64_s ][valtypeInd];
6990
6993
  Opcodes.i32_to_u = [ [], [ Opcodes.i32_wrap_i64 ], Opcodes.i32_trunc_sat_f64_u ][valtypeInd];
6991
6994
  Opcodes.i32_from = [ [], [ Opcodes.i64_extend_i32_s ], [ Opcodes.f64_convert_i32_s ] ][valtypeInd];
6992
6995
  Opcodes.i32_from_u = [ [], [ Opcodes.i64_extend_i32_u ], [ Opcodes.f64_convert_i32_u ] ][valtypeInd];
6993
-
6994
6996
  Opcodes.load = [ Opcodes.i32_load, Opcodes.i64_load, Opcodes.f64_load ][valtypeInd];
6995
6997
  Opcodes.store = [ Opcodes.i32_store, Opcodes.i64_store, Opcodes.f64_store ][valtypeInd];
6996
6998
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.55.21",
4
+ "version": "0.55.22",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/r.cjs CHANGED
@@ -1,4 +1,10 @@
1
+ class C {
2
+ [(() => { return Math.random(); })()] = 1337;
3
+ }
1
4
 
5
+ console.log(new C());
6
+ console.log(new C());
7
+ console.log(new C());
2
8
 
3
9
  // let o = { set foo(x) { console.log('set foo', x); }, __proto__: { set bar(x) { console.log('set bar', x); } } };
4
10
 
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.55.21';
3
+ globalThis.version = '0.55.22';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {