@markw65/monkeyc-optimizer 1.0.28 → 1.0.31
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 +75 -0
- package/build/api.cjs +2901 -342
- package/build/optimizer.cjs +2775 -429
- package/build/src/api.d.ts +6 -4
- package/build/src/ast.d.ts +8 -0
- package/build/src/build.d.ts +1 -0
- package/build/src/control-flow.d.ts +21 -0
- package/build/src/function-info.d.ts +12 -0
- package/build/src/inliner.d.ts +4 -3
- package/build/src/jungles.d.ts +1 -0
- package/build/src/mc-rewrite.d.ts +3 -2
- package/build/src/optimizer-types.d.ts +188 -0
- package/build/src/optimizer.d.ts +4 -173
- 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 +4 -2
package/build/src/api.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { traverseAst } from "./ast";
|
|
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
|
-
export { traverseAst };
|
|
5
|
+
export { traverseAst, hasProperty };
|
|
5
6
|
export declare function getApiMapping(state?: ProgramState, barrelList?: string[]): Promise<ProgramStateNode | null>;
|
|
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
|
-
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
8
7
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
9
8
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
10
9
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
10
|
+
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
11
11
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
12
12
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
13
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
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
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 isStatement(node: mctree.Node): node is mctree.Statement;
|
|
4
|
+
export declare function isExpression(node: mctree.Node): node is mctree.Expression;
|
|
5
|
+
export declare function mayThrow(node: mctree.Node): boolean;
|
|
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
|
+
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
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, 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,21 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ProgramStateAnalysis, FunctionStateNode } from "./optimizer-types";
|
|
3
|
+
export declare type BaseEvent = {
|
|
4
|
+
type: string;
|
|
5
|
+
mayThrow: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare type EventConstraint<_T> = BaseEvent;
|
|
8
|
+
export declare type Block<T extends EventConstraint<T>> = {
|
|
9
|
+
node?: mctree.Node;
|
|
10
|
+
preds?: Block<T>[];
|
|
11
|
+
succs?: Block<T>[];
|
|
12
|
+
expreds?: Block<T>[];
|
|
13
|
+
exsucc?: Block<T>;
|
|
14
|
+
events?: T[];
|
|
15
|
+
};
|
|
16
|
+
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean) => T | null): Block<T>;
|
|
17
|
+
export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
18
|
+
export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
19
|
+
export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
|
20
|
+
export declare function getPreOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
|
21
|
+
export {};
|
|
@@ -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,10 +1,11 @@
|
|
|
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
|
-
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.
|
|
5
|
-
export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.
|
|
5
|
+
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
|
6
|
+
export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
|
|
6
7
|
export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
|
|
7
|
-
export declare type InlineContext = mctree.ReturnStatement | mctree.AssignmentExpression | mctree.ExpressionStatement;
|
|
8
|
+
export declare type InlineContext = mctree.ReturnStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
|
|
8
9
|
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
|
9
10
|
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
10
11
|
export {};
|
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
|
-
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): null;
|
|
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,177 +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
|
-
_cache?: {
|
|
41
|
-
barrels?: Record<string, ResolvedJungle>;
|
|
42
|
-
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
|
|
46
|
-
type StateNodeDecls = {
|
|
47
|
-
[key: string]: StateNodeDecl[];
|
|
48
|
-
};
|
|
49
|
-
type ImportUsing = {
|
|
50
|
-
node: mctree.Using | mctree.ImportModule;
|
|
51
|
-
module?: ModuleStateNode | null | undefined;
|
|
52
|
-
};
|
|
53
|
-
interface BaseStateNode {
|
|
54
|
-
type: string;
|
|
55
|
-
node: mctree.Node | null | undefined;
|
|
56
|
-
name: string | null | undefined;
|
|
57
|
-
fullName: string | null | undefined;
|
|
58
|
-
decls?: StateNodeDecls | undefined;
|
|
59
|
-
type_decls?: StateNodeDecls | undefined;
|
|
60
|
-
stack?: ProgramStateStack | undefined;
|
|
61
|
-
usings?: Record<string, ImportUsing>;
|
|
62
|
-
imports?: ImportUsing[];
|
|
63
|
-
}
|
|
64
|
-
interface ProgramStateNode extends BaseStateNode {
|
|
65
|
-
type: "Program";
|
|
66
|
-
node: mctree.Program | undefined;
|
|
67
|
-
name: "$";
|
|
68
|
-
fullName: "$";
|
|
69
|
-
stack?: undefined;
|
|
70
|
-
}
|
|
71
|
-
interface ModuleStateNode extends BaseStateNode {
|
|
72
|
-
type: "ModuleDeclaration";
|
|
73
|
-
node: mctree.ModuleDeclaration;
|
|
74
|
-
name: string;
|
|
75
|
-
fullName: string;
|
|
76
|
-
}
|
|
77
|
-
interface ClassStateNode extends BaseStateNode {
|
|
78
|
-
type: "ClassDeclaration";
|
|
79
|
-
node: mctree.ClassDeclaration;
|
|
80
|
-
name: string;
|
|
81
|
-
fullName: string;
|
|
82
|
-
superClass?: ClassStateNode[] | true;
|
|
83
|
-
}
|
|
84
|
-
interface FunctionStateNode extends BaseStateNode {
|
|
85
|
-
type: "FunctionDeclaration";
|
|
86
|
-
node: mctree.FunctionDeclaration;
|
|
87
|
-
name: string;
|
|
88
|
-
fullName: string;
|
|
89
|
-
stack?: ProgramStateStack;
|
|
90
|
-
decls?: undefined;
|
|
91
|
-
isStatic?: boolean;
|
|
92
|
-
}
|
|
93
|
-
interface BlockStateNode extends BaseStateNode {
|
|
94
|
-
type: "BlockStatement";
|
|
95
|
-
name: undefined;
|
|
96
|
-
fullName: undefined;
|
|
97
|
-
node: mctree.BlockStatement;
|
|
98
|
-
stack?: undefined;
|
|
99
|
-
}
|
|
100
|
-
interface TypedefStateNode extends BaseStateNode {
|
|
101
|
-
type: "TypedefDeclaration";
|
|
102
|
-
node: mctree.TypedefDeclaration;
|
|
103
|
-
name: string;
|
|
104
|
-
fullName: string;
|
|
105
|
-
}
|
|
106
|
-
interface VariableStateNode extends BaseStateNode {
|
|
107
|
-
type: "VariableDeclarator";
|
|
108
|
-
node: mctree.VariableDeclarator;
|
|
109
|
-
name: string;
|
|
110
|
-
fullName: string;
|
|
111
|
-
stack: ProgramStateStack;
|
|
112
|
-
}
|
|
113
|
-
type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
|
|
114
|
-
type ProgramStateStack = StateNode[];
|
|
115
|
-
type LookupDefinition = {
|
|
116
|
-
parent: StateNodeDecl | null;
|
|
117
|
-
results: StateNodeDecl[];
|
|
118
|
-
};
|
|
119
|
-
type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
120
|
-
export type ProgramState = {
|
|
121
|
-
allFunctions?: FunctionStateNode[];
|
|
122
|
-
allClasses?: ClassStateNode[];
|
|
123
|
-
fnMap?: FilesToOptimizeMap;
|
|
124
|
-
stack?: ProgramStateStack;
|
|
125
|
-
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
126
|
-
shouldExclude?: (node: mctree.Node) => boolean;
|
|
127
|
-
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
128
|
-
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
129
|
-
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
130
|
-
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
131
|
-
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
132
|
-
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
|
|
133
|
-
stackClone?: () => ProgramStateStack;
|
|
134
|
-
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
135
|
-
inType?: boolean;
|
|
136
|
-
inlining?: true;
|
|
137
|
-
config?: BuildConfig;
|
|
138
|
-
exposed?: {
|
|
139
|
-
[key: string]: true;
|
|
140
|
-
};
|
|
141
|
-
calledFunctions?: {
|
|
142
|
-
[key: string]: mctree.FunctionDeclaration[];
|
|
143
|
-
};
|
|
144
|
-
localsStack?: {
|
|
145
|
-
node?: mctree.Node;
|
|
146
|
-
map?: {
|
|
147
|
-
[key: string]: boolean | string;
|
|
148
|
-
};
|
|
149
|
-
inners?: {
|
|
150
|
-
[key: string]: true;
|
|
151
|
-
};
|
|
152
|
-
}[];
|
|
153
|
-
index?: {
|
|
154
|
-
[key: string]: unknown[];
|
|
155
|
-
};
|
|
156
|
-
constants?: {
|
|
157
|
-
[key: string]: mctree.Literal;
|
|
158
|
-
};
|
|
159
|
-
diagnostics?: Record<string, {
|
|
160
|
-
type: DiagnosticType;
|
|
161
|
-
loc: {
|
|
162
|
-
start: mctree.Position;
|
|
163
|
-
end: mctree.Position;
|
|
164
|
-
};
|
|
165
|
-
message: string;
|
|
166
|
-
}[]>;
|
|
167
|
-
};
|
|
168
|
-
type Finalized<T, Keys extends keyof T> = T & {
|
|
169
|
-
[key in Keys]-?: NonNullable<T[key]>;
|
|
170
|
-
};
|
|
171
|
-
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
172
|
-
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
173
|
-
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
174
|
-
type ExcludeAnnotationsMap = {
|
|
175
|
-
[key: string]: boolean;
|
|
176
|
-
};
|
|
177
|
-
type FilesToOptimizeMap = {
|
|
178
|
-
[key: string]: {
|
|
179
|
-
output: string;
|
|
180
|
-
excludeAnnotations: ExcludeAnnotationsMap;
|
|
181
|
-
monkeyCSource?: string;
|
|
182
|
-
ast?: mctree.Program;
|
|
183
|
-
parserError?: Error;
|
|
184
|
-
hasTests?: boolean;
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
18
|
var lastModifiedSource: number;
|
|
188
19
|
}
|
|
189
20
|
/**
|
|
@@ -199,7 +30,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
199
30
|
product: string | null;
|
|
200
31
|
hasTests: boolean;
|
|
201
32
|
diagnostics: Record<string, {
|
|
202
|
-
type:
|
|
33
|
+
type: "ERROR" | "WARNING" | "INFO";
|
|
203
34
|
loc: {
|
|
204
35
|
start: mctree.Position;
|
|
205
36
|
end: mctree.Position;
|
|
@@ -219,7 +50,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
219
50
|
program: string;
|
|
220
51
|
hasTests: boolean;
|
|
221
52
|
diagnostics: Record<string, {
|
|
222
|
-
type:
|
|
53
|
+
type: "ERROR" | "WARNING" | "INFO";
|
|
223
54
|
loc: {
|
|
224
55
|
start: mctree.Position;
|
|
225
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.31",
|
|
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",
|
|
@@ -37,11 +37,12 @@
|
|
|
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",
|
|
44
44
|
"@types/prettier": "^2.6.1",
|
|
45
|
+
"@types/priorityqueuejs": "^1.0.1",
|
|
45
46
|
"@types/xml2js": "^0.4.11",
|
|
46
47
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
47
48
|
"@typescript-eslint/parser": "^5.28.0",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"peggy": "^1.2.0",
|
|
52
53
|
"prettier": "^2.6.2",
|
|
53
54
|
"prettier-plugin-pegjs": "^0.5.0",
|
|
55
|
+
"priorityqueuejs": "^2.0.0",
|
|
54
56
|
"ts-loader": "^9.3.0",
|
|
55
57
|
"typescript": "^4.6.4",
|
|
56
58
|
"webpack": "^5.72.0",
|