@markw65/monkeyc-optimizer 1.1.32 → 1.1.34
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 +1 -918
- package/build/api.cjs +31 -31
- package/build/{chunk-NUE3G2QE.cjs → chunk-QBCVUVLD.cjs} +180 -49
- package/build/optimizer.cjs +17 -17
- package/build/sdk-util.cjs +14 -14
- package/build/src/api.d.ts +1 -1
- package/build/src/projects.d.ts +1 -0
- package/build/src/readprg.d.ts +0 -6
- package/build/src/src/api.d.ts +51 -0
- package/build/src/src/ast.d.ts +59 -0
- package/build/src/src/build.d.ts +7 -0
- package/build/src/src/cftinfo.d.ts +32 -0
- package/build/src/src/control-flow.d.ts +22 -0
- package/build/src/src/data-flow.d.ts +107 -0
- package/build/src/src/driver.d.ts +2 -0
- package/build/src/src/function-info.d.ts +14 -0
- package/build/src/src/inliner.d.ts +13 -0
- package/build/src/src/jungles.d.ts +66 -0
- package/build/src/src/launch.d.ts +5 -0
- package/build/src/src/logger.d.ts +6 -0
- package/build/src/src/manifest.d.ts +11 -0
- package/build/src/src/mc-rewrite.d.ts +13 -0
- package/build/src/src/negative-fixups.d.ts +1 -0
- package/build/src/src/optimizer-types.d.ts +249 -0
- package/build/src/src/optimizer.d.ts +100 -0
- package/build/src/src/pragma-checker.d.ts +3 -0
- package/build/src/src/pre.d.ts +2 -0
- package/build/src/src/projects.d.ts +26 -0
- package/build/src/src/readprg/array-init.d.ts +3 -0
- package/build/src/src/readprg/bytecode.d.ts +72 -0
- package/build/src/src/readprg/cflow.d.ts +17 -0
- package/build/src/src/readprg/data.d.ts +4 -0
- package/build/src/src/readprg/dce.d.ts +6 -0
- package/build/src/src/readprg/emit.d.ts +23 -0
- package/build/src/src/readprg/exceptions.d.ts +10 -0
- package/build/src/src/readprg/header.d.ts +15 -0
- package/build/src/src/readprg/interp.d.ts +21 -0
- package/build/src/src/readprg/linenum.d.ts +29 -0
- package/build/src/src/readprg/locals.d.ts +3 -0
- package/build/src/src/readprg/opcodes.d.ts +279 -0
- package/build/src/src/readprg/optimize.d.ts +3 -0
- package/build/src/src/readprg/pre.d.ts +2 -0
- package/build/src/src/readprg/sharing.d.ts +2 -0
- package/build/src/src/readprg/signer.d.ts +8 -0
- package/build/src/src/readprg/symbols.d.ts +19 -0
- package/build/src/src/readprg.d.ts +25 -0
- package/build/src/src/resources.d.ts +12 -0
- package/build/src/src/sdk-util.d.ts +28 -0
- package/build/src/src/type-flow/could-be.d.ts +5 -0
- package/build/src/src/type-flow/dead-store.d.ts +18 -0
- package/build/src/src/type-flow/interp-binary.d.ts +4 -0
- package/build/src/src/type-flow/interp-call.d.ts +16 -0
- package/build/src/src/type-flow/interp.d.ts +33 -0
- package/build/src/src/type-flow/intersection-type.d.ts +4 -0
- package/build/src/src/type-flow/minimize-locals.d.ts +4 -0
- package/build/src/src/type-flow/minimize-modules.d.ts +3 -0
- package/build/src/src/type-flow/optimize.d.ts +7 -0
- package/build/src/src/type-flow/sub-type.d.ts +2 -0
- package/build/src/src/type-flow/type-flow-util.d.ts +27 -0
- package/build/src/src/type-flow/types.d.ts +204 -0
- package/build/src/src/type-flow/union-type.d.ts +4 -0
- package/build/src/src/type-flow.d.ts +18 -0
- package/build/src/src/unused-exprs.d.ts +3 -0
- package/build/src/src/util.d.ts +33 -0
- package/build/src/src/variable-renamer.d.ts +4 -0
- package/build/src/src/visitor.d.ts +5 -0
- package/build/src/src/worker-pool.d.ts +4 -0
- package/build/src/src/worker-task.d.ts +88 -0
- package/build/src/src/worker-thread.d.ts +1 -0
- package/build/src/src/xml-util.d.ts +172 -0
- package/build/src/test/mocha/bytecode.spec.d.ts +1 -0
- package/build/src/test/mocha/coudbe.spec.d.ts +2 -0
- package/build/src/test/mocha/intersection.spec.d.ts +2 -0
- package/build/src/test/mocha/root.spec.d.ts +1 -0
- package/build/src/test/mocha/subtype.spec.d.ts +2 -0
- package/build/src/test/mocha/test-utils.d.ts +6 -0
- package/build/src/test/mocha/types.spec.d.ts +1 -0
- package/build/src/type-flow/interp.d.ts +3 -1
- package/build/src/type-flow/types.d.ts +1 -1
- package/build/worker-thread.cjs +3 -3
- package/package.json +2 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import type { xmlUtil } from "./sdk-util";
|
|
3
|
+
export declare function traverseAst(node: mctree.Node, pre?: null | ((node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[]), post?: (node: mctree.Node, parent: mctree.Node | undefined) => void | null | false | mctree.Node | mctree.Node[], parent?: mctree.Node | undefined): false | void | null | mctree.Node | mctree.Node[];
|
|
4
|
+
export declare function isStatement(node: mctree.Node): node is mctree.Statement;
|
|
5
|
+
export declare function isExpression(node: mctree.Node): node is mctree.Expression;
|
|
6
|
+
export declare function mayThrow(node: mctree.Node): boolean;
|
|
7
|
+
export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
|
|
8
|
+
export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
9
|
+
export declare function withLoc<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined | false): T;
|
|
10
|
+
export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined | false, inplace?: boolean): T;
|
|
11
|
+
export declare function cloneDeep<T extends mctree.Node>(node: T): T;
|
|
12
|
+
interface NumberLiteral extends mctree.Literal {
|
|
13
|
+
value: number;
|
|
14
|
+
}
|
|
15
|
+
interface LongLiteral extends mctree.Literal {
|
|
16
|
+
value: number | bigint;
|
|
17
|
+
}
|
|
18
|
+
interface StringLiteral extends mctree.Literal {
|
|
19
|
+
value: string;
|
|
20
|
+
}
|
|
21
|
+
interface CharLiteral extends mctree.Literal {
|
|
22
|
+
value: string;
|
|
23
|
+
}
|
|
24
|
+
interface BooleanLiteral extends mctree.Literal {
|
|
25
|
+
value: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface NullLiteral extends mctree.Literal {
|
|
28
|
+
value: null;
|
|
29
|
+
}
|
|
30
|
+
type LiteralValues = [NumberLiteral, "Number" | "Float" | "Double"] | [LongLiteral, "Long"] | [StringLiteral, "String"] | [CharLiteral, "Char"] | [BooleanLiteral, "Boolean"] | [NullLiteral, "Null"];
|
|
31
|
+
export declare function getNodeValue(node: mctree.Literal): LiteralValues;
|
|
32
|
+
export declare function getNodeValue(node: mctree.Node): LiteralValues | [null, null];
|
|
33
|
+
export declare function wrap<T extends mctree.Node>(node: T, loc?: mctree.SourceLocation | null): T;
|
|
34
|
+
export declare function locRange(start: mctree.SourceLocation, end: mctree.SourceLocation): {
|
|
35
|
+
source: string | null | undefined;
|
|
36
|
+
start: mctree.Position;
|
|
37
|
+
end: mctree.Position;
|
|
38
|
+
};
|
|
39
|
+
export declare function adjustLoc(loc: xmlUtil.SourceLocation, start?: number, end?: number): {
|
|
40
|
+
readonly source: string | null | undefined;
|
|
41
|
+
readonly start: {
|
|
42
|
+
readonly offset: number;
|
|
43
|
+
readonly line: number;
|
|
44
|
+
readonly column: number;
|
|
45
|
+
};
|
|
46
|
+
readonly end: {
|
|
47
|
+
readonly offset: number;
|
|
48
|
+
readonly line: number;
|
|
49
|
+
readonly column: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare function makeIdentifier(name: string, loc?: mctree.SourceLocation | null | undefined): {
|
|
53
|
+
type: "Identifier";
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function makeMemberExpression(object: mctree.ScopedName, property: mctree.Identifier): mctree.DottedName;
|
|
57
|
+
export declare function makeScopedName(dotted: string, l?: mctree.SourceLocation): mctree.ScopedName;
|
|
58
|
+
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BuildConfig } from "./optimizer-types";
|
|
2
|
+
export declare function build_project(product: string | null, options: BuildConfig, lineCallback?: (line: string) => void): Promise<{
|
|
3
|
+
exe: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
program: string;
|
|
6
|
+
product: string | null;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function getCFTFontInfoFromBuffer(name: string, data: Buffer): {
|
|
3
|
+
name: string;
|
|
4
|
+
height: number;
|
|
5
|
+
ascent: number;
|
|
6
|
+
internalLeading: number;
|
|
7
|
+
charInfo: {
|
|
8
|
+
code: number;
|
|
9
|
+
char: string;
|
|
10
|
+
width: number;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export declare function getCFTFontInfo(filename: string): Promise<{
|
|
14
|
+
name: string;
|
|
15
|
+
height: number;
|
|
16
|
+
ascent: number;
|
|
17
|
+
internalLeading: number;
|
|
18
|
+
charInfo: {
|
|
19
|
+
code: number;
|
|
20
|
+
char: string;
|
|
21
|
+
width: number;
|
|
22
|
+
}[];
|
|
23
|
+
}>;
|
|
24
|
+
export declare function getDeviceFontInfo(dirname: string): Promise<{
|
|
25
|
+
device: string;
|
|
26
|
+
fontSets: {
|
|
27
|
+
[k: string]: {
|
|
28
|
+
[k: string]: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
langMap: Record<string, string>;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ProgramStateAnalysis, FunctionStateNode } from "./optimizer-types";
|
|
3
|
+
export type BaseEvent = {
|
|
4
|
+
type: string;
|
|
5
|
+
mayThrow: boolean;
|
|
6
|
+
};
|
|
7
|
+
type EventConstraint<_T> = BaseEvent;
|
|
8
|
+
export 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
|
+
bogopred?: Block<T>;
|
|
15
|
+
events?: T[];
|
|
16
|
+
};
|
|
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
|
+
export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
19
|
+
export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
20
|
+
export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
|
21
|
+
export declare function getPreOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { BaseEvent, Block } from "./control-flow";
|
|
3
|
+
import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
|
|
4
|
+
import { GenericQueue } from "./util";
|
|
5
|
+
export type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
|
|
6
|
+
export type MemberDecl = {
|
|
7
|
+
type: "MemberDecl";
|
|
8
|
+
node: mctree.MemberExpression;
|
|
9
|
+
base: StateNodeDecl | StateNodeDecl[];
|
|
10
|
+
path: mctree.MemberExpression[];
|
|
11
|
+
};
|
|
12
|
+
export type EventDecl = StateNodeDecl | StateNodeDecl[] | mctree.Literal | MemberDecl | {
|
|
13
|
+
type: "Unknown";
|
|
14
|
+
node: mctree.MemberExpression | mctree.Identifier | mctree.ThisExpression;
|
|
15
|
+
};
|
|
16
|
+
export interface RefEvent extends BaseEvent {
|
|
17
|
+
type: "ref";
|
|
18
|
+
node: RefNode;
|
|
19
|
+
decl: EventDecl;
|
|
20
|
+
}
|
|
21
|
+
export interface KillEvent extends BaseEvent {
|
|
22
|
+
type: "kil";
|
|
23
|
+
node: mctree.Node;
|
|
24
|
+
decl: StateNodeDecl | StateNodeDecl[];
|
|
25
|
+
}
|
|
26
|
+
export interface DefEvent extends BaseEvent {
|
|
27
|
+
type: "def";
|
|
28
|
+
node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator;
|
|
29
|
+
decl: EventDecl;
|
|
30
|
+
rhs?: EventDecl;
|
|
31
|
+
containedEvents?: Array<RefEvent | ModEvent>;
|
|
32
|
+
}
|
|
33
|
+
export interface ModEvent extends BaseEvent {
|
|
34
|
+
type: "mod";
|
|
35
|
+
node: mctree.Node;
|
|
36
|
+
decl?: EventDecl | undefined | null;
|
|
37
|
+
before?: boolean;
|
|
38
|
+
id?: RefNode;
|
|
39
|
+
callees?: FunctionStateNode[] | null;
|
|
40
|
+
calleeDecl?: EventDecl | undefined;
|
|
41
|
+
calleeObj?: EventDecl | undefined;
|
|
42
|
+
}
|
|
43
|
+
export declare enum FlowKind {
|
|
44
|
+
LEFT_EQ_RIGHT_DECL = 0,
|
|
45
|
+
LEFT_NE_RIGHT_DECL = 1,
|
|
46
|
+
LEFT_EQ_RIGHT_NODE = 2,
|
|
47
|
+
LEFT_NE_RIGHT_NODE = 3,
|
|
48
|
+
LEFT_TRUTHY = 4,
|
|
49
|
+
LEFT_FALSEY = 5,
|
|
50
|
+
INSTANCEOF = 6,
|
|
51
|
+
NOTINSTANCE = 7
|
|
52
|
+
}
|
|
53
|
+
export interface FlowEventDecl extends BaseEvent {
|
|
54
|
+
type: "flw";
|
|
55
|
+
node: mctree.BinaryExpression | mctree.UnaryExpression;
|
|
56
|
+
decl?: undefined;
|
|
57
|
+
kind: FlowKind.LEFT_EQ_RIGHT_DECL | FlowKind.LEFT_NE_RIGHT_DECL;
|
|
58
|
+
left: EventDecl;
|
|
59
|
+
right_decl: EventDecl;
|
|
60
|
+
right_node?: undefined;
|
|
61
|
+
}
|
|
62
|
+
export interface FlowEventNode extends BaseEvent {
|
|
63
|
+
type: "flw";
|
|
64
|
+
node: mctree.BinaryExpression | mctree.UnaryExpression;
|
|
65
|
+
decl?: undefined;
|
|
66
|
+
kind: FlowKind.LEFT_EQ_RIGHT_NODE | FlowKind.LEFT_NE_RIGHT_NODE;
|
|
67
|
+
left: EventDecl;
|
|
68
|
+
right_decl?: undefined;
|
|
69
|
+
right_node: mctree.Expression;
|
|
70
|
+
}
|
|
71
|
+
export interface FlowEventTruthy extends BaseEvent {
|
|
72
|
+
type: "flw";
|
|
73
|
+
node: mctree.Node;
|
|
74
|
+
decl?: undefined;
|
|
75
|
+
kind: FlowKind.LEFT_TRUTHY | FlowKind.LEFT_FALSEY;
|
|
76
|
+
left: EventDecl;
|
|
77
|
+
right_decl?: undefined;
|
|
78
|
+
right_node?: undefined;
|
|
79
|
+
}
|
|
80
|
+
export interface FlowEventInstanceof extends BaseEvent {
|
|
81
|
+
type: "flw";
|
|
82
|
+
node: mctree.InstanceofExpression | mctree.UnaryExpression;
|
|
83
|
+
decl?: undefined;
|
|
84
|
+
kind: FlowKind.INSTANCEOF | FlowKind.NOTINSTANCE;
|
|
85
|
+
left: EventDecl;
|
|
86
|
+
right_decl: EventDecl;
|
|
87
|
+
right_node?: undefined;
|
|
88
|
+
}
|
|
89
|
+
export type FlowEvent = FlowEventDecl | FlowEventNode | FlowEventTruthy | FlowEventInstanceof;
|
|
90
|
+
export interface ExnEvent extends BaseEvent {
|
|
91
|
+
type: "exn";
|
|
92
|
+
node: mctree.Node;
|
|
93
|
+
}
|
|
94
|
+
export type Event = RefEvent | KillEvent | DefEvent | ModEvent | FlowEvent | ExnEvent;
|
|
95
|
+
export interface DataFlowBlock extends Block<Event> {
|
|
96
|
+
order?: number;
|
|
97
|
+
}
|
|
98
|
+
export declare function declFullName(decl: EventDecl): string;
|
|
99
|
+
export declare function declName(decl: EventDecl): string | undefined;
|
|
100
|
+
export declare function unhandledType(node: never): never;
|
|
101
|
+
export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
|
|
102
|
+
identifiers: Set<string>;
|
|
103
|
+
graph: Block<Event>;
|
|
104
|
+
};
|
|
105
|
+
export declare class DataflowQueue extends GenericQueue<DataFlowBlock> {
|
|
106
|
+
constructor();
|
|
107
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { VariableStateNode, FunctionStateNode, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
|
+
export declare function cloneSet<T>(ae: Set<T>): Set<T>;
|
|
4
|
+
export declare function mergeSet<T>(a: Set<T>, b: Set<T>): void;
|
|
5
|
+
export declare function recordModifiedDecl(func: FunctionStateNode, decl: VariableStateNode): null;
|
|
6
|
+
export declare function recordModifiedDecls(func: FunctionStateNode, lookupDefs: LookupDefinition[]): void;
|
|
7
|
+
export declare function recordModifiedName(func: FunctionStateNode, name: string): void;
|
|
8
|
+
export declare function recordModifiedUnknown(func: FunctionStateNode): void;
|
|
9
|
+
export declare function recordCalledFunc(func: FunctionStateNode, callee: FunctionStateNode): null;
|
|
10
|
+
export declare function recordCalledFuncs(func: FunctionStateNode, callees: FunctionStateNode[]): void;
|
|
11
|
+
export declare function functionMayModify(state: ProgramStateAnalysis, func: FunctionStateNode, decl: VariableStateNode): boolean;
|
|
12
|
+
export declare function findCallees(lookupDefs: LookupDefinition[]): FunctionStateNode[] | null;
|
|
13
|
+
export declare function findCalleesForNew(lookupDefs: LookupDefinition[]): FunctionStateNode[];
|
|
14
|
+
export declare function findCalleesByNode(state: ProgramStateAnalysis, callee: mctree.Expression): FunctionStateNode[] | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
3
|
+
export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
|
|
4
|
+
export declare function inlineRequested(state: ProgramStateAnalysis, func: FunctionStateNode): boolean;
|
|
5
|
+
export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
|
|
6
|
+
type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
|
|
7
|
+
export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
|
|
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;
|
|
10
|
+
export type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
|
|
11
|
+
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
|
12
|
+
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ManifestXML } from "./manifest";
|
|
2
|
+
import { BuildConfig } from "./optimizer-types.js";
|
|
3
|
+
import { DeviceInfo, xmlUtil } from "./sdk-util";
|
|
4
|
+
export type JungleBuildDependencies = Record<string, xmlUtil.Document | true>;
|
|
5
|
+
export type JungleError = Error & {
|
|
6
|
+
buildDependencies?: JungleBuildDependencies;
|
|
7
|
+
};
|
|
8
|
+
export type Target = {
|
|
9
|
+
product: string;
|
|
10
|
+
qualifier: JungleQualifier;
|
|
11
|
+
shape?: string;
|
|
12
|
+
group?: {
|
|
13
|
+
optimizerConfig: JungleQualifier;
|
|
14
|
+
dir?: string;
|
|
15
|
+
key: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
type LangResourcePaths = {
|
|
19
|
+
[key: string]: string[];
|
|
20
|
+
};
|
|
21
|
+
type BarrelAnnotations = {
|
|
22
|
+
[key: string]: string[];
|
|
23
|
+
};
|
|
24
|
+
type BarrelMap = {
|
|
25
|
+
[key: string]: ResolvedBarrel;
|
|
26
|
+
};
|
|
27
|
+
type OptBarrelMap = Record<string, {
|
|
28
|
+
rawBarrelDir: string;
|
|
29
|
+
manifest: string;
|
|
30
|
+
jungleFiles: string[];
|
|
31
|
+
optBarrelDir: string;
|
|
32
|
+
}>;
|
|
33
|
+
export type JungleQualifier = {
|
|
34
|
+
sourcePath?: string[];
|
|
35
|
+
sourceExcludes?: string[];
|
|
36
|
+
excludeAnnotations?: string[];
|
|
37
|
+
resourcePath?: string[];
|
|
38
|
+
personality?: string[];
|
|
39
|
+
lang?: LangResourcePaths;
|
|
40
|
+
barrelPath?: (string | string[])[];
|
|
41
|
+
annotations?: BarrelAnnotations;
|
|
42
|
+
barrelMap?: BarrelMap;
|
|
43
|
+
optBarrels?: OptBarrelMap;
|
|
44
|
+
resourceMap?: JungleResourceMap;
|
|
45
|
+
products?: string[];
|
|
46
|
+
};
|
|
47
|
+
type JungleInfoBase = {
|
|
48
|
+
jungles: string[];
|
|
49
|
+
manifest: string;
|
|
50
|
+
xml: ManifestXML;
|
|
51
|
+
annotations?: string[];
|
|
52
|
+
resources: JungleResourceMap;
|
|
53
|
+
buildDependencies: JungleBuildDependencies;
|
|
54
|
+
devices: DeviceInfo;
|
|
55
|
+
};
|
|
56
|
+
export type JungleResourceMap = Record<string, xmlUtil.Document>;
|
|
57
|
+
export type ResolvedJungle = JungleInfoBase & {
|
|
58
|
+
targets: Target[];
|
|
59
|
+
typeCheckLevel?: string;
|
|
60
|
+
optimizationLevel?: string;
|
|
61
|
+
};
|
|
62
|
+
export type ResolvedBarrel = JungleInfoBase & {
|
|
63
|
+
qualifier: JungleQualifier;
|
|
64
|
+
};
|
|
65
|
+
export declare function get_jungle(jungles: string, options: BuildConfig, resources?: JungleResourceMap | undefined): Promise<ResolvedJungle>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LineHandler } from "./util";
|
|
2
|
+
export declare function launchSimulator(force?: boolean): Promise<void>;
|
|
3
|
+
export declare function checkIfSimulatorRunning(): Promise<boolean>;
|
|
4
|
+
export declare function checkIfSimulatorRunningOn(port: number): Promise<boolean>;
|
|
5
|
+
export declare function simulateProgram(prg: string, device: string, test?: boolean | string, logger?: LineHandler | LineHandler[]): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function logger(module: string, level: number, message: unknown): void;
|
|
2
|
+
export declare function wouldLog(module: string, level: number): boolean;
|
|
3
|
+
export declare function bumpLogging(module: string | null, amount: number): void;
|
|
4
|
+
export declare function setBanner(b: (() => string) | null): void;
|
|
5
|
+
export declare function log(message: unknown): void;
|
|
6
|
+
export declare function setLogger(log: (message: string) => void): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { xmlUtil } from "./sdk-util";
|
|
2
|
+
export type ManifestXML = xmlUtil.Document;
|
|
3
|
+
export declare function readManifest(manifest: string): Promise<ManifestXML>;
|
|
4
|
+
export declare function writeManifest(filename: string, xml: ManifestXML): Promise<void>;
|
|
5
|
+
export declare function manifestProducts(manifest: ManifestXML): string[];
|
|
6
|
+
export declare function manifestBarrels(manifest: ManifestXML): string[];
|
|
7
|
+
export declare function manifestDropBarrels(manifest: ManifestXML): void;
|
|
8
|
+
export declare function manifestBarrelName(manifestName: string, manifest: ManifestXML): string;
|
|
9
|
+
export declare function manifestAnnotations(manifest: ManifestXML): string[] | undefined;
|
|
10
|
+
export declare function manifestLanguages(manifest: ManifestXML): string[] | undefined;
|
|
11
|
+
export declare function checkManifest(manifest: ManifestXML, products: string[]): Promise<boolean>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { JungleResourceMap } from "./jungles";
|
|
3
|
+
import { BuildConfig, FilesToOptimizeMap, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
4
|
+
import { xmlUtil } from "./sdk-util";
|
|
5
|
+
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
6
|
+
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
7
|
+
export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
8
|
+
export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
|
|
9
|
+
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
10
|
+
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<{
|
|
11
|
+
diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
|
|
12
|
+
sdkVersion: number | undefined;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const negativeFixups: string[];
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { EnumStringMember } from "@markw65/prettier-plugin-monkeyc/build/estree-types";
|
|
3
|
+
import { xmlUtil } from "./sdk-util";
|
|
4
|
+
import { ExactOrUnion } from "./type-flow/types";
|
|
5
|
+
export type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
6
|
+
export type LookupRules = "COMPILER1" | "COMPILER2" | "DEFAULT";
|
|
7
|
+
export type EnforceStatic = "YES" | "NO";
|
|
8
|
+
export type BuildConfig = {
|
|
9
|
+
workspace?: string;
|
|
10
|
+
jungleFiles?: string;
|
|
11
|
+
developerKeyPath?: string;
|
|
12
|
+
typeCheckLevel?: string;
|
|
13
|
+
optimizationLevel?: string;
|
|
14
|
+
compilerOptions?: string;
|
|
15
|
+
compilerWarnings?: boolean;
|
|
16
|
+
simulatorBuild?: boolean;
|
|
17
|
+
releaseBuild?: boolean;
|
|
18
|
+
testBuild?: boolean;
|
|
19
|
+
products?: string[];
|
|
20
|
+
buildDir?: string;
|
|
21
|
+
outputPath?: string;
|
|
22
|
+
program?: string;
|
|
23
|
+
skipOptimization?: boolean;
|
|
24
|
+
checkManifest?: boolean;
|
|
25
|
+
device?: string;
|
|
26
|
+
ignoredExcludeAnnotations?: string;
|
|
27
|
+
ignoredAnnotations?: string;
|
|
28
|
+
ignoredSourcePaths?: string;
|
|
29
|
+
returnCommand?: boolean;
|
|
30
|
+
checkBuildPragmas?: boolean;
|
|
31
|
+
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
32
|
+
checkCompilerLookupRules?: DiagnosticType | "OFF";
|
|
33
|
+
compilerLookupRules?: LookupRules;
|
|
34
|
+
enforceStatic?: EnforceStatic;
|
|
35
|
+
sizeBasedPRE?: boolean | string;
|
|
36
|
+
prettier?: Record<string, unknown>;
|
|
37
|
+
extensionVersion?: string;
|
|
38
|
+
useLocalOptimizer?: boolean;
|
|
39
|
+
propagateTypes?: boolean;
|
|
40
|
+
trustDeclaredTypes?: boolean;
|
|
41
|
+
minimizeLocals?: boolean;
|
|
42
|
+
minimizeModules?: boolean;
|
|
43
|
+
postBuildOptimizer?: boolean;
|
|
44
|
+
singleUseCopyProp?: boolean;
|
|
45
|
+
iterateOptimizer?: boolean;
|
|
46
|
+
covarianceWarnings?: boolean;
|
|
47
|
+
checkTypes?: DiagnosticType | "OFF";
|
|
48
|
+
removeArgc?: boolean;
|
|
49
|
+
postBuildPRE?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier;
|
|
52
|
+
export type StateNodeDecls = {
|
|
53
|
+
[key: string]: StateNodeDecl[];
|
|
54
|
+
};
|
|
55
|
+
export type ImportUsing = {
|
|
56
|
+
node: mctree.Using | mctree.ImportModule;
|
|
57
|
+
module?: ModuleStateNode | null | undefined;
|
|
58
|
+
};
|
|
59
|
+
export declare const enum StateNodeAttributes {
|
|
60
|
+
NONE = 0,
|
|
61
|
+
PUBLIC = 1,
|
|
62
|
+
PROTECTED = 2,
|
|
63
|
+
PRIVATE = 4,
|
|
64
|
+
STATIC = 8
|
|
65
|
+
}
|
|
66
|
+
interface BaseStateNode {
|
|
67
|
+
type: string;
|
|
68
|
+
node: mctree.Node | null | undefined;
|
|
69
|
+
name: string | null | undefined;
|
|
70
|
+
fullName: string | null | undefined;
|
|
71
|
+
decls?: StateNodeDecls | undefined;
|
|
72
|
+
type_decls?: StateNodeDecls | undefined;
|
|
73
|
+
stack?: ProgramStateStack | undefined;
|
|
74
|
+
attributes: StateNodeAttributes;
|
|
75
|
+
}
|
|
76
|
+
export interface ProgramStateNode extends BaseStateNode {
|
|
77
|
+
type: "Program";
|
|
78
|
+
node: mctree.Program | undefined;
|
|
79
|
+
name: "$";
|
|
80
|
+
fullName: "$";
|
|
81
|
+
stack?: undefined;
|
|
82
|
+
}
|
|
83
|
+
export interface ModuleStateNode extends BaseStateNode {
|
|
84
|
+
type: "ModuleDeclaration";
|
|
85
|
+
node: mctree.ModuleDeclaration;
|
|
86
|
+
name: string;
|
|
87
|
+
fullName: string;
|
|
88
|
+
}
|
|
89
|
+
export interface ClassStateNode extends BaseStateNode {
|
|
90
|
+
type: "ClassDeclaration";
|
|
91
|
+
node: mctree.ClassDeclaration;
|
|
92
|
+
name: string;
|
|
93
|
+
fullName: string;
|
|
94
|
+
superClass?: ClassStateNode[] | true;
|
|
95
|
+
hasInvoke?: boolean;
|
|
96
|
+
superClasses?: Set<StateNode>;
|
|
97
|
+
}
|
|
98
|
+
export type FunctionInfo = {
|
|
99
|
+
modifiedDecls: Set<VariableStateNode>;
|
|
100
|
+
calledFuncs: Set<FunctionStateNode>;
|
|
101
|
+
resolvedDecls?: Set<VariableStateNode>;
|
|
102
|
+
callsExposed?: boolean;
|
|
103
|
+
modifiedUnknown?: boolean;
|
|
104
|
+
modifiedNames?: Set<string>;
|
|
105
|
+
};
|
|
106
|
+
export interface FunctionStateNode extends BaseStateNode {
|
|
107
|
+
type: "FunctionDeclaration";
|
|
108
|
+
node: mctree.FunctionDeclaration;
|
|
109
|
+
name: string;
|
|
110
|
+
fullName: string;
|
|
111
|
+
stack?: ProgramStateStack;
|
|
112
|
+
decls?: undefined;
|
|
113
|
+
info?: FunctionInfo | false;
|
|
114
|
+
next_info?: FunctionInfo;
|
|
115
|
+
}
|
|
116
|
+
export interface BlockStateNode extends BaseStateNode {
|
|
117
|
+
type: "BlockStatement";
|
|
118
|
+
name: undefined;
|
|
119
|
+
fullName: string;
|
|
120
|
+
node: mctree.BlockStatement | mctree.ForStatement;
|
|
121
|
+
stack?: undefined;
|
|
122
|
+
}
|
|
123
|
+
export interface TypedefStateNode extends BaseStateNode {
|
|
124
|
+
type: "TypedefDeclaration";
|
|
125
|
+
node: mctree.TypedefDeclaration;
|
|
126
|
+
name: string;
|
|
127
|
+
fullName: string;
|
|
128
|
+
isExpanding?: true;
|
|
129
|
+
isRecursive?: true;
|
|
130
|
+
resolvedType?: ExactOrUnion;
|
|
131
|
+
}
|
|
132
|
+
export interface VariableStateNode extends BaseStateNode {
|
|
133
|
+
type: "VariableDeclarator";
|
|
134
|
+
node: mctree.VariableDeclarator;
|
|
135
|
+
name: string;
|
|
136
|
+
fullName: string;
|
|
137
|
+
stack: ProgramStateStack;
|
|
138
|
+
used?: true;
|
|
139
|
+
resolvedType?: ExactOrUnion | undefined;
|
|
140
|
+
}
|
|
141
|
+
export interface EnumStateNode extends BaseStateNode {
|
|
142
|
+
type: "EnumDeclaration";
|
|
143
|
+
node: mctree.EnumDeclaration;
|
|
144
|
+
name: string;
|
|
145
|
+
fullName: string;
|
|
146
|
+
stack: ProgramStateStack;
|
|
147
|
+
resolvedType?: ExactOrUnion;
|
|
148
|
+
}
|
|
149
|
+
interface DiagnosticBase {
|
|
150
|
+
loc: mctree.SourceLocation;
|
|
151
|
+
message: string;
|
|
152
|
+
}
|
|
153
|
+
export interface DiagnosticInfo extends DiagnosticBase {
|
|
154
|
+
loc: Finalized<mctree.SourceLocation, "source">;
|
|
155
|
+
}
|
|
156
|
+
export interface Diagnostic extends DiagnosticBase {
|
|
157
|
+
type: DiagnosticType;
|
|
158
|
+
related?: DiagnosticInfo[];
|
|
159
|
+
extra?: {
|
|
160
|
+
uri: string;
|
|
161
|
+
message: string;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
type ProgramStateStackElem = {
|
|
165
|
+
sn: StateNode;
|
|
166
|
+
usings?: Record<string, ImportUsing>;
|
|
167
|
+
imports?: ImportUsing[];
|
|
168
|
+
};
|
|
169
|
+
export type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode | EnumStateNode;
|
|
170
|
+
export type ProgramStateStack = ProgramStateStackElem[];
|
|
171
|
+
export type LookupDefinition = {
|
|
172
|
+
parent: StateNode | null;
|
|
173
|
+
results: StateNodeDecl[];
|
|
174
|
+
};
|
|
175
|
+
export type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
|
|
176
|
+
export type ByNameStateNodeDecls = ModuleStateNode | ClassStateNode | FunctionStateNode | ProgramStateNode;
|
|
177
|
+
export type ProgramState = {
|
|
178
|
+
allFunctions?: Record<string, FunctionStateNode[]>;
|
|
179
|
+
allClasses?: ClassStateNode[];
|
|
180
|
+
invokeInfo?: FunctionInfo;
|
|
181
|
+
allDeclarations?: Record<string, ByNameStateNodeDecls[]>;
|
|
182
|
+
fnMap?: FilesToOptimizeMap;
|
|
183
|
+
rezAst?: mctree.Program;
|
|
184
|
+
manifestXML?: xmlUtil.Document;
|
|
185
|
+
stack?: ProgramStateStack;
|
|
186
|
+
top?: () => ProgramStateStackElem;
|
|
187
|
+
currentFunction?: FunctionStateNode;
|
|
188
|
+
removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
|
|
189
|
+
shouldExclude?: (node: mctree.Node) => boolean;
|
|
190
|
+
pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
|
|
191
|
+
post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
|
|
192
|
+
lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
193
|
+
lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
194
|
+
lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
195
|
+
lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
|
|
196
|
+
stackClone?: () => ProgramStateStack;
|
|
197
|
+
traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
|
|
198
|
+
inType?: number;
|
|
199
|
+
inlining?: true;
|
|
200
|
+
config?: BuildConfig;
|
|
201
|
+
sdk?: string;
|
|
202
|
+
sdkVersion?: number;
|
|
203
|
+
lookupRules?: LookupRules;
|
|
204
|
+
nextExposed?: Record<string, true>;
|
|
205
|
+
exposed?: Record<string, true>;
|
|
206
|
+
usedByName?: Record<string, true>;
|
|
207
|
+
calledFunctions?: {
|
|
208
|
+
[key: string]: mctree.FunctionDeclaration[];
|
|
209
|
+
};
|
|
210
|
+
localsStack?: {
|
|
211
|
+
node?: mctree.Node;
|
|
212
|
+
map?: {
|
|
213
|
+
[key: string]: boolean | string;
|
|
214
|
+
};
|
|
215
|
+
inners?: {
|
|
216
|
+
[key: string]: true;
|
|
217
|
+
};
|
|
218
|
+
}[];
|
|
219
|
+
index?: {
|
|
220
|
+
[key: string]: unknown[];
|
|
221
|
+
};
|
|
222
|
+
constants?: {
|
|
223
|
+
[key: string]: mctree.Literal;
|
|
224
|
+
};
|
|
225
|
+
diagnostics?: Record<string, Diagnostic[]>;
|
|
226
|
+
inlineDiagnostics?: Record<string, Diagnostic[]>;
|
|
227
|
+
enumMap?: Map<EnumStringMember, EnumStateNode>;
|
|
228
|
+
};
|
|
229
|
+
export type Finalized<T, Keys extends keyof T> = T & {
|
|
230
|
+
[key in Keys]-?: NonNullable<T[key]>;
|
|
231
|
+
};
|
|
232
|
+
export type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
233
|
+
export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
|
|
234
|
+
export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
235
|
+
export type ExcludeAnnotationsMap = {
|
|
236
|
+
[key: string]: boolean;
|
|
237
|
+
};
|
|
238
|
+
export type FilesToOptimizeMap = {
|
|
239
|
+
[key: string]: {
|
|
240
|
+
output: string;
|
|
241
|
+
barrel: string;
|
|
242
|
+
excludeAnnotations: ExcludeAnnotationsMap;
|
|
243
|
+
monkeyCSource?: string;
|
|
244
|
+
ast?: mctree.Program;
|
|
245
|
+
parserError?: Error;
|
|
246
|
+
hasTests?: boolean;
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
export {};
|