@markw65/monkeyc-optimizer 1.1.7 → 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 +12 -0
- package/build/api.cjs +3230 -166
- package/build/optimizer.cjs +52 -48
- 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
|
@@ -5075,7 +5075,7 @@ function renameVariable(state, locals, declName) {
|
|
|
5075
5075
|
let ok = false;
|
|
5076
5076
|
let i;
|
|
5077
5077
|
for (i = state.stack.length; i--;) {
|
|
5078
|
-
const elm = state.stack[i];
|
|
5078
|
+
const elm = state.stack[i].sn;
|
|
5079
5079
|
if (ok) {
|
|
5080
5080
|
if ((0,external_api_cjs_namespaceObject.hasProperty)(elm.decls, name)) {
|
|
5081
5081
|
break;
|
|
@@ -5179,9 +5179,9 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
5179
5179
|
// if decl is a local, it also can't be changed
|
|
5180
5180
|
// by a call to another function.
|
|
5181
5181
|
for (let i = 0;; i++) {
|
|
5182
|
-
if (!state.stack[i] || decl.stack[i] !== state.stack[i])
|
|
5182
|
+
if (!state.stack[i] || decl.stack[i]?.sn !== state.stack[i].sn)
|
|
5183
5183
|
return false;
|
|
5184
|
-
if (state.stack[i].type === "FunctionDeclaration")
|
|
5184
|
+
if (state.stack[i].sn.type === "FunctionDeclaration")
|
|
5185
5185
|
return true;
|
|
5186
5186
|
}
|
|
5187
5187
|
}
|
|
@@ -5318,7 +5318,7 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
5318
5318
|
}
|
|
5319
5319
|
return null;
|
|
5320
5320
|
};
|
|
5321
|
-
state.stack = func.stack.concat(func);
|
|
5321
|
+
state.stack = func.stack.concat({ sn: func });
|
|
5322
5322
|
state.traverse(func.node.body);
|
|
5323
5323
|
}
|
|
5324
5324
|
finally {
|
|
@@ -5429,7 +5429,7 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
5429
5429
|
// lookup determines static-ness of the lookup context based on seeing
|
|
5430
5430
|
// a static FunctionDeclaration, but the FunctionDeclaration's stack
|
|
5431
5431
|
// doesn't include the FunctionDeclaration itself.
|
|
5432
|
-
const lookupStack = func.stack.concat(func);
|
|
5432
|
+
const lookupStack = func.stack.concat({ sn: func });
|
|
5433
5433
|
try {
|
|
5434
5434
|
state.pre = (node) => {
|
|
5435
5435
|
if (failed)
|
|
@@ -5819,10 +5819,11 @@ function inlineFunction(state, func, call, context) {
|
|
|
5819
5819
|
if (!typecheckFalse) {
|
|
5820
5820
|
return ret;
|
|
5821
5821
|
}
|
|
5822
|
-
const
|
|
5823
|
-
if (!
|
|
5822
|
+
const callerElem = state.stack.find((elem) => elem.sn.type === "FunctionDeclaration");
|
|
5823
|
+
if (!callerElem) {
|
|
5824
5824
|
return ret;
|
|
5825
5825
|
}
|
|
5826
|
+
const callerSn = callerElem.sn;
|
|
5826
5827
|
const caller = callerSn.node;
|
|
5827
5828
|
if (!caller.attrs) {
|
|
5828
5829
|
caller.attrs = withLoc({
|
|
@@ -6888,7 +6889,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
6888
6889
|
});
|
|
6889
6890
|
}
|
|
6890
6891
|
if (wantsAllRefs) {
|
|
6891
|
-
const scope = state.
|
|
6892
|
+
const scope = state.top().sn;
|
|
6892
6893
|
if (scope.node === node &&
|
|
6893
6894
|
scope.type === "BlockStatement" &&
|
|
6894
6895
|
scope.decls &&
|
|
@@ -8864,7 +8865,7 @@ function unionInto(to, from) {
|
|
|
8864
8865
|
return true;
|
|
8865
8866
|
}
|
|
8866
8867
|
const newTags = to.type | from.type;
|
|
8867
|
-
if (!(from.type & ~
|
|
8868
|
+
if (!(from.type & ~SingletonTypeTagsConst)) {
|
|
8868
8869
|
// - Adding singletons never affects the data.
|
|
8869
8870
|
if (newTags === to.type)
|
|
8870
8871
|
return false;
|
|
@@ -9126,7 +9127,7 @@ function clearValuesUnder(v, tag, clearTag = false) {
|
|
|
9126
9127
|
const newTag = clearTag ? v.type & ~tag : v.type | tag;
|
|
9127
9128
|
// If the incoming type consists of singletons,
|
|
9128
9129
|
// we can always merge it without affecting our data.
|
|
9129
|
-
tag &= ~
|
|
9130
|
+
tag &= ~SingletonTypeTagsConst;
|
|
9130
9131
|
if (!tag || v.value == null) {
|
|
9131
9132
|
v.type = newTag;
|
|
9132
9133
|
return;
|
|
@@ -9310,7 +9311,7 @@ function typeTagName(tag) {
|
|
|
9310
9311
|
}
|
|
9311
9312
|
}
|
|
9312
9313
|
const LastTypeTag = 262144 /* TypeTag.Typedef */;
|
|
9313
|
-
const
|
|
9314
|
+
const SingletonTypeTagsConst = 1 /* TypeTag.Null */ | 2 /* TypeTag.False */ | 4 /* TypeTag.True */;
|
|
9314
9315
|
const UnionDataTypeTagsConst = 512 /* TypeTag.Array */ |
|
|
9315
9316
|
1024 /* TypeTag.Dictionary */ |
|
|
9316
9317
|
2048 /* TypeTag.Method */ |
|
|
@@ -9333,7 +9334,7 @@ const ObjectLikeTagsConst = 6 /* TypeTag.Boolean */ |
|
|
|
9333
9334
|
1024 /* TypeTag.Dictionary */ |
|
|
9334
9335
|
2048 /* TypeTag.Method */ |
|
|
9335
9336
|
65536 /* TypeTag.Enum */;
|
|
9336
|
-
const EnumTagsConst =
|
|
9337
|
+
const EnumTagsConst = SingletonTypeTagsConst | (ValueTypeTagsConst & ~131072 /* TypeTag.Symbol */);
|
|
9337
9338
|
function isExact(v) {
|
|
9338
9339
|
// check that there is exactly one bit set
|
|
9339
9340
|
return v.type !== 0 && !(v.type & (v.type - 1));
|
|
@@ -9342,27 +9343,18 @@ function isUnion(v) {
|
|
|
9342
9343
|
return v.type !== 0 && !isExact(v);
|
|
9343
9344
|
}
|
|
9344
9345
|
function isSingleton(v) {
|
|
9345
|
-
return isExact(v) && (v.type &
|
|
9346
|
+
return isExact(v) && (v.type & SingletonTypeTagsConst) !== 0;
|
|
9346
9347
|
}
|
|
9347
9348
|
function hasValue(v) {
|
|
9348
9349
|
return (isExact(v) &&
|
|
9349
|
-
((v.type &
|
|
9350
|
+
((v.type & SingletonTypeTagsConst) !== 0 || v.value !== undefined));
|
|
9350
9351
|
}
|
|
9351
9352
|
function hasNoData(v, t) {
|
|
9352
9353
|
if (v.value == null)
|
|
9353
9354
|
return true;
|
|
9354
9355
|
return ((hasUnionData(v.type)
|
|
9355
9356
|
? v.value.mask & t
|
|
9356
|
-
: v.type & t & ~
|
|
9357
|
-
}
|
|
9358
|
-
function lookupByFullName(state, fullName) {
|
|
9359
|
-
return fullName.split(".").reduce((results, part) => {
|
|
9360
|
-
return results
|
|
9361
|
-
.flatMap((result) => (0,external_api_cjs_namespaceObject.isStateNode)(result)
|
|
9362
|
-
? result.decls?.[part] || result.type_decls?.[part]
|
|
9363
|
-
: null)
|
|
9364
|
-
.filter((sn) => !!sn);
|
|
9365
|
-
}, [state.stack[0]]);
|
|
9357
|
+
: v.type & t & ~SingletonTypeTagsConst) === 0);
|
|
9366
9358
|
}
|
|
9367
9359
|
function cloneType(t) {
|
|
9368
9360
|
return { ...t };
|
|
@@ -9585,7 +9577,7 @@ function typeFromSingleTypeSpec(state, type, stack) {
|
|
|
9585
9577
|
function typeFromTypespec(state, ts, stack) {
|
|
9586
9578
|
if (!state.config?.trustDeclaredTypes) {
|
|
9587
9579
|
if (ts.ts.length === 1 && typeof ts.ts[0] === "string") {
|
|
9588
|
-
const e = lookupByFullName(state, ts.ts[0]);
|
|
9580
|
+
const e = (0,external_api_cjs_namespaceObject.lookupByFullName)(state, ts.ts[0]);
|
|
9589
9581
|
if (e && e.length === 1 && e[0].type === "EnumDeclaration") {
|
|
9590
9582
|
return {
|
|
9591
9583
|
type: 65536 /* TypeTag.Enum */,
|
|
@@ -9931,7 +9923,7 @@ function getObjectValue(t) {
|
|
|
9931
9923
|
}
|
|
9932
9924
|
function forEachUnionComponent(v, bits, fn) {
|
|
9933
9925
|
// never iterate the singleton bits, because they don't have data
|
|
9934
|
-
bits &= ~
|
|
9926
|
+
bits &= ~SingletonTypeTagsConst;
|
|
9935
9927
|
if (!bits)
|
|
9936
9928
|
return;
|
|
9937
9929
|
if ((v.type | bits) & UnionDataTypeTagsConst) {
|
|
@@ -9961,7 +9953,7 @@ function forEachUnionComponent(v, bits, fn) {
|
|
|
9961
9953
|
function getUnionComponent(v, tag) {
|
|
9962
9954
|
if (v.value == null)
|
|
9963
9955
|
return null;
|
|
9964
|
-
let bits = v.type & ~
|
|
9956
|
+
let bits = v.type & ~SingletonTypeTagsConst;
|
|
9965
9957
|
if (!bits)
|
|
9966
9958
|
return null;
|
|
9967
9959
|
if (bits & (bits - 1)) {
|
|
@@ -10035,7 +10027,7 @@ function getStateNodeDeclsFromType(state, object) {
|
|
|
10035
10027
|
next &= ~6 /* TypeTag.Boolean */;
|
|
10036
10028
|
}
|
|
10037
10029
|
const name = `Toybox.Lang.${typeTagName(bit)}`;
|
|
10038
|
-
const sns = lookupByFullName(state, name);
|
|
10030
|
+
const sns = (0,external_api_cjs_namespaceObject.lookupByFullName)(state, name);
|
|
10039
10031
|
sns.forEach((sn) => (0,external_api_cjs_namespaceObject.isStateNode)(sn) && decls.push(sn));
|
|
10040
10032
|
bits = next;
|
|
10041
10033
|
} while (bits);
|
|
@@ -10241,7 +10233,7 @@ function common_types(left, right, allowed) {
|
|
|
10241
10233
|
}
|
|
10242
10234
|
if (lt & 8 /* TypeTag.Number */) {
|
|
10243
10235
|
result |=
|
|
10244
|
-
rt & 6 /* TypeTag.Boolean */ ? 6 /* TypeTag.Boolean */ : rt & ~
|
|
10236
|
+
rt & 6 /* TypeTag.Boolean */ ? 6 /* TypeTag.Boolean */ : rt & ~SingletonTypeTagsConst;
|
|
10245
10237
|
}
|
|
10246
10238
|
if (lt & 16 /* TypeTag.Long */) {
|
|
10247
10239
|
if (rt & 6 /* TypeTag.Boolean */) {
|
|
@@ -10634,7 +10626,7 @@ function calleeObjectType(istate, callee) {
|
|
|
10634
10626
|
}
|
|
10635
10627
|
if (callee.type === "Identifier" && istate.func) {
|
|
10636
10628
|
const func = istate.func;
|
|
10637
|
-
const [self] = func.stack.slice(-1);
|
|
10629
|
+
const [{ sn: self }] = func.stack.slice(-1);
|
|
10638
10630
|
return typeFromTypeStateNode(istate.state, self, (func.attributes & StateNodeAttributes.STATIC) !== 0 ||
|
|
10639
10631
|
self.type !== "ClassDeclaration");
|
|
10640
10632
|
}
|
|
@@ -10766,14 +10758,14 @@ function checkCallArgs(istate, node, callees, args) {
|
|
|
10766
10758
|
return resultType;
|
|
10767
10759
|
}
|
|
10768
10760
|
function isOverride(cur, funcs) {
|
|
10769
|
-
const cls = cur.stack?.[cur.stack.length - 1];
|
|
10761
|
+
const cls = cur.stack?.[cur.stack.length - 1]?.sn;
|
|
10770
10762
|
if (cls?.type === "ClassDeclaration" && cls.superClasses) {
|
|
10771
10763
|
const supers = (0,external_api_cjs_namespaceObject.getSuperClasses)(cls);
|
|
10772
10764
|
if (supers &&
|
|
10773
10765
|
(0,external_util_cjs_namespaceObject.some)(funcs, (func) => {
|
|
10774
10766
|
if (func === cur)
|
|
10775
10767
|
return false;
|
|
10776
|
-
const fcls = func.stack?.[func.stack.length - 1];
|
|
10768
|
+
const fcls = func.stack?.[func.stack.length - 1].sn;
|
|
10777
10769
|
return fcls ? supers.has(fcls) : false;
|
|
10778
10770
|
})) {
|
|
10779
10771
|
return true;
|
|
@@ -11349,7 +11341,7 @@ function byteArrayType(state) {
|
|
|
11349
11341
|
value: {
|
|
11350
11342
|
klass: {
|
|
11351
11343
|
type: 16384 /* TypeTag.Class */,
|
|
11352
|
-
value: lookupByFullName(state, "Toybox.Lang.ByteArray"),
|
|
11344
|
+
value: (0,external_api_cjs_namespaceObject.lookupByFullName)(state, "Toybox.Lang.ByteArray"),
|
|
11353
11345
|
},
|
|
11354
11346
|
},
|
|
11355
11347
|
};
|
|
@@ -11528,7 +11520,7 @@ function evaluateNode(istate, node) {
|
|
|
11528
11520
|
case "ThisExpression": {
|
|
11529
11521
|
const self = (() => {
|
|
11530
11522
|
for (let i = state.stack.length; i--;) {
|
|
11531
|
-
const si = state.stack[i];
|
|
11523
|
+
const si = state.stack[i].sn;
|
|
11532
11524
|
if (si.type === "ClassDeclaration") {
|
|
11533
11525
|
const klass = { type: 16384 /* TypeTag.Class */, value: si };
|
|
11534
11526
|
if ((istate.func?.attributes || 0) & StateNodeAttributes.STATIC) {
|
|
@@ -11738,7 +11730,7 @@ function evaluateNode(istate, node) {
|
|
|
11738
11730
|
if (node.init) {
|
|
11739
11731
|
const init = popIstate(istate, node.init);
|
|
11740
11732
|
if (node.id.type === "BinaryExpression" && istate.typeChecker) {
|
|
11741
|
-
const top = istate.state.
|
|
11733
|
+
const top = istate.state.top().sn;
|
|
11742
11734
|
if (top.type !== "BlockStatement") {
|
|
11743
11735
|
const declType = typeFromTypespec(istate.state, node.id.right);
|
|
11744
11736
|
if (!istate.typeChecker(init.value, declType)) {
|
|
@@ -12157,7 +12149,7 @@ function filterDecls(decls, possible, name) {
|
|
|
12157
12149
|
const stack = d.stack;
|
|
12158
12150
|
possible.forEach((poss) => {
|
|
12159
12151
|
for (let i = stack.length; i--;) {
|
|
12160
|
-
const sn = stack[i];
|
|
12152
|
+
const sn = stack[i].sn;
|
|
12161
12153
|
if (sn.decls === poss.decls) {
|
|
12162
12154
|
if (!cur[0]) {
|
|
12163
12155
|
cur = [new Set(), new Set()];
|
|
@@ -12378,9 +12370,21 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
|
|
|
12378
12370
|
if (Array.isArray(decl) ||
|
|
12379
12371
|
(decl.type !== "MemberDecl" && decl.type !== "Unknown")) {
|
|
12380
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
|
+
*/
|
|
12381
12377
|
const v = blockState.get(decl);
|
|
12382
12378
|
if (v?.equivSet) {
|
|
12383
|
-
|
|
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);
|
|
12384
12388
|
return;
|
|
12385
12389
|
}
|
|
12386
12390
|
}
|
|
@@ -12486,7 +12490,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, logThisRun) {
|
|
|
12486
12490
|
return tmpState;
|
|
12487
12491
|
}
|
|
12488
12492
|
if (isExact(right) &&
|
|
12489
|
-
right.type &
|
|
12493
|
+
right.type & SingletonTypeTagsConst &&
|
|
12490
12494
|
left.type & right.type) {
|
|
12491
12495
|
// left is not equal to right, and right is one of the
|
|
12492
12496
|
// singleton types; so we can remove that type from left.
|
|
@@ -13600,7 +13604,7 @@ function tryDeEnumerate(istate, node, elem) {
|
|
|
13600
13604
|
|
|
13601
13605
|
|
|
13602
13606
|
function cleanupUnusedVars(state, node) {
|
|
13603
|
-
const
|
|
13607
|
+
const parent = state.stack.slice(-1).pop().sn;
|
|
13604
13608
|
if (parent.node !== node) {
|
|
13605
13609
|
return false;
|
|
13606
13610
|
}
|
|
@@ -13827,14 +13831,14 @@ function collectDeclarationsByName(state) {
|
|
|
13827
13831
|
}
|
|
13828
13832
|
}
|
|
13829
13833
|
};
|
|
13830
|
-
helper(state.stack[0]);
|
|
13834
|
+
helper(state.stack[0].sn);
|
|
13831
13835
|
}
|
|
13832
13836
|
function collectClassInfo(state) {
|
|
13833
|
-
const toybox = state.stack[0].decls["Toybox"][0];
|
|
13837
|
+
const toybox = state.stack[0].sn.decls["Toybox"][0];
|
|
13834
13838
|
const lang = toybox.decls["Lang"][0];
|
|
13835
13839
|
const object = lang.decls["Object"];
|
|
13836
13840
|
state.allClasses.forEach((elm) => {
|
|
13837
|
-
if (elm.stack[elm.stack.length - 1].type === "ClassDeclaration") {
|
|
13841
|
+
if (elm.stack[elm.stack.length - 1].sn.type === "ClassDeclaration") {
|
|
13838
13842
|
// nested classes don't get access to their contained
|
|
13839
13843
|
// context. Put them in the global scope instead.
|
|
13840
13844
|
elm.stack = elm.stack.slice(0, 1);
|
|
@@ -13981,7 +13985,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config) {
|
|
|
13981
13985
|
case "FunctionDeclaration":
|
|
13982
13986
|
case "ModuleDeclaration":
|
|
13983
13987
|
case "ClassDeclaration": {
|
|
13984
|
-
const
|
|
13988
|
+
const scope = state.top().sn;
|
|
13985
13989
|
scope.stack = state.stackClone().slice(0, -1);
|
|
13986
13990
|
if (scope.type === "FunctionDeclaration") {
|
|
13987
13991
|
if (markApi) {
|
|
@@ -14442,7 +14446,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
|
14442
14446
|
node.params &&
|
|
14443
14447
|
node.params.forEach((p) => (map[(0,external_api_cjs_namespaceObject.variableDeclarationName)(p)] = true));
|
|
14444
14448
|
state.localsStack.push({ node, map });
|
|
14445
|
-
const [parent, self] = state.stack.slice(-2);
|
|
14449
|
+
const [{ sn: parent }, { sn: self }] = state.stack.slice(-2);
|
|
14446
14450
|
if (state.currentFunction) {
|
|
14447
14451
|
throw new Error(`Nested functions: ${self.fullName} was activated during processing of ${state.currentFunction.fullName}`);
|
|
14448
14452
|
}
|
|
@@ -14508,7 +14512,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
|
14508
14512
|
node.optimizable = true;
|
|
14509
14513
|
}
|
|
14510
14514
|
if (!state.currentFunction) {
|
|
14511
|
-
throw new Error(`Finished function ${state.
|
|
14515
|
+
throw new Error(`Finished function ${state.top().sn.fullName}, but it was not marked current`);
|
|
14512
14516
|
}
|
|
14513
14517
|
state.currentFunction.info = state.currentFunction.next_info || false;
|
|
14514
14518
|
delete state.currentFunction.next_info;
|
|
@@ -15378,7 +15382,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
15378
15382
|
// the oldest optimized file, we don't need to regenerate
|
|
15379
15383
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
15380
15384
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
15381
|
-
if (source_time < opt_time &&
|
|
15385
|
+
if (source_time < opt_time && 1675030247366 < opt_time) {
|
|
15382
15386
|
return { hasTests, diagnostics: prevDiagnostics };
|
|
15383
15387
|
}
|
|
15384
15388
|
}
|
|
@@ -15405,7 +15409,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
15405
15409
|
return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
|
|
15406
15410
|
hasTests,
|
|
15407
15411
|
diagnostics,
|
|
15408
|
-
optimizerVersion: "1.1.
|
|
15412
|
+
optimizerVersion: "1.1.8",
|
|
15409
15413
|
...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
|
|
15410
15414
|
}))
|
|
15411
15415
|
.then(() => ({ hasTests, diagnostics }));
|
|
@@ -15474,7 +15478,7 @@ async function getProjectAnalysis(targets, analysis, manifestXML, options) {
|
|
|
15474
15478
|
state.pre = (node) => {
|
|
15475
15479
|
switch (node.type) {
|
|
15476
15480
|
case "FunctionDeclaration": {
|
|
15477
|
-
const self = state.
|
|
15481
|
+
const self = state.top().sn;
|
|
15478
15482
|
const istate = type_flow_buildTypeInfo(state, self, false);
|
|
15479
15483
|
if (istate) {
|
|
15480
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