@markw65/monkeyc-optimizer 1.1.3 → 1.1.5
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 +30 -0
- package/build/api.cjs +7837 -241
- package/build/optimizer.cjs +493 -327
- package/build/sdk-util.cjs +17 -14
- package/build/src/api.d.ts +1 -0
- package/build/src/optimizer-types.d.ts +3 -1
- package/build/src/optimizer.d.ts +2 -0
- package/build/src/type-flow/types.d.ts +10 -8
- package/build/src/type-flow.d.ts +1 -1
- package/build/src/visitor.d.ts +2 -1
- package/build/util.cjs +1 -1
- package/package.json +1 -1
package/build/sdk-util.cjs
CHANGED
|
@@ -255,6 +255,9 @@ function withLoc(node, start, end) {
|
|
|
255
255
|
if (!node.end)
|
|
256
256
|
node.end = start.end;
|
|
257
257
|
node.loc = { ...(node.loc || start.loc), start: start.loc.start };
|
|
258
|
+
if (end === start && start.origins) {
|
|
259
|
+
node.origins = start.origins;
|
|
260
|
+
}
|
|
258
261
|
}
|
|
259
262
|
if (end === false) {
|
|
260
263
|
if (node.loc) {
|
|
@@ -287,17 +290,17 @@ function cloneDeep(node) {
|
|
|
287
290
|
return withLocDeep(node, null);
|
|
288
291
|
}
|
|
289
292
|
function getNodeValue(node) {
|
|
290
|
-
if (node.type
|
|
291
|
-
node.operator
|
|
292
|
-
node.right.type
|
|
293
|
-
node.right.ts.length
|
|
294
|
-
typeof node.right.ts[0]
|
|
293
|
+
if (node.type === "BinaryExpression" &&
|
|
294
|
+
node.operator === "as" &&
|
|
295
|
+
node.right.type === "TypeSpecList" &&
|
|
296
|
+
node.right.ts.length === 1 &&
|
|
297
|
+
typeof node.right.ts[0] === "string") {
|
|
295
298
|
// this is a cast we inserted to retain the type of an enum
|
|
296
299
|
// any arithmetic on it will revert to "Number", or "Long",
|
|
297
300
|
// so just ignore it.
|
|
298
301
|
return getNodeValue(node.left);
|
|
299
302
|
}
|
|
300
|
-
if (node.type
|
|
303
|
+
if (node.type !== "Literal") {
|
|
301
304
|
return [null, null];
|
|
302
305
|
}
|
|
303
306
|
if (node.value === null) {
|
|
@@ -387,13 +390,13 @@ function makeScopedName(dotted, l) {
|
|
|
387
390
|
function getLiteralNode(node) {
|
|
388
391
|
if (node == null)
|
|
389
392
|
return null;
|
|
390
|
-
if (node.type
|
|
393
|
+
if (node.type === "Literal")
|
|
391
394
|
return node;
|
|
392
|
-
if (node.type
|
|
395
|
+
if (node.type === "BinaryExpression" && node.operator === "as") {
|
|
393
396
|
return getLiteralNode(node.left) && node;
|
|
394
397
|
}
|
|
395
|
-
if (node.type
|
|
396
|
-
if (node.argument.type
|
|
398
|
+
if (node.type === "UnaryExpression") {
|
|
399
|
+
if (node.argument.type !== "Literal")
|
|
397
400
|
return null;
|
|
398
401
|
switch (node.operator) {
|
|
399
402
|
case "-": {
|
|
@@ -695,7 +698,7 @@ function visit_xml(contents, visitor) {
|
|
|
695
698
|
if (visitor.pre && visitor.pre(c) === false) {
|
|
696
699
|
return;
|
|
697
700
|
}
|
|
698
|
-
if (c.type
|
|
701
|
+
if (c.type === "element" && c.children) {
|
|
699
702
|
visit_xml(c.children, visitor);
|
|
700
703
|
}
|
|
701
704
|
if (visitor.post)
|
|
@@ -736,13 +739,13 @@ async function readPrg(path) {
|
|
|
736
739
|
|
|
737
740
|
|
|
738
741
|
|
|
739
|
-
const isWin = process.platform
|
|
742
|
+
const isWin = process.platform === "win32";
|
|
740
743
|
const appSupport = isWin
|
|
741
744
|
? `${process.env.APPDATA}`.replace(/\\/g, "/")
|
|
742
|
-
: process.platform
|
|
745
|
+
: process.platform === "linux"
|
|
743
746
|
? `${process.env.HOME}/.config`
|
|
744
747
|
: `${process.env.HOME}/Library/Application Support`;
|
|
745
|
-
const connectiq = process.platform
|
|
748
|
+
const connectiq = process.platform === "linux"
|
|
746
749
|
? `${process.env.HOME}/.Garmin/ConnectIQ`
|
|
747
750
|
: `${appSupport}/Garmin/ConnectIQ`;
|
|
748
751
|
function getSdkPath() {
|
package/build/src/api.d.ts
CHANGED
|
@@ -30,4 +30,5 @@ export declare function getApiFunctionInfo(state: ProgramState, func: FunctionSt
|
|
|
30
30
|
export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
|
31
31
|
export declare function isLocal(v: VariableStateNode): boolean;
|
|
32
32
|
export declare function diagnostic(state: ProgramState, node: mctree.Node, message: string | null, type?: DiagnosticType, extra?: Diagnostic["extra"]): void;
|
|
33
|
+
export declare function diagnosticHelper(diagnostics: Record<string, Diagnostic[]>, node: mctree.Node, message: string | null, type: DiagnosticType | undefined, extra: Diagnostic["extra"] | undefined, uniqueLocs: boolean): void;
|
|
33
34
|
export declare function getSuperClasses(klass: ClassStateNode): Set<StateNode> | null;
|
|
@@ -109,7 +109,7 @@ export interface FunctionStateNode extends BaseStateNode {
|
|
|
109
109
|
export interface BlockStateNode extends BaseStateNode {
|
|
110
110
|
type: "BlockStatement";
|
|
111
111
|
name: undefined;
|
|
112
|
-
fullName:
|
|
112
|
+
fullName: string;
|
|
113
113
|
node: mctree.BlockStatement | mctree.ForStatement;
|
|
114
114
|
stack?: undefined;
|
|
115
115
|
}
|
|
@@ -129,6 +129,7 @@ export interface VariableStateNode extends BaseStateNode {
|
|
|
129
129
|
fullName: string;
|
|
130
130
|
stack: ProgramStateStack;
|
|
131
131
|
used?: true;
|
|
132
|
+
resolvedType?: ExactOrUnion | undefined;
|
|
132
133
|
}
|
|
133
134
|
export interface EnumStateNode extends BaseStateNode {
|
|
134
135
|
type: "EnumDeclaration";
|
|
@@ -209,6 +210,7 @@ export declare type ProgramState = {
|
|
|
209
210
|
[key: string]: mctree.Literal;
|
|
210
211
|
};
|
|
211
212
|
diagnostics?: Record<string, Diagnostic[]>;
|
|
213
|
+
inlineDiagnostics?: Record<string, Diagnostic[]>;
|
|
212
214
|
enumMap?: Map<EnumStringMember, EnumStateNode>;
|
|
213
215
|
};
|
|
214
216
|
export declare type Finalized<T, Keys extends keyof T> = T & {
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { launchSimulator, simulateProgram } from "./launch";
|
|
|
4
4
|
import { manifestProducts } from "./manifest";
|
|
5
5
|
import { BuildConfig, FilesToOptimizeMap, ProgramStateAnalysis } from "./optimizer-types";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
|
+
import { TypeMap } from "./type-flow/interp";
|
|
7
8
|
import { copyRecursiveAsNeeded } from "./util";
|
|
8
9
|
export * from "./optimizer-types";
|
|
9
10
|
export { copyRecursiveAsNeeded, get_jungle, JungleBuildDependencies, JungleError, JungleResourceMap, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
|
|
@@ -71,6 +72,7 @@ export declare type Analysis = {
|
|
|
71
72
|
fnMap: RequiredNonNull<FilesToOptimizeMap>;
|
|
72
73
|
paths: string[];
|
|
73
74
|
state: ProgramStateAnalysis;
|
|
75
|
+
typeMap?: TypeMap | null | undefined;
|
|
74
76
|
};
|
|
75
77
|
export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, manifestXML: xmlUtil.Document, options: BuildConfig): Promise<Analysis | PreAnalysis>;
|
|
76
78
|
/**
|
|
@@ -41,7 +41,15 @@ interface AbstractValue {
|
|
|
41
41
|
value?: unknown;
|
|
42
42
|
}
|
|
43
43
|
export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | MethodType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType | TypedefType;
|
|
44
|
-
declare type
|
|
44
|
+
declare type ExactPairHelper<T> = T extends ExactTypes ? {
|
|
45
|
+
type: T["type"];
|
|
46
|
+
avalue: T["value"];
|
|
47
|
+
bvalue: T["value"];
|
|
48
|
+
} : never;
|
|
49
|
+
export declare type ExactPairs = ExactPairHelper<ExactTypes>;
|
|
50
|
+
export declare type ValuePairs = ExactPairHelper<ValueTypes>;
|
|
51
|
+
declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : {
|
|
52
|
+
type: T["type"];
|
|
45
53
|
value: NonNullable<T["value"]>;
|
|
46
54
|
} : never;
|
|
47
55
|
export declare type ExactData<T extends ExactTypeTags> = T extends SingletonType ? undefined : NonNullable<Extract<ExactTypes, {
|
|
@@ -169,13 +177,7 @@ export declare type SingleValue = NonNullable<ValueTypes["value"]>;
|
|
|
169
177
|
declare type TagValue<TAG> = Extract<ValueTypes, {
|
|
170
178
|
type: TAG;
|
|
171
179
|
}>["value"];
|
|
172
|
-
export declare type ArrayValueType = TagValue<TypeTag.Array>;
|
|
173
|
-
export declare type DictionaryValueType = TagValue<TypeTag.Dictionary>;
|
|
174
|
-
export declare type MethodValueType = TagValue<TypeTag.Method>;
|
|
175
|
-
export declare type ObjectValueType = TagValue<TypeTag.Object>;
|
|
176
180
|
export declare type EnumValueType = TagValue<TypeTag.Enum>;
|
|
177
|
-
export declare type TypedefValueType = TagValue<TypeTag.Typedef>;
|
|
178
|
-
export declare type StateDeclValueType = TagValue<TypeTag.Module> | TagValue<TypeTag.Function> | TagValue<TypeTag.Class>;
|
|
179
181
|
export declare function isExact(v: AbstractValue): v is ExactTypes;
|
|
180
182
|
export declare function isUnion(v: AbstractValue): v is UnionType;
|
|
181
183
|
export declare function isSingleton(v: AbstractValue): v is SingletonType;
|
|
@@ -196,7 +198,7 @@ export declare function mustBeFalse(arg: ExactOrUnion): boolean;
|
|
|
196
198
|
export declare function display(type: ExactOrUnion): string;
|
|
197
199
|
export declare function hasUnionData(tag: TypeTag): boolean;
|
|
198
200
|
export declare function getObjectValue(t: ExactOrUnion): ObjectType["value"] | null;
|
|
199
|
-
export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn: (
|
|
201
|
+
export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn: (type: ExactTypes) => boolean | void): void;
|
|
200
202
|
export declare function getUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T): ExactData<T> | null;
|
|
201
203
|
export declare function setUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T, c: ExactData<T>): void;
|
|
202
204
|
export declare function getStateNodeDeclsFromType(state: ProgramStateAnalysis, object: ExactOrUnion): StateNode[];
|
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(
|
|
7
|
+
export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): [StateNode[], StateNode[]] | readonly [null, null];
|
|
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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
|
+
import { TypeMap } from "./type-flow/interp";
|
|
3
4
|
export declare function visitorNode(node: mctree.Node): mctree.Node;
|
|
4
|
-
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): 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): void;
|
package/build/util.cjs
CHANGED
|
@@ -7873,7 +7873,7 @@ function spawnByLine(command, args, lineHandlers, options) {
|
|
|
7873
7873
|
rle.on("line", errHandler);
|
|
7874
7874
|
rl.on("line", lineHandler);
|
|
7875
7875
|
proc.on("close", (code) => {
|
|
7876
|
-
if (code
|
|
7876
|
+
if (code === 0)
|
|
7877
7877
|
resolve();
|
|
7878
7878
|
reject(code);
|
|
7879
7879
|
});
|
package/package.json
CHANGED