@markw65/monkeyc-optimizer 1.1.2 → 1.1.4
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 +49 -0
- package/build/api.cjs +7789 -250
- package/build/optimizer.cjs +4350 -1360
- package/build/sdk-util.cjs +24 -18
- package/build/src/api.d.ts +9 -4
- package/build/src/ast.d.ts +1 -1
- package/build/src/control-flow.d.ts +2 -1
- package/build/src/data-flow.d.ts +68 -4
- package/build/src/mc-rewrite.d.ts +1 -8
- package/build/src/optimizer-types.d.ts +24 -11
- package/build/src/optimizer.d.ts +4 -16
- package/build/src/projects.d.ts +1 -1
- package/build/src/type-flow/could-be.d.ts +1 -0
- package/build/src/type-flow/dead-store.d.ts +5 -0
- package/build/src/type-flow/interp-call.d.ts +15 -3
- package/build/src/type-flow/interp.d.ts +7 -1
- package/build/src/type-flow/optimize.d.ts +1 -0
- package/build/src/type-flow/type-flow-util.d.ts +16 -0
- package/build/src/type-flow/types.d.ts +48 -45
- package/build/src/type-flow/union-type.d.ts +1 -0
- package/build/src/type-flow.d.ts +11 -2
- package/build/src/unused-exprs.d.ts +1 -1
- package/build/src/util.d.ts +3 -2
- package/build/src/visitor.d.ts +2 -1
- package/build/src/worker-task.d.ts +2 -16
- package/build/util.cjs +11 -2
- package/package.json +2 -2
package/build/sdk-util.cjs
CHANGED
|
@@ -171,7 +171,7 @@ function isMCTreeNode(node) {
|
|
|
171
171
|
* - if post returns false, the node it was called on is
|
|
172
172
|
* removed.
|
|
173
173
|
*/
|
|
174
|
-
function traverseAst(node, pre, post) {
|
|
174
|
+
function traverseAst(node, pre, post, parent) {
|
|
175
175
|
const nodes = pre && pre(node);
|
|
176
176
|
if (nodes === false)
|
|
177
177
|
return;
|
|
@@ -186,7 +186,7 @@ function traverseAst(node, pre, post) {
|
|
|
186
186
|
const values = value;
|
|
187
187
|
const deletions = values.reduce((state, obj, i) => {
|
|
188
188
|
if (isMCTreeNode(obj)) {
|
|
189
|
-
const repl = traverseAst(obj, pre, post);
|
|
189
|
+
const repl = traverseAst(obj, pre, post, node);
|
|
190
190
|
if (repl === false) {
|
|
191
191
|
if (!state)
|
|
192
192
|
state = {};
|
|
@@ -205,7 +205,7 @@ function traverseAst(node, pre, post) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
else if (isMCTreeNode(value)) {
|
|
208
|
-
let repl = traverseAst(value, pre, post);
|
|
208
|
+
let repl = traverseAst(value, pre, post, node);
|
|
209
209
|
if (repl === false) {
|
|
210
210
|
delete node[key];
|
|
211
211
|
}
|
|
@@ -225,7 +225,7 @@ function traverseAst(node, pre, post) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
return post && post(node);
|
|
228
|
+
return post && post(node, parent);
|
|
229
229
|
}
|
|
230
230
|
function isStatement(node) {
|
|
231
231
|
return hasProperty(mctreeTypeInfo[node.type], "stmt");
|
|
@@ -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) {
|
|
@@ -270,6 +273,9 @@ function withLoc(node, start, end) {
|
|
|
270
273
|
}
|
|
271
274
|
function withLocDeep(node, start, end, inplace) {
|
|
272
275
|
node = withLoc(inplace ? node : { ...node }, start, end);
|
|
276
|
+
if (!inplace && node.origins) {
|
|
277
|
+
node.origins = [...node.origins];
|
|
278
|
+
}
|
|
273
279
|
for (const key of mctreeTypeInfo[node.type].keys) {
|
|
274
280
|
const value = node[key];
|
|
275
281
|
if (!value)
|
|
@@ -284,17 +290,17 @@ function cloneDeep(node) {
|
|
|
284
290
|
return withLocDeep(node, null);
|
|
285
291
|
}
|
|
286
292
|
function getNodeValue(node) {
|
|
287
|
-
if (node.type
|
|
288
|
-
node.operator
|
|
289
|
-
node.right.type
|
|
290
|
-
node.right.ts.length
|
|
291
|
-
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") {
|
|
292
298
|
// this is a cast we inserted to retain the type of an enum
|
|
293
299
|
// any arithmetic on it will revert to "Number", or "Long",
|
|
294
300
|
// so just ignore it.
|
|
295
301
|
return getNodeValue(node.left);
|
|
296
302
|
}
|
|
297
|
-
if (node.type
|
|
303
|
+
if (node.type !== "Literal") {
|
|
298
304
|
return [null, null];
|
|
299
305
|
}
|
|
300
306
|
if (node.value === null) {
|
|
@@ -384,13 +390,13 @@ function makeScopedName(dotted, l) {
|
|
|
384
390
|
function getLiteralNode(node) {
|
|
385
391
|
if (node == null)
|
|
386
392
|
return null;
|
|
387
|
-
if (node.type
|
|
393
|
+
if (node.type === "Literal")
|
|
388
394
|
return node;
|
|
389
|
-
if (node.type
|
|
395
|
+
if (node.type === "BinaryExpression" && node.operator === "as") {
|
|
390
396
|
return getLiteralNode(node.left) && node;
|
|
391
397
|
}
|
|
392
|
-
if (node.type
|
|
393
|
-
if (node.argument.type
|
|
398
|
+
if (node.type === "UnaryExpression") {
|
|
399
|
+
if (node.argument.type !== "Literal")
|
|
394
400
|
return null;
|
|
395
401
|
switch (node.operator) {
|
|
396
402
|
case "-": {
|
|
@@ -692,7 +698,7 @@ function visit_xml(contents, visitor) {
|
|
|
692
698
|
if (visitor.pre && visitor.pre(c) === false) {
|
|
693
699
|
return;
|
|
694
700
|
}
|
|
695
|
-
if (c.type
|
|
701
|
+
if (c.type === "element" && c.children) {
|
|
696
702
|
visit_xml(c.children, visitor);
|
|
697
703
|
}
|
|
698
704
|
if (visitor.post)
|
|
@@ -733,13 +739,13 @@ async function readPrg(path) {
|
|
|
733
739
|
|
|
734
740
|
|
|
735
741
|
|
|
736
|
-
const isWin = process.platform
|
|
742
|
+
const isWin = process.platform === "win32";
|
|
737
743
|
const appSupport = isWin
|
|
738
744
|
? `${process.env.APPDATA}`.replace(/\\/g, "/")
|
|
739
|
-
: process.platform
|
|
745
|
+
: process.platform === "linux"
|
|
740
746
|
? `${process.env.HOME}/.config`
|
|
741
747
|
: `${process.env.HOME}/Library/Application Support`;
|
|
742
|
-
const connectiq = process.platform
|
|
748
|
+
const connectiq = process.platform === "linux"
|
|
743
749
|
? `${process.env.HOME}/.Garmin/ConnectIQ`
|
|
744
750
|
: `${appSupport}/Garmin/ConnectIQ`;
|
|
745
751
|
function getSdkPath() {
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
4
|
+
import { ClassStateNode, Diagnostic, DiagnosticType, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
5
5
|
import { visit_resources } from "./resources";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
7
|
export { visitorNode, visitReferences } from "./visitor";
|
|
@@ -9,10 +9,14 @@ export { traverseAst, hasProperty, visit_resources };
|
|
|
9
9
|
export declare function parseSdkVersion(version: string | undefined): number;
|
|
10
10
|
export declare function checkCompilerVersion(version: string, sdkVer: number): boolean | undefined;
|
|
11
11
|
export declare function getApiMapping(state?: ProgramState, resourcesMap?: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): Promise<ProgramStateNode | null>;
|
|
12
|
-
export declare function isStateNode(node:
|
|
12
|
+
export declare function isStateNode(node: {
|
|
13
|
+
type: string;
|
|
14
|
+
}): node is StateNode;
|
|
13
15
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
16
|
+
declare type DeclKind = "decls" | "type_decls";
|
|
14
17
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
15
18
|
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
19
|
+
export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
|
|
16
20
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
17
21
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
|
|
18
22
|
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier): ModuleStateNode | {
|
|
@@ -25,5 +29,6 @@ export declare function findUsingForNode(state: ProgramStateLive, stack: Program
|
|
|
25
29
|
export declare function getApiFunctionInfo(state: ProgramState, func: FunctionStateNode): FunctionInfo | false;
|
|
26
30
|
export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
|
27
31
|
export declare function isLocal(v: VariableStateNode): boolean;
|
|
28
|
-
export declare function diagnostic(state: ProgramState,
|
|
29
|
-
export declare function
|
|
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;
|
|
34
|
+
export declare function getSuperClasses(klass: ClassStateNode): Set<StateNode> | null;
|
package/build/src/ast.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import type { xmlUtil } from "./sdk-util";
|
|
3
|
-
export declare function traverseAst(node: mctree.Node, pre?: null | ((node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[]), post?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[]): false | void | null | mctree.Node | mctree.Node[];
|
|
3
|
+
export declare function traverseAst(node: mctree.Node, pre?: null | ((node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[]), post?: (node: mctree.Node, parent: mctree.Node | undefined) => void | null | false | mctree.Node | mctree.Node[], parent?: mctree.Node | undefined): false | void | null | mctree.Node | mctree.Node[];
|
|
4
4
|
export declare function isStatement(node: mctree.Node): node is mctree.Statement;
|
|
5
5
|
export declare function isExpression(node: mctree.Node): node is mctree.Expression;
|
|
6
6
|
export declare function mayThrow(node: mctree.Node): boolean;
|
|
@@ -11,9 +11,10 @@ export declare type Block<T extends EventConstraint<T>> = {
|
|
|
11
11
|
succs?: Block<T>[];
|
|
12
12
|
expreds?: Block<T>[];
|
|
13
13
|
exsucc?: Block<T>;
|
|
14
|
+
bogopred?: Block<T>;
|
|
14
15
|
events?: T[];
|
|
15
16
|
};
|
|
16
|
-
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1) => T | null): Block<T>;
|
|
17
|
+
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1) => T | T[] | null): Block<T>;
|
|
17
18
|
export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
18
19
|
export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
19
20
|
export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
package/build/src/data-flow.d.ts
CHANGED
|
@@ -2,16 +2,30 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
|
2
2
|
import { BaseEvent, Block } from "./control-flow";
|
|
3
3
|
import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
|
|
4
4
|
export declare type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
|
|
5
|
-
export declare type EventDecl = StateNodeDecl | StateNodeDecl[] | mctree.Literal
|
|
5
|
+
export declare type EventDecl = StateNodeDecl | StateNodeDecl[] | mctree.Literal | {
|
|
6
|
+
type: "MemberDecl";
|
|
7
|
+
node: mctree.MemberExpression;
|
|
8
|
+
base: StateNodeDecl | StateNodeDecl[];
|
|
9
|
+
path: mctree.MemberExpression[];
|
|
10
|
+
} | {
|
|
11
|
+
type: "Unknown";
|
|
12
|
+
node: mctree.MemberExpression | mctree.Identifier | mctree.ThisExpression;
|
|
13
|
+
};
|
|
6
14
|
export interface RefEvent extends BaseEvent {
|
|
7
15
|
type: "ref";
|
|
8
16
|
node: RefNode;
|
|
9
17
|
decl: EventDecl;
|
|
10
18
|
}
|
|
19
|
+
export interface KillEvent extends BaseEvent {
|
|
20
|
+
type: "kil";
|
|
21
|
+
node: mctree.Node;
|
|
22
|
+
decl: StateNodeDecl | StateNodeDecl[];
|
|
23
|
+
}
|
|
11
24
|
export interface DefEvent extends BaseEvent {
|
|
12
25
|
type: "def";
|
|
13
26
|
node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator;
|
|
14
27
|
decl: EventDecl;
|
|
28
|
+
rhs?: EventDecl;
|
|
15
29
|
}
|
|
16
30
|
export interface ModEvent extends BaseEvent {
|
|
17
31
|
type: "mod";
|
|
@@ -20,21 +34,70 @@ export interface ModEvent extends BaseEvent {
|
|
|
20
34
|
before?: boolean;
|
|
21
35
|
id?: RefNode;
|
|
22
36
|
callees?: FunctionStateNode[] | null;
|
|
37
|
+
calleeDecl?: EventDecl | undefined;
|
|
38
|
+
calleeObj?: EventDecl | undefined;
|
|
39
|
+
}
|
|
40
|
+
export declare enum FlowKind {
|
|
41
|
+
LEFT_EQ_RIGHT_DECL = 0,
|
|
42
|
+
LEFT_NE_RIGHT_DECL = 1,
|
|
43
|
+
LEFT_EQ_RIGHT_NODE = 2,
|
|
44
|
+
LEFT_NE_RIGHT_NODE = 3,
|
|
45
|
+
LEFT_TRUTHY = 4,
|
|
46
|
+
LEFT_FALSEY = 5,
|
|
47
|
+
INSTANCEOF = 6,
|
|
48
|
+
NOTINSTANCE = 7
|
|
49
|
+
}
|
|
50
|
+
interface FlowEventDecl extends BaseEvent {
|
|
51
|
+
type: "flw";
|
|
52
|
+
node: mctree.BinaryExpression | mctree.UnaryExpression;
|
|
53
|
+
decl?: undefined;
|
|
54
|
+
kind: FlowKind.LEFT_EQ_RIGHT_DECL | FlowKind.LEFT_NE_RIGHT_DECL;
|
|
55
|
+
left: EventDecl;
|
|
56
|
+
right_decl: EventDecl;
|
|
57
|
+
right_node?: undefined;
|
|
58
|
+
}
|
|
59
|
+
interface FlowEventNode extends BaseEvent {
|
|
60
|
+
type: "flw";
|
|
61
|
+
node: mctree.BinaryExpression | mctree.UnaryExpression;
|
|
62
|
+
decl?: undefined;
|
|
63
|
+
kind: FlowKind.LEFT_EQ_RIGHT_NODE | FlowKind.LEFT_NE_RIGHT_NODE;
|
|
64
|
+
left: EventDecl;
|
|
65
|
+
right_decl?: undefined;
|
|
66
|
+
right_node: mctree.Expression;
|
|
67
|
+
}
|
|
68
|
+
interface FlowEventTruthy extends BaseEvent {
|
|
69
|
+
type: "flw";
|
|
70
|
+
node: mctree.Node;
|
|
71
|
+
decl?: undefined;
|
|
72
|
+
kind: FlowKind.LEFT_TRUTHY | FlowKind.LEFT_FALSEY;
|
|
73
|
+
left: EventDecl;
|
|
74
|
+
right_decl?: undefined;
|
|
75
|
+
right_node?: undefined;
|
|
76
|
+
}
|
|
77
|
+
interface FlowEventInstanceof extends BaseEvent {
|
|
78
|
+
type: "flw";
|
|
79
|
+
node: mctree.InstanceofExpression | mctree.UnaryExpression;
|
|
80
|
+
decl?: undefined;
|
|
81
|
+
kind: FlowKind.INSTANCEOF | FlowKind.NOTINSTANCE;
|
|
82
|
+
left: EventDecl;
|
|
83
|
+
right_decl: EventDecl;
|
|
84
|
+
right_node?: undefined;
|
|
23
85
|
}
|
|
86
|
+
export declare type FlowEvent = FlowEventDecl | FlowEventNode | FlowEventTruthy | FlowEventInstanceof;
|
|
24
87
|
export interface ExnEvent extends BaseEvent {
|
|
25
88
|
type: "exn";
|
|
26
89
|
node: mctree.Node;
|
|
27
90
|
}
|
|
28
|
-
export declare type Event = RefEvent | DefEvent | ModEvent | ExnEvent;
|
|
91
|
+
export declare type Event = RefEvent | KillEvent | DefEvent | ModEvent | FlowEvent | ExnEvent;
|
|
29
92
|
export interface DataFlowBlock extends Block<Event> {
|
|
30
93
|
order?: number;
|
|
31
94
|
}
|
|
32
|
-
export declare function declFullName(decl: EventDecl): string
|
|
95
|
+
export declare function declFullName(decl: EventDecl): string;
|
|
33
96
|
export declare function declName(decl: EventDecl): string | undefined;
|
|
34
97
|
export declare function unhandledType(node: never): never;
|
|
35
98
|
export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
|
|
36
99
|
identifiers: Set<string>;
|
|
37
|
-
graph: Block<RefEvent | DefEvent | ModEvent | ExnEvent>;
|
|
100
|
+
graph: Block<RefEvent | KillEvent | DefEvent | ModEvent | FlowEventDecl | FlowEventNode | FlowEventTruthy | FlowEventInstanceof | ExnEvent>;
|
|
38
101
|
};
|
|
39
102
|
export declare class DataflowQueue {
|
|
40
103
|
private enqueued;
|
|
@@ -43,3 +106,4 @@ export declare class DataflowQueue {
|
|
|
43
106
|
dequeue(): DataFlowBlock;
|
|
44
107
|
empty(): boolean;
|
|
45
108
|
}
|
|
109
|
+
export {};
|
|
@@ -7,11 +7,4 @@ export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>
|
|
|
7
7
|
export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
8
8
|
export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
|
|
9
9
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
10
|
-
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<Record<string,
|
|
11
|
-
type: import("./optimizer-types").DiagnosticType;
|
|
12
|
-
loc: {
|
|
13
|
-
start: mctree.Position;
|
|
14
|
-
end: mctree.Position;
|
|
15
|
-
};
|
|
16
|
-
message: string;
|
|
17
|
-
}[]> | undefined>;
|
|
10
|
+
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<Record<string, import("./optimizer-types").Diagnostic[]> | undefined>;
|
|
@@ -37,6 +37,7 @@ export declare type BuildConfig = {
|
|
|
37
37
|
useLocalOptimizer?: boolean;
|
|
38
38
|
propagateTypes?: boolean;
|
|
39
39
|
trustDeclaredTypes?: boolean;
|
|
40
|
+
covarianceWarnings?: boolean;
|
|
40
41
|
checkTypes?: DiagnosticType | "OFF";
|
|
41
42
|
};
|
|
42
43
|
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier;
|
|
@@ -85,7 +86,7 @@ export interface ClassStateNode extends BaseStateNode {
|
|
|
85
86
|
fullName: string;
|
|
86
87
|
superClass?: ClassStateNode[] | true;
|
|
87
88
|
hasInvoke?: boolean;
|
|
88
|
-
superClasses?: Set<
|
|
89
|
+
superClasses?: Set<StateNode>;
|
|
89
90
|
}
|
|
90
91
|
export declare type FunctionInfo = {
|
|
91
92
|
modifiedDecls: Set<VariableStateNode>;
|
|
@@ -108,7 +109,7 @@ export interface FunctionStateNode extends BaseStateNode {
|
|
|
108
109
|
export interface BlockStateNode extends BaseStateNode {
|
|
109
110
|
type: "BlockStatement";
|
|
110
111
|
name: undefined;
|
|
111
|
-
fullName:
|
|
112
|
+
fullName: string;
|
|
112
113
|
node: mctree.BlockStatement | mctree.ForStatement;
|
|
113
114
|
stack?: undefined;
|
|
114
115
|
}
|
|
@@ -135,6 +136,22 @@ export interface EnumStateNode extends BaseStateNode {
|
|
|
135
136
|
name: string;
|
|
136
137
|
fullName: string;
|
|
137
138
|
stack: ProgramStateStack;
|
|
139
|
+
resolvedType?: ExactOrUnion;
|
|
140
|
+
}
|
|
141
|
+
interface DiagnosticBase {
|
|
142
|
+
loc: mctree.SourceLocation;
|
|
143
|
+
message: string;
|
|
144
|
+
}
|
|
145
|
+
export interface DiagnosticInfo extends DiagnosticBase {
|
|
146
|
+
loc: Finalized<mctree.SourceLocation, "source">;
|
|
147
|
+
}
|
|
148
|
+
export interface Diagnostic extends DiagnosticBase {
|
|
149
|
+
type: DiagnosticType;
|
|
150
|
+
related?: DiagnosticInfo[];
|
|
151
|
+
extra?: {
|
|
152
|
+
uri: string;
|
|
153
|
+
message: string;
|
|
154
|
+
};
|
|
138
155
|
}
|
|
139
156
|
export declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode | EnumStateNode;
|
|
140
157
|
export declare type ProgramStateStack = StateNode[];
|
|
@@ -143,10 +160,12 @@ export declare type LookupDefinition = {
|
|
|
143
160
|
results: StateNodeDecl[];
|
|
144
161
|
};
|
|
145
162
|
export declare type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
163
|
+
export declare type ByNameStateNodeDecls = ModuleStateNode | ClassStateNode | FunctionStateNode | ProgramStateNode;
|
|
146
164
|
export declare type ProgramState = {
|
|
147
165
|
allFunctions?: Record<string, FunctionStateNode[]>;
|
|
148
166
|
allClasses?: ClassStateNode[];
|
|
149
167
|
invokeInfo?: FunctionInfo;
|
|
168
|
+
allDeclarations?: Record<string, ByNameStateNodeDecls[]>;
|
|
150
169
|
fnMap?: FilesToOptimizeMap;
|
|
151
170
|
rezAst?: mctree.Program;
|
|
152
171
|
manifestXML?: xmlUtil.Document;
|
|
@@ -189,21 +208,15 @@ export declare type ProgramState = {
|
|
|
189
208
|
constants?: {
|
|
190
209
|
[key: string]: mctree.Literal;
|
|
191
210
|
};
|
|
192
|
-
diagnostics?: Record<string,
|
|
193
|
-
|
|
194
|
-
loc: {
|
|
195
|
-
start: mctree.Position;
|
|
196
|
-
end: mctree.Position;
|
|
197
|
-
};
|
|
198
|
-
message: string;
|
|
199
|
-
}[]>;
|
|
211
|
+
diagnostics?: Record<string, Diagnostic[]>;
|
|
212
|
+
inlineDiagnostics?: Record<string, Diagnostic[]>;
|
|
200
213
|
enumMap?: Map<EnumStringMember, EnumStateNode>;
|
|
201
214
|
};
|
|
202
215
|
export declare type Finalized<T, Keys extends keyof T> = T & {
|
|
203
216
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
204
217
|
};
|
|
205
218
|
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
206
|
-
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "invokeInfo">;
|
|
219
|
+
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
|
|
207
220
|
export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
208
221
|
export declare type ExcludeAnnotationsMap = {
|
|
209
222
|
[key: string]: boolean;
|
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, };
|
|
@@ -43,14 +44,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
43
44
|
program: string;
|
|
44
45
|
product: string | null;
|
|
45
46
|
hasTests: boolean;
|
|
46
|
-
diagnostics: Record<string,
|
|
47
|
-
type: import("./optimizer-types").DiagnosticType;
|
|
48
|
-
loc: {
|
|
49
|
-
start: mctree.Position;
|
|
50
|
-
end: mctree.Position;
|
|
51
|
-
};
|
|
52
|
-
message: string;
|
|
53
|
-
}[]> | undefined;
|
|
47
|
+
diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
|
|
54
48
|
}>;
|
|
55
49
|
export declare function generateOptimizedProject(options: BuildConfig): Promise<{
|
|
56
50
|
jungleFiles: string | undefined;
|
|
@@ -63,14 +57,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
63
57
|
xml: xmlUtil.Document;
|
|
64
58
|
program: string;
|
|
65
59
|
hasTests: boolean;
|
|
66
|
-
diagnostics: Record<string,
|
|
67
|
-
type: import("./optimizer-types").DiagnosticType;
|
|
68
|
-
loc: {
|
|
69
|
-
start: mctree.Position;
|
|
70
|
-
end: mctree.Position;
|
|
71
|
-
};
|
|
72
|
-
message: string;
|
|
73
|
-
}[]>;
|
|
60
|
+
diagnostics: Record<string, import("./optimizer-types").Diagnostic[]>;
|
|
74
61
|
}>;
|
|
75
62
|
export declare type PreAnalysis = {
|
|
76
63
|
fnMap: FilesToOptimizeMap;
|
|
@@ -85,6 +72,7 @@ export declare type Analysis = {
|
|
|
85
72
|
fnMap: RequiredNonNull<FilesToOptimizeMap>;
|
|
86
73
|
paths: string[];
|
|
87
74
|
state: ProgramStateAnalysis;
|
|
75
|
+
typeMap?: TypeMap | null | undefined;
|
|
88
76
|
};
|
|
89
77
|
export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, manifestXML: xmlUtil.Document, options: BuildConfig): Promise<Analysis | PreAnalysis>;
|
|
90
78
|
/**
|
package/build/src/projects.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type RemoteProject = string | {
|
|
|
16
16
|
test?: boolean;
|
|
17
17
|
};
|
|
18
18
|
export declare const githubProjects: RemoteProject[];
|
|
19
|
-
export declare function fetchGitProjects(projects: RemoteProject[], testOnly: boolean): Promise<(string | {
|
|
19
|
+
export declare function fetchGitProjects(projects: RemoteProject[], testOnly: boolean, skipRemote: boolean): Promise<(string | {
|
|
20
20
|
jungle: string;
|
|
21
21
|
build: boolean | null;
|
|
22
22
|
options: BuildConfig | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
|
|
3
|
+
import { TypeFlowBlock } from "./type-flow-util";
|
|
4
|
+
export declare function findDeadStores(graph: TypeFlowBlock, logThisRun: boolean): Set<mctree.Node>;
|
|
5
|
+
export declare function eliminateDeadStores(state: ProgramStateAnalysis, func: FunctionStateNode, graph: TypeFlowBlock, logThisRun: boolean): boolean;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import { ProgramStateAnalysis } from "../optimizer-types";
|
|
2
|
-
import { ExactOrUnion } from "./types";
|
|
3
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
4
|
-
|
|
2
|
+
import { FunctionStateNode } from "src/optimizer-types";
|
|
3
|
+
import { InterpStackElem, InterpState } from "./interp";
|
|
4
|
+
import { ExactOrUnion } from "./types";
|
|
5
|
+
export declare function evaluateCall(istate: InterpState, node: mctree.CallExpression, callee: ExactOrUnion, args: ExactOrUnion[]): InterpStackElem;
|
|
6
|
+
export declare function checkCallArgs(istate: InterpState, node: mctree.CallExpression, callees: FunctionStateNode | FunctionStateNode[], args: ExactOrUnion[]): InterpStackElem;
|
|
7
|
+
declare type SysCallHelperResult = {
|
|
8
|
+
calleeObj?: ExactOrUnion;
|
|
9
|
+
returnType?: ExactOrUnion;
|
|
10
|
+
argTypes?: ExactOrUnion[];
|
|
11
|
+
effectFree?: true;
|
|
12
|
+
argEffects?: true;
|
|
13
|
+
};
|
|
14
|
+
declare type SysCallHelper = (func: FunctionStateNode, calleeObj: ExactOrUnion, getArgs: () => Array<ExactOrUnion>) => SysCallHelperResult;
|
|
15
|
+
export declare function sysCallInfo(func: FunctionStateNode): SysCallHelper | null;
|
|
16
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
|
|
2
|
+
import { DiagnosticType, FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
|
|
3
3
|
import { ExactOrUnion } from "./types";
|
|
4
4
|
export declare type TypeMap = Map<mctree.Node, ExactOrUnion>;
|
|
5
5
|
export declare type InterpStackElem = {
|
|
@@ -14,10 +14,16 @@ export declare type InterpState = {
|
|
|
14
14
|
func?: FunctionStateNode;
|
|
15
15
|
pre?: (node: mctree.Node) => mctree.Node | false | null | void;
|
|
16
16
|
post?: (node: mctree.Node) => mctree.Node | false | null | void;
|
|
17
|
+
typeChecker?: (a: ExactOrUnion, b: ExactOrUnion) => boolean;
|
|
18
|
+
checkTypes?: DiagnosticType;
|
|
17
19
|
};
|
|
18
20
|
export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
|
|
21
|
+
export declare function tryPop(istate: InterpState, node: InterpStackElem["node"]): InterpStackElem;
|
|
19
22
|
export declare function evaluateExpr(state: ProgramStateAnalysis, expr: mctree.Expression, typeMap?: TypeMap): InterpStackElem;
|
|
23
|
+
export declare function preEvaluate(istate: InterpState, node: mctree.Node): null | (keyof mctree.NodeAll)[];
|
|
20
24
|
export declare function evaluate(istate: InterpState, node: mctree.Expression): InterpStackElem;
|
|
21
25
|
export declare function evaluate(istate: InterpState, node: mctree.Node): InterpStackElem | undefined;
|
|
26
|
+
export declare function deEnumerate(t: ExactOrUnion): ExactOrUnion;
|
|
22
27
|
export declare function evaluateNode(istate: InterpState, node: mctree.Node): void;
|
|
23
28
|
export declare function roundToFloat(value: number): number;
|
|
29
|
+
export declare function mustBeIdentical(a: ExactOrUnion, b: ExactOrUnion): boolean;
|
|
@@ -4,3 +4,4 @@ import { InterpState } from "./interp";
|
|
|
4
4
|
export declare function optimizeFunction(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
|
5
5
|
export declare function beforeEvaluate(istate: InterpState, node: mctree.Node): mctree.Node | null | false;
|
|
6
6
|
export declare function afterEvaluate(istate: InterpState, node: mctree.Node): mctree.Node | null | false;
|
|
7
|
+
export declare function tryDeEnumerate(istate: InterpState, node: mctree.Expression, elem: number): mctree.Expression | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { DataFlowBlock as TypeFlowBlock, Event, EventDecl } from "../data-flow";
|
|
3
|
+
import { VariableStateNode } from "../optimizer-types";
|
|
4
|
+
export { TypeFlowBlock };
|
|
5
|
+
export declare function isTypeStateKey(decl: EventDecl): decl is TypeStateKey;
|
|
6
|
+
export declare function declIsLocal(decl: EventDecl): decl is VariableStateNode | VariableStateNode[] | mctree.TypedIdentifier;
|
|
7
|
+
export declare function localDeclName(decl: EventDecl): string;
|
|
8
|
+
export declare type TypeStateKey = Exclude<EventDecl, {
|
|
9
|
+
type: "MemberDecl" | "Unknown";
|
|
10
|
+
}>;
|
|
11
|
+
export declare function tsKey(key: TypeStateKey): string;
|
|
12
|
+
export declare function sourceLocation(loc: mctree.SourceLocation | null | undefined): string;
|
|
13
|
+
export declare function printBlockHeader(block: TypeFlowBlock): void;
|
|
14
|
+
export declare function describeEvent(event: Event): string;
|
|
15
|
+
export declare function printBlockEvents(block: TypeFlowBlock, extra?: (event: Event) => string): void;
|
|
16
|
+
export declare function printBlockTrailer(block: TypeFlowBlock): void;
|