@markw65/monkeyc-optimizer 1.1.57 → 1.1.59

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,18 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.59
6
+
7
+ - Getv and Putv can directly access local 0 (Fixes #34)
8
+
9
+ ### 1.1.58
10
+
11
+ - Update to [@markw65/prettier-plugin-monkeyc@1.0.57](https://github.com/markw65/prettier-plugin-monkeyc/blob/main/CHANGELOG.md#1057)
12
+ - Just updates exported types. No change in functionality
13
+ - Properly quote paths in the generated jungle
14
+ - Take account of all references from resource files
15
+ - Include Null in the types of uninitialized variables in their initialize method
16
+
5
17
  ### 1.1.57
6
18
 
7
19
  - Include ConditionalExpression and LogicalExpression in evaluateFunction
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_PUEG4GNZ.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_PUEG4GNZ.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_PUEG4GNZ.createDocumentationMap,
24
- diagnostic: () => import_chunk_PUEG4GNZ.diagnostic,
25
- diagnosticHelper: () => import_chunk_PUEG4GNZ.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_PUEG4GNZ.findNamesInScope,
27
- findUsingForNode: () => import_chunk_PUEG4GNZ.findUsingForNode,
28
- formatAst: () => import_chunk_PUEG4GNZ.formatAst,
29
- formatAstLongLines: () => import_chunk_PUEG4GNZ.formatAstLongLines,
30
- formatScopedName: () => import_chunk_PUEG4GNZ.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_PUEG4GNZ.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_PUEG4GNZ.getApiMapping,
33
- getSuperClasses: () => import_chunk_PUEG4GNZ.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_53Q62QUI.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_53Q62QUI.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_53Q62QUI.createDocumentationMap,
24
+ diagnostic: () => import_chunk_53Q62QUI.diagnostic,
25
+ diagnosticHelper: () => import_chunk_53Q62QUI.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_53Q62QUI.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_53Q62QUI.findUsingForNode,
28
+ formatAst: () => import_chunk_53Q62QUI.formatAst,
29
+ formatAstLongLines: () => import_chunk_53Q62QUI.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_53Q62QUI.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_53Q62QUI.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_53Q62QUI.getApiMapping,
33
+ getSuperClasses: () => import_chunk_53Q62QUI.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_PUEG4GNZ.isClassVariable,
36
- isLocal: () => import_chunk_PUEG4GNZ.isLocal,
37
- isLookupCandidate: () => import_chunk_PUEG4GNZ.isLookupCandidate,
38
- isStateNode: () => import_chunk_PUEG4GNZ.isStateNode,
39
- lookupByFullName: () => import_chunk_PUEG4GNZ.lookupByFullName,
40
- lookupNext: () => import_chunk_PUEG4GNZ.lookupNext,
41
- lookupResultContains: () => import_chunk_PUEG4GNZ.lookupResultContains,
42
- lookupWithType: () => import_chunk_PUEG4GNZ.lookupWithType,
43
- makeToyboxLink: () => import_chunk_PUEG4GNZ.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_PUEG4GNZ.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_PUEG4GNZ.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_PUEG4GNZ.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_PUEG4GNZ.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_PUEG4GNZ.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_PUEG4GNZ.sameLookupResult,
35
+ isClassVariable: () => import_chunk_53Q62QUI.isClassVariable,
36
+ isLocal: () => import_chunk_53Q62QUI.isLocal,
37
+ isLookupCandidate: () => import_chunk_53Q62QUI.isLookupCandidate,
38
+ isStateNode: () => import_chunk_53Q62QUI.isStateNode,
39
+ lookupByFullName: () => import_chunk_53Q62QUI.lookupByFullName,
40
+ lookupNext: () => import_chunk_53Q62QUI.lookupNext,
41
+ lookupResultContains: () => import_chunk_53Q62QUI.lookupResultContains,
42
+ lookupWithType: () => import_chunk_53Q62QUI.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_53Q62QUI.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_53Q62QUI.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_53Q62QUI.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_53Q62QUI.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_53Q62QUI.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_53Q62QUI.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_53Q62QUI.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_PUEG4GNZ.variableDeclarationName,
52
- visitReferences: () => import_chunk_PUEG4GNZ.visitReferences,
53
- visit_resources: () => import_chunk_PUEG4GNZ.visit_resources,
54
- visitorNode: () => import_chunk_PUEG4GNZ.visitorNode
51
+ variableDeclarationName: () => import_chunk_53Q62QUI.variableDeclarationName,
52
+ visitReferences: () => import_chunk_53Q62QUI.visitReferences,
53
+ visit_resources: () => import_chunk_53Q62QUI.visit_resources,
54
+ visitorNode: () => import_chunk_53Q62QUI.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
57
+ var import_chunk_53Q62QUI = require("./chunk-53Q62QUI.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_PUEG4GNZ.init_api)();
61
+ (0, import_chunk_53Q62QUI.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_PUEG4GNZ_exports = {};
30
- __export(chunk_PUEG4GNZ_exports, {
29
+ var chunk_53Q62QUI_exports = {};
30
+ __export(chunk_53Q62QUI_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -133,7 +133,7 @@ __export(chunk_PUEG4GNZ_exports, {
133
133
  visitorNode: () => visitorNode,
134
134
  xml_util_exports: () => xml_util_exports
135
135
  });
136
- module.exports = __toCommonJS(chunk_PUEG4GNZ_exports);
136
+ module.exports = __toCommonJS(chunk_53Q62QUI_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");
@@ -12789,12 +12789,12 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12789
12789
  const order = getPostOrder(graph).reverse();
12790
12790
  const queue = new DataflowQueue();
12791
12791
  let selfClassDecl = null;
12792
- if (!(func.attributes & 8)) {
12793
- const klass = func.stack?.[func.stack?.length - 1].sn;
12794
- if (klass && klass.type === "ClassDeclaration") {
12795
- selfClassDecl = klass;
12796
- }
12792
+ const isStatic = !!(func.attributes & 8);
12793
+ const klass = func.stack?.[func.stack?.length - 1].sn;
12794
+ if (klass && klass.type === "ClassDeclaration") {
12795
+ selfClassDecl = klass;
12797
12796
  }
12797
+ const isInitialize = selfClassDecl && func.name === "initialize";
12798
12798
  order.forEach((block, i) => {
12799
12799
  block.order = i;
12800
12800
  });
@@ -12994,7 +12994,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12994
12994
  );
12995
12995
  }
12996
12996
  }
12997
- if (selfClassDecl) {
12997
+ if (!isStatic && selfClassDecl) {
12998
12998
  const baseObj = getObjectValue(baseElem.type);
12999
12999
  if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_SG7ODKRM.some)(
13000
13000
  baseObj.klass.value,
@@ -13055,6 +13055,9 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
13055
13055
  cur,
13056
13056
  decl.type === "Literal" ? typeFromLiteral(decl) : typeFromTypeStateNode(state, decl, true)
13057
13057
  );
13058
+ if (isInitialize && decl.type === "VariableDeclarator" && !decl.node.init && decl.node.kind === "var" && decl.stack[decl.stack.length - 1].sn === selfClassDecl) {
13059
+ cur.type |= 1;
13060
+ }
13058
13061
  return cur;
13059
13062
  },
13060
13063
  {
@@ -17057,19 +17060,25 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17057
17060
  Object.values(fnMap).forEach((f) => {
17058
17061
  collectNamespaces(f.ast, state);
17059
17062
  });
17060
- const cleanupAll = () => Object.values(fnMap).reduce((changes, f) => {
17061
- (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17062
- const ret = cleanup(state, node, f.ast);
17063
- if (ret === false) {
17064
- changes = true;
17065
- state.removeNodeComments(node, f.ast);
17066
- } else if (ret) {
17067
- changes = true;
17068
- }
17069
- return ret;
17070
- });
17071
- return changes;
17072
- }, false);
17063
+ const cleanupAll = () => {
17064
+ const usedDecls = findRezRefs(state);
17065
+ return Object.values(fnMap).reduce((changes, f) => {
17066
+ (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17067
+ if (usedDecls.has(node)) {
17068
+ return null;
17069
+ }
17070
+ const ret = cleanup(state, node, f.ast, usedDecls);
17071
+ if (ret === false) {
17072
+ changes = true;
17073
+ state.removeNodeComments(node, f.ast);
17074
+ } else if (ret) {
17075
+ changes = true;
17076
+ }
17077
+ return ret;
17078
+ });
17079
+ return changes;
17080
+ }, false);
17081
+ };
17073
17082
  do {
17074
17083
  state.usedByName = {};
17075
17084
  state.calledFunctions = {};
@@ -17080,7 +17089,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17080
17089
  });
17081
17090
  state.exposed = state.nextExposed;
17082
17091
  state.nextExposed = {};
17083
- } while (cleanupAll() && state.config?.iterateOptimizer);
17092
+ if (!cleanupAll())
17093
+ break;
17094
+ } while (state.config?.iterateOptimizer);
17084
17095
  delete state.pre;
17085
17096
  delete state.post;
17086
17097
  if (state.config?.minimizeModules ?? true) {
@@ -17129,6 +17140,53 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17129
17140
  sdkVersion: state.sdkVersion
17130
17141
  };
17131
17142
  }
17143
+ function findRezRefs(state) {
17144
+ const usedDecls = /* @__PURE__ */ new Set();
17145
+ state.rezAst && visitReferences(
17146
+ state,
17147
+ state.rezAst,
17148
+ null,
17149
+ false,
17150
+ (node, results, error) => {
17151
+ if (error)
17152
+ return;
17153
+ results.forEach(
17154
+ (result) => result.results.forEach((sn) => {
17155
+ switch (sn.type) {
17156
+ case "ModuleDeclaration":
17157
+ case "Program":
17158
+ case "BlockStatement":
17159
+ return;
17160
+ case "Identifier":
17161
+ case "BinaryExpression":
17162
+ return;
17163
+ case "EnumStringMember":
17164
+ if (sn.system)
17165
+ return;
17166
+ usedDecls.add(sn);
17167
+ break;
17168
+ case "ClassDeclaration":
17169
+ case "FunctionDeclaration":
17170
+ case "EnumDeclaration":
17171
+ case "TypedefDeclaration":
17172
+ if (sn.node.attrs?.system)
17173
+ return;
17174
+ case "VariableDeclarator":
17175
+ if (sn.fullName.startsWith("$.Toybox") || sn.fullName.startsWith("$.Rez")) {
17176
+ return;
17177
+ }
17178
+ usedDecls.add(sn.node);
17179
+ break;
17180
+ default:
17181
+ unhandledType(sn);
17182
+ }
17183
+ })
17184
+ );
17185
+ return void 0;
17186
+ }
17187
+ );
17188
+ return usedDecls;
17189
+ }
17132
17190
  function maybeCalled(state, func) {
17133
17191
  if (!func.body) {
17134
17192
  return true;
@@ -17149,13 +17207,15 @@ function maybeCalled(state, func) {
17149
17207
  }
17150
17208
  return false;
17151
17209
  }
17152
- function cleanup(state, node, ast) {
17210
+ function cleanup(state, node, ast, usedNodes) {
17153
17211
  switch (node.type) {
17154
17212
  case "ThisExpression":
17155
17213
  node.text = "self";
17156
17214
  break;
17157
17215
  case "EnumStringBody":
17158
17216
  if (node.members.every((m) => {
17217
+ if (usedNodes.has(m))
17218
+ return false;
17159
17219
  const name = "name" in m ? m.name : m.id.name;
17160
17220
  return (0, import_chunk_MBTLUWXR.hasProperty)(state.index, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.exposed, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.usedByName, name);
17161
17221
  })) {
@@ -17303,6 +17363,7 @@ var init_mc_rewrite = (0, import_chunk_ABYVSU2C.__esm)({
17303
17363
  init_unused_exprs();
17304
17364
  (0, import_chunk_SG7ODKRM.init_util)();
17305
17365
  init_variable_renamer();
17366
+ init_data_flow();
17306
17367
  }
17307
17368
  });
17308
17369
  var negativeFixups;
@@ -17975,126 +18036,132 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
17975
18036
  }
17976
18037
  checkResults([id.name, [{ parent: parent.sn, results }]], id);
17977
18038
  };
17978
- state.pre = (node) => {
17979
- if (filter && !filter(node))
17980
- return [];
17981
- switch (node.type) {
17982
- case "AttributeList":
18039
+ const { pre, post } = state;
18040
+ try {
18041
+ state.pre = (node) => {
18042
+ if (filter && !filter(node))
17983
18043
  return [];
17984
- case "UnaryExpression":
17985
- if (node.operator === ":")
18044
+ switch (node.type) {
18045
+ case "AttributeList":
17986
18046
  return [];
17987
- break;
17988
- case "BinaryExpression":
17989
- if (node.operator === "has") {
17990
- if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
17991
- if (!name || node.right.argument.name === name) {
17992
- return checkResults(
17993
- lookup2({
17994
- type: "MemberExpression",
17995
- object: node.left,
17996
- property: node.right.argument,
17997
- computed: false
17998
- }),
17999
- node
18000
- );
18047
+ case "UnaryExpression":
18048
+ if (node.operator === ":")
18049
+ return [];
18050
+ break;
18051
+ case "BinaryExpression":
18052
+ if (node.operator === "has") {
18053
+ if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
18054
+ if (!name || node.right.argument.name === name) {
18055
+ return checkResults(
18056
+ lookup2({
18057
+ type: "MemberExpression",
18058
+ object: node.left,
18059
+ property: node.right.argument,
18060
+ computed: false
18061
+ }),
18062
+ node
18063
+ );
18064
+ }
18001
18065
  }
18002
18066
  }
18003
- }
18004
- break;
18005
- case "CallExpression":
18006
- if (node.callee.type === "Identifier") {
18007
- if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
18008
- checkResults(lookup2(node.callee, true), node.callee);
18067
+ break;
18068
+ case "CallExpression":
18069
+ if (node.callee.type === "Identifier") {
18070
+ if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
18071
+ checkResults(lookup2(node.callee, true), node.callee);
18072
+ }
18073
+ return ["arguments"];
18009
18074
  }
18010
- return ["arguments"];
18011
- }
18012
- break;
18013
- case "Identifier":
18014
- if (!name || node.name === name) {
18015
- return checkResults(lookup2(node), node);
18016
- }
18017
- break;
18018
- case "MemberExpression": {
18019
- const property = isLookupCandidate(node);
18020
- if (property) {
18021
- if (!name || property.name === name) {
18022
- return checkResults(lookup2(node), node) || ["object"];
18075
+ break;
18076
+ case "Identifier":
18077
+ if (!name || node.name === name) {
18078
+ return checkResults(lookup2(node), node);
18023
18079
  }
18024
- return ["object"];
18025
- }
18026
- break;
18027
- }
18028
- case "MethodDefinition": {
18029
- if (!state.inType) {
18030
- throw new Error("Method definition outside of type!");
18031
- }
18032
- if (node.params) {
18033
- node.params.forEach((param) => {
18034
- if (param.type === "BinaryExpression") {
18035
- state.traverse(param.right);
18080
+ break;
18081
+ case "MemberExpression": {
18082
+ const property = isLookupCandidate(node);
18083
+ if (property) {
18084
+ if (!name || property.name === name) {
18085
+ return checkResults(lookup2(node), node) || ["object"];
18036
18086
  }
18037
- });
18038
- }
18039
- return ["returnType"];
18040
- }
18041
- case "ModuleDeclaration":
18042
- if (includeDefs) {
18043
- visitDef(node.id);
18044
- }
18045
- return ["body"];
18046
- case "ClassDeclaration":
18047
- if (includeDefs) {
18048
- visitDef(node.id, node);
18049
- }
18050
- return ["body", "superClass"];
18051
- case "FunctionDeclaration":
18052
- if (includeDefs) {
18053
- visitDef(node.id, node);
18054
- }
18055
- return ["params", "returnType", "body"];
18056
- case "TypedefDeclaration":
18057
- if (includeDefs) {
18058
- visitDef(node.id, node, "type_decls");
18059
- }
18060
- return ["ts"];
18061
- case "VariableDeclarator":
18062
- if (includeDefs) {
18063
- visitDef(node.id, node);
18087
+ return ["object"];
18088
+ }
18089
+ break;
18064
18090
  }
18065
- if (node.id.type === "BinaryExpression") {
18066
- state.traverse(node.id.right);
18091
+ case "MethodDefinition": {
18092
+ if (!state.inType) {
18093
+ throw new Error("Method definition outside of type!");
18094
+ }
18095
+ if (node.params) {
18096
+ node.params.forEach((param) => {
18097
+ if (param.type === "BinaryExpression") {
18098
+ state.traverse(param.right);
18099
+ }
18100
+ });
18101
+ }
18102
+ return ["returnType"];
18067
18103
  }
18068
- return ["init"];
18069
- case "EnumDeclaration":
18070
- if (includeDefs) {
18071
- if (node.id) {
18104
+ case "ModuleDeclaration":
18105
+ if (includeDefs) {
18106
+ visitDef(node.id);
18107
+ }
18108
+ return ["body"];
18109
+ case "ClassDeclaration":
18110
+ if (includeDefs) {
18111
+ visitDef(node.id, node);
18112
+ }
18113
+ return ["body", "superClass"];
18114
+ case "FunctionDeclaration":
18115
+ if (includeDefs) {
18116
+ visitDef(node.id, node);
18117
+ }
18118
+ return ["params", "returnType", "body"];
18119
+ case "TypedefDeclaration":
18120
+ if (includeDefs) {
18072
18121
  visitDef(node.id, node, "type_decls");
18073
18122
  }
18123
+ return ["ts"];
18124
+ case "VariableDeclarator":
18125
+ if (includeDefs) {
18126
+ visitDef(node.id, node);
18127
+ }
18128
+ if (node.id.type === "BinaryExpression") {
18129
+ state.traverse(node.id.right);
18130
+ }
18131
+ return ["init"];
18132
+ case "EnumDeclaration":
18133
+ if (includeDefs) {
18134
+ if (node.id) {
18135
+ visitDef(node.id, node, "type_decls");
18136
+ }
18137
+ break;
18138
+ }
18139
+ return [];
18140
+ case "EnumStringMember": {
18141
+ if (!filter || filter(node.id)) {
18142
+ checkResults(
18143
+ [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18144
+ node
18145
+ );
18146
+ }
18074
18147
  break;
18075
18148
  }
18076
- return [];
18077
- case "EnumStringMember": {
18078
- if (!filter || filter(node.id)) {
18079
- checkResults(
18080
- [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18081
- node
18082
- );
18083
- }
18084
- break;
18149
+ case "CatchClause":
18150
+ if (includeDefs)
18151
+ break;
18152
+ if (node.param && node.param.type !== "Identifier") {
18153
+ state.traverse(node.param.right);
18154
+ }
18155
+ return ["body"];
18085
18156
  }
18086
- case "CatchClause":
18087
- if (includeDefs)
18088
- break;
18089
- if (node.param && node.param.type !== "Identifier") {
18090
- state.traverse(node.param.right);
18091
- }
18092
- return ["body"];
18093
- }
18094
- return null;
18095
- };
18096
- collectNamespaces(ast, state);
18097
- delete state.pre;
18157
+ return null;
18158
+ };
18159
+ delete state.post;
18160
+ collectNamespaces(ast, state);
18161
+ } finally {
18162
+ state.pre = pre;
18163
+ state.post = post;
18164
+ }
18098
18165
  }
18099
18166
  var init_visitor = (0, import_chunk_ABYVSU2C.__esm)({
18100
18167
  "src/visitor.ts"() {
@@ -20353,19 +20420,19 @@ function opReadsLocal(bytecode) {
20353
20420
  case 67:
20354
20421
  case 68:
20355
20422
  case 42:
20423
+ case 13:
20424
+ case 14:
20356
20425
  return 0;
20357
20426
  case 70:
20358
20427
  return bytecode.arg.local;
20359
20428
  case 18:
20360
20429
  return bytecode.arg;
20361
20430
  case 19:
20362
- case 14:
20363
20431
  case 17:
20364
20432
  case 73:
20365
20433
  case 21:
20366
20434
  case 15:
20367
20435
  case 72:
20368
- case 13:
20369
20436
  case 69:
20370
20437
  case 71:
20371
20438
  case 16:
@@ -22012,11 +22079,11 @@ function localDCE(func, context) {
22012
22079
  dceInfo.stack.push({ dead: false });
22013
22080
  }
22014
22081
  dceInfo.locals.delete(bytecode.arg);
22015
- break;
22082
+ continue;
22016
22083
  }
22017
22084
  case 2:
22018
22085
  dceInfo.stack.push({ dead: true, deps: [i] });
22019
- break;
22086
+ continue;
22020
22087
  case 46: {
22021
22088
  const item = dceInfo.stack.pop();
22022
22089
  if (item?.dead) {
@@ -22028,7 +22095,7 @@ function localDCE(func, context) {
22028
22095
  dceInfo.stack[dceInfo.stack.length - 1 - bytecode.arg].dead = false;
22029
22096
  }
22030
22097
  }
22031
- break;
22098
+ continue;
22032
22099
  }
22033
22100
  case 70:
22034
22101
  case 68:
@@ -22061,11 +22128,7 @@ function localDCE(func, context) {
22061
22128
  item.deps.push(i);
22062
22129
  reportNop(item);
22063
22130
  item.deps.forEach((index) => makeNop(block.bytecodes[index]));
22064
- } else {
22065
- const local = opReadsLocal(bytecode);
22066
- if (local != null) {
22067
- dceInfo.locals.add(local);
22068
- }
22131
+ continue;
22069
22132
  }
22070
22133
  break;
22071
22134
  }
@@ -22095,10 +22158,10 @@ function localDCE(func, context) {
22095
22158
  makePopv(bytecode);
22096
22159
  dceInfo.stack.push({ dead: true, deps: item.deps.slice() });
22097
22160
  dceInfo.stack.push({ dead: true, deps: [i] });
22098
- } else {
22099
- dceInfo.stack.push({ dead: false });
22100
- dceInfo.stack.push({ dead: false });
22161
+ continue;
22101
22162
  }
22163
+ dceInfo.stack.push({ dead: false });
22164
+ dceInfo.stack.push({ dead: false });
22102
22165
  break;
22103
22166
  }
22104
22167
  case 21:
@@ -22115,16 +22178,16 @@ function localDCE(func, context) {
22115
22178
  makePopv(bytecode);
22116
22179
  item.deps.forEach((index) => makeNop(block.bytecodes[index]));
22117
22180
  dceInfo.stack.push({ dead: true, deps: [i] });
22118
- } else {
22119
- dceInfo.stack.push({ dead: false });
22181
+ continue;
22120
22182
  }
22183
+ dceInfo.stack.push({ dead: false });
22121
22184
  break;
22122
22185
  }
22123
22186
  case 51:
22124
22187
  case 15:
22125
22188
  case 72:
22126
22189
  if (block.exsucc) {
22127
- liveInLocals.get(block.exsucc)?.forEach((local) => dceInfo.locals.add(local));
22190
+ liveInLocals.get(block.exsucc)?.forEach((local2) => dceInfo.locals.add(local2));
22128
22191
  }
22129
22192
  case 17:
22130
22193
  case 73:
@@ -22154,6 +22217,10 @@ function localDCE(func, context) {
22154
22217
  default:
22155
22218
  unhandledType(bytecode);
22156
22219
  }
22220
+ const local = opReadsLocal(bytecode);
22221
+ if (local != null) {
22222
+ dceInfo.locals.add(local);
22223
+ }
22157
22224
  }
22158
22225
  if (changes) {
22159
22226
  anyChanges = true;
@@ -22413,6 +22480,8 @@ function minimizeLocals2(func, equivSets, context) {
22413
22480
  }
22414
22481
  break;
22415
22482
  }
22483
+ case 14:
22484
+ case 13:
22416
22485
  case 42:
22417
22486
  case 68:
22418
22487
  case 67: {
@@ -22459,6 +22528,8 @@ function computeSplitRanges(func, equivSets) {
22459
22528
  case 70:
22460
22529
  case 42:
22461
22530
  case 18:
22531
+ case 13:
22532
+ case 14:
22462
22533
  recordLocalRead(locals, bc);
22463
22534
  break;
22464
22535
  case 19: {
@@ -28729,7 +28800,14 @@ async function generateOptimizedProject(options) {
28729
28800
  const jungle_dir = path4.resolve(workspace, config.outputPath);
28730
28801
  await fs6.mkdir(jungle_dir, { recursive: true });
28731
28802
  const relative_path = (s) => path4.relative(jungle_dir, s);
28732
- let relative_manifest = relative_path(manifest);
28803
+ const quoted_relative_path = (s) => {
28804
+ const rel = relative_path(s);
28805
+ if (/[^-*._$/\\\w]/.test(rel)) {
28806
+ return `"${rel}"`;
28807
+ }
28808
+ return rel;
28809
+ };
28810
+ let relative_manifest = quoted_relative_path(manifest);
28733
28811
  const manifestOk = (!config.checkManifest || await checkManifest(
28734
28812
  xml,
28735
28813
  targets.map((t) => t.product)
@@ -28875,8 +28953,8 @@ async function generateOptimizedProject(options) {
28875
28953
  ).join(";")}`
28876
28954
  );
28877
28955
  }
28878
- process_field(prefix, qualifier, "resourcePath", relative_path);
28879
- process_field(prefix, qualifier, "personality", relative_path);
28956
+ process_field(prefix, qualifier, "resourcePath", quoted_relative_path);
28957
+ process_field(prefix, qualifier, "personality", quoted_relative_path);
28880
28958
  process_field(prefix, qualifier, "excludeAnnotations");
28881
28959
  const qLang = qualifier.lang;
28882
28960
  if (qLang) {
@@ -28885,7 +28963,7 @@ async function generateOptimizedProject(options) {
28885
28963
  if ((0, import_chunk_MBTLUWXR.hasProperty)(devLang, key) || !(0, import_chunk_MBTLUWXR.hasProperty)(languagesToInclude, key)) {
28886
28964
  return null;
28887
28965
  }
28888
- const mapped = map_field(qLang, key, relative_path);
28966
+ const mapped = map_field(qLang, key, quoted_relative_path);
28889
28967
  if (!mapped)
28890
28968
  return null;
28891
28969
  return [key, mapped];
@@ -29068,7 +29146,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29068
29146
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
29069
29147
  Object.values(fnMap).map((v) => v.output)
29070
29148
  );
29071
- if (source_time < opt_time && 1713624391103 < opt_time) {
29149
+ if (source_time < opt_time && 1713974596186 < opt_time) {
29072
29150
  return {
29073
29151
  hasTests,
29074
29152
  diagnostics: prevDiagnostics,
@@ -29107,7 +29185,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29107
29185
  hasTests: hasTests2,
29108
29186
  diagnostics,
29109
29187
  sdkVersion,
29110
- optimizerVersion: "1.1.57",
29188
+ optimizerVersion: "1.1.59",
29111
29189
  ...Object.fromEntries(
29112
29190
  configOptionsToCheck.map((option) => [option, config[option]])
29113
29191
  )
@@ -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_PUEG4GNZ.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_PUEG4GNZ.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_53Q62QUI.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_53Q62QUI.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_PUEG4GNZ.defaultConfig,
25
- display: () => import_chunk_PUEG4GNZ.display,
26
- generateOneConfig: () => import_chunk_PUEG4GNZ.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_PUEG4GNZ.generateOptimizedProject,
28
- getConfig: () => import_chunk_PUEG4GNZ.getConfig,
29
- getProjectAnalysis: () => import_chunk_PUEG4GNZ.getProjectAnalysis,
30
- get_jungle: () => import_chunk_PUEG4GNZ.get_jungle,
31
- isErrorWithLocation: () => import_chunk_PUEG4GNZ.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_PUEG4GNZ.launchSimulator,
33
- manifestProducts: () => import_chunk_PUEG4GNZ.manifestProducts,
34
- mctree: () => import_chunk_PUEG4GNZ.mctree,
35
- simulateProgram: () => import_chunk_PUEG4GNZ.simulateProgram
24
+ defaultConfig: () => import_chunk_53Q62QUI.defaultConfig,
25
+ display: () => import_chunk_53Q62QUI.display,
26
+ generateOneConfig: () => import_chunk_53Q62QUI.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_53Q62QUI.generateOptimizedProject,
28
+ getConfig: () => import_chunk_53Q62QUI.getConfig,
29
+ getProjectAnalysis: () => import_chunk_53Q62QUI.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_53Q62QUI.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_53Q62QUI.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_53Q62QUI.launchSimulator,
33
+ manifestProducts: () => import_chunk_53Q62QUI.manifestProducts,
34
+ mctree: () => import_chunk_53Q62QUI.mctree,
35
+ simulateProgram: () => import_chunk_53Q62QUI.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
38
+ var import_chunk_53Q62QUI = require("./chunk-53Q62QUI.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_PUEG4GNZ.init_optimizer)();
42
+ (0, import_chunk_53Q62QUI.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_PUEG4GNZ.SectionKinds,
22
- appSupport: () => import_chunk_PUEG4GNZ.appSupport,
23
- connectiq: () => import_chunk_PUEG4GNZ.connectiq,
24
- getDeviceInfo: () => import_chunk_PUEG4GNZ.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_PUEG4GNZ.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_PUEG4GNZ.getLanguages,
27
- getSdkPath: () => import_chunk_PUEG4GNZ.getSdkPath,
28
- isWin: () => import_chunk_PUEG4GNZ.isWin,
29
- optimizeProgram: () => import_chunk_PUEG4GNZ.optimizeProgram,
30
- readPrg: () => import_chunk_PUEG4GNZ.readPrg,
31
- readPrgWithOffsets: () => import_chunk_PUEG4GNZ.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_PUEG4GNZ.xml_util_exports
21
+ SectionKinds: () => import_chunk_53Q62QUI.SectionKinds,
22
+ appSupport: () => import_chunk_53Q62QUI.appSupport,
23
+ connectiq: () => import_chunk_53Q62QUI.connectiq,
24
+ getDeviceInfo: () => import_chunk_53Q62QUI.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_53Q62QUI.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_53Q62QUI.getLanguages,
27
+ getSdkPath: () => import_chunk_53Q62QUI.getSdkPath,
28
+ isWin: () => import_chunk_53Q62QUI.isWin,
29
+ optimizeProgram: () => import_chunk_53Q62QUI.optimizeProgram,
30
+ readPrg: () => import_chunk_53Q62QUI.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_53Q62QUI.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_53Q62QUI.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
35
+ var import_chunk_53Q62QUI = require("./chunk-53Q62QUI.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_PUEG4GNZ.init_sdk_util)();
39
+ (0, import_chunk_53Q62QUI.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -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_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
24
+ var import_chunk_53Q62QUI = require("./chunk-53Q62QUI.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_PUEG4GNZ.init_worker_task)();
31
+ (0, import_chunk_53Q62QUI.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_PUEG4GNZ.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_53Q62QUI.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.57",
4
+ "version": "1.1.59",
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",
@@ -52,7 +52,7 @@
52
52
  "author": "markw65",
53
53
  "license": "MIT",
54
54
  "dependencies": {
55
- "@markw65/prettier-plugin-monkeyc": "^1.0.56"
55
+ "@markw65/prettier-plugin-monkeyc": "^1.0.57"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@markw65/peggy-optimizer": "^1.0.1",