@markw65/monkeyc-optimizer 1.0.42 → 1.0.44

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,11 +1,11 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
- import { FunctionStateNode, ProgramStateAnalysis, ProgramStateLive } from "./optimizer-types";
2
+ import { FunctionStateNode, ProgramState, ProgramStateAnalysis } from "./optimizer-types";
3
3
  export declare function inlinableSubExpression(expr: mctree.Expression): mctree.SimpleCallExpression | null;
4
4
  export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): boolean;
5
5
  declare type InlineBody = mctree.BlockStatement | mctree.ExpressionStatement["expression"];
6
6
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"]): mctree.Statement[];
7
7
  export declare function unused(state: ProgramStateAnalysis, expression: mctree.ExpressionStatement["expression"], top: true): mctree.Statement[] | null;
8
- export declare function diagnostic(state: ProgramStateLive, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
8
+ export declare function diagnostic(state: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
9
9
  export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
10
10
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
11
11
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -32,6 +32,7 @@ export declare type BuildConfig = {
32
32
  sizeBasedPRE?: boolean | string;
33
33
  prettier?: Record<string, unknown>;
34
34
  extensionVersion?: string;
35
+ useLocalOptimizer?: boolean;
35
36
  };
36
37
  export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
37
38
  export declare type StateNodeDecls = {
@@ -1,13 +1,12 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { JungleResourceMap } from "./jungles";
3
+ import { ProgramState } from "./optimizer-types";
3
4
  import { xmlUtil } from "./sdk-util";
4
5
  declare type Visit = (e: xmlUtil.Element, module: string | null, parent: xmlUtil.Element | null) => void;
5
6
  declare type Visitor = {
6
7
  visit?: Visit;
7
8
  error?: (node: xmlUtil.Element, parent: string | null) => void;
8
- pre?: (node: xmlUtil.Content) => boolean | null | undefined | void;
9
- post?: (node: xmlUtil.Content) => void;
10
- };
9
+ } & xmlUtil.Visitor;
11
10
  export declare function visit_resources(elements: xmlUtil.Content[], parent: xmlUtil.Element | null, v: Visitor | Visit): void;
12
- export declare function add_resources_to_ast(ast: mctree.Program, resources: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): void;
11
+ export declare function add_resources_to_ast(state: ProgramState | undefined, ast: mctree.Program, resources: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): void;
13
12
  export {};
@@ -0,0 +1,4 @@
1
+ import type { WorkerTask, WorkerTaskResult } from "./worker-task";
2
+ export declare function startPool(): void;
3
+ export declare function stopPool(): void;
4
+ export declare function runTaskInPool<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
@@ -0,0 +1,29 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ interface BaseNode {
3
+ type: string;
4
+ data: unknown;
5
+ }
6
+ interface ParserData extends BaseNode {
7
+ data: {
8
+ source: string;
9
+ options?: Record<string, unknown>;
10
+ };
11
+ }
12
+ interface JungleParserTask extends ParserData {
13
+ type: "parseJungle";
14
+ }
15
+ interface MonkeyCParserTask extends ParserData {
16
+ type: "parseMonkeyC";
17
+ }
18
+ interface XmlParserTask extends ParserData {
19
+ type: "parseXml";
20
+ }
21
+ export declare type WorkerTask = JungleParserTask | MonkeyCParserTask | XmlParserTask;
22
+ export declare const workerTaskHandlers: {
23
+ readonly parseJungle: (data: JungleParserTask["data"]) => Assignment[];
24
+ readonly parseMonkeyC: (data: MonkeyCParserTask["data"]) => mctree.Program;
25
+ readonly parseXml: (data: XmlParserTask["data"]) => ParserResult;
26
+ };
27
+ export declare type WorkerTaskResult<T> = T extends WorkerTask ? ReturnType<typeof workerTaskHandlers[T["type"]]> : never;
28
+ export declare function performTask<T extends WorkerTask>(task: T): WorkerTaskResult<T>;
29
+ export {};
@@ -1,4 +1,3 @@
1
- import { xmlUtil } from "./sdk-util.js";
2
1
  export declare class PeggyError extends Error {
3
2
  location: SourceLocation | null | undefined;
4
3
  constructor(message: string, location: SourceLocation | null | undefined);
@@ -134,9 +133,17 @@ export declare class Document {
134
133
  misc: Array<Misc>;
135
134
  source?: string | undefined;
136
135
  data?: Record<string, unknown>;
136
+ private entities;
137
+ private pentities;
137
138
  constructor(prolog: Prolog | null, body: Nodes | Error, misc: Array<Misc>, source?: string | undefined);
138
- }
139
- export declare function elementKids(e: Element): xmlUtil.Element[];
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[];
140
147
  declare type ElementMatcher = string | ((c: Element) => boolean);
141
148
  export declare class Nodes {
142
149
  elements: Array<Element>;
@@ -144,11 +151,11 @@ export declare class Nodes {
144
151
  length(): number;
145
152
  deleteChildren(arg: ElementMatcher): void;
146
153
  addChildren(elements: Element[]): void;
147
- filter(arg: ElementMatcher): xmlUtil.Nodes;
148
- skip(name: string): xmlUtil.Nodes;
149
- children(name?: string): xmlUtil.Nodes;
154
+ filter(arg: ElementMatcher): Nodes;
155
+ skip(name: string): Nodes;
156
+ children(name?: string): Nodes;
150
157
  text(): string[];
151
- attrs(): Record<string, xmlUtil.Attribute | undefined>[];
158
+ attrs(): Record<string, Attribute | undefined>[];
152
159
  }
153
160
  export declare function attrString(value: string | AttrStr): AttrStr | {
154
161
  readonly type: "attrstr";
@@ -157,4 +164,9 @@ export declare function attrString(value: string | AttrStr): AttrStr | {
157
164
  export declare function makeAttribute(name: string | AttrStr, value: string | AttrStr): Attribute;
158
165
  export declare function parseXml(content: string, fileName?: string | null): Document;
159
166
  export declare function writeXml(doc: Document): string;
167
+ export declare 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;
160
172
  export {};
package/build/util.cjs CHANGED
@@ -7756,7 +7756,7 @@ function globa(pattern, options) {
7756
7756
  }
7757
7757
  function globSome(pattern, predicate, options) {
7758
7758
  return new Promise((resolve, _reject) => {
7759
- const stream = out.stream(pattern, options || {});
7759
+ const stream = out.stream(pattern.replace(/\\/g, "/"), options || {});
7760
7760
  let result = false;
7761
7761
  const resolver = () => {
7762
7762
  resolve(result);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.42",
4
+ "version": "1.0.44",
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",
@@ -38,7 +38,7 @@
38
38
  "author": "markw65",
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
- "@markw65/prettier-plugin-monkeyc": "^1.0.38"
41
+ "@markw65/prettier-plugin-monkeyc": "^1.0.40"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/glob": "^8.0.0",
@@ -1,324 +0,0 @@
1
- declare type InclusiveUnionKeys<U> = U extends unknown ? keyof U : never;
2
- declare type InclusiveUnion<U> = {
3
- [K in InclusiveUnionKeys<U>]: U extends any ? K extends keyof U ? U[K] : never : never;
4
- };
5
- declare type SubfieldsOfType<T, U> = {
6
- [K in keyof T as T[K] extends U ? K : never]: T[K];
7
- };
8
- export declare type NodeAll = InclusiveUnion<Node>;
9
- export declare type NodeSubFields = SubfieldsOfType<NodeAll, Node>;
10
- export declare type NodeSubArrays = SubfieldsOfType<NodeAll, Node[]>;
11
- interface BaseNode {
12
- type: string;
13
- loc?: SourceLocation | null | undefined;
14
- start?: number;
15
- end?: number;
16
- range?: [number, number] | undefined;
17
- }
18
- export declare type Node = Identifier | Literal | Program | SwitchCase | CatchClause | VariableDeclarator | EnumStringBody | EnumStringMember | Statement | Expression | Property | Declaration | ImportStatement | AsTypeSpec | TypeSpecList | ClassElement | ClassBody | Comment;
19
- export interface Comment extends BaseNode {
20
- type: "Line" | "Block";
21
- value: string;
22
- }
23
- interface SourceLocation {
24
- source?: string | null | undefined;
25
- start: Position;
26
- end: Position;
27
- }
28
- export interface Position {
29
- /** >= 1 */
30
- line: number;
31
- /** >= 0 */
32
- column: number;
33
- }
34
- export interface Program extends BaseNode {
35
- type: "Program";
36
- body: Array<Declaration | ImportStatement>;
37
- comments?: Array<Comment> | undefined;
38
- }
39
- export interface ModuleDeclaration extends BaseDeclaration {
40
- type: "ModuleDeclaration";
41
- body: Array<Declaration | ImportStatement>;
42
- id: Identifier;
43
- }
44
- interface BaseFunction extends BaseNode {
45
- params: Array<Identifier | AsExpression>;
46
- body: BlockStatement;
47
- }
48
- export declare type Statement = ExpressionStatement | BlockStatement | ReturnStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | Declaration;
49
- interface BaseStatement extends BaseNode {
50
- }
51
- export interface BlockStatement extends BaseStatement {
52
- type: "BlockStatement";
53
- body: Array<Statement>;
54
- innerComments?: Array<Comment> | undefined;
55
- }
56
- export interface ExpressionStatement extends BaseStatement {
57
- type: "ExpressionStatement";
58
- expression: Expression;
59
- }
60
- export interface IfStatement extends BaseStatement {
61
- type: "IfStatement";
62
- test: Expression;
63
- consequent: Statement;
64
- alternate?: Statement | null | undefined;
65
- }
66
- export interface BreakStatement extends BaseStatement {
67
- type: "BreakStatement";
68
- }
69
- export interface ContinueStatement extends BaseStatement {
70
- type: "ContinueStatement";
71
- }
72
- export interface SwitchStatement extends BaseStatement {
73
- type: "SwitchStatement";
74
- discriminant: Expression;
75
- cases: Array<SwitchCase>;
76
- }
77
- export interface ReturnStatement extends BaseStatement {
78
- type: "ReturnStatement";
79
- argument?: Expression | null | undefined;
80
- }
81
- export interface ThrowStatement extends BaseStatement {
82
- type: "ThrowStatement";
83
- argument: Expression;
84
- }
85
- export interface TryStatement extends BaseStatement {
86
- type: "TryStatement";
87
- block: BlockStatement;
88
- handler?: CatchClause | CatchClauses | null | undefined;
89
- finalizer?: BlockStatement | null | undefined;
90
- }
91
- export interface WhileStatement extends BaseStatement {
92
- type: "WhileStatement";
93
- test: Expression;
94
- body: Statement;
95
- }
96
- export interface DoWhileStatement extends BaseStatement {
97
- type: "DoWhileStatement";
98
- body: Statement;
99
- test: Expression;
100
- }
101
- export interface ForStatement extends BaseStatement {
102
- type: "ForStatement";
103
- init?: VariableDeclaration | Expression | null | undefined;
104
- test?: Expression | null | undefined;
105
- update?: Expression | null | undefined;
106
- body: Statement;
107
- }
108
- export declare type Declaration = ClassDeclaration | EnumDeclaration | FunctionDeclaration | ModuleDeclaration | TypedefDeclaration | VariableDeclaration;
109
- interface BaseDeclaration extends BaseStatement {
110
- attrs?: AttributeList;
111
- }
112
- export interface FunctionDeclaration extends BaseFunction, BaseDeclaration {
113
- type: "FunctionDeclaration";
114
- id: Identifier;
115
- body: BlockStatement;
116
- optimizable?: boolean;
117
- hasOverride?: boolean;
118
- }
119
- export interface VariableDeclaration extends BaseDeclaration {
120
- type: "VariableDeclaration";
121
- declarations: Array<VariableDeclarator>;
122
- kind: "var" | "const";
123
- }
124
- export interface VariableDeclarator extends BaseNode {
125
- type: "VariableDeclarator";
126
- id: Identifier | AsExpression;
127
- init?: Expression | null | undefined;
128
- kind: "var" | "const";
129
- }
130
- declare type Expression = ThisExpression | ArrayExpression | ObjectExpression | Literal | UnaryExpression | UpdateExpression | BinaryExpression | AsExpression | AssignmentExpression | LogicalExpression | MemberExpression | ConditionalExpression | CallExpression | NewExpression | SequenceExpression | Identifier;
131
- export interface BaseExpression extends BaseNode {
132
- enumType?: string | Node;
133
- }
134
- export interface ThisExpression extends BaseExpression {
135
- type: "ThisExpression";
136
- text: string;
137
- }
138
- export interface ArrayExpression extends BaseExpression {
139
- type: "ArrayExpression";
140
- elements: Array<Expression>;
141
- }
142
- export interface ObjectExpression extends BaseExpression {
143
- type: "ObjectExpression";
144
- properties: Array<Property>;
145
- }
146
- export interface Property extends BaseNode {
147
- type: "Property";
148
- key: Expression;
149
- value: Expression;
150
- kind: "init";
151
- }
152
- export interface SequenceExpression extends BaseExpression {
153
- type: "SequenceExpression";
154
- expressions: Array<Expression>;
155
- }
156
- interface BaseUnaryExpression extends BaseExpression {
157
- type: "UnaryExpression";
158
- prefix: true;
159
- }
160
- interface TrueUnaryExpression extends BaseUnaryExpression {
161
- operator: UnaryOperator;
162
- argument: Expression;
163
- }
164
- interface SymbolExpression extends BaseUnaryExpression {
165
- operator: ":";
166
- argument: Identifier;
167
- }
168
- export declare type UnaryExpression = TrueUnaryExpression | SymbolExpression;
169
- export interface BinaryExpression extends BaseExpression {
170
- type: "BinaryExpression";
171
- operator: BinaryOperator;
172
- left: Expression;
173
- right: Expression;
174
- }
175
- export interface AsExpression extends BaseExpression {
176
- type: "BinaryExpression";
177
- operator: "as";
178
- left: Expression;
179
- right: TypeSpecList;
180
- }
181
- export interface AssignmentExpression extends BaseExpression {
182
- type: "AssignmentExpression";
183
- operator: AssignmentOperator;
184
- left: Identifier | MemberExpression;
185
- right: Expression;
186
- }
187
- export interface UpdateExpression extends BaseExpression {
188
- type: "UpdateExpression";
189
- operator: UpdateOperator;
190
- argument: Expression;
191
- prefix: boolean;
192
- }
193
- export interface LogicalExpression extends BaseExpression {
194
- type: "LogicalExpression";
195
- operator: LogicalOperator;
196
- left: Expression;
197
- right: Expression;
198
- }
199
- export interface ConditionalExpression extends BaseExpression {
200
- type: "ConditionalExpression";
201
- test: Expression;
202
- alternate: Expression;
203
- consequent: Expression;
204
- }
205
- interface BaseCallExpression extends BaseExpression {
206
- callee: Expression;
207
- arguments: Array<Expression>;
208
- }
209
- export declare type CallExpression = SimpleCallExpression | NewExpression;
210
- export interface SimpleCallExpression extends BaseCallExpression {
211
- type: "CallExpression";
212
- }
213
- export interface NewExpression extends BaseCallExpression {
214
- type: "NewExpression";
215
- }
216
- export interface MemberExpression extends BaseExpression {
217
- type: "MemberExpression";
218
- object: Expression;
219
- property: Expression;
220
- computed: boolean;
221
- }
222
- export interface SwitchCase extends BaseNode {
223
- type: "SwitchCase";
224
- test?: Expression | null | undefined;
225
- consequent: Array<Statement>;
226
- }
227
- export interface CatchClause extends BaseNode {
228
- type: "CatchClause";
229
- param: Identifier | null;
230
- body: BlockStatement;
231
- }
232
- export interface CatchClauses extends BaseNode {
233
- type: "CatchClauses";
234
- catches: CatchClause[];
235
- }
236
- export interface Identifier extends BaseNode, BaseExpression {
237
- type: "Identifier";
238
- name: string;
239
- }
240
- export interface Literal extends BaseNode, BaseExpression {
241
- type: "Literal";
242
- value: string | boolean | number | null;
243
- raw?: string | undefined;
244
- }
245
- export declare type UnaryOperator = "-" | "+" | "!" | "~" | " as";
246
- export declare type BinaryOperator = "==" | "!=" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "has" | "instanceof";
247
- export declare type LogicalOperator = "||" | "&&";
248
- export declare type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | "|=" | "^=" | "&=";
249
- export declare type UpdateOperator = "++" | "--";
250
- export interface ClassDeclaration extends BaseDeclaration {
251
- type: "ClassDeclaration";
252
- id: Identifier;
253
- superClass?: Expression | null | undefined;
254
- body: ClassBody;
255
- }
256
- export interface ClassBody extends BaseStatement {
257
- type: "ClassBody";
258
- body: Array<ClassElement>;
259
- }
260
- export interface ClassElement extends BaseStatement {
261
- type: "ClassElement";
262
- item: Omit<Declaration, "ModuleDeclaration">;
263
- }
264
- export interface EnumDeclaration extends BaseDeclaration {
265
- type: "EnumDeclaration";
266
- id?: Identifier | null;
267
- body: EnumStringBody;
268
- }
269
- export interface EnumStringBody extends BaseNode {
270
- type: "EnumStringBody";
271
- members: Array<EnumStringMember | Identifier>;
272
- enumType?: string | Node;
273
- }
274
- export interface EnumStringMember extends BaseNode {
275
- type: "EnumStringMember";
276
- id: Identifier;
277
- init: Expression;
278
- enumType?: string | Node;
279
- }
280
- export interface TypedefDeclaration extends BaseDeclaration {
281
- type: "TypedefDeclaration";
282
- id: Identifier;
283
- ts: AsTypeSpec;
284
- }
285
- export interface AsTypeSpec extends Omit<UnaryExpression, "operator" | "argument"> {
286
- operator: " as";
287
- argument: TypeSpecList;
288
- }
289
- export interface TypeSpecList extends BaseNode {
290
- type: "TypeSpecList";
291
- ts: Array<TypeSpecPart>;
292
- }
293
- export interface TypeSpecPart extends BaseNode {
294
- type: "TypeSpecPart";
295
- name: Identifier | MemberExpression;
296
- body?: BlockStatement;
297
- callspec?: MethodDefinition;
298
- generics?: Array<TypeSpecList>;
299
- }
300
- export interface MethodDefinition extends BaseNode {
301
- type: "MethodDefinition";
302
- kind: "method";
303
- key: "";
304
- params: Array<Identifier | AsExpression>;
305
- returnType: AsTypeSpec;
306
- }
307
- export declare type AccessSpecifier = "static" | "private" | "protected" | "hidden" | "public";
308
- export interface AttributeList extends BaseNode {
309
- type: "AttributeList";
310
- attrs?: Attribute[];
311
- access?: AccessSpecifier[];
312
- }
313
- declare type Attribute = SymbolExpression | CallExpression;
314
- export declare type ImportStatement = ImportModule | Using;
315
- export interface ImportModule extends BaseNode {
316
- type: "ImportModule";
317
- id: MemberExpression;
318
- }
319
- export interface Using extends BaseNode {
320
- type: "Using";
321
- id: MemberExpression;
322
- as: Identifier;
323
- }
324
- export {};