@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 +12 -0
- package/build/api.cjs +34 -34
- package/build/{chunk-PUEG4GNZ.cjs → chunk-53Q62QUI.cjs} +230 -152
- package/build/optimizer.cjs +16 -16
- package/build/sdk-util.cjs +14 -14
- package/build/worker-thread.cjs +3 -3
- package/package.json +2 -2
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: () =>
|
|
22
|
-
collectNamespaces: () =>
|
|
23
|
-
createDocumentationMap: () =>
|
|
24
|
-
diagnostic: () =>
|
|
25
|
-
diagnosticHelper: () =>
|
|
26
|
-
findNamesInScope: () =>
|
|
27
|
-
findUsingForNode: () =>
|
|
28
|
-
formatAst: () =>
|
|
29
|
-
formatAstLongLines: () =>
|
|
30
|
-
formatScopedName: () =>
|
|
31
|
-
getApiFunctionInfo: () =>
|
|
32
|
-
getApiMapping: () =>
|
|
33
|
-
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: () =>
|
|
36
|
-
isLocal: () =>
|
|
37
|
-
isLookupCandidate: () =>
|
|
38
|
-
isStateNode: () =>
|
|
39
|
-
lookupByFullName: () =>
|
|
40
|
-
lookupNext: () =>
|
|
41
|
-
lookupResultContains: () =>
|
|
42
|
-
lookupWithType: () =>
|
|
43
|
-
makeToyboxLink: () =>
|
|
44
|
-
mapVarDeclsByType: () =>
|
|
45
|
-
markInvokeClassMethod: () =>
|
|
46
|
-
parseSdkVersion: () =>
|
|
47
|
-
resolveDiagnostics: () =>
|
|
48
|
-
resolveDiagnosticsMap: () =>
|
|
49
|
-
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: () =>
|
|
52
|
-
visitReferences: () =>
|
|
53
|
-
visit_resources: () =>
|
|
54
|
-
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
|
|
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,
|
|
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
|
|
30
|
-
__export(
|
|
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(
|
|
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
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
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 = () =>
|
|
17061
|
-
|
|
17062
|
-
|
|
17063
|
-
|
|
17064
|
-
|
|
17065
|
-
|
|
17066
|
-
|
|
17067
|
-
|
|
17068
|
-
|
|
17069
|
-
|
|
17070
|
-
|
|
17071
|
-
|
|
17072
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
case "AttributeList":
|
|
18039
|
+
const { pre, post } = state;
|
|
18040
|
+
try {
|
|
18041
|
+
state.pre = (node) => {
|
|
18042
|
+
if (filter && !filter(node))
|
|
17983
18043
|
return [];
|
|
17984
|
-
|
|
17985
|
-
|
|
18044
|
+
switch (node.type) {
|
|
18045
|
+
case "AttributeList":
|
|
17986
18046
|
return [];
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
17995
|
-
|
|
17996
|
-
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
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
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
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
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
|
|
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
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18066
|
-
state.
|
|
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
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
|
|
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
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
|
|
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
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
|
|
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
|
-
|
|
22082
|
+
continue;
|
|
22016
22083
|
}
|
|
22017
22084
|
case 2:
|
|
22018
22085
|
dceInfo.stack.push({ dead: true, deps: [i] });
|
|
22019
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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((
|
|
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
|
-
|
|
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",
|
|
28879
|
-
process_field(prefix, qualifier, "personality",
|
|
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,
|
|
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 &&
|
|
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.
|
|
29188
|
+
optimizerVersion: "1.1.59",
|
|
29111
29189
|
...Object.fromEntries(
|
|
29112
29190
|
configOptionsToCheck.map((option) => [option, config[option]])
|
|
29113
29191
|
)
|
package/build/optimizer.cjs
CHANGED
|
@@ -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: () =>
|
|
22
|
-
buildOptimizedProject: () =>
|
|
21
|
+
StateNodeAttributes: () => import_chunk_53Q62QUI.StateNodeAttributes,
|
|
22
|
+
buildOptimizedProject: () => import_chunk_53Q62QUI.buildOptimizedProject,
|
|
23
23
|
copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
|
|
24
|
-
defaultConfig: () =>
|
|
25
|
-
display: () =>
|
|
26
|
-
generateOneConfig: () =>
|
|
27
|
-
generateOptimizedProject: () =>
|
|
28
|
-
getConfig: () =>
|
|
29
|
-
getProjectAnalysis: () =>
|
|
30
|
-
get_jungle: () =>
|
|
31
|
-
isErrorWithLocation: () =>
|
|
32
|
-
launchSimulator: () =>
|
|
33
|
-
manifestProducts: () =>
|
|
34
|
-
mctree: () =>
|
|
35
|
-
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
|
|
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,
|
|
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,
|
package/build/sdk-util.cjs
CHANGED
|
@@ -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: () =>
|
|
22
|
-
appSupport: () =>
|
|
23
|
-
connectiq: () =>
|
|
24
|
-
getDeviceInfo: () =>
|
|
25
|
-
getFunctionDocumentation: () =>
|
|
26
|
-
getLanguages: () =>
|
|
27
|
-
getSdkPath: () =>
|
|
28
|
-
isWin: () =>
|
|
29
|
-
optimizeProgram: () =>
|
|
30
|
-
readPrg: () =>
|
|
31
|
-
readPrgWithOffsets: () =>
|
|
32
|
-
xmlUtil: () =>
|
|
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
|
|
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,
|
|
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,
|
package/build/worker-thread.cjs
CHANGED
|
@@ -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
|
|
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,
|
|
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,
|
|
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.
|
|
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.
|
|
55
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.57"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@markw65/peggy-optimizer": "^1.0.1",
|