@markw65/monkeyc-optimizer 1.1.9 → 1.1.11
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 +26 -0
- package/build/api.cjs +1402 -462
- package/build/optimizer.cjs +4492 -3580
- package/build/src/api.d.ts +1 -0
- package/build/src/control-flow.d.ts +1 -1
- package/build/src/data-flow.d.ts +5 -3
- package/build/src/inliner.d.ts +2 -0
- package/build/src/optimizer-types.d.ts +2 -0
- package/build/src/optimizer.d.ts +1 -0
- package/build/src/type-flow/could-be.d.ts +2 -0
- package/build/src/type-flow/dead-store.d.ts +10 -2
- package/build/src/type-flow/interp-call.d.ts +1 -1
- package/build/src/type-flow/type-flow-util.d.ts +12 -1
- package/build/src/type-flow/types.d.ts +1 -1
- package/build/src/type-flow.d.ts +3 -10
- package/build/src/variable-renamer.d.ts +2 -0
- package/package.json +2 -2
package/build/src/api.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare function findUsingForNode(state: ProgramStateLive, stack: Program
|
|
|
45
45
|
export declare function getApiFunctionInfo(state: ProgramState, func: FunctionStateNode): FunctionInfo | false;
|
|
46
46
|
export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
|
47
47
|
export declare function isLocal(v: VariableStateNode): boolean;
|
|
48
|
+
export declare function isClassVariable(v: VariableStateNode): boolean;
|
|
48
49
|
export declare function diagnostic(state: ProgramState, node: mctree.Node, message: string | null, type?: DiagnosticType, extra?: Diagnostic["extra"]): void;
|
|
49
50
|
export declare function diagnosticHelper(diagnostics: Record<string, Diagnostic[]>, node: mctree.Node, message: string | null, type: DiagnosticType | undefined, extra: Diagnostic["extra"] | undefined, uniqueLocs: boolean): void;
|
|
50
51
|
export declare function getSuperClasses(klass: ClassStateNode): Set<StateNode> | null;
|
|
@@ -14,7 +14,7 @@ export declare type Block<T extends EventConstraint<T>> = {
|
|
|
14
14
|
bogopred?: Block<T>;
|
|
15
15
|
events?: T[];
|
|
16
16
|
};
|
|
17
|
-
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1) => T | T[] | null): Block<T>;
|
|
17
|
+
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, refsForUpdate: boolean, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1, containedEvents: () => T[]) => T | T[] | null): Block<T>;
|
|
18
18
|
export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
19
19
|
export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
20
20
|
export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
package/build/src/data-flow.d.ts
CHANGED
|
@@ -2,12 +2,13 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
|
2
2
|
import { BaseEvent, Block } from "./control-flow";
|
|
3
3
|
import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
|
|
4
4
|
export declare type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
|
|
5
|
-
export declare type
|
|
5
|
+
export declare type MemberDecl = {
|
|
6
6
|
type: "MemberDecl";
|
|
7
7
|
node: mctree.MemberExpression;
|
|
8
8
|
base: StateNodeDecl | StateNodeDecl[];
|
|
9
9
|
path: mctree.MemberExpression[];
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
export declare type EventDecl = StateNodeDecl | StateNodeDecl[] | mctree.Literal | MemberDecl | {
|
|
11
12
|
type: "Unknown";
|
|
12
13
|
node: mctree.MemberExpression | mctree.Identifier | mctree.ThisExpression;
|
|
13
14
|
};
|
|
@@ -26,6 +27,7 @@ export interface DefEvent extends BaseEvent {
|
|
|
26
27
|
node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator;
|
|
27
28
|
decl: EventDecl;
|
|
28
29
|
rhs?: EventDecl;
|
|
30
|
+
containedEvents?: Array<RefEvent | ModEvent>;
|
|
29
31
|
}
|
|
30
32
|
export interface ModEvent extends BaseEvent {
|
|
31
33
|
type: "mod";
|
|
@@ -97,7 +99,7 @@ export declare function declName(decl: EventDecl): string | undefined;
|
|
|
97
99
|
export declare function unhandledType(node: never): never;
|
|
98
100
|
export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
|
|
99
101
|
identifiers: Set<string>;
|
|
100
|
-
graph: Block<
|
|
102
|
+
graph: Block<Event>;
|
|
101
103
|
};
|
|
102
104
|
export declare class DataflowQueue {
|
|
103
105
|
private enqueued;
|
package/build/src/inliner.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
3
|
export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
|
|
4
|
+
export declare function inlineRequested(state: ProgramStateAnalysis, func: FunctionStateNode): boolean;
|
|
4
5
|
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
|
|
5
6
|
declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
6
7
|
export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
|
7
8
|
export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
|
|
9
|
+
export declare function inlineDiagnostic(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, message: string | null): void;
|
|
8
10
|
export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
|
|
9
11
|
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
|
10
12
|
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
@@ -37,6 +37,8 @@ export declare type BuildConfig = {
|
|
|
37
37
|
useLocalOptimizer?: boolean;
|
|
38
38
|
propagateTypes?: boolean;
|
|
39
39
|
trustDeclaredTypes?: boolean;
|
|
40
|
+
minimizeLocals?: boolean;
|
|
41
|
+
singleUseCopyProp?: boolean;
|
|
40
42
|
covarianceWarnings?: boolean;
|
|
41
43
|
checkTypes?: DiagnosticType | "OFF";
|
|
42
44
|
};
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { xmlUtil } from "./sdk-util";
|
|
|
7
7
|
import { TypeMap } from "./type-flow/interp";
|
|
8
8
|
import { copyRecursiveAsNeeded } from "./util";
|
|
9
9
|
export * from "./optimizer-types";
|
|
10
|
+
export { display } from "./type-flow/types";
|
|
10
11
|
export { copyRecursiveAsNeeded, get_jungle, JungleBuildDependencies, JungleError, JungleResourceMap, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
|
|
11
12
|
export declare const defaultConfig: {
|
|
12
13
|
outputPath: string;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { ExactOrUnion } from "./types";
|
|
2
|
+
export declare function couldBeHelper(a: ExactOrUnion, b: ExactOrUnion, shallow: boolean): boolean;
|
|
2
3
|
export declare function couldBe(a: ExactOrUnion, b: ExactOrUnion): boolean;
|
|
3
4
|
export declare function couldBeWeak(a: ExactOrUnion, b: ExactOrUnion): boolean;
|
|
5
|
+
export declare function couldBeShallow(a: ExactOrUnion, b: ExactOrUnion): boolean;
|
|
@@ -2,9 +2,17 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
|
2
2
|
import { NodeEquivMap } from "src/type-flow";
|
|
3
3
|
import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
|
|
4
4
|
import { TypeFlowBlock, TypeStateKey } from "./type-flow-util";
|
|
5
|
-
export declare
|
|
5
|
+
export declare type CopyPropStores = Map<mctree.Node, {
|
|
6
|
+
ref: mctree.Node;
|
|
7
|
+
ant: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function findDeadStores(func: FunctionStateNode, graph: TypeFlowBlock, nodeEquivs: NodeEquivMap | null, findCopyPropCandidates: boolean, logThisRun: boolean): {
|
|
6
10
|
deadStores: Set<mctree.Node>;
|
|
7
11
|
locals: Set<TypeStateKey>;
|
|
8
12
|
localConflicts: Map<TypeStateKey, Set<TypeStateKey>> | null;
|
|
13
|
+
copyPropStores: CopyPropStores;
|
|
14
|
+
};
|
|
15
|
+
export declare function eliminateDeadStores(state: ProgramStateAnalysis, func: FunctionStateNode, graph: TypeFlowBlock, logThisRun: boolean): {
|
|
16
|
+
changes: boolean;
|
|
17
|
+
copyPropStores: CopyPropStores;
|
|
9
18
|
};
|
|
10
|
-
export declare function eliminateDeadStores(state: ProgramStateAnalysis, func: FunctionStateNode, graph: TypeFlowBlock, logThisRun: boolean): boolean;
|
|
@@ -12,5 +12,5 @@ declare type SysCallHelperResult = {
|
|
|
12
12
|
argEffects?: true;
|
|
13
13
|
};
|
|
14
14
|
declare type SysCallHelper = (state: ProgramStateAnalysis, func: FunctionStateNode, calleeObj: ExactOrUnion, getArgs: () => Array<ExactOrUnion>) => SysCallHelperResult;
|
|
15
|
-
export declare function sysCallInfo(func: FunctionStateNode): SysCallHelper | null;
|
|
15
|
+
export declare function sysCallInfo(state: ProgramStateAnalysis, func: FunctionStateNode): SysCallHelper | null;
|
|
16
16
|
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { DataFlowBlock as TypeFlowBlock, Event, EventDecl } from "../data-flow";
|
|
3
|
-
import { VariableStateNode } from "../optimizer-types";
|
|
3
|
+
import { ProgramStateAnalysis, StateNode, VariableStateNode } from "../optimizer-types";
|
|
4
|
+
import { InterpState } from "./interp";
|
|
5
|
+
import { ExactOrUnion } from "./types";
|
|
4
6
|
export { TypeFlowBlock };
|
|
5
7
|
export declare function isTypeStateKey(decl: EventDecl): decl is TypeStateKey;
|
|
6
8
|
export declare function declIsLocal(decl: EventDecl): decl is VariableStateNode | VariableStateNode[] | mctree.TypedIdentifier;
|
|
9
|
+
export declare function declIsNonLocal(decl: EventDecl): decl is VariableStateNode | VariableStateNode[];
|
|
7
10
|
export declare function localDeclName(decl: EventDecl): string;
|
|
8
11
|
export declare type TypeStateKey = Exclude<EventDecl, {
|
|
9
12
|
type: "MemberDecl" | "Unknown";
|
|
@@ -14,3 +17,11 @@ export declare function printBlockHeader(block: TypeFlowBlock): void;
|
|
|
14
17
|
export declare function describeEvent(event: Event): string;
|
|
15
18
|
export declare function printBlockEvents(block: TypeFlowBlock, extra?: (event: Event) => string): void;
|
|
16
19
|
export declare function printBlockTrailer(block: TypeFlowBlock): void;
|
|
20
|
+
export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): readonly [null, null] | [StateNode[], StateNode[]];
|
|
21
|
+
export declare function refineObjectTypeByDecls(istate: InterpState, object: ExactOrUnion, trueDecls: StateNode[]): ExactOrUnion;
|
|
22
|
+
export declare function findNextObjectType(istate: InterpState, trueDecls: StateNode[], next: mctree.DottedMemberExpression): import("./types").UnionType | import("./types").NumberType | import("./types").LongType | import("./types").FloatType | import("./types").DoubleType | import("./types").CharType | import("./types").StringType | import("./types").ArrayType | import("./types").DictionaryType | import("./types").MethodType | import("./types").ModuleType | import("./types").FunctionType | import("./types").ClassType | import("./types").ObjectType | import("./types").EnumType | import("./types").SymbolType | import("./types").TypedefType | null;
|
|
23
|
+
export declare function resolveDottedMember(istate: InterpState, object: ExactOrUnion, next: mctree.DottedMemberExpression): {
|
|
24
|
+
mayThrow: boolean;
|
|
25
|
+
object: ExactOrUnion;
|
|
26
|
+
property: import("./types").UnionType | import("./types").NumberType | import("./types").LongType | import("./types").FloatType | import("./types").DoubleType | import("./types").CharType | import("./types").StringType | import("./types").ArrayType | import("./types").DictionaryType | import("./types").MethodType | import("./types").ModuleType | import("./types").FunctionType | import("./types").ClassType | import("./types").ObjectType | import("./types").EnumType | import("./types").SymbolType | import("./types").TypedefType;
|
|
27
|
+
} | null;
|
|
@@ -26,7 +26,7 @@ export declare const enum TypeTag {
|
|
|
26
26
|
Typedef = 262144,
|
|
27
27
|
Any = 524287
|
|
28
28
|
}
|
|
29
|
-
export declare function typeTagName(tag: TypeTag): "
|
|
29
|
+
export declare function typeTagName(tag: TypeTag): "Never" | "Null" | "False" | "True" | "Boolean" | "Number" | "Long" | "Float" | "Double" | "Decimal" | "Numeric" | "Char" | "String" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Object" | "Enum" | "Symbol" | "Typedef" | "Any";
|
|
30
30
|
export declare const LastTypeTag = TypeTag.Typedef;
|
|
31
31
|
export declare const SingletonTypeTagsConst: number;
|
|
32
32
|
export declare const UnionDataTypeTagsConst: number;
|
package/build/src/type-flow.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { EventDecl } from "./data-flow";
|
|
3
|
-
import { FunctionStateNode, ProgramStateAnalysis
|
|
2
|
+
import { Event, EventDecl } from "./data-flow";
|
|
3
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
4
4
|
import { InterpState } from "./type-flow/interp";
|
|
5
5
|
import { TypeStateKey } from "./type-flow/type-flow-util";
|
|
6
|
-
import { ExactOrUnion } from "./type-flow/types";
|
|
7
6
|
export declare const missingNullWorkaround = true;
|
|
8
7
|
export declare type NodeEquivMap = Map<mctree.Node, {
|
|
9
8
|
decl: EventDecl;
|
|
@@ -11,15 +10,9 @@ export declare type NodeEquivMap = Map<mctree.Node, {
|
|
|
11
10
|
}>;
|
|
12
11
|
export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode, optimizeEquivalencies: boolean): InterpState | undefined;
|
|
13
12
|
export declare function buildConflictGraph(state: ProgramStateAnalysis, func: FunctionStateNode): {
|
|
14
|
-
graph: import("./control-flow").Block<
|
|
13
|
+
graph: import("./control-flow").Block<Event>;
|
|
15
14
|
localConflicts: Map<TypeStateKey, Set<TypeStateKey>> | null;
|
|
16
15
|
locals: Set<TypeStateKey>;
|
|
17
16
|
identifiers: Set<string>;
|
|
18
17
|
logThisRun: boolean;
|
|
19
18
|
} | undefined;
|
|
20
|
-
export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): readonly [null, null] | [StateNode[], StateNode[]];
|
|
21
|
-
export declare function resolveDottedMember(istate: InterpState, object: ExactOrUnion, next: mctree.DottedMemberExpression): {
|
|
22
|
-
mayThrow: boolean;
|
|
23
|
-
object: ExactOrUnion;
|
|
24
|
-
property: import("./type-flow/types").UnionType | import("./type-flow/types").NumberType | import("./type-flow/types").LongType | import("./type-flow/types").FloatType | import("./type-flow/types").DoubleType | import("./type-flow/types").CharType | import("./type-flow/types").StringType | import("./type-flow/types").ArrayType | import("./type-flow/types").DictionaryType | import("./type-flow/types").MethodType | import("./type-flow/types").ModuleType | import("./type-flow/types").FunctionType | import("./type-flow/types").ClassType | import("./type-flow/types").ObjectType | import("./type-flow/types").EnumType | import("./type-flow/types").SymbolType | import("./type-flow/types").TypedefType;
|
|
25
|
-
} | null;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
1
2
|
import { ProgramStateAnalysis } from "./optimizer-types";
|
|
3
|
+
export declare function renameIdentifier(ident: mctree.Identifier, newName: string): void;
|
|
2
4
|
export declare function renameVariable(state: ProgramStateAnalysis, locals: NonNullable<ProgramStateAnalysis["localsStack"]>[number], declName: string | null): string | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.11",
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"author": "markw65",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
43
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.44"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/chai": "^4.3.4",
|