@markw65/monkeyc-optimizer 1.0.45 → 1.1.1

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.
@@ -237,8 +237,6 @@ function mayThrow(node) {
237
237
  switch (node.type) {
238
238
  case "BinaryExpression":
239
239
  case "CallExpression":
240
- case "ConditionalExpression":
241
- case "LogicalExpression":
242
240
  case "NewExpression":
243
241
  case "ThrowStatement":
244
242
  case "UnaryExpression":
@@ -383,6 +381,28 @@ function makeScopedName(dotted, l) {
383
381
  throw new Error("Failed to make a ScopedName");
384
382
  return result;
385
383
  }
384
+ function getLiteralNode(node) {
385
+ if (node == null)
386
+ return null;
387
+ if (node.type == "Literal")
388
+ return node;
389
+ if (node.type == "BinaryExpression" && node.operator == "as") {
390
+ return getLiteralNode(node.left) && node;
391
+ }
392
+ if (node.type == "UnaryExpression") {
393
+ if (node.argument.type != "Literal")
394
+ return null;
395
+ switch (node.operator) {
396
+ case "-": {
397
+ const [arg, type] = getNodeValue(node.argument);
398
+ if (type === "Number" || type === "Long") {
399
+ return { ...arg, value: -arg.value, raw: `-${arg.raw}` };
400
+ }
401
+ }
402
+ }
403
+ }
404
+ return null;
405
+ }
386
406
 
387
407
  ;// CONCATENATED MODULE: ./src/xml-util.ts
388
408
 
@@ -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, VariableStateNode } from "./optimizer-types";
4
+ import { ClassStateNode, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, 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,6 +22,8 @@ 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 | false;
26
- export declare function markInvokeClassMethod(func: FunctionStateNode): void;
25
+ export declare function getApiFunctionInfo(state: ProgramState, func: FunctionStateNode): FunctionInfo | false;
26
+ export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
27
27
  export declare function isLocal(v: VariableStateNode): boolean;
28
+ export declare function diagnostic(state: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
29
+ export declare function getSuperClasses(klass: ClassStateNode): Set<ClassStateNode> | null;
@@ -55,4 +55,5 @@ export declare function makeIdentifier(name: string, loc?: mctree.SourceLocation
55
55
  };
56
56
  export declare function makeMemberExpression(object: mctree.ScopedName, property: mctree.Identifier): mctree.DottedName;
57
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;
58
59
  export {};
@@ -13,7 +13,7 @@ export declare type Block<T extends EventConstraint<T>> = {
13
13
  exsucc?: Block<T>;
14
14
  events?: T[];
15
15
  };
16
- export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean) => T | null): Block<T>;
16
+ export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1) => T | null): Block<T>;
17
17
  export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
18
18
  export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
19
19
  export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
@@ -31,7 +31,7 @@ export interface DataFlowBlock extends Block<Event> {
31
31
  }
32
32
  export declare function declFullName(decl: EventDecl): string | undefined;
33
33
  export declare function declName(decl: EventDecl): string | undefined;
34
- export declare function unhandledExpression(node: never): void;
34
+ export declare function unhandledType(node: never): never;
35
35
  export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
36
36
  identifiers: Set<string>;
37
37
  graph: Block<RefEvent | DefEvent | ModEvent | ExnEvent>;
@@ -1,11 +1,10 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { FunctionStateNode, ProgramState, ProgramStateAnalysis } from "./optimizer-types";
2
+ import { FunctionStateNode, 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: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
9
8
  export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
10
9
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
11
10
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -4,10 +4,9 @@ import { BuildConfig, FilesToOptimizeMap, LookupDefinition, ProgramStateAnalysis
4
4
  import { xmlUtil } from "./sdk-util";
5
5
  export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
6
6
  export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
7
- export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<ProgramStateAnalysis>;
7
+ export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig): Promise<ProgramStateAnalysis>;
8
8
  export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
9
9
  export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
10
- export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
11
10
  export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<Record<string, {
12
11
  type: import("./optimizer-types").DiagnosticType;
13
12
  loc: {
@@ -1,6 +1,7 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { EnumStringMember } from "@markw65/prettier-plugin-monkeyc/build/estree-types";
3
3
  import { xmlUtil } from "./sdk-util";
4
+ import { ExactOrUnion } from "./type-flow/types";
4
5
  export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
5
6
  export declare type LookupRules = "COMPILER1" | "COMPILER2" | "DEFAULT";
6
7
  export declare type EnforceStatic = "YES" | "NO";
@@ -34,6 +35,9 @@ export declare type BuildConfig = {
34
35
  prettier?: Record<string, unknown>;
35
36
  extensionVersion?: string;
36
37
  useLocalOptimizer?: boolean;
38
+ propagateTypes?: boolean;
39
+ trustDeclaredTypes?: boolean;
40
+ checkTypes?: DiagnosticType | "OFF";
37
41
  };
38
42
  export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier;
39
43
  export declare type StateNodeDecls = {
@@ -81,6 +85,7 @@ export interface ClassStateNode extends BaseStateNode {
81
85
  fullName: string;
82
86
  superClass?: ClassStateNode[] | true;
83
87
  hasInvoke?: boolean;
88
+ superClasses?: Set<ClassStateNode>;
84
89
  }
85
90
  export declare type FunctionInfo = {
86
91
  modifiedDecls: Set<VariableStateNode>;
@@ -112,6 +117,9 @@ export interface TypedefStateNode extends BaseStateNode {
112
117
  node: mctree.TypedefDeclaration;
113
118
  name: string;
114
119
  fullName: string;
120
+ isExpanding?: true;
121
+ isRecursive?: true;
122
+ resolvedType?: ExactOrUnion;
115
123
  }
116
124
  export interface VariableStateNode extends BaseStateNode {
117
125
  type: "VariableDeclarator";
@@ -138,6 +146,7 @@ export declare type LookupResult = [string, LookupDefinition[]] | [null, null] |
138
146
  export declare type ProgramState = {
139
147
  allFunctions?: Record<string, FunctionStateNode[]>;
140
148
  allClasses?: ClassStateNode[];
149
+ invokeInfo?: FunctionInfo;
141
150
  fnMap?: FilesToOptimizeMap;
142
151
  rezAst?: mctree.Program;
143
152
  manifestXML?: xmlUtil.Document;
@@ -190,11 +199,11 @@ export declare type ProgramState = {
190
199
  }[]>;
191
200
  enumMap?: Map<EnumStringMember, EnumStateNode>;
192
201
  };
193
- declare type Finalized<T, Keys extends keyof T> = T & {
202
+ export declare type Finalized<T, Keys extends keyof T> = T & {
194
203
  [key in Keys]-?: NonNullable<T[key]>;
195
204
  };
196
205
  export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
197
- export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
206
+ export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "invokeInfo">;
198
207
  export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
199
208
  export declare type ExcludeAnnotationsMap = {
200
209
  [key: string]: boolean;
@@ -0,0 +1,2 @@
1
+ import { ExactOrUnion } from "./types";
2
+ export declare function couldBe(a: ExactOrUnion, b: ExactOrUnion): boolean;
@@ -1,4 +1,4 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { ExactOrUnion } from "./mc-types";
2
+ import { ExactOrUnion } from "./types";
3
3
  export declare function evaluateBinaryTypes(op: mctree.BinaryOperator | "instanceof", left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
4
4
  export declare function evaluateLogicalTypes(op: mctree.LogicalOperator, left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
@@ -0,0 +1,4 @@
1
+ import { ProgramStateAnalysis } from "../optimizer-types";
2
+ import { ExactOrUnion } from "./types";
3
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
4
+ export declare function evaluateCall(state: ProgramStateAnalysis, node: mctree.CallExpression, callee: ExactOrUnion, _args: ExactOrUnion[]): ExactOrUnion;
@@ -1,6 +1,6 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { ExactOrUnion } from "./type-flow/types";
3
- import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
2
+ import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
3
+ import { ExactOrUnion } from "./types";
4
4
  export declare type TypeMap = Map<mctree.Node, ExactOrUnion>;
5
5
  export declare type InterpStackElem = {
6
6
  value: ExactOrUnion;
@@ -12,8 +12,8 @@ export declare type InterpState = {
12
12
  stack: InterpStackElem[];
13
13
  typeMap?: TypeMap;
14
14
  func?: FunctionStateNode;
15
- pre?: (node: mctree.Node) => mctree.Node | null | void;
16
- post?: (node: mctree.Node) => mctree.Node | null | void;
15
+ pre?: (node: mctree.Node) => mctree.Node | false | null | void;
16
+ post?: (node: mctree.Node) => mctree.Node | false | null | void;
17
17
  };
18
18
  export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
19
19
  export declare function evaluateExpr(state: ProgramStateAnalysis, expr: mctree.Expression, typeMap?: TypeMap): InterpStackElem;
@@ -0,0 +1,4 @@
1
+ import { ExactOrUnion } from "./types";
2
+ export declare function expandTypedef(t: ExactOrUnion): ExactOrUnion;
3
+ export declare function intersection(a: ExactOrUnion, b: ExactOrUnion): ExactOrUnion;
4
+ export declare function restrictByEquality(a: ExactOrUnion, b: ExactOrUnion): ExactOrUnion;
@@ -0,0 +1,6 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
3
+ import { InterpState } from "./interp";
4
+ export declare function optimizeFunction(state: ProgramStateAnalysis, func: FunctionStateNode): void;
5
+ export declare function beforeEvaluate(istate: InterpState, node: mctree.Node): mctree.Node | null | false;
6
+ export declare function afterEvaluate(istate: InterpState, node: mctree.Node): mctree.Node | null | false;
@@ -0,0 +1,2 @@
1
+ import { ExactOrUnion } from "./types";
2
+ export declare function subtypeOf(a: ExactOrUnion, b: ExactOrUnion): boolean;
@@ -1,5 +1,5 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl } from "./optimizer-types";
2
+ import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl, TypedefStateNode } from "../optimizer-types";
3
3
  /**
4
4
  * TypeBit gives the position of the 1 bit in TypeTag
5
5
  */
@@ -20,7 +20,8 @@ export declare enum TypeBit {
20
20
  Class = 13,
21
21
  Object = 14,
22
22
  Enum = 15,
23
- Symbol = 16
23
+ Symbol = 16,
24
+ Typedef = 17
24
25
  }
25
26
  export declare enum TypeTag {
26
27
  Never = 0,
@@ -43,16 +44,21 @@ export declare enum TypeTag {
43
44
  Object = 16384,
44
45
  Enum = 32768,
45
46
  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;
47
+ Typedef = 131072,
48
+ Any = 262143
49
+ }
50
+ export declare const SingleTonTypeTagsConst: number;
51
+ export declare const UnionDataTypeTagsConst: number;
52
+ export declare const ValueTypeTagsConst: number;
53
+ export declare const ObjectLikeTagsConst: number;
54
+ 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.Class | TypeTag.Object | TypeTag.Enum | TypeTag.Symbol | TypeTag.Typedef;
49
55
  export declare type EnumeratedTypeTags = ExactTypeTags | TypeTag.Never | TypeTag.Any;
50
56
  export declare type UnionTypeTags = number;
51
57
  interface AbstractValue {
52
58
  type: UnionTypeTags;
53
59
  value?: unknown;
54
60
  }
55
- export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType;
61
+ export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType | TypedefType;
56
62
  declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : T & {
57
63
  value: NonNullable<T["value"]>;
58
64
  } : never;
@@ -121,6 +127,10 @@ export interface ClassType extends AbstractValue {
121
127
  type: TypeTag.Class;
122
128
  value?: ClassStateNode | ClassStateNode[] | undefined;
123
129
  }
130
+ export interface TypedefType extends AbstractValue {
131
+ type: TypeTag.Typedef;
132
+ value?: TypedefStateNode | TypedefStateNode[] | undefined;
133
+ }
124
134
  export interface ObjectType extends AbstractValue {
125
135
  type: TypeTag.Object;
126
136
  value?: {
@@ -144,17 +154,38 @@ export interface AnyType extends AbstractValue {
144
154
  value?: undefined;
145
155
  }
146
156
  export declare type SingletonType = NullType | FalseType | TrueType;
157
+ export declare type UnionData = {
158
+ mask: TypeTag;
159
+ [TypeTag.Array]?: NonNullable<ArrayType["value"]>;
160
+ [TypeTag.Dictionary]?: NonNullable<DictionaryType["value"]>;
161
+ [TypeTag.Module]?: NonNullable<ModuleType["value"]>;
162
+ [TypeTag.Function]?: NonNullable<FunctionType["value"]>;
163
+ [TypeTag.Class]?: NonNullable<ClassType["value"]>;
164
+ [TypeTag.Object]?: NonNullable<ObjectType["value"]>;
165
+ [TypeTag.Enum]?: NonNullable<EnumType["value"]>;
166
+ };
167
+ export declare type UnionDataKey = Exclude<keyof UnionData, "mask">;
147
168
  export interface UnionType extends AbstractValue {
148
- value?: undefined;
169
+ value?: UnionData | undefined;
149
170
  }
150
171
  export declare type ExactOrUnion = UnionType | ExactTypes;
172
+ export declare type SingleValue = NonNullable<ValueTypes["value"]>;
173
+ declare type TagValue<TAG> = Extract<ValueTypes, {
174
+ type: TAG;
175
+ }>["value"];
176
+ export declare type ArrayValueType = TagValue<TypeTag.Array>;
177
+ export declare type DictionaryValueType = TagValue<TypeTag.Dictionary>;
178
+ export declare type ObjectValueType = TagValue<TypeTag.Object>;
179
+ export declare type EnumValueType = TagValue<TypeTag.Enum>;
180
+ export declare type TypedefValueType = TagValue<TypeTag.Typedef>;
181
+ export declare type StateDeclValueType = TagValue<TypeTag.Module> | TagValue<TypeTag.Function> | TagValue<TypeTag.Class>;
151
182
  export declare function isExact(v: AbstractValue): v is ExactTypes;
152
183
  export declare function isUnion(v: AbstractValue): v is UnionType;
153
184
  export declare function isSingleton(v: AbstractValue): v is SingletonType;
154
185
  export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
155
- export declare function unionInto(to: ExactOrUnion, from: ExactOrUnion): boolean;
156
186
  export declare function cloneType<T extends ExactOrUnion>(t: T): T;
157
187
  export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
188
+ export declare function typeFromTypeStateNodes(state: ProgramStateAnalysis, sns: StateNodeDecl[], classVsObj?: boolean): ExactOrUnion;
158
189
  export declare function typeFromTypespec(state: ProgramStateAnalysis, ts: mctree.TypeSpecList, stack?: ProgramStateStack | undefined): ExactOrUnion;
159
190
  export declare function typeFromLiteral(literal: mctree.Literal): ExactTypes;
160
191
  export declare function mcExprFromType(type: ValueTypes): mctree.Expression | null;
@@ -163,4 +194,8 @@ export declare const TruthyTypes: number;
163
194
  export declare function mustBeTrue(arg: ExactOrUnion): boolean;
164
195
  export declare function mustBeFalse(arg: ExactOrUnion): boolean;
165
196
  export declare function display(type: ExactOrUnion): string;
197
+ export declare function hasUnionData(tag: TypeTag): boolean;
198
+ export declare function getObjectValue(t: ExactOrUnion): ObjectType["value"] | null;
199
+ export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn: (tag: UnionDataKey, value: SingleValue | null | undefined) => boolean | void): void;
200
+ export declare function getUnionComponent(v: ExactOrUnion, tag: TypeTag): SingleValue | null;
166
201
  export {};
@@ -0,0 +1,3 @@
1
+ import { ExactOrUnion, TypeTag } from "./types";
2
+ export declare function unionInto(to: ExactOrUnion, from: ExactOrUnion): boolean;
3
+ export declare function clearValuesUnder(v: ExactOrUnion, tag: TypeTag, clearTag?: boolean): void;
@@ -1,4 +1,3 @@
1
1
  import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
2
2
  import { InterpState } from "./type-flow/interp";
3
- export declare const missingNullWorkaround = true;
4
3
  export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode): InterpState | undefined;
@@ -1,4 +1,4 @@
1
1
  import type { WorkerTask, WorkerTaskResult } from "./worker-task";
2
- export declare function startPool(): void;
2
+ export declare function startPool(parallelism?: number): void;
3
3
  export declare function stopPool(): void;
4
4
  export declare function runTaskInPool<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
@@ -1,29 +1,60 @@
1
- import { mctree } from "@markw65/prettier-plugin-monkeyc";
1
+ import { BuildConfig } from "./optimizer";
2
2
  interface BaseNode {
3
3
  type: string;
4
4
  data: unknown;
5
5
  }
6
- interface ParserData extends BaseNode {
6
+ interface BuildOptimizedProject extends BaseNode {
7
+ type: "buildOptimizedProject";
7
8
  data: {
8
- source: string;
9
- options?: Record<string, unknown>;
9
+ product: string | null;
10
+ options: BuildConfig;
10
11
  };
11
12
  }
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";
13
+ interface GenerateOptimizedProject extends BaseNode {
14
+ type: "generateOptimizedProject";
15
+ data: {
16
+ options: BuildConfig;
17
+ };
20
18
  }
21
- export declare type WorkerTask = JungleParserTask | MonkeyCParserTask | XmlParserTask;
19
+ export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject;
22
20
  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;
21
+ readonly buildOptimizedProject: (data: BuildOptimizedProject["data"]) => Promise<{
22
+ exe: string;
23
+ args: string[];
24
+ program: string;
25
+ product: string | null;
26
+ hasTests: boolean;
27
+ diagnostics: Record<string, {
28
+ type: import("./optimizer-types").DiagnosticType;
29
+ loc: {
30
+ start: import("@markw65/prettier-plugin-monkeyc/build/estree-types").Position;
31
+ end: import("@markw65/prettier-plugin-monkeyc/build/estree-types").Position;
32
+ };
33
+ message: string;
34
+ }[]> | undefined;
35
+ }>;
36
+ readonly generateOptimizedProject: (data: GenerateOptimizedProject["data"]) => Promise<{
37
+ jungleFiles: string | undefined;
38
+ xml: import("./xml-util").Document;
39
+ program: string;
40
+ hasTests: boolean;
41
+ diagnostics?: undefined;
42
+ } | {
43
+ jungleFiles: string;
44
+ xml: import("./xml-util").Document;
45
+ program: string;
46
+ hasTests: boolean;
47
+ diagnostics: Record<string, {
48
+ type: import("./optimizer-types").DiagnosticType;
49
+ loc: {
50
+ start: import("@markw65/prettier-plugin-monkeyc/build/estree-types").Position;
51
+ end: import("@markw65/prettier-plugin-monkeyc/build/estree-types").Position;
52
+ };
53
+ message: string;
54
+ }[]>;
55
+ }>;
26
56
  };
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>;
57
+ declare type RemovePromise<T> = T extends Promise<infer U> ? U : T;
58
+ export declare type WorkerTaskResult<T> = T extends WorkerTask ? RemovePromise<ReturnType<typeof workerTaskHandlers[T["type"]]>> : never;
59
+ export declare function performTask<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
29
60
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.45",
4
+ "version": "1.1.1",
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,7 +21,8 @@
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 && npm run test-remote-tests",
24
+ "test": "npm run test-mocha && npm run test-optimized && npm run test-unopt && npm run test-remote && npm run test-remote-tests",
25
+ "test-mocha": "npx mocha --timeout 999999 build/mocha.cjs",
25
26
  "test-remote": "node ./test/test.js --product=pick-one --github",
26
27
  "test-remote-tests": "node ./test/test.js --product=pick-one --run-tests --github",
27
28
  "test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
@@ -34,7 +35,7 @@
34
35
  "build/util.cjs",
35
36
  "build/sdk-util.cjs",
36
37
  "build/api.cjs",
37
- "build/src/*.d.ts"
38
+ "build/src/**/*.d.ts"
38
39
  ],
39
40
  "author": "markw65",
40
41
  "license": "MIT",
@@ -42,14 +43,18 @@
42
43
  "@markw65/prettier-plugin-monkeyc": "^1.0.41"
43
44
  },
44
45
  "devDependencies": {
46
+ "@types/chai": "^4.3.4",
45
47
  "@types/glob": "^8.0.0",
48
+ "@types/mocha": "^10.0.1",
46
49
  "@types/prettier": "^2.6.1",
47
50
  "@types/priorityqueuejs": "^1.0.1",
48
51
  "@typescript-eslint/eslint-plugin": "^5.28.0",
49
52
  "@typescript-eslint/parser": "^5.28.0",
53
+ "chai": "^4.3.7",
50
54
  "eslint": "^8.12.0",
51
55
  "extract-zip": "^2.0.1",
52
56
  "fast-glob": "^3.2.12",
57
+ "mocha": "^10.2.0",
53
58
  "peggy": "^2.0.1",
54
59
  "prettier": "^2.6.2",
55
60
  "prettier-plugin-pegjs": "https://github.com/markw65/prettier-plugin-pegjs/releases/download/v0.5.2/prettier-plugin-pegjs-0.5.2.tgz",
@@ -1,3 +0,0 @@
1
- import { ExactOrUnion } from "./mc-types";
2
- import { ProgramStateAnalysis } from "./optimizer-types";
3
- export declare function evaluateCall(state: ProgramStateAnalysis, callee: ExactOrUnion, _args: ExactOrUnion[]): ExactOrUnion;