@markw65/monkeyc-optimizer 1.0.21 → 1.0.22

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,9 +1,12 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- export declare function getApiMapping(state?: ProgramState): Promise<ProgramStateNode | null>;
2
+ export { visitReferences } from "./visitor";
3
+ export declare function getApiMapping(state?: ProgramState, barrelList?: string[]): Promise<ProgramStateNode | null>;
3
4
  export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
4
5
  export declare function hasProperty<T>(obj: T, prop: string): boolean;
5
6
  export declare function isStateNode(node: StateNodeDecl): node is StateNode;
6
- export declare function variableDeclarationName(node: mctree.TypedIdentifier): string;
7
+ export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
8
+ export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
7
9
  export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
8
10
  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[];
9
11
  export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
12
+ export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier, isType: boolean): StateNodeDecl[] | null;
@@ -1,13 +1,9 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- export declare enum InlineStatus {
3
- Never = 0,
4
- AsExpression = 1,
5
- AsStatement = 2
6
- }
7
2
  export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
8
3
  declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
9
4
  export declare function unused(expression: mctree.ExpressionStatement["expression"]): mctree.ExpressionStatement[];
10
5
  export declare function unused(expression: mctree.ExpressionStatement["expression"], top: true): mctree.ExpressionStatement[] | null;
6
+ export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
11
7
  export declare type InlineContext = mctree.ReturnStatement | mctree.AssignmentExpression | mctree.ExpressionStatement;
12
8
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
13
9
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -1,11 +1,11 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
3
3
  export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
4
- export declare function analyze(fnMap: FilesToOptimizeMap): Promise<ProgramStateAnalysis>;
5
- export declare function getLiteralFromDecls(decls: StateNodeDecl[]): null;
4
+ export declare function analyze(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<ProgramStateAnalysis>;
5
+ export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): null;
6
6
  export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
7
- export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap): Promise<Record<string, {
8
- type: "ERROR" | "WARNING" | "INFO";
7
+ export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<Record<string, {
8
+ type: DiagnosticType;
9
9
  loc: {
10
10
  start: mctree.Position;
11
11
  end: mctree.Position;
@@ -13,6 +13,7 @@ export interface ErrorWithLocation extends Error {
13
13
  }
14
14
  export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
15
15
  declare global {
16
+ type DiagnosticType = "ERROR" | "WARNING" | "INFO";
16
17
  type BuildConfig = {
17
18
  workspace?: string;
18
19
  jungleFiles?: string;
@@ -35,6 +36,7 @@ declare global {
35
36
  ignoredSourcePaths?: string;
36
37
  returnCommand?: boolean;
37
38
  checkBuildPragmas?: boolean;
39
+ checkInvalidSymbols?: DiagnosticType | "OFF";
38
40
  _cache?: {
39
41
  barrels?: Record<string, ResolvedJungle>;
40
42
  barrelMap?: Record<string, Record<string, ResolvedJungle>>;
@@ -44,6 +46,10 @@ declare global {
44
46
  type StateNodeDecls = {
45
47
  [key: string]: StateNodeDecl[];
46
48
  };
49
+ type ImportUsing = {
50
+ node: mctree.Using | mctree.ImportModule;
51
+ module?: ModuleStateNode | null | undefined;
52
+ };
47
53
  interface BaseStateNode {
48
54
  type: string;
49
55
  node: mctree.Node | null | undefined;
@@ -52,10 +58,12 @@ declare global {
52
58
  decls?: StateNodeDecls | undefined;
53
59
  type_decls?: StateNodeDecls | undefined;
54
60
  stack?: ProgramStateStack | undefined;
61
+ usings?: Record<string, ImportUsing>;
62
+ imports?: ImportUsing[];
55
63
  }
56
64
  interface ProgramStateNode extends BaseStateNode {
57
65
  type: "Program";
58
- node: null | undefined;
66
+ node: mctree.Program | undefined;
59
67
  name: "$";
60
68
  fullName: "$";
61
69
  stack?: undefined;
@@ -80,6 +88,7 @@ declare global {
80
88
  fullName: string;
81
89
  stack?: ProgramStateStack;
82
90
  decls?: undefined;
91
+ isStatic?: boolean;
83
92
  }
84
93
  interface BlockStateNode extends BaseStateNode {
85
94
  type: "BlockStatement";
@@ -103,6 +112,11 @@ declare global {
103
112
  }
104
113
  type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
105
114
  type ProgramStateStack = StateNode[];
115
+ type LookupDefinition = {
116
+ parent: StateNodeDecl | null;
117
+ results: StateNodeDecl[];
118
+ };
119
+ type LookupResult = [string, LookupDefinition[]] | [null, null] | [false, false];
106
120
  export type ProgramState = {
107
121
  allFunctions?: FunctionStateNode[];
108
122
  allClasses?: ClassStateNode[];
@@ -112,12 +126,15 @@ declare global {
112
126
  shouldExclude?: (node: mctree.Node) => boolean;
113
127
  pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
114
128
  post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
115
- lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
116
- lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
117
- lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
129
+ lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
130
+ lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
131
+ lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
132
+ lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
133
+ stackClone?: () => ProgramStateStack;
118
134
  traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
119
135
  inType?: boolean;
120
136
  inlining?: true;
137
+ config?: BuildConfig;
121
138
  exposed?: {
122
139
  [key: string]: true;
123
140
  };
@@ -140,7 +157,7 @@ declare global {
140
157
  [key: string]: mctree.Literal;
141
158
  };
142
159
  diagnostics?: Record<string, {
143
- type: "ERROR" | "WARNING" | "INFO";
160
+ type: DiagnosticType;
144
161
  loc: {
145
162
  start: mctree.Position;
146
163
  end: mctree.Position;
@@ -151,7 +168,7 @@ declare global {
151
168
  type Finalized<T, Keys extends keyof T> = T & {
152
169
  [key in Keys]-?: NonNullable<T[key]>;
153
170
  };
154
- export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
171
+ export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
155
172
  export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
156
173
  export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
157
174
  type ExcludeAnnotationsMap = {
@@ -182,7 +199,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
182
199
  product: string | null;
183
200
  hasTests: boolean | undefined;
184
201
  diagnostics: Record<string, {
185
- type: "ERROR" | "WARNING" | "INFO";
202
+ type: DiagnosticType;
186
203
  loc: {
187
204
  start: mctree.Position;
188
205
  end: mctree.Position;
@@ -202,7 +219,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
202
219
  program: string;
203
220
  hasTests: boolean;
204
221
  diagnostics: Record<string, {
205
- type: "ERROR" | "WARNING" | "INFO";
222
+ type: DiagnosticType;
206
223
  loc: {
207
224
  start: mctree.Position;
208
225
  end: mctree.Position;
@@ -1,2 +1,2 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- export declare function pragmaChecker(ast: mctree.Program): void;
2
+ export declare function pragmaChecker(ast: mctree.Program, diagnostics: NonNullable<ProgramState["diagnostics"]>[string] | null | undefined): void;
@@ -3,6 +3,7 @@ export declare function globa(pattern: string, options?: glob.IOptions): Promise
3
3
  export declare function last_modified(inputs: string[]): Promise<number>;
4
4
  export declare function first_modified(inputs: string[]): Promise<number>;
5
5
  export declare function pushUnique<T, U extends T>(arr: T[], value: U): void;
6
+ export declare function sameArrays<T>(a1: T[], a2: T[], check: (a: T, b: T) => boolean): boolean;
6
7
  export declare type LineHandler = (line: string) => void;
7
8
  export declare function spawnByLine(command: string, args: string[], lineHandlers: LineHandler | LineHandler[], options?: {
8
9
  [key: string]: unknown;
@@ -0,0 +1,2 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false): void;
package/build/util.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globa,last_modified,promiseAll,pushUnique,readByLine,spawnByLine});
1
+ 0 && (module.exports = {copyRecursiveAsNeeded,first_modified,globa,last_modified,promiseAll,pushUnique,readByLine,sameArrays,spawnByLine});
2
2
  /******/ (() => { // webpackBootstrap
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
@@ -4005,6 +4005,7 @@ __webpack_require__.d(__webpack_exports__, {
4005
4005
  "promiseAll": () => (/* binding */ promiseAll),
4006
4006
  "pushUnique": () => (/* binding */ pushUnique),
4007
4007
  "readByLine": () => (/* binding */ readByLine),
4008
+ "sameArrays": () => (/* binding */ sameArrays),
4008
4009
  "spawnByLine": () => (/* binding */ spawnByLine)
4009
4010
  });
4010
4011
 
@@ -4065,6 +4066,9 @@ function pushUnique(arr, value) {
4065
4066
  return;
4066
4067
  arr.push(value);
4067
4068
  }
4069
+ function sameArrays(a1, a2, check) {
4070
+ return a1.length === a2.length && a1.every((e, i) => check(e, a2[i]));
4071
+ }
4068
4072
  // return a promise that will process the output of command
4069
4073
  // line-by-line via lineHandlers.
4070
4074
  function spawnByLine(command, args, lineHandlers, options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.21",
4
+ "version": "1.0.22",
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",
@@ -34,7 +34,7 @@
34
34
  "author": "markw65",
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@markw65/prettier-plugin-monkeyc": "^1.0.24"
37
+ "@markw65/prettier-plugin-monkeyc": "^1.0.26"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/glob": "^7.2.0",