mlogjs 0.4.0 → 0.4.1
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/index.cjs +359 -313
- package/dist/index.mjs +359 -313
- package/dist/macros/Asm.d.ts +1 -2
- package/dist/macros/Function.d.ts +2 -2
- package/dist/macros/GetGlobal.d.ts +2 -2
- package/dist/macros/Math.d.ts +1 -2
- package/dist/macros/Memory.d.ts +1 -2
- package/dist/macros/Namespace.d.ts +1 -1
- package/dist/macros/Other.d.ts +1 -2
- package/dist/macros/commands/ApplyStatus.d.ts +1 -2
- package/dist/macros/commands/Control.d.ts +1 -2
- package/dist/macros/commands/Cutscene.d.ts +1 -2
- package/dist/macros/commands/Draw.d.ts +1 -2
- package/dist/macros/commands/DrawFlush.d.ts +1 -2
- package/dist/macros/commands/End.d.ts +1 -2
- package/dist/macros/commands/Explosion.d.ts +1 -2
- package/dist/macros/commands/Fetch.d.ts +1 -2
- package/dist/macros/commands/FlushMessage.d.ts +1 -2
- package/dist/macros/commands/GetBlock.d.ts +1 -2
- package/dist/macros/commands/GetFlag.d.ts +1 -2
- package/dist/macros/commands/GetLink.d.ts +1 -2
- package/dist/macros/commands/Lookup.d.ts +1 -2
- package/dist/macros/commands/PackColor.d.ts +1 -2
- package/dist/macros/commands/Print.d.ts +1 -2
- package/dist/macros/commands/PrintFlush.d.ts +1 -2
- package/dist/macros/commands/Radar.d.ts +1 -2
- package/dist/macros/commands/Sensor.d.ts +1 -2
- package/dist/macros/commands/SetBlock.d.ts +1 -2
- package/dist/macros/commands/SetFlag.d.ts +1 -2
- package/dist/macros/commands/SetRate.d.ts +1 -2
- package/dist/macros/commands/SetRule.d.ts +1 -2
- package/dist/macros/commands/SpawnUnit.d.ts +1 -2
- package/dist/macros/commands/SpawnWave.d.ts +1 -2
- package/dist/macros/commands/Stop.d.ts +1 -2
- package/dist/macros/commands/UnitBind.d.ts +1 -2
- package/dist/macros/commands/UnitControl.d.ts +1 -2
- package/dist/macros/commands/UnitLocate.d.ts +1 -2
- package/dist/macros/commands/UnitRadar.d.ts +1 -2
- package/dist/macros/commands/Wait.d.ts +1 -2
- package/dist/macros/util.d.ts +2 -3
- package/dist/types.d.ts +0 -1
- package/dist/values/BaseValue.d.ts +1 -2
- package/dist/values/DestructuringValue.d.ts +1 -1
- package/dist/values/FunctionValue.d.ts +3 -4
- package/dist/values/LiteralValue.d.ts +3 -2
- package/dist/values/ObjectValue.d.ts +3 -3
- package/dist/values/StoreValue.d.ts +4 -2
- package/dist/values/VoidValue.d.ts +0 -2
- package/lib/commands.d.ts +6 -10
- package/package.json +2 -2
- package/dist/bin.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/types/Compiler.d.ts +0 -39
- package/dist/types/CompilerError.d.ts +0 -33
- package/dist/types/Scope.d.ts +0 -24
- package/dist/types/assertions.d.ts +0 -28
- package/dist/types/bin.d.ts +0 -1
- package/dist/types/handlers/BlockStatement.d.ts +0 -2
- package/dist/types/handlers/CallExpression.d.ts +0 -4
- package/dist/types/handlers/File.d.ts +0 -2
- package/dist/types/handlers/ForStatement.d.ts +0 -2
- package/dist/types/handlers/Function.d.ts +0 -5
- package/dist/types/handlers/Identifier.d.ts +0 -2
- package/dist/types/handlers/IfStatement.d.ts +0 -2
- package/dist/types/handlers/Literal.d.ts +0 -5
- package/dist/types/handlers/Object.d.ts +0 -6
- package/dist/types/handlers/OperationExpressions.d.ts +0 -8
- package/dist/types/handlers/Program.d.ts +0 -2
- package/dist/types/handlers/Statements.d.ts +0 -5
- package/dist/types/handlers/SwitchStatement.d.ts +0 -2
- package/dist/types/handlers/TemplateExpression.d.ts +0 -2
- package/dist/types/handlers/Typescript.d.ts +0 -7
- package/dist/types/handlers/VariableDeclaration.d.ts +0 -3
- package/dist/types/handlers/WhileStatement.d.ts +0 -3
- package/dist/types/handlers/index.d.ts +0 -17
- package/dist/types/index.d.ts +0 -3
- package/dist/types/initScope.d.ts +0 -5
- package/dist/types/instructions/AddressResolver.d.ts +0 -12
- package/dist/types/instructions/ControlInstructions.d.ts +0 -10
- package/dist/types/instructions/EndInstruction.d.ts +0 -4
- package/dist/types/instructions/InstructionBase.d.ts +0 -14
- package/dist/types/instructions/JumpInstruction.d.ts +0 -16
- package/dist/types/instructions/OperationInstruction.d.ts +0 -5
- package/dist/types/instructions/SetCounterInstruction.d.ts +0 -5
- package/dist/types/instructions/SetInstruction.d.ts +0 -6
- package/dist/types/instructions/ZeroSpaceInstruction.d.ts +0 -4
- package/dist/types/instructions/index.d.ts +0 -9
- package/dist/types/macros/Asm.d.ts +0 -5
- package/dist/types/macros/Function.d.ts +0 -13
- package/dist/types/macros/GetGlobal.d.ts +0 -5
- package/dist/types/macros/Math.d.ts +0 -5
- package/dist/types/macros/Memory.d.ts +0 -5
- package/dist/types/macros/Namespace.d.ts +0 -13
- package/dist/types/macros/Other.d.ts +0 -5
- package/dist/types/macros/commands/ApplyStatus.d.ts +0 -5
- package/dist/types/macros/commands/Control.d.ts +0 -5
- package/dist/types/macros/commands/Cutscene.d.ts +0 -5
- package/dist/types/macros/commands/Draw.d.ts +0 -5
- package/dist/types/macros/commands/DrawFlush.d.ts +0 -5
- package/dist/types/macros/commands/End.d.ts +0 -5
- package/dist/types/macros/commands/Explosion.d.ts +0 -5
- package/dist/types/macros/commands/Fetch.d.ts +0 -5
- package/dist/types/macros/commands/FlushMessage.d.ts +0 -5
- package/dist/types/macros/commands/GetBlock.d.ts +0 -5
- package/dist/types/macros/commands/GetFlag.d.ts +0 -5
- package/dist/types/macros/commands/GetLink.d.ts +0 -5
- package/dist/types/macros/commands/Lookup.d.ts +0 -5
- package/dist/types/macros/commands/PackColor.d.ts +0 -5
- package/dist/types/macros/commands/Print.d.ts +0 -5
- package/dist/types/macros/commands/PrintFlush.d.ts +0 -5
- package/dist/types/macros/commands/Radar.d.ts +0 -7
- package/dist/types/macros/commands/Sensor.d.ts +0 -5
- package/dist/types/macros/commands/SetBlock.d.ts +0 -5
- package/dist/types/macros/commands/SetFlag.d.ts +0 -5
- package/dist/types/macros/commands/SetRate.d.ts +0 -5
- package/dist/types/macros/commands/SetRule.d.ts +0 -5
- package/dist/types/macros/commands/SpawnUnit.d.ts +0 -5
- package/dist/types/macros/commands/SpawnWave.d.ts +0 -5
- package/dist/types/macros/commands/Stop.d.ts +0 -5
- package/dist/types/macros/commands/UnitBind.d.ts +0 -5
- package/dist/types/macros/commands/UnitControl.d.ts +0 -5
- package/dist/types/macros/commands/UnitLocate.d.ts +0 -5
- package/dist/types/macros/commands/UnitRadar.d.ts +0 -5
- package/dist/types/macros/commands/Wait.d.ts +0 -5
- package/dist/types/macros/commands/index.d.ts +0 -30
- package/dist/types/macros/index.d.ts +0 -6
- package/dist/types/macros/util.d.ts +0 -18
- package/dist/types/operators.d.ts +0 -25
- package/dist/types/types.d.ts +0 -238
- package/dist/types/utils.d.ts +0 -47
- package/dist/types/values/BaseValue.d.ts +0 -9
- package/dist/types/values/DestructuringValue.d.ts +0 -17
- package/dist/types/values/FunctionValue.d.ts +0 -47
- package/dist/types/values/LiteralValue.d.ts +0 -13
- package/dist/types/values/ObjectValue.d.ts +0 -23
- package/dist/types/values/SenseableValue.d.ts +0 -23
- package/dist/types/values/StoreValue.d.ts +0 -15
- package/dist/types/values/ValueOwner.d.ts +0 -27
- package/dist/types/values/VoidValue.d.ts +0 -16
- package/dist/types/values/index.d.ts +0 -7
package/dist/index.cjs
CHANGED
|
@@ -171,11 +171,10 @@ const singleOperators = [...unaryOperators, ...updateOperators];
|
|
|
171
171
|
const operators = [...leftRightOperators, ...singleOperators];
|
|
172
172
|
|
|
173
173
|
class VoidValue {
|
|
174
|
-
constructor(
|
|
174
|
+
constructor() {
|
|
175
175
|
this.owner = null;
|
|
176
176
|
this.mutability = EMutability.mutable;
|
|
177
177
|
this.macro = false;
|
|
178
|
-
this.scope = scope;
|
|
179
178
|
}
|
|
180
179
|
eval(_scope) {
|
|
181
180
|
throw new CompilerError(`${this} cannot eval.`);
|
|
@@ -312,38 +311,6 @@ class ContinueInstruction extends JumpInstruction {
|
|
|
312
311
|
}
|
|
313
312
|
}
|
|
314
313
|
|
|
315
|
-
class ValueOwner {
|
|
316
|
-
/**
|
|
317
|
-
* Creates a new `ValueOwner`, if `value` is already owned,
|
|
318
|
-
* `this` will be aliased to `value`, else `this` will own `value`
|
|
319
|
-
*/
|
|
320
|
-
constructor({ scope, constant = false, value, identifier, name, }) {
|
|
321
|
-
this.scope = scope;
|
|
322
|
-
this.constant = constant;
|
|
323
|
-
this.value = value;
|
|
324
|
-
this.identifier = identifier;
|
|
325
|
-
this.name = name ?? scope.makeTempName();
|
|
326
|
-
this.persistent = !!name;
|
|
327
|
-
this.owned = new Set();
|
|
328
|
-
if (!value.owner?.persistent)
|
|
329
|
-
this.own(value);
|
|
330
|
-
}
|
|
331
|
-
own(target) {
|
|
332
|
-
target.owner = this;
|
|
333
|
-
this.owned.add(target);
|
|
334
|
-
}
|
|
335
|
-
replace(target) {
|
|
336
|
-
this.value.owner = null;
|
|
337
|
-
this.owned.delete(this.value);
|
|
338
|
-
this.value = target;
|
|
339
|
-
this.own(target);
|
|
340
|
-
}
|
|
341
|
-
moveInto(owner) {
|
|
342
|
-
this.owned.forEach(value => owner.own(value));
|
|
343
|
-
this.owned.clear();
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
314
|
class BaseValue extends VoidValue {
|
|
348
315
|
"u-"(scope) {
|
|
349
316
|
const [that, inst] = this.consume(scope);
|
|
@@ -352,7 +319,7 @@ class BaseValue extends VoidValue {
|
|
|
352
319
|
temp,
|
|
353
320
|
[
|
|
354
321
|
...inst,
|
|
355
|
-
new OperationInstruction("sub", temp, new LiteralValue(
|
|
322
|
+
new OperationInstruction("sub", temp, new LiteralValue(0), that),
|
|
356
323
|
],
|
|
357
324
|
];
|
|
358
325
|
}
|
|
@@ -363,7 +330,7 @@ class BaseValue extends VoidValue {
|
|
|
363
330
|
"!"(scope) {
|
|
364
331
|
const [that, inst] = this.consume(scope);
|
|
365
332
|
const temp = new StoreValue(scope);
|
|
366
|
-
const falseLiteral = new LiteralValue(
|
|
333
|
+
const falseLiteral = new LiteralValue(0);
|
|
367
334
|
return [
|
|
368
335
|
temp,
|
|
369
336
|
[...inst, new OperationInstruction("equal", temp, that, falseLiteral)],
|
|
@@ -374,9 +341,6 @@ class BaseValue extends VoidValue {
|
|
|
374
341
|
const temp = new StoreValue(scope);
|
|
375
342
|
return [temp, [...inst, new OperationInstruction("not", temp, that, null)]];
|
|
376
343
|
}
|
|
377
|
-
ensureOwned() {
|
|
378
|
-
this.owner ??= new ValueOwner({ scope: this.scope, value: this });
|
|
379
|
-
}
|
|
380
344
|
}
|
|
381
345
|
const operatorMap$1 = {
|
|
382
346
|
"==": "equal",
|
|
@@ -452,23 +416,20 @@ for (const key of updateOperators) {
|
|
|
452
416
|
inst.push(...tempInst);
|
|
453
417
|
}
|
|
454
418
|
const kind = key === "++" ? "+=" : "-=";
|
|
455
|
-
return [
|
|
456
|
-
ret,
|
|
457
|
-
[...inst, ...this[kind](scope, new LiteralValue(scope, 1))[1]],
|
|
458
|
-
];
|
|
419
|
+
return [ret, [...inst, ...this[kind](scope, new LiteralValue(1))[1]]];
|
|
459
420
|
};
|
|
460
421
|
}
|
|
461
422
|
|
|
462
423
|
const literalMethods = {
|
|
463
|
-
length: function (
|
|
424
|
+
length: function () {
|
|
464
425
|
if (typeof this.data !== "string")
|
|
465
426
|
throw new CompilerError("Length method only works on string literal values.");
|
|
466
|
-
return new LiteralValue(
|
|
427
|
+
return new LiteralValue(this.data.length);
|
|
467
428
|
},
|
|
468
429
|
};
|
|
469
430
|
class LiteralValue extends BaseValue {
|
|
470
|
-
constructor(
|
|
471
|
-
super(
|
|
431
|
+
constructor(data) {
|
|
432
|
+
super();
|
|
472
433
|
this.mutability = EMutability.constant;
|
|
473
434
|
this.data = data;
|
|
474
435
|
}
|
|
@@ -496,9 +457,10 @@ class LiteralValue extends BaseValue {
|
|
|
496
457
|
return 1;
|
|
497
458
|
return this.data;
|
|
498
459
|
}
|
|
499
|
-
typeof(
|
|
500
|
-
return [new LiteralValue(
|
|
460
|
+
typeof() {
|
|
461
|
+
return [new LiteralValue("literal"), []];
|
|
501
462
|
}
|
|
463
|
+
ensureOwned() { }
|
|
502
464
|
}
|
|
503
465
|
const operatorMap = {
|
|
504
466
|
"==": (a, b) => +(a == b),
|
|
@@ -530,10 +492,7 @@ for (const key in operatorMap) {
|
|
|
530
492
|
if (!(value instanceof LiteralValue)) {
|
|
531
493
|
return BaseValue.prototype[key].apply(this, [scope, value]);
|
|
532
494
|
}
|
|
533
|
-
return [
|
|
534
|
-
new LiteralValue(scope, fn(this.data, value.data)),
|
|
535
|
-
[],
|
|
536
|
-
];
|
|
495
|
+
return [new LiteralValue(fn(this.data, value.data)), []];
|
|
537
496
|
};
|
|
538
497
|
}
|
|
539
498
|
const unaryOperatorMap = {
|
|
@@ -543,9 +502,9 @@ const unaryOperatorMap = {
|
|
|
543
502
|
"u+": v => +v,
|
|
544
503
|
};
|
|
545
504
|
for (const key in unaryOperatorMap) {
|
|
546
|
-
LiteralValue.prototype[key] = function (
|
|
505
|
+
LiteralValue.prototype[key] = function () {
|
|
547
506
|
const fn = unaryOperatorMap[key];
|
|
548
|
-
return [new LiteralValue(
|
|
507
|
+
return [new LiteralValue(fn(this.data)), []];
|
|
549
508
|
};
|
|
550
509
|
}
|
|
551
510
|
|
|
@@ -624,17 +583,50 @@ function isTemplateObjectArray(value) {
|
|
|
624
583
|
typeof value.data.raw.data.length.data === "number");
|
|
625
584
|
}
|
|
626
585
|
|
|
586
|
+
class ValueOwner {
|
|
587
|
+
/**
|
|
588
|
+
* Creates a new `ValueOwner`, if `value` is already owned,
|
|
589
|
+
* `this` will be aliased to `value`, else `this` will own `value`
|
|
590
|
+
*/
|
|
591
|
+
constructor({ scope, constant = false, value, identifier, name, }) {
|
|
592
|
+
this.scope = scope;
|
|
593
|
+
this.constant = constant;
|
|
594
|
+
this.value = value;
|
|
595
|
+
this.identifier = identifier;
|
|
596
|
+
this.name = name ?? scope.makeTempName();
|
|
597
|
+
this.persistent = !!name;
|
|
598
|
+
this.owned = new Set();
|
|
599
|
+
if (!value.owner?.persistent)
|
|
600
|
+
this.own(value);
|
|
601
|
+
}
|
|
602
|
+
own(target) {
|
|
603
|
+
target.owner = this;
|
|
604
|
+
this.owned.add(target);
|
|
605
|
+
}
|
|
606
|
+
replace(target) {
|
|
607
|
+
this.value.owner = null;
|
|
608
|
+
this.owned.delete(this.value);
|
|
609
|
+
this.value = target;
|
|
610
|
+
this.own(target);
|
|
611
|
+
}
|
|
612
|
+
moveInto(owner) {
|
|
613
|
+
this.owned.forEach(value => owner.own(value));
|
|
614
|
+
this.owned.clear();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
627
618
|
/**
|
|
628
619
|
* `StoreValue` represents values unknown at compile time,
|
|
629
620
|
* mostly used with mutable variables and temporary values
|
|
630
621
|
*/
|
|
631
622
|
class StoreValue extends BaseValue {
|
|
632
623
|
constructor(scope) {
|
|
633
|
-
super(
|
|
624
|
+
super();
|
|
625
|
+
this.scope = scope;
|
|
634
626
|
this.mutability = EMutability.mutable;
|
|
635
627
|
}
|
|
636
|
-
typeof(
|
|
637
|
-
return [new LiteralValue(
|
|
628
|
+
typeof() {
|
|
629
|
+
return [new LiteralValue("store"), []];
|
|
638
630
|
}
|
|
639
631
|
"="(scope, value) {
|
|
640
632
|
if (this.mutability !== EMutability.mutable)
|
|
@@ -661,31 +653,34 @@ class StoreValue extends BaseValue {
|
|
|
661
653
|
this.ensureOwned();
|
|
662
654
|
return [this, []];
|
|
663
655
|
}
|
|
656
|
+
ensureOwned() {
|
|
657
|
+
this.owner ??= new ValueOwner({ scope: this.scope, value: this });
|
|
658
|
+
}
|
|
664
659
|
toString() {
|
|
665
660
|
return this.owner?.name ?? discardedName;
|
|
666
661
|
}
|
|
667
662
|
}
|
|
668
663
|
|
|
669
664
|
class ObjectValue extends VoidValue {
|
|
670
|
-
constructor(
|
|
671
|
-
super(
|
|
665
|
+
constructor(data = {}) {
|
|
666
|
+
super();
|
|
672
667
|
this.mutability = EMutability.constant;
|
|
673
668
|
this.macro = true;
|
|
674
669
|
this.data = data;
|
|
675
670
|
}
|
|
676
|
-
static fromArray(
|
|
671
|
+
static fromArray(items, intialData) {
|
|
677
672
|
const data = {
|
|
678
673
|
...intialData,
|
|
679
|
-
length: new LiteralValue(
|
|
674
|
+
length: new LiteralValue(items.length),
|
|
680
675
|
};
|
|
681
676
|
items.forEach((item, i) => {
|
|
682
677
|
if (item)
|
|
683
678
|
data[i] = item;
|
|
684
679
|
});
|
|
685
|
-
return new ObjectValue(
|
|
680
|
+
return new ObjectValue(data);
|
|
686
681
|
}
|
|
687
|
-
typeof(
|
|
688
|
-
return [new LiteralValue(
|
|
682
|
+
typeof() {
|
|
683
|
+
return [new LiteralValue("object"), []];
|
|
689
684
|
}
|
|
690
685
|
get(scope, key) {
|
|
691
686
|
// avoids naming collisions with keys like
|
|
@@ -722,9 +717,7 @@ class ObjectValue extends VoidValue {
|
|
|
722
717
|
return super.call(scope, args);
|
|
723
718
|
return $call.call(scope, args);
|
|
724
719
|
}
|
|
725
|
-
ensureOwned() {
|
|
726
|
-
this.owner ??= new ValueOwner({ scope: this.scope, value: this });
|
|
727
|
-
}
|
|
720
|
+
ensureOwned() { }
|
|
728
721
|
}
|
|
729
722
|
for (const op of operators) {
|
|
730
723
|
ObjectValue.prototype[op] = function (...args) {
|
|
@@ -793,8 +786,8 @@ class SenseableValue extends StoreValue {
|
|
|
793
786
|
* each of them to their counterparts on the right hand value.
|
|
794
787
|
*/
|
|
795
788
|
class DestructuringValue extends VoidValue {
|
|
796
|
-
constructor(
|
|
797
|
-
super(
|
|
789
|
+
constructor(members) {
|
|
790
|
+
super();
|
|
798
791
|
this.members = members;
|
|
799
792
|
this.macro = true;
|
|
800
793
|
}
|
|
@@ -981,7 +974,7 @@ const DeclareObjectPattern = (c, scope, node, kind, base) => {
|
|
|
981
974
|
throw new CompilerError("The rest operator is not supported", prop);
|
|
982
975
|
const { key, value } = prop;
|
|
983
976
|
const keyInst = key.type === "Identifier" && !prop.computed
|
|
984
|
-
? [new LiteralValue(
|
|
977
|
+
? [new LiteralValue(key.name), []]
|
|
985
978
|
: c.handleConsume(scope, prop.key);
|
|
986
979
|
const propInit = init.get(scope, keyInst[0]);
|
|
987
980
|
const declarationInst = Declare(c, scope, value, kind, propInit[0]);
|
|
@@ -990,14 +983,14 @@ const DeclareObjectPattern = (c, scope, node, kind, base) => {
|
|
|
990
983
|
return [null, [...inst, ...propertiesInst[1]]];
|
|
991
984
|
};
|
|
992
985
|
|
|
993
|
-
const Literal = (_c, scope, node) => [new LiteralValue(
|
|
986
|
+
const Literal = (_c, scope, node) => [new LiteralValue(node.value), []];
|
|
994
987
|
const NumericLiteral = Literal;
|
|
995
988
|
const StringLiteral = Literal;
|
|
996
|
-
const NullLiteral = (
|
|
997
|
-
new LiteralValue(
|
|
989
|
+
const NullLiteral = () => [
|
|
990
|
+
new LiteralValue(null),
|
|
998
991
|
[],
|
|
999
992
|
];
|
|
1000
|
-
const BooleanLiteral = (_c, scope, node) => [new LiteralValue(
|
|
993
|
+
const BooleanLiteral = (_c, scope, node) => [new LiteralValue(+node.value), []];
|
|
1001
994
|
|
|
1002
995
|
const LRExpression = (c, scope, node) => {
|
|
1003
996
|
const [left, leftInst] = c.handleConsume(scope, node.left);
|
|
@@ -1009,8 +1002,8 @@ const BinaryExpression = LRExpression;
|
|
|
1009
1002
|
const LogicalExpression = (c, scope, node) => {
|
|
1010
1003
|
if (node.operator !== "??")
|
|
1011
1004
|
return LRExpression(c, scope, node);
|
|
1012
|
-
const nullLiteral = new LiteralValue(
|
|
1013
|
-
const endAdress = new LiteralValue(
|
|
1005
|
+
const nullLiteral = new LiteralValue(null);
|
|
1006
|
+
const endAdress = new LiteralValue(null);
|
|
1014
1007
|
const [left, leftInst] = c.handleEval(scope, node.left);
|
|
1015
1008
|
const [nullTest] = left["=="](scope, nullLiteral);
|
|
1016
1009
|
if (nullTest instanceof LiteralValue) {
|
|
@@ -1069,13 +1062,13 @@ const ConditionalExpression = (c, scope, node) => {
|
|
|
1069
1062
|
result.ensureOwned();
|
|
1070
1063
|
const consequent = c.handleEval(scope, node.consequent);
|
|
1071
1064
|
const alternate = c.handleEval(scope, node.alternate);
|
|
1072
|
-
const alternateStartAdress = new LiteralValue(
|
|
1073
|
-
const endExpressionAdress = new LiteralValue(
|
|
1065
|
+
const alternateStartAdress = new LiteralValue(null);
|
|
1066
|
+
const endExpressionAdress = new LiteralValue(null);
|
|
1074
1067
|
return [
|
|
1075
1068
|
result,
|
|
1076
1069
|
[
|
|
1077
1070
|
...testInst,
|
|
1078
|
-
new JumpInstruction(alternateStartAdress, EJumpKind.Equal, test, new LiteralValue(
|
|
1071
|
+
new JumpInstruction(alternateStartAdress, EJumpKind.Equal, test, new LiteralValue(0)),
|
|
1079
1072
|
...consequent[1],
|
|
1080
1073
|
...result["="](scope, consequent[0])[1],
|
|
1081
1074
|
new JumpInstruction(endExpressionAdress, EJumpKind.Always),
|
|
@@ -1095,12 +1088,12 @@ const ExpressionStatement = (c, scope, node) => {
|
|
|
1095
1088
|
return c.handle(scope, node.expression);
|
|
1096
1089
|
};
|
|
1097
1090
|
const BreakStatement = (_, scope) => {
|
|
1098
|
-
const addr = new LiteralValue(
|
|
1091
|
+
const addr = new LiteralValue(null);
|
|
1099
1092
|
scope.break.bind(addr);
|
|
1100
1093
|
return [null, [new BreakInstruction(addr)]];
|
|
1101
1094
|
};
|
|
1102
1095
|
const ContinueStatement = (_, scope) => {
|
|
1103
|
-
const addr = new LiteralValue(
|
|
1096
|
+
const addr = new LiteralValue(null);
|
|
1104
1097
|
scope.continue.bind(addr);
|
|
1105
1098
|
return [null, [new ContinueInstruction(addr)]];
|
|
1106
1099
|
};
|
|
@@ -1122,9 +1115,9 @@ const IfStatement = (c, scope, node) => {
|
|
|
1122
1115
|
inst.push(...c.handle(scope, node.alternate)[1]);
|
|
1123
1116
|
return [null, inst];
|
|
1124
1117
|
}
|
|
1125
|
-
const endIfAddr = new LiteralValue(
|
|
1126
|
-
inst.push(...testInst, new JumpInstruction(endIfAddr, EJumpKind.Equal, test, new LiteralValue(
|
|
1127
|
-
const endElseAddr = new LiteralValue(
|
|
1118
|
+
const endIfAddr = new LiteralValue(null);
|
|
1119
|
+
inst.push(...testInst, new JumpInstruction(endIfAddr, EJumpKind.Equal, test, new LiteralValue(0)), ...withAlwaysRuns(c.handle(scope, node.consequent), false)[1], new AddressResolver(endIfAddr));
|
|
1120
|
+
const endElseAddr = new LiteralValue(null);
|
|
1128
1121
|
if (node.alternate) {
|
|
1129
1122
|
inst.push(new JumpInstruction(endElseAddr, EJumpKind.Always), new AddressResolver(endIfAddr), ...withAlwaysRuns(c.handle(scope, node.alternate), false)[1], new AddressResolver(endElseAddr));
|
|
1130
1123
|
}
|
|
@@ -1135,13 +1128,13 @@ const SwitchStatement = (c, scope, node) => {
|
|
|
1135
1128
|
const innerScope = scope.createScope();
|
|
1136
1129
|
const [ref, refInst] = c.handleConsume(scope, node.discriminant);
|
|
1137
1130
|
const inst = [];
|
|
1138
|
-
const endAdress = new LiteralValue(
|
|
1131
|
+
const endAdress = new LiteralValue(null);
|
|
1139
1132
|
const endLine = new AddressResolver(endAdress).bindBreak(innerScope);
|
|
1140
1133
|
const caseJumps = [];
|
|
1141
1134
|
let defaultJump;
|
|
1142
1135
|
for (const scase of node.cases) {
|
|
1143
1136
|
const [, bodyInst] = c.handleMany(innerScope, scase.consequent);
|
|
1144
|
-
const bodyAdress = new LiteralValue(
|
|
1137
|
+
const bodyAdress = new LiteralValue(null);
|
|
1145
1138
|
const bodyLine = new AddressResolver(bodyAdress);
|
|
1146
1139
|
if (!scase.test) {
|
|
1147
1140
|
[defaultJump] = c.handle(innerScope, scase, () => [
|
|
@@ -1195,8 +1188,8 @@ const SwitchStatement = (c, scope, node) => {
|
|
|
1195
1188
|
const WhileStatement = (c, scope, node) => {
|
|
1196
1189
|
const lines = [];
|
|
1197
1190
|
const [test, testLines] = c.handleConsume(scope, node.test);
|
|
1198
|
-
const startLoopAddr = new LiteralValue(
|
|
1199
|
-
const endLoopAddr = new LiteralValue(
|
|
1191
|
+
const startLoopAddr = new LiteralValue(null);
|
|
1192
|
+
const endLoopAddr = new LiteralValue(null);
|
|
1200
1193
|
const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
|
|
1201
1194
|
const endLoopLine = new AddressResolver(endLoopAddr).bindBreak(scope);
|
|
1202
1195
|
if (test instanceof LiteralValue) {
|
|
@@ -1205,13 +1198,13 @@ const WhileStatement = (c, scope, node) => {
|
|
|
1205
1198
|
}
|
|
1206
1199
|
return [null, lines];
|
|
1207
1200
|
}
|
|
1208
|
-
lines.push(startLoopLine, ...testLines, new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(
|
|
1201
|
+
lines.push(startLoopLine, ...testLines, new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(0)), ...withAlwaysRuns(c.handle(scope, node.body), false)[1], new JumpInstruction(startLoopAddr, EJumpKind.Always), endLoopLine);
|
|
1209
1202
|
return [null, lines];
|
|
1210
1203
|
};
|
|
1211
1204
|
const DoWhileStatement = (c, scope, node) => {
|
|
1212
1205
|
const lines = [];
|
|
1213
1206
|
const [test, testLines] = c.handleConsume(scope, node.test);
|
|
1214
|
-
const startLoopAddr = new LiteralValue(
|
|
1207
|
+
const startLoopAddr = new LiteralValue(null);
|
|
1215
1208
|
const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
|
|
1216
1209
|
const [, bodyLines] = c.handle(scope, node.body);
|
|
1217
1210
|
if (test instanceof LiteralValue) {
|
|
@@ -1227,7 +1220,7 @@ const DoWhileStatement = (c, scope, node) => {
|
|
|
1227
1220
|
],
|
|
1228
1221
|
];
|
|
1229
1222
|
}
|
|
1230
|
-
lines.push(startLoopLine, ...bodyLines, ...testLines, new JumpInstruction(startLoopAddr, EJumpKind.Equal, test, new LiteralValue(
|
|
1223
|
+
lines.push(startLoopLine, ...bodyLines, ...testLines, new JumpInstruction(startLoopAddr, EJumpKind.Equal, test, new LiteralValue(1)));
|
|
1231
1224
|
return [null, lines];
|
|
1232
1225
|
};
|
|
1233
1226
|
|
|
@@ -1236,10 +1229,10 @@ const ForStatement = (c, scope, node) => {
|
|
|
1236
1229
|
const initInst = node.init ? c.handle(scope, node.init)[1] : [];
|
|
1237
1230
|
const [test, testLines] = node.test
|
|
1238
1231
|
? c.handleConsume(scope, node.test)
|
|
1239
|
-
: [new LiteralValue(
|
|
1232
|
+
: [new LiteralValue(1), []];
|
|
1240
1233
|
const updateLines = node.update ? c.handle(scope, node.update)[1] : [];
|
|
1241
|
-
const startLoopAddr = new LiteralValue(
|
|
1242
|
-
const endLoopAddr = new LiteralValue(
|
|
1234
|
+
const startLoopAddr = new LiteralValue(null);
|
|
1235
|
+
const endLoopAddr = new LiteralValue(null);
|
|
1243
1236
|
const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
|
|
1244
1237
|
const endLoopLine = new AddressResolver(endLoopAddr).bindBreak(scope);
|
|
1245
1238
|
return [
|
|
@@ -1248,7 +1241,7 @@ const ForStatement = (c, scope, node) => {
|
|
|
1248
1241
|
...initInst,
|
|
1249
1242
|
startLoopLine,
|
|
1250
1243
|
...testLines,
|
|
1251
|
-
new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(
|
|
1244
|
+
new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(0)),
|
|
1252
1245
|
...withAlwaysRuns(c.handle(scope, node.body), false)[1],
|
|
1253
1246
|
...updateLines,
|
|
1254
1247
|
new JumpInstruction(startLoopAddr, EJumpKind.Always),
|
|
@@ -1258,20 +1251,20 @@ const ForStatement = (c, scope, node) => {
|
|
|
1258
1251
|
};
|
|
1259
1252
|
|
|
1260
1253
|
class FunctionValue extends VoidValue {
|
|
1261
|
-
constructor({ scope, params, body, c,
|
|
1262
|
-
super(
|
|
1254
|
+
constructor({ scope, params, body, c, }) {
|
|
1255
|
+
super();
|
|
1263
1256
|
this.mutability = EMutability.constant;
|
|
1264
1257
|
this.macro = true;
|
|
1265
1258
|
this.paramOwners = [];
|
|
1266
1259
|
this.bundled = false;
|
|
1267
1260
|
this.initialized = false;
|
|
1261
|
+
this.scope = scope;
|
|
1268
1262
|
this.body = body;
|
|
1269
1263
|
this.c = c;
|
|
1270
|
-
this.node = node;
|
|
1271
1264
|
this.params = params;
|
|
1272
1265
|
}
|
|
1273
|
-
typeof(
|
|
1274
|
-
return [new LiteralValue(
|
|
1266
|
+
typeof() {
|
|
1267
|
+
return [new LiteralValue("function"), []];
|
|
1275
1268
|
}
|
|
1276
1269
|
initScope(name) {
|
|
1277
1270
|
this.childScope = this.scope.createFunction(name);
|
|
@@ -1299,7 +1292,7 @@ class FunctionValue extends VoidValue {
|
|
|
1299
1292
|
this.initialized = true;
|
|
1300
1293
|
const { name } = this.owner;
|
|
1301
1294
|
this.initScope(name);
|
|
1302
|
-
this.addr = new LiteralValue(
|
|
1295
|
+
this.addr = new LiteralValue(null);
|
|
1303
1296
|
this.temp = new ValueOwner({
|
|
1304
1297
|
scope: this.childScope,
|
|
1305
1298
|
name: `${internalPrefix}f${name}`,
|
|
@@ -1333,7 +1326,7 @@ class FunctionValue extends VoidValue {
|
|
|
1333
1326
|
if (!this.bundled)
|
|
1334
1327
|
this.childScope.inst.push(...this.inst);
|
|
1335
1328
|
this.bundled = true;
|
|
1336
|
-
const callAddressLiteral = new LiteralValue(
|
|
1329
|
+
const callAddressLiteral = new LiteralValue(null);
|
|
1337
1330
|
const inst = this.paramOwners
|
|
1338
1331
|
.map(({ value: param }, i) => param["="](scope, args[i])[1])
|
|
1339
1332
|
.reduce((s, c) => s.concat(c), [])
|
|
@@ -1371,7 +1364,7 @@ class FunctionValue extends VoidValue {
|
|
|
1371
1364
|
name: owner.name,
|
|
1372
1365
|
}));
|
|
1373
1366
|
});
|
|
1374
|
-
this.inlineEnd = new LiteralValue(
|
|
1367
|
+
this.inlineEnd = new LiteralValue(null);
|
|
1375
1368
|
this.tryingInline = true;
|
|
1376
1369
|
let inst = this.c.handle(fnScope, this.body)[1];
|
|
1377
1370
|
this.tryingInline = false;
|
|
@@ -1430,7 +1423,6 @@ function handleFunctionNode(c, scope, node) {
|
|
|
1430
1423
|
}
|
|
1431
1424
|
return [
|
|
1432
1425
|
new FunctionValue({
|
|
1433
|
-
node,
|
|
1434
1426
|
scope,
|
|
1435
1427
|
params: params,
|
|
1436
1428
|
body,
|
|
@@ -1476,8 +1468,8 @@ const NewExpression = CallExpression;
|
|
|
1476
1468
|
const TaggedTemplateExpression = (c, scope, node) => {
|
|
1477
1469
|
const [tag, tagInst] = c.handleConsume(scope, node.tag);
|
|
1478
1470
|
const template = node.quasi;
|
|
1479
|
-
const stringsObject = ObjectValue.fromArray(
|
|
1480
|
-
raw: ObjectValue.fromArray(
|
|
1471
|
+
const stringsObject = ObjectValue.fromArray(template.quasis.map(quasi => new LiteralValue(quasi.value.cooked ?? "")), {
|
|
1472
|
+
raw: ObjectValue.fromArray(template.quasis.map(quasi => new LiteralValue(quasi.value.raw))),
|
|
1481
1473
|
});
|
|
1482
1474
|
const expressions = [];
|
|
1483
1475
|
const expressionInsts = [];
|
|
@@ -1522,7 +1514,7 @@ const ObjectExpression = (c, scope, node) => {
|
|
|
1522
1514
|
data[index] = member;
|
|
1523
1515
|
inst.push(...memberInst);
|
|
1524
1516
|
}
|
|
1525
|
-
return [new ObjectValue(
|
|
1517
|
+
return [new ObjectValue(data), inst];
|
|
1526
1518
|
};
|
|
1527
1519
|
const ArrayExpression = (c, scope, node) => {
|
|
1528
1520
|
const items = [];
|
|
@@ -1534,13 +1526,13 @@ const ArrayExpression = (c, scope, node) => {
|
|
|
1534
1526
|
items.push(value);
|
|
1535
1527
|
inst.push(...valueInst);
|
|
1536
1528
|
});
|
|
1537
|
-
return [ObjectValue.fromArray(
|
|
1529
|
+
return [ObjectValue.fromArray(items), inst];
|
|
1538
1530
|
};
|
|
1539
1531
|
const MemberExpression = (c, scope, node) => {
|
|
1540
1532
|
const [obj, objInst] = c.handleConsume(scope, node.object);
|
|
1541
1533
|
const [prop, propInst] = node.computed
|
|
1542
1534
|
? c.handleConsume(scope, node.property)
|
|
1543
|
-
: [new LiteralValue(
|
|
1535
|
+
: [new LiteralValue(node.property.name), []];
|
|
1544
1536
|
const [got, gotInst] = obj.get(scope, prop);
|
|
1545
1537
|
return [got, [...objInst, ...propInst, ...gotInst]];
|
|
1546
1538
|
};
|
|
@@ -1555,9 +1547,9 @@ const ArrayPattern = (c, scope, node) => {
|
|
|
1555
1547
|
if (!valueInst[0])
|
|
1556
1548
|
throw new CompilerError("Destructuring element must resolve to a value", element);
|
|
1557
1549
|
inst.push(...valueInst[1]);
|
|
1558
|
-
members.set(new LiteralValue(
|
|
1550
|
+
members.set(new LiteralValue(i), valueInst[0]);
|
|
1559
1551
|
}
|
|
1560
|
-
return [new DestructuringValue(
|
|
1552
|
+
return [new DestructuringValue(members), inst];
|
|
1561
1553
|
};
|
|
1562
1554
|
const ObjectPattern = (c, scope, node) => {
|
|
1563
1555
|
const inst = [];
|
|
@@ -1569,7 +1561,7 @@ const ObjectPattern = (c, scope, node) => {
|
|
|
1569
1561
|
continue;
|
|
1570
1562
|
const { key } = prop;
|
|
1571
1563
|
const keyInst = !prop.computed && key.type === "Identifier"
|
|
1572
|
-
? [new LiteralValue(
|
|
1564
|
+
? [new LiteralValue(key.name), []]
|
|
1573
1565
|
: c.handleConsume(scope, prop.key);
|
|
1574
1566
|
inst.push(...keyInst[1]);
|
|
1575
1567
|
const valueInst = c.handle(scope, prop.value);
|
|
@@ -1578,7 +1570,7 @@ const ObjectPattern = (c, scope, node) => {
|
|
|
1578
1570
|
inst.push(...valueInst[1]);
|
|
1579
1571
|
members.set(keyInst[0], valueInst[0]);
|
|
1580
1572
|
}
|
|
1581
|
-
return [new DestructuringValue(
|
|
1573
|
+
return [new DestructuringValue(members), inst];
|
|
1582
1574
|
};
|
|
1583
1575
|
|
|
1584
1576
|
const TemplateLiteral = () => {
|
|
@@ -1618,7 +1610,7 @@ const TSEnumDeclaration = (c, scope, node) => {
|
|
|
1618
1610
|
throw new CompilerError("This enum member must be initialized", member);
|
|
1619
1611
|
const [value] = member.initializer
|
|
1620
1612
|
? c.handleEval(scope, member.initializer)
|
|
1621
|
-
: [new LiteralValue(
|
|
1613
|
+
: [new LiteralValue(counter)];
|
|
1622
1614
|
if (!(value instanceof LiteralValue))
|
|
1623
1615
|
throw new CompilerError("Enum members must contain literal values", member);
|
|
1624
1616
|
if (typeof value.data === "number") {
|
|
@@ -1633,7 +1625,7 @@ const TSEnumDeclaration = (c, scope, node) => {
|
|
|
1633
1625
|
}
|
|
1634
1626
|
scope.set(new ValueOwner({
|
|
1635
1627
|
scope,
|
|
1636
|
-
value: new ObjectValue(
|
|
1628
|
+
value: new ObjectValue(data),
|
|
1637
1629
|
constant: true,
|
|
1638
1630
|
identifier: node.id.name,
|
|
1639
1631
|
name: nodeName(node, !c.compactNames && node.id.name),
|
|
@@ -1694,14 +1686,14 @@ var handlers = /*#__PURE__*/Object.freeze({
|
|
|
1694
1686
|
});
|
|
1695
1687
|
|
|
1696
1688
|
class MacroFunction extends VoidValue {
|
|
1697
|
-
constructor(
|
|
1698
|
-
super(
|
|
1689
|
+
constructor(fn) {
|
|
1690
|
+
super();
|
|
1699
1691
|
this.macro = true;
|
|
1700
1692
|
this.constant = true;
|
|
1701
1693
|
this.fn = fn;
|
|
1702
1694
|
}
|
|
1703
1695
|
call(scope, args) {
|
|
1704
|
-
return this.fn.apply(this, args);
|
|
1696
|
+
return this.fn.apply(this, [scope, ...args]);
|
|
1705
1697
|
}
|
|
1706
1698
|
eval(_scope) {
|
|
1707
1699
|
return [this, []];
|
|
@@ -1732,16 +1724,16 @@ const mathOperations = {
|
|
|
1732
1724
|
sqrt: a => Math.sqrt(a),
|
|
1733
1725
|
rand: null,
|
|
1734
1726
|
};
|
|
1735
|
-
function createMacroMathOperations(
|
|
1727
|
+
function createMacroMathOperations() {
|
|
1736
1728
|
const macroMathOperations = {};
|
|
1737
1729
|
for (const key in mathOperations) {
|
|
1738
1730
|
const fn = mathOperations[key];
|
|
1739
|
-
macroMathOperations[key] = new MacroFunction(scope,
|
|
1731
|
+
macroMathOperations[key] = new MacroFunction((scope, a, b) => {
|
|
1740
1732
|
if (b) {
|
|
1741
1733
|
if (fn && a instanceof LiteralValue && b instanceof LiteralValue) {
|
|
1742
1734
|
if (typeof a.data !== "number" || typeof b.data !== "number")
|
|
1743
1735
|
throw new CompilerError("Cannot do math operation with non-numerical literals.");
|
|
1744
|
-
return [new LiteralValue(
|
|
1736
|
+
return [new LiteralValue(fn(a.num, b.num)), []];
|
|
1745
1737
|
}
|
|
1746
1738
|
const temp = new StoreValue(scope);
|
|
1747
1739
|
return [temp, [new OperationInstruction(key, temp, a, b)]];
|
|
@@ -1749,7 +1741,7 @@ function createMacroMathOperations(scope) {
|
|
|
1749
1741
|
if (fn && a instanceof LiteralValue) {
|
|
1750
1742
|
if (typeof a.data !== "number")
|
|
1751
1743
|
throw new CompilerError("Cannot do math operation with non-numerical literal.");
|
|
1752
|
-
return [new LiteralValue(
|
|
1744
|
+
return [new LiteralValue(fn(a.num)), []];
|
|
1753
1745
|
}
|
|
1754
1746
|
const temp = new StoreValue(scope);
|
|
1755
1747
|
return [temp, [new OperationInstruction(key, temp, a, b)]];
|
|
@@ -1758,21 +1750,21 @@ function createMacroMathOperations(scope) {
|
|
|
1758
1750
|
return macroMathOperations;
|
|
1759
1751
|
}
|
|
1760
1752
|
class MlogMath extends ObjectValue {
|
|
1761
|
-
constructor(
|
|
1762
|
-
super(
|
|
1753
|
+
constructor() {
|
|
1754
|
+
super(createMacroMathOperations());
|
|
1763
1755
|
}
|
|
1764
1756
|
}
|
|
1765
1757
|
// op angle result a b
|
|
1766
1758
|
// op len result a b
|
|
1767
1759
|
|
|
1768
1760
|
class Concat extends MacroFunction {
|
|
1769
|
-
constructor(
|
|
1770
|
-
super(scope,
|
|
1761
|
+
constructor() {
|
|
1762
|
+
super((scope, ...values) => {
|
|
1771
1763
|
for (const value of values)
|
|
1772
1764
|
if (!(value instanceof LiteralValue))
|
|
1773
1765
|
throw new CompilerError("Concat arguments must all be literal values.");
|
|
1774
1766
|
return [
|
|
1775
|
-
new LiteralValue(
|
|
1767
|
+
new LiteralValue(values.map(v => v.data).join("")),
|
|
1776
1768
|
[],
|
|
1777
1769
|
];
|
|
1778
1770
|
});
|
|
@@ -1827,18 +1819,18 @@ function assertObjectFields(value, fields) {
|
|
|
1827
1819
|
}
|
|
1828
1820
|
|
|
1829
1821
|
/** Used to create namespaces that contain multiple methods that map into instructions */
|
|
1830
|
-
function createOverloadNamespace({
|
|
1822
|
+
function createOverloadNamespace({ overloads, handler, }) {
|
|
1831
1823
|
const result = {};
|
|
1832
1824
|
for (const key in overloads) {
|
|
1833
1825
|
const { named, args } = overloads[key];
|
|
1834
1826
|
if (named) {
|
|
1835
|
-
result[key] = new MacroFunction(scope, options => {
|
|
1827
|
+
result[key] = new MacroFunction((scope, options) => {
|
|
1836
1828
|
assertIsObjectMacro(options, named);
|
|
1837
|
-
return handler(key, ...assertObjectFields(options, args));
|
|
1829
|
+
return handler(scope, key, ...assertObjectFields(options, args));
|
|
1838
1830
|
});
|
|
1839
1831
|
continue;
|
|
1840
1832
|
}
|
|
1841
|
-
result[key] = new MacroFunction(scope,
|
|
1833
|
+
result[key] = new MacroFunction((scope, ...params) => {
|
|
1842
1834
|
const handlerParams = [];
|
|
1843
1835
|
// validate the paramters
|
|
1844
1836
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -1855,16 +1847,15 @@ function createOverloadNamespace({ scope, overloads, handler, }) {
|
|
|
1855
1847
|
arg.validate?.(param);
|
|
1856
1848
|
handlerParams.push(param);
|
|
1857
1849
|
}
|
|
1858
|
-
return handler(key, ...handlerParams);
|
|
1850
|
+
return handler(scope, key, ...handlerParams);
|
|
1859
1851
|
});
|
|
1860
1852
|
}
|
|
1861
1853
|
return result;
|
|
1862
1854
|
}
|
|
1863
1855
|
|
|
1864
1856
|
class Draw extends ObjectValue {
|
|
1865
|
-
constructor(
|
|
1857
|
+
constructor() {
|
|
1866
1858
|
const data = createOverloadNamespace({
|
|
1867
|
-
scope,
|
|
1868
1859
|
overloads: {
|
|
1869
1860
|
clear: {
|
|
1870
1861
|
args: ["r", "g", "b"],
|
|
@@ -1901,17 +1892,17 @@ class Draw extends ObjectValue {
|
|
|
1901
1892
|
args: ["x", "y", "image", "size", "rotation"],
|
|
1902
1893
|
},
|
|
1903
1894
|
},
|
|
1904
|
-
handler(overload, ...args) {
|
|
1895
|
+
handler(scope, overload, ...args) {
|
|
1905
1896
|
return [null, [new InstructionBase("draw", overload, ...args)]];
|
|
1906
1897
|
},
|
|
1907
1898
|
});
|
|
1908
|
-
super(
|
|
1899
|
+
super(data);
|
|
1909
1900
|
}
|
|
1910
1901
|
}
|
|
1911
1902
|
|
|
1912
1903
|
class Print extends MacroFunction {
|
|
1913
|
-
constructor(
|
|
1914
|
-
super(scope,
|
|
1904
|
+
constructor() {
|
|
1905
|
+
super((scope, ...values) => {
|
|
1915
1906
|
const [first] = values;
|
|
1916
1907
|
const inst = [];
|
|
1917
1908
|
if (!isTemplateObjectArray(first)) {
|
|
@@ -1924,12 +1915,12 @@ class Print extends MacroFunction {
|
|
|
1924
1915
|
// maybe this should be checked in another way?
|
|
1925
1916
|
const { length } = first.data;
|
|
1926
1917
|
for (let i = 1; i < values.length; i++) {
|
|
1927
|
-
const [string] = first.get(scope, new LiteralValue(
|
|
1918
|
+
const [string] = first.get(scope, new LiteralValue(i - 1));
|
|
1928
1919
|
if (string.data)
|
|
1929
1920
|
inst.push(new InstructionBase("print", string));
|
|
1930
1921
|
inst.push(new InstructionBase("print", values[i]));
|
|
1931
1922
|
}
|
|
1932
|
-
const [tail] = first.get(scope, new LiteralValue(
|
|
1923
|
+
const [tail] = first.get(scope, new LiteralValue(length.data - 1));
|
|
1933
1924
|
if (tail.data)
|
|
1934
1925
|
inst.push(new InstructionBase("print", tail));
|
|
1935
1926
|
return [null, inst];
|
|
@@ -1939,8 +1930,8 @@ class Print extends MacroFunction {
|
|
|
1939
1930
|
|
|
1940
1931
|
const defaultTargetName$1 = "message1";
|
|
1941
1932
|
class PrintFlush extends MacroFunction {
|
|
1942
|
-
constructor(
|
|
1943
|
-
super(scope,
|
|
1933
|
+
constructor() {
|
|
1934
|
+
super((scope, target) => {
|
|
1944
1935
|
if (!target)
|
|
1945
1936
|
return [null, [new InstructionBase("printflush", defaultTargetName$1)]];
|
|
1946
1937
|
if (!(target instanceof SenseableValue))
|
|
@@ -1952,8 +1943,8 @@ class PrintFlush extends MacroFunction {
|
|
|
1952
1943
|
|
|
1953
1944
|
const defaultTargetName = "display1";
|
|
1954
1945
|
class DrawFlush extends MacroFunction {
|
|
1955
|
-
constructor(
|
|
1956
|
-
super(scope,
|
|
1946
|
+
constructor() {
|
|
1947
|
+
super((scope, target) => {
|
|
1957
1948
|
if (!target)
|
|
1958
1949
|
return [null, [new InstructionBase("drawflush", defaultTargetName)]];
|
|
1959
1950
|
if (!(target instanceof SenseableValue))
|
|
@@ -1964,16 +1955,15 @@ class DrawFlush extends MacroFunction {
|
|
|
1964
1955
|
}
|
|
1965
1956
|
|
|
1966
1957
|
class GetBlock extends ObjectValue {
|
|
1967
|
-
constructor(
|
|
1958
|
+
constructor() {
|
|
1968
1959
|
const data = createOverloadNamespace({
|
|
1969
|
-
scope,
|
|
1970
1960
|
overloads: {
|
|
1971
1961
|
floor: { args: ["x", "y"] },
|
|
1972
1962
|
ore: { args: ["x", "y"] },
|
|
1973
1963
|
block: { args: ["x", "y"] },
|
|
1974
1964
|
building: { args: ["x", "y"] },
|
|
1975
1965
|
},
|
|
1976
|
-
handler(overload, x, y) {
|
|
1966
|
+
handler(scope, overload, x, y) {
|
|
1977
1967
|
const output = overload === "building"
|
|
1978
1968
|
? new SenseableValue(scope)
|
|
1979
1969
|
: new StoreValue(scope);
|
|
@@ -1983,13 +1973,13 @@ class GetBlock extends ObjectValue {
|
|
|
1983
1973
|
];
|
|
1984
1974
|
},
|
|
1985
1975
|
});
|
|
1986
|
-
super(
|
|
1976
|
+
super(data);
|
|
1987
1977
|
}
|
|
1988
1978
|
}
|
|
1989
1979
|
|
|
1990
1980
|
class GetLink extends MacroFunction {
|
|
1991
|
-
constructor(
|
|
1992
|
-
super(scope,
|
|
1981
|
+
constructor() {
|
|
1982
|
+
super((scope, index) => {
|
|
1993
1983
|
if (!(index instanceof StoreValue) &&
|
|
1994
1984
|
(!(index instanceof LiteralValue) || typeof index.data !== "number"))
|
|
1995
1985
|
throw new CompilerError("The getlink index must be a number literal or a store");
|
|
@@ -2000,9 +1990,8 @@ class GetLink extends MacroFunction {
|
|
|
2000
1990
|
}
|
|
2001
1991
|
|
|
2002
1992
|
class Control extends ObjectValue {
|
|
2003
|
-
constructor(
|
|
2004
|
-
super(
|
|
2005
|
-
scope,
|
|
1993
|
+
constructor() {
|
|
1994
|
+
super(createOverloadNamespace({
|
|
2006
1995
|
overloads: {
|
|
2007
1996
|
enabled: { args: ["building", "value"] },
|
|
2008
1997
|
shoot: {
|
|
@@ -2016,7 +2005,7 @@ class Control extends ObjectValue {
|
|
|
2016
2005
|
config: { args: ["building", "value"] },
|
|
2017
2006
|
color: { args: ["building", "r", "g", "b"] },
|
|
2018
2007
|
},
|
|
2019
|
-
handler(overload, ...args) {
|
|
2008
|
+
handler(scope, overload, ...args) {
|
|
2020
2009
|
return [null, [new InstructionBase("control", overload, ...args)]];
|
|
2021
2010
|
},
|
|
2022
2011
|
}));
|
|
@@ -2041,8 +2030,8 @@ const validRadarSorts = [
|
|
|
2041
2030
|
"maxHealth",
|
|
2042
2031
|
];
|
|
2043
2032
|
class Radar extends MacroFunction {
|
|
2044
|
-
constructor(
|
|
2045
|
-
super(scope, options => {
|
|
2033
|
+
constructor() {
|
|
2034
|
+
super((scope, options) => {
|
|
2046
2035
|
assertIsObjectMacro(options, "The radar options");
|
|
2047
2036
|
const { building, filters, order, sort } = options.data;
|
|
2048
2037
|
if (!(building instanceof SenseableValue))
|
|
@@ -2073,8 +2062,8 @@ class Radar extends MacroFunction {
|
|
|
2073
2062
|
}
|
|
2074
2063
|
|
|
2075
2064
|
class Sensor extends MacroFunction {
|
|
2076
|
-
constructor(
|
|
2077
|
-
super(scope,
|
|
2065
|
+
constructor() {
|
|
2066
|
+
super((scope, property, target) => {
|
|
2078
2067
|
if (!(property instanceof StoreValue))
|
|
2079
2068
|
throw new CompilerError("The sensor property must be a store");
|
|
2080
2069
|
if (!(target instanceof SenseableValue))
|
|
@@ -2088,8 +2077,8 @@ class Sensor extends MacroFunction {
|
|
|
2088
2077
|
}
|
|
2089
2078
|
|
|
2090
2079
|
class Wait extends MacroFunction {
|
|
2091
|
-
constructor(
|
|
2092
|
-
super(scope, seconds => {
|
|
2080
|
+
constructor() {
|
|
2081
|
+
super((scope, seconds) => {
|
|
2093
2082
|
if (!(seconds instanceof StoreValue) &&
|
|
2094
2083
|
!(seconds instanceof LiteralValue && typeof seconds.data === "number"))
|
|
2095
2084
|
throw new CompilerError("The wait seconds must be either a number literal or a store");
|
|
@@ -2099,16 +2088,15 @@ class Wait extends MacroFunction {
|
|
|
2099
2088
|
}
|
|
2100
2089
|
|
|
2101
2090
|
class Lookup extends ObjectValue {
|
|
2102
|
-
constructor(
|
|
2091
|
+
constructor() {
|
|
2103
2092
|
const data = createOverloadNamespace({
|
|
2104
|
-
scope,
|
|
2105
2093
|
overloads: {
|
|
2106
2094
|
block: { args: ["index"] },
|
|
2107
2095
|
unit: { args: ["index"] },
|
|
2108
2096
|
item: { args: ["index"] },
|
|
2109
2097
|
liquid: { args: ["index"] },
|
|
2110
2098
|
},
|
|
2111
|
-
handler(overload, index) {
|
|
2099
|
+
handler(scope, overload, index) {
|
|
2112
2100
|
const output = new StoreValue(scope);
|
|
2113
2101
|
return [
|
|
2114
2102
|
output,
|
|
@@ -2116,13 +2104,13 @@ class Lookup extends ObjectValue {
|
|
|
2116
2104
|
];
|
|
2117
2105
|
},
|
|
2118
2106
|
});
|
|
2119
|
-
super(
|
|
2107
|
+
super(data);
|
|
2120
2108
|
}
|
|
2121
2109
|
}
|
|
2122
2110
|
|
|
2123
2111
|
class PackColor extends MacroFunction {
|
|
2124
|
-
constructor(
|
|
2125
|
-
super(scope,
|
|
2112
|
+
constructor() {
|
|
2113
|
+
super((scope, ...args) => {
|
|
2126
2114
|
if (args.length !== 4) {
|
|
2127
2115
|
throw new CompilerError(`Expected 4 arguments, received ${args.length}`);
|
|
2128
2116
|
}
|
|
@@ -2137,15 +2125,14 @@ class PackColor extends MacroFunction {
|
|
|
2137
2125
|
}
|
|
2138
2126
|
|
|
2139
2127
|
class End extends MacroFunction {
|
|
2140
|
-
constructor(
|
|
2141
|
-
super(
|
|
2128
|
+
constructor() {
|
|
2129
|
+
super(() => [null, [new EndInstruction()]]);
|
|
2142
2130
|
}
|
|
2143
2131
|
}
|
|
2144
2132
|
|
|
2145
2133
|
class SetBlock extends ObjectValue {
|
|
2146
|
-
constructor(
|
|
2134
|
+
constructor() {
|
|
2147
2135
|
const data = createOverloadNamespace({
|
|
2148
|
-
scope,
|
|
2149
2136
|
overloads: {
|
|
2150
2137
|
floor: { args: ["x", "y", "to"] },
|
|
2151
2138
|
ore: { args: ["x", "y", "to"] },
|
|
@@ -2154,7 +2141,7 @@ class SetBlock extends ObjectValue {
|
|
|
2154
2141
|
args: ["x", "y", "to", "team", { key: "rotation", default: "0" }],
|
|
2155
2142
|
},
|
|
2156
2143
|
},
|
|
2157
|
-
handler(overload, x, y, to, team, rotation) {
|
|
2144
|
+
handler(scope, overload, x, y, to, team, rotation) {
|
|
2158
2145
|
return [
|
|
2159
2146
|
null,
|
|
2160
2147
|
[
|
|
@@ -2163,13 +2150,13 @@ class SetBlock extends ObjectValue {
|
|
|
2163
2150
|
];
|
|
2164
2151
|
},
|
|
2165
2152
|
});
|
|
2166
|
-
super(
|
|
2153
|
+
super(data);
|
|
2167
2154
|
}
|
|
2168
2155
|
}
|
|
2169
2156
|
|
|
2170
2157
|
class SpawnUnit extends MacroFunction {
|
|
2171
|
-
constructor(
|
|
2172
|
-
super(scope, options => {
|
|
2158
|
+
constructor() {
|
|
2159
|
+
super((scope, options) => {
|
|
2173
2160
|
assertIsObjectMacro(options, "The options");
|
|
2174
2161
|
const { type, x, y, team, rotation } = options.data;
|
|
2175
2162
|
assertIsRuntimeValue(type, "type");
|
|
@@ -2188,14 +2175,14 @@ class SpawnUnit extends MacroFunction {
|
|
|
2188
2175
|
}
|
|
2189
2176
|
|
|
2190
2177
|
class Stop extends MacroFunction {
|
|
2191
|
-
constructor(
|
|
2192
|
-
super(
|
|
2178
|
+
constructor() {
|
|
2179
|
+
super(() => [null, [new InstructionBase("stop")]]);
|
|
2193
2180
|
}
|
|
2194
2181
|
}
|
|
2195
2182
|
|
|
2196
2183
|
class UnitBind extends MacroFunction {
|
|
2197
|
-
constructor(
|
|
2198
|
-
super(scope, type => {
|
|
2184
|
+
constructor() {
|
|
2185
|
+
super((scope, type) => {
|
|
2199
2186
|
if (!(type instanceof StoreValue))
|
|
2200
2187
|
throw new CompilerError("The unitBind type must be a store");
|
|
2201
2188
|
return [null, [new InstructionBase("ubind", type)]];
|
|
@@ -2204,9 +2191,8 @@ class UnitBind extends MacroFunction {
|
|
|
2204
2191
|
}
|
|
2205
2192
|
|
|
2206
2193
|
class UnitControl extends ObjectValue {
|
|
2207
|
-
constructor(
|
|
2194
|
+
constructor() {
|
|
2208
2195
|
const data = createOverloadNamespace({
|
|
2209
|
-
scope,
|
|
2210
2196
|
overloads: {
|
|
2211
2197
|
idle: { args: [] },
|
|
2212
2198
|
stop: { args: [] },
|
|
@@ -2235,21 +2221,21 @@ class UnitControl extends ObjectValue {
|
|
|
2235
2221
|
args: ["x", "y", "radius"],
|
|
2236
2222
|
},
|
|
2237
2223
|
},
|
|
2238
|
-
handler(overload, ...args) {
|
|
2224
|
+
handler(scope, overload, ...args) {
|
|
2239
2225
|
let result = null;
|
|
2240
2226
|
let extraArgs = [];
|
|
2241
2227
|
switch (overload) {
|
|
2242
2228
|
case "getBlock": {
|
|
2243
2229
|
const outType = new StoreValue(scope);
|
|
2244
2230
|
const outBuilding = new SenseableValue(scope);
|
|
2245
|
-
result = ObjectValue.fromArray(
|
|
2246
|
-
extraArgs = [outType, outBuilding, new LiteralValue(
|
|
2231
|
+
result = ObjectValue.fromArray([outType, outBuilding]);
|
|
2232
|
+
extraArgs = [outType, outBuilding, new LiteralValue(0)];
|
|
2247
2233
|
break;
|
|
2248
2234
|
}
|
|
2249
2235
|
case "within": {
|
|
2250
2236
|
const temp = new StoreValue(scope);
|
|
2251
2237
|
result = temp;
|
|
2252
|
-
extraArgs = [temp, new LiteralValue(
|
|
2238
|
+
extraArgs = [temp, new LiteralValue(0)];
|
|
2253
2239
|
break;
|
|
2254
2240
|
}
|
|
2255
2241
|
}
|
|
@@ -2259,13 +2245,13 @@ class UnitControl extends ObjectValue {
|
|
|
2259
2245
|
];
|
|
2260
2246
|
},
|
|
2261
2247
|
});
|
|
2262
|
-
super(
|
|
2248
|
+
super(data);
|
|
2263
2249
|
}
|
|
2264
2250
|
}
|
|
2265
2251
|
|
|
2266
2252
|
class UnitRadar extends MacroFunction {
|
|
2267
|
-
constructor(
|
|
2268
|
-
super(scope, options => {
|
|
2253
|
+
constructor() {
|
|
2254
|
+
super((scope, options) => {
|
|
2269
2255
|
assertIsObjectMacro(options, "The radar options");
|
|
2270
2256
|
const { filters, order, sort } = options.data;
|
|
2271
2257
|
assertIsArrayMacro(filters, "filters");
|
|
@@ -2306,9 +2292,8 @@ const validBuildingGroups = [
|
|
|
2306
2292
|
"reactor",
|
|
2307
2293
|
];
|
|
2308
2294
|
class UnitLocate extends ObjectValue {
|
|
2309
|
-
constructor(
|
|
2295
|
+
constructor() {
|
|
2310
2296
|
const data = createOverloadNamespace({
|
|
2311
|
-
scope,
|
|
2312
2297
|
overloads: {
|
|
2313
2298
|
ore: {
|
|
2314
2299
|
args: ["ore"],
|
|
@@ -2321,7 +2306,7 @@ class UnitLocate extends ObjectValue {
|
|
|
2321
2306
|
args: [],
|
|
2322
2307
|
},
|
|
2323
2308
|
},
|
|
2324
|
-
handler(overload, ...args) {
|
|
2309
|
+
handler(scope, overload, ...args) {
|
|
2325
2310
|
const outFound = new StoreValue(scope);
|
|
2326
2311
|
const outX = new StoreValue(scope);
|
|
2327
2312
|
const outY = new StoreValue(scope);
|
|
@@ -2349,7 +2334,7 @@ class UnitLocate extends ObjectValue {
|
|
|
2349
2334
|
}
|
|
2350
2335
|
}
|
|
2351
2336
|
return [
|
|
2352
|
-
ObjectValue.fromArray(
|
|
2337
|
+
ObjectValue.fromArray([
|
|
2353
2338
|
outFound,
|
|
2354
2339
|
outX,
|
|
2355
2340
|
outY,
|
|
@@ -2359,7 +2344,7 @@ class UnitLocate extends ObjectValue {
|
|
|
2359
2344
|
];
|
|
2360
2345
|
},
|
|
2361
2346
|
});
|
|
2362
|
-
super(
|
|
2347
|
+
super(data);
|
|
2363
2348
|
}
|
|
2364
2349
|
}
|
|
2365
2350
|
|
|
@@ -2380,16 +2365,15 @@ const validEffects = [
|
|
|
2380
2365
|
"blasted",
|
|
2381
2366
|
];
|
|
2382
2367
|
class ApplyStatus extends ObjectValue {
|
|
2383
|
-
constructor(
|
|
2368
|
+
constructor() {
|
|
2384
2369
|
const data = createOverloadNamespace({
|
|
2385
|
-
scope,
|
|
2386
2370
|
overloads: {
|
|
2387
2371
|
apply: {
|
|
2388
2372
|
args: ["status", "unit", { key: "duration", default: "10" }],
|
|
2389
2373
|
},
|
|
2390
2374
|
clear: { args: ["status", "unit"] },
|
|
2391
2375
|
},
|
|
2392
|
-
handler(overload, effect, unit, duration) {
|
|
2376
|
+
handler(scope, overload, effect, unit, duration) {
|
|
2393
2377
|
if (!(effect instanceof LiteralValue))
|
|
2394
2378
|
throw new CompilerError("The status effect must be a string literal");
|
|
2395
2379
|
assertLiteralOneOf(effect, validEffects, "The status effect");
|
|
@@ -2401,13 +2385,13 @@ class ApplyStatus extends ObjectValue {
|
|
|
2401
2385
|
];
|
|
2402
2386
|
},
|
|
2403
2387
|
});
|
|
2404
|
-
super(
|
|
2388
|
+
super(data);
|
|
2405
2389
|
}
|
|
2406
2390
|
}
|
|
2407
2391
|
|
|
2408
2392
|
class SpawnWave extends MacroFunction {
|
|
2409
|
-
constructor(
|
|
2410
|
-
super(scope,
|
|
2393
|
+
constructor() {
|
|
2394
|
+
super((scope, natural, x, y) => {
|
|
2411
2395
|
if (!(natural instanceof LiteralValue) ||
|
|
2412
2396
|
(natural.data !== 1 && natural.data !== 0))
|
|
2413
2397
|
throw new CompilerError("The 'natural' argument must be a boolean literal");
|
|
@@ -2422,9 +2406,8 @@ class SpawnWave extends MacroFunction {
|
|
|
2422
2406
|
}
|
|
2423
2407
|
|
|
2424
2408
|
class SetRule extends ObjectValue {
|
|
2425
|
-
constructor(
|
|
2409
|
+
constructor() {
|
|
2426
2410
|
const data = createOverloadNamespace({
|
|
2427
|
-
scope,
|
|
2428
2411
|
overloads: {
|
|
2429
2412
|
currentWaveTime: { args: ["seconds"] },
|
|
2430
2413
|
waveTimer: { args: ["enabled"] },
|
|
@@ -2448,7 +2431,7 @@ class SetRule extends ObjectValue {
|
|
|
2448
2431
|
rtsMinWeight: { args: ["team", "value"] },
|
|
2449
2432
|
rtsMinSquad: { args: ["team", "value"] },
|
|
2450
2433
|
},
|
|
2451
|
-
handler(overload, ...args) {
|
|
2434
|
+
handler(scope, overload, ...args) {
|
|
2452
2435
|
const params = ["10", "0", "0", "100", "100"];
|
|
2453
2436
|
switch (overload) {
|
|
2454
2437
|
case "mapArea": {
|
|
@@ -2477,49 +2460,47 @@ class SetRule extends ObjectValue {
|
|
|
2477
2460
|
return [null, [new InstructionBase("setrule", overload, ...params)]];
|
|
2478
2461
|
},
|
|
2479
2462
|
});
|
|
2480
|
-
super(
|
|
2463
|
+
super(data);
|
|
2481
2464
|
}
|
|
2482
2465
|
}
|
|
2483
2466
|
|
|
2484
2467
|
class FlushMessage extends ObjectValue {
|
|
2485
|
-
constructor(
|
|
2468
|
+
constructor() {
|
|
2486
2469
|
const data = createOverloadNamespace({
|
|
2487
|
-
scope,
|
|
2488
2470
|
overloads: {
|
|
2489
2471
|
notify: { args: [] },
|
|
2490
2472
|
mission: { args: [] },
|
|
2491
2473
|
announce: { args: ["duration"] },
|
|
2492
2474
|
toast: { args: ["duration"] },
|
|
2493
2475
|
},
|
|
2494
|
-
handler(overload, duration) {
|
|
2476
|
+
handler(scope, overload, duration) {
|
|
2495
2477
|
return [null, [new InstructionBase("message", overload, duration)]];
|
|
2496
2478
|
},
|
|
2497
2479
|
});
|
|
2498
|
-
super(
|
|
2480
|
+
super(data);
|
|
2499
2481
|
}
|
|
2500
2482
|
}
|
|
2501
2483
|
|
|
2502
2484
|
class Cutscene extends ObjectValue {
|
|
2503
|
-
constructor(
|
|
2485
|
+
constructor() {
|
|
2504
2486
|
const data = createOverloadNamespace({
|
|
2505
|
-
scope,
|
|
2506
2487
|
overloads: {
|
|
2507
2488
|
pan: { named: "options", args: ["x", "y", "speed"] },
|
|
2508
2489
|
zoom: { args: ["level"] },
|
|
2509
2490
|
stop: { args: [] },
|
|
2510
2491
|
},
|
|
2511
|
-
handler(overload, ...args) {
|
|
2492
|
+
handler(scope, overload, ...args) {
|
|
2512
2493
|
const params = Object.assign(["100", "100", "0.06", "0"], args);
|
|
2513
2494
|
return [null, [new InstructionBase("cutscene", overload, ...params)]];
|
|
2514
2495
|
},
|
|
2515
2496
|
});
|
|
2516
|
-
super(
|
|
2497
|
+
super(data);
|
|
2517
2498
|
}
|
|
2518
2499
|
}
|
|
2519
2500
|
|
|
2520
2501
|
class Explosion extends MacroFunction {
|
|
2521
|
-
constructor(
|
|
2522
|
-
super(scope, options => {
|
|
2502
|
+
constructor() {
|
|
2503
|
+
super((scope, options) => {
|
|
2523
2504
|
assertIsObjectMacro(options, "The options");
|
|
2524
2505
|
const params = assertObjectFields(options, [
|
|
2525
2506
|
"team",
|
|
@@ -2537,15 +2518,14 @@ class Explosion extends MacroFunction {
|
|
|
2537
2518
|
}
|
|
2538
2519
|
|
|
2539
2520
|
class SetRate extends MacroFunction {
|
|
2540
|
-
constructor(
|
|
2541
|
-
super(scope, ipt => [null, [new InstructionBase("setrate", ipt)]]);
|
|
2521
|
+
constructor() {
|
|
2522
|
+
super((scope, ipt) => [null, [new InstructionBase("setrate", ipt)]]);
|
|
2542
2523
|
}
|
|
2543
2524
|
}
|
|
2544
2525
|
|
|
2545
2526
|
class Fetch extends ObjectValue {
|
|
2546
|
-
constructor(
|
|
2527
|
+
constructor() {
|
|
2547
2528
|
const data = createOverloadNamespace({
|
|
2548
|
-
scope,
|
|
2549
2529
|
overloads: {
|
|
2550
2530
|
unit: { args: ["team", "index"] },
|
|
2551
2531
|
unitCount: { args: ["team"] },
|
|
@@ -2556,7 +2536,7 @@ class Fetch extends ObjectValue {
|
|
|
2556
2536
|
build: { args: ["team", "index", "block"] },
|
|
2557
2537
|
buildCount: { args: ["team", "block"] },
|
|
2558
2538
|
},
|
|
2559
|
-
handler(overload, team, ...rest) {
|
|
2539
|
+
handler(scope, overload, team, ...rest) {
|
|
2560
2540
|
const output = new SenseableValue(scope);
|
|
2561
2541
|
const params = ["0", "@conveyor"];
|
|
2562
2542
|
if (overload === "buildCount") {
|
|
@@ -2571,13 +2551,13 @@ class Fetch extends ObjectValue {
|
|
|
2571
2551
|
];
|
|
2572
2552
|
},
|
|
2573
2553
|
});
|
|
2574
|
-
super(
|
|
2554
|
+
super(data);
|
|
2575
2555
|
}
|
|
2576
2556
|
}
|
|
2577
2557
|
|
|
2578
2558
|
class GetFlag extends MacroFunction {
|
|
2579
|
-
constructor(
|
|
2580
|
-
super(scope, flag => {
|
|
2559
|
+
constructor() {
|
|
2560
|
+
super((scope, flag) => {
|
|
2581
2561
|
const result = new StoreValue(scope);
|
|
2582
2562
|
return [result, [new InstructionBase("getflag", result, flag)]];
|
|
2583
2563
|
});
|
|
@@ -2585,8 +2565,8 @@ class GetFlag extends MacroFunction {
|
|
|
2585
2565
|
}
|
|
2586
2566
|
|
|
2587
2567
|
class SetFlag extends MacroFunction {
|
|
2588
|
-
constructor(
|
|
2589
|
-
super(scope,
|
|
2568
|
+
constructor() {
|
|
2569
|
+
super((scope, flag, value) => {
|
|
2590
2570
|
if (!flag)
|
|
2591
2571
|
throw new CompilerError("Missing flag argument");
|
|
2592
2572
|
if (!value)
|
|
@@ -2596,36 +2576,48 @@ class SetFlag extends MacroFunction {
|
|
|
2596
2576
|
}
|
|
2597
2577
|
}
|
|
2598
2578
|
|
|
2599
|
-
class MemoryEntry extends
|
|
2579
|
+
class MemoryEntry extends BaseValue {
|
|
2600
2580
|
constructor(scope, mem, prop) {
|
|
2601
|
-
super(
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
return [temp, [new InstructionBase("read", temp, mem.cell, prop)]];
|
|
2607
|
-
}),
|
|
2608
|
-
$consume: new MacroFunction(scope, () => {
|
|
2609
|
-
if (this.store)
|
|
2610
|
-
return [this.store, []];
|
|
2611
|
-
this.ensureOwned();
|
|
2612
|
-
this.store = new StoreValue(scope);
|
|
2613
|
-
this.owner.own(this.store);
|
|
2614
|
-
return [
|
|
2615
|
-
this.store,
|
|
2616
|
-
[new InstructionBase("read", this.store, mem.cell, prop)],
|
|
2617
|
-
];
|
|
2618
|
-
}),
|
|
2619
|
-
"$=": new MacroFunction(scope, value => {
|
|
2620
|
-
const [data, dataInst] = value.consume(scope);
|
|
2621
|
-
return [
|
|
2622
|
-
data,
|
|
2623
|
-
[...dataInst, new InstructionBase("write", data, mem.cell, prop)],
|
|
2624
|
-
];
|
|
2625
|
-
}),
|
|
2626
|
-
});
|
|
2581
|
+
super();
|
|
2582
|
+
this.scope = scope;
|
|
2583
|
+
this.mem = mem;
|
|
2584
|
+
this.prop = prop;
|
|
2585
|
+
this.macro = true;
|
|
2627
2586
|
this.store = null;
|
|
2628
2587
|
}
|
|
2588
|
+
eval(scope) {
|
|
2589
|
+
if (this.store)
|
|
2590
|
+
return [this.store, []];
|
|
2591
|
+
const temp = new StoreValue(scope);
|
|
2592
|
+
return [
|
|
2593
|
+
temp,
|
|
2594
|
+
[new InstructionBase("read", temp, this.mem.cell, this.prop)],
|
|
2595
|
+
];
|
|
2596
|
+
}
|
|
2597
|
+
consume(scope) {
|
|
2598
|
+
if (this.store)
|
|
2599
|
+
return [this.store, []];
|
|
2600
|
+
this.ensureOwned();
|
|
2601
|
+
this.store = new StoreValue(scope);
|
|
2602
|
+
this.owner.own(this.store);
|
|
2603
|
+
return [
|
|
2604
|
+
this.store,
|
|
2605
|
+
[new InstructionBase("read", this.store, this.mem.cell, this.prop)],
|
|
2606
|
+
];
|
|
2607
|
+
}
|
|
2608
|
+
"="(scope, value) {
|
|
2609
|
+
const [data, dataInst] = value.consume(scope);
|
|
2610
|
+
return [
|
|
2611
|
+
data,
|
|
2612
|
+
[
|
|
2613
|
+
...dataInst,
|
|
2614
|
+
new InstructionBase("write", data, this.mem.cell, this.prop),
|
|
2615
|
+
],
|
|
2616
|
+
];
|
|
2617
|
+
}
|
|
2618
|
+
ensureOwned() {
|
|
2619
|
+
this.owner ??= new ValueOwner({ scope: this.scope, value: this });
|
|
2620
|
+
}
|
|
2629
2621
|
}
|
|
2630
2622
|
for (const operator of operators) {
|
|
2631
2623
|
if (operator === "=")
|
|
@@ -2636,9 +2628,9 @@ for (const operator of operators) {
|
|
|
2636
2628
|
};
|
|
2637
2629
|
}
|
|
2638
2630
|
class MemoryMacro extends ObjectValue {
|
|
2639
|
-
constructor(
|
|
2640
|
-
super(
|
|
2641
|
-
$get: new MacroFunction(scope,
|
|
2631
|
+
constructor(cell, size) {
|
|
2632
|
+
super({
|
|
2633
|
+
$get: new MacroFunction((scope, prop) => {
|
|
2642
2634
|
if (prop instanceof LiteralValue && typeof prop.data !== "number")
|
|
2643
2635
|
throw new CompilerError(`Invalid memory object property: "${prop.data}"`);
|
|
2644
2636
|
const obj = new MemoryEntry(scope, this, prop);
|
|
@@ -2648,21 +2640,20 @@ class MemoryMacro extends ObjectValue {
|
|
|
2648
2640
|
size,
|
|
2649
2641
|
});
|
|
2650
2642
|
this.cell = cell;
|
|
2651
|
-
this.name = cell.toString();
|
|
2652
2643
|
}
|
|
2653
2644
|
toString() {
|
|
2654
|
-
return this.
|
|
2645
|
+
return this.cell.toString();
|
|
2655
2646
|
}
|
|
2656
2647
|
}
|
|
2657
2648
|
class MemoryBuilder extends ObjectValue {
|
|
2658
|
-
constructor(
|
|
2659
|
-
super(
|
|
2660
|
-
$call: new MacroFunction(scope,
|
|
2649
|
+
constructor() {
|
|
2650
|
+
super({
|
|
2651
|
+
$call: new MacroFunction((scope, cell, size = new LiteralValue(64)) => {
|
|
2661
2652
|
if (!(cell instanceof SenseableValue))
|
|
2662
2653
|
throw new CompilerError("Memory cell must be a senseable value.");
|
|
2663
2654
|
if (!(size instanceof LiteralValue && typeof size.data === "number"))
|
|
2664
2655
|
throw new CompilerError("The memory size must be a number literal.");
|
|
2665
|
-
return [new MemoryMacro(
|
|
2656
|
+
return [new MemoryMacro(cell, size), []];
|
|
2666
2657
|
}),
|
|
2667
2658
|
});
|
|
2668
2659
|
}
|
|
@@ -2670,9 +2661,9 @@ class MemoryBuilder extends ObjectValue {
|
|
|
2670
2661
|
|
|
2671
2662
|
const dynamicVars = ["time", "tick"];
|
|
2672
2663
|
class NamespaceMacro extends ObjectValue {
|
|
2673
|
-
constructor(
|
|
2674
|
-
super(
|
|
2675
|
-
$get: new MacroFunction(scope, prop => {
|
|
2664
|
+
constructor({ changeCasing = false } = {}) {
|
|
2665
|
+
super({
|
|
2666
|
+
$get: new MacroFunction((scope, prop) => {
|
|
2676
2667
|
if (!(prop instanceof LiteralValue) || typeof prop.data !== "string")
|
|
2677
2668
|
throw new CompilerError("Cannot use dynamic properties on namespace macros");
|
|
2678
2669
|
const symbolName = this.changeCasing
|
|
@@ -2696,7 +2687,7 @@ class NamespaceMacro extends ObjectValue {
|
|
|
2696
2687
|
}
|
|
2697
2688
|
class VarsNamespace extends NamespaceMacro {
|
|
2698
2689
|
constructor(scope) {
|
|
2699
|
-
super(
|
|
2690
|
+
super();
|
|
2700
2691
|
Object.assign(this.data, {
|
|
2701
2692
|
unit: new ValueOwner({
|
|
2702
2693
|
scope,
|
|
@@ -2713,8 +2704,8 @@ class VarsNamespace extends NamespaceMacro {
|
|
|
2713
2704
|
}
|
|
2714
2705
|
|
|
2715
2706
|
class GetGlobal extends MacroFunction {
|
|
2716
|
-
constructor(
|
|
2717
|
-
super(scope,
|
|
2707
|
+
constructor(mutability) {
|
|
2708
|
+
super((scope, name) => {
|
|
2718
2709
|
if (!(name instanceof LiteralValue) || typeof name.data !== "string")
|
|
2719
2710
|
throw new CompilerError("The name parameter must be a string literal.");
|
|
2720
2711
|
const owner = new ValueOwner({
|
|
@@ -2730,22 +2721,77 @@ class GetGlobal extends MacroFunction {
|
|
|
2730
2721
|
}
|
|
2731
2722
|
|
|
2732
2723
|
class Asm extends MacroFunction {
|
|
2733
|
-
constructor(
|
|
2734
|
-
super(scope,
|
|
2724
|
+
constructor() {
|
|
2725
|
+
super((scope, stringsArray, ...values) => {
|
|
2735
2726
|
if (!isTemplateObjectArray(stringsArray))
|
|
2736
2727
|
throw new CompilerError("Expected to receive a template strings array");
|
|
2737
2728
|
const args = [];
|
|
2738
2729
|
for (let i = 0; i < values.length; i++) {
|
|
2739
|
-
const [item] = stringsArray.get(scope, new LiteralValue(
|
|
2730
|
+
const [item] = stringsArray.get(scope, new LiteralValue(i));
|
|
2740
2731
|
args.push(item.data);
|
|
2741
2732
|
args.push(values[i]);
|
|
2742
2733
|
}
|
|
2743
2734
|
const { length } = stringsArray.data;
|
|
2744
|
-
const [tail] = stringsArray.get(scope, new LiteralValue(
|
|
2735
|
+
const [tail] = stringsArray.get(scope, new LiteralValue(length.data - 1));
|
|
2745
2736
|
args.push(tail.data);
|
|
2746
|
-
return [null,
|
|
2737
|
+
return [null, formatInstructions(args)];
|
|
2747
2738
|
});
|
|
2748
2739
|
}
|
|
2740
|
+
}
|
|
2741
|
+
/** Splits multiline asm calls and formats each line. */
|
|
2742
|
+
function formatInstructions(args) {
|
|
2743
|
+
const instructions = [];
|
|
2744
|
+
let buffer = [];
|
|
2745
|
+
for (let i = 0; i < args.length; i++) {
|
|
2746
|
+
const arg = args[i];
|
|
2747
|
+
if (typeof arg !== "string" || !arg.includes("\n")) {
|
|
2748
|
+
buffer.push(arg);
|
|
2749
|
+
continue;
|
|
2750
|
+
}
|
|
2751
|
+
const segments = arg.split("\n");
|
|
2752
|
+
const params = [...buffer, segments[0]];
|
|
2753
|
+
if (validateInstructionArgs(params)) {
|
|
2754
|
+
instructions.push(new ZeroSpaceInstruction(...params));
|
|
2755
|
+
buffer = [];
|
|
2756
|
+
}
|
|
2757
|
+
// iterates over all segments except the first and last
|
|
2758
|
+
// the first segment was already processed above
|
|
2759
|
+
// the last segment will be added to the buffer because there might
|
|
2760
|
+
// be an interpolation after it
|
|
2761
|
+
// and putting it in the buffer makes sure it has a proper output format
|
|
2762
|
+
for (let i = 1; i < segments.length - 1; i++) {
|
|
2763
|
+
const trimmed = segments[i].trim();
|
|
2764
|
+
if (trimmed.length == 0)
|
|
2765
|
+
continue;
|
|
2766
|
+
instructions.push(new ZeroSpaceInstruction(trimmed));
|
|
2767
|
+
}
|
|
2768
|
+
if (segments.length > 1) {
|
|
2769
|
+
buffer.push(segments[segments.length - 1]);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
if (buffer.length > 0 && validateInstructionArgs(buffer)) {
|
|
2773
|
+
instructions.push(new ZeroSpaceInstruction(...buffer));
|
|
2774
|
+
}
|
|
2775
|
+
return instructions;
|
|
2776
|
+
}
|
|
2777
|
+
/** Determines if an asm line should be generated and trims it at the start and end */
|
|
2778
|
+
function validateInstructionArgs(args) {
|
|
2779
|
+
if (args.length === 0)
|
|
2780
|
+
return false;
|
|
2781
|
+
if (args.length === 1) {
|
|
2782
|
+
const item = args[0];
|
|
2783
|
+
if (typeof item !== "string")
|
|
2784
|
+
return true;
|
|
2785
|
+
args[0] = item.trim();
|
|
2786
|
+
return args[0].length !== 0;
|
|
2787
|
+
}
|
|
2788
|
+
const first = args[0];
|
|
2789
|
+
const last = args[args.length - 1];
|
|
2790
|
+
if (typeof first === "string")
|
|
2791
|
+
args[0] = first.trimStart();
|
|
2792
|
+
if (typeof last === "string")
|
|
2793
|
+
args[args.length - 1] = last.trimEnd();
|
|
2794
|
+
return true;
|
|
2749
2795
|
}
|
|
2750
2796
|
|
|
2751
2797
|
/**
|
|
@@ -2753,53 +2799,53 @@ class Asm extends MacroFunction {
|
|
|
2753
2799
|
*/
|
|
2754
2800
|
function initScope(scope) {
|
|
2755
2801
|
// namespaces
|
|
2756
|
-
scope.hardSet("ControlKind", new NamespaceMacro(
|
|
2802
|
+
scope.hardSet("ControlKind", new NamespaceMacro());
|
|
2757
2803
|
scope.hardSet("Vars", new VarsNamespace(scope));
|
|
2758
|
-
scope.hardSet("Teams", new NamespaceMacro(
|
|
2759
|
-
scope.hardSet("Items", new NamespaceMacro(
|
|
2760
|
-
scope.hardSet("Liquids", new NamespaceMacro(
|
|
2761
|
-
scope.hardSet("Units", new NamespaceMacro(
|
|
2762
|
-
scope.hardSet("LAccess", new NamespaceMacro(
|
|
2763
|
-
scope.hardSet("Blocks", new NamespaceMacro(
|
|
2804
|
+
scope.hardSet("Teams", new NamespaceMacro());
|
|
2805
|
+
scope.hardSet("Items", new NamespaceMacro({ changeCasing: true }));
|
|
2806
|
+
scope.hardSet("Liquids", new NamespaceMacro());
|
|
2807
|
+
scope.hardSet("Units", new NamespaceMacro({ changeCasing: true }));
|
|
2808
|
+
scope.hardSet("LAccess", new NamespaceMacro());
|
|
2809
|
+
scope.hardSet("Blocks", new NamespaceMacro({ changeCasing: true }));
|
|
2764
2810
|
// helper methods
|
|
2765
|
-
scope.hardSet("getBuilding", new GetGlobal(
|
|
2766
|
-
scope.hardSet("getVar", new GetGlobal(
|
|
2767
|
-
scope.hardSet("concat", new Concat(
|
|
2768
|
-
scope.hardSet("asm", new Asm(
|
|
2769
|
-
scope.hardSet("Math", new MlogMath(
|
|
2770
|
-
scope.hardSet("Memory", new MemoryBuilder(
|
|
2811
|
+
scope.hardSet("getBuilding", new GetGlobal(EMutability.constant));
|
|
2812
|
+
scope.hardSet("getVar", new GetGlobal(EMutability.mutable));
|
|
2813
|
+
scope.hardSet("concat", new Concat());
|
|
2814
|
+
scope.hardSet("asm", new Asm());
|
|
2815
|
+
scope.hardSet("Math", new MlogMath());
|
|
2816
|
+
scope.hardSet("Memory", new MemoryBuilder());
|
|
2771
2817
|
// commands
|
|
2772
|
-
scope.hardSet("draw", new Draw(
|
|
2773
|
-
scope.hardSet("print", new Print(
|
|
2774
|
-
scope.hardSet("printFlush", new PrintFlush(
|
|
2775
|
-
scope.hardSet("drawFlush", new DrawFlush(
|
|
2776
|
-
scope.hardSet("getLink", new GetLink(
|
|
2777
|
-
scope.hardSet("control", new Control(
|
|
2778
|
-
scope.hardSet("radar", new Radar(
|
|
2779
|
-
scope.hardSet("sensor", new Sensor(
|
|
2780
|
-
scope.hardSet("wait", new Wait(
|
|
2781
|
-
scope.hardSet("lookup", new Lookup(
|
|
2782
|
-
scope.hardSet("packColor", new PackColor(
|
|
2783
|
-
scope.hardSet("endScript", new End(
|
|
2784
|
-
scope.hardSet("stopScript", new Stop(
|
|
2785
|
-
scope.hardSet("unitBind", new UnitBind(
|
|
2786
|
-
scope.hardSet("unitControl", new UnitControl(
|
|
2787
|
-
scope.hardSet("unitRadar", new UnitRadar(
|
|
2788
|
-
scope.hardSet("unitLocate", new UnitLocate(
|
|
2818
|
+
scope.hardSet("draw", new Draw());
|
|
2819
|
+
scope.hardSet("print", new Print());
|
|
2820
|
+
scope.hardSet("printFlush", new PrintFlush());
|
|
2821
|
+
scope.hardSet("drawFlush", new DrawFlush());
|
|
2822
|
+
scope.hardSet("getLink", new GetLink());
|
|
2823
|
+
scope.hardSet("control", new Control());
|
|
2824
|
+
scope.hardSet("radar", new Radar());
|
|
2825
|
+
scope.hardSet("sensor", new Sensor());
|
|
2826
|
+
scope.hardSet("wait", new Wait());
|
|
2827
|
+
scope.hardSet("lookup", new Lookup());
|
|
2828
|
+
scope.hardSet("packColor", new PackColor());
|
|
2829
|
+
scope.hardSet("endScript", new End());
|
|
2830
|
+
scope.hardSet("stopScript", new Stop());
|
|
2831
|
+
scope.hardSet("unitBind", new UnitBind());
|
|
2832
|
+
scope.hardSet("unitControl", new UnitControl());
|
|
2833
|
+
scope.hardSet("unitRadar", new UnitRadar());
|
|
2834
|
+
scope.hardSet("unitLocate", new UnitLocate());
|
|
2789
2835
|
// world processor commands
|
|
2790
|
-
scope.hardSet("getBlock", new GetBlock(
|
|
2791
|
-
scope.hardSet("setBlock", new SetBlock(
|
|
2792
|
-
scope.hardSet("spawnUnit", new SpawnUnit(
|
|
2793
|
-
scope.hardSet("applyStatus", new ApplyStatus(
|
|
2794
|
-
scope.hardSet("spawnWave", new SpawnWave(
|
|
2795
|
-
scope.hardSet("setRule", new SetRule(
|
|
2796
|
-
scope.hardSet("flushMessage", new FlushMessage(
|
|
2797
|
-
scope.hardSet("cutscene", new Cutscene(
|
|
2798
|
-
scope.hardSet("explosion", new Explosion(
|
|
2799
|
-
scope.hardSet("setRate", new SetRate(
|
|
2800
|
-
scope.hardSet("fetch", new Fetch(
|
|
2801
|
-
scope.hardSet("getFlag", new GetFlag(
|
|
2802
|
-
scope.hardSet("setFlag", new SetFlag(
|
|
2836
|
+
scope.hardSet("getBlock", new GetBlock());
|
|
2837
|
+
scope.hardSet("setBlock", new SetBlock());
|
|
2838
|
+
scope.hardSet("spawnUnit", new SpawnUnit());
|
|
2839
|
+
scope.hardSet("applyStatus", new ApplyStatus());
|
|
2840
|
+
scope.hardSet("spawnWave", new SpawnWave());
|
|
2841
|
+
scope.hardSet("setRule", new SetRule());
|
|
2842
|
+
scope.hardSet("flushMessage", new FlushMessage());
|
|
2843
|
+
scope.hardSet("cutscene", new Cutscene());
|
|
2844
|
+
scope.hardSet("explosion", new Explosion());
|
|
2845
|
+
scope.hardSet("setRate", new SetRate());
|
|
2846
|
+
scope.hardSet("fetch", new Fetch());
|
|
2847
|
+
scope.hardSet("getFlag", new GetFlag());
|
|
2848
|
+
scope.hardSet("setFlag", new SetFlag());
|
|
2803
2849
|
}
|
|
2804
2850
|
|
|
2805
2851
|
class Compiler {
|