@markw65/monkeyc-optimizer 1.1.32 → 1.1.34

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.
Files changed (81) hide show
  1. package/README.md +1 -918
  2. package/build/api.cjs +31 -31
  3. package/build/{chunk-NUE3G2QE.cjs → chunk-QBCVUVLD.cjs} +180 -49
  4. package/build/optimizer.cjs +17 -17
  5. package/build/sdk-util.cjs +14 -14
  6. package/build/src/api.d.ts +1 -1
  7. package/build/src/projects.d.ts +1 -0
  8. package/build/src/readprg.d.ts +0 -6
  9. package/build/src/src/api.d.ts +51 -0
  10. package/build/src/src/ast.d.ts +59 -0
  11. package/build/src/src/build.d.ts +7 -0
  12. package/build/src/src/cftinfo.d.ts +32 -0
  13. package/build/src/src/control-flow.d.ts +22 -0
  14. package/build/src/src/data-flow.d.ts +107 -0
  15. package/build/src/src/driver.d.ts +2 -0
  16. package/build/src/src/function-info.d.ts +14 -0
  17. package/build/src/src/inliner.d.ts +13 -0
  18. package/build/src/src/jungles.d.ts +66 -0
  19. package/build/src/src/launch.d.ts +5 -0
  20. package/build/src/src/logger.d.ts +6 -0
  21. package/build/src/src/manifest.d.ts +11 -0
  22. package/build/src/src/mc-rewrite.d.ts +13 -0
  23. package/build/src/src/negative-fixups.d.ts +1 -0
  24. package/build/src/src/optimizer-types.d.ts +249 -0
  25. package/build/src/src/optimizer.d.ts +100 -0
  26. package/build/src/src/pragma-checker.d.ts +3 -0
  27. package/build/src/src/pre.d.ts +2 -0
  28. package/build/src/src/projects.d.ts +26 -0
  29. package/build/src/src/readprg/array-init.d.ts +3 -0
  30. package/build/src/src/readprg/bytecode.d.ts +72 -0
  31. package/build/src/src/readprg/cflow.d.ts +17 -0
  32. package/build/src/src/readprg/data.d.ts +4 -0
  33. package/build/src/src/readprg/dce.d.ts +6 -0
  34. package/build/src/src/readprg/emit.d.ts +23 -0
  35. package/build/src/src/readprg/exceptions.d.ts +10 -0
  36. package/build/src/src/readprg/header.d.ts +15 -0
  37. package/build/src/src/readprg/interp.d.ts +21 -0
  38. package/build/src/src/readprg/linenum.d.ts +29 -0
  39. package/build/src/src/readprg/locals.d.ts +3 -0
  40. package/build/src/src/readprg/opcodes.d.ts +279 -0
  41. package/build/src/src/readprg/optimize.d.ts +3 -0
  42. package/build/src/src/readprg/pre.d.ts +2 -0
  43. package/build/src/src/readprg/sharing.d.ts +2 -0
  44. package/build/src/src/readprg/signer.d.ts +8 -0
  45. package/build/src/src/readprg/symbols.d.ts +19 -0
  46. package/build/src/src/readprg.d.ts +25 -0
  47. package/build/src/src/resources.d.ts +12 -0
  48. package/build/src/src/sdk-util.d.ts +28 -0
  49. package/build/src/src/type-flow/could-be.d.ts +5 -0
  50. package/build/src/src/type-flow/dead-store.d.ts +18 -0
  51. package/build/src/src/type-flow/interp-binary.d.ts +4 -0
  52. package/build/src/src/type-flow/interp-call.d.ts +16 -0
  53. package/build/src/src/type-flow/interp.d.ts +33 -0
  54. package/build/src/src/type-flow/intersection-type.d.ts +4 -0
  55. package/build/src/src/type-flow/minimize-locals.d.ts +4 -0
  56. package/build/src/src/type-flow/minimize-modules.d.ts +3 -0
  57. package/build/src/src/type-flow/optimize.d.ts +7 -0
  58. package/build/src/src/type-flow/sub-type.d.ts +2 -0
  59. package/build/src/src/type-flow/type-flow-util.d.ts +27 -0
  60. package/build/src/src/type-flow/types.d.ts +204 -0
  61. package/build/src/src/type-flow/union-type.d.ts +4 -0
  62. package/build/src/src/type-flow.d.ts +18 -0
  63. package/build/src/src/unused-exprs.d.ts +3 -0
  64. package/build/src/src/util.d.ts +33 -0
  65. package/build/src/src/variable-renamer.d.ts +4 -0
  66. package/build/src/src/visitor.d.ts +5 -0
  67. package/build/src/src/worker-pool.d.ts +4 -0
  68. package/build/src/src/worker-task.d.ts +88 -0
  69. package/build/src/src/worker-thread.d.ts +1 -0
  70. package/build/src/src/xml-util.d.ts +172 -0
  71. package/build/src/test/mocha/bytecode.spec.d.ts +1 -0
  72. package/build/src/test/mocha/coudbe.spec.d.ts +2 -0
  73. package/build/src/test/mocha/intersection.spec.d.ts +2 -0
  74. package/build/src/test/mocha/root.spec.d.ts +1 -0
  75. package/build/src/test/mocha/subtype.spec.d.ts +2 -0
  76. package/build/src/test/mocha/test-utils.d.ts +6 -0
  77. package/build/src/test/mocha/types.spec.d.ts +1 -0
  78. package/build/src/type-flow/interp.d.ts +3 -1
  79. package/build/src/type-flow/types.d.ts +1 -1
  80. package/build/worker-thread.cjs +3 -3
  81. package/package.json +2 -2
@@ -0,0 +1,172 @@
1
+ export declare class PeggyError extends Error {
2
+ location: SourceLocation | null | undefined;
3
+ constructor(message: string, location: SourceLocation | null | undefined);
4
+ }
5
+ export interface Position {
6
+ /** >= 0 */
7
+ offset: number;
8
+ /** >= 1 */
9
+ line: number;
10
+ /** >= 0 */
11
+ column: number;
12
+ }
13
+ export interface SourceLocation {
14
+ source?: string | null | undefined;
15
+ start: Position;
16
+ end: Position;
17
+ }
18
+ interface BaseNode {
19
+ type: string;
20
+ loc?: SourceLocation | null | undefined;
21
+ start?: number;
22
+ end?: number;
23
+ range?: [number, number] | undefined;
24
+ }
25
+ interface AttrStr extends BaseNode {
26
+ type: "attrstr";
27
+ value: string;
28
+ }
29
+ export interface Attribute extends BaseNode {
30
+ type: "attribute";
31
+ name: AttrStr;
32
+ value: AttrStr;
33
+ }
34
+ export interface CharData extends BaseNode {
35
+ type: "chardata";
36
+ value: string;
37
+ }
38
+ interface CharRef extends BaseNode {
39
+ type: "charref";
40
+ value: number;
41
+ base: 10 | 16;
42
+ }
43
+ interface Comment extends BaseNode {
44
+ type: "comment";
45
+ value: string;
46
+ }
47
+ interface DocTypeDecl extends BaseNode {
48
+ type: "doctypedecl";
49
+ name: string;
50
+ externalID?: ExternalID;
51
+ intSubset?: Array<MarkupDecl | PEReference>;
52
+ }
53
+ interface EntityDecl extends BaseNode {
54
+ type: "entitydecl";
55
+ name: string;
56
+ def: XValue;
57
+ kind: "&" | "%";
58
+ }
59
+ interface XValue extends BaseNode {
60
+ type: "entityvalue";
61
+ value?: Array<string | Reference | PEReference>;
62
+ extid?: System;
63
+ ndecl?: NData;
64
+ }
65
+ type Reference = CharRef | EntityRef;
66
+ type PEReference = PERef;
67
+ type SystemLiteral = string;
68
+ interface EntityRef extends BaseNode {
69
+ type: "entityref";
70
+ name: string;
71
+ }
72
+ interface PERef extends BaseNode {
73
+ type: "peref";
74
+ name: string;
75
+ }
76
+ interface NotationDecl extends BaseNode {
77
+ type: "notationdecl";
78
+ name: string;
79
+ id: ExternalID | PublicID;
80
+ }
81
+ interface PublicID extends BaseNode {
82
+ type: "publicid";
83
+ value: string;
84
+ }
85
+ interface NData extends BaseNode {
86
+ type: "ndata";
87
+ value: string;
88
+ }
89
+ type ExternalID = System | Public;
90
+ type MarkupDecl = EntityDecl | NotationDecl | PI | Comment;
91
+ interface System extends BaseNode {
92
+ type: "system";
93
+ value: SystemLiteral;
94
+ }
95
+ interface Public extends BaseNode {
96
+ type: "public";
97
+ value: SystemLiteral;
98
+ pubid: string;
99
+ }
100
+ export type Misc = Comment | PI | CharData;
101
+ export type Content = Element | Reference | CData | Misc;
102
+ export interface CData extends BaseNode {
103
+ type: "cdata";
104
+ value: string;
105
+ }
106
+ export interface PI extends BaseNode {
107
+ type: "pi";
108
+ name: string;
109
+ value: string | null;
110
+ }
111
+ export interface Element extends BaseNode {
112
+ type: "element";
113
+ name: string;
114
+ attr: Record<string, Attribute | undefined>;
115
+ children?: Array<Content> | undefined;
116
+ }
117
+ export interface Prolog extends BaseNode {
118
+ type: "prolog";
119
+ xmldecl?: XmlDecl;
120
+ misc1: Misc[];
121
+ doctypedecl?: DocTypeDecl;
122
+ misc2: Misc[];
123
+ }
124
+ interface XmlDecl extends BaseNode {
125
+ type: "xmldecl";
126
+ version: "1.0";
127
+ encoding?: string;
128
+ standalone?: string;
129
+ }
130
+ export declare class Document {
131
+ prolog: Prolog | null;
132
+ body: Nodes | Error;
133
+ misc: Array<Misc>;
134
+ source?: string | undefined;
135
+ data?: Record<string, unknown>;
136
+ private entities;
137
+ private pentities;
138
+ constructor(prolog: Prolog | null, body: Nodes | Error, misc: Array<Misc>, source?: string | undefined);
139
+ /**
140
+ * If all the children are chardata, charref or entityref,
141
+ * return the resulting string. Otherwise null.
142
+ */
143
+ textContent(element: Element): string | null;
144
+ processRefs(text: string): string;
145
+ }
146
+ export declare function elementKids(e: Element): Element[];
147
+ type ElementMatcher = string | ((c: Element) => boolean);
148
+ export declare class Nodes {
149
+ elements: Array<Element>;
150
+ constructor(elements: Element | Element[]);
151
+ length(): number;
152
+ deleteChildren(arg: ElementMatcher): void;
153
+ addChildren(elements: Element[]): void;
154
+ filter(arg: ElementMatcher): Nodes;
155
+ skip(name: string): Nodes;
156
+ children(name?: string): Nodes;
157
+ text(): string[];
158
+ attrs(): Record<string, Attribute | undefined>[];
159
+ }
160
+ export declare function attrString(value: string | AttrStr): AttrStr | {
161
+ readonly type: "attrstr";
162
+ readonly value: string;
163
+ };
164
+ export declare function makeAttribute(name: string | AttrStr, value: string | AttrStr): Attribute;
165
+ export declare function parseXml(content: string, fileName?: string | null): Document;
166
+ export declare function writeXml(doc: Document): string;
167
+ export type Visitor = {
168
+ pre?: (node: Content) => boolean | null | undefined | void;
169
+ post?: (node: Content) => void;
170
+ };
171
+ export declare function visit_xml(contents: Content[], visitor: Visitor): void;
172
+ export {};
@@ -0,0 +1 @@
1
+ export declare function bytecodeTests(): void;
@@ -0,0 +1,2 @@
1
+ import { ProgramStateAnalysis } from "../../src/optimizer-types";
2
+ export declare function couldBeTests(statefn: () => ProgramStateAnalysis | null): void;
@@ -0,0 +1,2 @@
1
+ import { ProgramStateAnalysis } from "../../src/optimizer-types";
2
+ export declare function intersectionTests(statefn: () => ProgramStateAnalysis | null): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ProgramStateAnalysis } from "../../src/optimizer-types";
2
+ export declare function subtypeOfTests(statefn: () => ProgramStateAnalysis | null): void;
@@ -0,0 +1,6 @@
1
+ import { BuildConfig, ProgramStateAnalysis, StateNodeDecl } from "../../src/optimizer-types";
2
+ import { ExactOrUnion } from "../../src/type-flow/types";
3
+ export declare function create_program_analysis(source: string, filename: string, config: BuildConfig): Promise<ProgramStateAnalysis>;
4
+ export declare function find_by_name(state: ProgramStateAnalysis, name: string): StateNodeDecl[];
5
+ export declare function find_type_by_name(state: ProgramStateAnalysis, name: string): ExactOrUnion;
6
+ export declare function assertNonNull<T>(obj: T, message?: string): asserts obj is NonNullable<T>;
@@ -0,0 +1 @@
1
+ export declare function typeTests(): void;
@@ -1,6 +1,6 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { DiagnosticType, FunctionStateNode, ProgramStateAnalysis } from "../optimizer-types";
3
- import { ExactOrUnion } from "./types";
3
+ import { ExactOrUnion, ObjectType } from "./types";
4
4
  export type TypeMap = Map<mctree.Node, ExactOrUnion>;
5
5
  export type InterpStackElem = {
6
6
  value: ExactOrUnion;
@@ -29,3 +29,5 @@ export declare function deEnumerate(t: ExactOrUnion): ExactOrUnion;
29
29
  export declare function evaluateNode(istate: InterpState, node: mctree.Node): void;
30
30
  export declare function roundToFloat(value: number): number;
31
31
  export declare function mustBeIdentical(a: ExactOrUnion, b: ExactOrUnion): boolean;
32
+ export declare function isByteArray(object: ExactOrUnion): boolean | undefined;
33
+ export declare function isByteArrayData(objectData: NonNullable<ObjectType["value"]>): boolean | undefined;
@@ -26,7 +26,7 @@ export declare const enum TypeTag {
26
26
  Typedef = 262144,
27
27
  Any = 524287
28
28
  }
29
- export declare function typeTagName(tag: TypeTag): "Never" | "Null" | "False" | "True" | "Boolean" | "Number" | "Long" | "Float" | "Double" | "Decimal" | "Numeric" | "Char" | "String" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Object" | "Enum" | "Symbol" | "Typedef" | "Any";
29
+ export declare function typeTagName(tag: TypeTag): "Symbol" | "Object" | "Number" | "Float" | "Double" | "Long" | "String" | "Char" | "Boolean" | "Null" | "Never" | "False" | "True" | "Decimal" | "Numeric" | "Array" | "Dictionary" | "Method" | "Module" | "Function" | "Class" | "Enum" | "Typedef" | "Any";
30
30
  export declare const LastTypeTag = TypeTag.Typedef;
31
31
  export declare const SingletonTypeTagsConst: number;
32
32
  export declare const UnionDataTypeTagsConst: number;
@@ -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_NUE3G2QE = require("./chunk-NUE3G2QE.cjs");
24
+ var import_chunk_QBCVUVLD = require("./chunk-QBCVUVLD.cjs");
25
25
  var import_chunk_PVBIKZYZ = require("./chunk-PVBIKZYZ.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.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_NUE3G2QE.init_worker_task)();
31
+ (0, import_chunk_QBCVUVLD.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_NUE3G2QE.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_QBCVUVLD.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.32",
4
+ "version": "1.1.34",
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",
@@ -48,7 +48,7 @@
48
48
  "author": "markw65",
49
49
  "license": "MIT",
50
50
  "dependencies": {
51
- "@markw65/prettier-plugin-monkeyc": "^1.0.49"
51
+ "@markw65/prettier-plugin-monkeyc": "^1.0.51"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/chai": "^4.3.4",