@markw65/monkeyc-optimizer 1.1.7 → 1.1.9

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,4 +1,4 @@
1
- 0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin,readPrg,xmlUtil});
1
+ 0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getFunctionDocumentation,getLanguages,getSdkPath,isWin,readPrg,xmlUtil});
2
2
  /******/ (() => { // webpackBootstrap
3
3
  /******/ "use strict";
4
4
  /******/ // The require scope
@@ -44,6 +44,7 @@ __webpack_require__.d(__webpack_exports__, {
44
44
  "appSupport": () => (/* binding */ appSupport),
45
45
  "connectiq": () => (/* binding */ connectiq),
46
46
  "getDeviceInfo": () => (/* binding */ getDeviceInfo),
47
+ "getFunctionDocumentation": () => (/* binding */ getFunctionDocumentation),
47
48
  "getLanguages": () => (/* binding */ getLanguages),
48
49
  "getSdkPath": () => (/* binding */ getSdkPath),
49
50
  "isWin": () => (/* binding */ isWin),
@@ -796,6 +797,29 @@ async function getLanguages() {
796
797
  })
797
798
  .filter((s) => s != null);
798
799
  }
800
+ async function getFunctionDocumentation() {
801
+ const file = external_path_namespaceObject.join(await getSdkPath(), "bin", "api.debug.xml");
802
+ const data = await promises_namespaceObject.readFile(file);
803
+ const xml = parseXml(data.toString(), file);
804
+ if (xml.body instanceof Error) {
805
+ return null;
806
+ }
807
+ const entries = xml.body
808
+ .children("functions")
809
+ .children("functionEntry")
810
+ .elements.map((e) => ({
811
+ name: e.attr.name?.value.value,
812
+ parent: e.attr.parent?.value.value,
813
+ doc: e.children
814
+ ?.filter((child) => child.type === "element" &&
815
+ child.name === "documentation" &&
816
+ child.children != null)
817
+ .map((doc) => doc.children?.map((c) => c.type === "chardata" || c.type === "cdata" ? c.value : "") || "")
818
+ .join("") || "",
819
+ }))
820
+ .filter((x) => x.name != null && x.parent != null && x.doc !== "");
821
+ return entries;
822
+ }
799
823
 
800
824
  var __webpack_export_target__ = exports;
801
825
  for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
@@ -1,9 +1,10 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { hasProperty, traverseAst } from "./ast";
3
3
  import { JungleResourceMap } from "./jungles";
4
- import { ClassStateNode, Diagnostic, DiagnosticType, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
4
+ import { ClassStateNode, Diagnostic, DiagnosticType, EnumStateNode, FunctionInfo, FunctionStateNode, LookupDefinition, LookupResult, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, TypedefStateNode, VariableStateNode } from "./optimizer-types";
5
5
  import { visit_resources } from "./resources";
6
6
  import { xmlUtil } from "./sdk-util";
7
+ import { TypeMap } from "./type-flow/interp";
7
8
  export { visitorNode, visitReferences } from "./visitor";
8
9
  export { traverseAst, hasProperty, visit_resources };
9
10
  export declare function parseSdkVersion(version: string | undefined): number;
@@ -15,10 +16,25 @@ export declare function isStateNode(node: {
15
16
  export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
16
17
  declare type DeclKind = "decls" | "type_decls";
17
18
  export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
19
+ export declare function lookupResultContains(a: LookupDefinition[], b: LookupDefinition[]): boolean;
18
20
  export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
19
21
  export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
22
+ export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
20
23
  export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
21
24
  export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
25
+ export declare function findNamesInScope(declStack: StateNode[][], pattern: string | RegExp): [StateNodeDecl, {
26
+ parent: StateNode;
27
+ depth: number;
28
+ }][];
29
+ export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (ModuleStateNode | FunctionStateNode | ClassStateNode | TypedefStateNode | ProgramStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | EnumStateNode | mctree.EnumStringMember | mctree.Identifier | mctree.AsIdentifier)[];
30
+ export declare function formatAstLongLines(node: mctree.Node): string;
31
+ export declare function createDocumentationMap(functionDocumentation: {
32
+ name: string;
33
+ parent: string;
34
+ doc: string;
35
+ }[]): Promise<Map<string, string>>;
36
+ export declare function makeToyboxLink(result: StateNodeDecl): string | null;
37
+ export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
22
38
  export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier): ModuleStateNode | {
23
39
  name: string;
24
40
  decls: {
@@ -47,7 +47,7 @@ export declare enum FlowKind {
47
47
  INSTANCEOF = 6,
48
48
  NOTINSTANCE = 7
49
49
  }
50
- interface FlowEventDecl extends BaseEvent {
50
+ export interface FlowEventDecl extends BaseEvent {
51
51
  type: "flw";
52
52
  node: mctree.BinaryExpression | mctree.UnaryExpression;
53
53
  decl?: undefined;
@@ -56,7 +56,7 @@ interface FlowEventDecl extends BaseEvent {
56
56
  right_decl: EventDecl;
57
57
  right_node?: undefined;
58
58
  }
59
- interface FlowEventNode extends BaseEvent {
59
+ export interface FlowEventNode extends BaseEvent {
60
60
  type: "flw";
61
61
  node: mctree.BinaryExpression | mctree.UnaryExpression;
62
62
  decl?: undefined;
@@ -65,7 +65,7 @@ interface FlowEventNode extends BaseEvent {
65
65
  right_decl?: undefined;
66
66
  right_node: mctree.Expression;
67
67
  }
68
- interface FlowEventTruthy extends BaseEvent {
68
+ export interface FlowEventTruthy extends BaseEvent {
69
69
  type: "flw";
70
70
  node: mctree.Node;
71
71
  decl?: undefined;
@@ -74,7 +74,7 @@ interface FlowEventTruthy extends BaseEvent {
74
74
  right_decl?: undefined;
75
75
  right_node?: undefined;
76
76
  }
77
- interface FlowEventInstanceof extends BaseEvent {
77
+ export interface FlowEventInstanceof extends BaseEvent {
78
78
  type: "flw";
79
79
  node: mctree.InstanceofExpression | mctree.UnaryExpression;
80
80
  decl?: undefined;
@@ -106,4 +106,3 @@ export declare class DataflowQueue {
106
106
  dequeue(): DataFlowBlock;
107
107
  empty(): boolean;
108
108
  }
109
- export {};
@@ -62,8 +62,6 @@ interface BaseStateNode {
62
62
  decls?: StateNodeDecls | undefined;
63
63
  type_decls?: StateNodeDecls | undefined;
64
64
  stack?: ProgramStateStack | undefined;
65
- usings?: Record<string, ImportUsing>;
66
- imports?: ImportUsing[];
67
65
  attributes: StateNodeAttributes;
68
66
  }
69
67
  export interface ProgramStateNode extends BaseStateNode {
@@ -154,8 +152,13 @@ export interface Diagnostic extends DiagnosticBase {
154
152
  message: string;
155
153
  };
156
154
  }
155
+ declare type ProgramStateStackElem = {
156
+ sn: StateNode;
157
+ usings?: Record<string, ImportUsing>;
158
+ imports?: ImportUsing[];
159
+ };
157
160
  export declare type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode | EnumStateNode;
158
- export declare type ProgramStateStack = StateNode[];
161
+ export declare type ProgramStateStack = ProgramStateStackElem[];
159
162
  export declare type LookupDefinition = {
160
163
  parent: StateNode | null;
161
164
  results: StateNodeDecl[];
@@ -171,15 +174,16 @@ export declare type ProgramState = {
171
174
  rezAst?: mctree.Program;
172
175
  manifestXML?: xmlUtil.Document;
173
176
  stack?: ProgramStateStack;
177
+ top?: () => ProgramStateStackElem;
174
178
  currentFunction?: FunctionStateNode;
175
179
  removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
176
180
  shouldExclude?: (node: mctree.Node) => boolean;
177
181
  pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
178
182
  post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node | mctree.Node[];
179
- lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
180
- lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
181
- lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
182
- lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => LookupResult;
183
+ lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
184
+ lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
185
+ lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
186
+ lookupNonlocal?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack | null) => LookupResult;
183
187
  stackClone?: () => ProgramStateStack;
184
188
  traverse?: (node: mctree.Node) => void | null | false | mctree.Node | mctree.Node[];
185
189
  inType?: number;
@@ -216,7 +220,7 @@ export declare type ProgramState = {
216
220
  export declare type Finalized<T, Keys extends keyof T> = T & {
217
221
  [key in Keys]-?: NonNullable<T[key]>;
218
222
  };
219
- export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
223
+ export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
220
224
  export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
221
225
  export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
222
226
  export declare type ExcludeAnnotationsMap = {
@@ -20,3 +20,8 @@ export declare function getLanguages(): Promise<{
20
20
  id: string;
21
21
  name: string;
22
22
  }[]>;
23
+ export declare function getFunctionDocumentation(): Promise<{
24
+ name: string;
25
+ parent: string;
26
+ doc: string;
27
+ }[] | null>;
@@ -1,5 +1,10 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { NodeEquivMap } from "src/type-flow";
2
3
  import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
3
- import { TypeFlowBlock } from "./type-flow-util";
4
- export declare function findDeadStores(graph: TypeFlowBlock, logThisRun: boolean): Set<mctree.Node>;
4
+ import { TypeFlowBlock, TypeStateKey } from "./type-flow-util";
5
+ export declare function findDeadStores(func: FunctionStateNode, graph: TypeFlowBlock, nodeEquivs: NodeEquivMap | null, logThisRun: boolean): {
6
+ deadStores: Set<mctree.Node>;
7
+ locals: Set<TypeStateKey>;
8
+ localConflicts: Map<TypeStateKey, Set<TypeStateKey>> | null;
9
+ };
5
10
  export declare function eliminateDeadStores(state: ProgramStateAnalysis, func: FunctionStateNode, graph: TypeFlowBlock, logThisRun: boolean): boolean;
File without changes
@@ -0,0 +1,2 @@
1
+ import { FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
2
+ export declare function minimizeLocals(state: ProgramStateAnalysis, func: FunctionStateNode): void;
@@ -26,9 +26,9 @@ export declare const enum TypeTag {
26
26
  Typedef = 262144,
27
27
  Any = 524287
28
28
  }
29
- export declare function typeTagName(tag: TypeTag): "Object" | "Number" | "Float" | "Double" | "Long" | "String" | "Char" | "Boolean" | "Null" | "Never" | "False" | "True" | "Decimal" | "Numeric" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Enum" | "Symbol" | "Typedef" | "Any";
29
+ export declare function typeTagName(tag: TypeTag): "Number" | "Float" | "Double" | "Long" | "String" | "Char" | "Boolean" | "Null" | "Never" | "False" | "True" | "Decimal" | "Numeric" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Object" | "Enum" | "Symbol" | "Typedef" | "Any";
30
30
  export declare const LastTypeTag = TypeTag.Typedef;
31
- export declare const SingleTonTypeTagsConst: number;
31
+ export declare const SingletonTypeTagsConst: number;
32
32
  export declare const UnionDataTypeTagsConst: number;
33
33
  export declare const ValueTypeTagsConst: number;
34
34
  export declare const ObjectLikeTagsConst: number;
@@ -183,7 +183,6 @@ export declare function isUnion(v: AbstractValue): v is UnionType;
183
183
  export declare function isSingleton(v: AbstractValue): v is SingletonType;
184
184
  export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
185
185
  export declare function hasNoData(v: AbstractValue, t: TypeTag): boolean;
186
- export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
187
186
  export declare function cloneType<T extends ExactOrUnion>(t: T): T;
188
187
  export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
189
188
  export declare function typeFromTypeStateNodes(state: ProgramStateAnalysis, sns: StateNodeDecl[], classVsObj?: boolean): ExactOrUnion;
@@ -1,10 +1,23 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { EventDecl } from "./data-flow";
2
3
  import { FunctionStateNode, ProgramStateAnalysis, StateNode } from "./optimizer-types";
3
4
  import { InterpState } from "./type-flow/interp";
5
+ import { TypeStateKey } from "./type-flow/type-flow-util";
4
6
  import { ExactOrUnion } from "./type-flow/types";
5
7
  export declare const missingNullWorkaround = true;
8
+ export declare type NodeEquivMap = Map<mctree.Node, {
9
+ decl: EventDecl;
10
+ equiv: Array<EventDecl>;
11
+ }>;
6
12
  export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode, optimizeEquivalencies: boolean): InterpState | undefined;
7
- export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): [StateNode[], StateNode[]] | readonly [null, null];
13
+ export declare function buildConflictGraph(state: ProgramStateAnalysis, func: FunctionStateNode): {
14
+ graph: import("./control-flow").Block<import("./data-flow").RefEvent | import("./data-flow").KillEvent | import("./data-flow").DefEvent | import("./data-flow").ModEvent | import("./data-flow").FlowEventDecl | import("./data-flow").FlowEventNode | import("./data-flow").FlowEventTruthy | import("./data-flow").FlowEventInstanceof | import("./data-flow").ExnEvent>;
15
+ localConflicts: Map<TypeStateKey, Set<TypeStateKey>> | null;
16
+ locals: Set<TypeStateKey>;
17
+ identifiers: Set<string>;
18
+ logThisRun: boolean;
19
+ } | undefined;
20
+ export declare function findObjectDeclsByProperty(state: ProgramStateAnalysis, object: ExactOrUnion, next: mctree.DottedMemberExpression): readonly [null, null] | [StateNode[], StateNode[]];
8
21
  export declare function resolveDottedMember(istate: InterpState, object: ExactOrUnion, next: mctree.DottedMemberExpression): {
9
22
  mayThrow: boolean;
10
23
  object: ExactOrUnion;
@@ -2,4 +2,4 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
3
3
  import { TypeMap } from "./type-flow/interp";
4
4
  export declare function visitorNode(node: mctree.Node): mctree.Node;
5
- 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, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null): void;
5
+ 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, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null, findSingleDefinition?: boolean): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.1.7",
4
+ "version": "1.1.9",
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",
@@ -40,7 +40,7 @@
40
40
  "author": "markw65",
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "@markw65/prettier-plugin-monkeyc": "^1.0.42"
43
+ "@markw65/prettier-plugin-monkeyc": "^1.0.43"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/chai": "^4.3.4",