@markw65/monkeyc-optimizer 1.0.15 → 1.0.18
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 +37 -0
- package/build/api.cjs +648 -292
- package/build/optimizer.cjs +626 -109
- 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 +20 -5
- 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,12 +34,13 @@ 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
|
};
|
|
@@ -87,20 +88,34 @@ declare global {
|
|
|
87
88
|
node: mctree.BlockStatement;
|
|
88
89
|
stack?: undefined;
|
|
89
90
|
}
|
|
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;
|
|
91
105
|
type ProgramStateStack = StateNode[];
|
|
92
106
|
export type ProgramState = {
|
|
93
107
|
allFunctions?: FunctionStateNode[];
|
|
94
108
|
allClasses?: ClassStateNode[];
|
|
109
|
+
fnMap?: FilesToOptimizeMap;
|
|
95
110
|
stack?: ProgramStateStack;
|
|
96
111
|
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
97
112
|
shouldExclude?: (node: mctree.Node) => boolean;
|
|
98
113
|
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
99
|
-
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node;
|
|
114
|
+
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
100
115
|
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
101
116
|
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
102
117
|
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
|
|
103
|
-
traverse?: (node: mctree.Node) => void | null | false | mctree.Node;
|
|
118
|
+
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
104
119
|
inType?: boolean;
|
|
105
120
|
exposed?: {
|
|
106
121
|
[key: string]: true;
|
|
@@ -128,7 +143,7 @@ declare global {
|
|
|
128
143
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
129
144
|
};
|
|
130
145
|
export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
|
|
131
|
-
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions">;
|
|
146
|
+
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
132
147
|
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
|
|
133
148
|
type ExcludeAnnotationsMap = {
|
|
134
149
|
[key: string]: boolean;
|
|
@@ -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.18",
|
|
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",
|