@markw65/monkeyc-optimizer 1.1.32 → 1.1.34

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.
Files changed (81) hide show
  1. package/README.md +1 -918
  2. package/build/api.cjs +31 -31
  3. package/build/{chunk-NUE3G2QE.cjs → chunk-QBCVUVLD.cjs} +180 -49
  4. package/build/optimizer.cjs +17 -17
  5. package/build/sdk-util.cjs +14 -14
  6. package/build/src/api.d.ts +1 -1
  7. package/build/src/projects.d.ts +1 -0
  8. package/build/src/readprg.d.ts +0 -6
  9. package/build/src/src/api.d.ts +51 -0
  10. package/build/src/src/ast.d.ts +59 -0
  11. package/build/src/src/build.d.ts +7 -0
  12. package/build/src/src/cftinfo.d.ts +32 -0
  13. package/build/src/src/control-flow.d.ts +22 -0
  14. package/build/src/src/data-flow.d.ts +107 -0
  15. package/build/src/src/driver.d.ts +2 -0
  16. package/build/src/src/function-info.d.ts +14 -0
  17. package/build/src/src/inliner.d.ts +13 -0
  18. package/build/src/src/jungles.d.ts +66 -0
  19. package/build/src/src/launch.d.ts +5 -0
  20. package/build/src/src/logger.d.ts +6 -0
  21. package/build/src/src/manifest.d.ts +11 -0
  22. package/build/src/src/mc-rewrite.d.ts +13 -0
  23. package/build/src/src/negative-fixups.d.ts +1 -0
  24. package/build/src/src/optimizer-types.d.ts +249 -0
  25. package/build/src/src/optimizer.d.ts +100 -0
  26. package/build/src/src/pragma-checker.d.ts +3 -0
  27. package/build/src/src/pre.d.ts +2 -0
  28. package/build/src/src/projects.d.ts +26 -0
  29. package/build/src/src/readprg/array-init.d.ts +3 -0
  30. package/build/src/src/readprg/bytecode.d.ts +72 -0
  31. package/build/src/src/readprg/cflow.d.ts +17 -0
  32. package/build/src/src/readprg/data.d.ts +4 -0
  33. package/build/src/src/readprg/dce.d.ts +6 -0
  34. package/build/src/src/readprg/emit.d.ts +23 -0
  35. package/build/src/src/readprg/exceptions.d.ts +10 -0
  36. package/build/src/src/readprg/header.d.ts +15 -0
  37. package/build/src/src/readprg/interp.d.ts +21 -0
  38. package/build/src/src/readprg/linenum.d.ts +29 -0
  39. package/build/src/src/readprg/locals.d.ts +3 -0
  40. package/build/src/src/readprg/opcodes.d.ts +279 -0
  41. package/build/src/src/readprg/optimize.d.ts +3 -0
  42. package/build/src/src/readprg/pre.d.ts +2 -0
  43. package/build/src/src/readprg/sharing.d.ts +2 -0
  44. package/build/src/src/readprg/signer.d.ts +8 -0
  45. package/build/src/src/readprg/symbols.d.ts +19 -0
  46. package/build/src/src/readprg.d.ts +25 -0
  47. package/build/src/src/resources.d.ts +12 -0
  48. package/build/src/src/sdk-util.d.ts +28 -0
  49. package/build/src/src/type-flow/could-be.d.ts +5 -0
  50. package/build/src/src/type-flow/dead-store.d.ts +18 -0
  51. package/build/src/src/type-flow/interp-binary.d.ts +4 -0
  52. package/build/src/src/type-flow/interp-call.d.ts +16 -0
  53. package/build/src/src/type-flow/interp.d.ts +33 -0
  54. package/build/src/src/type-flow/intersection-type.d.ts +4 -0
  55. package/build/src/src/type-flow/minimize-locals.d.ts +4 -0
  56. package/build/src/src/type-flow/minimize-modules.d.ts +3 -0
  57. package/build/src/src/type-flow/optimize.d.ts +7 -0
  58. package/build/src/src/type-flow/sub-type.d.ts +2 -0
  59. package/build/src/src/type-flow/type-flow-util.d.ts +27 -0
  60. package/build/src/src/type-flow/types.d.ts +204 -0
  61. package/build/src/src/type-flow/union-type.d.ts +4 -0
  62. package/build/src/src/type-flow.d.ts +18 -0
  63. package/build/src/src/unused-exprs.d.ts +3 -0
  64. package/build/src/src/util.d.ts +33 -0
  65. package/build/src/src/variable-renamer.d.ts +4 -0
  66. package/build/src/src/visitor.d.ts +5 -0
  67. package/build/src/src/worker-pool.d.ts +4 -0
  68. package/build/src/src/worker-task.d.ts +88 -0
  69. package/build/src/src/worker-thread.d.ts +1 -0
  70. package/build/src/src/xml-util.d.ts +172 -0
  71. package/build/src/test/mocha/bytecode.spec.d.ts +1 -0
  72. package/build/src/test/mocha/coudbe.spec.d.ts +2 -0
  73. package/build/src/test/mocha/intersection.spec.d.ts +2 -0
  74. package/build/src/test/mocha/root.spec.d.ts +1 -0
  75. package/build/src/test/mocha/subtype.spec.d.ts +2 -0
  76. package/build/src/test/mocha/test-utils.d.ts +6 -0
  77. package/build/src/test/mocha/types.spec.d.ts +1 -0
  78. package/build/src/type-flow/interp.d.ts +3 -1
  79. package/build/src/type-flow/types.d.ts +1 -1
  80. package/build/worker-thread.cjs +3 -3
  81. package/package.json +2 -2
package/build/api.cjs CHANGED
@@ -18,44 +18,44 @@ 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_NUE3G2QE.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_NUE3G2QE.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_NUE3G2QE.createDocumentationMap,
24
- diagnostic: () => import_chunk_NUE3G2QE.diagnostic,
25
- diagnosticHelper: () => import_chunk_NUE3G2QE.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_NUE3G2QE.findNamesInScope,
27
- findUsingForNode: () => import_chunk_NUE3G2QE.findUsingForNode,
28
- formatAst: () => import_chunk_NUE3G2QE.formatAst,
29
- formatAstLongLines: () => import_chunk_NUE3G2QE.formatAstLongLines,
30
- getApiFunctionInfo: () => import_chunk_NUE3G2QE.getApiFunctionInfo,
31
- getApiMapping: () => import_chunk_NUE3G2QE.getApiMapping,
32
- getSuperClasses: () => import_chunk_NUE3G2QE.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_QBCVUVLD.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_QBCVUVLD.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_QBCVUVLD.createDocumentationMap,
24
+ diagnostic: () => import_chunk_QBCVUVLD.diagnostic,
25
+ diagnosticHelper: () => import_chunk_QBCVUVLD.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_QBCVUVLD.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_QBCVUVLD.findUsingForNode,
28
+ formatAst: () => import_chunk_QBCVUVLD.formatAst,
29
+ formatAstLongLines: () => import_chunk_QBCVUVLD.formatAstLongLines,
30
+ getApiFunctionInfo: () => import_chunk_QBCVUVLD.getApiFunctionInfo,
31
+ getApiMapping: () => import_chunk_QBCVUVLD.getApiMapping,
32
+ getSuperClasses: () => import_chunk_QBCVUVLD.getSuperClasses,
33
33
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
34
- isClassVariable: () => import_chunk_NUE3G2QE.isClassVariable,
35
- isLocal: () => import_chunk_NUE3G2QE.isLocal,
36
- isLookupCandidate: () => import_chunk_NUE3G2QE.isLookupCandidate,
37
- isStateNode: () => import_chunk_NUE3G2QE.isStateNode,
38
- lookupByFullName: () => import_chunk_NUE3G2QE.lookupByFullName,
39
- lookupNext: () => import_chunk_NUE3G2QE.lookupNext,
40
- lookupResultContains: () => import_chunk_NUE3G2QE.lookupResultContains,
41
- lookupWithType: () => import_chunk_NUE3G2QE.lookupWithType,
42
- makeToyboxLink: () => import_chunk_NUE3G2QE.makeToyboxLink,
43
- mapVarDeclsByType: () => import_chunk_NUE3G2QE.mapVarDeclsByType,
44
- markInvokeClassMethod: () => import_chunk_NUE3G2QE.markInvokeClassMethod,
45
- parseSdkVersion: () => import_chunk_NUE3G2QE.parseSdkVersion,
46
- sameLookupResult: () => import_chunk_NUE3G2QE.sameLookupResult,
34
+ isClassVariable: () => import_chunk_QBCVUVLD.isClassVariable,
35
+ isLocal: () => import_chunk_QBCVUVLD.isLocal,
36
+ isLookupCandidate: () => import_chunk_QBCVUVLD.isLookupCandidate,
37
+ isStateNode: () => import_chunk_QBCVUVLD.isStateNode,
38
+ lookupByFullName: () => import_chunk_QBCVUVLD.lookupByFullName,
39
+ lookupNext: () => import_chunk_QBCVUVLD.lookupNext,
40
+ lookupResultContains: () => import_chunk_QBCVUVLD.lookupResultContains,
41
+ lookupWithType: () => import_chunk_QBCVUVLD.lookupWithType,
42
+ makeToyboxLink: () => import_chunk_QBCVUVLD.makeToyboxLink,
43
+ mapVarDeclsByType: () => import_chunk_QBCVUVLD.mapVarDeclsByType,
44
+ markInvokeClassMethod: () => import_chunk_QBCVUVLD.markInvokeClassMethod,
45
+ parseSdkVersion: () => import_chunk_QBCVUVLD.parseSdkVersion,
46
+ sameLookupResult: () => import_chunk_QBCVUVLD.sameLookupResult,
47
47
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
48
- variableDeclarationName: () => import_chunk_NUE3G2QE.variableDeclarationName,
49
- visitReferences: () => import_chunk_NUE3G2QE.visitReferences,
50
- visit_resources: () => import_chunk_NUE3G2QE.visit_resources,
51
- visitorNode: () => import_chunk_NUE3G2QE.visitorNode
48
+ variableDeclarationName: () => import_chunk_QBCVUVLD.variableDeclarationName,
49
+ visitReferences: () => import_chunk_QBCVUVLD.visitReferences,
50
+ visit_resources: () => import_chunk_QBCVUVLD.visit_resources,
51
+ visitorNode: () => import_chunk_QBCVUVLD.visitorNode
52
52
  });
53
53
  module.exports = __toCommonJS(api_exports);
54
- var import_chunk_NUE3G2QE = require("./chunk-NUE3G2QE.cjs");
54
+ var import_chunk_QBCVUVLD = require("./chunk-QBCVUVLD.cjs");
55
55
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.cjs");
56
56
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
57
57
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
58
- (0, import_chunk_NUE3G2QE.init_api)();
58
+ (0, import_chunk_QBCVUVLD.init_api)();
59
59
  // Annotate the CommonJS export names for ESM import in node:
60
60
  0 && (module.exports = {
61
61
  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_NUE3G2QE_exports = {};
30
- __export(chunk_NUE3G2QE_exports, {
29
+ var chunk_QBCVUVLD_exports = {};
30
+ __export(chunk_QBCVUVLD_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -122,7 +122,7 @@ __export(chunk_NUE3G2QE_exports, {
122
122
  visitorNode: () => visitorNode,
123
123
  xml_util_exports: () => xml_util_exports
124
124
  });
125
- module.exports = __toCommonJS(chunk_NUE3G2QE_exports);
125
+ module.exports = __toCommonJS(chunk_QBCVUVLD_exports);
126
126
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.cjs");
127
127
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
128
128
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -11724,19 +11724,70 @@ function getLhsConstraint(istate, node) {
11724
11724
  throw new Error("Checking types without a typeMap");
11725
11725
  }
11726
11726
  const object = istate.typeMap.get(node.object);
11727
- if (object && !node.computed) {
11728
- const [, trueDecls2] = findObjectDeclsByProperty(
11729
- istate.state,
11730
- object,
11731
- node
11732
- );
11733
- if (trueDecls2) {
11734
- lookupDefs = lookupNext(
11727
+ if (object) {
11728
+ if (node.computed) {
11729
+ if (object.value) {
11730
+ let result = null;
11731
+ if (object.type & 512) {
11732
+ const arr = getUnionComponent(
11733
+ object,
11734
+ 512
11735
+ /* Array */
11736
+ );
11737
+ if (arr) {
11738
+ result = arr;
11739
+ }
11740
+ }
11741
+ if (object.type & 1024) {
11742
+ const dict = getUnionComponent(
11743
+ object,
11744
+ 1024
11745
+ /* Dictionary */
11746
+ );
11747
+ if (dict) {
11748
+ if (result) {
11749
+ result = cloneType(result);
11750
+ unionInto(result, dict.value);
11751
+ } else {
11752
+ result = dict.value;
11753
+ }
11754
+ }
11755
+ }
11756
+ if (object.type & 32768) {
11757
+ const obj = getUnionComponent(
11758
+ object,
11759
+ 32768
11760
+ /* Object */
11761
+ );
11762
+ if (obj && isByteArrayData(obj)) {
11763
+ const t = {
11764
+ type: 8 | 128
11765
+ /* Char */
11766
+ };
11767
+ if (result) {
11768
+ unionInto(t, result);
11769
+ }
11770
+ result = t;
11771
+ }
11772
+ }
11773
+ if (result) {
11774
+ return result;
11775
+ }
11776
+ }
11777
+ } else {
11778
+ const [, trueDecls2] = findObjectDeclsByProperty(
11735
11779
  istate.state,
11736
- [{ parent: null, results: trueDecls2 }],
11737
- "decls",
11738
- node.property
11780
+ object,
11781
+ node
11739
11782
  );
11783
+ if (trueDecls2) {
11784
+ lookupDefs = lookupNext(
11785
+ istate.state,
11786
+ [{ parent: null, results: trueDecls2 }],
11787
+ "decls",
11788
+ node.property
11789
+ );
11790
+ }
11740
11791
  }
11741
11792
  }
11742
11793
  }
@@ -11842,7 +11893,10 @@ function evaluateNode(istate, node) {
11842
11893
  });
11843
11894
  return;
11844
11895
  }
11845
- if (istate.checkTypes && !couldBe(left.value, right.value)) {
11896
+ if (istate.checkTypes && !couldBe(left.value, right.value) && !subtypeOf({
11897
+ type: 1 | 32768
11898
+ /* Object */
11899
+ }, right.value)) {
11846
11900
  diagnostic(
11847
11901
  istate.state,
11848
11902
  node,
@@ -12077,26 +12131,39 @@ function evaluateNode(istate, node) {
12077
12131
  if (!isLookupCandidate(node)) {
12078
12132
  const property = popIstate(istate, node.property);
12079
12133
  const object = popIstate(istate, node.object);
12080
- if (hasValue(object.value) && object.value.type === 512 && property.value.type & (8 | 16)) {
12081
- push({
12082
- value: object.value.value,
12083
- embeddedEffects: object.embeddedEffects || property.embeddedEffects,
12084
- node
12085
- });
12086
- break;
12087
- }
12088
- if (hasValue(object.value) && object.value.type === 1024 && property.value.type & object.value.value.key.type) {
12089
- const value2 = {
12090
- type: 1
12091
- /* Null */
12092
- };
12093
- unionInto(value2, object.value.value.value);
12094
- push({
12095
- value: value2,
12096
- embeddedEffects: object.embeddedEffects || property.embeddedEffects,
12097
- node
12098
- });
12099
- break;
12134
+ if (hasValue(object.value)) {
12135
+ if (object.value.type === 512 && property.value.type & (8 | 16)) {
12136
+ push({
12137
+ value: object.value.value,
12138
+ embeddedEffects: object.embeddedEffects || property.embeddedEffects,
12139
+ node
12140
+ });
12141
+ break;
12142
+ }
12143
+ if (object.value.type === 1024 && property.value.type & object.value.value.key.type) {
12144
+ const value2 = {
12145
+ type: 1
12146
+ /* Null */
12147
+ };
12148
+ unionInto(value2, object.value.value.value);
12149
+ push({
12150
+ value: value2,
12151
+ embeddedEffects: object.embeddedEffects || property.embeddedEffects,
12152
+ node
12153
+ });
12154
+ break;
12155
+ }
12156
+ if (property.value.type & (8 | 16) && isByteArray(object.value)) {
12157
+ push({
12158
+ value: {
12159
+ type: 8
12160
+ /* Number */
12161
+ },
12162
+ embeddedEffects: object.embeddedEffects || property.embeddedEffects,
12163
+ node
12164
+ });
12165
+ break;
12166
+ }
12100
12167
  }
12101
12168
  push({
12102
12169
  value: {
@@ -12400,6 +12467,15 @@ function mustBeIdentical(a, b) {
12400
12467
  }
12401
12468
  return false;
12402
12469
  }
12470
+ function isByteArray(object) {
12471
+ return hasValue(object) && object.type === 32768 && isByteArrayData(object.value);
12472
+ }
12473
+ function isByteArrayData(objectData) {
12474
+ return objectData.klass.value && (0, import_chunk_PVBIKZYZ.every)(
12475
+ objectData.klass.value,
12476
+ (klass) => klass.fullName === "$.Toybox.Lang.ByteArray"
12477
+ );
12478
+ }
12403
12479
  var init_interp = (0, import_chunk_ABYVSU2C.__esm)({
12404
12480
  "src/type-flow/interp.ts"() {
12405
12481
  "use strict";
@@ -12407,6 +12483,7 @@ var init_interp = (0, import_chunk_ABYVSU2C.__esm)({
12407
12483
  (0, import_chunk_MBTLUWXR.init_ast)();
12408
12484
  init_data_flow();
12409
12485
  init_optimizer_types();
12486
+ (0, import_chunk_PVBIKZYZ.init_util)();
12410
12487
  init_could_be();
12411
12488
  init_interp_binary();
12412
12489
  init_interp_call();
@@ -14172,7 +14249,14 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14172
14249
  next = findNextObjectType(istate, trueDecls, me);
14173
14250
  }
14174
14251
  } else {
14175
- if (cur.type & (4096 | 16384 | 32768)) {
14252
+ let byteArray = false;
14253
+ if (cur.type & 32768 && cur.value) {
14254
+ const odata = getObjectValue(cur);
14255
+ if (odata && isByteArrayData(odata)) {
14256
+ byteArray = true;
14257
+ }
14258
+ }
14259
+ if (cur.type & (4096 | 16384 | (byteArray ? 0 : 32768))) {
14176
14260
  next = {
14177
14261
  type: 524287
14178
14262
  /* Any */
@@ -14181,6 +14265,16 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
14181
14265
  updateAny = true;
14182
14266
  }
14183
14267
  } else {
14268
+ if (byteArray) {
14269
+ const t = {
14270
+ type: 8
14271
+ /* Number */
14272
+ };
14273
+ if (next) {
14274
+ unionInto(t, next);
14275
+ }
14276
+ next = t;
14277
+ }
14184
14278
  if (cur.type & 512) {
14185
14279
  const avalue = getUnionComponent(
14186
14280
  cur,
@@ -22562,6 +22656,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22562
22656
  interpState = cloneState2(null);
22563
22657
  }
22564
22658
  const putvStarts = [];
22659
+ const dupsToFix = [];
22565
22660
  let i;
22566
22661
  let initInst = null;
22567
22662
  let initType = null;
@@ -22594,6 +22689,12 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22594
22689
  usedLocals |= 1n << BigInt(bc.arg);
22595
22690
  }
22596
22691
  const delta = interpState.stack.length - depth;
22692
+ if (delta < 0) {
22693
+ break;
22694
+ }
22695
+ if (bc.op === 46 && bc.arg >= delta - 1) {
22696
+ dupsToFix[k] = putvStarts.length;
22697
+ }
22597
22698
  if (delta === 3) {
22598
22699
  const t = interpState.stack[interpState.stack.length - 1].type;
22599
22700
  if (bc.op === 18) {
@@ -22607,9 +22708,6 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22607
22708
  }
22608
22709
  thisInit = null;
22609
22710
  }
22610
- if (delta < 0 || bc.op === 46 && bc.arg >= delta - 1) {
22611
- break;
22612
- }
22613
22711
  }
22614
22712
  if (found === i)
22615
22713
  break;
@@ -22677,6 +22775,11 @@ function optimizeArrayInit(func, block, index, context, interpState) {
22677
22775
  /* aputv */
22678
22776
  );
22679
22777
  };
22778
+ dupsToFix.forEach((x, n) => {
22779
+ const bc = block.bytecodes[n];
22780
+ (0, import_node_assert9.default)(bc.op === 46 && bc.arg >= 2);
22781
+ bc.arg -= 2;
22782
+ });
22680
22783
  convertAputv(i - 1);
22681
22784
  for (let i2 = putvStarts.length; i2--; ) {
22682
22785
  const offset = putvStarts[i2];
@@ -22796,6 +22899,11 @@ ${blockToString(block, context)}`
22796
22899
  if (local >= 0) {
22797
22900
  block.bytecodes.splice(i, 0, bytecode(2, void 0));
22798
22901
  }
22902
+ dupsToFix.forEach((x, n) => {
22903
+ const bc = block.bytecodes[n];
22904
+ (0, import_node_assert9.default)(bc.op === 46 && bc.arg >= 2);
22905
+ bc.arg += (putvStarts.length - x - 1) * 2;
22906
+ });
22799
22907
  for (let i2 = putvStarts.length; i2-- > 1; ) {
22800
22908
  block.bytecodes.splice(putvStarts[i2], 2);
22801
22909
  }
@@ -23738,7 +23846,7 @@ function simpleOpts(func, context) {
23738
23846
  return Array.from(func.blocks.values()).reduce((changes, block) => {
23739
23847
  for (let i = block.bytecodes.length; i--; ) {
23740
23848
  const cur = block.bytecodes[i];
23741
- if (cur.op === 0 || context.config.removeArgc && cur.op === 53) {
23849
+ if (cur.op === 0 || cur.op === 1 && cur.arg === 0 || context.config.removeArgc && cur.op === 53) {
23742
23850
  block.bytecodes.splice(i, 1);
23743
23851
  changes = true;
23744
23852
  if (logging3) {
@@ -23756,6 +23864,18 @@ function simpleOpts(func, context) {
23756
23864
  logging3 && (0, import_chunk_PVBIKZYZ.log)(`${func.name}: deleting no-op shift (${shift})`);
23757
23865
  continue;
23758
23866
  }
23867
+ if (shift === 1n && prev.op === 37) {
23868
+ const dup = prev;
23869
+ dup.op = 46;
23870
+ dup.arg = 0;
23871
+ dup.size = 2;
23872
+ const add = cur;
23873
+ add.op = 3;
23874
+ delete add.arg;
23875
+ add.size = 1;
23876
+ logging3 && (0, import_chunk_PVBIKZYZ.log)(`${func.name}: converting "ipush 1; shlv" to "dup 0; addv"`);
23877
+ continue;
23878
+ }
23759
23879
  if (shift < (prev.op === 49 ? 64n : 31n)) {
23760
23880
  const mul = 1n << shift;
23761
23881
  if (prev.op === 37) {
@@ -25354,11 +25474,15 @@ var init_symbols = (0, import_chunk_ABYVSU2C.__esm)({
25354
25474
  const { startPc, name, parent } = functionEntry.attr;
25355
25475
  if (!startPc || !name)
25356
25476
  return;
25477
+ const fullPc = Number(startPc.value.value);
25478
+ if (fullPc >>> 28 !== 1) {
25479
+ return;
25480
+ }
25481
+ const pc = fullPc & 16777215;
25357
25482
  const argc = functionEntry.children?.filter(
25358
25483
  (node) => node.type === "element" && node.name === "param"
25359
25484
  ).length || null;
25360
25485
  const fullName = (parent ? debugXml.processRefs(parent.value.value) + "." : "") + debugXml.processRefs(name.value.value);
25361
- const pc = Number(startPc.value.value) & 16777215;
25362
25486
  this.methods.set(pc, {
25363
25487
  name: fullName,
25364
25488
  id: null,
@@ -29893,7 +30017,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29893
30017
  const opt_time = await (0, import_chunk_PVBIKZYZ.first_modified)(
29894
30018
  Object.values(fnMap).map((v) => v.output)
29895
30019
  );
29896
- if (source_time < opt_time && 1690215897566 < opt_time) {
30020
+ if (source_time < opt_time && 1692125151130 < opt_time) {
29897
30021
  return {
29898
30022
  hasTests,
29899
30023
  diagnostics: prevDiagnostics,
@@ -29931,7 +30055,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29931
30055
  hasTests: hasTests2,
29932
30056
  diagnostics,
29933
30057
  sdkVersion,
29934
- optimizerVersion: "1.1.32",
30058
+ optimizerVersion: "1.1.34",
29935
30059
  ...Object.fromEntries(
29936
30060
  configOptionsToCheck.map((option) => [option, config[option]])
29937
30061
  )
@@ -30372,14 +30496,17 @@ async function optimizeProgram(filepath, devKey, output, config) {
30372
30496
  if (!output) {
30373
30497
  output = removeExt(filepath, ".prg") + ".opt.prg";
30374
30498
  }
30375
- const xmlBytes = await fs7.readFile(filepath + ".debug.xml").catch(() => "");
30376
- const debugXml = xml_util_exports.parseXml(xmlBytes.toString());
30377
- const key = devKey ? await getDevKey(devKey) : void 0;
30378
- const view = new DataView((await fs7.readFile(filepath)).buffer);
30379
- const { signature, buffer } = await optimizeProgramBuffer(
30499
+ const [debugXml, apiDebugXml, key, view] = await Promise.all([
30500
+ fs7.readFile(filepath + ".debug.xml").catch(() => "").then((xmlBytes) => xml_util_exports.parseXml(xmlBytes.toString())),
30501
+ getSdkPath().then((sdk) => fs7.readFile(`${sdk}bin/api.debug.xml`)).catch(() => "").then((xmlBytes) => xml_util_exports.parseXml(xmlBytes.toString())),
30502
+ devKey ? getDevKey(devKey) : void 0,
30503
+ fs7.readFile(filepath).then((prgData) => new DataView(prgData.buffer))
30504
+ ]);
30505
+ const { signature, buffer } = optimizeProgramBuffer(
30380
30506
  filepath,
30381
30507
  view,
30382
30508
  debugXml,
30509
+ apiDebugXml,
30383
30510
  key,
30384
30511
  config
30385
30512
  );
@@ -30400,7 +30527,7 @@ async function optimizeProgram(filepath, devKey, output, config) {
30400
30527
  await Promise.all(promises);
30401
30528
  return { signature, output };
30402
30529
  }
30403
- function optimizeProgramBuffer(filepath, view, debugXml, key, config) {
30530
+ function optimizeProgramBuffer(filepath, view, debugXml, apiDebugXml, key, config) {
30404
30531
  const { sections } = readPrgWithOffsets(view);
30405
30532
  (0, import_chunk_PVBIKZYZ.logger)("readprg", 5, sections);
30406
30533
  const symbolTable = new SymbolTable();
@@ -30411,6 +30538,9 @@ function optimizeProgramBuffer(filepath, view, debugXml, key, config) {
30411
30538
  ].view);
30412
30539
  }
30413
30540
  symbolTable.parseXml(debugXml);
30541
+ if (apiDebugXml) {
30542
+ symbolTable.parseXml(apiDebugXml);
30543
+ }
30414
30544
  const header = parseHeader(sections[
30415
30545
  -805253120
30416
30546
  /* HEADER */
@@ -30661,6 +30791,7 @@ function optimizePrgAndDebug(prgName, prgBuffer, prgOffset, prgLength, xmlName,
30661
30791
  prgName,
30662
30792
  new DataView(prgBuffer, prgOffset, prgLength),
30663
30793
  debugXml,
30794
+ null,
30664
30795
  key,
30665
30796
  config
30666
30797
  );
@@ -18,29 +18,29 @@ 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_NUE3G2QE.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_NUE3G2QE.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_QBCVUVLD.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_QBCVUVLD.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_PVBIKZYZ.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_NUE3G2QE.defaultConfig,
25
- display: () => import_chunk_NUE3G2QE.display,
26
- generateApiMirTests: () => import_chunk_NUE3G2QE.generateApiMirTests,
27
- generateOneConfig: () => import_chunk_NUE3G2QE.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_NUE3G2QE.generateOptimizedProject,
29
- getConfig: () => import_chunk_NUE3G2QE.getConfig,
30
- getProjectAnalysis: () => import_chunk_NUE3G2QE.getProjectAnalysis,
31
- get_jungle: () => import_chunk_NUE3G2QE.get_jungle,
32
- isErrorWithLocation: () => import_chunk_NUE3G2QE.isErrorWithLocation,
33
- launchSimulator: () => import_chunk_NUE3G2QE.launchSimulator,
34
- manifestProducts: () => import_chunk_NUE3G2QE.manifestProducts,
35
- mctree: () => import_chunk_NUE3G2QE.mctree,
36
- simulateProgram: () => import_chunk_NUE3G2QE.simulateProgram
24
+ defaultConfig: () => import_chunk_QBCVUVLD.defaultConfig,
25
+ display: () => import_chunk_QBCVUVLD.display,
26
+ generateApiMirTests: () => import_chunk_QBCVUVLD.generateApiMirTests,
27
+ generateOneConfig: () => import_chunk_QBCVUVLD.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_QBCVUVLD.generateOptimizedProject,
29
+ getConfig: () => import_chunk_QBCVUVLD.getConfig,
30
+ getProjectAnalysis: () => import_chunk_QBCVUVLD.getProjectAnalysis,
31
+ get_jungle: () => import_chunk_QBCVUVLD.get_jungle,
32
+ isErrorWithLocation: () => import_chunk_QBCVUVLD.isErrorWithLocation,
33
+ launchSimulator: () => import_chunk_QBCVUVLD.launchSimulator,
34
+ manifestProducts: () => import_chunk_QBCVUVLD.manifestProducts,
35
+ mctree: () => import_chunk_QBCVUVLD.mctree,
36
+ simulateProgram: () => import_chunk_QBCVUVLD.simulateProgram
37
37
  });
38
38
  module.exports = __toCommonJS(optimizer_exports);
39
- var import_chunk_NUE3G2QE = require("./chunk-NUE3G2QE.cjs");
39
+ var import_chunk_QBCVUVLD = require("./chunk-QBCVUVLD.cjs");
40
40
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.cjs");
41
41
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
42
42
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
43
- (0, import_chunk_NUE3G2QE.init_optimizer)();
43
+ (0, import_chunk_QBCVUVLD.init_optimizer)();
44
44
  // Annotate the CommonJS export names for ESM import in node:
45
45
  0 && (module.exports = {
46
46
  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_NUE3G2QE.SectionKinds,
22
- appSupport: () => import_chunk_NUE3G2QE.appSupport,
23
- connectiq: () => import_chunk_NUE3G2QE.connectiq,
24
- getDeviceInfo: () => import_chunk_NUE3G2QE.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_NUE3G2QE.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_NUE3G2QE.getLanguages,
27
- getSdkPath: () => import_chunk_NUE3G2QE.getSdkPath,
28
- isWin: () => import_chunk_NUE3G2QE.isWin,
29
- optimizeProgram: () => import_chunk_NUE3G2QE.optimizeProgram,
30
- readPrg: () => import_chunk_NUE3G2QE.readPrg,
31
- readPrgWithOffsets: () => import_chunk_NUE3G2QE.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_NUE3G2QE.xml_util_exports
21
+ SectionKinds: () => import_chunk_QBCVUVLD.SectionKinds,
22
+ appSupport: () => import_chunk_QBCVUVLD.appSupport,
23
+ connectiq: () => import_chunk_QBCVUVLD.connectiq,
24
+ getDeviceInfo: () => import_chunk_QBCVUVLD.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_QBCVUVLD.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_QBCVUVLD.getLanguages,
27
+ getSdkPath: () => import_chunk_QBCVUVLD.getSdkPath,
28
+ isWin: () => import_chunk_QBCVUVLD.isWin,
29
+ optimizeProgram: () => import_chunk_QBCVUVLD.optimizeProgram,
30
+ readPrg: () => import_chunk_QBCVUVLD.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_QBCVUVLD.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_QBCVUVLD.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_NUE3G2QE = require("./chunk-NUE3G2QE.cjs");
35
+ var import_chunk_QBCVUVLD = require("./chunk-QBCVUVLD.cjs");
36
36
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.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_NUE3G2QE.init_sdk_util)();
39
+ (0, import_chunk_QBCVUVLD.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -26,7 +26,7 @@ export declare function findNamesInScope(declStack: StateNode[][], pattern: stri
26
26
  readonly parent: StateNode;
27
27
  readonly depth: number;
28
28
  }])[];
29
- export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | FunctionStateNode | ClassStateNode | ModuleStateNode | ProgramStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | TypedefStateNode | EnumStateNode)[];
29
+ export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | FunctionStateNode | ModuleStateNode | ClassStateNode | TypedefStateNode | ProgramStateNode | EnumStateNode | import("./optimizer-types").BlockStateNode | VariableStateNode)[];
30
30
  export declare function formatAstLongLines(node: mctree.Node): string;
31
31
  export declare function createDocumentationMap(functionDocumentation: {
32
32
  name: string;
@@ -14,6 +14,7 @@ export type RemoteProject = string | {
14
14
  jungleContent?: string[];
15
15
  garminOptLevel?: number;
16
16
  test?: boolean | string[];
17
+ branch?: string;
17
18
  };
18
19
  export declare const githubProjects: RemoteProject[];
19
20
  export declare function fetchGitProjects(projects: RemoteProject[], testOnly: boolean, skipRemote: boolean): Promise<(string | {
@@ -1,9 +1,7 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import * as crypto from "node:crypto";
4
3
  import { BuildConfig } from "./optimizer-types";
5
4
  import { SectionInfo } from "./readprg/bytecode";
6
- import { xmlUtil } from "./sdk-util";
7
5
  export declare function readPrg(path: string): Promise<{
8
6
  [k: string]: number;
9
7
  }>;
@@ -16,10 +14,6 @@ export declare function readPrgWithOffsets(view: DataView): {
16
14
  sections: Record<number, SectionInfo>;
17
15
  };
18
16
  export declare function optimizeProgram(filepath: string, devKey?: string | undefined, output?: string, config?: BuildConfig): Promise<unknown>;
19
- export declare function optimizeProgramBuffer(filepath: string, view: DataView, debugXml: xmlUtil.Document, key: crypto.KeyObject | undefined, config: BuildConfig | undefined): {
20
- signature: Buffer | undefined;
21
- buffer: Buffer;
22
- };
23
17
  export declare function optimizePrgAndDebug(prgName: string, prgBuffer: ArrayBuffer, prgOffset: number, prgLength: number, xmlName: string, xmlBuffer: ArrayBuffer, xmlOffset: number, xmlLength: number, key: crypto.KeyObject, config: BuildConfig | undefined): Promise<{
24
18
  sigBuffer: ArrayBufferLike | undefined;
25
19
  sigOffset: number | undefined;
@@ -0,0 +1,51 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { hasProperty, traverseAst } from "./ast";
3
+ import { JungleResourceMap } from "./jungles";
4
+ import { ClassStateNode, Diagnostic, DiagnosticType, EnumStateNode, FunctionInfo, FunctionStateNode, LookupDefinition, LookupResult, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, TypedefStateNode, VariableStateNode } from "./optimizer-types";
5
+ import { visit_resources } from "./resources";
6
+ import { xmlUtil } from "./sdk-util";
7
+ import { TypeMap } from "./type-flow/interp";
8
+ export { visitorNode, visitReferences } from "./visitor";
9
+ export { traverseAst, hasProperty, visit_resources };
10
+ export declare function parseSdkVersion(version: string | undefined): number;
11
+ export declare function checkCompilerVersion(version: string, sdkVer: number): boolean | undefined;
12
+ export declare function getApiMapping(state?: ProgramState, resourcesMap?: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): Promise<ProgramStateNode>;
13
+ export declare function isStateNode(node: {
14
+ type: string;
15
+ }): node is StateNode;
16
+ export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
17
+ type DeclKind = "decls" | "type_decls";
18
+ export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
19
+ export declare function lookupResultContains(a: LookupDefinition[], b: LookupDefinition[]): boolean;
20
+ export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
21
+ export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
22
+ export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
23
+ export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
24
+ export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
25
+ export declare function findNamesInScope(declStack: StateNode[][], pattern: string | RegExp): (readonly [StateNodeDecl, {
26
+ readonly parent: StateNode;
27
+ readonly depth: number;
28
+ }])[];
29
+ export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | FunctionStateNode | ClassStateNode | ModuleStateNode | ProgramStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | TypedefStateNode | EnumStateNode)[];
30
+ export declare function formatAstLongLines(node: mctree.Node): string;
31
+ export declare function createDocumentationMap(functionDocumentation: {
32
+ name: string;
33
+ parent: string;
34
+ doc: string;
35
+ }[]): Promise<Map<string, string>>;
36
+ export declare function makeToyboxLink(result: StateNodeDecl): string | null;
37
+ export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
38
+ export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier): ModuleStateNode | {
39
+ name: string;
40
+ decls: {
41
+ parent: StateNode;
42
+ results: StateNodeDecl[];
43
+ };
44
+ }[] | null;
45
+ export declare function getApiFunctionInfo(state: ProgramState, func: FunctionStateNode): FunctionInfo | false;
46
+ export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
47
+ export declare function isLocal(v: VariableStateNode): boolean;
48
+ export declare function isClassVariable(v: VariableStateNode): boolean;
49
+ export declare function diagnostic(state: ProgramState, node: mctree.Node, message: string | null, type?: DiagnosticType, extra?: Diagnostic["extra"]): void;
50
+ export declare function diagnosticHelper(diagnostics: Record<string, Diagnostic[]>, node: mctree.Node, message: string | null, type: DiagnosticType | undefined, extra: Diagnostic["extra"] | undefined, uniqueLocs: boolean): void;
51
+ export declare function getSuperClasses(klass: ClassStateNode): Set<StateNode> | null;