@markw65/monkeyc-optimizer 1.0.29 → 1.0.32
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 +54 -0
- package/build/api.cjs +1049 -305
- package/build/optimizer.cjs +947 -393
- package/build/src/api.d.ts +5 -1
- package/build/src/ast.d.ts +2 -1
- package/build/src/build.d.ts +1 -0
- package/build/src/control-flow.d.ts +1 -0
- package/build/src/function-info.d.ts +12 -0
- package/build/src/inliner.d.ts +1 -0
- package/build/src/jungles.d.ts +1 -0
- package/build/src/mc-rewrite.d.ts +2 -1
- package/build/src/optimizer-types.d.ts +188 -0
- package/build/src/optimizer.d.ts +4 -174
- package/build/src/pragma-checker.d.ts +2 -1
- package/build/src/pre.d.ts +1 -0
- package/build/src/unused-exprs.d.ts +3 -0
- package/build/src/variable-renamer.d.ts +1 -0
- package/build/src/visitor.d.ts +1 -0
- package/package.json +6 -6
package/build/src/api.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import {
|
|
2
|
+
import { hasProperty, traverseAst } from "./ast";
|
|
3
|
+
import { LookupDefinition, ProgramState, ProgramStateLive, ProgramStateNode, StateNode, StateNodeDecl, ProgramStateStack, FunctionInfo, FunctionStateNode } from "./optimizer-types";
|
|
3
4
|
export { visitReferences } from "./visitor";
|
|
4
5
|
export { traverseAst, hasProperty };
|
|
5
6
|
export declare function getApiMapping(state?: ProgramState, barrelList?: string[]): Promise<ProgramStateNode | null>;
|
|
6
7
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
7
8
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
8
9
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
10
|
+
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
9
11
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
10
12
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
11
13
|
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier, isType: boolean): StateNodeDecl[] | null;
|
|
14
|
+
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo;
|
|
15
|
+
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
package/build/src/ast.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare function mayThrow(node: mctree.Node): boolean;
|
|
|
6
6
|
export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
|
|
7
7
|
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
8
8
|
export declare function withLoc<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined): T;
|
|
9
|
-
export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined): T;
|
|
9
|
+
export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined, inplace?: boolean): T;
|
|
10
|
+
export declare function cloneDeep<T extends mctree.Node>(node: T): T;
|
package/build/src/build.d.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VariableStateNode, FunctionStateNode, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
|
+
export declare function cloneSet<T>(ae: Set<T>): Set<T>;
|
|
3
|
+
export declare function mergeSet<T>(a: Set<T>, b: Set<T>): void;
|
|
4
|
+
export declare function recordModifiedDecl(func: FunctionStateNode, decl: VariableStateNode): null;
|
|
5
|
+
export declare function recordModifiedDecls(func: FunctionStateNode, lookupDefs: LookupDefinition[]): void;
|
|
6
|
+
export declare function recordModifiedName(func: FunctionStateNode, name: string): void;
|
|
7
|
+
export declare function recordModifiedUnknown(func: FunctionStateNode): void;
|
|
8
|
+
export declare function recordCalledFunc(func: FunctionStateNode, callee: FunctionStateNode): null;
|
|
9
|
+
export declare function recordCalledFuncs(func: FunctionStateNode, callees: FunctionStateNode[]): void;
|
|
10
|
+
export declare function functionMayModify(state: ProgramStateAnalysis, func: FunctionStateNode, decl: VariableStateNode): boolean;
|
|
11
|
+
export declare function findCallees(lookupDefs: LookupDefinition[]): FunctionStateNode[] | null;
|
|
12
|
+
export declare function findCalleesForNew(lookupDefs: LookupDefinition[]): FunctionStateNode[];
|
package/build/src/inliner.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { FunctionStateNode, ProgramStateAnalysis, ProgramStateLive } from "./optimizer-types";
|
|
2
3
|
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
|
|
3
4
|
declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
4
5
|
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
package/build/src/jungles.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { BuildConfig, FilesToOptimizeMap, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
3
|
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
3
4
|
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
4
5
|
export declare function analyze(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
5
6
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
6
7
|
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
7
8
|
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<Record<string, {
|
|
8
|
-
type:
|
|
9
|
+
type: "ERROR" | "WARNING" | "INFO";
|
|
9
10
|
loc: {
|
|
10
11
|
start: mctree.Position;
|
|
11
12
|
end: mctree.Position;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ResolvedJungle } from "./jungles";
|
|
3
|
+
declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
4
|
+
export declare type BuildConfig = {
|
|
5
|
+
workspace?: string;
|
|
6
|
+
jungleFiles?: string;
|
|
7
|
+
developerKeyPath?: string;
|
|
8
|
+
typeCheckLevel?: string;
|
|
9
|
+
compilerOptions?: string;
|
|
10
|
+
compilerWarnings?: boolean;
|
|
11
|
+
simulatorBuild?: boolean;
|
|
12
|
+
releaseBuild?: boolean;
|
|
13
|
+
testBuild?: boolean;
|
|
14
|
+
products?: string[];
|
|
15
|
+
buildDir?: string;
|
|
16
|
+
outputPath?: string;
|
|
17
|
+
program?: string;
|
|
18
|
+
skipOptimization?: boolean;
|
|
19
|
+
checkManifest?: boolean;
|
|
20
|
+
device?: string;
|
|
21
|
+
ignoredExcludeAnnotations?: string;
|
|
22
|
+
ignoredAnnotations?: string;
|
|
23
|
+
ignoredSourcePaths?: string;
|
|
24
|
+
returnCommand?: boolean;
|
|
25
|
+
checkBuildPragmas?: boolean;
|
|
26
|
+
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
27
|
+
sizeBasedPRE?: boolean | string;
|
|
28
|
+
_cache?: {
|
|
29
|
+
barrels?: Record<string, ResolvedJungle>;
|
|
30
|
+
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
|
|
34
|
+
export declare type StateNodeDecls = {
|
|
35
|
+
[key: string]: StateNodeDecl[];
|
|
36
|
+
};
|
|
37
|
+
export declare type ImportUsing = {
|
|
38
|
+
node: mctree.Using | mctree.ImportModule;
|
|
39
|
+
module?: ModuleStateNode | null | undefined;
|
|
40
|
+
};
|
|
41
|
+
interface BaseStateNode {
|
|
42
|
+
type: string;
|
|
43
|
+
node: mctree.Node | null | undefined;
|
|
44
|
+
name: string | null | undefined;
|
|
45
|
+
fullName: string | null | undefined;
|
|
46
|
+
decls?: StateNodeDecls | undefined;
|
|
47
|
+
type_decls?: StateNodeDecls | undefined;
|
|
48
|
+
stack?: ProgramStateStack | undefined;
|
|
49
|
+
usings?: Record<string, ImportUsing>;
|
|
50
|
+
imports?: ImportUsing[];
|
|
51
|
+
}
|
|
52
|
+
export interface ProgramStateNode extends BaseStateNode {
|
|
53
|
+
type: "Program";
|
|
54
|
+
node: mctree.Program | undefined;
|
|
55
|
+
name: "$";
|
|
56
|
+
fullName: "$";
|
|
57
|
+
stack?: undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface ModuleStateNode extends BaseStateNode {
|
|
60
|
+
type: "ModuleDeclaration";
|
|
61
|
+
node: mctree.ModuleDeclaration;
|
|
62
|
+
name: string;
|
|
63
|
+
fullName: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ClassStateNode extends BaseStateNode {
|
|
66
|
+
type: "ClassDeclaration";
|
|
67
|
+
node: mctree.ClassDeclaration;
|
|
68
|
+
name: string;
|
|
69
|
+
fullName: string;
|
|
70
|
+
superClass?: ClassStateNode[] | true;
|
|
71
|
+
hasInvoke?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare type FunctionInfo = {
|
|
74
|
+
modifiedDecls: Set<VariableStateNode>;
|
|
75
|
+
calledFuncs: Set<FunctionStateNode>;
|
|
76
|
+
resolvedDecls?: Set<VariableStateNode>;
|
|
77
|
+
callsExposed?: boolean;
|
|
78
|
+
modifiedUnknown?: boolean;
|
|
79
|
+
modifiedNames?: Set<string>;
|
|
80
|
+
};
|
|
81
|
+
export interface FunctionStateNode extends BaseStateNode {
|
|
82
|
+
type: "FunctionDeclaration";
|
|
83
|
+
node: mctree.FunctionDeclaration;
|
|
84
|
+
name: string;
|
|
85
|
+
fullName: string;
|
|
86
|
+
stack?: ProgramStateStack;
|
|
87
|
+
decls?: undefined;
|
|
88
|
+
isStatic?: boolean;
|
|
89
|
+
info?: FunctionInfo;
|
|
90
|
+
next_info?: FunctionInfo;
|
|
91
|
+
}
|
|
92
|
+
export interface BlockStateNode extends BaseStateNode {
|
|
93
|
+
type: "BlockStatement";
|
|
94
|
+
name: undefined;
|
|
95
|
+
fullName: undefined;
|
|
96
|
+
node: mctree.BlockStatement | mctree.ForStatement;
|
|
97
|
+
stack?: undefined;
|
|
98
|
+
}
|
|
99
|
+
export interface TypedefStateNode extends BaseStateNode {
|
|
100
|
+
type: "TypedefDeclaration";
|
|
101
|
+
node: mctree.TypedefDeclaration;
|
|
102
|
+
name: string;
|
|
103
|
+
fullName: string;
|
|
104
|
+
}
|
|
105
|
+
export interface VariableStateNode extends BaseStateNode {
|
|
106
|
+
type: "VariableDeclarator";
|
|
107
|
+
node: mctree.VariableDeclarator;
|
|
108
|
+
name: string;
|
|
109
|
+
fullName: string;
|
|
110
|
+
stack: ProgramStateStack;
|
|
111
|
+
used?: true;
|
|
112
|
+
}
|
|
113
|
+
export declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
|
|
114
|
+
export declare type ProgramStateStack = StateNode[];
|
|
115
|
+
export declare type LookupDefinition = {
|
|
116
|
+
parent: StateNode | null;
|
|
117
|
+
results: StateNodeDecl[];
|
|
118
|
+
};
|
|
119
|
+
export declare type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
120
|
+
export declare type ProgramState = {
|
|
121
|
+
allFunctions?: Record<string, FunctionStateNode[]>;
|
|
122
|
+
allClasses?: ClassStateNode[];
|
|
123
|
+
fnMap?: FilesToOptimizeMap;
|
|
124
|
+
stack?: ProgramStateStack;
|
|
125
|
+
currentFunction?: FunctionStateNode;
|
|
126
|
+
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
127
|
+
shouldExclude?: (node: mctree.Node) => boolean;
|
|
128
|
+
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
129
|
+
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
130
|
+
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
131
|
+
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
132
|
+
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
133
|
+
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
134
|
+
stackClone?: () => ProgramStateStack;
|
|
135
|
+
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
136
|
+
inType?: number;
|
|
137
|
+
inlining?: true;
|
|
138
|
+
config?: BuildConfig;
|
|
139
|
+
nextExposed?: Record<string, true>;
|
|
140
|
+
exposed?: Record<string, true>;
|
|
141
|
+
usedByName?: Record<string, true>;
|
|
142
|
+
calledFunctions?: {
|
|
143
|
+
[key: string]: mctree.FunctionDeclaration[];
|
|
144
|
+
};
|
|
145
|
+
localsStack?: {
|
|
146
|
+
node?: mctree.Node;
|
|
147
|
+
map?: {
|
|
148
|
+
[key: string]: boolean | string;
|
|
149
|
+
};
|
|
150
|
+
inners?: {
|
|
151
|
+
[key: string]: true;
|
|
152
|
+
};
|
|
153
|
+
}[];
|
|
154
|
+
index?: {
|
|
155
|
+
[key: string]: unknown[];
|
|
156
|
+
};
|
|
157
|
+
constants?: {
|
|
158
|
+
[key: string]: mctree.Literal;
|
|
159
|
+
};
|
|
160
|
+
diagnostics?: Record<string, {
|
|
161
|
+
type: DiagnosticType;
|
|
162
|
+
loc: {
|
|
163
|
+
start: mctree.Position;
|
|
164
|
+
end: mctree.Position;
|
|
165
|
+
};
|
|
166
|
+
message: string;
|
|
167
|
+
}[]>;
|
|
168
|
+
};
|
|
169
|
+
declare type Finalized<T, Keys extends keyof T> = T & {
|
|
170
|
+
[key in Keys]-?: NonNullable<T[key]>;
|
|
171
|
+
};
|
|
172
|
+
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed">;
|
|
173
|
+
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
174
|
+
export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
175
|
+
export declare type ExcludeAnnotationsMap = {
|
|
176
|
+
[key: string]: boolean;
|
|
177
|
+
};
|
|
178
|
+
export declare type FilesToOptimizeMap = {
|
|
179
|
+
[key: string]: {
|
|
180
|
+
output: string;
|
|
181
|
+
excludeAnnotations: ExcludeAnnotationsMap;
|
|
182
|
+
monkeyCSource?: string;
|
|
183
|
+
ast?: mctree.Program;
|
|
184
|
+
parserError?: Error;
|
|
185
|
+
hasTests?: boolean;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
export {};
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { get_jungle, ResolvedJungle, Target } from "./jungles";
|
|
|
3
3
|
import { launchSimulator, simulateProgram } from "./launch";
|
|
4
4
|
import { manifestProducts } from "./manifest";
|
|
5
5
|
import { copyRecursiveAsNeeded } from "./util";
|
|
6
|
+
import { BuildConfig, FilesToOptimizeMap, ProgramStateAnalysis } from "./optimizer-types";
|
|
7
|
+
export * from "./optimizer-types";
|
|
6
8
|
export { copyRecursiveAsNeeded, get_jungle, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
|
|
7
9
|
export declare const defaultConfig: {
|
|
8
10
|
outputPath: string;
|
|
@@ -13,178 +15,6 @@ export interface ErrorWithLocation extends Error {
|
|
|
13
15
|
}
|
|
14
16
|
export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
|
|
15
17
|
declare global {
|
|
16
|
-
type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
17
|
-
type BuildConfig = {
|
|
18
|
-
workspace?: string;
|
|
19
|
-
jungleFiles?: string;
|
|
20
|
-
developerKeyPath?: string;
|
|
21
|
-
typeCheckLevel?: string;
|
|
22
|
-
compilerOptions?: string;
|
|
23
|
-
compilerWarnings?: boolean;
|
|
24
|
-
simulatorBuild?: boolean;
|
|
25
|
-
releaseBuild?: boolean;
|
|
26
|
-
testBuild?: boolean;
|
|
27
|
-
products?: string[];
|
|
28
|
-
buildDir?: string;
|
|
29
|
-
outputPath?: string;
|
|
30
|
-
program?: string;
|
|
31
|
-
skipOptimization?: boolean;
|
|
32
|
-
checkManifest?: boolean;
|
|
33
|
-
device?: string;
|
|
34
|
-
ignoredExcludeAnnotations?: string;
|
|
35
|
-
ignoredAnnotations?: string;
|
|
36
|
-
ignoredSourcePaths?: string;
|
|
37
|
-
returnCommand?: boolean;
|
|
38
|
-
checkBuildPragmas?: boolean;
|
|
39
|
-
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
40
|
-
sizeBasedPRE?: boolean | string;
|
|
41
|
-
_cache?: {
|
|
42
|
-
barrels?: Record<string, ResolvedJungle>;
|
|
43
|
-
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
|
|
47
|
-
type StateNodeDecls = {
|
|
48
|
-
[key: string]: StateNodeDecl[];
|
|
49
|
-
};
|
|
50
|
-
type ImportUsing = {
|
|
51
|
-
node: mctree.Using | mctree.ImportModule;
|
|
52
|
-
module?: ModuleStateNode | null | undefined;
|
|
53
|
-
};
|
|
54
|
-
interface BaseStateNode {
|
|
55
|
-
type: string;
|
|
56
|
-
node: mctree.Node | null | undefined;
|
|
57
|
-
name: string | null | undefined;
|
|
58
|
-
fullName: string | null | undefined;
|
|
59
|
-
decls?: StateNodeDecls | undefined;
|
|
60
|
-
type_decls?: StateNodeDecls | undefined;
|
|
61
|
-
stack?: ProgramStateStack | undefined;
|
|
62
|
-
usings?: Record<string, ImportUsing>;
|
|
63
|
-
imports?: ImportUsing[];
|
|
64
|
-
}
|
|
65
|
-
interface ProgramStateNode extends BaseStateNode {
|
|
66
|
-
type: "Program";
|
|
67
|
-
node: mctree.Program | undefined;
|
|
68
|
-
name: "$";
|
|
69
|
-
fullName: "$";
|
|
70
|
-
stack?: undefined;
|
|
71
|
-
}
|
|
72
|
-
interface ModuleStateNode extends BaseStateNode {
|
|
73
|
-
type: "ModuleDeclaration";
|
|
74
|
-
node: mctree.ModuleDeclaration;
|
|
75
|
-
name: string;
|
|
76
|
-
fullName: string;
|
|
77
|
-
}
|
|
78
|
-
interface ClassStateNode extends BaseStateNode {
|
|
79
|
-
type: "ClassDeclaration";
|
|
80
|
-
node: mctree.ClassDeclaration;
|
|
81
|
-
name: string;
|
|
82
|
-
fullName: string;
|
|
83
|
-
superClass?: ClassStateNode[] | true;
|
|
84
|
-
}
|
|
85
|
-
interface FunctionStateNode extends BaseStateNode {
|
|
86
|
-
type: "FunctionDeclaration";
|
|
87
|
-
node: mctree.FunctionDeclaration;
|
|
88
|
-
name: string;
|
|
89
|
-
fullName: string;
|
|
90
|
-
stack?: ProgramStateStack;
|
|
91
|
-
decls?: undefined;
|
|
92
|
-
isStatic?: boolean;
|
|
93
|
-
}
|
|
94
|
-
interface BlockStateNode extends BaseStateNode {
|
|
95
|
-
type: "BlockStatement";
|
|
96
|
-
name: undefined;
|
|
97
|
-
fullName: undefined;
|
|
98
|
-
node: mctree.BlockStatement;
|
|
99
|
-
stack?: undefined;
|
|
100
|
-
}
|
|
101
|
-
interface TypedefStateNode extends BaseStateNode {
|
|
102
|
-
type: "TypedefDeclaration";
|
|
103
|
-
node: mctree.TypedefDeclaration;
|
|
104
|
-
name: string;
|
|
105
|
-
fullName: string;
|
|
106
|
-
}
|
|
107
|
-
interface VariableStateNode extends BaseStateNode {
|
|
108
|
-
type: "VariableDeclarator";
|
|
109
|
-
node: mctree.VariableDeclarator;
|
|
110
|
-
name: string;
|
|
111
|
-
fullName: string;
|
|
112
|
-
stack: ProgramStateStack;
|
|
113
|
-
}
|
|
114
|
-
type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
|
|
115
|
-
type ProgramStateStack = StateNode[];
|
|
116
|
-
type LookupDefinition = {
|
|
117
|
-
parent: StateNodeDecl | null;
|
|
118
|
-
results: StateNodeDecl[];
|
|
119
|
-
};
|
|
120
|
-
type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
121
|
-
export type ProgramState = {
|
|
122
|
-
allFunctions?: FunctionStateNode[];
|
|
123
|
-
allClasses?: ClassStateNode[];
|
|
124
|
-
fnMap?: FilesToOptimizeMap;
|
|
125
|
-
stack?: ProgramStateStack;
|
|
126
|
-
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
127
|
-
shouldExclude?: (node: mctree.Node) => boolean;
|
|
128
|
-
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
129
|
-
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
130
|
-
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
131
|
-
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
132
|
-
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
133
|
-
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
134
|
-
stackClone?: () => ProgramStateStack;
|
|
135
|
-
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
136
|
-
inType?: boolean;
|
|
137
|
-
inlining?: true;
|
|
138
|
-
config?: BuildConfig;
|
|
139
|
-
exposed?: {
|
|
140
|
-
[key: string]: true;
|
|
141
|
-
};
|
|
142
|
-
calledFunctions?: {
|
|
143
|
-
[key: string]: mctree.FunctionDeclaration[];
|
|
144
|
-
};
|
|
145
|
-
localsStack?: {
|
|
146
|
-
node?: mctree.Node;
|
|
147
|
-
map?: {
|
|
148
|
-
[key: string]: boolean | string;
|
|
149
|
-
};
|
|
150
|
-
inners?: {
|
|
151
|
-
[key: string]: true;
|
|
152
|
-
};
|
|
153
|
-
}[];
|
|
154
|
-
index?: {
|
|
155
|
-
[key: string]: unknown[];
|
|
156
|
-
};
|
|
157
|
-
constants?: {
|
|
158
|
-
[key: string]: mctree.Literal;
|
|
159
|
-
};
|
|
160
|
-
diagnostics?: Record<string, {
|
|
161
|
-
type: DiagnosticType;
|
|
162
|
-
loc: {
|
|
163
|
-
start: mctree.Position;
|
|
164
|
-
end: mctree.Position;
|
|
165
|
-
};
|
|
166
|
-
message: string;
|
|
167
|
-
}[]>;
|
|
168
|
-
};
|
|
169
|
-
type Finalized<T, Keys extends keyof T> = T & {
|
|
170
|
-
[key in Keys]-?: NonNullable<T[key]>;
|
|
171
|
-
};
|
|
172
|
-
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
173
|
-
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
174
|
-
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
175
|
-
type ExcludeAnnotationsMap = {
|
|
176
|
-
[key: string]: boolean;
|
|
177
|
-
};
|
|
178
|
-
type FilesToOptimizeMap = {
|
|
179
|
-
[key: string]: {
|
|
180
|
-
output: string;
|
|
181
|
-
excludeAnnotations: ExcludeAnnotationsMap;
|
|
182
|
-
monkeyCSource?: string;
|
|
183
|
-
ast?: mctree.Program;
|
|
184
|
-
parserError?: Error;
|
|
185
|
-
hasTests?: boolean;
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
18
|
var lastModifiedSource: number;
|
|
189
19
|
}
|
|
190
20
|
/**
|
|
@@ -200,7 +30,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
200
30
|
product: string | null;
|
|
201
31
|
hasTests: boolean;
|
|
202
32
|
diagnostics: Record<string, {
|
|
203
|
-
type:
|
|
33
|
+
type: "ERROR" | "WARNING" | "INFO";
|
|
204
34
|
loc: {
|
|
205
35
|
start: mctree.Position;
|
|
206
36
|
end: mctree.Position;
|
|
@@ -220,7 +50,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
220
50
|
program: string;
|
|
221
51
|
hasTests: boolean;
|
|
222
52
|
diagnostics: Record<string, {
|
|
223
|
-
type:
|
|
53
|
+
type: "ERROR" | "WARNING" | "INFO";
|
|
224
54
|
loc: {
|
|
225
55
|
start: mctree.Position;
|
|
226
56
|
end: mctree.Position;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
|
|
2
|
+
import { ProgramState, ProgramStateOptimizer } from "./optimizer-types";
|
|
3
|
+
export declare function pragmaChecker(state: ProgramStateOptimizer, ast: mctree.Program, diagnostics: NonNullable<ProgramState["diagnostics"]>[string] | null | undefined): void;
|
package/build/src/pre.d.ts
CHANGED
package/build/src/visitor.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
3
|
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): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.32",
|
|
5
5
|
"description": "Source to source optimizer for Garmin Monkey C code",
|
|
6
6
|
"main": "build/optimizer.cjs",
|
|
7
7
|
"types": "build/src/optimizer.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"build-debug": "webpack --mode development",
|
|
21
21
|
"build-release": "webpack --mode production",
|
|
22
22
|
"prepack": "webpack --mode production",
|
|
23
|
-
"test": "npm run test-optimized && npm run test-remote",
|
|
23
|
+
"test": "npm run test-optimized && npm run test-unopt && npm run test-remote",
|
|
24
24
|
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
25
|
-
"test-optimized": "node test/test.js --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
26
|
-
"test-unopt": "node test/test.js --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
27
|
-
"test-garmin-opt": "node test/test.js --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
25
|
+
"test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
26
|
+
"test-unopt": "node test/test.js --typeCheckLevel Strict --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
27
|
+
"test-garmin-opt": "node test/test.js --typeCheckLevel Strict --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
28
28
|
"eslint": "npx eslint ."
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"author": "markw65",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
40
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.33"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/glob": "^7.2.0",
|