@markw65/monkeyc-optimizer 1.0.44 → 1.0.45
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 +18 -0
- package/build/api.cjs +905 -668
- package/build/optimizer.cjs +465 -214
- package/build/sdk-util.cjs +58 -0
- package/build/src/api.d.ts +3 -2
- package/build/src/ast.d.ts +26 -0
- package/build/src/data-flow.d.ts +45 -0
- package/build/src/function-info.d.ts +2 -0
- package/build/src/interp-binary.d.ts +4 -0
- package/build/src/interp-call.d.ts +3 -0
- package/build/src/interp.d.ts +23 -0
- package/build/src/jungles.d.ts +2 -1
- package/build/src/manifest.d.ts +1 -0
- package/build/src/mc-types.d.ts +166 -0
- package/build/src/optimizer-types.d.ts +12 -3
- package/build/src/pre.d.ts +1 -1
- package/build/src/projects.d.ts +2 -1
- package/build/src/type-flow.d.ts +4 -0
- package/build/src/util.d.ts +6 -1
- package/build/util.cjs +58 -2
- package/package.json +4 -3
package/build/sdk-util.cjs
CHANGED
|
@@ -325,6 +325,64 @@ function getNodeValue(node) {
|
|
|
325
325
|
}
|
|
326
326
|
throw new Error(`Literal has unknown type '${type}'`);
|
|
327
327
|
}
|
|
328
|
+
function wrap(node, loc) {
|
|
329
|
+
if (loc) {
|
|
330
|
+
node.loc = loc;
|
|
331
|
+
node.start = loc.start.offset;
|
|
332
|
+
node.end = loc.end.offset;
|
|
333
|
+
}
|
|
334
|
+
return node;
|
|
335
|
+
}
|
|
336
|
+
function locRange(start, end) {
|
|
337
|
+
return {
|
|
338
|
+
source: start.source || end.source,
|
|
339
|
+
start: start.start,
|
|
340
|
+
end: end.end,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function adjustLoc(loc, start = 1, end = -1) {
|
|
344
|
+
return {
|
|
345
|
+
source: loc.source,
|
|
346
|
+
start: {
|
|
347
|
+
offset: loc.start.offset + start,
|
|
348
|
+
line: loc.start.line,
|
|
349
|
+
column: loc.start.column + start,
|
|
350
|
+
},
|
|
351
|
+
end: {
|
|
352
|
+
offset: loc.end.offset + end,
|
|
353
|
+
line: loc.end.line,
|
|
354
|
+
column: loc.end.column + end,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function makeIdentifier(name, loc) {
|
|
359
|
+
return wrap({ type: "Identifier", name }, loc);
|
|
360
|
+
}
|
|
361
|
+
function makeMemberExpression(object, property) {
|
|
362
|
+
return wrap({
|
|
363
|
+
type: "MemberExpression",
|
|
364
|
+
object,
|
|
365
|
+
property,
|
|
366
|
+
computed: false,
|
|
367
|
+
}, object.loc && locRange(object.loc, property.loc));
|
|
368
|
+
}
|
|
369
|
+
function makeScopedName(dotted, l) {
|
|
370
|
+
const loc = l && adjustLoc(l, 0, l.start.offset - l.end.offset);
|
|
371
|
+
const result = dotted.split(/\s*\.\s*/).reduce(({ cur, offset }, next) => {
|
|
372
|
+
const id = makeIdentifier(next, loc && adjustLoc(loc, offset, offset + next.length));
|
|
373
|
+
if (!cur) {
|
|
374
|
+
cur = id;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
cur = makeMemberExpression(cur, id);
|
|
378
|
+
}
|
|
379
|
+
offset += next.length + 1;
|
|
380
|
+
return { cur, offset };
|
|
381
|
+
}, { cur: null, offset: 0 }).cur;
|
|
382
|
+
if (!result)
|
|
383
|
+
throw new Error("Failed to make a ScopedName");
|
|
384
|
+
return result;
|
|
385
|
+
}
|
|
328
386
|
|
|
329
387
|
;// CONCATENATED MODULE: ./src/xml-util.ts
|
|
330
388
|
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { hasProperty, traverseAst } from "./ast";
|
|
3
3
|
import { JungleResourceMap } from "./jungles";
|
|
4
|
-
import { FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl } from "./optimizer-types";
|
|
4
|
+
import { FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
5
5
|
import { visit_resources } from "./resources";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
7
|
export { visitorNode, visitReferences } from "./visitor";
|
|
@@ -22,5 +22,6 @@ export declare function findUsingForNode(state: ProgramStateLive, stack: Program
|
|
|
22
22
|
results: StateNodeDecl[];
|
|
23
23
|
};
|
|
24
24
|
}[] | null;
|
|
25
|
-
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo;
|
|
25
|
+
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo | false;
|
|
26
26
|
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
|
27
|
+
export declare function isLocal(v: VariableStateNode): boolean;
|
package/build/src/ast.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import type { xmlUtil } from "./sdk-util";
|
|
2
3
|
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[];
|
|
3
4
|
export declare function isStatement(node: mctree.Node): node is mctree.Statement;
|
|
4
5
|
export declare function isExpression(node: mctree.Node): node is mctree.Expression;
|
|
@@ -29,4 +30,29 @@ interface NullLiteral extends mctree.Literal {
|
|
|
29
30
|
declare type LiteralValues = [NumberLiteral, "Number" | "Float" | "Double"] | [LongLiteral, "Long"] | [StringLiteral, "String"] | [CharLiteral, "Char"] | [BooleanLiteral, "Boolean"] | [NullLiteral, "Null"];
|
|
30
31
|
export declare function getNodeValue(node: mctree.Literal): LiteralValues;
|
|
31
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;
|
|
32
58
|
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { BaseEvent, Block } from "./control-flow";
|
|
3
|
+
import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
|
|
4
|
+
export declare type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
|
|
5
|
+
export declare type EventDecl = StateNodeDecl | StateNodeDecl[] | mctree.Literal;
|
|
6
|
+
export interface RefEvent extends BaseEvent {
|
|
7
|
+
type: "ref";
|
|
8
|
+
node: RefNode;
|
|
9
|
+
decl: EventDecl;
|
|
10
|
+
}
|
|
11
|
+
export interface DefEvent extends BaseEvent {
|
|
12
|
+
type: "def";
|
|
13
|
+
node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator;
|
|
14
|
+
decl: EventDecl;
|
|
15
|
+
}
|
|
16
|
+
export interface ModEvent extends BaseEvent {
|
|
17
|
+
type: "mod";
|
|
18
|
+
node: mctree.Node;
|
|
19
|
+
decl?: EventDecl | undefined | null;
|
|
20
|
+
before?: boolean;
|
|
21
|
+
id?: RefNode;
|
|
22
|
+
callees?: FunctionStateNode[] | null;
|
|
23
|
+
}
|
|
24
|
+
export interface ExnEvent extends BaseEvent {
|
|
25
|
+
type: "exn";
|
|
26
|
+
node: mctree.Node;
|
|
27
|
+
}
|
|
28
|
+
export declare type Event = RefEvent | DefEvent | ModEvent | ExnEvent;
|
|
29
|
+
export interface DataFlowBlock extends Block<Event> {
|
|
30
|
+
order?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function declFullName(decl: EventDecl): string | undefined;
|
|
33
|
+
export declare function declName(decl: EventDecl): string | undefined;
|
|
34
|
+
export declare function unhandledExpression(node: never): void;
|
|
35
|
+
export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
|
|
36
|
+
identifiers: Set<string>;
|
|
37
|
+
graph: Block<RefEvent | DefEvent | ModEvent | ExnEvent>;
|
|
38
|
+
};
|
|
39
|
+
export declare class DataflowQueue {
|
|
40
|
+
private enqueued;
|
|
41
|
+
private queue;
|
|
42
|
+
enqueue(block: DataFlowBlock): void;
|
|
43
|
+
dequeue(): DataFlowBlock;
|
|
44
|
+
empty(): boolean;
|
|
45
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
1
2
|
import { VariableStateNode, FunctionStateNode, LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
3
|
export declare function cloneSet<T>(ae: Set<T>): Set<T>;
|
|
3
4
|
export declare function mergeSet<T>(a: Set<T>, b: Set<T>): void;
|
|
@@ -10,3 +11,4 @@ export declare function recordCalledFuncs(func: FunctionStateNode, callees: Func
|
|
|
10
11
|
export declare function functionMayModify(state: ProgramStateAnalysis, func: FunctionStateNode, decl: VariableStateNode): boolean;
|
|
11
12
|
export declare function findCallees(lookupDefs: LookupDefinition[]): FunctionStateNode[] | null;
|
|
12
13
|
export declare function findCalleesForNew(lookupDefs: LookupDefinition[]): FunctionStateNode[];
|
|
14
|
+
export declare function findCalleesByNode(state: ProgramStateAnalysis, callee: mctree.Expression): FunctionStateNode[] | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ExactOrUnion } from "./mc-types";
|
|
3
|
+
export declare function evaluateBinaryTypes(op: mctree.BinaryOperator | "instanceof", left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
|
|
4
|
+
export declare function evaluateLogicalTypes(op: mctree.LogicalOperator, left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ExactOrUnion } from "./type-flow/types";
|
|
3
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
4
|
+
export declare type TypeMap = Map<mctree.Node, ExactOrUnion>;
|
|
5
|
+
export declare type InterpStackElem = {
|
|
6
|
+
value: ExactOrUnion;
|
|
7
|
+
embeddedEffects: boolean;
|
|
8
|
+
node: mctree.Expression | mctree.TypeSpecList | mctree.InstanceOfCase;
|
|
9
|
+
};
|
|
10
|
+
export declare type InterpState = {
|
|
11
|
+
state: ProgramStateAnalysis;
|
|
12
|
+
stack: InterpStackElem[];
|
|
13
|
+
typeMap?: TypeMap;
|
|
14
|
+
func?: FunctionStateNode;
|
|
15
|
+
pre?: (node: mctree.Node) => mctree.Node | null | void;
|
|
16
|
+
post?: (node: mctree.Node) => mctree.Node | null | void;
|
|
17
|
+
};
|
|
18
|
+
export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
|
|
19
|
+
export declare function evaluateExpr(state: ProgramStateAnalysis, expr: mctree.Expression, typeMap?: TypeMap): InterpStackElem;
|
|
20
|
+
export declare function evaluate(istate: InterpState, node: mctree.Expression): InterpStackElem;
|
|
21
|
+
export declare function evaluate(istate: InterpState, node: mctree.Node): InterpStackElem | undefined;
|
|
22
|
+
export declare function evaluateNode(istate: InterpState, node: mctree.Node): void;
|
|
23
|
+
export declare function roundToFloat(value: number): number;
|
package/build/src/jungles.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ManifestXML } from "./manifest";
|
|
2
2
|
import { BuildConfig } from "./optimizer-types.js";
|
|
3
|
-
import { xmlUtil } from "./sdk-util";
|
|
3
|
+
import { DeviceInfo, xmlUtil } from "./sdk-util";
|
|
4
4
|
export declare type JungleBuildDependencies = Record<string, xmlUtil.Document | true>;
|
|
5
5
|
export declare type JungleError = Error & {
|
|
6
6
|
buildDependencies?: JungleBuildDependencies;
|
|
@@ -49,6 +49,7 @@ declare type JungleInfoBase = {
|
|
|
49
49
|
annotations?: string[];
|
|
50
50
|
resources: JungleResourceMap;
|
|
51
51
|
buildDependencies: JungleBuildDependencies;
|
|
52
|
+
devices: DeviceInfo;
|
|
52
53
|
};
|
|
53
54
|
export declare type JungleResourceMap = Record<string, xmlUtil.Document>;
|
|
54
55
|
export declare type ResolvedJungle = JungleInfoBase & {
|
package/build/src/manifest.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export declare function manifestBarrels(manifest: ManifestXML): string[];
|
|
|
7
7
|
export declare function manifestDropBarrels(manifest: ManifestXML): void;
|
|
8
8
|
export declare function manifestBarrelName(manifestName: string, manifest: ManifestXML): string;
|
|
9
9
|
export declare function manifestAnnotations(manifest: ManifestXML): string[] | undefined;
|
|
10
|
+
export declare function manifestLanguages(manifest: ManifestXML): string[] | undefined;
|
|
10
11
|
export declare function checkManifest(manifest: ManifestXML, products: string[]): Promise<boolean>;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl } from "./optimizer-types";
|
|
3
|
+
/**
|
|
4
|
+
* TypeBit gives the position of the 1 bit in TypeTag
|
|
5
|
+
*/
|
|
6
|
+
export declare enum TypeBit {
|
|
7
|
+
Null = 0,
|
|
8
|
+
False = 1,
|
|
9
|
+
True = 2,
|
|
10
|
+
Number = 3,
|
|
11
|
+
Long = 4,
|
|
12
|
+
Float = 5,
|
|
13
|
+
Double = 6,
|
|
14
|
+
Char = 7,
|
|
15
|
+
String = 8,
|
|
16
|
+
Array = 9,
|
|
17
|
+
Dictionary = 10,
|
|
18
|
+
Module = 11,
|
|
19
|
+
Function = 12,
|
|
20
|
+
Class = 13,
|
|
21
|
+
Object = 14,
|
|
22
|
+
Enum = 15,
|
|
23
|
+
Symbol = 16
|
|
24
|
+
}
|
|
25
|
+
export declare enum TypeTag {
|
|
26
|
+
Never = 0,
|
|
27
|
+
Null = 1,
|
|
28
|
+
False = 2,
|
|
29
|
+
True = 4,
|
|
30
|
+
Boolean = 6,
|
|
31
|
+
Number = 8,
|
|
32
|
+
Long = 16,
|
|
33
|
+
Float = 32,
|
|
34
|
+
Double = 64,
|
|
35
|
+
Numeric = 120,
|
|
36
|
+
Char = 128,
|
|
37
|
+
String = 256,
|
|
38
|
+
Array = 512,
|
|
39
|
+
Dictionary = 1024,
|
|
40
|
+
Module = 2048,
|
|
41
|
+
Function = 4096,
|
|
42
|
+
Class = 8192,
|
|
43
|
+
Object = 16384,
|
|
44
|
+
Enum = 32768,
|
|
45
|
+
Symbol = 65536,
|
|
46
|
+
Any = 131071
|
|
47
|
+
}
|
|
48
|
+
declare type ExactTypeTags = TypeTag.Null | TypeTag.False | TypeTag.True | TypeTag.Number | TypeTag.Long | TypeTag.Float | TypeTag.Double | TypeTag.Char | TypeTag.String | TypeTag.Array | TypeTag.Dictionary | TypeTag.Module | TypeTag.Function | TypeTag.Function | TypeTag.Class | TypeTag.Object | TypeTag.Enum | TypeTag.Function | TypeTag.Symbol;
|
|
49
|
+
export declare type EnumeratedTypeTags = ExactTypeTags | TypeTag.Never | TypeTag.Any;
|
|
50
|
+
export declare type UnionTypeTags = number;
|
|
51
|
+
interface AbstractValue {
|
|
52
|
+
type: UnionTypeTags;
|
|
53
|
+
value?: unknown;
|
|
54
|
+
}
|
|
55
|
+
export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType;
|
|
56
|
+
declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : T & {
|
|
57
|
+
value: NonNullable<T["value"]>;
|
|
58
|
+
} : never;
|
|
59
|
+
export declare type ValueTypes = WithValue<ExactTypes>;
|
|
60
|
+
export declare type ExtendedTypes = ExactTypes | NeverType | AnyType;
|
|
61
|
+
export interface NeverType extends AbstractValue {
|
|
62
|
+
type: 0;
|
|
63
|
+
value?: undefined;
|
|
64
|
+
}
|
|
65
|
+
export interface NullType extends AbstractValue {
|
|
66
|
+
type: TypeTag.Null;
|
|
67
|
+
value?: undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface FalseType extends AbstractValue {
|
|
70
|
+
type: TypeTag.False;
|
|
71
|
+
value?: undefined;
|
|
72
|
+
}
|
|
73
|
+
export interface TrueType extends AbstractValue {
|
|
74
|
+
type: TypeTag.True;
|
|
75
|
+
value?: undefined;
|
|
76
|
+
}
|
|
77
|
+
export interface NumberType extends AbstractValue {
|
|
78
|
+
type: TypeTag.Number;
|
|
79
|
+
value?: number | undefined;
|
|
80
|
+
}
|
|
81
|
+
export interface LongType extends AbstractValue {
|
|
82
|
+
type: TypeTag.Long;
|
|
83
|
+
value?: bigint | undefined;
|
|
84
|
+
}
|
|
85
|
+
export interface FloatType extends AbstractValue {
|
|
86
|
+
type: TypeTag.Float;
|
|
87
|
+
value?: number | undefined;
|
|
88
|
+
}
|
|
89
|
+
export interface DoubleType extends AbstractValue {
|
|
90
|
+
type: TypeTag.Double;
|
|
91
|
+
value?: number | undefined;
|
|
92
|
+
}
|
|
93
|
+
export interface CharType extends AbstractValue {
|
|
94
|
+
type: TypeTag.Char;
|
|
95
|
+
value?: string | undefined;
|
|
96
|
+
}
|
|
97
|
+
export interface StringType extends AbstractValue {
|
|
98
|
+
type: TypeTag.String;
|
|
99
|
+
value?: string | undefined;
|
|
100
|
+
}
|
|
101
|
+
export interface ArrayType extends AbstractValue {
|
|
102
|
+
type: TypeTag.Array;
|
|
103
|
+
value?: ExactOrUnion | undefined;
|
|
104
|
+
}
|
|
105
|
+
export interface DictionaryType extends AbstractValue {
|
|
106
|
+
type: TypeTag.Dictionary;
|
|
107
|
+
value?: {
|
|
108
|
+
key: ExactOrUnion;
|
|
109
|
+
value: ExactOrUnion;
|
|
110
|
+
} | undefined;
|
|
111
|
+
}
|
|
112
|
+
export interface ModuleType extends AbstractValue {
|
|
113
|
+
type: TypeTag.Module;
|
|
114
|
+
value?: ModuleStateNode | ModuleStateNode[] | undefined;
|
|
115
|
+
}
|
|
116
|
+
export interface FunctionType extends AbstractValue {
|
|
117
|
+
type: TypeTag.Function;
|
|
118
|
+
value?: FunctionStateNode | FunctionStateNode[] | undefined;
|
|
119
|
+
}
|
|
120
|
+
export interface ClassType extends AbstractValue {
|
|
121
|
+
type: TypeTag.Class;
|
|
122
|
+
value?: ClassStateNode | ClassStateNode[] | undefined;
|
|
123
|
+
}
|
|
124
|
+
export interface ObjectType extends AbstractValue {
|
|
125
|
+
type: TypeTag.Object;
|
|
126
|
+
value?: {
|
|
127
|
+
klass: ClassType;
|
|
128
|
+
obj?: Record<string, ExactOrUnion>;
|
|
129
|
+
} | undefined;
|
|
130
|
+
}
|
|
131
|
+
export interface EnumType extends AbstractValue {
|
|
132
|
+
type: TypeTag.Enum;
|
|
133
|
+
value?: {
|
|
134
|
+
enum: EnumStateNode;
|
|
135
|
+
value?: ExactOrUnion | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
}
|
|
138
|
+
export interface SymbolType extends AbstractValue {
|
|
139
|
+
type: TypeTag.Symbol;
|
|
140
|
+
value?: string | undefined;
|
|
141
|
+
}
|
|
142
|
+
export interface AnyType extends AbstractValue {
|
|
143
|
+
type: -1;
|
|
144
|
+
value?: undefined;
|
|
145
|
+
}
|
|
146
|
+
export declare type SingletonType = NullType | FalseType | TrueType;
|
|
147
|
+
export interface UnionType extends AbstractValue {
|
|
148
|
+
value?: undefined;
|
|
149
|
+
}
|
|
150
|
+
export declare type ExactOrUnion = UnionType | ExactTypes;
|
|
151
|
+
export declare function isExact(v: AbstractValue): v is ExactTypes;
|
|
152
|
+
export declare function isUnion(v: AbstractValue): v is UnionType;
|
|
153
|
+
export declare function isSingleton(v: AbstractValue): v is SingletonType;
|
|
154
|
+
export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
|
|
155
|
+
export declare function unionInto(to: ExactOrUnion, from: ExactOrUnion): boolean;
|
|
156
|
+
export declare function cloneType<T extends ExactOrUnion>(t: T): T;
|
|
157
|
+
export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
|
|
158
|
+
export declare function typeFromTypespec(state: ProgramStateAnalysis, ts: mctree.TypeSpecList, stack?: ProgramStateStack | undefined): ExactOrUnion;
|
|
159
|
+
export declare function typeFromLiteral(literal: mctree.Literal): ExactTypes;
|
|
160
|
+
export declare function mcExprFromType(type: ValueTypes): mctree.Expression | null;
|
|
161
|
+
export declare function castType(type: ExactOrUnion, target: UnionTypeTags): ExactOrUnion;
|
|
162
|
+
export declare const TruthyTypes: number;
|
|
163
|
+
export declare function mustBeTrue(arg: ExactOrUnion): boolean;
|
|
164
|
+
export declare function mustBeFalse(arg: ExactOrUnion): boolean;
|
|
165
|
+
export declare function display(type: ExactOrUnion): string;
|
|
166
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
+
import { EnumStringMember } from "@markw65/prettier-plugin-monkeyc/build/estree-types";
|
|
2
3
|
import { xmlUtil } from "./sdk-util";
|
|
3
4
|
export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
4
5
|
export declare type LookupRules = "COMPILER1" | "COMPILER2" | "DEFAULT";
|
|
@@ -34,7 +35,7 @@ export declare type BuildConfig = {
|
|
|
34
35
|
extensionVersion?: string;
|
|
35
36
|
useLocalOptimizer?: boolean;
|
|
36
37
|
};
|
|
37
|
-
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier
|
|
38
|
+
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier;
|
|
38
39
|
export declare type StateNodeDecls = {
|
|
39
40
|
[key: string]: StateNodeDecl[];
|
|
40
41
|
};
|
|
@@ -96,7 +97,7 @@ export interface FunctionStateNode extends BaseStateNode {
|
|
|
96
97
|
fullName: string;
|
|
97
98
|
stack?: ProgramStateStack;
|
|
98
99
|
decls?: undefined;
|
|
99
|
-
info?: FunctionInfo;
|
|
100
|
+
info?: FunctionInfo | false;
|
|
100
101
|
next_info?: FunctionInfo;
|
|
101
102
|
}
|
|
102
103
|
export interface BlockStateNode extends BaseStateNode {
|
|
@@ -120,7 +121,14 @@ export interface VariableStateNode extends BaseStateNode {
|
|
|
120
121
|
stack: ProgramStateStack;
|
|
121
122
|
used?: true;
|
|
122
123
|
}
|
|
123
|
-
export
|
|
124
|
+
export interface EnumStateNode extends BaseStateNode {
|
|
125
|
+
type: "EnumDeclaration";
|
|
126
|
+
node: mctree.EnumDeclaration;
|
|
127
|
+
name: string;
|
|
128
|
+
fullName: string;
|
|
129
|
+
stack: ProgramStateStack;
|
|
130
|
+
}
|
|
131
|
+
export declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode | EnumStateNode;
|
|
124
132
|
export declare type ProgramStateStack = StateNode[];
|
|
125
133
|
export declare type LookupDefinition = {
|
|
126
134
|
parent: StateNode | null;
|
|
@@ -180,6 +188,7 @@ export declare type ProgramState = {
|
|
|
180
188
|
};
|
|
181
189
|
message: string;
|
|
182
190
|
}[]>;
|
|
191
|
+
enumMap?: Map<EnumStringMember, EnumStateNode>;
|
|
183
192
|
};
|
|
184
193
|
declare type Finalized<T, Keys extends keyof T> = T & {
|
|
185
194
|
[key in Keys]-?: NonNullable<T[key]>;
|
package/build/src/pre.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
2
|
export declare function sizeBasedPRE(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
package/build/src/projects.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export declare type RemoteProject = string | {
|
|
|
13
13
|
sourcePath?: string;
|
|
14
14
|
jungleContent?: string[];
|
|
15
15
|
garminOptLevel?: number;
|
|
16
|
+
test?: boolean;
|
|
16
17
|
};
|
|
17
18
|
export declare const githubProjects: RemoteProject[];
|
|
18
|
-
export declare function fetchGitProjects(projects: RemoteProject[]): Promise<(string | {
|
|
19
|
+
export declare function fetchGitProjects(projects: RemoteProject[], testOnly: boolean): Promise<(string | {
|
|
19
20
|
jungle: string;
|
|
20
21
|
build: boolean | null;
|
|
21
22
|
options: BuildConfig | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
|
+
import { InterpState } from "./type-flow/interp";
|
|
3
|
+
export declare const missingNullWorkaround = true;
|
|
4
|
+
export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode): InterpState | undefined;
|
package/build/src/util.d.ts
CHANGED
|
@@ -5,9 +5,14 @@ export declare function globa(pattern: string, options?: glob.Options & {
|
|
|
5
5
|
export declare function globSome(pattern: string, predicate: (path: string) => boolean, options?: glob.Options & {
|
|
6
6
|
mark?: boolean;
|
|
7
7
|
}): Promise<boolean>;
|
|
8
|
+
export declare function forEach<T>(val: T | T[] | null | undefined, fn: (v: T) => void): void;
|
|
9
|
+
export declare function map<T, U>(val: T | T[] | null | undefined, fn: (v: T) => U): U[];
|
|
10
|
+
export declare function every<T>(val: T | T[] | null | undefined, fn: (v: T) => void): boolean | void;
|
|
11
|
+
export declare function some<T>(val: T | T[] | null | undefined, fn: (v: T) => void): boolean | void;
|
|
12
|
+
export declare function reduce<T, U>(val: T | T[] | null | undefined, fn: (p: U, v: T) => U, init: U): U;
|
|
8
13
|
export declare function last_modified(inputs: string[]): Promise<number>;
|
|
9
14
|
export declare function first_modified(inputs: string[]): Promise<number>;
|
|
10
|
-
export declare function pushUnique<T, U extends T>(arr: T[], value: U):
|
|
15
|
+
export declare function pushUnique<T, U extends T>(arr: T[], value: U): boolean;
|
|
11
16
|
export declare function sameArrays<T>(a1: T[], a2: T[], check: (a: T, b: T) => boolean): boolean;
|
|
12
17
|
export declare type LineHandler = (line: string) => void;
|
|
13
18
|
export declare function spawnByLine(command: string, args: string[], lineHandlers: LineHandler | LineHandler[], options?: {
|
package/build/util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globSome,globa,last_modified,promiseAll,pushUnique,readByLine,sameArrays,spawnByLine});
|
|
1
|
+
0 && (module.exports = {copyRecursiveAsNeeded,every,first_modified,forEach,globSome,globa,last_modified,map,promiseAll,pushUnique,readByLine,reduce,sameArrays,some,spawnByLine});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -7713,14 +7713,19 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7713
7713
|
// EXPORTS
|
|
7714
7714
|
__webpack_require__.d(__webpack_exports__, {
|
|
7715
7715
|
"copyRecursiveAsNeeded": () => (/* binding */ copyRecursiveAsNeeded),
|
|
7716
|
+
"every": () => (/* binding */ every),
|
|
7716
7717
|
"first_modified": () => (/* binding */ first_modified),
|
|
7718
|
+
"forEach": () => (/* binding */ forEach),
|
|
7717
7719
|
"globSome": () => (/* binding */ globSome),
|
|
7718
7720
|
"globa": () => (/* binding */ globa),
|
|
7719
7721
|
"last_modified": () => (/* binding */ last_modified),
|
|
7722
|
+
"map": () => (/* binding */ map),
|
|
7720
7723
|
"promiseAll": () => (/* binding */ promiseAll),
|
|
7721
7724
|
"pushUnique": () => (/* binding */ pushUnique),
|
|
7722
7725
|
"readByLine": () => (/* binding */ readByLine),
|
|
7726
|
+
"reduce": () => (/* binding */ reduce),
|
|
7723
7727
|
"sameArrays": () => (/* binding */ sameArrays),
|
|
7728
|
+
"some": () => (/* binding */ some),
|
|
7724
7729
|
"spawnByLine": () => (/* binding */ spawnByLine)
|
|
7725
7730
|
});
|
|
7726
7731
|
|
|
@@ -7770,6 +7775,56 @@ function globSome(pattern, predicate, options) {
|
|
|
7770
7775
|
});
|
|
7771
7776
|
});
|
|
7772
7777
|
}
|
|
7778
|
+
function forEach(val, fn) {
|
|
7779
|
+
if (!val)
|
|
7780
|
+
return;
|
|
7781
|
+
if (Array.isArray(val)) {
|
|
7782
|
+
val.forEach(fn);
|
|
7783
|
+
}
|
|
7784
|
+
else {
|
|
7785
|
+
fn(val);
|
|
7786
|
+
}
|
|
7787
|
+
}
|
|
7788
|
+
function map(val, fn) {
|
|
7789
|
+
if (!val)
|
|
7790
|
+
return [];
|
|
7791
|
+
if (Array.isArray(val)) {
|
|
7792
|
+
return val.map(fn);
|
|
7793
|
+
}
|
|
7794
|
+
else {
|
|
7795
|
+
return [fn(val)];
|
|
7796
|
+
}
|
|
7797
|
+
}
|
|
7798
|
+
function every(val, fn) {
|
|
7799
|
+
if (!val)
|
|
7800
|
+
return true;
|
|
7801
|
+
if (Array.isArray(val)) {
|
|
7802
|
+
return val.every(fn);
|
|
7803
|
+
}
|
|
7804
|
+
else {
|
|
7805
|
+
return fn(val);
|
|
7806
|
+
}
|
|
7807
|
+
}
|
|
7808
|
+
function some(val, fn) {
|
|
7809
|
+
if (!val)
|
|
7810
|
+
return false;
|
|
7811
|
+
if (Array.isArray(val)) {
|
|
7812
|
+
return val.some(fn);
|
|
7813
|
+
}
|
|
7814
|
+
else {
|
|
7815
|
+
return fn(val);
|
|
7816
|
+
}
|
|
7817
|
+
}
|
|
7818
|
+
function reduce(val, fn, init) {
|
|
7819
|
+
if (!val)
|
|
7820
|
+
return init;
|
|
7821
|
+
if (Array.isArray(val)) {
|
|
7822
|
+
return val.reduce(fn, init);
|
|
7823
|
+
}
|
|
7824
|
+
else {
|
|
7825
|
+
return fn(init, val);
|
|
7826
|
+
}
|
|
7827
|
+
}
|
|
7773
7828
|
async function modified_times(inputs, missing) {
|
|
7774
7829
|
return Promise.all(inputs.map(async (path) => {
|
|
7775
7830
|
try {
|
|
@@ -7789,8 +7844,9 @@ async function first_modified(inputs) {
|
|
|
7789
7844
|
}
|
|
7790
7845
|
function pushUnique(arr, value) {
|
|
7791
7846
|
if (arr.find((v) => v === value) != null)
|
|
7792
|
-
return;
|
|
7847
|
+
return false;
|
|
7793
7848
|
arr.push(value);
|
|
7849
|
+
return true;
|
|
7794
7850
|
}
|
|
7795
7851
|
function sameArrays(a1, a2, check) {
|
|
7796
7852
|
return a1.length === a2.length && a1.every((e, i) => check(e, a2[i]));
|
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.45",
|
|
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",
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
"build-debug": "webpack --mode development",
|
|
22
22
|
"build-release": "webpack --mode production",
|
|
23
23
|
"prepack": "webpack --mode production",
|
|
24
|
-
"test": "npm run test-optimized && npm run test-unopt && npm run test-remote",
|
|
24
|
+
"test": "npm run test-optimized && npm run test-unopt && npm run test-remote && npm run test-remote-tests",
|
|
25
25
|
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
26
|
+
"test-remote-tests": "node ./test/test.js --product=pick-one --run-tests --github",
|
|
26
27
|
"test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
27
28
|
"test-unopt": "node test/test.js --typeCheckLevel Strict --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
28
29
|
"test-garmin-opt": "node test/test.js --typeCheckLevel Strict --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"author": "markw65",
|
|
39
40
|
"license": "MIT",
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
42
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.41"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@types/glob": "^8.0.0",
|