@markw65/monkeyc-optimizer 1.1.6 → 1.1.8
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 +18 -1
- package/build/api.cjs +3302 -242
- package/build/optimizer.cjs +62 -61
- package/build/sdk-util.cjs +25 -1
- package/build/src/api.d.ts +17 -1
- package/build/src/optimizer-types.d.ts +12 -8
- package/build/src/sdk-util.d.ts +5 -0
- package/build/src/type-flow/types.d.ts +2 -3
- package/build/src/type-flow.d.ts +1 -1
- package/build/src/visitor.d.ts +1 -1
- package/package.json +1 -1
package/build/optimizer.cjs
CHANGED
|
@@ -5035,15 +5035,6 @@ function findCalleesByNode(state, callee) {
|
|
|
5035
5035
|
return ((hasProperty(state.allFunctions, name) && state.allFunctions[name]) || null);
|
|
5036
5036
|
}
|
|
5037
5037
|
|
|
5038
|
-
;// CONCATENATED MODULE: ./src/optimizer-types.ts
|
|
5039
|
-
var StateNodeAttributes;
|
|
5040
|
-
(function (StateNodeAttributes) {
|
|
5041
|
-
StateNodeAttributes[StateNodeAttributes["PUBLIC"] = 1] = "PUBLIC";
|
|
5042
|
-
StateNodeAttributes[StateNodeAttributes["PROTECTED"] = 2] = "PROTECTED";
|
|
5043
|
-
StateNodeAttributes[StateNodeAttributes["PRIVATE"] = 4] = "PRIVATE";
|
|
5044
|
-
StateNodeAttributes[StateNodeAttributes["STATIC"] = 8] = "STATIC";
|
|
5045
|
-
})(StateNodeAttributes || (StateNodeAttributes = {}));
|
|
5046
|
-
|
|
5047
5038
|
;// CONCATENATED MODULE: ./src/variable-renamer.ts
|
|
5048
5039
|
|
|
5049
5040
|
|
|
@@ -5084,7 +5075,7 @@ function renameVariable(state, locals, declName) {
|
|
|
5084
5075
|
let ok = false;
|
|
5085
5076
|
let i;
|
|
5086
5077
|
for (i = state.stack.length; i--;) {
|
|
5087
|
-
const elm = state.stack[i];
|
|
5078
|
+
const elm = state.stack[i].sn;
|
|
5088
5079
|
if (ok) {
|
|
5089
5080
|
if ((0,external_api_cjs_namespaceObject.hasProperty)(elm.decls, name)) {
|
|
5090
5081
|
break;
|
|
@@ -5110,7 +5101,6 @@ function renameVariable(state, locals, declName) {
|
|
|
5110
5101
|
|
|
5111
5102
|
|
|
5112
5103
|
|
|
5113
|
-
|
|
5114
5104
|
// Note: Keep in sync with replaceInlinedSubExpression below
|
|
5115
5105
|
function inlinableSubExpression(expr) {
|
|
5116
5106
|
while (true) {
|
|
@@ -5189,9 +5179,9 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
5189
5179
|
// if decl is a local, it also can't be changed
|
|
5190
5180
|
// by a call to another function.
|
|
5191
5181
|
for (let i = 0;; i++) {
|
|
5192
|
-
if (!state.stack[i] || decl.stack[i] !== state.stack[i])
|
|
5182
|
+
if (!state.stack[i] || decl.stack[i]?.sn !== state.stack[i].sn)
|
|
5193
5183
|
return false;
|
|
5194
|
-
if (state.stack[i].type === "FunctionDeclaration")
|
|
5184
|
+
if (state.stack[i].sn.type === "FunctionDeclaration")
|
|
5195
5185
|
return true;
|
|
5196
5186
|
}
|
|
5197
5187
|
}
|
|
@@ -5328,7 +5318,7 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
5328
5318
|
}
|
|
5329
5319
|
return null;
|
|
5330
5320
|
};
|
|
5331
|
-
state.stack = func.stack;
|
|
5321
|
+
state.stack = func.stack.concat({ sn: func });
|
|
5332
5322
|
state.traverse(func.node.body);
|
|
5333
5323
|
}
|
|
5334
5324
|
finally {
|
|
@@ -5439,9 +5429,7 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
5439
5429
|
// lookup determines static-ness of the lookup context based on seeing
|
|
5440
5430
|
// a static FunctionDeclaration, but the FunctionDeclaration's stack
|
|
5441
5431
|
// doesn't include the FunctionDeclaration itself.
|
|
5442
|
-
const
|
|
5443
|
-
? func.stack.concat(func)
|
|
5444
|
-
: func.stack;
|
|
5432
|
+
const lookupStack = func.stack.concat({ sn: func });
|
|
5445
5433
|
try {
|
|
5446
5434
|
state.pre = (node) => {
|
|
5447
5435
|
if (failed)
|
|
@@ -5497,7 +5485,7 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
5497
5485
|
}
|
|
5498
5486
|
return null;
|
|
5499
5487
|
}
|
|
5500
|
-
const replacement = fixNodeScope(state, node,
|
|
5488
|
+
const replacement = fixNodeScope(state, node, lookupStack);
|
|
5501
5489
|
if (!replacement) {
|
|
5502
5490
|
failed = true;
|
|
5503
5491
|
inlineDiagnostic(state, func, call, `Failed to resolve '${node.name}'`);
|
|
@@ -5831,10 +5819,11 @@ function inlineFunction(state, func, call, context) {
|
|
|
5831
5819
|
if (!typecheckFalse) {
|
|
5832
5820
|
return ret;
|
|
5833
5821
|
}
|
|
5834
|
-
const
|
|
5835
|
-
if (!
|
|
5822
|
+
const callerElem = state.stack.find((elem) => elem.sn.type === "FunctionDeclaration");
|
|
5823
|
+
if (!callerElem) {
|
|
5836
5824
|
return ret;
|
|
5837
5825
|
}
|
|
5826
|
+
const callerSn = callerElem.sn;
|
|
5838
5827
|
const caller = callerSn.node;
|
|
5839
5828
|
if (!caller.attrs) {
|
|
5840
5829
|
caller.attrs = withLoc({
|
|
@@ -5953,6 +5942,15 @@ function fixNodeScope(state, lookupNode, nodeStack) {
|
|
|
5953
5942
|
return null;
|
|
5954
5943
|
}
|
|
5955
5944
|
|
|
5945
|
+
;// CONCATENATED MODULE: ./src/optimizer-types.ts
|
|
5946
|
+
var StateNodeAttributes;
|
|
5947
|
+
(function (StateNodeAttributes) {
|
|
5948
|
+
StateNodeAttributes[StateNodeAttributes["PUBLIC"] = 1] = "PUBLIC";
|
|
5949
|
+
StateNodeAttributes[StateNodeAttributes["PROTECTED"] = 2] = "PROTECTED";
|
|
5950
|
+
StateNodeAttributes[StateNodeAttributes["PRIVATE"] = 4] = "PRIVATE";
|
|
5951
|
+
StateNodeAttributes[StateNodeAttributes["STATIC"] = 8] = "STATIC";
|
|
5952
|
+
})(StateNodeAttributes || (StateNodeAttributes = {}));
|
|
5953
|
+
|
|
5956
5954
|
;// CONCATENATED MODULE: ./src/pragma-checker.ts
|
|
5957
5955
|
|
|
5958
5956
|
|
|
@@ -6891,7 +6889,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
6891
6889
|
});
|
|
6892
6890
|
}
|
|
6893
6891
|
if (wantsAllRefs) {
|
|
6894
|
-
const scope = state.
|
|
6892
|
+
const scope = state.top().sn;
|
|
6895
6893
|
if (scope.node === node &&
|
|
6896
6894
|
scope.type === "BlockStatement" &&
|
|
6897
6895
|
scope.decls &&
|
|
@@ -8867,7 +8865,7 @@ function unionInto(to, from) {
|
|
|
8867
8865
|
return true;
|
|
8868
8866
|
}
|
|
8869
8867
|
const newTags = to.type | from.type;
|
|
8870
|
-
if (!(from.type & ~
|
|
8868
|
+
if (!(from.type & ~SingletonTypeTagsConst)) {
|
|
8871
8869
|
// - Adding singletons never affects the data.
|
|
8872
8870
|
if (newTags === to.type)
|
|
8873
8871
|
return false;
|
|
@@ -9129,7 +9127,7 @@ function clearValuesUnder(v, tag, clearTag = false) {
|
|
|
9129
9127
|
const newTag = clearTag ? v.type & ~tag : v.type | tag;
|
|
9130
9128
|
// If the incoming type consists of singletons,
|
|
9131
9129
|
// we can always merge it without affecting our data.
|
|
9132
|
-
tag &= ~
|
|
9130
|
+
tag &= ~SingletonTypeTagsConst;
|
|
9133
9131
|
if (!tag || v.value == null) {
|
|
9134
9132
|
v.type = newTag;
|
|
9135
9133
|
return;
|
|
@@ -9313,7 +9311,7 @@ function typeTagName(tag) {
|
|
|
9313
9311
|
}
|
|
9314
9312
|
}
|
|
9315
9313
|
const LastTypeTag = 262144 /* TypeTag.Typedef */;
|
|
9316
|
-
const
|
|
9314
|
+
const SingletonTypeTagsConst = 1 /* TypeTag.Null */ | 2 /* TypeTag.False */ | 4 /* TypeTag.True */;
|
|
9317
9315
|
const UnionDataTypeTagsConst = 512 /* TypeTag.Array */ |
|
|
9318
9316
|
1024 /* TypeTag.Dictionary */ |
|
|
9319
9317
|
2048 /* TypeTag.Method */ |
|
|
@@ -9336,7 +9334,7 @@ const ObjectLikeTagsConst = 6 /* TypeTag.Boolean */ |
|
|
|
9336
9334
|
1024 /* TypeTag.Dictionary */ |
|
|
9337
9335
|
2048 /* TypeTag.Method */ |
|
|
9338
9336
|
65536 /* TypeTag.Enum */;
|
|
9339
|
-
const EnumTagsConst =
|
|
9337
|
+
const EnumTagsConst = SingletonTypeTagsConst | (ValueTypeTagsConst & ~131072 /* TypeTag.Symbol */);
|
|
9340
9338
|
function isExact(v) {
|
|
9341
9339
|
// check that there is exactly one bit set
|
|
9342
9340
|
return v.type !== 0 && !(v.type & (v.type - 1));
|
|
@@ -9345,27 +9343,18 @@ function isUnion(v) {
|
|
|
9345
9343
|
return v.type !== 0 && !isExact(v);
|
|
9346
9344
|
}
|
|
9347
9345
|
function isSingleton(v) {
|
|
9348
|
-
return isExact(v) && (v.type &
|
|
9346
|
+
return isExact(v) && (v.type & SingletonTypeTagsConst) !== 0;
|
|
9349
9347
|
}
|
|
9350
9348
|
function hasValue(v) {
|
|
9351
9349
|
return (isExact(v) &&
|
|
9352
|
-
((v.type &
|
|
9350
|
+
((v.type & SingletonTypeTagsConst) !== 0 || v.value !== undefined));
|
|
9353
9351
|
}
|
|
9354
9352
|
function hasNoData(v, t) {
|
|
9355
9353
|
if (v.value == null)
|
|
9356
9354
|
return true;
|
|
9357
9355
|
return ((hasUnionData(v.type)
|
|
9358
9356
|
? v.value.mask & t
|
|
9359
|
-
: v.type & t & ~
|
|
9360
|
-
}
|
|
9361
|
-
function lookupByFullName(state, fullName) {
|
|
9362
|
-
return fullName.split(".").reduce((results, part) => {
|
|
9363
|
-
return results
|
|
9364
|
-
.flatMap((result) => (0,external_api_cjs_namespaceObject.isStateNode)(result)
|
|
9365
|
-
? result.decls?.[part] || result.type_decls?.[part]
|
|
9366
|
-
: null)
|
|
9367
|
-
.filter((sn) => !!sn);
|
|
9368
|
-
}, [state.stack[0]]);
|
|
9357
|
+
: v.type & t & ~SingletonTypeTagsConst) === 0);
|
|
9369
9358
|
}
|
|
9370
9359
|
function cloneType(t) {
|
|
9371
9360
|
return { ...t };
|
|
@@ -9588,7 +9577,7 @@ function typeFromSingleTypeSpec(state, type, stack) {
|
|
|
9588
9577
|
function typeFromTypespec(state, ts, stack) {
|
|
9589
9578
|
if (!state.config?.trustDeclaredTypes) {
|
|
9590
9579
|
if (ts.ts.length === 1 && typeof ts.ts[0] === "string") {
|
|
9591
|
-
const e = lookupByFullName(state, ts.ts[0]);
|
|
9580
|
+
const e = (0,external_api_cjs_namespaceObject.lookupByFullName)(state, ts.ts[0]);
|
|
9592
9581
|
if (e && e.length === 1 && e[0].type === "EnumDeclaration") {
|
|
9593
9582
|
return {
|
|
9594
9583
|
type: 65536 /* TypeTag.Enum */,
|
|
@@ -9934,7 +9923,7 @@ function getObjectValue(t) {
|
|
|
9934
9923
|
}
|
|
9935
9924
|
function forEachUnionComponent(v, bits, fn) {
|
|
9936
9925
|
// never iterate the singleton bits, because they don't have data
|
|
9937
|
-
bits &= ~
|
|
9926
|
+
bits &= ~SingletonTypeTagsConst;
|
|
9938
9927
|
if (!bits)
|
|
9939
9928
|
return;
|
|
9940
9929
|
if ((v.type | bits) & UnionDataTypeTagsConst) {
|
|
@@ -9964,7 +9953,7 @@ function forEachUnionComponent(v, bits, fn) {
|
|
|
9964
9953
|
function getUnionComponent(v, tag) {
|
|
9965
9954
|
if (v.value == null)
|
|
9966
9955
|
return null;
|
|
9967
|
-
let bits = v.type & ~
|
|
9956
|
+
let bits = v.type & ~SingletonTypeTagsConst;
|
|
9968
9957
|
if (!bits)
|
|
9969
9958
|
return null;
|
|
9970
9959
|
if (bits & (bits - 1)) {
|
|
@@ -10038,7 +10027,7 @@ function getStateNodeDeclsFromType(state, object) {
|
|
|
10038
10027
|
next &= ~6 /* TypeTag.Boolean */;
|
|
10039
10028
|
}
|
|
10040
10029
|
const name = `Toybox.Lang.${typeTagName(bit)}`;
|
|
10041
|
-
const sns = lookupByFullName(state, name);
|
|
10030
|
+
const sns = (0,external_api_cjs_namespaceObject.lookupByFullName)(state, name);
|
|
10042
10031
|
sns.forEach((sn) => (0,external_api_cjs_namespaceObject.isStateNode)(sn) && decls.push(sn));
|
|
10043
10032
|
bits = next;
|
|
10044
10033
|
} while (bits);
|
|
@@ -10244,7 +10233,7 @@ function common_types(left, right, allowed) {
|
|
|
10244
10233
|
}
|
|
10245
10234
|
if (lt & 8 /* TypeTag.Number */) {
|
|
10246
10235
|
result |=
|
|
10247
|
-
rt & 6 /* TypeTag.Boolean */ ? 6 /* TypeTag.Boolean */ : rt & ~
|
|
10236
|
+
rt & 6 /* TypeTag.Boolean */ ? 6 /* TypeTag.Boolean */ : rt & ~SingletonTypeTagsConst;
|
|
10248
10237
|
}
|
|
10249
10238
|
if (lt & 16 /* TypeTag.Long */) {
|
|
10250
10239
|
if (rt & 6 /* TypeTag.Boolean */) {
|
|
@@ -10637,7 +10626,7 @@ function calleeObjectType(istate, callee) {
|
|
|
10637
10626
|
}
|
|
10638
10627
|
if (callee.type === "Identifier" && istate.func) {
|
|
10639
10628
|
const func = istate.func;
|
|
10640
|
-
const [self] = func.stack.slice(-1);
|
|
10629
|
+
const [{ sn: self }] = func.stack.slice(-1);
|
|
10641
10630
|
return typeFromTypeStateNode(istate.state, self, (func.attributes & StateNodeAttributes.STATIC) !== 0 ||
|
|
10642
10631
|
self.type !== "ClassDeclaration");
|
|
10643
10632
|
}
|
|
@@ -10769,14 +10758,14 @@ function checkCallArgs(istate, node, callees, args) {
|
|
|
10769
10758
|
return resultType;
|
|
10770
10759
|
}
|
|
10771
10760
|
function isOverride(cur, funcs) {
|
|
10772
|
-
const cls = cur.stack?.[cur.stack.length - 1];
|
|
10761
|
+
const cls = cur.stack?.[cur.stack.length - 1]?.sn;
|
|
10773
10762
|
if (cls?.type === "ClassDeclaration" && cls.superClasses) {
|
|
10774
10763
|
const supers = (0,external_api_cjs_namespaceObject.getSuperClasses)(cls);
|
|
10775
10764
|
if (supers &&
|
|
10776
10765
|
(0,external_util_cjs_namespaceObject.some)(funcs, (func) => {
|
|
10777
10766
|
if (func === cur)
|
|
10778
10767
|
return false;
|
|
10779
|
-
const fcls = func.stack?.[func.stack.length - 1];
|
|
10768
|
+
const fcls = func.stack?.[func.stack.length - 1].sn;
|
|
10780
10769
|
return fcls ? supers.has(fcls) : false;
|
|
10781
10770
|
})) {
|
|
10782
10771
|
return true;
|
|
@@ -11352,7 +11341,7 @@ function byteArrayType(state) {
|
|
|
11352
11341
|
value: {
|
|
11353
11342
|
klass: {
|
|
11354
11343
|
type: 16384 /* TypeTag.Class */,
|
|
11355
|
-
value: lookupByFullName(state, "Toybox.Lang.ByteArray"),
|
|
11344
|
+
value: (0,external_api_cjs_namespaceObject.lookupByFullName)(state, "Toybox.Lang.ByteArray"),
|
|
11356
11345
|
},
|
|
11357
11346
|
},
|
|
11358
11347
|
};
|
|
@@ -11531,7 +11520,7 @@ function evaluateNode(istate, node) {
|
|
|
11531
11520
|
case "ThisExpression": {
|
|
11532
11521
|
const self = (() => {
|
|
11533
11522
|
for (let i = state.stack.length; i--;) {
|
|
11534
|
-
const si = state.stack[i];
|
|
11523
|
+
const si = state.stack[i].sn;
|
|
11535
11524
|
if (si.type === "ClassDeclaration") {
|
|
11536
11525
|
const klass = { type: 16384 /* TypeTag.Class */, value: si };
|
|
11537
11526
|
if ((istate.func?.attributes || 0) & StateNodeAttributes.STATIC) {
|
|
@@ -11741,7 +11730,7 @@ function evaluateNode(istate, node) {
|
|
|
11741
11730
|
if (node.init) {
|
|
11742
11731
|
const init = popIstate(istate, node.init);
|
|
11743
11732
|
if (node.id.type === "BinaryExpression" && istate.typeChecker) {
|
|
11744
|
-
const top = istate.state.
|
|
11733
|
+
const top = istate.state.top().sn;
|
|
11745
11734
|
if (top.type !== "BlockStatement") {
|
|
11746
11735
|
const declType = typeFromTypespec(istate.state, node.id.right);
|
|
11747
11736
|
if (!istate.typeChecker(init.value, declType)) {
|
|
@@ -12160,7 +12149,7 @@ function filterDecls(decls, possible, name) {
|
|
|
12160
12149
|
const stack = d.stack;
|
|
12161
12150
|
possible.forEach((poss) => {
|
|
12162
12151
|
for (let i = stack.length; i--;) {
|
|
12163
|
-
const sn = stack[i];
|
|
12152
|
+
const sn = stack[i].sn;
|
|
12164
12153
|
if (sn.decls === poss.decls) {
|
|
12165
12154
|
if (!cur[0]) {
|
|
12166
12155
|
cur = [new Set(), new Set()];
|
|
@@ -12381,9 +12370,21 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
|
|
|
12381
12370
|
if (Array.isArray(decl) ||
|
|
12382
12371
|
(decl.type !== "MemberDecl" && decl.type !== "Unknown")) {
|
|
12383
12372
|
if (!clearEquiv) {
|
|
12373
|
+
/*
|
|
12374
|
+
* If we're not clearing the equivalencies then this update
|
|
12375
|
+
* must be applied to every element of the set
|
|
12376
|
+
*/
|
|
12384
12377
|
const v = blockState.get(decl);
|
|
12385
12378
|
if (v?.equivSet) {
|
|
12386
|
-
|
|
12379
|
+
let s = decl;
|
|
12380
|
+
do {
|
|
12381
|
+
const next = blockState.get(s);
|
|
12382
|
+
if (!next || !next.equivSet) {
|
|
12383
|
+
throw new Error(`Inconsistent equivSet for ${tsKey(decl)}: missing value for ${tsKey(s)}`);
|
|
12384
|
+
}
|
|
12385
|
+
blockState.set(s, { ...next, curType: value });
|
|
12386
|
+
s = next.equivSet.next;
|
|
12387
|
+
} while (s !== decl);
|
|
12387
12388
|
return;
|
|
12388
12389
|
}
|
|
12389
12390
|
}
|
|
@@ -12489,7 +12490,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
|
|
|
12489
12490
|
return tmpState;
|
|
12490
12491
|
}
|
|
12491
12492
|
if (isExact(right) &&
|
|
12492
|
-
right.type &
|
|
12493
|
+
right.type & SingletonTypeTagsConst &&
|
|
12493
12494
|
left.type & right.type) {
|
|
12494
12495
|
// left is not equal to right, and right is one of the
|
|
12495
12496
|
// singleton types; so we can remove that type from left.
|
|
@@ -13603,7 +13604,7 @@ function tryDeEnumerate(istate, node, elem) {
|
|
|
13603
13604
|
|
|
13604
13605
|
|
|
13605
13606
|
function cleanupUnusedVars(state, node) {
|
|
13606
|
-
const
|
|
13607
|
+
const parent = state.stack.slice(-1).pop().sn;
|
|
13607
13608
|
if (parent.node !== node) {
|
|
13608
13609
|
return false;
|
|
13609
13610
|
}
|
|
@@ -13830,14 +13831,14 @@ function collectDeclarationsByName(state) {
|
|
|
13830
13831
|
}
|
|
13831
13832
|
}
|
|
13832
13833
|
};
|
|
13833
|
-
helper(state.stack[0]);
|
|
13834
|
+
helper(state.stack[0].sn);
|
|
13834
13835
|
}
|
|
13835
13836
|
function collectClassInfo(state) {
|
|
13836
|
-
const toybox = state.stack[0].decls["Toybox"][0];
|
|
13837
|
+
const toybox = state.stack[0].sn.decls["Toybox"][0];
|
|
13837
13838
|
const lang = toybox.decls["Lang"][0];
|
|
13838
13839
|
const object = lang.decls["Object"];
|
|
13839
13840
|
state.allClasses.forEach((elm) => {
|
|
13840
|
-
if (elm.stack[elm.stack.length - 1].type === "ClassDeclaration") {
|
|
13841
|
+
if (elm.stack[elm.stack.length - 1].sn.type === "ClassDeclaration") {
|
|
13841
13842
|
// nested classes don't get access to their contained
|
|
13842
13843
|
// context. Put them in the global scope instead.
|
|
13843
13844
|
elm.stack = elm.stack.slice(0, 1);
|
|
@@ -13984,7 +13985,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config) {
|
|
|
13984
13985
|
case "FunctionDeclaration":
|
|
13985
13986
|
case "ModuleDeclaration":
|
|
13986
13987
|
case "ClassDeclaration": {
|
|
13987
|
-
const
|
|
13988
|
+
const scope = state.top().sn;
|
|
13988
13989
|
scope.stack = state.stackClone().slice(0, -1);
|
|
13989
13990
|
if (scope.type === "FunctionDeclaration") {
|
|
13990
13991
|
if (markApi) {
|
|
@@ -14445,7 +14446,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
|
14445
14446
|
node.params &&
|
|
14446
14447
|
node.params.forEach((p) => (map[(0,external_api_cjs_namespaceObject.variableDeclarationName)(p)] = true));
|
|
14447
14448
|
state.localsStack.push({ node, map });
|
|
14448
|
-
const [parent, self] = state.stack.slice(-2);
|
|
14449
|
+
const [{ sn: parent }, { sn: self }] = state.stack.slice(-2);
|
|
14449
14450
|
if (state.currentFunction) {
|
|
14450
14451
|
throw new Error(`Nested functions: ${self.fullName} was activated during processing of ${state.currentFunction.fullName}`);
|
|
14451
14452
|
}
|
|
@@ -14511,7 +14512,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
|
14511
14512
|
node.optimizable = true;
|
|
14512
14513
|
}
|
|
14513
14514
|
if (!state.currentFunction) {
|
|
14514
|
-
throw new Error(`Finished function ${state.
|
|
14515
|
+
throw new Error(`Finished function ${state.top().sn.fullName}, but it was not marked current`);
|
|
14515
14516
|
}
|
|
14516
14517
|
state.currentFunction.info = state.currentFunction.next_info || false;
|
|
14517
14518
|
delete state.currentFunction.next_info;
|
|
@@ -15381,7 +15382,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
15381
15382
|
// the oldest optimized file, we don't need to regenerate
|
|
15382
15383
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
15383
15384
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
15384
|
-
if (source_time < opt_time &&
|
|
15385
|
+
if (source_time < opt_time && 1675030247366 < opt_time) {
|
|
15385
15386
|
return { hasTests, diagnostics: prevDiagnostics };
|
|
15386
15387
|
}
|
|
15387
15388
|
}
|
|
@@ -15408,7 +15409,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
15408
15409
|
return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
|
|
15409
15410
|
hasTests,
|
|
15410
15411
|
diagnostics,
|
|
15411
|
-
optimizerVersion: "1.1.
|
|
15412
|
+
optimizerVersion: "1.1.8",
|
|
15412
15413
|
...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
|
|
15413
15414
|
}))
|
|
15414
15415
|
.then(() => ({ hasTests, diagnostics }));
|
|
@@ -15477,7 +15478,7 @@ async function getProjectAnalysis(targets, analysis, manifestXML, options) {
|
|
|
15477
15478
|
state.pre = (node) => {
|
|
15478
15479
|
switch (node.type) {
|
|
15479
15480
|
case "FunctionDeclaration": {
|
|
15480
|
-
const self = state.
|
|
15481
|
+
const self = state.top().sn;
|
|
15481
15482
|
const istate = type_flow_buildTypeInfo(state, self, false);
|
|
15482
15483
|
if (istate) {
|
|
15483
15484
|
istate.state = state;
|
package/build/sdk-util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin,readPrg,xmlUtil});
|
|
1
|
+
0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getFunctionDocumentation,getLanguages,getSdkPath,isWin,readPrg,xmlUtil});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ "use strict";
|
|
4
4
|
/******/ // The require scope
|
|
@@ -44,6 +44,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
44
44
|
"appSupport": () => (/* binding */ appSupport),
|
|
45
45
|
"connectiq": () => (/* binding */ connectiq),
|
|
46
46
|
"getDeviceInfo": () => (/* binding */ getDeviceInfo),
|
|
47
|
+
"getFunctionDocumentation": () => (/* binding */ getFunctionDocumentation),
|
|
47
48
|
"getLanguages": () => (/* binding */ getLanguages),
|
|
48
49
|
"getSdkPath": () => (/* binding */ getSdkPath),
|
|
49
50
|
"isWin": () => (/* binding */ isWin),
|
|
@@ -796,6 +797,29 @@ async function getLanguages() {
|
|
|
796
797
|
})
|
|
797
798
|
.filter((s) => s != null);
|
|
798
799
|
}
|
|
800
|
+
async function getFunctionDocumentation() {
|
|
801
|
+
const file = external_path_namespaceObject.join(await getSdkPath(), "bin", "api.debug.xml");
|
|
802
|
+
const data = await promises_namespaceObject.readFile(file);
|
|
803
|
+
const xml = parseXml(data.toString(), file);
|
|
804
|
+
if (xml.body instanceof Error) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
const entries = xml.body
|
|
808
|
+
.children("functions")
|
|
809
|
+
.children("functionEntry")
|
|
810
|
+
.elements.map((e) => ({
|
|
811
|
+
name: e.attr.name?.value.value,
|
|
812
|
+
parent: e.attr.parent?.value.value,
|
|
813
|
+
doc: e.children
|
|
814
|
+
?.filter((child) => child.type === "element" &&
|
|
815
|
+
child.name === "documentation" &&
|
|
816
|
+
child.children != null)
|
|
817
|
+
.map((doc) => doc.children?.map((c) => c.type === "chardata" || c.type === "cdata" ? c.value : "") || "")
|
|
818
|
+
.join("") || "",
|
|
819
|
+
}))
|
|
820
|
+
.filter((x) => x.name != null && x.parent != null && x.doc !== "");
|
|
821
|
+
return entries;
|
|
822
|
+
}
|
|
799
823
|
|
|
800
824
|
var __webpack_export_target__ = exports;
|
|
801
825
|
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { hasProperty, traverseAst } from "./ast";
|
|
3
3
|
import { JungleResourceMap } from "./jungles";
|
|
4
|
-
import { ClassStateNode, Diagnostic, DiagnosticType, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
4
|
+
import { ClassStateNode, Diagnostic, DiagnosticType, EnumStateNode, FunctionInfo, FunctionStateNode, LookupDefinition, LookupResult, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, TypedefStateNode, VariableStateNode } from "./optimizer-types";
|
|
5
5
|
import { visit_resources } from "./resources";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
|
+
import { TypeMap } from "./type-flow/interp";
|
|
7
8
|
export { visitorNode, visitReferences } from "./visitor";
|
|
8
9
|
export { traverseAst, hasProperty, visit_resources };
|
|
9
10
|
export declare function parseSdkVersion(version: string | undefined): number;
|
|
@@ -15,10 +16,25 @@ export declare function isStateNode(node: {
|
|
|
15
16
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
16
17
|
declare type DeclKind = "decls" | "type_decls";
|
|
17
18
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
19
|
+
export declare function lookupResultContains(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
18
20
|
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
19
21
|
export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
|
|
22
|
+
export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
|
|
20
23
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
21
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
|
+
}][];
|
|
29
|
+
export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (ModuleStateNode | FunctionStateNode | ClassStateNode | TypedefStateNode | ProgramStateNode | EnumStateNode | mctree.EnumStringMember | mctree.Identifier | mctree.AsIdentifier | import("./optimizer-types").BlockStateNode | VariableStateNode)[];
|
|
30
|
+
export declare function formatAstLongLines(node: mctree.Node): string;
|
|
31
|
+
export declare function createDocumentationMap(functionDocumentation: {
|
|
32
|
+
name: string;
|
|
33
|
+
parent: string;
|
|
34
|
+
doc: string;
|
|
35
|
+
}[]): Promise<Map<string, string>>;
|
|
36
|
+
export declare function makeToyboxLink(result: StateNodeDecl): string | null;
|
|
37
|
+
export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
|
|
22
38
|
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier): ModuleStateNode | {
|
|
23
39
|
name: string;
|
|
24
40
|
decls: {
|
|
@@ -62,8 +62,6 @@ interface BaseStateNode {
|
|
|
62
62
|
decls?: StateNodeDecls | undefined;
|
|
63
63
|
type_decls?: StateNodeDecls | undefined;
|
|
64
64
|
stack?: ProgramStateStack | undefined;
|
|
65
|
-
usings?: Record<string, ImportUsing>;
|
|
66
|
-
imports?: ImportUsing[];
|
|
67
65
|
attributes: StateNodeAttributes;
|
|
68
66
|
}
|
|
69
67
|
export interface ProgramStateNode extends BaseStateNode {
|
|
@@ -154,8 +152,13 @@ export interface Diagnostic extends DiagnosticBase {
|
|
|
154
152
|
message: string;
|
|
155
153
|
};
|
|
156
154
|
}
|
|
155
|
+
declare type ProgramStateStackElem = {
|
|
156
|
+
sn: StateNode;
|
|
157
|
+
usings?: Record<string, ImportUsing>;
|
|
158
|
+
imports?: ImportUsing[];
|
|
159
|
+
};
|
|
157
160
|
export declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode | EnumStateNode;
|
|
158
|
-
export declare type ProgramStateStack =
|
|
161
|
+
export declare type ProgramStateStack = ProgramStateStackElem[];
|
|
159
162
|
export declare type LookupDefinition = {
|
|
160
163
|
parent: StateNode | null;
|
|
161
164
|
results: StateNodeDecl[];
|
|
@@ -171,15 +174,16 @@ export declare type ProgramState = {
|
|
|
171
174
|
rezAst?: mctree.Program;
|
|
172
175
|
manifestXML?: xmlUtil.Document;
|
|
173
176
|
stack?: ProgramStateStack;
|
|
177
|
+
top?: () => ProgramStateStackElem;
|
|
174
178
|
currentFunction?: FunctionStateNode;
|
|
175
179
|
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
176
180
|
shouldExclude?: (node: mctree.Node) => boolean;
|
|
177
181
|
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
178
182
|
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
179
|
-
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
180
|
-
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
181
|
-
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
182
|
-
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
183
|
+
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
184
|
+
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
185
|
+
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
186
|
+
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
183
187
|
stackClone?: () => ProgramStateStack;
|
|
184
188
|
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
185
189
|
inType?: number;
|
|
@@ -216,7 +220,7 @@ export declare type ProgramState = {
|
|
|
216
220
|
export declare type Finalized<T, Keys extends keyof T> = T & {
|
|
217
221
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
218
222
|
};
|
|
219
|
-
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
223
|
+
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
220
224
|
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
|
|
221
225
|
export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
222
226
|
export declare type ExcludeAnnotationsMap = {
|
package/build/src/sdk-util.d.ts
CHANGED
|
@@ -26,9 +26,9 @@ export declare const enum TypeTag {
|
|
|
26
26
|
Typedef = 262144,
|
|
27
27
|
Any = 524287
|
|
28
28
|
}
|
|
29
|
-
export declare function typeTagName(tag: TypeTag): "
|
|
29
|
+
export declare function typeTagName(tag: TypeTag): "Never" | "Null" | "False" | "True" | "Boolean" | "Number" | "Long" | "Float" | "Double" | "Decimal" | "Numeric" | "Char" | "String" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Object" | "Enum" | "Symbol" | "Typedef" | "Any";
|
|
30
30
|
export declare const LastTypeTag = TypeTag.Typedef;
|
|
31
|
-
export declare const
|
|
31
|
+
export declare const SingletonTypeTagsConst: number;
|
|
32
32
|
export declare const UnionDataTypeTagsConst: number;
|
|
33
33
|
export declare const ValueTypeTagsConst: number;
|
|
34
34
|
export declare const ObjectLikeTagsConst: number;
|
|
@@ -183,7 +183,6 @@ export declare function isUnion(v: AbstractValue): v is UnionType;
|
|
|
183
183
|
export declare function isSingleton(v: AbstractValue): v is SingletonType;
|
|
184
184
|
export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
|
|
185
185
|
export declare function hasNoData(v: AbstractValue, t: TypeTag): boolean;
|
|
186
|
-
export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
|
|
187
186
|
export declare function cloneType<T extends ExactOrUnion>(t: T): T;
|
|
188
187
|
export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
|
|
189
188
|
export declare function typeFromTypeStateNodes(state: ProgramStateAnalysis, sns: StateNodeDecl[], classVsObj?: boolean): ExactOrUnion;
|
package/build/src/type-flow.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { InterpState } from "./type-flow/interp";
|
|
|
4
4
|
import { ExactOrUnion } from "./type-flow/types";
|
|
5
5
|
export declare const missingNullWorkaround = true;
|
|
6
6
|
export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode, optimizeEquivalencies: boolean): InterpState | undefined;
|
|
7
|
-
export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): [
|
|
7
|
+
export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): readonly [null, null] | [StateNode[], StateNode[]];
|
|
8
8
|
export declare function resolveDottedMember(istate: InterpState, object: ExactOrUnion, next: mctree.DottedMemberExpression): {
|
|
9
9
|
mayThrow: boolean;
|
|
10
10
|
object: ExactOrUnion;
|
package/build/src/visitor.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
|
2
2
|
import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
3
|
import { TypeMap } from "./type-flow/interp";
|
|
4
4
|
export declare function visitorNode(node: mctree.Node): mctree.Node;
|
|
5
|
-
export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null): void;
|
|
5
|
+
export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null, findSingleDefinition?: boolean): void;
|
package/package.json
CHANGED