@markw65/monkeyc-optimizer 1.1.53 → 1.1.54

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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.54
6
+
7
+ - Fix return types of Dictionary.values() and Dictionary.keys()
8
+ - Fix issue with single-copy-prop creating stores that the Garmin compiler can't parse
9
+ - Handle percentage strings in resources
10
+ - Handle special strings in <param> nodes
11
+ - Don't treat '@Dotted.Name' as special in strings and jsonData
12
+ - Include ipush2 and ipush3 in pre
13
+
5
14
  ### 1.1.53
6
15
 
7
16
  - Update to [@markw65/prettier-plugin-monkeyc@1.0.56](https://github.com/markw65/prettier-plugin-monkeyc/blob/main/CHANGELOG.md#1056)
package/build/api.cjs CHANGED
@@ -18,47 +18,47 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- checkCompilerVersion: () => import_chunk_32NRMXAJ.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_32NRMXAJ.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_32NRMXAJ.createDocumentationMap,
24
- diagnostic: () => import_chunk_32NRMXAJ.diagnostic,
25
- diagnosticHelper: () => import_chunk_32NRMXAJ.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_32NRMXAJ.findNamesInScope,
27
- findUsingForNode: () => import_chunk_32NRMXAJ.findUsingForNode,
28
- formatAst: () => import_chunk_32NRMXAJ.formatAst,
29
- formatAstLongLines: () => import_chunk_32NRMXAJ.formatAstLongLines,
30
- formatScopedName: () => import_chunk_32NRMXAJ.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_32NRMXAJ.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_32NRMXAJ.getApiMapping,
33
- getSuperClasses: () => import_chunk_32NRMXAJ.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_5K64MLXC.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_5K64MLXC.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_5K64MLXC.createDocumentationMap,
24
+ diagnostic: () => import_chunk_5K64MLXC.diagnostic,
25
+ diagnosticHelper: () => import_chunk_5K64MLXC.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_5K64MLXC.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_5K64MLXC.findUsingForNode,
28
+ formatAst: () => import_chunk_5K64MLXC.formatAst,
29
+ formatAstLongLines: () => import_chunk_5K64MLXC.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_5K64MLXC.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_5K64MLXC.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_5K64MLXC.getApiMapping,
33
+ getSuperClasses: () => import_chunk_5K64MLXC.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_32NRMXAJ.isClassVariable,
36
- isLocal: () => import_chunk_32NRMXAJ.isLocal,
37
- isLookupCandidate: () => import_chunk_32NRMXAJ.isLookupCandidate,
38
- isStateNode: () => import_chunk_32NRMXAJ.isStateNode,
39
- lookupByFullName: () => import_chunk_32NRMXAJ.lookupByFullName,
40
- lookupNext: () => import_chunk_32NRMXAJ.lookupNext,
41
- lookupResultContains: () => import_chunk_32NRMXAJ.lookupResultContains,
42
- lookupWithType: () => import_chunk_32NRMXAJ.lookupWithType,
43
- makeToyboxLink: () => import_chunk_32NRMXAJ.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_32NRMXAJ.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_32NRMXAJ.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_32NRMXAJ.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_32NRMXAJ.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_32NRMXAJ.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_32NRMXAJ.sameLookupResult,
35
+ isClassVariable: () => import_chunk_5K64MLXC.isClassVariable,
36
+ isLocal: () => import_chunk_5K64MLXC.isLocal,
37
+ isLookupCandidate: () => import_chunk_5K64MLXC.isLookupCandidate,
38
+ isStateNode: () => import_chunk_5K64MLXC.isStateNode,
39
+ lookupByFullName: () => import_chunk_5K64MLXC.lookupByFullName,
40
+ lookupNext: () => import_chunk_5K64MLXC.lookupNext,
41
+ lookupResultContains: () => import_chunk_5K64MLXC.lookupResultContains,
42
+ lookupWithType: () => import_chunk_5K64MLXC.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_5K64MLXC.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_5K64MLXC.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_5K64MLXC.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_5K64MLXC.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_5K64MLXC.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_5K64MLXC.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_5K64MLXC.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_32NRMXAJ.variableDeclarationName,
52
- visitReferences: () => import_chunk_32NRMXAJ.visitReferences,
53
- visit_resources: () => import_chunk_32NRMXAJ.visit_resources,
54
- visitorNode: () => import_chunk_32NRMXAJ.visitorNode
51
+ variableDeclarationName: () => import_chunk_5K64MLXC.variableDeclarationName,
52
+ visitReferences: () => import_chunk_5K64MLXC.visitReferences,
53
+ visit_resources: () => import_chunk_5K64MLXC.visit_resources,
54
+ visitorNode: () => import_chunk_5K64MLXC.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_32NRMXAJ = require("./chunk-32NRMXAJ.cjs");
57
+ var import_chunk_5K64MLXC = require("./chunk-5K64MLXC.cjs");
58
58
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
59
59
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
60
60
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
61
- (0, import_chunk_32NRMXAJ.init_api)();
61
+ (0, import_chunk_5K64MLXC.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  checkCompilerVersion,
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_32NRMXAJ_exports = {};
30
- __export(chunk_32NRMXAJ_exports, {
29
+ var chunk_5K64MLXC_exports = {};
30
+ __export(chunk_5K64MLXC_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -133,7 +133,7 @@ __export(chunk_32NRMXAJ_exports, {
133
133
  visitorNode: () => visitorNode,
134
134
  xml_util_exports: () => xml_util_exports
135
135
  });
136
- module.exports = __toCommonJS(chunk_32NRMXAJ_exports);
136
+ module.exports = __toCommonJS(chunk_5K64MLXC_exports);
137
137
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
138
138
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
139
139
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -5896,7 +5896,11 @@ function shouldInline(state, func, call, context) {
5896
5896
  state,
5897
5897
  func,
5898
5898
  call,
5899
- "This function can only be inlined in statement, assignment, if or return contexts"
5899
+ "This function can only be inlined in statement, assignment, if or return contexts",
5900
+ {
5901
+ uri: "https://github.com/markw65/monkeyc-optimizer/wiki/Inlining#so-inlining-is-restricted-to-a-few-fairly-common-places-or-contexts",
5902
+ message: "contexts"
5903
+ }
5900
5904
  );
5901
5905
  }
5902
5906
  return context != null;
@@ -6128,7 +6132,7 @@ function unused(state, expression, top) {
6128
6132
  }
6129
6133
  return top ? null : [estmt(expression)];
6130
6134
  }
6131
- function inlineDiagnostic(state, func, call, message) {
6135
+ function inlineDiagnostic(state, func, call, message, extra) {
6132
6136
  if (inlineRequested(state, func)) {
6133
6137
  if (!state.inlineDiagnostics) {
6134
6138
  state.inlineDiagnostics = {};
@@ -6138,7 +6142,7 @@ function inlineDiagnostic(state, func, call, message) {
6138
6142
  call,
6139
6143
  message && `While inlining ${func.node.id.name}: ${message}`,
6140
6144
  "INFO",
6141
- void 0
6145
+ extra
6142
6146
  );
6143
6147
  }
6144
6148
  }
@@ -9382,7 +9386,7 @@ function getSystemCallTable(state) {
9382
9386
  returnType.value = value2;
9383
9387
  }
9384
9388
  }
9385
- ret.returnType = { type: 512, value: returnType };
9389
+ ret.returnType = returnType;
9386
9390
  }
9387
9391
  }
9388
9392
  return ret;
@@ -9414,7 +9418,7 @@ function getSystemCallTable(state) {
9414
9418
  returnType.value = value2;
9415
9419
  }
9416
9420
  }
9417
- ret.returnType = { type: 512, value: returnType };
9421
+ ret.returnType = returnType;
9418
9422
  }
9419
9423
  }
9420
9424
  return ret;
@@ -13576,6 +13580,20 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
13576
13580
  case "def": {
13577
13581
  const lval = event.node.type === "UpdateExpression" ? event.node.argument : event.node.type === "AssignmentExpression" ? event.node.left : null;
13578
13582
  if (lval) {
13583
+ if (nodeCopyProp.size && lval.type === "MemberExpression") {
13584
+ let t = lval;
13585
+ while (t.type === "MemberExpression") {
13586
+ t = t.object;
13587
+ }
13588
+ const target = nodeCopyProp.get(t);
13589
+ if (target) {
13590
+ const copyExpr = target.type === "AssignmentExpression" ? target.right : target.type === "VariableDeclarator" ? target.init : null;
13591
+ if (copyExpr?.type === "BinaryExpression") {
13592
+ nodeCopyProp.set(target, false);
13593
+ nodeCopyProp.delete(t);
13594
+ }
13595
+ }
13596
+ }
13579
13597
  if (declIsLocal(event.decl)) {
13580
13598
  if (!istate.localLvals) {
13581
13599
  istate.localLvals = /* @__PURE__ */ new Set();
@@ -17516,7 +17534,7 @@ function visit_resource_refs(state, doc, e) {
17516
17534
  name = name.substring(1);
17517
17535
  loc = (0, import_chunk_MBTLUWXR.adjustLoc)(loc, 1, 0);
17518
17536
  }
17519
- if ((0, import_chunk_MBTLUWXR.hasProperty)(skip, name)) {
17537
+ if ((0, import_chunk_MBTLUWXR.hasProperty)(skip, name) || /^\d+(\.\d+)?%?$/.test(name)) {
17520
17538
  return;
17521
17539
  }
17522
17540
  if (/^([-\w_$]+\s*\.\s*)*[-\w_$]+$/.test(name)) {
@@ -17590,7 +17608,12 @@ function visit_resource_refs(state, doc, e) {
17590
17608
  switch (element.name) {
17591
17609
  case "param":
17592
17610
  if (id === null) {
17593
- parseArg(dotted, l);
17611
+ const name = element.attr.name?.value.value;
17612
+ parseArg(
17613
+ dotted,
17614
+ l,
17615
+ name && (0, import_chunk_MBTLUWXR.hasProperty)(drawableSkips, name) ? drawableSkips[name] : null
17616
+ );
17594
17617
  }
17595
17618
  return;
17596
17619
  case "drawable":
@@ -17628,16 +17651,22 @@ function visit_resource_refs(state, doc, e) {
17628
17651
  });
17629
17652
  const content = doc.textContent(node);
17630
17653
  if (content) {
17631
- stringToScopedName(
17632
- node,
17633
- null,
17634
- content,
17635
- (0, import_chunk_MBTLUWXR.locRange)(
17636
- node.children[0].loc,
17637
- node.children[node.children.length - 1].loc
17638
- )
17639
- );
17640
- return false;
17654
+ switch (node.name) {
17655
+ case "string":
17656
+ case "jsonData":
17657
+ return false;
17658
+ default:
17659
+ stringToScopedName(
17660
+ node,
17661
+ null,
17662
+ content,
17663
+ (0, import_chunk_MBTLUWXR.locRange)(
17664
+ node.children[0].loc,
17665
+ node.children[node.children.length - 1].loc
17666
+ )
17667
+ );
17668
+ return false;
17669
+ }
17641
17670
  }
17642
17671
  return;
17643
17672
  }
@@ -17833,7 +17862,9 @@ var init_resources = (0, import_chunk_ABYVSU2C.__esm)({
17833
17862
  init_sdk_util();
17834
17863
  drawableSkips = {
17835
17864
  x: { center: true, left: true, right: true, start: true },
17865
+ locX: { center: true, left: true, right: true, start: true },
17836
17866
  y: { center: true, top: true, bottom: true, start: true },
17867
+ locY: { center: true, top: true, bottom: true, start: true },
17837
17868
  width: { fill: true },
17838
17869
  height: { fill: true },
17839
17870
  a: { fill: true },
@@ -19763,7 +19794,7 @@ function parseCode(view, lineTable) {
19763
19794
  case 29:
19764
19795
  case 30:
19765
19796
  case 31:
19766
- return { op, offset, size: 1 };
19797
+ return { op, offset };
19767
19798
  case 42:
19768
19799
  case 34:
19769
19800
  case 33:
@@ -19787,7 +19818,7 @@ function parseCode(view, lineTable) {
19787
19818
  case 68:
19788
19819
  case 73:
19789
19820
  case 75:
19790
- return { op, offset, size: 1 };
19821
+ return { op, offset };
19791
19822
  case 1:
19792
19823
  case 15:
19793
19824
  case 18:
@@ -19796,7 +19827,7 @@ function parseCode(view, lineTable) {
19796
19827
  case 46:
19797
19828
  case 53:
19798
19829
  case 56:
19799
- return { op, arg: view.getUint8(current++), offset, size: 2 };
19830
+ return { op, arg: view.getUint8(current++), offset };
19800
19831
  case 25:
19801
19832
  case 35:
19802
19833
  case 40:
@@ -19804,22 +19835,19 @@ function parseCode(view, lineTable) {
19804
19835
  return {
19805
19836
  op,
19806
19837
  arg: offset + view.getInt16((current += 2) - 2) + 3,
19807
- offset,
19808
- size: 3
19838
+ offset
19809
19839
  };
19810
19840
  case 57:
19811
19841
  return {
19812
19842
  op,
19813
19843
  arg: view.getInt16((current += 2) - 2),
19814
- offset,
19815
- size: 3
19844
+ offset
19816
19845
  };
19817
19846
  case 58:
19818
19847
  return {
19819
19848
  op,
19820
19849
  arg: view.getInt32((current += 3) - 3) >> 8,
19821
- offset,
19822
- size: 4
19850
+ offset
19823
19851
  };
19824
19852
  case 24:
19825
19853
  case 64:
@@ -19830,7 +19858,7 @@ function parseCode(view, lineTable) {
19830
19858
  case 52:
19831
19859
  case 71:
19832
19860
  case 67:
19833
- return { op, arg: view.getInt32((current += 4) - 4), offset, size: 5 };
19861
+ return { op, arg: view.getInt32((current += 4) - 4), offset };
19834
19862
  case 69:
19835
19863
  return {
19836
19864
  op,
@@ -19838,8 +19866,7 @@ function parseCode(view, lineTable) {
19838
19866
  module: view.getInt32((current += 4) - 4),
19839
19867
  var: view.getInt32((current += 4) - 4)
19840
19868
  },
19841
- offset,
19842
- size: 9
19869
+ offset
19843
19870
  };
19844
19871
  case 70:
19845
19872
  return {
@@ -19848,8 +19875,7 @@ function parseCode(view, lineTable) {
19848
19875
  local: view.getUint8(current++),
19849
19876
  var: view.getInt32((current += 4) - 4)
19850
19877
  },
19851
- offset,
19852
- size: 6
19878
+ offset
19853
19879
  };
19854
19880
  case 74:
19855
19881
  return {
@@ -19858,29 +19884,25 @@ function parseCode(view, lineTable) {
19858
19884
  argc: view.getUint8(current++),
19859
19885
  incsp: view.getUint8(current++)
19860
19886
  },
19861
- offset,
19862
- size: 3
19887
+ offset
19863
19888
  };
19864
19889
  case 49:
19865
19890
  return {
19866
19891
  op,
19867
19892
  arg: view.getBigInt64((current += 8) - 8),
19868
- offset,
19869
- size: 9
19893
+ offset
19870
19894
  };
19871
19895
  case 38:
19872
19896
  return {
19873
19897
  op,
19874
19898
  arg: view.getFloat32((current += 4) - 4),
19875
- offset,
19876
- size: 5
19899
+ offset
19877
19900
  };
19878
19901
  case 50:
19879
19902
  return {
19880
19903
  op,
19881
19904
  arg: view.getFloat64((current += 8) - 8),
19882
- offset,
19883
- size: 9
19905
+ offset
19884
19906
  };
19885
19907
  case 36:
19886
19908
  throw new Error(`Unknown opcode ${op}`);
@@ -19897,7 +19919,7 @@ function parseCode(view, lineTable) {
19897
19919
  }
19898
19920
  results.push(nextOp);
19899
19921
  }
19900
- results.push({ op: 0, size: 1, offset: current });
19922
+ results.push({ op: 0, offset: current });
19901
19923
  return results;
19902
19924
  }
19903
19925
  function opcodeSize(op) {
@@ -19946,6 +19968,8 @@ function opcodeSize(op) {
19946
19968
  case 68:
19947
19969
  case 73:
19948
19970
  case 75:
19971
+ case 10:
19972
+ case 11:
19949
19973
  return 1;
19950
19974
  case 1:
19951
19975
  case 15:
@@ -19954,8 +19978,6 @@ function opcodeSize(op) {
19954
19978
  case 43:
19955
19979
  case 46:
19956
19980
  case 53:
19957
- case 10:
19958
- case 11:
19959
19981
  case 56:
19960
19982
  return 2;
19961
19983
  case 25:
@@ -21192,6 +21214,8 @@ function interpFunc(func, context) {
21192
21214
  break;
21193
21215
  }
21194
21216
  case 37:
21217
+ case 57:
21218
+ case 58:
21195
21219
  case 49:
21196
21220
  case 38:
21197
21221
  case 50:
@@ -21213,7 +21237,6 @@ function interpFunc(func, context) {
21213
21237
  op: 46,
21214
21238
  arg,
21215
21239
  offset: bc.offset,
21216
- size: 2,
21217
21240
  invert: localState.stack.length <= ~index
21218
21241
  });
21219
21242
  } else {
@@ -21222,7 +21245,6 @@ function interpFunc(func, context) {
21222
21245
  op: 18,
21223
21246
  arg,
21224
21247
  offset: bc.offset,
21225
- size: 2,
21226
21248
  invert: localState.locals.length <= index
21227
21249
  });
21228
21250
  }
@@ -21401,11 +21423,9 @@ function interpFunc(func, context) {
21401
21423
  } else {
21402
21424
  delete orig.arg;
21403
21425
  }
21404
- orig.size = rep.size;
21405
21426
  if (rep.invert) {
21406
21427
  const invv = { ...orig };
21407
21428
  invv.op = 45;
21408
- invv.size = 1;
21409
21429
  invv.offset = context.nextOffset++;
21410
21430
  delete invv.arg;
21411
21431
  block.bytecodes.splice(i + 1, 0, invv);
@@ -21435,7 +21455,6 @@ function interpFunc(func, context) {
21435
21455
  for (let i = 0; i < pops; i++) {
21436
21456
  block.bytecodes.push({
21437
21457
  op: 2,
21438
- size: 1,
21439
21458
  offset: context.nextOffset++
21440
21459
  });
21441
21460
  }
@@ -21454,29 +21473,27 @@ function instForType(type, offset) {
21454
21473
  return null;
21455
21474
  switch (type.type) {
21456
21475
  case 1:
21457
- return { op: 44, offset, size: 1 };
21476
+ return { op: 44, offset };
21458
21477
  case 2:
21459
21478
  case 4:
21460
21479
  return {
21461
21480
  op: 43,
21462
21481
  arg: type.type === 2 ? 0 : 1,
21463
- offset,
21464
- size: 2
21482
+ offset
21465
21483
  };
21466
21484
  case 8:
21467
- return { op: 37, arg: type.value, offset, size: 5 };
21485
+ return { op: 37, arg: type.value, offset };
21468
21486
  case 16:
21469
- return { op: 49, arg: type.value, offset, size: 9 };
21487
+ return { op: 49, arg: type.value, offset };
21470
21488
  case 32:
21471
- return { op: 38, arg: type.value, offset, size: 5 };
21489
+ return { op: 38, arg: type.value, offset };
21472
21490
  case 64:
21473
- return { op: 50, arg: type.value, offset, size: 9 };
21491
+ return { op: 50, arg: type.value, offset };
21474
21492
  case 128:
21475
21493
  return {
21476
21494
  op: 52,
21477
21495
  arg: type.value.charCodeAt(0),
21478
- offset,
21479
- size: 5
21496
+ offset
21480
21497
  };
21481
21498
  case 131072: {
21482
21499
  const match = type.value.match(/<(\d+)>$/);
@@ -21484,8 +21501,7 @@ function instForType(type, offset) {
21484
21501
  return {
21485
21502
  op: 39,
21486
21503
  arg: parseInt(match[1], 10),
21487
- offset,
21488
- size: 5
21504
+ offset
21489
21505
  };
21490
21506
  }
21491
21507
  }
@@ -21591,7 +21607,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
21591
21607
  }
21592
21608
  if (initType) {
21593
21609
  const bc = block.bytecodes[found - 1];
21594
- if (bc.op !== 46 && (!initInst || initInst.size > bc.size)) {
21610
+ if (bc.op !== 46 && (!initInst || opcodeSize(initInst.op) > opcodeSize(bc.op))) {
21595
21611
  const { push, pop } = getOpInfo(bc);
21596
21612
  if (push === 1 && pop === 0) {
21597
21613
  initInst = bc;
@@ -21625,7 +21641,6 @@ function optimizeArrayInit(func, block, index, context, interpState) {
21625
21641
  const bc = block.bytecodes[i2];
21626
21642
  const op = bc.op;
21627
21643
  bc.op = 2;
21628
- bc.size = 1;
21629
21644
  delete bc.arg;
21630
21645
  (0, import_node_assert8.default)(
21631
21646
  op === 17
@@ -21688,7 +21703,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
21688
21703
  } else {
21689
21704
  initInst = null;
21690
21705
  }
21691
- if (initLocal && (!initInst || initInst.size > initLocal.size)) {
21706
+ if (initLocal && (!initInst || opcodeSize(initInst.op) > opcodeSize(initLocal.op))) {
21692
21707
  initInst = initLocal;
21693
21708
  }
21694
21709
  if (initInst) {
@@ -22279,7 +22294,6 @@ function minimizeLocals2(func, equivSets, context) {
22279
22294
  const argCount = bc;
22280
22295
  argCount.op = 53;
22281
22296
  argCount.arg = argc;
22282
- argCount.size = 2;
22283
22297
  filter = true;
22284
22298
  }
22285
22299
  break;
@@ -22300,7 +22314,6 @@ function minimizeLocals2(func, equivSets, context) {
22300
22314
  const nop = bc;
22301
22315
  nop.op = 0;
22302
22316
  delete nop.arg;
22303
- nop.size = 1;
22304
22317
  filter = true;
22305
22318
  }
22306
22319
  break;
@@ -22544,11 +22557,17 @@ function sizeBasedPRE2(func, context) {
22544
22557
  view.setFloat32(0, bc.arg);
22545
22558
  return BigInt(view.getInt32(0)) << 8n | BigInt(bc.op);
22546
22559
  }
22560
+ case 37:
22561
+ case 57:
22562
+ case 58:
22563
+ return BigInt(bc.arg) << 8n | BigInt(
22564
+ 37
22565
+ /* ipush */
22566
+ );
22547
22567
  case 39:
22548
22568
  if (bcs[index + 1]?.op === 48) {
22549
22569
  break;
22550
22570
  }
22551
- case 37:
22552
22571
  case 49:
22553
22572
  case 52:
22554
22573
  case 24:
@@ -22673,7 +22692,6 @@ function sizeBasedPRE2(func, context) {
22673
22692
  bc2.op = 0;
22674
22693
  prev.op = 18;
22675
22694
  prev.arg = slot;
22676
- prev.size = 2;
22677
22695
  }
22678
22696
  })
22679
22697
  );
@@ -22698,7 +22716,6 @@ function sizeBasedPRE2(func, context) {
22698
22716
  bcs.forEach((bc2) => {
22699
22717
  bc2.op = 18;
22700
22718
  bc2.arg = slot;
22701
- bc2.size = 2;
22702
22719
  });
22703
22720
  }
22704
22721
  });
@@ -22763,7 +22780,7 @@ function blockSharing(func, context) {
22763
22780
  blocks.forEach((block) => {
22764
22781
  const blockEnd = block.bytecodes[block.bytecodes.length - 1];
22765
22782
  if (!group.length) {
22766
- size = blockEnd.size;
22783
+ size = opcodeSize(blockEnd.op);
22767
22784
  } else {
22768
22785
  const key = group[0];
22769
22786
  const keyEnd = key.bytecodes[key.bytecodes.length - 1];
@@ -22832,7 +22849,7 @@ function blockSharing(func, context) {
22832
22849
  }
22833
22850
  entry.group.delete(block);
22834
22851
  } else {
22835
- const sz = size2 + (bc?.size ?? 0);
22852
+ const sz = size2 + (bc ? opcodeSize(bc.op) : 0);
22836
22853
  nextState.push({ group: blocks2.map((b) => group2[b]), size: sz });
22837
22854
  }
22838
22855
  });
@@ -23014,11 +23031,9 @@ function simpleOpts(func, context) {
23014
23031
  const dup = prev;
23015
23032
  dup.op = 46;
23016
23033
  dup.arg = 0;
23017
- dup.size = 2;
23018
23034
  const add = cur;
23019
23035
  add.op = 3;
23020
23036
  delete add.arg;
23021
- add.size = 1;
23022
23037
  logging3 && (0, import_chunk_SG7ODKRM.log)(`${func.name}: converting "ipush 1; shlv" to "dup 0; addv"`);
23023
23038
  continue;
23024
23039
  }
@@ -23035,7 +23050,6 @@ function simpleOpts(func, context) {
23035
23050
  changes = true;
23036
23051
  const mulv = cur;
23037
23052
  mulv.op = 5;
23038
- mulv.size = 1;
23039
23053
  delete mulv.arg;
23040
23054
  }
23041
23055
  }
@@ -23127,8 +23141,7 @@ function equalSymbolToEq(block, equalsIndex) {
23127
23141
  }
23128
23142
  block.bytecodes.splice(equalsIndex, 5, spush, {
23129
23143
  op: 26,
23130
- offset: invokem.offset,
23131
- size: 1
23144
+ offset: invokem.offset
23132
23145
  });
23133
23146
  (0, import_chunk_SG7ODKRM.logger)(
23134
23147
  "optimize",
@@ -23212,7 +23225,7 @@ function removeUnreachableCatches(func, context) {
23212
23225
  }
23213
23226
  delete next.preds;
23214
23227
  removeBlock(func, next.offset);
23215
- } else if (next.next == null && next.bytecodes.length < 3 && next.bytecodes.reduce((size, bc) => size + bc.size, 0) < 3 && countFallthroughPreds(func, next) > 1) {
23228
+ } else if (next.next == null && next.bytecodes.length < 3 && next.bytecodes.reduce((size, bc) => size + opcodeSize(bc.op), 0) < 3 && countFallthroughPreds(func, next) > 1) {
23216
23229
  (0, import_chunk_SG7ODKRM.logger)(
23217
23230
  "cfg",
23218
23231
  1,
@@ -23226,7 +23239,7 @@ function removeUnreachableCatches(func, context) {
23226
23239
  let offset = context.nextOffset;
23227
23240
  next.bytecodes.forEach((bc) => {
23228
23241
  block.bytecodes.push({ ...bc, offset });
23229
- offset += bc.size;
23242
+ offset += opcodeSize(bc.op);
23230
23243
  });
23231
23244
  context.nextOffset = offset;
23232
23245
  redirect(func, block, next.offset, null);
@@ -23415,8 +23428,7 @@ function emitFunc(func, view, start, updateInfo, context) {
23415
23428
  const bc = {
23416
23429
  op: 25,
23417
23430
  arg: block.next,
23418
- offset: block.offset,
23419
- size: 3
23431
+ offset: block.offset
23420
23432
  };
23421
23433
  offset = emitBytecode(bc, view, offset, linktable, shift_hack);
23422
23434
  }
@@ -24162,6 +24174,9 @@ function bytecodeToString(bytecode, symbolTable) {
24162
24174
  }
24163
24175
  return `${Opcodes[bytecode.op]}${arg ?? ""}`;
24164
24176
  }
24177
+ function offsetAfter(bc) {
24178
+ return bc.offset + opcodeSize(bc.op);
24179
+ }
24165
24180
  function findFunctions({
24166
24181
  bytecodes,
24167
24182
  symbolTable,
@@ -24181,13 +24196,13 @@ function findFunctions({
24181
24196
  case 41:
24182
24197
  case 25:
24183
24198
  case 35:
24184
- blockStarts.add(bytecode.offset + bytecode.size);
24199
+ blockStarts.add(offsetAfter(bytecode));
24185
24200
  blockStarts.add(bytecode.arg);
24186
24201
  return;
24187
24202
  case 22:
24188
24203
  case 23:
24189
24204
  case 51:
24190
- blockStarts.add(bytecode.offset + bytecode.size);
24205
+ blockStarts.add(offsetAfter(bytecode));
24191
24206
  return;
24192
24207
  }
24193
24208
  });
@@ -24198,7 +24213,7 @@ function findFunctions({
24198
24213
  let next;
24199
24214
  let taken;
24200
24215
  bytecodes.forEach((bytecode, i) => {
24201
- const nextBcOffset = bytecode.offset + bytecode.size;
24216
+ const nextBcOffset = offsetAfter(bytecode);
24202
24217
  next = nextBcOffset;
24203
24218
  taken = void 0;
24204
24219
  switch (bytecode.op) {
@@ -24328,7 +24343,6 @@ function findFunctions({
24328
24343
  function makeArgless(bc, op) {
24329
24344
  bc.op = op;
24330
24345
  delete bc.arg;
24331
- bc.size = 1;
24332
24346
  }
24333
24347
  function removeBlock(func, offset) {
24334
24348
  const block = func.blocks.get(offset);
@@ -28367,7 +28381,7 @@ async function launchSimulator(force = true) {
28367
28381
  for (let i = 0; ; i++) {
28368
28382
  if (await checkIfSimulatorRunning())
28369
28383
  return;
28370
- if (i === 10)
28384
+ if (i === 25)
28371
28385
  return;
28372
28386
  await new Promise((r) => setTimeout(r, 200));
28373
28387
  }
@@ -28969,7 +28983,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28969
28983
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
28970
28984
  Object.values(fnMap).map((v) => v.output)
28971
28985
  );
28972
- if (source_time < opt_time && 1712549362694 < opt_time) {
28986
+ if (source_time < opt_time && 1713154555665 < opt_time) {
28973
28987
  return {
28974
28988
  hasTests,
28975
28989
  diagnostics: prevDiagnostics,
@@ -29008,7 +29022,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29008
29022
  hasTests: hasTests2,
29009
29023
  diagnostics,
29010
29024
  sdkVersion,
29011
- optimizerVersion: "1.1.53",
29025
+ optimizerVersion: "1.1.54",
29012
29026
  ...Object.fromEntries(
29013
29027
  configOptionsToCheck.map((option) => [option, config[option]])
29014
29028
  )
@@ -29505,7 +29519,7 @@ function optimizeProgramBuffer(filepath, view, debugXml, apiDebugXml, key, confi
29505
29519
  exceptionsMap,
29506
29520
  key,
29507
29521
  debugXml,
29508
- nextOffset: (bytecodes[bytecodes.length - 1]?.offset ?? 0) + (bytecodes[bytecodes.length - 1]?.size ?? 0),
29522
+ nextOffset: bytecodes[bytecodes.length - 1] ? offsetAfter(bytecodes[bytecodes.length - 1]) : 0,
29509
29523
  nextLocalId: 0
29510
29524
  };
29511
29525
  optimizeBytecode(context);
@@ -18,28 +18,28 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_32NRMXAJ.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_32NRMXAJ.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_5K64MLXC.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_5K64MLXC.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_32NRMXAJ.defaultConfig,
25
- display: () => import_chunk_32NRMXAJ.display,
26
- generateOneConfig: () => import_chunk_32NRMXAJ.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_32NRMXAJ.generateOptimizedProject,
28
- getConfig: () => import_chunk_32NRMXAJ.getConfig,
29
- getProjectAnalysis: () => import_chunk_32NRMXAJ.getProjectAnalysis,
30
- get_jungle: () => import_chunk_32NRMXAJ.get_jungle,
31
- isErrorWithLocation: () => import_chunk_32NRMXAJ.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_32NRMXAJ.launchSimulator,
33
- manifestProducts: () => import_chunk_32NRMXAJ.manifestProducts,
34
- mctree: () => import_chunk_32NRMXAJ.mctree,
35
- simulateProgram: () => import_chunk_32NRMXAJ.simulateProgram
24
+ defaultConfig: () => import_chunk_5K64MLXC.defaultConfig,
25
+ display: () => import_chunk_5K64MLXC.display,
26
+ generateOneConfig: () => import_chunk_5K64MLXC.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_5K64MLXC.generateOptimizedProject,
28
+ getConfig: () => import_chunk_5K64MLXC.getConfig,
29
+ getProjectAnalysis: () => import_chunk_5K64MLXC.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_5K64MLXC.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_5K64MLXC.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_5K64MLXC.launchSimulator,
33
+ manifestProducts: () => import_chunk_5K64MLXC.manifestProducts,
34
+ mctree: () => import_chunk_5K64MLXC.mctree,
35
+ simulateProgram: () => import_chunk_5K64MLXC.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_32NRMXAJ = require("./chunk-32NRMXAJ.cjs");
38
+ var import_chunk_5K64MLXC = require("./chunk-5K64MLXC.cjs");
39
39
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
40
40
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
41
41
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
42
- (0, import_chunk_32NRMXAJ.init_optimizer)();
42
+ (0, import_chunk_5K64MLXC.init_optimizer)();
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
45
45
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_32NRMXAJ.SectionKinds,
22
- appSupport: () => import_chunk_32NRMXAJ.appSupport,
23
- connectiq: () => import_chunk_32NRMXAJ.connectiq,
24
- getDeviceInfo: () => import_chunk_32NRMXAJ.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_32NRMXAJ.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_32NRMXAJ.getLanguages,
27
- getSdkPath: () => import_chunk_32NRMXAJ.getSdkPath,
28
- isWin: () => import_chunk_32NRMXAJ.isWin,
29
- optimizeProgram: () => import_chunk_32NRMXAJ.optimizeProgram,
30
- readPrg: () => import_chunk_32NRMXAJ.readPrg,
31
- readPrgWithOffsets: () => import_chunk_32NRMXAJ.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_32NRMXAJ.xml_util_exports
21
+ SectionKinds: () => import_chunk_5K64MLXC.SectionKinds,
22
+ appSupport: () => import_chunk_5K64MLXC.appSupport,
23
+ connectiq: () => import_chunk_5K64MLXC.connectiq,
24
+ getDeviceInfo: () => import_chunk_5K64MLXC.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_5K64MLXC.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_5K64MLXC.getLanguages,
27
+ getSdkPath: () => import_chunk_5K64MLXC.getSdkPath,
28
+ isWin: () => import_chunk_5K64MLXC.isWin,
29
+ optimizeProgram: () => import_chunk_5K64MLXC.optimizeProgram,
30
+ readPrg: () => import_chunk_5K64MLXC.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_5K64MLXC.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_5K64MLXC.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_32NRMXAJ = require("./chunk-32NRMXAJ.cjs");
35
+ var import_chunk_5K64MLXC = require("./chunk-5K64MLXC.cjs");
36
36
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
37
37
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_32NRMXAJ.init_sdk_util)();
39
+ (0, import_chunk_5K64MLXC.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -1,12 +1,12 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
2
+ import { Diagnostic, FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
3
3
  export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
4
4
  export declare function inlineRequested(state: ProgramStateAnalysis, func: FunctionStateNode): boolean;
5
5
  export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
6
6
  type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
7
7
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
8
8
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
9
- export declare function inlineDiagnostic(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, message: string | null): void;
9
+ export declare function inlineDiagnostic(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, message: string | null, extra?: Diagnostic["extra"]): void;
10
10
  export type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
11
11
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
12
12
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -62,6 +62,7 @@ export declare function functionToString(func: FuncEntry, context: Context | nul
62
62
  export declare function blockToString(block: Block, context: Context | null): string;
63
63
  export declare function lineInfoToString(lineInfo: LineNumber, context: Context | null): string;
64
64
  export declare function bytecodeToString(bytecode: Bytecode, symbolTable: SymbolTable | null | undefined): string;
65
+ export declare function offsetAfter(bc: Bytecode): number;
65
66
  export declare function findFunctions({ bytecodes, symbolTable, exceptionsMap, }: Context): Map<number, FuncEntry>;
66
67
  export declare function makeArgless(bc: Bytecode, op: Opcodes): void;
67
68
  export declare function equalBlocks(b1: Block, b2: Block): boolean;
@@ -80,7 +80,6 @@ export declare enum Opcodes {
80
80
  interface BaseOpcode {
81
81
  op: Opcodes;
82
82
  offset: number;
83
- size: number;
84
83
  lineNum?: LineNumber;
85
84
  arg?: unknown;
86
85
  }
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_32NRMXAJ = require("./chunk-32NRMXAJ.cjs");
24
+ var import_chunk_5K64MLXC = require("./chunk-5K64MLXC.cjs");
25
25
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_32NRMXAJ.init_worker_task)();
31
+ (0, import_chunk_5K64MLXC.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_32NRMXAJ.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_5K64MLXC.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.53",
4
+ "version": "1.1.54",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",