@markw65/monkeyc-optimizer 1.1.27 → 1.1.29

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/README.md CHANGED
@@ -876,3 +876,23 @@ No functional change, just fixes a typo that broke the typescript exports.
876
876
 
877
877
  - New features
878
878
  - Adds a [standalone script](https://github.com/markw65/monkeyc-optimizer/wiki/Garmin-Font-Analyzer) to analyze .cft (font) files.
879
+
880
+ ### 1.1.28
881
+
882
+ - Bug fixes
883
+
884
+ - Fixes an issue in the post build optimizer which could cause a pre-definition to be inserted just prior to an `frpush`, which could result in the wrong value of `self` being passed to a call
885
+ - Don't add personality paths to the generated jungle file if the sdk is prior to 4.2.1
886
+ - Fixes a bug in the source-to-source optimizer that could incorrectly infer that an `if` block was never entered when the if's comparison was between a primitive type, and a plain `Object`
887
+
888
+ - Improved optimizations
889
+ - Constant folding between `Char` and types other than `Number` is now handled (previously such comparisons were just left for Garmin's compiler to handle). This works around a [bug in Garmin's optimizer](https://forums.garmin.com/developer/connect-iq/i/bug-reports/the-optimizer-constant-folds-char-comparisons-incorrectly) by (correctly) resolving the comparisons before Garmin's optimizer can do the wrong thing.
890
+
891
+ ### 1.1.29
892
+
893
+ - Bug fixes
894
+
895
+ - Fixes an issue where a value could incorrectly be inferred to be true-ish when its declared type was known to be an object of class type. This is not of itself incorrect, but some Toybox APIs are declared as returning an Object of a class, but may in fact return null - so we can't treat them as non-null.
896
+
897
+ - Enhancements
898
+ - various methods used by the extension for completion and hover info have been updated to give more accurate results.
File without changes
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_DD4VX53Y.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_DD4VX53Y.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_DD4VX53Y.createDocumentationMap,
24
- diagnostic: () => import_chunk_DD4VX53Y.diagnostic,
25
- diagnosticHelper: () => import_chunk_DD4VX53Y.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_DD4VX53Y.findNamesInScope,
27
- findUsingForNode: () => import_chunk_DD4VX53Y.findUsingForNode,
28
- formatAst: () => import_chunk_DD4VX53Y.formatAst,
29
- formatAstLongLines: () => import_chunk_DD4VX53Y.formatAstLongLines,
30
- getApiFunctionInfo: () => import_chunk_DD4VX53Y.getApiFunctionInfo,
31
- getApiMapping: () => import_chunk_DD4VX53Y.getApiMapping,
32
- getSuperClasses: () => import_chunk_DD4VX53Y.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_PUYLJGKM.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_PUYLJGKM.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_PUYLJGKM.createDocumentationMap,
24
+ diagnostic: () => import_chunk_PUYLJGKM.diagnostic,
25
+ diagnosticHelper: () => import_chunk_PUYLJGKM.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_PUYLJGKM.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_PUYLJGKM.findUsingForNode,
28
+ formatAst: () => import_chunk_PUYLJGKM.formatAst,
29
+ formatAstLongLines: () => import_chunk_PUYLJGKM.formatAstLongLines,
30
+ getApiFunctionInfo: () => import_chunk_PUYLJGKM.getApiFunctionInfo,
31
+ getApiMapping: () => import_chunk_PUYLJGKM.getApiMapping,
32
+ getSuperClasses: () => import_chunk_PUYLJGKM.getSuperClasses,
33
33
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
34
- isClassVariable: () => import_chunk_DD4VX53Y.isClassVariable,
35
- isLocal: () => import_chunk_DD4VX53Y.isLocal,
36
- isLookupCandidate: () => import_chunk_DD4VX53Y.isLookupCandidate,
37
- isStateNode: () => import_chunk_DD4VX53Y.isStateNode,
38
- lookupByFullName: () => import_chunk_DD4VX53Y.lookupByFullName,
39
- lookupNext: () => import_chunk_DD4VX53Y.lookupNext,
40
- lookupResultContains: () => import_chunk_DD4VX53Y.lookupResultContains,
41
- lookupWithType: () => import_chunk_DD4VX53Y.lookupWithType,
42
- makeToyboxLink: () => import_chunk_DD4VX53Y.makeToyboxLink,
43
- mapVarDeclsByType: () => import_chunk_DD4VX53Y.mapVarDeclsByType,
44
- markInvokeClassMethod: () => import_chunk_DD4VX53Y.markInvokeClassMethod,
45
- parseSdkVersion: () => import_chunk_DD4VX53Y.parseSdkVersion,
46
- sameLookupResult: () => import_chunk_DD4VX53Y.sameLookupResult,
34
+ isClassVariable: () => import_chunk_PUYLJGKM.isClassVariable,
35
+ isLocal: () => import_chunk_PUYLJGKM.isLocal,
36
+ isLookupCandidate: () => import_chunk_PUYLJGKM.isLookupCandidate,
37
+ isStateNode: () => import_chunk_PUYLJGKM.isStateNode,
38
+ lookupByFullName: () => import_chunk_PUYLJGKM.lookupByFullName,
39
+ lookupNext: () => import_chunk_PUYLJGKM.lookupNext,
40
+ lookupResultContains: () => import_chunk_PUYLJGKM.lookupResultContains,
41
+ lookupWithType: () => import_chunk_PUYLJGKM.lookupWithType,
42
+ makeToyboxLink: () => import_chunk_PUYLJGKM.makeToyboxLink,
43
+ mapVarDeclsByType: () => import_chunk_PUYLJGKM.mapVarDeclsByType,
44
+ markInvokeClassMethod: () => import_chunk_PUYLJGKM.markInvokeClassMethod,
45
+ parseSdkVersion: () => import_chunk_PUYLJGKM.parseSdkVersion,
46
+ sameLookupResult: () => import_chunk_PUYLJGKM.sameLookupResult,
47
47
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
48
- variableDeclarationName: () => import_chunk_DD4VX53Y.variableDeclarationName,
49
- visitReferences: () => import_chunk_DD4VX53Y.visitReferences,
50
- visit_resources: () => import_chunk_DD4VX53Y.visit_resources,
51
- visitorNode: () => import_chunk_DD4VX53Y.visitorNode
48
+ variableDeclarationName: () => import_chunk_PUYLJGKM.variableDeclarationName,
49
+ visitReferences: () => import_chunk_PUYLJGKM.visitReferences,
50
+ visit_resources: () => import_chunk_PUYLJGKM.visit_resources,
51
+ visitorNode: () => import_chunk_PUYLJGKM.visitorNode
52
52
  });
53
53
  module.exports = __toCommonJS(api_exports);
54
- var import_chunk_DD4VX53Y = require("./chunk-DD4VX53Y.cjs");
54
+ var import_chunk_PUYLJGKM = require("./chunk-PUYLJGKM.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_DD4VX53Y.init_api)();
58
+ (0, import_chunk_PUYLJGKM.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_DD4VX53Y_exports = {};
30
- __export(chunk_DD4VX53Y_exports, {
29
+ var chunk_PUYLJGKM_exports = {};
30
+ __export(chunk_PUYLJGKM_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -122,7 +122,7 @@ __export(chunk_DD4VX53Y_exports, {
122
122
  visitorNode: () => visitorNode,
123
123
  xml_util_exports: () => xml_util_exports
124
124
  });
125
- module.exports = __toCommonJS(chunk_DD4VX53Y_exports);
125
+ module.exports = __toCommonJS(chunk_PUYLJGKM_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");
@@ -10008,13 +10008,18 @@ function restrictExactTypesByEquality(a, b) {
10008
10008
  }
10009
10009
  case 8: {
10010
10010
  let extra_bits = 0;
10011
- if (b.type & 2 && (a.value == null || a.value === 0)) {
10011
+ if (a.value == null || a.value === 0) {
10012
10012
  extra_bits |= 2;
10013
10013
  }
10014
- if (b.type & 4 && (a.value == null || a.value === 1)) {
10014
+ if (a.value == null || a.value === 1) {
10015
10015
  extra_bits |= 4;
10016
10016
  }
10017
10017
  let value_bits = b.type & (120 | 128);
10018
+ if (b.type & 32768 && !getObjectValue(b)) {
10019
+ value_bits |= 120 | 128;
10020
+ } else {
10021
+ extra_bits &= b.type;
10022
+ }
10018
10023
  if (a.value != null && value_bits & 32 && roundToFloat(Number(a.value)) !== a.value) {
10019
10024
  value_bits -= 32;
10020
10025
  }
@@ -10035,11 +10040,17 @@ function restrictExactTypesByEquality(a, b) {
10035
10040
  return fixupEnum(a, v, b);
10036
10041
  }
10037
10042
  case 16: {
10038
- let value_bits = b.type & 120;
10043
+ let value_bits = b.type & (120 | 128);
10044
+ if (b.type & 32768 && !getObjectValue(b)) {
10045
+ value_bits |= 120 | 128;
10046
+ }
10039
10047
  if (a.value != null) {
10040
10048
  if (value_bits & 8 && BigInt.asIntN(32, a.value) !== a.value) {
10041
10049
  value_bits -= 8;
10042
10050
  }
10051
+ if (value_bits & 128 && BigInt.asIntN(32, a.value) !== a.value) {
10052
+ value_bits -= 128;
10053
+ }
10043
10054
  if (value_bits & 32 && BigInt(roundToFloat(Number(a.value))) !== a.value) {
10044
10055
  value_bits -= 32;
10045
10056
  }
@@ -10065,23 +10076,25 @@ function restrictExactTypesByEquality(a, b) {
10065
10076
  }
10066
10077
  case 64:
10067
10078
  case 32: {
10068
- let value_bits = 120;
10079
+ let value_bits = b.type & (120 | 128);
10080
+ if (b.type & 32768 && !getObjectValue(b)) {
10081
+ value_bits |= 120 | 128;
10082
+ }
10069
10083
  if (a.value != null) {
10070
10084
  if (!Number.isInteger(a.value)) {
10071
- value_bits -= 8 | 16;
10085
+ value_bits &= ~(8 | 16 | 128);
10072
10086
  } else {
10073
10087
  if (Number(BigInt.asIntN(32, BigInt(a.value))) !== a.value) {
10074
- value_bits -= 8;
10088
+ value_bits &= ~(8 | 128);
10075
10089
  }
10076
10090
  }
10077
10091
  }
10078
- value_bits &= b.type;
10079
10092
  let v = {
10080
10093
  type: value_bits
10081
10094
  };
10082
10095
  if (value_bits && !(value_bits & value_bits - 1)) {
10083
10096
  if (a.value != null) {
10084
- v.value = value_bits === 16 ? BigInt(a.value) : Number(a.value);
10097
+ v.value = value_bits === 16 ? BigInt(a.value) : value_bits === 128 ? String.fromCharCode(Number(a.value)) : a.value;
10085
10098
  if (b.value && !couldBe(v, b)) {
10086
10099
  v.type = 0;
10087
10100
  delete v.value;
@@ -10093,13 +10106,25 @@ function restrictExactTypesByEquality(a, b) {
10093
10106
  return fixupEnum(a, v, b);
10094
10107
  }
10095
10108
  case 128: {
10096
- const value_bits = b.type & (8 | 128);
10109
+ let extra_bits = 0;
10110
+ if (a.value == null || a.value.charCodeAt(0) === 0) {
10111
+ extra_bits |= 2;
10112
+ }
10113
+ if (a.value == null || a.value.charCodeAt(0) === 1) {
10114
+ extra_bits |= 4;
10115
+ }
10116
+ let value_bits = b.type & (120 | 128);
10117
+ if (b.type & 32768 && !getObjectValue(b)) {
10118
+ value_bits |= 120 | 128;
10119
+ } else {
10120
+ extra_bits &= b.type;
10121
+ }
10097
10122
  let v = {
10098
- type: value_bits
10123
+ type: value_bits | extra_bits
10099
10124
  };
10100
10125
  if (value_bits && !(value_bits & value_bits - 1)) {
10101
10126
  if (a.value != null) {
10102
- v.value = value_bits === 8 ? a.value.charCodeAt(0) : a.value;
10127
+ v.value = value_bits === 16 ? BigInt(a.value.charCodeAt(0)) : value_bits & 120 ? a.value.charCodeAt(0) : a.value;
10103
10128
  if (b.value && !couldBe(v, b)) {
10104
10129
  v.type = 0;
10105
10130
  delete v.value;
@@ -10403,10 +10428,10 @@ function equalsCheck(left, right) {
10403
10428
  return left.type & 120 && right.type & 120 ? (
10404
10429
  // eslint-disable-next-line eqeqeq
10405
10430
  left.value == right.value
10406
- ) : lrBits === (8 | 128) ? (
10407
- // Char vs Number is true iff the number is the char-code of the char
10408
- left.type === 128 ? left.value.charCodeAt(0) === right.value : left.value === right.value.charCodeAt(0)
10409
- ) : left.type === 8 && right.type & 6 ? left.value === (right.value ? 1 : 0) : right.type === 8 && left.type & 6 ? right.value === (left.value ? 1 : 0) : left.type !== right.type ? lrBits & 1 ? lrBits & (32768 | 512 | 1024) ? void 0 : false : lrBits & (4096 | 8192 | 16384) ? false : void 0 : left.type === 128 || left.type === 131072 ? left.value === right.value : isSingleton(left) ? true : void 0;
10431
+ ) : (
10432
+ // Char vs Numeric is true iff the number is the char-code of the char
10433
+ left.type === 128 && right.type & 120 ? left.value.charCodeAt(0) === Number(right.value) : right.type === 128 && left.type & 120 ? Number(left.value) === right.value.charCodeAt(0) : left.type === 128 && right.type & 6 ? left.value.charCodeAt(0) === (right.value ? 1 : 0) : right.type === 128 && left.type & 6 ? right.value.charCodeAt(0) === (left.value ? 1 : 0) : left.type === 8 && right.type & 6 ? left.value === (right.value ? 1 : 0) : right.type === 8 && left.type & 6 ? right.value === (left.value ? 1 : 0) : left.type !== right.type ? lrBits & 1 ? lrBits & (32768 | 512 | 1024) ? void 0 : false : lrBits & (4096 | 8192 | 16384) ? false : void 0 : left.type === 128 || left.type === 131072 ? left.value === right.value : isSingleton(left) ? true : void 0
10434
+ );
10410
10435
  }
10411
10436
  function evaluateBinaryTypes(op, left, right) {
10412
10437
  if (!operators) {
@@ -10743,6 +10768,7 @@ function filterDecls(decls, possible, name) {
10743
10768
  return [null, null];
10744
10769
  const result = decls.reduce(
10745
10770
  (cur, decl) => {
10771
+ let declSups;
10746
10772
  const found = possible.reduce((flag, poss) => {
10747
10773
  if (decl === poss || poss.type === "ClassDeclaration" && getSuperClasses(poss)?.has(decl)) {
10748
10774
  if (!cur[0]) {
@@ -10751,12 +10777,27 @@ function filterDecls(decls, possible, name) {
10751
10777
  cur[0].add(poss);
10752
10778
  cur[1].add(poss);
10753
10779
  return true;
10754
- } else if (decl.type === "ClassDeclaration" && getSuperClasses(decl)?.has(poss)) {
10780
+ } else if (declSups !== void 0 ? declSups?.has(poss) : decl.type === "ClassDeclaration" && (declSups = getSuperClasses(decl))?.has(poss)) {
10755
10781
  if (!cur[0]) {
10756
- cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
10782
+ cur = [/* @__PURE__ */ new Set([decl]), /* @__PURE__ */ new Set([poss])];
10783
+ } else {
10784
+ cur[0].add(decl);
10785
+ if (Array.from(cur[1]).every((d) => {
10786
+ if (decl === d)
10787
+ return false;
10788
+ if (!declSups.has(d))
10789
+ return true;
10790
+ if (d.type === "ClassDeclaration" && getSuperClasses(d)?.has(poss)) {
10791
+ return false;
10792
+ }
10793
+ if (poss.type === "ClassDeclaration" && getSuperClasses(poss)?.has(d)) {
10794
+ cur[1].delete(d);
10795
+ }
10796
+ return true;
10797
+ })) {
10798
+ cur[1].add(poss);
10799
+ }
10757
10800
  }
10758
- cur[0].add(decl);
10759
- cur[1].add(poss);
10760
10801
  return true;
10761
10802
  }
10762
10803
  return flag;
@@ -13149,7 +13190,8 @@ var init_types = (0, import_chunk_ABYVSU2C.__esm)({
13149
13190
  ValueTypeTagsConst = 8 | 16 | 32 | 64 | 128 | 256 | 131072;
13150
13191
  ObjectLikeTagsConst = 6 | ValueTypeTagsConst | 512 | 1024 | 2048 | 65536;
13151
13192
  EnumTagsConst = SingletonTypeTagsConst | ValueTypeTagsConst & ~131072;
13152
- TruthyTypes = 4 | 32768 | 4096 | 16384 | 8192;
13193
+ TruthyTypes = 4 | // TypeTag.Object | // omit because of missing null on various Toybox types
13194
+ 4096 | 16384 | 8192;
13153
13195
  }
13154
13196
  });
13155
13197
  function couldBeHelper(a, b, shallow) {
@@ -18180,7 +18222,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
18180
18222
  pragmaChecker(state, f.ast, state.diagnostics?.[name]);
18181
18223
  }
18182
18224
  });
18183
- return state.diagnostics;
18225
+ return { diagnostics: state.diagnostics, sdkVersion: state.sdkVersion };
18184
18226
  }
18185
18227
  function maybeCalled(state, func) {
18186
18228
  if (!func.body) {
@@ -19508,6 +19550,20 @@ function lookupWithType(state, node, typeMap, nonLocal = false, stack = null) {
19508
19550
  return [node.property.name, next];
19509
19551
  }
19510
19552
  }
19553
+ } else if (node.type === "Literal") {
19554
+ const type = typeFromLiteral(node);
19555
+ const results2 = getStateNodeDeclsFromType(state, type);
19556
+ return [node.raw, [{ parent: null, results: results2 }]];
19557
+ } else if (node.type === "UnaryExpression" && node.operator === ":") {
19558
+ return [
19559
+ node.argument.name,
19560
+ [
19561
+ {
19562
+ parent: null,
19563
+ results: lookupByFullName(state, "Toybox.Lang.Symbol")
19564
+ }
19565
+ ]
19566
+ ];
19511
19567
  }
19512
19568
  return results;
19513
19569
  }
@@ -19968,7 +20024,7 @@ function findNamesInExactScope(decl, regexp) {
19968
20024
  if (!decl.decls)
19969
20025
  return [];
19970
20026
  return Object.entries(decl.decls).flatMap(
19971
- ([key, value2]) => regexp.test(key) ? value2 : []
20027
+ ([name, decls]) => regexp.test(name) ? { name, decls } : []
19972
20028
  );
19973
20029
  }
19974
20030
  function findNamesInScope(declStack, pattern) {
@@ -19978,11 +20034,18 @@ function findNamesInScope(declStack, pattern) {
19978
20034
  decls.forEach((parent) => {
19979
20035
  if (parent.type === "ClassDeclaration") {
19980
20036
  if (parent.superClass && parent.superClass !== true) {
19981
- helper(parent.superClass, depth2 + 1);
20037
+ helper(parent.superClass, depth2);
19982
20038
  }
19983
20039
  }
19984
- findNamesInExactScope(parent, regex).forEach((sn) => {
19985
- results.set(sn, { parent, depth: depth2 });
20040
+ findNamesInExactScope(parent, regex).forEach(({ name, decls: decls2 }) => {
20041
+ let names = results.get(name);
20042
+ if (!names) {
20043
+ results.set(name, names = /* @__PURE__ */ new Map());
20044
+ }
20045
+ names.set(
20046
+ depth2,
20047
+ decls2.map((decl) => ({ decl, parent }))
20048
+ );
19986
20049
  });
19987
20050
  });
19988
20051
  };
@@ -19991,7 +20054,11 @@ function findNamesInScope(declStack, pattern) {
19991
20054
  helper(declStack[declStack.length - 1 - depth], depth);
19992
20055
  depth++;
19993
20056
  }
19994
- return Array.from(results);
20057
+ return Array.from(results.values()).map(
20058
+ (m) => Array.from(m).map(
20059
+ ([depth2, entries]) => entries.map(({ decl, parent }) => [decl, { parent, depth: depth2 }])
20060
+ )
20061
+ ).flat(2);
19995
20062
  }
19996
20063
  function mapVarDeclsByType(state, decls, node, typeMap) {
19997
20064
  return decls.flatMap((decl) => {
@@ -21567,7 +21634,7 @@ function sizeBasedPRE2(func, context) {
21567
21634
  })
21568
21635
  );
21569
21636
  (0, import_node_assert7.default)(spush);
21570
- if (index >= 0 && index < block.bytecodes.length) {
21637
+ if (index >= 0 && index < block.bytecodes.length && bcs.has(block.bytecodes[index])) {
21571
21638
  index--;
21572
21639
  }
21573
21640
  block.bytecodes.splice(
@@ -29455,6 +29522,7 @@ async function generateOptimizedProject(options) {
29455
29522
  if (configsToBuild > 1) {
29456
29523
  poolStarted = startPool();
29457
29524
  }
29525
+ let hasPersonality = false;
29458
29526
  const promises = Object.keys(buildConfigs).sort().map((key) => {
29459
29527
  const buildConfig = buildConfigs[key];
29460
29528
  const outputPath = path4.join(config.outputPath, key);
@@ -29483,6 +29551,9 @@ async function generateOptimizedProject(options) {
29483
29551
  if (t.diagnostics) {
29484
29552
  diagnostics = { ...diagnostics, ...t.diagnostics };
29485
29553
  }
29554
+ if (t.sdkVersion != null && t.sdkVersion >= 4002001) {
29555
+ hasPersonality = true;
29556
+ }
29486
29557
  }) : fs6.rm(path4.resolve(workspace, outputPath), {
29487
29558
  recursive: true,
29488
29559
  force: true
@@ -29618,8 +29689,11 @@ async function generateOptimizedProject(options) {
29618
29689
  });
29619
29690
  }
29620
29691
  });
29621
- promises.push(fs6.writeFile(jungleFiles, parts.join("\n")));
29622
29692
  await Promise.all(promises);
29693
+ await fs6.writeFile(
29694
+ jungleFiles,
29695
+ (hasPersonality ? parts : parts.filter((part) => !/\.personality = /.test(part))).join("\n")
29696
+ );
29623
29697
  } finally {
29624
29698
  if (poolStarted) {
29625
29699
  stopPool();
@@ -29755,6 +29829,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29755
29829
  const {
29756
29830
  hasTests,
29757
29831
  diagnostics: prevDiagnostics,
29832
+ sdkVersion: prevSdkVersion,
29758
29833
  ...prevOptions
29759
29834
  } = JSON.parse(
29760
29835
  await fs6.readFile(path4.join(output, "build-info.json"), "utf-8").catch(() => "{}")
@@ -29769,8 +29844,12 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29769
29844
  const opt_time = await (0, import_chunk_PVBIKZYZ.first_modified)(
29770
29845
  Object.values(fnMap).map((v) => v.output)
29771
29846
  );
29772
- if (source_time < opt_time && 1682889148128 < opt_time) {
29773
- return { hasTests, diagnostics: prevDiagnostics };
29847
+ if (source_time < opt_time && 1685575802667 < opt_time) {
29848
+ return {
29849
+ hasTests,
29850
+ diagnostics: prevDiagnostics,
29851
+ sdkVersion: prevSdkVersion
29852
+ };
29774
29853
  }
29775
29854
  }
29776
29855
  const [, , prettierConfig] = await Promise.all([
@@ -29782,7 +29861,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29782
29861
  })
29783
29862
  ]);
29784
29863
  return optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config).then(
29785
- (diagnostics) => {
29864
+ ({ diagnostics, sdkVersion }) => {
29786
29865
  const options = { ...prettierConfig, ...config.prettier || {} };
29787
29866
  return Promise.all(
29788
29867
  mcFiles.map(async (info) => {
@@ -29801,12 +29880,13 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29801
29880
  JSON.stringify({
29802
29881
  hasTests: hasTests2,
29803
29882
  diagnostics,
29804
- optimizerVersion: "1.1.27",
29883
+ sdkVersion,
29884
+ optimizerVersion: "1.1.29",
29805
29885
  ...Object.fromEntries(
29806
29886
  configOptionsToCheck.map((option) => [option, config[option]])
29807
29887
  )
29808
29888
  })
29809
- ).then(() => ({ hasTests: hasTests2, diagnostics }));
29889
+ ).then(() => ({ hasTests: hasTests2, diagnostics, sdkVersion }));
29810
29890
  });
29811
29891
  }
29812
29892
  );
@@ -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_DD4VX53Y.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_DD4VX53Y.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_PUYLJGKM.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_PUYLJGKM.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_PVBIKZYZ.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_DD4VX53Y.defaultConfig,
25
- display: () => import_chunk_DD4VX53Y.display,
26
- generateApiMirTests: () => import_chunk_DD4VX53Y.generateApiMirTests,
27
- generateOneConfig: () => import_chunk_DD4VX53Y.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_DD4VX53Y.generateOptimizedProject,
29
- getConfig: () => import_chunk_DD4VX53Y.getConfig,
30
- getProjectAnalysis: () => import_chunk_DD4VX53Y.getProjectAnalysis,
31
- get_jungle: () => import_chunk_DD4VX53Y.get_jungle,
32
- isErrorWithLocation: () => import_chunk_DD4VX53Y.isErrorWithLocation,
33
- launchSimulator: () => import_chunk_DD4VX53Y.launchSimulator,
34
- manifestProducts: () => import_chunk_DD4VX53Y.manifestProducts,
35
- mctree: () => import_chunk_DD4VX53Y.mctree,
36
- simulateProgram: () => import_chunk_DD4VX53Y.simulateProgram
24
+ defaultConfig: () => import_chunk_PUYLJGKM.defaultConfig,
25
+ display: () => import_chunk_PUYLJGKM.display,
26
+ generateApiMirTests: () => import_chunk_PUYLJGKM.generateApiMirTests,
27
+ generateOneConfig: () => import_chunk_PUYLJGKM.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_PUYLJGKM.generateOptimizedProject,
29
+ getConfig: () => import_chunk_PUYLJGKM.getConfig,
30
+ getProjectAnalysis: () => import_chunk_PUYLJGKM.getProjectAnalysis,
31
+ get_jungle: () => import_chunk_PUYLJGKM.get_jungle,
32
+ isErrorWithLocation: () => import_chunk_PUYLJGKM.isErrorWithLocation,
33
+ launchSimulator: () => import_chunk_PUYLJGKM.launchSimulator,
34
+ manifestProducts: () => import_chunk_PUYLJGKM.manifestProducts,
35
+ mctree: () => import_chunk_PUYLJGKM.mctree,
36
+ simulateProgram: () => import_chunk_PUYLJGKM.simulateProgram
37
37
  });
38
38
  module.exports = __toCommonJS(optimizer_exports);
39
- var import_chunk_DD4VX53Y = require("./chunk-DD4VX53Y.cjs");
39
+ var import_chunk_PUYLJGKM = require("./chunk-PUYLJGKM.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_DD4VX53Y.init_optimizer)();
43
+ (0, import_chunk_PUYLJGKM.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_DD4VX53Y.SectionKinds,
22
- appSupport: () => import_chunk_DD4VX53Y.appSupport,
23
- connectiq: () => import_chunk_DD4VX53Y.connectiq,
24
- getDeviceInfo: () => import_chunk_DD4VX53Y.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_DD4VX53Y.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_DD4VX53Y.getLanguages,
27
- getSdkPath: () => import_chunk_DD4VX53Y.getSdkPath,
28
- isWin: () => import_chunk_DD4VX53Y.isWin,
29
- optimizeProgram: () => import_chunk_DD4VX53Y.optimizeProgram,
30
- readPrg: () => import_chunk_DD4VX53Y.readPrg,
31
- readPrgWithOffsets: () => import_chunk_DD4VX53Y.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_DD4VX53Y.xml_util_exports
21
+ SectionKinds: () => import_chunk_PUYLJGKM.SectionKinds,
22
+ appSupport: () => import_chunk_PUYLJGKM.appSupport,
23
+ connectiq: () => import_chunk_PUYLJGKM.connectiq,
24
+ getDeviceInfo: () => import_chunk_PUYLJGKM.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_PUYLJGKM.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_PUYLJGKM.getLanguages,
27
+ getSdkPath: () => import_chunk_PUYLJGKM.getSdkPath,
28
+ isWin: () => import_chunk_PUYLJGKM.isWin,
29
+ optimizeProgram: () => import_chunk_PUYLJGKM.optimizeProgram,
30
+ readPrg: () => import_chunk_PUYLJGKM.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_PUYLJGKM.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_PUYLJGKM.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_DD4VX53Y = require("./chunk-DD4VX53Y.cjs");
35
+ var import_chunk_PUYLJGKM = require("./chunk-PUYLJGKM.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_DD4VX53Y.init_sdk_util)();
39
+ (0, import_chunk_PUYLJGKM.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -22,10 +22,10 @@ export declare function lookupNext(state: ProgramStateLive, results: LookupDefin
22
22
  export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
23
23
  export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
24
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): [StateNodeDecl, {
26
- parent: StateNode;
27
- depth: number;
28
- }][];
25
+ export declare function findNamesInScope(declStack: StateNode[][], pattern: string | RegExp): (readonly [StateNodeDecl, {
26
+ readonly parent: StateNode;
27
+ readonly depth: number;
28
+ }])[];
29
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
30
  export declare function formatAstLongLines(node: mctree.Node): string;
31
31
  export declare function createDocumentationMap(functionDocumentation: {
@@ -7,4 +7,7 @@ export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>
7
7
  export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig): Promise<ProgramStateAnalysis>;
8
8
  export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
9
9
  export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
10
- export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<Record<string, import("./optimizer-types").Diagnostic[]> | undefined>;
10
+ export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<{
11
+ diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
12
+ sdkVersion: number | undefined;
13
+ }>;
@@ -89,6 +89,7 @@ export type Analysis = {
89
89
  export declare function generateOneConfig(buildConfig: JungleQualifier, manifestXML: xmlUtil.Document, dependencyFiles: string[], config: BuildConfig): Promise<{
90
90
  hasTests: boolean;
91
91
  diagnostics: ProgramState["diagnostics"];
92
+ sdkVersion: number | undefined;
92
93
  }>;
93
94
  export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, manifestXML: xmlUtil.Document, options: BuildConfig): Promise<Analysis | PreAnalysis>;
94
95
  /**
@@ -13,7 +13,7 @@ export type RemoteProject = string | {
13
13
  sourcePath?: string;
14
14
  jungleContent?: string[];
15
15
  garminOptLevel?: number;
16
- test?: boolean;
16
+ test?: boolean | string[];
17
17
  };
18
18
  export declare const githubProjects: RemoteProject[];
19
19
  export declare function fetchGitProjects(projects: RemoteProject[], testOnly: boolean, skipRemote: boolean): Promise<(string | {
@@ -21,4 +21,5 @@ export declare function fetchGitProjects(projects: RemoteProject[], testOnly: bo
21
21
  build: boolean | null;
22
22
  options: BuildConfig | null;
23
23
  garminOptLevel: number | null;
24
+ products: string[] | null;
24
25
  })[]>;
@@ -70,6 +70,7 @@ export declare const workerTaskHandlers: {
70
70
  readonly generateOneConfig: (data: GenerateOneConfig["data"]) => Promise<{
71
71
  hasTests: boolean;
72
72
  diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
73
+ sdkVersion: number | undefined;
73
74
  }>;
74
75
  readonly optimizePrgAndDebug: (data: OptimizePrgAndDebug["data"]) => Promise<{
75
76
  sigBuffer: ArrayBufferLike | undefined;
@@ -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_DD4VX53Y = require("./chunk-DD4VX53Y.cjs");
24
+ var import_chunk_PUYLJGKM = require("./chunk-PUYLJGKM.cjs");
25
25
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.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_DD4VX53Y.init_worker_task)();
31
+ (0, import_chunk_PUYLJGKM.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_DD4VX53Y.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_PUYLJGKM.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.27",
4
+ "version": "1.1.29",
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",