@markw65/monkeyc-optimizer 1.0.31 → 1.0.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.
- package/README.md +26 -0
- package/build/api.cjs +54 -42
- package/build/optimizer.cjs +77 -56
- package/build/sdk-util.cjs +31 -2
- package/build/src/api.d.ts +1 -1
- package/build/src/ast.d.ts +19 -0
- package/build/src/driver.d.ts +2 -0
- package/build/src/mc-rewrite.d.ts +1 -1
- package/build/src/optimizer-types.d.ts +2 -1
- package/build/src/optimizer.d.ts +2 -2
- package/build/src/projects.d.ts +21 -0
- package/build/src/readprg.d.ts +5 -0
- package/build/src/sdk-util.d.ts +1 -0
- package/build/src/util.d.ts +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -378,3 +378,29 @@ Bug Fixes
|
|
|
378
378
|
- Collect info about what each function may modify and call
|
|
379
379
|
- Better analysis of inline function bodies
|
|
380
380
|
- Update the StateNodeDecls when renaming locals
|
|
381
|
+
|
|
382
|
+
### 1.0.32
|
|
383
|
+
|
|
384
|
+
- Bug fixes
|
|
385
|
+
- Fixup the tests to run unoptimized again, and add running unoptimized to the standard test run
|
|
386
|
+
- Fix PRE to not merge Numbers and Floats (ie 1 is not the same thing as 1.0), and add a test
|
|
387
|
+
|
|
388
|
+
### 1.0.33
|
|
389
|
+
|
|
390
|
+
- New features
|
|
391
|
+
|
|
392
|
+
- Tagging a function with (:keep) will prevent the optimizer from removing it, even if it appears to be unused.
|
|
393
|
+
|
|
394
|
+
- Bug fixes
|
|
395
|
+
- Fix PRE to not merge values with different types. ie Number, Long, Float and Double literals should all be treated separately, even when the compare the same.
|
|
396
|
+
|
|
397
|
+
### 1.0.34
|
|
398
|
+
|
|
399
|
+
- Bug fixes
|
|
400
|
+
|
|
401
|
+
- Fix parser to allow white space to separate attributes, in addition to comma
|
|
402
|
+
- Fix optimizer to respect prettier options when formatting the optimized code
|
|
403
|
+
|
|
404
|
+
- Testing
|
|
405
|
+
- rewrite test harness in typescript
|
|
406
|
+
- fix up tests to work with compiler2 again, and also with compiler2 at -O0
|
package/build/api.cjs
CHANGED
|
@@ -281,6 +281,7 @@ const promises_namespaceObject = require("fs/promises");
|
|
|
281
281
|
;// CONCATENATED MODULE: external "prettier"
|
|
282
282
|
const external_prettier_namespaceObject = require("prettier");
|
|
283
283
|
;// CONCATENATED MODULE: ./src/ast.ts
|
|
284
|
+
|
|
284
285
|
/*
|
|
285
286
|
* This ensures that mctreeTypeInfo has every key of MCTreeTypeInfo,
|
|
286
287
|
* and that the corresponding arrays contain every element of the
|
|
@@ -482,6 +483,44 @@ function ast_withLocDeep(node, start, end, inplace) {
|
|
|
482
483
|
function ast_cloneDeep(node) {
|
|
483
484
|
return ast_withLocDeep(node, null);
|
|
484
485
|
}
|
|
486
|
+
function ast_getNodeValue(node) {
|
|
487
|
+
if (node.type == "BinaryExpression" &&
|
|
488
|
+
node.operator == "as" &&
|
|
489
|
+
node.right.type == "TypeSpecList" &&
|
|
490
|
+
node.right.ts.length == 1 &&
|
|
491
|
+
typeof node.right.ts[0] == "string") {
|
|
492
|
+
// this is a cast we inserted to retain the type of an enum
|
|
493
|
+
// any arithmetic on it will revert to "Number", or "Long",
|
|
494
|
+
// so just ignore it.
|
|
495
|
+
return ast_getNodeValue(node.left);
|
|
496
|
+
}
|
|
497
|
+
if (node.type != "Literal") {
|
|
498
|
+
return [null, null];
|
|
499
|
+
}
|
|
500
|
+
if (node.value === null) {
|
|
501
|
+
return [node, "Null"];
|
|
502
|
+
}
|
|
503
|
+
const type = typeof node.value;
|
|
504
|
+
if (type === "number") {
|
|
505
|
+
const match = prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
506
|
+
if (match) {
|
|
507
|
+
return match[2] === "l" || match[2] === "L"
|
|
508
|
+
? [node, "Long"]
|
|
509
|
+
: [node, "Number"];
|
|
510
|
+
}
|
|
511
|
+
return [node, node.raw.endsWith("d") ? "Double" : "Float"];
|
|
512
|
+
}
|
|
513
|
+
if (type === "bigint") {
|
|
514
|
+
return [node, "Long"];
|
|
515
|
+
}
|
|
516
|
+
if (type === "string") {
|
|
517
|
+
return [node, "String"];
|
|
518
|
+
}
|
|
519
|
+
if (type === "boolean") {
|
|
520
|
+
return [node, "Boolean"];
|
|
521
|
+
}
|
|
522
|
+
throw new Error(`Literal has unknown type '${type}'`);
|
|
523
|
+
}
|
|
485
524
|
|
|
486
525
|
;// CONCATENATED MODULE: external "./api.cjs"
|
|
487
526
|
const external_api_cjs_namespaceObject = require("./api.cjs");
|
|
@@ -2164,10 +2203,15 @@ function buildPREGraph(state, func) {
|
|
|
2164
2203
|
break;
|
|
2165
2204
|
case "Literal":
|
|
2166
2205
|
if (refCost(node) > LocalRefCost) {
|
|
2167
|
-
|
|
2206
|
+
const result = getNodeValue(node);
|
|
2207
|
+
const key = result[1] +
|
|
2208
|
+
(result[0].value === null
|
|
2209
|
+
? ""
|
|
2210
|
+
: "-" + result[0].value.toString());
|
|
2211
|
+
let decl = literals.get(key);
|
|
2168
2212
|
if (!decl) {
|
|
2169
2213
|
decl = node;
|
|
2170
|
-
literals.set(
|
|
2214
|
+
literals.set(key, decl);
|
|
2171
2215
|
}
|
|
2172
2216
|
return {
|
|
2173
2217
|
type: "ref",
|
|
@@ -3367,7 +3411,7 @@ function getLiteralNode(node) {
|
|
|
3367
3411
|
return null;
|
|
3368
3412
|
switch (node.operator) {
|
|
3369
3413
|
case "-": {
|
|
3370
|
-
const [arg, type] =
|
|
3414
|
+
const [arg, type] = ast_getNodeValue(node.argument);
|
|
3371
3415
|
if (type === "Number" || type === "Long") {
|
|
3372
3416
|
return replacementLiteral(arg, -arg.value, type);
|
|
3373
3417
|
}
|
|
@@ -3376,44 +3420,6 @@ function getLiteralNode(node) {
|
|
|
3376
3420
|
}
|
|
3377
3421
|
return null;
|
|
3378
3422
|
}
|
|
3379
|
-
function getNodeValue(node) {
|
|
3380
|
-
if (node.type == "BinaryExpression" &&
|
|
3381
|
-
node.operator == "as" &&
|
|
3382
|
-
node.right.type == "TypeSpecList" &&
|
|
3383
|
-
node.right.ts.length == 1 &&
|
|
3384
|
-
typeof node.right.ts[0] == "string") {
|
|
3385
|
-
// this is a cast we inserted to retain the type of an enum
|
|
3386
|
-
// any arithmetic on it will revert to "Number", or "Long",
|
|
3387
|
-
// so just ignore it.
|
|
3388
|
-
return getNodeValue(node.left);
|
|
3389
|
-
}
|
|
3390
|
-
if (node.type != "Literal") {
|
|
3391
|
-
return [null, null];
|
|
3392
|
-
}
|
|
3393
|
-
if (node.value === null) {
|
|
3394
|
-
return [node, "Null"];
|
|
3395
|
-
}
|
|
3396
|
-
const type = typeof node.value;
|
|
3397
|
-
if (type === "number") {
|
|
3398
|
-
const match = prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
3399
|
-
if (match) {
|
|
3400
|
-
return match[2] === "l" || match[2] === "L"
|
|
3401
|
-
? [node, "Long"]
|
|
3402
|
-
: [node, "Number"];
|
|
3403
|
-
}
|
|
3404
|
-
return [node, node.raw.endsWith("d") ? "Double" : "Float"];
|
|
3405
|
-
}
|
|
3406
|
-
if (type === "bigint") {
|
|
3407
|
-
return [node, "Long"];
|
|
3408
|
-
}
|
|
3409
|
-
if (type === "string") {
|
|
3410
|
-
return [node, "String"];
|
|
3411
|
-
}
|
|
3412
|
-
if (type === "boolean") {
|
|
3413
|
-
return [node, "Boolean"];
|
|
3414
|
-
}
|
|
3415
|
-
throw new Error(`Literal has unknown type '${type}'`);
|
|
3416
|
-
}
|
|
3417
3423
|
function fullTypeName(state, tsp) {
|
|
3418
3424
|
if (typeof tsp.name === "string") {
|
|
3419
3425
|
return tsp.name;
|
|
@@ -4246,6 +4252,11 @@ async function optimizeMonkeyC(fnMap, barrelList, config) {
|
|
|
4246
4252
|
break;
|
|
4247
4253
|
case "FunctionDeclaration":
|
|
4248
4254
|
if (!maybeCalled(node)) {
|
|
4255
|
+
if (node.attrs &&
|
|
4256
|
+
node.attrs.attributes &&
|
|
4257
|
+
node.attrs.attributes.elements.some((attr) => attr.type === "UnaryExpression" && attr.argument.name === "keep")) {
|
|
4258
|
+
break;
|
|
4259
|
+
}
|
|
4249
4260
|
return false;
|
|
4250
4261
|
}
|
|
4251
4262
|
break;
|
|
@@ -5048,7 +5059,7 @@ function api_collectNamespaces(ast, stateIn) {
|
|
|
5048
5059
|
}
|
|
5049
5060
|
return state.stack[0];
|
|
5050
5061
|
}
|
|
5051
|
-
function api_formatAst(node, monkeyCSource = null) {
|
|
5062
|
+
function api_formatAst(node, monkeyCSource = null, options = null) {
|
|
5052
5063
|
/*
|
|
5053
5064
|
* The estree printer sometimes looks at the parent node without
|
|
5054
5065
|
* checking that there *is* a parent node (eg it assumes all
|
|
@@ -5076,6 +5087,7 @@ function api_formatAst(node, monkeyCSource = null) {
|
|
|
5076
5087
|
// looking for in the source.
|
|
5077
5088
|
const source = (monkeyCSource || "") + "\n" + (0,prettier_plugin_monkeyc_namespaceObject.serializeMonkeyC)(node);
|
|
5078
5089
|
return external_prettier_namespaceObject.format(source, {
|
|
5090
|
+
...(options || {}),
|
|
5079
5091
|
parser: "monkeyc-json",
|
|
5080
5092
|
plugins: [(prettier_plugin_monkeyc_default())],
|
|
5081
5093
|
endOfLine: "lf",
|
package/build/optimizer.cjs
CHANGED
|
@@ -10024,6 +10024,8 @@ const external_crypto_namespaceObject = require("crypto");
|
|
|
10024
10024
|
const promises_namespaceObject = require("fs/promises");
|
|
10025
10025
|
// EXTERNAL MODULE: external "path"
|
|
10026
10026
|
var external_path_ = __webpack_require__(1423);
|
|
10027
|
+
;// CONCATENATED MODULE: external "prettier"
|
|
10028
|
+
const external_prettier_namespaceObject = require("prettier");
|
|
10027
10029
|
;// CONCATENATED MODULE: external "./api.cjs"
|
|
10028
10030
|
const external_api_cjs_namespaceObject = require("./api.cjs");
|
|
10029
10031
|
;// CONCATENATED MODULE: external "./sdk-util.cjs"
|
|
@@ -10977,6 +10979,7 @@ function simulateProgram(prg, device, test = false, logger) {
|
|
|
10977
10979
|
}
|
|
10978
10980
|
|
|
10979
10981
|
;// CONCATENATED MODULE: ./src/ast.ts
|
|
10982
|
+
|
|
10980
10983
|
/*
|
|
10981
10984
|
* This ensures that mctreeTypeInfo has every key of MCTreeTypeInfo,
|
|
10982
10985
|
* and that the corresponding arrays contain every element of the
|
|
@@ -11178,6 +11181,44 @@ function withLocDeep(node, start, end, inplace) {
|
|
|
11178
11181
|
function cloneDeep(node) {
|
|
11179
11182
|
return withLocDeep(node, null);
|
|
11180
11183
|
}
|
|
11184
|
+
function getNodeValue(node) {
|
|
11185
|
+
if (node.type == "BinaryExpression" &&
|
|
11186
|
+
node.operator == "as" &&
|
|
11187
|
+
node.right.type == "TypeSpecList" &&
|
|
11188
|
+
node.right.ts.length == 1 &&
|
|
11189
|
+
typeof node.right.ts[0] == "string") {
|
|
11190
|
+
// this is a cast we inserted to retain the type of an enum
|
|
11191
|
+
// any arithmetic on it will revert to "Number", or "Long",
|
|
11192
|
+
// so just ignore it.
|
|
11193
|
+
return getNodeValue(node.left);
|
|
11194
|
+
}
|
|
11195
|
+
if (node.type != "Literal") {
|
|
11196
|
+
return [null, null];
|
|
11197
|
+
}
|
|
11198
|
+
if (node.value === null) {
|
|
11199
|
+
return [node, "Null"];
|
|
11200
|
+
}
|
|
11201
|
+
const type = typeof node.value;
|
|
11202
|
+
if (type === "number") {
|
|
11203
|
+
const match = prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
11204
|
+
if (match) {
|
|
11205
|
+
return match[2] === "l" || match[2] === "L"
|
|
11206
|
+
? [node, "Long"]
|
|
11207
|
+
: [node, "Number"];
|
|
11208
|
+
}
|
|
11209
|
+
return [node, node.raw.endsWith("d") ? "Double" : "Float"];
|
|
11210
|
+
}
|
|
11211
|
+
if (type === "bigint") {
|
|
11212
|
+
return [node, "Long"];
|
|
11213
|
+
}
|
|
11214
|
+
if (type === "string") {
|
|
11215
|
+
return [node, "String"];
|
|
11216
|
+
}
|
|
11217
|
+
if (type === "boolean") {
|
|
11218
|
+
return [node, "Boolean"];
|
|
11219
|
+
}
|
|
11220
|
+
throw new Error(`Literal has unknown type '${type}'`);
|
|
11221
|
+
}
|
|
11181
11222
|
|
|
11182
11223
|
;// CONCATENATED MODULE: ./src/function-info.ts
|
|
11183
11224
|
|
|
@@ -12856,10 +12897,15 @@ function buildPREGraph(state, func) {
|
|
|
12856
12897
|
break;
|
|
12857
12898
|
case "Literal":
|
|
12858
12899
|
if (refCost(node) > LocalRefCost) {
|
|
12859
|
-
|
|
12900
|
+
const result = getNodeValue(node);
|
|
12901
|
+
const key = result[1] +
|
|
12902
|
+
(result[0].value === null
|
|
12903
|
+
? ""
|
|
12904
|
+
: "-" + result[0].value.toString());
|
|
12905
|
+
let decl = literals.get(key);
|
|
12860
12906
|
if (!decl) {
|
|
12861
12907
|
decl = node;
|
|
12862
|
-
literals.set(
|
|
12908
|
+
literals.set(key, decl);
|
|
12863
12909
|
}
|
|
12864
12910
|
return {
|
|
12865
12911
|
type: "ref",
|
|
@@ -14067,44 +14113,6 @@ function getLiteralNode(node) {
|
|
|
14067
14113
|
}
|
|
14068
14114
|
return null;
|
|
14069
14115
|
}
|
|
14070
|
-
function getNodeValue(node) {
|
|
14071
|
-
if (node.type == "BinaryExpression" &&
|
|
14072
|
-
node.operator == "as" &&
|
|
14073
|
-
node.right.type == "TypeSpecList" &&
|
|
14074
|
-
node.right.ts.length == 1 &&
|
|
14075
|
-
typeof node.right.ts[0] == "string") {
|
|
14076
|
-
// this is a cast we inserted to retain the type of an enum
|
|
14077
|
-
// any arithmetic on it will revert to "Number", or "Long",
|
|
14078
|
-
// so just ignore it.
|
|
14079
|
-
return getNodeValue(node.left);
|
|
14080
|
-
}
|
|
14081
|
-
if (node.type != "Literal") {
|
|
14082
|
-
return [null, null];
|
|
14083
|
-
}
|
|
14084
|
-
if (node.value === null) {
|
|
14085
|
-
return [node, "Null"];
|
|
14086
|
-
}
|
|
14087
|
-
const type = typeof node.value;
|
|
14088
|
-
if (type === "number") {
|
|
14089
|
-
const match = prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.exec(node.raw);
|
|
14090
|
-
if (match) {
|
|
14091
|
-
return match[2] === "l" || match[2] === "L"
|
|
14092
|
-
? [node, "Long"]
|
|
14093
|
-
: [node, "Number"];
|
|
14094
|
-
}
|
|
14095
|
-
return [node, node.raw.endsWith("d") ? "Double" : "Float"];
|
|
14096
|
-
}
|
|
14097
|
-
if (type === "bigint") {
|
|
14098
|
-
return [node, "Long"];
|
|
14099
|
-
}
|
|
14100
|
-
if (type === "string") {
|
|
14101
|
-
return [node, "String"];
|
|
14102
|
-
}
|
|
14103
|
-
if (type === "boolean") {
|
|
14104
|
-
return [node, "Boolean"];
|
|
14105
|
-
}
|
|
14106
|
-
throw new Error(`Literal has unknown type '${type}'`);
|
|
14107
|
-
}
|
|
14108
14116
|
function fullTypeName(state, tsp) {
|
|
14109
14117
|
if (typeof tsp.name === "string") {
|
|
14110
14118
|
return tsp.name;
|
|
@@ -14937,6 +14945,11 @@ async function optimizeMonkeyC(fnMap, barrelList, config) {
|
|
|
14937
14945
|
break;
|
|
14938
14946
|
case "FunctionDeclaration":
|
|
14939
14947
|
if (!maybeCalled(node)) {
|
|
14948
|
+
if (node.attrs &&
|
|
14949
|
+
node.attrs.attributes &&
|
|
14950
|
+
node.attrs.attributes.elements.some((attr) => attr.type === "UnaryExpression" && attr.argument.name === "keep")) {
|
|
14951
|
+
break;
|
|
14952
|
+
}
|
|
14940
14953
|
return false;
|
|
14941
14954
|
}
|
|
14942
14955
|
break;
|
|
@@ -15036,6 +15049,7 @@ function optimizeCall(state, node, context) {
|
|
|
15036
15049
|
|
|
15037
15050
|
|
|
15038
15051
|
|
|
15052
|
+
|
|
15039
15053
|
function relative_path_no_dotdot(relative) {
|
|
15040
15054
|
return relative.replace(/^(\.\.[\\/])+/, (str) => `__${"dot".repeat(str.length / 3)}__${str.slice(-1)}`);
|
|
15041
15055
|
}
|
|
@@ -15458,28 +15472,35 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
15458
15472
|
// the oldest optimized file, we don't need to regenerate
|
|
15459
15473
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
15460
15474
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
15461
|
-
if (source_time < opt_time &&
|
|
15475
|
+
if (source_time < opt_time && 1659827507288 < opt_time) {
|
|
15462
15476
|
return { hasTests, diagnostics: prevDiagnostics };
|
|
15463
15477
|
}
|
|
15464
15478
|
}
|
|
15465
15479
|
await promises_namespaceObject.rm(output, { recursive: true, force: true });
|
|
15466
15480
|
await promises_namespaceObject.mkdir(output, { recursive: true });
|
|
15467
15481
|
const diagnostics = await optimizeMonkeyC(fnMap, Object.keys(buildConfig.barrelMap || {}), config);
|
|
15468
|
-
return
|
|
15469
|
-
|
|
15470
|
-
|
|
15471
|
-
|
|
15472
|
-
const
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
|
|
15477
|
-
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
}))
|
|
15482
|
-
.
|
|
15482
|
+
return external_prettier_namespaceObject.resolveConfig(config.workspace, {
|
|
15483
|
+
useCache: false,
|
|
15484
|
+
editorconfig: true,
|
|
15485
|
+
}).then((prettierConfig) => {
|
|
15486
|
+
const options = { ...prettierConfig, ...(config.prettier || {}) };
|
|
15487
|
+
return Promise.all(Object.values(fnMap).map(async (info) => {
|
|
15488
|
+
const name = info.output;
|
|
15489
|
+
const dir = external_path_.dirname(name);
|
|
15490
|
+
await promises_namespaceObject.mkdir(dir, { recursive: true });
|
|
15491
|
+
options.filepath = name;
|
|
15492
|
+
const opt_source = (0,external_api_cjs_namespaceObject.formatAst)(info.ast, info.monkeyCSource, options);
|
|
15493
|
+
await promises_namespaceObject.writeFile(name, opt_source);
|
|
15494
|
+
return info.hasTests;
|
|
15495
|
+
})).then((results) => {
|
|
15496
|
+
const hasTests = results.some((v) => v);
|
|
15497
|
+
return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
|
|
15498
|
+
hasTests,
|
|
15499
|
+
diagnostics,
|
|
15500
|
+
...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
|
|
15501
|
+
}))
|
|
15502
|
+
.then(() => ({ hasTests, diagnostics }));
|
|
15503
|
+
});
|
|
15483
15504
|
});
|
|
15484
15505
|
}
|
|
15485
15506
|
async function getProjectAnalysis(targets, analysis, options) {
|
package/build/sdk-util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin});
|
|
1
|
+
0 && (module.exports = {SectionKinds,appSupport,connectiq,getDeviceInfo,getLanguages,getSdkPath,isWin,readPrg});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -7171,12 +7171,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7171
7171
|
|
|
7172
7172
|
// EXPORTS
|
|
7173
7173
|
__webpack_require__.d(__webpack_exports__, {
|
|
7174
|
+
"SectionKinds": () => (/* reexport */ SectionKinds),
|
|
7174
7175
|
"appSupport": () => (/* binding */ appSupport),
|
|
7175
7176
|
"connectiq": () => (/* binding */ connectiq),
|
|
7176
7177
|
"getDeviceInfo": () => (/* binding */ getDeviceInfo),
|
|
7177
7178
|
"getLanguages": () => (/* binding */ getLanguages),
|
|
7178
7179
|
"getSdkPath": () => (/* binding */ getSdkPath),
|
|
7179
|
-
"isWin": () => (/* binding */ isWin)
|
|
7180
|
+
"isWin": () => (/* binding */ isWin),
|
|
7181
|
+
"readPrg": () => (/* reexport */ readPrg)
|
|
7180
7182
|
});
|
|
7181
7183
|
|
|
7182
7184
|
;// CONCATENATED MODULE: external "fs/promises"
|
|
@@ -7187,11 +7189,38 @@ const external_path_namespaceObject = require("path");
|
|
|
7187
7189
|
var xml2js = __webpack_require__(5055);
|
|
7188
7190
|
;// CONCATENATED MODULE: external "./util.cjs"
|
|
7189
7191
|
const external_util_cjs_namespaceObject = require("./util.cjs");
|
|
7192
|
+
;// CONCATENATED MODULE: ./src/readprg.ts
|
|
7193
|
+
|
|
7194
|
+
var SectionKinds;
|
|
7195
|
+
(function (SectionKinds) {
|
|
7196
|
+
SectionKinds[SectionKinds["TEXT"] = -1059145026] = "TEXT";
|
|
7197
|
+
SectionKinds[SectionKinds["DATA"] = -629491010] = "DATA";
|
|
7198
|
+
})(SectionKinds || (SectionKinds = {}));
|
|
7199
|
+
async function readPrg(path) {
|
|
7200
|
+
const data = await promises_namespaceObject.readFile(path);
|
|
7201
|
+
const view = new DataView(data.buffer);
|
|
7202
|
+
const sections = {};
|
|
7203
|
+
let offset = 0;
|
|
7204
|
+
while (view.byteLength - offset > 8) {
|
|
7205
|
+
const type = view.getInt32(offset);
|
|
7206
|
+
offset += 4;
|
|
7207
|
+
const length = view.getInt32(offset);
|
|
7208
|
+
offset += 4;
|
|
7209
|
+
if (length > view.byteLength - offset) {
|
|
7210
|
+
throw new Error(`Invalid length for section ${type}`);
|
|
7211
|
+
}
|
|
7212
|
+
sections[type] = length;
|
|
7213
|
+
offset += length;
|
|
7214
|
+
}
|
|
7215
|
+
return sections;
|
|
7216
|
+
}
|
|
7217
|
+
|
|
7190
7218
|
;// CONCATENATED MODULE: ./src/sdk-util.ts
|
|
7191
7219
|
|
|
7192
7220
|
|
|
7193
7221
|
|
|
7194
7222
|
|
|
7223
|
+
|
|
7195
7224
|
const isWin = process.platform == "win32";
|
|
7196
7225
|
const appSupport = isWin
|
|
7197
7226
|
? `${process.env.APPDATA}`.replace(/\\/g, "/")
|
package/build/src/api.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function variableDeclarationName(node: mctree.TypedIdentifier | m
|
|
|
9
9
|
export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
|
|
10
10
|
export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
|
|
11
11
|
export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
|
|
12
|
-
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
|
|
12
|
+
export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): string;
|
|
13
13
|
export declare function findUsingForNode(state: ProgramStateLive, stack: ProgramStateStack, i: number, node: mctree.Identifier, isType: boolean): StateNodeDecl[] | null;
|
|
14
14
|
export declare function getApiFunctionInfo(func: FunctionStateNode): FunctionInfo;
|
|
15
15
|
export declare function markInvokeClassMethod(func: FunctionStateNode): void;
|
package/build/src/ast.d.ts
CHANGED
|
@@ -8,3 +8,22 @@ export declare function hasProperty<T>(obj: T, prop: string): boolean;
|
|
|
8
8
|
export declare function withLoc<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined): T;
|
|
9
9
|
export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined, inplace?: boolean): T;
|
|
10
10
|
export declare function cloneDeep<T extends mctree.Node>(node: T): T;
|
|
11
|
+
interface NumberLiteral extends mctree.Literal {
|
|
12
|
+
value: number;
|
|
13
|
+
}
|
|
14
|
+
interface LongLiteral extends mctree.Literal {
|
|
15
|
+
value: number | bigint;
|
|
16
|
+
}
|
|
17
|
+
interface StringLiteral extends mctree.Literal {
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
interface BooleanLiteral extends mctree.Literal {
|
|
21
|
+
value: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface NullLiteral extends mctree.Literal {
|
|
24
|
+
value: null;
|
|
25
|
+
}
|
|
26
|
+
declare type LiteralValues = [NumberLiteral, "Number" | "Float" | "Double"] | [LongLiteral, "Long"] | [StringLiteral, "String"] | [BooleanLiteral, "Boolean"] | [NullLiteral, "Null"];
|
|
27
|
+
export declare function getNodeValue(node: mctree.Literal): LiteralValues;
|
|
28
|
+
export declare function getNodeValue(node: mctree.Node): LiteralValues | [null, null];
|
|
29
|
+
export {};
|
|
@@ -6,7 +6,7 @@ export declare function analyze(fnMap: FilesToOptimizeMap, barrelList?: string[]
|
|
|
6
6
|
export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
|
|
7
7
|
export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
|
|
8
8
|
export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, barrelList?: string[], config?: BuildConfig): Promise<Record<string, {
|
|
9
|
-
type: "
|
|
9
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
10
10
|
loc: {
|
|
11
11
|
start: mctree.Position;
|
|
12
12
|
end: mctree.Position;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
2
|
import { ResolvedJungle } from "./jungles";
|
|
3
|
-
declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
3
|
+
export declare type DiagnosticType = "ERROR" | "WARNING" | "INFO";
|
|
4
4
|
export declare type BuildConfig = {
|
|
5
5
|
workspace?: string;
|
|
6
6
|
jungleFiles?: string;
|
|
@@ -25,6 +25,7 @@ export declare type BuildConfig = {
|
|
|
25
25
|
checkBuildPragmas?: boolean;
|
|
26
26
|
checkInvalidSymbols?: DiagnosticType | "OFF";
|
|
27
27
|
sizeBasedPRE?: boolean | string;
|
|
28
|
+
prettier?: Record<string, unknown>;
|
|
28
29
|
_cache?: {
|
|
29
30
|
barrels?: Record<string, ResolvedJungle>;
|
|
30
31
|
barrelMap?: Record<string, Record<string, ResolvedJungle>>;
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare function buildOptimizedProject(product: string | null, options: B
|
|
|
30
30
|
product: string | null;
|
|
31
31
|
hasTests: boolean;
|
|
32
32
|
diagnostics: Record<string, {
|
|
33
|
-
type: "
|
|
33
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
34
34
|
loc: {
|
|
35
35
|
start: mctree.Position;
|
|
36
36
|
end: mctree.Position;
|
|
@@ -50,7 +50,7 @@ export declare function generateOptimizedProject(options: BuildConfig): Promise<
|
|
|
50
50
|
program: string;
|
|
51
51
|
hasTests: boolean;
|
|
52
52
|
diagnostics: Record<string, {
|
|
53
|
-
type: "
|
|
53
|
+
type: import("./optimizer-types").DiagnosticType;
|
|
54
54
|
loc: {
|
|
55
55
|
start: mctree.Position;
|
|
56
56
|
end: mctree.Position;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BuildConfig } from "./optimizer-types";
|
|
2
|
+
export declare type RemoteProject = string | {
|
|
3
|
+
root: string;
|
|
4
|
+
options?: BuildConfig;
|
|
5
|
+
rename?: {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
}[];
|
|
9
|
+
build?: boolean;
|
|
10
|
+
comment?: string;
|
|
11
|
+
exclude?: string;
|
|
12
|
+
include?: string;
|
|
13
|
+
sourcePath?: string;
|
|
14
|
+
jungleContent?: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const githubProjects: RemoteProject[];
|
|
17
|
+
export declare function fetchGitProjects(projects: RemoteProject[]): Promise<(string | {
|
|
18
|
+
jungle: string;
|
|
19
|
+
build: boolean | null;
|
|
20
|
+
options: BuildConfig | null;
|
|
21
|
+
})[]>;
|
package/build/src/sdk-util.d.ts
CHANGED
package/build/src/util.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare function spawnByLine(command: string, args: string[], lineHandler
|
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}): Promise<void>;
|
|
11
11
|
export declare function readByLine(file: string, lineHandler: LineHandler): Promise<unknown>;
|
|
12
|
-
export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T
|
|
12
|
+
export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T> | null, parallelism: number): Promise<T[]>;
|
|
13
13
|
export declare function copyRecursiveAsNeeded(source: string, target: string, filter?: (src: string, tgt: string) => boolean): Promise<void>;
|
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.0.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",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"build-debug": "webpack --mode development",
|
|
21
21
|
"build-release": "webpack --mode production",
|
|
22
22
|
"prepack": "webpack --mode production",
|
|
23
|
-
"test": "npm run test-optimized && npm run test-remote",
|
|
23
|
+
"test": "npm run test-optimized && npm run test-unopt && npm run test-remote",
|
|
24
24
|
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
25
|
-
"test-optimized": "node test/test.js --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
26
|
-
"test-unopt": "node test/test.js --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
27
|
-
"test-garmin-opt": "node test/test.js --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
25
|
+
"test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
26
|
+
"test-unopt": "node test/test.js --typeCheckLevel Strict --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
27
|
+
"test-garmin-opt": "node test/test.js --typeCheckLevel Strict --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle",
|
|
28
28
|
"eslint": "npx eslint ."
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"author": "markw65",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@markw65/prettier-plugin-monkeyc": "^1.0.
|
|
40
|
+
"@markw65/prettier-plugin-monkeyc": "^1.0.34"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/glob": "^7.2.0",
|