@markw65/monkeyc-optimizer 1.0.45 → 1.1.0
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.
- package/README.md +28 -0
- package/build/api.cjs +448 -4794
- package/build/optimizer.cjs +3243 -690
- package/build/sdk-util.cjs +22 -2
- package/build/src/api.d.ts +5 -3
- package/build/src/ast.d.ts +1 -0
- package/build/src/control-flow.d.ts +1 -1
- package/build/src/data-flow.d.ts +1 -1
- package/build/src/inliner.d.ts +1 -2
- package/build/src/mc-rewrite.d.ts +1 -2
- package/build/src/optimizer-types.d.ts +11 -2
- package/build/src/type-flow.d.ts +0 -1
- package/build/src/worker-pool.d.ts +1 -1
- package/build/src/worker-task.d.ts +49 -18
- package/build/src/worker-thread.d.ts +1 -0
- package/package.json +7 -2
- package/build/src/interp-binary.d.ts +0 -4
- package/build/src/interp-call.d.ts +0 -3
- package/build/src/interp.d.ts +0 -23
- package/build/src/mc-types.d.ts +0 -166
package/build/sdk-util.cjs
CHANGED
|
@@ -237,8 +237,6 @@ function mayThrow(node) {
|
|
|
237
237
|
switch (node.type) {
|
|
238
238
|
case "BinaryExpression":
|
|
239
239
|
case "CallExpression":
|
|
240
|
-
case "ConditionalExpression":
|
|
241
|
-
case "LogicalExpression":
|
|
242
240
|
case "NewExpression":
|
|
243
241
|
case "ThrowStatement":
|
|
244
242
|
case "UnaryExpression":
|
|
@@ -383,6 +381,28 @@ function makeScopedName(dotted, l) {
|
|
|
383
381
|
throw new Error("Failed to make a ScopedName");
|
|
384
382
|
return result;
|
|
385
383
|
}
|
|
384
|
+
function getLiteralNode(node) {
|
|
385
|
+
if (node == null)
|
|
386
|
+
return null;
|
|
387
|
+
if (node.type == "Literal")
|
|
388
|
+
return node;
|
|
389
|
+
if (node.type == "BinaryExpression" && node.operator == "as") {
|
|
390
|
+
return getLiteralNode(node.left) && node;
|
|
391
|
+
}
|
|
392
|
+
if (node.type == "UnaryExpression") {
|
|
393
|
+
if (node.argument.type != "Literal")
|
|
394
|
+
return null;
|
|
395
|
+
switch (node.operator) {
|
|
396
|
+
case "-": {
|
|
397
|
+
const [arg, type] = getNodeValue(node.argument);
|
|
398
|
+
if (type === "Number" || type === "Long") {
|
|
399
|
+
return { ...arg, value: -arg.value, raw: `-${arg.raw}` };
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
386
406
|
|
|
387
407
|
;// CONCATENATED MODULE: ./src/xml-util.ts
|
|
388
408
|
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { hasProperty, traverseAst } from "./ast";
|
|
3
3
|
import { JungleResourceMap } from "./jungles";
|
|
4
|
-
import { FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
4
|
+
import { ClassStateNode, FunctionInfo, FunctionStateNode, LookupDefinition, ModuleStateNode, ProgramState, ProgramStateAnalysis, ProgramStateLive, ProgramStateNode, ProgramStateStack, StateNode, StateNodeDecl, VariableStateNode } from "./optimizer-types";
|
|
5
5
|
import { visit_resources } from "./resources";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
7
|
export { visitorNode, visitReferences } from "./visitor";
|
|
@@ -22,6 +22,8 @@ export declare function findUsingForNode(state: ProgramStateLive, stack: Program
|
|
|
22
22
|
results: StateNodeDecl[];
|
|
23
23
|
};
|
|
24
24
|
}[] | null;
|
|
25
|
-
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo | false;
|
|
26
|
-
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
|
25
|
+
export declare function getApiFunctionInfo(state: ProgramState, func: FunctionStateNode): FunctionInfo | false;
|
|
26
|
+
export declare function markInvokeClassMethod(state: ProgramStateAnalysis, func: FunctionStateNode): void;
|
|
27
27
|
export declare function isLocal(v: VariableStateNode): boolean;
|
|
28
|
+
export declare function diagnostic(state: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
|
|
29
|
+
export declare function getSuperClasses(klass: ClassStateNode): Set<ClassStateNode> | null;
|
package/build/src/ast.d.ts
CHANGED
|
@@ -55,4 +55,5 @@ export declare function makeIdentifier(name: string, loc?: mctree.SourceLocation
|
|
|
55
55
|
};
|
|
56
56
|
export declare function makeMemberExpression(object: mctree.ScopedName, property: mctree.Identifier): mctree.DottedName;
|
|
57
57
|
export declare function makeScopedName(dotted: string, l?: mctree.SourceLocation): mctree.ScopedName;
|
|
58
|
+
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
58
59
|
export {};
|
|
@@ -13,7 +13,7 @@ export declare type Block<T extends EventConstraint<T>> = {
|
|
|
13
13
|
exsucc?: Block<T>;
|
|
14
14
|
events?: T[];
|
|
15
15
|
};
|
|
16
|
-
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean) => T | null): Block<T>;
|
|
16
|
+
export declare function buildReducedGraph<T extends EventConstraint<T>>(state: ProgramStateAnalysis, func: FunctionStateNode, notice: (node: mctree.Node, stmt: mctree.Node, mayThrow: boolean | 1) => T | null): Block<T>;
|
|
17
17
|
export declare function postOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
18
18
|
export declare function preOrderTraverse<T extends EventConstraint<T>>(head: Block<T>, visitor: (block: Block<T>) => void): void;
|
|
19
19
|
export declare function getPostOrder<T extends EventConstraint<T>>(head: Block<T>): Block<T>[];
|
package/build/src/data-flow.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface DataFlowBlock extends Block<Event> {
|
|
|
31
31
|
}
|
|
32
32
|
export declare function declFullName(decl: EventDecl): string | undefined;
|
|
33
33
|
export declare function declName(decl: EventDecl): string | undefined;
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function unhandledType(node: never): never;
|
|
35
35
|
export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: FunctionStateNode, wantsLiteral: (literal: mctree.Literal) => boolean, trackInsertionPoints: boolean, wantsAllRefs: boolean): {
|
|
36
36
|
identifiers: Set<string>;
|
|
37
37
|
graph: Block<RefEvent | DefEvent | ModEvent | ExnEvent>;
|
package/build/src/inliner.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { FunctionStateNode,
|
|
2
|
+
import { FunctionStateNode, 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: ProgramState, loc: mctree.Node["loc"], message: string | null, type?: NonNullable<ProgramStateAnalysis["diagnostics"]>[string][number]["type"]): void;
|
|
9
8
|
export declare type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
|
|
10
9
|
export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
|
|
11
10
|
export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
|
|
@@ -4,10 +4,9 @@ import { BuildConfig, FilesToOptimizeMap, LookupDefinition, ProgramStateAnalysis
|
|
|
4
4
|
import { xmlUtil } from "./sdk-util";
|
|
5
5
|
export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
|
|
6
6
|
export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
|
|
7
|
-
export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
7
|
+
export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig): Promise<ProgramStateAnalysis>;
|
|
8
8
|
export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
|
|
9
9
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
10
|
-
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
11
10
|
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<Record<string, {
|
|
12
11
|
type: import("./optimizer-types").DiagnosticType;
|
|
13
12
|
loc: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { EnumStringMember } from "@markw65/prettier-plugin-monkeyc/build/estree-types";
|
|
3
3
|
import { xmlUtil } from "./sdk-util";
|
|
4
|
+
import { ExactOrUnion } from "./type-flow/types";
|
|
4
5
|
export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
5
6
|
export declare type LookupRules = "COMPILER1" | "COMPILER2" | "DEFAULT";
|
|
6
7
|
export declare type EnforceStatic = "YES" | "NO";
|
|
@@ -34,6 +35,9 @@ export declare type BuildConfig = {
|
|
|
34
35
|
prettier?: Record<string, unknown>;
|
|
35
36
|
extensionVersion?: string;
|
|
36
37
|
useLocalOptimizer?: boolean;
|
|
38
|
+
propagateTypes?: boolean;
|
|
39
|
+
trustDeclaredTypes?: boolean;
|
|
40
|
+
checkTypes?: DiagnosticType | "OFF";
|
|
37
41
|
};
|
|
38
42
|
export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier;
|
|
39
43
|
export declare type StateNodeDecls = {
|
|
@@ -81,6 +85,7 @@ export interface ClassStateNode extends BaseStateNode {
|
|
|
81
85
|
fullName: string;
|
|
82
86
|
superClass?: ClassStateNode[] | true;
|
|
83
87
|
hasInvoke?: boolean;
|
|
88
|
+
superClasses?: Set<ClassStateNode>;
|
|
84
89
|
}
|
|
85
90
|
export declare type FunctionInfo = {
|
|
86
91
|
modifiedDecls: Set<VariableStateNode>;
|
|
@@ -112,6 +117,9 @@ export interface TypedefStateNode extends BaseStateNode {
|
|
|
112
117
|
node: mctree.TypedefDeclaration;
|
|
113
118
|
name: string;
|
|
114
119
|
fullName: string;
|
|
120
|
+
isExpanding?: true;
|
|
121
|
+
isRecursive?: true;
|
|
122
|
+
resolvedType?: ExactOrUnion;
|
|
115
123
|
}
|
|
116
124
|
export interface VariableStateNode extends BaseStateNode {
|
|
117
125
|
type: "VariableDeclarator";
|
|
@@ -138,6 +146,7 @@ export declare type LookupResult = [string, LookupDefinition[]] | [null, null] |
|
|
|
138
146
|
export declare type ProgramState = {
|
|
139
147
|
allFunctions?: Record<string, FunctionStateNode[]>;
|
|
140
148
|
allClasses?: ClassStateNode[];
|
|
149
|
+
invokeInfo?: FunctionInfo;
|
|
141
150
|
fnMap?: FilesToOptimizeMap;
|
|
142
151
|
rezAst?: mctree.Program;
|
|
143
152
|
manifestXML?: xmlUtil.Document;
|
|
@@ -190,11 +199,11 @@ export declare type ProgramState = {
|
|
|
190
199
|
}[]>;
|
|
191
200
|
enumMap?: Map<EnumStringMember, EnumStateNode>;
|
|
192
201
|
};
|
|
193
|
-
declare type Finalized<T, Keys extends keyof T> = T & {
|
|
202
|
+
export declare type Finalized<T, Keys extends keyof T> = T & {
|
|
194
203
|
[key in Keys]-?: NonNullable<T[key]>;
|
|
195
204
|
};
|
|
196
205
|
export declare type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
|
|
197
|
-
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
|
|
206
|
+
export declare type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap" | "invokeInfo">;
|
|
198
207
|
export declare type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
|
|
199
208
|
export declare type ExcludeAnnotationsMap = {
|
|
200
209
|
[key: string]: boolean;
|
package/build/src/type-flow.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
2
2
|
import { InterpState } from "./type-flow/interp";
|
|
3
|
-
export declare const missingNullWorkaround = true;
|
|
4
3
|
export declare function buildTypeInfo(state: ProgramStateAnalysis, func: FunctionStateNode): InterpState | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { WorkerTask, WorkerTaskResult } from "./worker-task";
|
|
2
|
-
export declare function startPool(): void;
|
|
2
|
+
export declare function startPool(parallelism?: number): void;
|
|
3
3
|
export declare function stopPool(): void;
|
|
4
4
|
export declare function runTaskInPool<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
|
|
@@ -1,29 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuildConfig } from "./optimizer";
|
|
2
2
|
interface BaseNode {
|
|
3
3
|
type: string;
|
|
4
4
|
data: unknown;
|
|
5
5
|
}
|
|
6
|
-
interface
|
|
6
|
+
interface BuildOptimizedProject extends BaseNode {
|
|
7
|
+
type: "buildOptimizedProject";
|
|
7
8
|
data: {
|
|
8
|
-
|
|
9
|
-
options
|
|
9
|
+
product: string | null;
|
|
10
|
+
options: BuildConfig;
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
interface
|
|
13
|
-
type: "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
interface XmlParserTask extends ParserData {
|
|
19
|
-
type: "parseXml";
|
|
13
|
+
interface GenerateOptimizedProject extends BaseNode {
|
|
14
|
+
type: "generateOptimizedProject";
|
|
15
|
+
data: {
|
|
16
|
+
options: BuildConfig;
|
|
17
|
+
};
|
|
20
18
|
}
|
|
21
|
-
export declare type WorkerTask =
|
|
19
|
+
export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject;
|
|
22
20
|
export declare const workerTaskHandlers: {
|
|
23
|
-
readonly
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
readonly buildOptimizedProject: (data: BuildOptimizedProject["data"]) => Promise<{
|
|
22
|
+
exe: string;
|
|
23
|
+
args: string[];
|
|
24
|
+
program: string;
|
|
25
|
+
product: string | null;
|
|
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;
|
|
35
|
+
}>;
|
|
36
|
+
readonly generateOptimizedProject: (data: GenerateOptimizedProject["data"]) => Promise<{
|
|
37
|
+
jungleFiles: string | undefined;
|
|
38
|
+
xml: import("./xml-util").Document;
|
|
39
|
+
program: string;
|
|
40
|
+
hasTests: boolean;
|
|
41
|
+
diagnostics?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
jungleFiles: string;
|
|
44
|
+
xml: import("./xml-util").Document;
|
|
45
|
+
program: string;
|
|
46
|
+
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
|
+
}[]>;
|
|
55
|
+
}>;
|
|
26
56
|
};
|
|
27
|
-
|
|
28
|
-
export declare
|
|
57
|
+
declare type RemovePromise<T> = T extends Promise<infer U> ? U : T;
|
|
58
|
+
export declare type WorkerTaskResult<T> = T extends WorkerTask ? RemovePromise<ReturnType<typeof workerTaskHandlers[T["type"]]>> : never;
|
|
59
|
+
export declare function performTask<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
|
|
29
60
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"build-debug": "webpack --mode development",
|
|
22
22
|
"build-release": "webpack --mode production",
|
|
23
23
|
"prepack": "webpack --mode production",
|
|
24
|
-
"test": "npm run test-optimized && npm run test-unopt && npm run test-remote && npm run test-remote-tests",
|
|
24
|
+
"test": "npm run test-mocha && npm run test-optimized && npm run test-unopt && npm run test-remote && npm run test-remote-tests",
|
|
25
|
+
"test-mocha": "npx mocha --timeout 999999 build/mocha.cjs",
|
|
25
26
|
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
26
27
|
"test-remote-tests": "node ./test/test.js --product=pick-one --run-tests --github",
|
|
27
28
|
"test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
@@ -42,14 +43,18 @@
|
|
|
42
43
|
"@markw65/prettier-plugin-monkeyc": "^1.0.41"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@types/chai": "^4.3.4",
|
|
45
47
|
"@types/glob": "^8.0.0",
|
|
48
|
+
"@types/mocha": "^10.0.1",
|
|
46
49
|
"@types/prettier": "^2.6.1",
|
|
47
50
|
"@types/priorityqueuejs": "^1.0.1",
|
|
48
51
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
49
52
|
"@typescript-eslint/parser": "^5.28.0",
|
|
53
|
+
"chai": "^4.3.7",
|
|
50
54
|
"eslint": "^8.12.0",
|
|
51
55
|
"extract-zip": "^2.0.1",
|
|
52
56
|
"fast-glob": "^3.2.12",
|
|
57
|
+
"mocha": "^10.2.0",
|
|
53
58
|
"peggy": "^2.0.1",
|
|
54
59
|
"prettier": "^2.6.2",
|
|
55
60
|
"prettier-plugin-pegjs": "https://github.com/markw65/prettier-plugin-pegjs/releases/download/v0.5.2/prettier-plugin-pegjs-0.5.2.tgz",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { ExactOrUnion } from "./mc-types";
|
|
3
|
-
export declare function evaluateBinaryTypes(op: mctree.BinaryOperator | "instanceof", left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
|
|
4
|
-
export declare function evaluateLogicalTypes(op: mctree.LogicalOperator, left: ExactOrUnion, right: ExactOrUnion): ExactOrUnion;
|
package/build/src/interp.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { ExactOrUnion } from "./type-flow/types";
|
|
3
|
-
import { FunctionStateNode, ProgramStateAnalysis } from "./optimizer-types";
|
|
4
|
-
export declare type TypeMap = Map<mctree.Node, ExactOrUnion>;
|
|
5
|
-
export declare type InterpStackElem = {
|
|
6
|
-
value: ExactOrUnion;
|
|
7
|
-
embeddedEffects: boolean;
|
|
8
|
-
node: mctree.Expression | mctree.TypeSpecList | mctree.InstanceOfCase;
|
|
9
|
-
};
|
|
10
|
-
export declare type InterpState = {
|
|
11
|
-
state: ProgramStateAnalysis;
|
|
12
|
-
stack: InterpStackElem[];
|
|
13
|
-
typeMap?: TypeMap;
|
|
14
|
-
func?: FunctionStateNode;
|
|
15
|
-
pre?: (node: mctree.Node) => mctree.Node | null | void;
|
|
16
|
-
post?: (node: mctree.Node) => mctree.Node | null | void;
|
|
17
|
-
};
|
|
18
|
-
export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
|
|
19
|
-
export declare function evaluateExpr(state: ProgramStateAnalysis, expr: mctree.Expression, typeMap?: TypeMap): InterpStackElem;
|
|
20
|
-
export declare function evaluate(istate: InterpState, node: mctree.Expression): InterpStackElem;
|
|
21
|
-
export declare function evaluate(istate: InterpState, node: mctree.Node): InterpStackElem | undefined;
|
|
22
|
-
export declare function evaluateNode(istate: InterpState, node: mctree.Node): void;
|
|
23
|
-
export declare function roundToFloat(value: number): number;
|
package/build/src/mc-types.d.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { ClassStateNode, EnumStateNode, FunctionStateNode, ModuleStateNode, ProgramStateAnalysis, ProgramStateStack, StateNodeDecl } 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
|
-
}
|
|
25
|
-
export declare enum TypeTag {
|
|
26
|
-
Never = 0,
|
|
27
|
-
Null = 1,
|
|
28
|
-
False = 2,
|
|
29
|
-
True = 4,
|
|
30
|
-
Boolean = 6,
|
|
31
|
-
Number = 8,
|
|
32
|
-
Long = 16,
|
|
33
|
-
Float = 32,
|
|
34
|
-
Double = 64,
|
|
35
|
-
Numeric = 120,
|
|
36
|
-
Char = 128,
|
|
37
|
-
String = 256,
|
|
38
|
-
Array = 512,
|
|
39
|
-
Dictionary = 1024,
|
|
40
|
-
Module = 2048,
|
|
41
|
-
Function = 4096,
|
|
42
|
-
Class = 8192,
|
|
43
|
-
Object = 16384,
|
|
44
|
-
Enum = 32768,
|
|
45
|
-
Symbol = 65536,
|
|
46
|
-
Any = 131071
|
|
47
|
-
}
|
|
48
|
-
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.Function | TypeTag.Class | TypeTag.Object | TypeTag.Enum | TypeTag.Function | TypeTag.Symbol;
|
|
49
|
-
export declare type EnumeratedTypeTags = ExactTypeTags | TypeTag.Never | TypeTag.Any;
|
|
50
|
-
export declare type UnionTypeTags = number;
|
|
51
|
-
interface AbstractValue {
|
|
52
|
-
type: UnionTypeTags;
|
|
53
|
-
value?: unknown;
|
|
54
|
-
}
|
|
55
|
-
export declare type ExactTypes = NullType | FalseType | TrueType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType;
|
|
56
|
-
declare type WithValue<T> = T extends ExactTypes ? T extends SingletonType ? T : T & {
|
|
57
|
-
value: NonNullable<T["value"]>;
|
|
58
|
-
} : never;
|
|
59
|
-
export declare type ValueTypes = WithValue<ExactTypes>;
|
|
60
|
-
export declare type ExtendedTypes = ExactTypes | NeverType | AnyType;
|
|
61
|
-
export interface NeverType extends AbstractValue {
|
|
62
|
-
type: 0;
|
|
63
|
-
value?: undefined;
|
|
64
|
-
}
|
|
65
|
-
export interface NullType extends AbstractValue {
|
|
66
|
-
type: TypeTag.Null;
|
|
67
|
-
value?: undefined;
|
|
68
|
-
}
|
|
69
|
-
export interface FalseType extends AbstractValue {
|
|
70
|
-
type: TypeTag.False;
|
|
71
|
-
value?: undefined;
|
|
72
|
-
}
|
|
73
|
-
export interface TrueType extends AbstractValue {
|
|
74
|
-
type: TypeTag.True;
|
|
75
|
-
value?: undefined;
|
|
76
|
-
}
|
|
77
|
-
export interface NumberType extends AbstractValue {
|
|
78
|
-
type: TypeTag.Number;
|
|
79
|
-
value?: number | undefined;
|
|
80
|
-
}
|
|
81
|
-
export interface LongType extends AbstractValue {
|
|
82
|
-
type: TypeTag.Long;
|
|
83
|
-
value?: bigint | undefined;
|
|
84
|
-
}
|
|
85
|
-
export interface FloatType extends AbstractValue {
|
|
86
|
-
type: TypeTag.Float;
|
|
87
|
-
value?: number | undefined;
|
|
88
|
-
}
|
|
89
|
-
export interface DoubleType extends AbstractValue {
|
|
90
|
-
type: TypeTag.Double;
|
|
91
|
-
value?: number | undefined;
|
|
92
|
-
}
|
|
93
|
-
export interface CharType extends AbstractValue {
|
|
94
|
-
type: TypeTag.Char;
|
|
95
|
-
value?: string | undefined;
|
|
96
|
-
}
|
|
97
|
-
export interface StringType extends AbstractValue {
|
|
98
|
-
type: TypeTag.String;
|
|
99
|
-
value?: string | undefined;
|
|
100
|
-
}
|
|
101
|
-
export interface ArrayType extends AbstractValue {
|
|
102
|
-
type: TypeTag.Array;
|
|
103
|
-
value?: ExactOrUnion | undefined;
|
|
104
|
-
}
|
|
105
|
-
export interface DictionaryType extends AbstractValue {
|
|
106
|
-
type: TypeTag.Dictionary;
|
|
107
|
-
value?: {
|
|
108
|
-
key: ExactOrUnion;
|
|
109
|
-
value: ExactOrUnion;
|
|
110
|
-
} | undefined;
|
|
111
|
-
}
|
|
112
|
-
export interface ModuleType extends AbstractValue {
|
|
113
|
-
type: TypeTag.Module;
|
|
114
|
-
value?: ModuleStateNode | ModuleStateNode[] | undefined;
|
|
115
|
-
}
|
|
116
|
-
export interface FunctionType extends AbstractValue {
|
|
117
|
-
type: TypeTag.Function;
|
|
118
|
-
value?: FunctionStateNode | FunctionStateNode[] | undefined;
|
|
119
|
-
}
|
|
120
|
-
export interface ClassType extends AbstractValue {
|
|
121
|
-
type: TypeTag.Class;
|
|
122
|
-
value?: ClassStateNode | ClassStateNode[] | undefined;
|
|
123
|
-
}
|
|
124
|
-
export interface ObjectType extends AbstractValue {
|
|
125
|
-
type: TypeTag.Object;
|
|
126
|
-
value?: {
|
|
127
|
-
klass: ClassType;
|
|
128
|
-
obj?: Record<string, ExactOrUnion>;
|
|
129
|
-
} | undefined;
|
|
130
|
-
}
|
|
131
|
-
export interface EnumType extends AbstractValue {
|
|
132
|
-
type: TypeTag.Enum;
|
|
133
|
-
value?: {
|
|
134
|
-
enum: EnumStateNode;
|
|
135
|
-
value?: ExactOrUnion | undefined;
|
|
136
|
-
} | undefined;
|
|
137
|
-
}
|
|
138
|
-
export interface SymbolType extends AbstractValue {
|
|
139
|
-
type: TypeTag.Symbol;
|
|
140
|
-
value?: string | undefined;
|
|
141
|
-
}
|
|
142
|
-
export interface AnyType extends AbstractValue {
|
|
143
|
-
type: -1;
|
|
144
|
-
value?: undefined;
|
|
145
|
-
}
|
|
146
|
-
export declare type SingletonType = NullType | FalseType | TrueType;
|
|
147
|
-
export interface UnionType extends AbstractValue {
|
|
148
|
-
value?: undefined;
|
|
149
|
-
}
|
|
150
|
-
export declare type ExactOrUnion = UnionType | ExactTypes;
|
|
151
|
-
export declare function isExact(v: AbstractValue): v is ExactTypes;
|
|
152
|
-
export declare function isUnion(v: AbstractValue): v is UnionType;
|
|
153
|
-
export declare function isSingleton(v: AbstractValue): v is SingletonType;
|
|
154
|
-
export declare function hasValue(v: AbstractValue): v is WithValue<ExactTypes>;
|
|
155
|
-
export declare function unionInto(to: ExactOrUnion, from: ExactOrUnion): boolean;
|
|
156
|
-
export declare function cloneType<T extends ExactOrUnion>(t: T): T;
|
|
157
|
-
export declare function typeFromTypeStateNode(state: ProgramStateAnalysis, sn: StateNodeDecl, classVsObj?: boolean): ExactOrUnion;
|
|
158
|
-
export declare function typeFromTypespec(state: ProgramStateAnalysis, ts: mctree.TypeSpecList, stack?: ProgramStateStack | undefined): ExactOrUnion;
|
|
159
|
-
export declare function typeFromLiteral(literal: mctree.Literal): ExactTypes;
|
|
160
|
-
export declare function mcExprFromType(type: ValueTypes): mctree.Expression | null;
|
|
161
|
-
export declare function castType(type: ExactOrUnion, target: UnionTypeTags): ExactOrUnion;
|
|
162
|
-
export declare const TruthyTypes: number;
|
|
163
|
-
export declare function mustBeTrue(arg: ExactOrUnion): boolean;
|
|
164
|
-
export declare function mustBeFalse(arg: ExactOrUnion): boolean;
|
|
165
|
-
export declare function display(type: ExactOrUnion): string;
|
|
166
|
-
export {};
|