@markw65/monkeyc-optimizer 1.0.43 → 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.
@@ -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;
@@ -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;
@@ -17,13 +18,41 @@ interface LongLiteral extends mctree.Literal {
17
18
  interface StringLiteral extends mctree.Literal {
18
19
  value: string;
19
20
  }
21
+ interface CharLiteral extends mctree.Literal {
22
+ value: string;
23
+ }
20
24
  interface BooleanLiteral extends mctree.Literal {
21
25
  value: boolean;
22
26
  }
23
27
  interface NullLiteral extends mctree.Literal {
24
28
  value: null;
25
29
  }
26
- declare type LiteralValues = [NumberLiteral, "Number" | "Float" | "Double"] | [LongLiteral, "Long"] | [StringLiteral, "String"] | [BooleanLiteral, "Boolean"] | [NullLiteral, "Null"];
30
+ declare type LiteralValues = [NumberLiteral, "Number" | "Float" | "Double"] | [LongLiteral, "Long"] | [StringLiteral, "String"] | [CharLiteral, "Char"] | [BooleanLiteral, "Boolean"] | [NullLiteral, "Null"];
27
31
  export declare function getNodeValue(node: mctree.Literal): LiteralValues;
28
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;
29
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;
@@ -1,11 +1,11 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { FunctionStateNode, ProgramStateAnalysis, ProgramStateLive } from "./optimizer-types";
2
+ import { FunctionStateNode, ProgramState, ProgramStateAnalysis } from "./optimizer-types";
3
3
  export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
4
4
  export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
5
5
  declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
6
6
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
7
7
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
8
- export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
8
+ export declare function diagnostic(state: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
9
9
  export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
10
10
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
11
11
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -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,3 @@
1
+ import { ExactOrUnion } from "./mc-types";
2
+ import { ProgramStateAnalysis } from "./optimizer-types";
3
+ export declare function evaluateCall(state: ProgramStateAnalysis, callee: ExactOrUnion, _args: 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;
@@ -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 & {
@@ -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 | mctree.EnumDeclaration;
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 declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
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]>;
@@ -1,2 +1,2 @@
1
- import { ProgramStateAnalysis, FunctionStateNode } from "./optimizer-types";
1
+ import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
2
2
  export declare function sizeBasedPRE(state: ProgramStateAnalysis, func: FunctionStateNode): void;
@@ -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;
@@ -1,13 +1,12 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { JungleResourceMap } from "./jungles";
3
+ import { ProgramState } from "./optimizer-types";
3
4
  import { xmlUtil } from "./sdk-util";
4
5
  declare type Visit = (e: xmlUtil.Element, module: string | null, parent: xmlUtil.Element | null) => void;
5
6
  declare type Visitor = {
6
7
  visit?: Visit;
7
8
  error?: (node: xmlUtil.Element, parent: string | null) => void;
8
- pre?: (node: xmlUtil.Content) => boolean | null | undefined | void;
9
- post?: (node: xmlUtil.Content) => void;
10
- };
9
+ } & xmlUtil.Visitor;
11
10
  export declare function visit_resources(elements: xmlUtil.Content[], parent: xmlUtil.Element | null, v: Visitor | Visit): void;
12
- export declare function add_resources_to_ast(ast: mctree.Program, resources: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): void;
11
+ export declare function add_resources_to_ast(state: ProgramState | undefined, ast: mctree.Program, resources: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): void;
13
12
  export {};
@@ -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;
@@ -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): void;
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?: {
@@ -0,0 +1,4 @@
1
+ import type { WorkerTask, WorkerTaskResult } from "./worker-task";
2
+ export declare function startPool(): void;
3
+ export declare function stopPool(): void;
4
+ export declare function runTaskInPool<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
@@ -0,0 +1,29 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ interface BaseNode {
3
+ type: string;
4
+ data: unknown;
5
+ }
6
+ interface ParserData extends BaseNode {
7
+ data: {
8
+ source: string;
9
+ options?: Record<string, unknown>;
10
+ };
11
+ }
12
+ interface JungleParserTask extends ParserData {
13
+ type: "parseJungle";
14
+ }
15
+ interface MonkeyCParserTask extends ParserData {
16
+ type: "parseMonkeyC";
17
+ }
18
+ interface XmlParserTask extends ParserData {
19
+ type: "parseXml";
20
+ }
21
+ export declare type WorkerTask = JungleParserTask | MonkeyCParserTask | XmlParserTask;
22
+ export declare const workerTaskHandlers: {
23
+ readonly parseJungle: (data: JungleParserTask["data"]) => Assignment[];
24
+ readonly parseMonkeyC: (data: MonkeyCParserTask["data"]) => mctree.Program;
25
+ readonly parseXml: (data: XmlParserTask["data"]) => ParserResult;
26
+ };
27
+ export declare type WorkerTaskResult<T> = T extends WorkerTask ? ReturnType<typeof workerTaskHandlers[T["type"]]> : never;
28
+ export declare function performTask<T extends WorkerTask>(task: T): WorkerTaskResult<T>;
29
+ export {};
@@ -1,4 +1,3 @@
1
- import { xmlUtil } from "./sdk-util.js";
2
1
  export declare class PeggyError extends Error {
3
2
  location: SourceLocation | null | undefined;
4
3
  constructor(message: string, location: SourceLocation | null | undefined);
@@ -134,9 +133,17 @@ export declare class Document {
134
133
  misc: Array<Misc>;
135
134
  source?: string | undefined;
136
135
  data?: Record<string, unknown>;
136
+ private entities;
137
+ private pentities;
137
138
  constructor(prolog: Prolog | null, body: Nodes | Error, misc: Array<Misc>, source?: string | undefined);
138
- }
139
- export declare function elementKids(e: Element): xmlUtil.Element[];
139
+ /**
140
+ * If all the children are chardata, charref or entityref,
141
+ * return the resulting string. Otherwise null.
142
+ */
143
+ textContent(element: Element): string | null;
144
+ processRefs(text: string): string;
145
+ }
146
+ export declare function elementKids(e: Element): Element[];
140
147
  declare type ElementMatcher = string | ((c: Element) => boolean);
141
148
  export declare class Nodes {
142
149
  elements: Array<Element>;
@@ -144,11 +151,11 @@ export declare class Nodes {
144
151
  length(): number;
145
152
  deleteChildren(arg: ElementMatcher): void;
146
153
  addChildren(elements: Element[]): void;
147
- filter(arg: ElementMatcher): xmlUtil.Nodes;
148
- skip(name: string): xmlUtil.Nodes;
149
- children(name?: string): xmlUtil.Nodes;
154
+ filter(arg: ElementMatcher): Nodes;
155
+ skip(name: string): Nodes;
156
+ children(name?: string): Nodes;
150
157
  text(): string[];
151
- attrs(): Record<string, xmlUtil.Attribute | undefined>[];
158
+ attrs(): Record<string, Attribute | undefined>[];
152
159
  }
153
160
  export declare function attrString(value: string | AttrStr): AttrStr | {
154
161
  readonly type: "attrstr";
@@ -157,4 +164,9 @@ export declare function attrString(value: string | AttrStr): AttrStr | {
157
164
  export declare function makeAttribute(name: string | AttrStr, value: string | AttrStr): Attribute;
158
165
  export declare function parseXml(content: string, fileName?: string | null): Document;
159
166
  export declare function writeXml(doc: Document): string;
167
+ export declare type Visitor = {
168
+ pre?: (node: Content) => boolean | null | undefined | void;
169
+ post?: (node: Content) => void;
170
+ };
171
+ export declare function visit_xml(contents: Content[], visitor: Visitor): void;
160
172
  export {};
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]));