mlogjs 0.4.3 → 0.4.5
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/dist/bin.cjs +4 -9
- package/dist/bin.cjs.map +1 -1
- package/dist/index.cjs +38 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +35 -3
- package/dist/index.mjs.map +1 -1
- package/dist/macros/DynamicArray.d.ts +15 -2
- package/dist/values/LazyValue.d.ts +9 -0
- package/lib/globals.d.ts +1 -0
- package/lib/kinds.d.ts +1 -0
- package/lib/traits.d.ts +5 -0
- package/package.json +7 -8
package/dist/bin.cjs
CHANGED
|
@@ -9,12 +9,7 @@ var yargs = require('yargs');
|
|
|
9
9
|
var chalk = require('chalk');
|
|
10
10
|
var path = require('path');
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);
|
|
15
|
-
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
16
|
-
|
|
17
|
-
yargs__default["default"](helpers.hideBin(process.argv))
|
|
12
|
+
yargs(helpers.hideBin(process.argv))
|
|
18
13
|
.command("$0 [path] [out]", "compiles your Javascript file to MLog", yargs => {
|
|
19
14
|
return yargs
|
|
20
15
|
.positional("path", {
|
|
@@ -51,14 +46,14 @@ yargs__default["default"](helpers.hideBin(process.argv))
|
|
|
51
46
|
}
|
|
52
47
|
const { start, end } = error.loc;
|
|
53
48
|
const lines = code.split("\n");
|
|
54
|
-
console.log(
|
|
49
|
+
console.log(chalk.cyanBright([path.resolve(path$1), start.line, start.column].join(":")));
|
|
55
50
|
for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
|
|
56
51
|
const n = i + 1;
|
|
57
52
|
if (n !== start.line)
|
|
58
53
|
continue;
|
|
59
|
-
const head =
|
|
54
|
+
const head = chalk.gray(`${n} | `.padStart(6, " "));
|
|
60
55
|
console.log(head + cliHighlight.highlight(lines[i], { language: "js" }));
|
|
61
|
-
console.log(
|
|
56
|
+
console.log(chalk.red(" ".repeat(6 + start.column) + "^ " + error.message));
|
|
62
57
|
}
|
|
63
58
|
return;
|
|
64
59
|
}
|
package/dist/bin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.cjs","sources":["../src/bin.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"bin.cjs","sources":["../src/bin.ts"],"sourcesContent":[null],"names":["hideBin","path","existsSync","Compiler","readFileSync","resolve","highlight","writeFileSync","parse","join"],"mappings":";;;;;;;;;;;AAQA,KAAK,CAACA,eAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,KAAA,OAAO,CACN,iBAAiB,EACjB,uCAAuC,EACvC,KAAK,IAAG;AACN,IAAA,OAAO,KAAK;SACT,UAAU,CAAC,MAAM,EAAE;AAClB,QAAA,QAAQ,EAAE,6BAA6B;AACvC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,UAAU,CAAC,KAAK,EAAE;AACjB,QAAA,QAAQ,EAAE,yBAAyB;AACnC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,MAAM,CAAC,eAAe,EAAE;AACvB,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,QAAQ,EACN,4EAA4E;AAC/E,KAAA,CAAC,CAAC;AACP,CAAC,EACD,IAAI,IAAG;AACL,IAAA,MAAMC,MAAI,GAAG,IAAI,CAAC,IAAI,CAAC;AACvB,IAAA,IAAI,CAACA,MAAI;AAAE,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChE,IAAA,IAAI,CAACC,aAAU,CAACD,MAAI,CAAC;QACnB,OAAO,OAAO,CAAC,GAAG,CAAC,WAAWA,MAAI,CAAA,eAAA,CAAiB,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,IAAI,CAAC,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,CAAC,KAAK,KAAK,CAAC,IAAI;gBAAE,SAAS;AAC/B,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAG,EAAA,CAAC,CAAK,GAAA,CAAA,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AACpD,YAAA,OAAO,CAAC,GAAG,CAAC,IAAI,GAAGK,sBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAC/D,CAAC;AACH,SAAA;QAED,OAAO;AACR,KAAA;AACD,IAAAC,gBAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CACT,CAAA,kBAAA,EAAqBN,MAAI,CAA8B,2BAAA,EAAA,GAAG,CAAG,CAAA,CAAA,CAC9D,CAAC;AACJ,CAAC,CACF;AACA,KAAA,IAAI,EAAE;KACN,UAAU,CAAC,QAAQ,CAAC;AACpB,KAAA,aAAa,EAAE;AACf,KAAA,KAAK,EAAE,CAAC;AAEX,SAAS,cAAc,CAACA,MAAY,EAAA;AAClC,IAAA,MAAM,MAAM,GAAGO,UAAK,CAACP,MAAI,CAAC,CAAC;AAC3B,IAAA,OAAOQ,SAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAG,EAAA,MAAM,CAAC,IAAI,CAAO,KAAA,CAAA,CAAC,CAAC;AACjD;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var parser = require('@babel/parser');
|
|
6
4
|
var es = require('@babel/types');
|
|
7
5
|
|
|
8
|
-
function
|
|
9
|
-
if (e && e.__esModule) return e;
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
10
7
|
var n = Object.create(null);
|
|
11
8
|
if (e) {
|
|
12
9
|
Object.keys(e).forEach(function (k) {
|
|
@@ -19,11 +16,11 @@ function _interopNamespace(e) {
|
|
|
19
16
|
}
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
|
-
n
|
|
19
|
+
n.default = e;
|
|
23
20
|
return Object.freeze(n);
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
var es__namespace = /*#__PURE__*/
|
|
23
|
+
var es__namespace = /*#__PURE__*/_interopNamespaceDefault(es);
|
|
27
24
|
|
|
28
25
|
class CompilerError extends Error {
|
|
29
26
|
constructor(message, source) {
|
|
@@ -598,6 +595,12 @@ const itemNames = [
|
|
|
598
595
|
"sporePod",
|
|
599
596
|
"blastCompound",
|
|
600
597
|
"pyratite",
|
|
598
|
+
"beryllium",
|
|
599
|
+
"tungsten",
|
|
600
|
+
"oxide",
|
|
601
|
+
"carbide",
|
|
602
|
+
"fissileMatter",
|
|
603
|
+
"dormantCyst",
|
|
601
604
|
];
|
|
602
605
|
/**
|
|
603
606
|
* A more type safe version of `Object.assign`
|
|
@@ -1301,11 +1304,14 @@ const ForStatement = (c, parentScope, node) => {
|
|
|
1301
1304
|
: [new LiteralValue(1), []];
|
|
1302
1305
|
const updateLines = node.update ? c.handle(scope, node.update)[1] : [];
|
|
1303
1306
|
const startLoopAddr = new LiteralValue(null);
|
|
1307
|
+
// continue statements jump here to run the loop update lines
|
|
1308
|
+
const beforeEndAddr = new LiteralValue(null);
|
|
1304
1309
|
const endLoopAddr = new LiteralValue(null);
|
|
1305
|
-
const startLoopLine = new AddressResolver(startLoopAddr)
|
|
1310
|
+
const startLoopLine = new AddressResolver(startLoopAddr);
|
|
1306
1311
|
const endLoopLine = new AddressResolver(endLoopAddr).bindBreak(scope);
|
|
1312
|
+
const beforeEndLine = new AddressResolver(beforeEndAddr).bindContinue(scope);
|
|
1307
1313
|
if (parentScope.label) {
|
|
1308
|
-
|
|
1314
|
+
beforeEndLine.bindContinue(parentScope);
|
|
1309
1315
|
}
|
|
1310
1316
|
return [
|
|
1311
1317
|
null,
|
|
@@ -1315,6 +1321,7 @@ const ForStatement = (c, parentScope, node) => {
|
|
|
1315
1321
|
...testLines,
|
|
1316
1322
|
new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(0)),
|
|
1317
1323
|
...withAlwaysRuns(c.handle(scope, node.body), false)[1],
|
|
1324
|
+
beforeEndLine,
|
|
1318
1325
|
...updateLines,
|
|
1319
1326
|
new JumpInstruction(startLoopAddr, EJumpKind.Always),
|
|
1320
1327
|
endLoopLine,
|
|
@@ -1477,6 +1484,14 @@ class FunctionValue extends VoidValue {
|
|
|
1477
1484
|
function endsWithReturn(inst) {
|
|
1478
1485
|
for (let i = inst.length - 1; i >= 0; i--) {
|
|
1479
1486
|
const instruction = inst[i];
|
|
1487
|
+
// this means that there is an instruction trying to reference
|
|
1488
|
+
// the final function `set @counter` instruction
|
|
1489
|
+
// of course this generates an unecessary
|
|
1490
|
+
// `set @counter` in cases where a control flow
|
|
1491
|
+
// structure contains a fallback return statement
|
|
1492
|
+
// TODO: fix this with static analysis
|
|
1493
|
+
if (instruction instanceof AddressResolver)
|
|
1494
|
+
return false;
|
|
1480
1495
|
if (instruction.hidden)
|
|
1481
1496
|
continue;
|
|
1482
1497
|
return instruction instanceof SetCounterInstruction;
|
|
@@ -2094,7 +2109,21 @@ class Control extends ObjectValue {
|
|
|
2094
2109
|
color: { args: ["building", "r", "g", "b"] },
|
|
2095
2110
|
},
|
|
2096
2111
|
handler(scope, overload, ...args) {
|
|
2097
|
-
|
|
2112
|
+
if (overload !== "color")
|
|
2113
|
+
return [null, [new InstructionBase("control", overload, ...args)]];
|
|
2114
|
+
const temp = new StoreValue(scope);
|
|
2115
|
+
temp.ensureOwned();
|
|
2116
|
+
// this "patch" is here for compatibility reasons
|
|
2117
|
+
// I don't want to add another breaking change
|
|
2118
|
+
// TODO: figure out if this patch should be removed later
|
|
2119
|
+
const [building, ...colors] = args;
|
|
2120
|
+
return [
|
|
2121
|
+
null,
|
|
2122
|
+
[
|
|
2123
|
+
new InstructionBase("packcolor", temp, ...colors),
|
|
2124
|
+
new InstructionBase("control", overload, building, temp),
|
|
2125
|
+
],
|
|
2126
|
+
];
|
|
2098
2127
|
},
|
|
2099
2128
|
}));
|
|
2100
2129
|
}
|