@markw65/monkeyc-optimizer 1.1.2 → 1.1.4

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,29 +1,6 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl, TypedefStateNode } 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
- Typedef = 17
25
- }
26
- export declare enum TypeTag {
2
+ import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNode, StateNodeDecl, TypedefStateNode } from "../optimizer-types";
3
+ export declare const enum TypeTag {
27
4
  Never = 0,
28
5
  Null = 1,
29
6
  False = 2,
@@ -33,35 +10,51 @@ export declare enum TypeTag {
33
10
  Long = 16,
34
11
  Float = 32,
35
12
  Double = 64,
13
+ Decimal = 96,
36
14
  Numeric = 120,
37
15
  Char = 128,
38
16
  String = 256,
39
17
  Array = 512,
40
18
  Dictionary = 1024,
41
- Module = 2048,
42
- Function = 4096,
43
- Class = 8192,
44
- Object = 16384,
45
- Enum = 32768,
46
- Symbol = 65536,
47
- Typedef = 131072,
48
- Any = 262143
49
- }
19
+ Method = 2048,
20
+ Module = 4096,
21
+ Function = 8192,
22
+ Class = 16384,
23
+ Object = 32768,
24
+ Enum = 65536,
25
+ Symbol = 131072,
26
+ Typedef = 262144,
27
+ Any = 524287
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";
30
+ export declare const LastTypeTag = TypeTag.Typedef;
50
31
  export declare const SingleTonTypeTagsConst: number;
51
32
  export declare const UnionDataTypeTagsConst: number;
52
33
  export declare const ValueTypeTagsConst: number;
53
34
  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;
35
+ export declare const EnumTagsConst: number;
36
+ 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.Method | TypeTag.Module | TypeTag.Function | TypeTag.Class | TypeTag.Object | TypeTag.Enum | TypeTag.Symbol | TypeTag.Typedef;
55
37
  export declare type EnumeratedTypeTags = ExactTypeTags | TypeTag.Never | TypeTag.Any;
56
38
  export declare type UnionTypeTags = number;
57
39
  interface AbstractValue {
58
40
  type: UnionTypeTags;
59
41
  value?: unknown;
60
42
  }
61
- export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType | TypedefType;
62
- declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : T & {
43
+ export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | MethodType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType | TypedefType;
44
+ declare type ExactPairHelper<T> = T extends ExactTypes ? {
45
+ type: T["type"];
46
+ avalue: T["value"];
47
+ bvalue: T["value"];
48
+ } : never;
49
+ export declare type ExactPairs = ExactPairHelper<ExactTypes>;
50
+ export declare type ValuePairs = ExactPairHelper<ValueTypes>;
51
+ declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : {
52
+ type: T["type"];
63
53
  value: NonNullable<T["value"]>;
64
54
  } : never;
55
+ export declare type ExactData<T extends ExactTypeTags> = T extends SingletonType ? undefined : NonNullable<Extract<ExactTypes, {
56
+ type: T;
57
+ }>["value"]>;
65
58
  export declare type ValueTypes = WithValue<ExactTypes>;
66
59
  export declare type ExtendedTypes = ExactTypes | NeverType | AnyType;
67
60
  export interface NeverType extends AbstractValue {
@@ -115,6 +108,13 @@ export interface DictionaryType extends AbstractValue {
115
108
  value: ExactOrUnion;
116
109
  } | undefined;
117
110
  }
111
+ export interface MethodType extends AbstractValue {
112
+ type: TypeTag.Method;
113
+ value?: {
114
+ args: ExactOrUnion[];
115
+ result: ExactOrUnion;
116
+ } | undefined;
117
+ }
118
118
  export interface ModuleType extends AbstractValue {
119
119
  type: TypeTag.Module;
120
120
  value?: ModuleStateNode | ModuleStateNode[] | undefined;
@@ -143,6 +143,9 @@ export interface EnumType extends AbstractValue {
143
143
  value?: {
144
144
  enum: EnumStateNode;
145
145
  value?: ExactOrUnion | undefined;
146
+ } | {
147
+ enum?: undefined;
148
+ value: ExactOrUnion;
146
149
  } | undefined;
147
150
  }
148
151
  export interface SymbolType extends AbstractValue {
@@ -150,7 +153,7 @@ export interface SymbolType extends AbstractValue {
150
153
  value?: string | undefined;
151
154
  }
152
155
  export interface AnyType extends AbstractValue {
153
- type: -1;
156
+ type: TypeTag.Any;
154
157
  value?: undefined;
155
158
  }
156
159
  export declare type SingletonType = NullType | FalseType | TrueType;
@@ -158,6 +161,7 @@ export declare type UnionData = {
158
161
  mask: TypeTag;
159
162
  [TypeTag.Array]?: NonNullable<ArrayType["value"]>;
160
163
  [TypeTag.Dictionary]?: NonNullable<DictionaryType["value"]>;
164
+ [TypeTag.Method]?: NonNullable<MethodType["value"]>;
161
165
  [TypeTag.Module]?: NonNullable<ModuleType["value"]>;
162
166
  [TypeTag.Function]?: NonNullable<FunctionType["value"]>;
163
167
  [TypeTag.Class]?: NonNullable<ClassType["value"]>;
@@ -173,20 +177,17 @@ export declare type SingleValue = NonNullable<ValueTypes["value"]>;
173
177
  declare type TagValue<TAG> = Extract<ValueTypes, {
174
178
  type: TAG;
175
179
  }>["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
180
  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>;
182
181
  export declare function isExact(v: AbstractValue): v is ExactTypes;
183
182
  export declare function isUnion(v: AbstractValue): v is UnionType;
184
183
  export declare function isSingleton(v: AbstractValue): v is SingletonType;
185
184
  export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
186
185
  export declare function hasNoData(v: AbstractValue, t: TypeTag): boolean;
186
+ export declare function lookupByFullName(state: ProgramStateAnalysis, fullName: string): StateNodeDecl[];
187
187
  export declare function cloneType<T extends ExactOrUnion>(t: T): T;
188
188
  export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
189
189
  export declare function typeFromTypeStateNodes(state: ProgramStateAnalysis, sns: StateNodeDecl[], classVsObj?: boolean): ExactOrUnion;
190
+ export declare function typeFromSingleTypeSpec(state: ProgramStateAnalysis, type: mctree.TypeSpecPart | mctree.ObjectExpression, stack?: ProgramStateStack | undefined): ExactOrUnion;
190
191
  export declare function typeFromTypespec(state: ProgramStateAnalysis, ts: mctree.TypeSpecList, stack?: ProgramStateStack | undefined): ExactOrUnion;
191
192
  export declare function typeFromLiteral(literal: mctree.Literal): ExactTypes;
192
193
  export declare function mcExprFromType(type: ValueTypes): mctree.Expression | null;
@@ -197,6 +198,8 @@ export declare function mustBeFalse(arg: ExactOrUnion): boolean;
197
198
  export declare function display(type: ExactOrUnion): string;
198
199
  export declare function hasUnionData(tag: TypeTag): boolean;
199
200
  export declare function getObjectValue(t: ExactOrUnion): ObjectType["value"] | null;
200
- export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn: (tag: UnionDataKey, value: SingleValue | null | undefined) => boolean | void): void;
201
- export declare function getUnionComponent(v: ExactOrUnion, tag: TypeTag): SingleValue | null;
201
+ export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn: (type: ExactTypes) => boolean | void): void;
202
+ export declare function getUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T): ExactData<T> | null;
203
+ export declare function setUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T, c: ExactData<T>): void;
204
+ export declare function getStateNodeDeclsFromType(state: ProgramStateAnalysis, object: ExactOrUnion): StateNode[];
202
205
  export {};
@@ -1,3 +1,4 @@
1
1
  import { ExactOrUnion, TypeTag } from "./types";
2
2
  export declare function unionInto(to: ExactOrUnion, from: ExactOrUnion): boolean;
3
3
  export declare function clearValuesUnder(v: ExactOrUnion, tag: TypeTag, clearTag?: boolean): void;
4
+ export declare function widenType(t: ExactOrUnion): null;
@@ -1,3 +1,12 @@
1
- import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { FunctionStateNode, ProgramStateAnalysis, StateNode } from "./optimizer-types";
2
3
  import { InterpState } from "./type-flow/interp";
3
- export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode): InterpState | undefined;
4
+ import { ExactOrUnion } from "./type-flow/types";
5
+ export declare const missingNullWorkaround = true;
6
+ 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[] | null;
8
+ export declare function resolveDottedMember(istate: InterpState, object: ExactOrUnion, next: mctree.DottedMemberExpression): {
9
+ mayThrow: boolean;
10
+ object: ExactOrUnion;
11
+ property: import("./type-flow/types").UnionType | import("./type-flow/types").NumberType | import("./type-flow/types").LongType | import("./type-flow/types").FloatType | import("./type-flow/types").DoubleType | import("./type-flow/types").CharType | import("./type-flow/types").StringType | import("./type-flow/types").ArrayType | import("./type-flow/types").DictionaryType | import("./type-flow/types").MethodType | import("./type-flow/types").ModuleType | import("./type-flow/types").FunctionType | import("./type-flow/types").ClassType | import("./type-flow/types").ObjectType | import("./type-flow/types").EnumType | import("./type-flow/types").SymbolType | import("./type-flow/types").TypedefType;
12
+ } | null;
@@ -1,3 +1,3 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { ProgramStateOptimizer } from "./optimizer-types";
3
- export declare function cleanupUnusedVars(state: ProgramStateOptimizer, node: mctree.BlockStatement | mctree.ForStatement): void;
3
+ export declare function cleanupUnusedVars(state: ProgramStateOptimizer, node: mctree.BlockStatement | mctree.ForStatement): boolean;
@@ -7,8 +7,8 @@ export declare function globSome(pattern: string, predicate: (path: string) => b
7
7
  }): Promise<boolean>;
8
8
  export declare function forEach<T>(val: T | T[] | null | undefined, fn: (v: T) => void): void;
9
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;
10
+ export declare function every<T>(val: T | T[] | null | undefined, fn: (v: T) => boolean): boolean;
11
+ export declare function some<T>(val: T | T[] | null | undefined, fn: (v: T) => boolean): boolean;
12
12
  export declare function reduce<T, U>(val: T | T[] | null | undefined, fn: (p: U, v: T) => U, init: U): U;
13
13
  export declare function last_modified(inputs: string[]): Promise<number>;
14
14
  export declare function first_modified(inputs: string[]): Promise<number>;
@@ -21,3 +21,4 @@ export declare function spawnByLine(command: string, args: string[], lineHandler
21
21
  export declare function readByLine(file: string, lineHandler: LineHandler): Promise<unknown>;
22
22
  export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T> | null, parallelism: number): Promise<T[]>;
23
23
  export declare function copyRecursiveAsNeeded(source: string, target: string, filter?: (src: string, tgt: string) => boolean): Promise<void>;
24
+ export declare function popcount(x: number): number;
@@ -1,4 +1,5 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
3
+ import { TypeMap } from "./type-flow/interp";
3
4
  export declare function visitorNode(node: mctree.Node): mctree.Node;
4
- 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): 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): void;
@@ -24,14 +24,7 @@ export declare const workerTaskHandlers: {
24
24
  program: string;
25
25
  product: string | null;
26
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;
27
+ diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
35
28
  }>;
36
29
  readonly generateOptimizedProject: (data: GenerateOptimizedProject["data"]) => Promise<{
37
30
  jungleFiles: string | undefined;
@@ -44,14 +37,7 @@ export declare const workerTaskHandlers: {
44
37
  xml: import("./xml-util").Document;
45
38
  program: string;
46
39
  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
- }[]>;
40
+ diagnostics: Record<string, import("./optimizer-types").Diagnostic[]>;
55
41
  }>;
56
42
  };
57
43
  declare type RemovePromise<T> = T extends Promise<infer U> ? U : T;
package/build/util.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 0 && (module.exports = {copyRecursiveAsNeeded,every,first_modified,forEach,globSome,globa,last_modified,map,promiseAll,pushUnique,readByLine,reduce,sameArrays,some,spawnByLine});
1
+ 0 && (module.exports = {copyRecursiveAsNeeded,every,first_modified,forEach,globSome,globa,last_modified,map,popcount,promiseAll,pushUnique,readByLine,reduce,sameArrays,some,spawnByLine});
2
2
  /******/ (() => { // webpackBootstrap
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
@@ -7720,6 +7720,7 @@ __webpack_require__.d(__webpack_exports__, {
7720
7720
  "globa": () => (/* binding */ globa),
7721
7721
  "last_modified": () => (/* binding */ last_modified),
7722
7722
  "map": () => (/* binding */ map),
7723
+ "popcount": () => (/* binding */ popcount),
7723
7724
  "promiseAll": () => (/* binding */ promiseAll),
7724
7725
  "pushUnique": () => (/* binding */ pushUnique),
7725
7726
  "readByLine": () => (/* binding */ readByLine),
@@ -7872,7 +7873,7 @@ function spawnByLine(command, args, lineHandlers, options) {
7872
7873
  rle.on("line", errHandler);
7873
7874
  rl.on("line", lineHandler);
7874
7875
  proc.on("close", (code) => {
7875
- if (code == 0)
7876
+ if (code === 0)
7876
7877
  resolve();
7877
7878
  reject(code);
7878
7879
  });
@@ -7944,6 +7945,14 @@ async function copyRecursiveAsNeeded(source, target, filter) {
7944
7945
  }
7945
7946
  }
7946
7947
  }
7948
+ function popcount(x) {
7949
+ x -= (x >> 1) & 0x55555555;
7950
+ x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
7951
+ x = (x + (x >> 4)) & 0x0f0f0f0f;
7952
+ x += x >> 8;
7953
+ x += x >> 16;
7954
+ return x & 0x7f;
7955
+ }
7947
7956
 
7948
7957
  })();
7949
7958
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.1.2",
4
+ "version": "1.1.4",
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.41"
43
+ "@markw65/prettier-plugin-monkeyc": "^1.0.42"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/chai": "^4.3.4",