@markw65/monkeyc-optimizer 1.0.20 → 1.0.23
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 +40 -0
- package/build/api.cjs +770 -286
- package/build/optimizer.cjs +552 -201
- package/build/src/api.d.ts +7 -3
- package/build/src/ast.d.ts +2 -0
- package/build/src/inliner.d.ts +1 -5
- package/build/src/mc-rewrite.d.ts +4 -4
- package/build/src/optimizer.d.ts +29 -11
- package/build/src/pragma-checker.d.ts +1 -1
- package/build/src/util.d.ts +1 -0
- package/build/src/visitor.d.ts +2 -0
- package/build/util.cjs +10 -4
- package/package.json +9 -4
package/build/src/api.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
|
|
2
|
+
import { traverseAst } from "./ast";
|
|
3
|
+
export { visitReferences } from "./visitor";
|
|
4
|
+
export { traverseAst };
|
|
5
|
+
export declare function getApiMapping(state?: ProgramState, barrelList?: string[]): Promise<ProgramStateNode | null>;
|
|
3
6
|
export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
|
|
4
7
|
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
5
8
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
6
|
-
export declare function variableDeclarationName(node: mctree.TypedIdentifier): string;
|
|
9
|
+
export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
|
|
10
|
+
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
7
11
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
8
|
-
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[];
|
|
9
12
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
13
|
+
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier, isType: boolean): StateNodeDecl[] | null;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
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[];
|
package/build/src/inliner.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
export declare enum InlineStatus {
|
|
3
|
-
Never = 0,
|
|
4
|
-
AsExpression = 1,
|
|
5
|
-
AsStatement = 2
|
|
6
|
-
}
|
|
7
2
|
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
|
|
8
3
|
declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
9
4
|
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.ExpressionStatement[];
|
|
10
5
|
export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.ExpressionStatement[] | null;
|
|
6
|
+
export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
|
|
11
7
|
export declare type InlineContext = mctree.ReturnStatement | mctree.AssignmentExpression | mctree.ExpressionStatement;
|
|
12
8
|
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
|
13
9
|
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
3
3
|
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
4
|
-
export declare function analyze(fnMap: FilesToOptimizeMap): Promise<ProgramStateAnalysis>;
|
|
5
|
-
export declare function getLiteralFromDecls(
|
|
4
|
+
export declare function analyze(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
5
|
+
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): null;
|
|
6
6
|
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
7
|
-
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap): Promise<Record<string, {
|
|
8
|
-
type:
|
|
7
|
+
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<Record<string, {
|
|
8
|
+
type: DiagnosticType;
|
|
9
9
|
loc: {
|
|
10
10
|
start: mctree.Position;
|
|
11
11
|
end: mctree.Position;
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ErrorWithLocation extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
|
|
15
15
|
declare global {
|
|
16
|
+
type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
16
17
|
type BuildConfig = {
|
|
17
18
|
workspace?: string;
|
|
18
19
|
jungleFiles?: string;
|
|
@@ -35,6 +36,7 @@ declare global {
|
|
|
35
36
|
ignoredSourcePaths?: string;
|
|
36
37
|
returnCommand?: boolean;
|
|
37
38
|
checkBuildPragmas?: boolean;
|
|
39
|
+
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
38
40
|
_cache?: {
|
|
39
41
|
barrels?: Record<string, ResolvedJungle>;
|
|
40
42
|
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
@@ -44,6 +46,10 @@ declare global {
|
|
|
44
46
|
type StateNodeDecls = {
|
|
45
47
|
[key: string]: StateNodeDecl[];
|
|
46
48
|
};
|
|
49
|
+
type ImportUsing = {
|
|
50
|
+
node: mctree.Using | mctree.ImportModule;
|
|
51
|
+
module?: ModuleStateNode | null | undefined;
|
|
52
|
+
};
|
|
47
53
|
interface BaseStateNode {
|
|
48
54
|
type: string;
|
|
49
55
|
node: mctree.Node | null | undefined;
|
|
@@ -52,10 +58,12 @@ declare global {
|
|
|
52
58
|
decls?: StateNodeDecls | undefined;
|
|
53
59
|
type_decls?: StateNodeDecls | undefined;
|
|
54
60
|
stack?: ProgramStateStack | undefined;
|
|
61
|
+
usings?: Record<string, ImportUsing>;
|
|
62
|
+
imports?: ImportUsing[];
|
|
55
63
|
}
|
|
56
64
|
interface ProgramStateNode extends BaseStateNode {
|
|
57
65
|
type: "Program";
|
|
58
|
-
node:
|
|
66
|
+
node: mctree.Program | undefined;
|
|
59
67
|
name: "$";
|
|
60
68
|
fullName: "$";
|
|
61
69
|
stack?: undefined;
|
|
@@ -80,6 +88,7 @@ declare global {
|
|
|
80
88
|
fullName: string;
|
|
81
89
|
stack?: ProgramStateStack;
|
|
82
90
|
decls?: undefined;
|
|
91
|
+
isStatic?: boolean;
|
|
83
92
|
}
|
|
84
93
|
interface BlockStateNode extends BaseStateNode {
|
|
85
94
|
type: "BlockStatement";
|
|
@@ -103,6 +112,11 @@ declare global {
|
|
|
103
112
|
}
|
|
104
113
|
type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
|
|
105
114
|
type ProgramStateStack = StateNode[];
|
|
115
|
+
type LookupDefinition = {
|
|
116
|
+
parent: StateNodeDecl | null;
|
|
117
|
+
results: StateNodeDecl[];
|
|
118
|
+
};
|
|
119
|
+
type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
106
120
|
export type ProgramState = {
|
|
107
121
|
allFunctions?: FunctionStateNode[];
|
|
108
122
|
allClasses?: ClassStateNode[];
|
|
@@ -112,11 +126,15 @@ declare global {
|
|
|
112
126
|
shouldExclude?: (node: mctree.Node) => boolean;
|
|
113
127
|
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
114
128
|
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
115
|
-
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) =>
|
|
116
|
-
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) =>
|
|
117
|
-
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) =>
|
|
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;
|
|
118
134
|
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
119
135
|
inType?: boolean;
|
|
136
|
+
inlining?: true;
|
|
137
|
+
config?: BuildConfig;
|
|
120
138
|
exposed?: {
|
|
121
139
|
[key: string]: true;
|
|
122
140
|
};
|
|
@@ -139,7 +157,7 @@ declare global {
|
|
|
139
157
|
[key: string]: mctree.Literal;
|
|
140
158
|
};
|
|
141
159
|
diagnostics?: Record<string, {
|
|
142
|
-
type:
|
|
160
|
+
type: DiagnosticType;
|
|
143
161
|
loc: {
|
|
144
162
|
start: mctree.Position;
|
|
145
163
|
end: mctree.Position;
|
|
@@ -150,7 +168,7 @@ declare global {
|
|
|
150
168
|
type Finalized<T, Keys extends keyof T> = T & {
|
|
151
169
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
152
170
|
};
|
|
153
|
-
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
171
|
+
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
154
172
|
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
155
173
|
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
156
174
|
type ExcludeAnnotationsMap = {
|
|
@@ -179,9 +197,9 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
179
197
|
args: string[];
|
|
180
198
|
program: string;
|
|
181
199
|
product: string | null;
|
|
182
|
-
hasTests: boolean
|
|
200
|
+
hasTests: boolean;
|
|
183
201
|
diagnostics: Record<string, {
|
|
184
|
-
type:
|
|
202
|
+
type: DiagnosticType;
|
|
185
203
|
loc: {
|
|
186
204
|
start: mctree.Position;
|
|
187
205
|
end: mctree.Position;
|
|
@@ -191,9 +209,9 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
191
209
|
}>;
|
|
192
210
|
export declare function generateOptimizedProject(options: BuildConfig): Promise<{
|
|
193
211
|
jungleFiles: string | undefined;
|
|
212
|
+
xml: import("./manifest").ManifestXML;
|
|
194
213
|
program: string;
|
|
195
|
-
|
|
196
|
-
hasTests?: undefined;
|
|
214
|
+
hasTests: boolean;
|
|
197
215
|
diagnostics?: undefined;
|
|
198
216
|
} | {
|
|
199
217
|
jungleFiles: string;
|
|
@@ -201,7 +219,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
201
219
|
program: string;
|
|
202
220
|
hasTests: boolean;
|
|
203
221
|
diagnostics: Record<string, {
|
|
204
|
-
type:
|
|
222
|
+
type: DiagnosticType;
|
|
205
223
|
loc: {
|
|
206
224
|
start: mctree.Position;
|
|
207
225
|
end: mctree.Position;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
export declare function pragmaChecker(ast: mctree.Program): void;
|
|
2
|
+
export declare function pragmaChecker(ast: mctree.Program, diagnostics: NonNullable<ProgramState["diagnostics"]>[string] | null | undefined): void;
|
package/build/src/util.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare function globa(pattern: string, options?: glob.IOptions): Promise
|
|
|
3
3
|
export declare function last_modified(inputs: string[]): Promise<number>;
|
|
4
4
|
export declare function first_modified(inputs: string[]): Promise<number>;
|
|
5
5
|
export declare function pushUnique<T, U extends T>(arr: T[], value: U): void;
|
|
6
|
+
export declare function sameArrays<T>(a1: T[], a2: T[], check: (a: T, b: T) => boolean): boolean;
|
|
6
7
|
export declare type LineHandler = (line: string) => void;
|
|
7
8
|
export declare function spawnByLine(command: string, args: string[], lineHandlers: LineHandler | LineHandler[], options?: {
|
|
8
9
|
[key: string]: unknown;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
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/build/util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globa,last_modified,promiseAll,pushUnique,readByLine,spawnByLine});
|
|
1
|
+
0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globa,last_modified,promiseAll,pushUnique,readByLine,sameArrays,spawnByLine});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -4005,6 +4005,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
4005
4005
|
"promiseAll": () => (/* binding */ promiseAll),
|
|
4006
4006
|
"pushUnique": () => (/* binding */ pushUnique),
|
|
4007
4007
|
"readByLine": () => (/* binding */ readByLine),
|
|
4008
|
+
"sameArrays": () => (/* binding */ sameArrays),
|
|
4008
4009
|
"spawnByLine": () => (/* binding */ spawnByLine)
|
|
4009
4010
|
});
|
|
4010
4011
|
|
|
@@ -4065,6 +4066,9 @@ function pushUnique(arr, value) {
|
|
|
4065
4066
|
return;
|
|
4066
4067
|
arr.push(value);
|
|
4067
4068
|
}
|
|
4069
|
+
function sameArrays(a1, a2, check) {
|
|
4070
|
+
return a1.length === a2.length && a1.every((e, i) => check(e, a2[i]));
|
|
4071
|
+
}
|
|
4068
4072
|
// return a promise that will process the output of command
|
|
4069
4073
|
// line-by-line via lineHandlers.
|
|
4070
4074
|
function spawnByLine(command, args, lineHandlers, options) {
|
|
@@ -4141,10 +4145,12 @@ async function copyRecursiveAsNeeded(source, target, filter) {
|
|
|
4141
4145
|
}
|
|
4142
4146
|
const files = await promises_namespaceObject.readdir(source);
|
|
4143
4147
|
return Promise.all(files.map((file) => {
|
|
4144
|
-
|
|
4145
|
-
|
|
4148
|
+
const src = external_path_.join(source, file);
|
|
4149
|
+
const tgt = external_path_.join(target, file);
|
|
4146
4150
|
return copyRecursiveAsNeeded(src, tgt, filter);
|
|
4147
|
-
})).then(() => {
|
|
4151
|
+
})).then(() => {
|
|
4152
|
+
return;
|
|
4153
|
+
});
|
|
4148
4154
|
}
|
|
4149
4155
|
else {
|
|
4150
4156
|
if (filter && !filter(source, target)) {
|
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.23",
|
|
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,9 +20,12 @@
|
|
|
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-
|
|
23
|
+
"test": "npm run test-optimized && npm run test-remote",
|
|
24
24
|
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
25
|
-
"test-
|
|
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",
|
|
28
|
+
"eslint": "npx eslint ."
|
|
26
29
|
},
|
|
27
30
|
"files": [
|
|
28
31
|
"build/optimizer.cjs",
|
|
@@ -34,12 +37,14 @@
|
|
|
34
37
|
"author": "markw65",
|
|
35
38
|
"license": "MIT",
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
40
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.27"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"@types/glob": "^7.2.0",
|
|
41
44
|
"@types/prettier": "^2.6.1",
|
|
42
45
|
"@types/xml2js": "^0.4.11",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.28.0",
|
|
43
48
|
"eslint": "^8.12.0",
|
|
44
49
|
"extract-zip": "^2.0.1",
|
|
45
50
|
"glob": "^7.2.0",
|