@markw65/monkeyc-optimizer 1.0.14 → 1.0.17
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 +38 -0
- package/build/api.cjs +769 -351
- package/build/optimizer.cjs +664 -114
- package/build/sdk-util.cjs +1 -1
- package/build/src/api.d.ts +1 -1
- package/build/src/inliner.d.ts +13 -0
- package/build/src/optimizer.d.ts +52 -31
- package/build/src/pragma-checker.d.ts +2 -0
- package/build/src/variable-renamer.d.ts +1 -0
- package/build/util.cjs +1 -1
- package/package.json +4 -3
package/build/sdk-util.cjs
CHANGED
package/build/src/api.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
|
5
5
|
export declare function isStateNode(node: StateNodeDecl): node is StateNode;
|
|
6
6
|
export declare function variableDeclarationName(node: mctree.TypedIdentifier): string;
|
|
7
7
|
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): false | void | null | mctree.Node;
|
|
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
9
|
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
export declare enum InlineStatus {
|
|
3
|
+
Never = 0,
|
|
4
|
+
AsExpression = 1,
|
|
5
|
+
AsStatement = 2
|
|
6
|
+
}
|
|
7
|
+
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, args: mctree.Node[]): InlineStatus;
|
|
8
|
+
declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
9
|
+
export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.ExpressionStatement[];
|
|
10
|
+
export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.ExpressionStatement[] | null;
|
|
11
|
+
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, inlineStatus: InlineStatus): InlineBody | null;
|
|
12
|
+
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
13
|
+
export {};
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -34,68 +34,89 @@ declare global {
|
|
|
34
34
|
ignoredAnnotations?: string;
|
|
35
35
|
ignoredSourcePaths?: string;
|
|
36
36
|
returnCommand?: boolean;
|
|
37
|
+
checkBuildPragmas?: boolean;
|
|
37
38
|
_cache?: {
|
|
38
39
|
barrels?: Record<string, ResolvedJungle>;
|
|
39
40
|
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
|
-
type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration
|
|
43
|
+
type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
|
|
43
44
|
type StateNodeDecls = {
|
|
44
45
|
[key: string]: StateNodeDecl[];
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
+
interface BaseStateNode {
|
|
48
|
+
type: string;
|
|
49
|
+
node: mctree.Node | null | undefined;
|
|
50
|
+
name: string | null | undefined;
|
|
51
|
+
fullName: string | null | undefined;
|
|
52
|
+
decls?: StateNodeDecls | undefined;
|
|
53
|
+
type_decls?: StateNodeDecls | undefined;
|
|
54
|
+
stack?: ProgramStateStack | undefined;
|
|
55
|
+
}
|
|
56
|
+
interface ProgramStateNode extends BaseStateNode {
|
|
47
57
|
type: "Program";
|
|
48
58
|
node: null | undefined;
|
|
49
59
|
name: "$";
|
|
50
60
|
fullName: "$";
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type ModuleStateNode = {
|
|
61
|
+
stack?: undefined;
|
|
62
|
+
}
|
|
63
|
+
interface ModuleStateNode extends BaseStateNode {
|
|
55
64
|
type: "ModuleDeclaration";
|
|
65
|
+
node: mctree.ModuleDeclaration;
|
|
56
66
|
name: string;
|
|
57
67
|
fullName: string;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
decls?: StateNodeDecls;
|
|
61
|
-
};
|
|
62
|
-
type ClassStateNode = {
|
|
68
|
+
}
|
|
69
|
+
interface ClassStateNode extends BaseStateNode {
|
|
63
70
|
type: "ClassDeclaration";
|
|
71
|
+
node: mctree.ClassDeclaration;
|
|
64
72
|
name: string;
|
|
65
73
|
fullName: string;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
superClass: ClassStateNode[] | true;
|
|
70
|
-
};
|
|
71
|
-
type FunctionStateNode = {
|
|
74
|
+
superClass?: ClassStateNode[] | true;
|
|
75
|
+
}
|
|
76
|
+
interface FunctionStateNode extends BaseStateNode {
|
|
72
77
|
type: "FunctionDeclaration";
|
|
78
|
+
node: mctree.FunctionDeclaration;
|
|
73
79
|
name: string;
|
|
74
80
|
fullName: string;
|
|
75
|
-
node: mctree.FunctionDeclaration;
|
|
76
81
|
stack?: ProgramStateStack;
|
|
77
82
|
decls?: undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
83
|
+
}
|
|
84
|
+
interface BlockStateNode extends BaseStateNode {
|
|
80
85
|
type: "BlockStatement";
|
|
81
|
-
name
|
|
82
|
-
fullName
|
|
86
|
+
name: undefined;
|
|
87
|
+
fullName: undefined;
|
|
83
88
|
node: mctree.BlockStatement;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
stack?: undefined;
|
|
90
|
+
}
|
|
91
|
+
interface TypedefStateNode extends BaseStateNode {
|
|
92
|
+
type: "TypedefDeclaration";
|
|
93
|
+
node: mctree.TypedefDeclaration;
|
|
94
|
+
name: string;
|
|
95
|
+
fullName: string;
|
|
96
|
+
}
|
|
97
|
+
interface VariableStateNode extends BaseStateNode {
|
|
98
|
+
type: "VariableDeclarator";
|
|
99
|
+
node: mctree.VariableDeclarator;
|
|
100
|
+
name: string;
|
|
101
|
+
fullName: string;
|
|
102
|
+
stack: ProgramStateStack;
|
|
103
|
+
}
|
|
104
|
+
type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
|
|
88
105
|
type ProgramStateStack = StateNode[];
|
|
89
106
|
export type ProgramState = {
|
|
90
107
|
allFunctions?: FunctionStateNode[];
|
|
91
108
|
allClasses?: ClassStateNode[];
|
|
109
|
+
fnMap?: FilesToOptimizeMap;
|
|
92
110
|
stack?: ProgramStateStack;
|
|
93
111
|
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
94
112
|
shouldExclude?: (node: mctree.Node) => boolean;
|
|
95
113
|
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
96
|
-
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node;
|
|
114
|
+
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
97
115
|
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
98
|
-
|
|
116
|
+
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
117
|
+
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
118
|
+
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
119
|
+
inType?: boolean;
|
|
99
120
|
exposed?: {
|
|
100
121
|
[key: string]: true;
|
|
101
122
|
};
|
|
@@ -121,8 +142,8 @@ declare global {
|
|
|
121
142
|
type Finalized<T, Keys extends keyof T> = T & {
|
|
122
143
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
123
144
|
};
|
|
124
|
-
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "traverse" | "index" | "constants" | "removeNodeComments">;
|
|
125
|
-
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions">;
|
|
145
|
+
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
146
|
+
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
126
147
|
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
127
148
|
type ExcludeAnnotationsMap = {
|
|
128
149
|
[key: string]: boolean;
|
|
@@ -175,7 +196,7 @@ declare type RequiredNonNull<T> = {
|
|
|
175
196
|
export declare type Analysis = {
|
|
176
197
|
fnMap: RequiredNonNull<FilesToOptimizeMap>;
|
|
177
198
|
paths: string[];
|
|
178
|
-
state:
|
|
199
|
+
state: ProgramStateAnalysis;
|
|
179
200
|
};
|
|
180
201
|
export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, options: BuildConfig): Promise<Analysis | PreAnalysis>;
|
|
181
202
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renameVariable(state: ProgramStateAnalysis, locals: NonNullable<ProgramStateAnalysis["localsStack"]>[number], declName: string): string | null;
|
package/build/util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {globa,last_modified,
|
|
1
|
+
0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globa,last_modified,promiseAll,pushUnique,readByLine,spawnByLine});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
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.17",
|
|
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,8 +20,9 @@
|
|
|
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-remote",
|
|
24
|
-
"test-remote": "node ./test/test.js --product=pick-one --github"
|
|
23
|
+
"test": "npm run test-inline && npm run test-remote",
|
|
24
|
+
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
25
|
+
"test-inline": "node test/test.js --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"build/optimizer.cjs",
|