@markw65/monkeyc-optimizer 1.1.68 → 1.1.70

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.
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_MBTLUWXR_exports = {};
20
- __export(chunk_MBTLUWXR_exports, {
19
+ var chunk_JDC43A3I_exports = {};
20
+ __export(chunk_JDC43A3I_exports, {
21
21
  adjustLoc: () => adjustLoc,
22
22
  cloneDeep: () => cloneDeep,
23
23
  getLiteralNode: () => getLiteralNode,
@@ -36,7 +36,7 @@ __export(chunk_MBTLUWXR_exports, {
36
36
  withLocDeep: () => withLocDeep,
37
37
  wrap: () => wrap
38
38
  });
39
- module.exports = __toCommonJS(chunk_MBTLUWXR_exports);
39
+ module.exports = __toCommonJS(chunk_JDC43A3I_exports);
40
40
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
41
41
  var import_prettier_plugin_monkeyc = require("@markw65/prettier-plugin-monkeyc");
42
42
  function isMCTreeNode(node) {
@@ -239,7 +239,7 @@ function makeMemberExpression(object, property) {
239
239
  object.loc && locRange(object.loc, property.loc)
240
240
  );
241
241
  }
242
- function makeScopedName(dotted, l) {
242
+ function makeScopedName(dotted, l, base) {
243
243
  const loc = l && adjustLoc(l, 0, l.start.offset - l.end.offset);
244
244
  const result = dotted.split(/\s*\.\s*/).reduce(
245
245
  ({ cur, offset }, next) => {
@@ -255,7 +255,7 @@ function makeScopedName(dotted, l) {
255
255
  offset += next.length + 1;
256
256
  return { cur, offset };
257
257
  },
258
- { cur: null, offset: 0 }
258
+ { cur: base, offset: 0 }
259
259
  ).cur;
260
260
  if (!result)
261
261
  throw new Error("Failed to make a ScopedName");
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_OASVKTK5_exports = {};
30
- __export(chunk_OASVKTK5_exports, {
29
+ var chunk_NHZRKHZO_exports = {};
30
+ __export(chunk_NHZRKHZO_exports, {
31
31
  AwaitedError: () => AwaitedError,
32
32
  GenericQueue: () => GenericQueue,
33
33
  bumpLogging: () => bumpLogging,
@@ -55,7 +55,7 @@ __export(chunk_OASVKTK5_exports, {
55
55
  spawnByLine: () => spawnByLine,
56
56
  wouldLog: () => wouldLog
57
57
  });
58
- module.exports = __toCommonJS(chunk_OASVKTK5_exports);
58
+ module.exports = __toCommonJS(chunk_NHZRKHZO_exports);
59
59
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
60
60
  var child_process = __toESM(require("child_process"));
61
61
  var fsc = __toESM(require("fs"));
@@ -5474,6 +5474,7 @@ function log(...messages) {
5474
5474
  }
5475
5475
  }
5476
5476
  });
5477
+ return logPromise;
5477
5478
  }
5478
5479
  function getLoggerSettings() {
5479
5480
  const ls = /* @__PURE__ */ new Map();
@@ -18,30 +18,30 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_NGCEDNHJ.StateNodeAttributes,
22
- buildConfigDescription: () => import_chunk_NGCEDNHJ.buildConfigDescription,
23
- buildOptimizedProject: () => import_chunk_NGCEDNHJ.buildOptimizedProject,
24
- copyRecursiveAsNeeded: () => import_chunk_OASVKTK5.copyRecursiveAsNeeded,
25
- defaultConfig: () => import_chunk_NGCEDNHJ.defaultConfig,
26
- display: () => import_chunk_NGCEDNHJ.display,
27
- generateOneConfig: () => import_chunk_NGCEDNHJ.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_NGCEDNHJ.generateOptimizedProject,
29
- getConfig: () => import_chunk_NGCEDNHJ.getConfig,
30
- getFnMapAnalysis: () => import_chunk_NGCEDNHJ.getFnMapAnalysis,
31
- getProjectAnalysis: () => import_chunk_NGCEDNHJ.getProjectAnalysis,
32
- get_jungle: () => import_chunk_NGCEDNHJ.get_jungle,
33
- isErrorWithLocation: () => import_chunk_NGCEDNHJ.isErrorWithLocation,
34
- launchSimulator: () => import_chunk_NGCEDNHJ.launchSimulator,
35
- manifestProducts: () => import_chunk_NGCEDNHJ.manifestProducts,
36
- mctree: () => import_chunk_NGCEDNHJ.mctree,
37
- simulateProgram: () => import_chunk_NGCEDNHJ.simulateProgram
21
+ StateNodeAttributes: () => import_chunk_2PJMJVYN.StateNodeAttributes,
22
+ buildConfigDescription: () => import_chunk_2PJMJVYN.buildConfigDescription,
23
+ buildOptimizedProject: () => import_chunk_2PJMJVYN.buildOptimizedProject,
24
+ copyRecursiveAsNeeded: () => import_chunk_NHZRKHZO.copyRecursiveAsNeeded,
25
+ defaultConfig: () => import_chunk_2PJMJVYN.defaultConfig,
26
+ display: () => import_chunk_2PJMJVYN.display,
27
+ generateOneConfig: () => import_chunk_2PJMJVYN.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_2PJMJVYN.generateOptimizedProject,
29
+ getConfig: () => import_chunk_2PJMJVYN.getConfig,
30
+ getFnMapAnalysis: () => import_chunk_2PJMJVYN.getFnMapAnalysis,
31
+ getProjectAnalysis: () => import_chunk_2PJMJVYN.getProjectAnalysis,
32
+ get_jungle: () => import_chunk_2PJMJVYN.get_jungle,
33
+ isErrorWithLocation: () => import_chunk_2PJMJVYN.isErrorWithLocation,
34
+ launchSimulator: () => import_chunk_2PJMJVYN.launchSimulator,
35
+ manifestProducts: () => import_chunk_2PJMJVYN.manifestProducts,
36
+ mctree: () => import_chunk_2PJMJVYN.mctree,
37
+ simulateProgram: () => import_chunk_2PJMJVYN.simulateProgram
38
38
  });
39
39
  module.exports = __toCommonJS(optimizer_exports);
40
- var import_chunk_NGCEDNHJ = require("./chunk-NGCEDNHJ.cjs");
41
- var import_chunk_OASVKTK5 = require("./chunk-OASVKTK5.cjs");
42
- var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
40
+ var import_chunk_2PJMJVYN = require("./chunk-2PJMJVYN.cjs");
41
+ var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
42
+ var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
43
43
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
44
- (0, import_chunk_NGCEDNHJ.init_optimizer)();
44
+ (0, import_chunk_2PJMJVYN.init_optimizer)();
45
45
  // Annotate the CommonJS export names for ESM import in node:
46
46
  0 && (module.exports = {
47
47
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_NGCEDNHJ.SectionKinds,
22
- appSupport: () => import_chunk_NGCEDNHJ.appSupport,
23
- connectiq: () => import_chunk_NGCEDNHJ.connectiq,
24
- getDeviceInfo: () => import_chunk_NGCEDNHJ.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_NGCEDNHJ.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_NGCEDNHJ.getLanguages,
27
- getSdkPath: () => import_chunk_NGCEDNHJ.getSdkPath,
28
- isWin: () => import_chunk_NGCEDNHJ.isWin,
29
- optimizeProgram: () => import_chunk_NGCEDNHJ.optimizeProgram,
30
- readPrg: () => import_chunk_NGCEDNHJ.readPrg,
31
- readPrgWithOffsets: () => import_chunk_NGCEDNHJ.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_NGCEDNHJ.xml_util_exports
21
+ SectionKinds: () => import_chunk_2PJMJVYN.SectionKinds,
22
+ appSupport: () => import_chunk_2PJMJVYN.appSupport,
23
+ connectiq: () => import_chunk_2PJMJVYN.connectiq,
24
+ getDeviceInfo: () => import_chunk_2PJMJVYN.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_2PJMJVYN.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_2PJMJVYN.getLanguages,
27
+ getSdkPath: () => import_chunk_2PJMJVYN.getSdkPath,
28
+ isWin: () => import_chunk_2PJMJVYN.isWin,
29
+ optimizeProgram: () => import_chunk_2PJMJVYN.optimizeProgram,
30
+ readPrg: () => import_chunk_2PJMJVYN.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_2PJMJVYN.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_2PJMJVYN.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_NGCEDNHJ = require("./chunk-NGCEDNHJ.cjs");
36
- var import_chunk_OASVKTK5 = require("./chunk-OASVKTK5.cjs");
37
- var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
35
+ var import_chunk_2PJMJVYN = require("./chunk-2PJMJVYN.cjs");
36
+ var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
37
+ var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_NGCEDNHJ.init_sdk_util)();
39
+ (0, import_chunk_2PJMJVYN.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -5,10 +5,13 @@ import { ClassStateNode, Diagnostic, DiagnosticType, EnumStateNode, FunctionInfo
5
5
  import { visit_resources } from "./resources";
6
6
  import { xmlUtil } from "./sdk-util";
7
7
  import { TypeMap } from "./type-flow/interp";
8
+ import { RootStateNode } from "./control-flow";
8
9
  export { visitReferences, visitorNode } from "./visitor";
9
10
  export { hasProperty, traverseAst, visit_resources };
10
11
  export declare function parseSdkVersion(version: string | undefined): number;
11
12
  export declare function checkCompilerVersion(version: string, sdkVer: number): boolean | undefined;
13
+ export declare function pushRootNode(stack: ProgramStateStack, root: RootStateNode): void;
14
+ export declare function popRootNode(stack: ProgramStateStack, root: RootStateNode): void;
12
15
  export declare function getApiMapping(state?: ProgramState, resourcesMap?: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): Promise<ProgramStateNode>;
13
16
  export declare function isStateNode(node: {
14
17
  type: string;
@@ -20,13 +23,14 @@ export declare function lookupResultContains(a: LookupDefinition[], b: LookupDef
20
23
  export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
21
24
  export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
22
25
  export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
26
+ export declare function handleImportUsing(state: ProgramStateLive, node: mctree.Using | mctree.ImportModule): void;
23
27
  export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
24
28
  export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): Promise<string>;
25
29
  export declare function findNamesInScope(declStack: StateNode[][], pattern: string | RegExp): (readonly [StateNodeDecl, {
26
30
  readonly parent: StateNode;
27
31
  readonly depth: number;
28
32
  }])[];
29
- export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | FunctionStateNode | ClassStateNode | ModuleStateNode | ProgramStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | TypedefStateNode | EnumStateNode)[];
33
+ export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | ProgramStateNode | FunctionStateNode | ModuleStateNode | ClassStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | TypedefStateNode | EnumStateNode)[];
30
34
  export declare function formatScopedName(node: mctree.ScopedName | mctree.ThisExpression): string;
31
35
  export declare function formatAstLongLines(node: mctree.Node): Promise<string>;
32
36
  export declare function createDocumentationMap(functionDocumentation: {
@@ -42,6 +42,6 @@ export declare function makeIdentifier(name: string, loc?: mctree.SourceLocation
42
42
  name: string;
43
43
  };
44
44
  export declare function makeMemberExpression(object: mctree.ScopedName, property: mctree.Identifier): mctree.DottedName;
45
- export declare function makeScopedName(dotted: string, l?: mctree.SourceLocation): mctree.ScopedName;
45
+ export declare function makeScopedName(dotted: string, l?: mctree.SourceLocation, base?: mctree.ScopedName): mctree.ScopedName;
46
46
  export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
47
47
  export {};
@@ -1,5 +1,6 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { ProgramStateAnalysis, FunctionStateNode } from "./optimizer-types";
2
+ import { ProgramStateAnalysis, FunctionStateNode, ModuleStateNode, ClassStateNode, ProgramStateNode } from "./optimizer-types";
3
+ export type RootStateNode = ProgramStateNode | FunctionStateNode | ModuleStateNode | ClassStateNode;
3
4
  export type BaseEvent = {
4
5
  type: string;
5
6
  mayThrow: boolean;
@@ -14,7 +15,7 @@ export type Block<T extends EventConstraint<T>> = {
14
15
  bogopred?: Block<T>;
15
16
  events?: T[];
16
17
  };
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 buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, root: RootStateNode, refsForUpdate: boolean, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1, containedEvents: () => T[]) => T | T[] | null): Block<T>;
18
19
  export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
19
20
  export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
20
21
  export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
@@ -1,6 +1,6 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { BaseEvent, Block } from "./control-flow";
3
- import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
2
+ import { BaseEvent, Block, RootStateNode } from "./control-flow";
3
+ import { FunctionStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl } from "./optimizer-types";
4
4
  import { GenericQueue } from "./util";
5
5
  export type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
6
6
  export type MemberDecl = {
@@ -25,7 +25,7 @@ export interface KillEvent extends BaseEvent {
25
25
  }
26
26
  export interface DefEvent extends BaseEvent {
27
27
  type: "def";
28
- node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator;
28
+ node: mctree.AssignmentExpression | mctree.UpdateExpression | mctree.VariableDeclarator | mctree.EnumStringMember;
29
29
  decl: EventDecl;
30
30
  rhs?: EventDecl;
31
31
  containedEvents?: Array<RefEvent | ModEvent>;
@@ -40,6 +40,16 @@ export interface ModEvent extends BaseEvent {
40
40
  calleeDecl?: EventDecl | undefined;
41
41
  calleeObj?: EventDecl | undefined;
42
42
  }
43
+ /**
44
+ * When analyzing Program and ModuleDeclaration scopes,
45
+ * we need to keep the imports up to date.
46
+ */
47
+ export interface ImpEvent extends BaseEvent {
48
+ type: "imp";
49
+ node: mctree.Using | mctree.ImportModule | mctree.Program | mctree.ModuleDeclaration;
50
+ stack?: ProgramStateStack;
51
+ decl?: undefined;
52
+ }
43
53
  export declare enum FlowKind {
44
54
  LEFT_EQ_RIGHT_DECL = 0,
45
55
  LEFT_NE_RIGHT_DECL = 1,
@@ -91,14 +101,14 @@ export interface ExnEvent extends BaseEvent {
91
101
  type: "exn";
92
102
  node: mctree.Node;
93
103
  }
94
- export type Event = RefEvent | KillEvent | DefEvent | ModEvent | FlowEvent | ExnEvent;
104
+ export type Event = RefEvent | KillEvent | DefEvent | ModEvent | FlowEvent | ImpEvent | ExnEvent;
95
105
  export interface DataFlowBlock extends Block<Event> {
96
106
  order?: number;
97
107
  }
98
108
  export declare function declFullName(decl: EventDecl): Promise<string>;
99
109
  export declare function declName(decl: EventDecl): string | undefined;
100
110
  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): {
111
+ export declare function buildDataFlowGraph(state: ProgramStateAnalysis, root: RootStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
102
112
  identifiers: Set<string>;
103
113
  graph: Block<Event>;
104
114
  };
@@ -3,5 +3,5 @@ export declare function wouldLog(module: string, level: number): boolean;
3
3
  export declare function bumpLogging(module: string | null, amount: number): void;
4
4
  export declare function setBanner(b: (() => string) | null): void;
5
5
  export declare let logPromise: Promise<unknown>;
6
- export declare function log(...messages: unknown[]): void;
6
+ export declare function log(...messages: unknown[]): Promise<unknown>;
7
7
  export declare function setLogger(log: (message: string) => void): void;
@@ -21,6 +21,7 @@ export declare const enum StateNodeAttributes {
21
21
  interface BaseStateNode {
22
22
  type: string;
23
23
  node: mctree.Node | null | undefined;
24
+ nodes?: Map<mctree.ModuleDeclaration | mctree.Program, ProgramStateStack>;
24
25
  name: string | null | undefined;
25
26
  fullName: string | null | undefined;
26
27
  decls?: StateNodeDecls | undefined;
@@ -31,13 +32,14 @@ interface BaseStateNode {
31
32
  export interface ProgramStateNode extends BaseStateNode {
32
33
  type: "Program";
33
34
  node: mctree.Program | undefined;
35
+ nodes: Map<mctree.Program | mctree.ModuleDeclaration, ProgramStateStack>;
34
36
  name: "$";
35
37
  fullName: "$";
36
- stack?: undefined;
37
38
  }
38
39
  export interface ModuleStateNode extends BaseStateNode {
39
40
  type: "ModuleDeclaration";
40
41
  node: mctree.ModuleDeclaration;
42
+ nodes: Map<mctree.Program | mctree.ModuleDeclaration, ProgramStateStack>;
41
43
  name: string;
42
44
  fullName: string;
43
45
  }
@@ -63,7 +65,6 @@ export interface FunctionStateNode extends BaseStateNode {
63
65
  node: mctree.FunctionDeclaration;
64
66
  name: string;
65
67
  fullName: string;
66
- stack?: ProgramStateStack;
67
68
  decls?: undefined;
68
69
  info?: FunctionInfo | false;
69
70
  next_info?: FunctionInfo;
@@ -135,6 +136,7 @@ export type ByNameStateNodeDecls = ModuleStateNode | ClassStateNode | FunctionSt
135
136
  export type ProgramState = {
136
137
  allFunctions?: Record<string, FunctionStateNode[]>;
137
138
  allClasses?: ClassStateNode[];
139
+ allModules?: Set<ModuleStateNode>;
138
140
  invokeInfo?: FunctionInfo;
139
141
  allDeclarations?: Record<string, ByNameStateNodeDecls[]>;
140
142
  fnMap?: FilesToOptimizeMap;
@@ -145,8 +147,8 @@ export type ProgramState = {
145
147
  currentFunction?: FunctionStateNode;
146
148
  removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
147
149
  shouldExclude?: (node: mctree.Node) => boolean;
148
- pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
149
- post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
150
+ pre?: (node: mctree.Node) => null | false | (keyof mctree.NodeAll)[];
151
+ post?: (node: mctree.Node) => null | false | mctree.Node | mctree.Node[];
150
152
  lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
151
153
  lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
152
154
  lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
@@ -188,7 +190,7 @@ export type Finalized<T, Keys extends keyof T> = T & {
188
190
  [key in Keys]-?: NonNullable<T[key]>;
189
191
  };
190
192
  export type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
191
- export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
193
+ export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allModules" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
192
194
  export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
193
195
  export type ExcludeAnnotationsMap = {
194
196
  [key: string]: boolean;
@@ -1,8 +1,15 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { DiagnosticType, FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
2
+ import { RootStateNode } from "src/control-flow";
3
+ import { DiagnosticType, ProgramStateAnalysis } from "../optimizer-types";
3
4
  import { OpMatch } from "./interp-binary";
4
5
  import { ExactOrUnion, ObjectType } from "./types";
5
6
  export type TypeMap = Map<mctree.Node, ExactOrUnion>;
7
+ export declare const enum DependencyFlags {
8
+ None = 0,
9
+ Type = 1,
10
+ Info = 2
11
+ }
12
+ export type DependencyMap = Map<RootStateNode, DependencyFlags>;
6
13
  export type InterpStackElem = {
7
14
  value: ExactOrUnion;
8
15
  embeddedEffects: boolean;
@@ -13,11 +20,13 @@ export type InterpState = {
13
20
  stack: InterpStackElem[];
14
21
  typeMap?: TypeMap;
15
22
  localLvals?: Set<mctree.Node>;
16
- func?: FunctionStateNode;
23
+ root?: RootStateNode;
17
24
  pre?: (node: mctree.Node) => mctree.Node | false | null | void;
18
25
  post?: (node: mctree.Node) => mctree.Node | false | null | void;
19
26
  typeChecker?: (a: ExactOrUnion, b: ExactOrUnion) => boolean;
20
27
  checkTypes?: DiagnosticType;
28
+ dependencies?: DependencyMap;
29
+ frpushType?: ExactOrUnion;
21
30
  };
22
31
  export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
23
32
  export declare function tryPop(istate: InterpState, node: InterpStackElem["node"]): InterpStackElem;
@@ -0,0 +1,3 @@
1
+ import { ProgramStateAnalysis } from "../optimizer-types";
2
+ import { TypeMap } from "./interp";
3
+ export declare function analyze_module_types(state: ProgramStateAnalysis): Promise<TypeMap | null>;
@@ -1,4 +1,5 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { RootStateNode } from "./control-flow";
2
3
  import { Event, EventDecl } from "./data-flow";
3
4
  import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
4
5
  import { InterpState } from "./type-flow/interp";
@@ -8,7 +9,7 @@ export type NodeEquivMap = Map<mctree.Node, {
8
9
  decl: EventDecl;
9
10
  equiv: Array<EventDecl>;
10
11
  }>;
11
- export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode, optimizeEquivalencies: boolean): InterpState | undefined;
12
+ export declare function buildTypeInfo(state: ProgramStateAnalysis, root: RootStateNode, optimizeEquivalencies: boolean): InterpState | undefined;
12
13
  export declare function buildConflictGraph(state: ProgramStateAnalysis, func: FunctionStateNode): {
13
14
  graph: import("./control-flow").Block<Event>;
14
15
  localConflicts: Map<TypeStateKey, Set<TypeStateKey>> | null;
package/build/util.cjs CHANGED
@@ -18,35 +18,35 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var util_exports = {};
20
20
  __export(util_exports, {
21
- AwaitedError: () => import_chunk_OASVKTK5.AwaitedError,
22
- GenericQueue: () => import_chunk_OASVKTK5.GenericQueue,
23
- bumpLogging: () => import_chunk_OASVKTK5.bumpLogging,
24
- copyRecursiveAsNeeded: () => import_chunk_OASVKTK5.copyRecursiveAsNeeded,
25
- every: () => import_chunk_OASVKTK5.every,
26
- first_modified: () => import_chunk_OASVKTK5.first_modified,
27
- forEach: () => import_chunk_OASVKTK5.forEach,
28
- globSome: () => import_chunk_OASVKTK5.globSome,
29
- globa: () => import_chunk_OASVKTK5.globa,
30
- last_modified: () => import_chunk_OASVKTK5.last_modified,
31
- log: () => import_chunk_OASVKTK5.log,
32
- logPromise: () => import_chunk_OASVKTK5.logPromise,
33
- logger: () => import_chunk_OASVKTK5.logger,
34
- map: () => import_chunk_OASVKTK5.map,
35
- popcount: () => import_chunk_OASVKTK5.popcount,
36
- promiseAll: () => import_chunk_OASVKTK5.promiseAll,
37
- pushUnique: () => import_chunk_OASVKTK5.pushUnique,
38
- readByLine: () => import_chunk_OASVKTK5.readByLine,
39
- reduce: () => import_chunk_OASVKTK5.reduce,
40
- sameArrays: () => import_chunk_OASVKTK5.sameArrays,
41
- setBanner: () => import_chunk_OASVKTK5.setBanner,
42
- some: () => import_chunk_OASVKTK5.some,
43
- spawnByLine: () => import_chunk_OASVKTK5.spawnByLine,
44
- wouldLog: () => import_chunk_OASVKTK5.wouldLog
21
+ AwaitedError: () => import_chunk_NHZRKHZO.AwaitedError,
22
+ GenericQueue: () => import_chunk_NHZRKHZO.GenericQueue,
23
+ bumpLogging: () => import_chunk_NHZRKHZO.bumpLogging,
24
+ copyRecursiveAsNeeded: () => import_chunk_NHZRKHZO.copyRecursiveAsNeeded,
25
+ every: () => import_chunk_NHZRKHZO.every,
26
+ first_modified: () => import_chunk_NHZRKHZO.first_modified,
27
+ forEach: () => import_chunk_NHZRKHZO.forEach,
28
+ globSome: () => import_chunk_NHZRKHZO.globSome,
29
+ globa: () => import_chunk_NHZRKHZO.globa,
30
+ last_modified: () => import_chunk_NHZRKHZO.last_modified,
31
+ log: () => import_chunk_NHZRKHZO.log,
32
+ logPromise: () => import_chunk_NHZRKHZO.logPromise,
33
+ logger: () => import_chunk_NHZRKHZO.logger,
34
+ map: () => import_chunk_NHZRKHZO.map,
35
+ popcount: () => import_chunk_NHZRKHZO.popcount,
36
+ promiseAll: () => import_chunk_NHZRKHZO.promiseAll,
37
+ pushUnique: () => import_chunk_NHZRKHZO.pushUnique,
38
+ readByLine: () => import_chunk_NHZRKHZO.readByLine,
39
+ reduce: () => import_chunk_NHZRKHZO.reduce,
40
+ sameArrays: () => import_chunk_NHZRKHZO.sameArrays,
41
+ setBanner: () => import_chunk_NHZRKHZO.setBanner,
42
+ some: () => import_chunk_NHZRKHZO.some,
43
+ spawnByLine: () => import_chunk_NHZRKHZO.spawnByLine,
44
+ wouldLog: () => import_chunk_NHZRKHZO.wouldLog
45
45
  });
46
46
  module.exports = __toCommonJS(util_exports);
47
- var import_chunk_OASVKTK5 = require("./chunk-OASVKTK5.cjs");
47
+ var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
48
48
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
49
- (0, import_chunk_OASVKTK5.init_util)();
49
+ (0, import_chunk_NHZRKHZO.init_util)();
50
50
  // Annotate the CommonJS export names for ESM import in node:
51
51
  0 && (module.exports = {
52
52
  AwaitedError,
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_NGCEDNHJ = require("./chunk-NGCEDNHJ.cjs");
25
- var import_chunk_OASVKTK5 = require("./chunk-OASVKTK5.cjs");
26
- var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
24
+ var import_chunk_2PJMJVYN = require("./chunk-2PJMJVYN.cjs");
25
+ var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
26
+ var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_NGCEDNHJ.init_worker_task)();
31
+ (0, import_chunk_2PJMJVYN.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_NGCEDNHJ.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_2PJMJVYN.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.68",
4
+ "version": "1.1.70",
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",