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.
Files changed (141) hide show
  1. package/dist/index.cjs +359 -313
  2. package/dist/index.mjs +359 -313
  3. package/dist/macros/Asm.d.ts +1 -2
  4. package/dist/macros/Function.d.ts +2 -2
  5. package/dist/macros/GetGlobal.d.ts +2 -2
  6. package/dist/macros/Math.d.ts +1 -2
  7. package/dist/macros/Memory.d.ts +1 -2
  8. package/dist/macros/Namespace.d.ts +1 -1
  9. package/dist/macros/Other.d.ts +1 -2
  10. package/dist/macros/commands/ApplyStatus.d.ts +1 -2
  11. package/dist/macros/commands/Control.d.ts +1 -2
  12. package/dist/macros/commands/Cutscene.d.ts +1 -2
  13. package/dist/macros/commands/Draw.d.ts +1 -2
  14. package/dist/macros/commands/DrawFlush.d.ts +1 -2
  15. package/dist/macros/commands/End.d.ts +1 -2
  16. package/dist/macros/commands/Explosion.d.ts +1 -2
  17. package/dist/macros/commands/Fetch.d.ts +1 -2
  18. package/dist/macros/commands/FlushMessage.d.ts +1 -2
  19. package/dist/macros/commands/GetBlock.d.ts +1 -2
  20. package/dist/macros/commands/GetFlag.d.ts +1 -2
  21. package/dist/macros/commands/GetLink.d.ts +1 -2
  22. package/dist/macros/commands/Lookup.d.ts +1 -2
  23. package/dist/macros/commands/PackColor.d.ts +1 -2
  24. package/dist/macros/commands/Print.d.ts +1 -2
  25. package/dist/macros/commands/PrintFlush.d.ts +1 -2
  26. package/dist/macros/commands/Radar.d.ts +1 -2
  27. package/dist/macros/commands/Sensor.d.ts +1 -2
  28. package/dist/macros/commands/SetBlock.d.ts +1 -2
  29. package/dist/macros/commands/SetFlag.d.ts +1 -2
  30. package/dist/macros/commands/SetRate.d.ts +1 -2
  31. package/dist/macros/commands/SetRule.d.ts +1 -2
  32. package/dist/macros/commands/SpawnUnit.d.ts +1 -2
  33. package/dist/macros/commands/SpawnWave.d.ts +1 -2
  34. package/dist/macros/commands/Stop.d.ts +1 -2
  35. package/dist/macros/commands/UnitBind.d.ts +1 -2
  36. package/dist/macros/commands/UnitControl.d.ts +1 -2
  37. package/dist/macros/commands/UnitLocate.d.ts +1 -2
  38. package/dist/macros/commands/UnitRadar.d.ts +1 -2
  39. package/dist/macros/commands/Wait.d.ts +1 -2
  40. package/dist/macros/util.d.ts +2 -3
  41. package/dist/types.d.ts +0 -1
  42. package/dist/values/BaseValue.d.ts +1 -2
  43. package/dist/values/DestructuringValue.d.ts +1 -1
  44. package/dist/values/FunctionValue.d.ts +3 -4
  45. package/dist/values/LiteralValue.d.ts +3 -2
  46. package/dist/values/ObjectValue.d.ts +3 -3
  47. package/dist/values/StoreValue.d.ts +4 -2
  48. package/dist/values/VoidValue.d.ts +0 -2
  49. package/lib/commands.d.ts +6 -10
  50. package/package.json +2 -2
  51. package/dist/bin.cjs.map +0 -1
  52. package/dist/index.cjs.map +0 -1
  53. package/dist/index.mjs.map +0 -1
  54. package/dist/types/Compiler.d.ts +0 -39
  55. package/dist/types/CompilerError.d.ts +0 -33
  56. package/dist/types/Scope.d.ts +0 -24
  57. package/dist/types/assertions.d.ts +0 -28
  58. package/dist/types/bin.d.ts +0 -1
  59. package/dist/types/handlers/BlockStatement.d.ts +0 -2
  60. package/dist/types/handlers/CallExpression.d.ts +0 -4
  61. package/dist/types/handlers/File.d.ts +0 -2
  62. package/dist/types/handlers/ForStatement.d.ts +0 -2
  63. package/dist/types/handlers/Function.d.ts +0 -5
  64. package/dist/types/handlers/Identifier.d.ts +0 -2
  65. package/dist/types/handlers/IfStatement.d.ts +0 -2
  66. package/dist/types/handlers/Literal.d.ts +0 -5
  67. package/dist/types/handlers/Object.d.ts +0 -6
  68. package/dist/types/handlers/OperationExpressions.d.ts +0 -8
  69. package/dist/types/handlers/Program.d.ts +0 -2
  70. package/dist/types/handlers/Statements.d.ts +0 -5
  71. package/dist/types/handlers/SwitchStatement.d.ts +0 -2
  72. package/dist/types/handlers/TemplateExpression.d.ts +0 -2
  73. package/dist/types/handlers/Typescript.d.ts +0 -7
  74. package/dist/types/handlers/VariableDeclaration.d.ts +0 -3
  75. package/dist/types/handlers/WhileStatement.d.ts +0 -3
  76. package/dist/types/handlers/index.d.ts +0 -17
  77. package/dist/types/index.d.ts +0 -3
  78. package/dist/types/initScope.d.ts +0 -5
  79. package/dist/types/instructions/AddressResolver.d.ts +0 -12
  80. package/dist/types/instructions/ControlInstructions.d.ts +0 -10
  81. package/dist/types/instructions/EndInstruction.d.ts +0 -4
  82. package/dist/types/instructions/InstructionBase.d.ts +0 -14
  83. package/dist/types/instructions/JumpInstruction.d.ts +0 -16
  84. package/dist/types/instructions/OperationInstruction.d.ts +0 -5
  85. package/dist/types/instructions/SetCounterInstruction.d.ts +0 -5
  86. package/dist/types/instructions/SetInstruction.d.ts +0 -6
  87. package/dist/types/instructions/ZeroSpaceInstruction.d.ts +0 -4
  88. package/dist/types/instructions/index.d.ts +0 -9
  89. package/dist/types/macros/Asm.d.ts +0 -5
  90. package/dist/types/macros/Function.d.ts +0 -13
  91. package/dist/types/macros/GetGlobal.d.ts +0 -5
  92. package/dist/types/macros/Math.d.ts +0 -5
  93. package/dist/types/macros/Memory.d.ts +0 -5
  94. package/dist/types/macros/Namespace.d.ts +0 -13
  95. package/dist/types/macros/Other.d.ts +0 -5
  96. package/dist/types/macros/commands/ApplyStatus.d.ts +0 -5
  97. package/dist/types/macros/commands/Control.d.ts +0 -5
  98. package/dist/types/macros/commands/Cutscene.d.ts +0 -5
  99. package/dist/types/macros/commands/Draw.d.ts +0 -5
  100. package/dist/types/macros/commands/DrawFlush.d.ts +0 -5
  101. package/dist/types/macros/commands/End.d.ts +0 -5
  102. package/dist/types/macros/commands/Explosion.d.ts +0 -5
  103. package/dist/types/macros/commands/Fetch.d.ts +0 -5
  104. package/dist/types/macros/commands/FlushMessage.d.ts +0 -5
  105. package/dist/types/macros/commands/GetBlock.d.ts +0 -5
  106. package/dist/types/macros/commands/GetFlag.d.ts +0 -5
  107. package/dist/types/macros/commands/GetLink.d.ts +0 -5
  108. package/dist/types/macros/commands/Lookup.d.ts +0 -5
  109. package/dist/types/macros/commands/PackColor.d.ts +0 -5
  110. package/dist/types/macros/commands/Print.d.ts +0 -5
  111. package/dist/types/macros/commands/PrintFlush.d.ts +0 -5
  112. package/dist/types/macros/commands/Radar.d.ts +0 -7
  113. package/dist/types/macros/commands/Sensor.d.ts +0 -5
  114. package/dist/types/macros/commands/SetBlock.d.ts +0 -5
  115. package/dist/types/macros/commands/SetFlag.d.ts +0 -5
  116. package/dist/types/macros/commands/SetRate.d.ts +0 -5
  117. package/dist/types/macros/commands/SetRule.d.ts +0 -5
  118. package/dist/types/macros/commands/SpawnUnit.d.ts +0 -5
  119. package/dist/types/macros/commands/SpawnWave.d.ts +0 -5
  120. package/dist/types/macros/commands/Stop.d.ts +0 -5
  121. package/dist/types/macros/commands/UnitBind.d.ts +0 -5
  122. package/dist/types/macros/commands/UnitControl.d.ts +0 -5
  123. package/dist/types/macros/commands/UnitLocate.d.ts +0 -5
  124. package/dist/types/macros/commands/UnitRadar.d.ts +0 -5
  125. package/dist/types/macros/commands/Wait.d.ts +0 -5
  126. package/dist/types/macros/commands/index.d.ts +0 -30
  127. package/dist/types/macros/index.d.ts +0 -6
  128. package/dist/types/macros/util.d.ts +0 -18
  129. package/dist/types/operators.d.ts +0 -25
  130. package/dist/types/types.d.ts +0 -238
  131. package/dist/types/utils.d.ts +0 -47
  132. package/dist/types/values/BaseValue.d.ts +0 -9
  133. package/dist/types/values/DestructuringValue.d.ts +0 -17
  134. package/dist/types/values/FunctionValue.d.ts +0 -47
  135. package/dist/types/values/LiteralValue.d.ts +0 -13
  136. package/dist/types/values/ObjectValue.d.ts +0 -23
  137. package/dist/types/values/SenseableValue.d.ts +0 -23
  138. package/dist/types/values/StoreValue.d.ts +0 -15
  139. package/dist/types/values/ValueOwner.d.ts +0 -27
  140. package/dist/types/values/VoidValue.d.ts +0 -16
  141. package/dist/types/values/index.d.ts +0 -7
package/dist/index.mjs CHANGED
@@ -147,11 +147,10 @@ const singleOperators = [...unaryOperators, ...updateOperators];
147
147
  const operators = [...leftRightOperators, ...singleOperators];
148
148
 
149
149
  class VoidValue {
150
- constructor(scope) {
150
+ constructor() {
151
151
  this.owner = null;
152
152
  this.mutability = EMutability.mutable;
153
153
  this.macro = false;
154
- this.scope = scope;
155
154
  }
156
155
  eval(_scope) {
157
156
  throw new CompilerError(`${this} cannot eval.`);
@@ -288,38 +287,6 @@ class ContinueInstruction extends JumpInstruction {
288
287
  }
289
288
  }
290
289
 
291
- class ValueOwner {
292
- /**
293
- * Creates a new `ValueOwner`, if `value` is already owned,
294
- * `this` will be aliased to `value`, else `this` will own `value`
295
- */
296
- constructor({ scope, constant = false, value, identifier, name, }) {
297
- this.scope = scope;
298
- this.constant = constant;
299
- this.value = value;
300
- this.identifier = identifier;
301
- this.name = name ?? scope.makeTempName();
302
- this.persistent = !!name;
303
- this.owned = new Set();
304
- if (!value.owner?.persistent)
305
- this.own(value);
306
- }
307
- own(target) {
308
- target.owner = this;
309
- this.owned.add(target);
310
- }
311
- replace(target) {
312
- this.value.owner = null;
313
- this.owned.delete(this.value);
314
- this.value = target;
315
- this.own(target);
316
- }
317
- moveInto(owner) {
318
- this.owned.forEach(value => owner.own(value));
319
- this.owned.clear();
320
- }
321
- }
322
-
323
290
  class BaseValue extends VoidValue {
324
291
  "u-"(scope) {
325
292
  const [that, inst] = this.consume(scope);
@@ -328,7 +295,7 @@ class BaseValue extends VoidValue {
328
295
  temp,
329
296
  [
330
297
  ...inst,
331
- new OperationInstruction("sub", temp, new LiteralValue(scope, 0), that),
298
+ new OperationInstruction("sub", temp, new LiteralValue(0), that),
332
299
  ],
333
300
  ];
334
301
  }
@@ -339,7 +306,7 @@ class BaseValue extends VoidValue {
339
306
  "!"(scope) {
340
307
  const [that, inst] = this.consume(scope);
341
308
  const temp = new StoreValue(scope);
342
- const falseLiteral = new LiteralValue(scope, 0);
309
+ const falseLiteral = new LiteralValue(0);
343
310
  return [
344
311
  temp,
345
312
  [...inst, new OperationInstruction("equal", temp, that, falseLiteral)],
@@ -350,9 +317,6 @@ class BaseValue extends VoidValue {
350
317
  const temp = new StoreValue(scope);
351
318
  return [temp, [...inst, new OperationInstruction("not", temp, that, null)]];
352
319
  }
353
- ensureOwned() {
354
- this.owner ??= new ValueOwner({ scope: this.scope, value: this });
355
- }
356
320
  }
357
321
  const operatorMap$1 = {
358
322
  "==": "equal",
@@ -428,23 +392,20 @@ for (const key of updateOperators) {
428
392
  inst.push(...tempInst);
429
393
  }
430
394
  const kind = key === "++" ? "+=" : "-=";
431
- return [
432
- ret,
433
- [...inst, ...this[kind](scope, new LiteralValue(scope, 1))[1]],
434
- ];
395
+ return [ret, [...inst, ...this[kind](scope, new LiteralValue(1))[1]]];
435
396
  };
436
397
  }
437
398
 
438
399
  const literalMethods = {
439
- length: function (scope) {
400
+ length: function () {
440
401
  if (typeof this.data !== "string")
441
402
  throw new CompilerError("Length method only works on string literal values.");
442
- return new LiteralValue(scope, this.data.length);
403
+ return new LiteralValue(this.data.length);
443
404
  },
444
405
  };
445
406
  class LiteralValue extends BaseValue {
446
- constructor(scope, data) {
447
- super(scope);
407
+ constructor(data) {
408
+ super();
448
409
  this.mutability = EMutability.constant;
449
410
  this.data = data;
450
411
  }
@@ -472,9 +433,10 @@ class LiteralValue extends BaseValue {
472
433
  return 1;
473
434
  return this.data;
474
435
  }
475
- typeof(scope) {
476
- return [new LiteralValue(scope, "literal"), []];
436
+ typeof() {
437
+ return [new LiteralValue("literal"), []];
477
438
  }
439
+ ensureOwned() { }
478
440
  }
479
441
  const operatorMap = {
480
442
  "==": (a, b) => +(a == b),
@@ -506,10 +468,7 @@ for (const key in operatorMap) {
506
468
  if (!(value instanceof LiteralValue)) {
507
469
  return BaseValue.prototype[key].apply(this, [scope, value]);
508
470
  }
509
- return [
510
- new LiteralValue(scope, fn(this.data, value.data)),
511
- [],
512
- ];
471
+ return [new LiteralValue(fn(this.data, value.data)), []];
513
472
  };
514
473
  }
515
474
  const unaryOperatorMap = {
@@ -519,9 +478,9 @@ const unaryOperatorMap = {
519
478
  "u+": v => +v,
520
479
  };
521
480
  for (const key in unaryOperatorMap) {
522
- LiteralValue.prototype[key] = function (scope) {
481
+ LiteralValue.prototype[key] = function () {
523
482
  const fn = unaryOperatorMap[key];
524
- return [new LiteralValue(scope, fn(this.data)), []];
483
+ return [new LiteralValue(fn(this.data)), []];
525
484
  };
526
485
  }
527
486
 
@@ -600,17 +559,50 @@ function isTemplateObjectArray(value) {
600
559
  typeof value.data.raw.data.length.data === "number");
601
560
  }
602
561
 
562
+ class ValueOwner {
563
+ /**
564
+ * Creates a new `ValueOwner`, if `value` is already owned,
565
+ * `this` will be aliased to `value`, else `this` will own `value`
566
+ */
567
+ constructor({ scope, constant = false, value, identifier, name, }) {
568
+ this.scope = scope;
569
+ this.constant = constant;
570
+ this.value = value;
571
+ this.identifier = identifier;
572
+ this.name = name ?? scope.makeTempName();
573
+ this.persistent = !!name;
574
+ this.owned = new Set();
575
+ if (!value.owner?.persistent)
576
+ this.own(value);
577
+ }
578
+ own(target) {
579
+ target.owner = this;
580
+ this.owned.add(target);
581
+ }
582
+ replace(target) {
583
+ this.value.owner = null;
584
+ this.owned.delete(this.value);
585
+ this.value = target;
586
+ this.own(target);
587
+ }
588
+ moveInto(owner) {
589
+ this.owned.forEach(value => owner.own(value));
590
+ this.owned.clear();
591
+ }
592
+ }
593
+
603
594
  /**
604
595
  * `StoreValue` represents values unknown at compile time,
605
596
  * mostly used with mutable variables and temporary values
606
597
  */
607
598
  class StoreValue extends BaseValue {
608
599
  constructor(scope) {
609
- super(scope);
600
+ super();
601
+ this.scope = scope;
610
602
  this.mutability = EMutability.mutable;
611
603
  }
612
- typeof(scope) {
613
- return [new LiteralValue(scope, "store"), []];
604
+ typeof() {
605
+ return [new LiteralValue("store"), []];
614
606
  }
615
607
  "="(scope, value) {
616
608
  if (this.mutability !== EMutability.mutable)
@@ -637,31 +629,34 @@ class StoreValue extends BaseValue {
637
629
  this.ensureOwned();
638
630
  return [this, []];
639
631
  }
632
+ ensureOwned() {
633
+ this.owner ??= new ValueOwner({ scope: this.scope, value: this });
634
+ }
640
635
  toString() {
641
636
  return this.owner?.name ?? discardedName;
642
637
  }
643
638
  }
644
639
 
645
640
  class ObjectValue extends VoidValue {
646
- constructor(scope, data = {}) {
647
- super(scope);
641
+ constructor(data = {}) {
642
+ super();
648
643
  this.mutability = EMutability.constant;
649
644
  this.macro = true;
650
645
  this.data = data;
651
646
  }
652
- static fromArray(scope, items, intialData) {
647
+ static fromArray(items, intialData) {
653
648
  const data = {
654
649
  ...intialData,
655
- length: new LiteralValue(scope, items.length),
650
+ length: new LiteralValue(items.length),
656
651
  };
657
652
  items.forEach((item, i) => {
658
653
  if (item)
659
654
  data[i] = item;
660
655
  });
661
- return new ObjectValue(scope, data);
656
+ return new ObjectValue(data);
662
657
  }
663
- typeof(scope) {
664
- return [new LiteralValue(scope, "object"), []];
658
+ typeof() {
659
+ return [new LiteralValue("object"), []];
665
660
  }
666
661
  get(scope, key) {
667
662
  // avoids naming collisions with keys like
@@ -698,9 +693,7 @@ class ObjectValue extends VoidValue {
698
693
  return super.call(scope, args);
699
694
  return $call.call(scope, args);
700
695
  }
701
- ensureOwned() {
702
- this.owner ??= new ValueOwner({ scope: this.scope, value: this });
703
- }
696
+ ensureOwned() { }
704
697
  }
705
698
  for (const op of operators) {
706
699
  ObjectValue.prototype[op] = function (...args) {
@@ -769,8 +762,8 @@ class SenseableValue extends StoreValue {
769
762
  * each of them to their counterparts on the right hand value.
770
763
  */
771
764
  class DestructuringValue extends VoidValue {
772
- constructor(scope, members) {
773
- super(scope);
765
+ constructor(members) {
766
+ super();
774
767
  this.members = members;
775
768
  this.macro = true;
776
769
  }
@@ -957,7 +950,7 @@ const DeclareObjectPattern = (c, scope, node, kind, base) => {
957
950
  throw new CompilerError("The rest operator is not supported", prop);
958
951
  const { key, value } = prop;
959
952
  const keyInst = key.type === "Identifier" && !prop.computed
960
- ? [new LiteralValue(scope, key.name), []]
953
+ ? [new LiteralValue(key.name), []]
961
954
  : c.handleConsume(scope, prop.key);
962
955
  const propInit = init.get(scope, keyInst[0]);
963
956
  const declarationInst = Declare(c, scope, value, kind, propInit[0]);
@@ -966,14 +959,14 @@ const DeclareObjectPattern = (c, scope, node, kind, base) => {
966
959
  return [null, [...inst, ...propertiesInst[1]]];
967
960
  };
968
961
 
969
- const Literal = (_c, scope, node) => [new LiteralValue(scope, node.value), []];
962
+ const Literal = (_c, scope, node) => [new LiteralValue(node.value), []];
970
963
  const NumericLiteral = Literal;
971
964
  const StringLiteral = Literal;
972
- const NullLiteral = (_c, scope) => [
973
- new LiteralValue(scope, null),
965
+ const NullLiteral = () => [
966
+ new LiteralValue(null),
974
967
  [],
975
968
  ];
976
- const BooleanLiteral = (_c, scope, node) => [new LiteralValue(scope, +node.value), []];
969
+ const BooleanLiteral = (_c, scope, node) => [new LiteralValue(+node.value), []];
977
970
 
978
971
  const LRExpression = (c, scope, node) => {
979
972
  const [left, leftInst] = c.handleConsume(scope, node.left);
@@ -985,8 +978,8 @@ const BinaryExpression = LRExpression;
985
978
  const LogicalExpression = (c, scope, node) => {
986
979
  if (node.operator !== "??")
987
980
  return LRExpression(c, scope, node);
988
- const nullLiteral = new LiteralValue(scope, null);
989
- const endAdress = new LiteralValue(scope, null);
981
+ const nullLiteral = new LiteralValue(null);
982
+ const endAdress = new LiteralValue(null);
990
983
  const [left, leftInst] = c.handleEval(scope, node.left);
991
984
  const [nullTest] = left["=="](scope, nullLiteral);
992
985
  if (nullTest instanceof LiteralValue) {
@@ -1045,13 +1038,13 @@ const ConditionalExpression = (c, scope, node) => {
1045
1038
  result.ensureOwned();
1046
1039
  const consequent = c.handleEval(scope, node.consequent);
1047
1040
  const alternate = c.handleEval(scope, node.alternate);
1048
- const alternateStartAdress = new LiteralValue(scope, null);
1049
- const endExpressionAdress = new LiteralValue(scope, null);
1041
+ const alternateStartAdress = new LiteralValue(null);
1042
+ const endExpressionAdress = new LiteralValue(null);
1050
1043
  return [
1051
1044
  result,
1052
1045
  [
1053
1046
  ...testInst,
1054
- new JumpInstruction(alternateStartAdress, EJumpKind.Equal, test, new LiteralValue(scope, 0)),
1047
+ new JumpInstruction(alternateStartAdress, EJumpKind.Equal, test, new LiteralValue(0)),
1055
1048
  ...consequent[1],
1056
1049
  ...result["="](scope, consequent[0])[1],
1057
1050
  new JumpInstruction(endExpressionAdress, EJumpKind.Always),
@@ -1071,12 +1064,12 @@ const ExpressionStatement = (c, scope, node) => {
1071
1064
  return c.handle(scope, node.expression);
1072
1065
  };
1073
1066
  const BreakStatement = (_, scope) => {
1074
- const addr = new LiteralValue(scope, null);
1067
+ const addr = new LiteralValue(null);
1075
1068
  scope.break.bind(addr);
1076
1069
  return [null, [new BreakInstruction(addr)]];
1077
1070
  };
1078
1071
  const ContinueStatement = (_, scope) => {
1079
- const addr = new LiteralValue(scope, null);
1072
+ const addr = new LiteralValue(null);
1080
1073
  scope.continue.bind(addr);
1081
1074
  return [null, [new ContinueInstruction(addr)]];
1082
1075
  };
@@ -1098,9 +1091,9 @@ const IfStatement = (c, scope, node) => {
1098
1091
  inst.push(...c.handle(scope, node.alternate)[1]);
1099
1092
  return [null, inst];
1100
1093
  }
1101
- const endIfAddr = new LiteralValue(scope, null);
1102
- inst.push(...testInst, new JumpInstruction(endIfAddr, EJumpKind.Equal, test, new LiteralValue(scope, 0)), ...withAlwaysRuns(c.handle(scope, node.consequent), false)[1], new AddressResolver(endIfAddr));
1103
- const endElseAddr = new LiteralValue(scope, null);
1094
+ const endIfAddr = new LiteralValue(null);
1095
+ inst.push(...testInst, new JumpInstruction(endIfAddr, EJumpKind.Equal, test, new LiteralValue(0)), ...withAlwaysRuns(c.handle(scope, node.consequent), false)[1], new AddressResolver(endIfAddr));
1096
+ const endElseAddr = new LiteralValue(null);
1104
1097
  if (node.alternate) {
1105
1098
  inst.push(new JumpInstruction(endElseAddr, EJumpKind.Always), new AddressResolver(endIfAddr), ...withAlwaysRuns(c.handle(scope, node.alternate), false)[1], new AddressResolver(endElseAddr));
1106
1099
  }
@@ -1111,13 +1104,13 @@ const SwitchStatement = (c, scope, node) => {
1111
1104
  const innerScope = scope.createScope();
1112
1105
  const [ref, refInst] = c.handleConsume(scope, node.discriminant);
1113
1106
  const inst = [];
1114
- const endAdress = new LiteralValue(innerScope, null);
1107
+ const endAdress = new LiteralValue(null);
1115
1108
  const endLine = new AddressResolver(endAdress).bindBreak(innerScope);
1116
1109
  const caseJumps = [];
1117
1110
  let defaultJump;
1118
1111
  for (const scase of node.cases) {
1119
1112
  const [, bodyInst] = c.handleMany(innerScope, scase.consequent);
1120
- const bodyAdress = new LiteralValue(innerScope, null);
1113
+ const bodyAdress = new LiteralValue(null);
1121
1114
  const bodyLine = new AddressResolver(bodyAdress);
1122
1115
  if (!scase.test) {
1123
1116
  [defaultJump] = c.handle(innerScope, scase, () => [
@@ -1171,8 +1164,8 @@ const SwitchStatement = (c, scope, node) => {
1171
1164
  const WhileStatement = (c, scope, node) => {
1172
1165
  const lines = [];
1173
1166
  const [test, testLines] = c.handleConsume(scope, node.test);
1174
- const startLoopAddr = new LiteralValue(scope, null);
1175
- const endLoopAddr = new LiteralValue(scope, null);
1167
+ const startLoopAddr = new LiteralValue(null);
1168
+ const endLoopAddr = new LiteralValue(null);
1176
1169
  const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
1177
1170
  const endLoopLine = new AddressResolver(endLoopAddr).bindBreak(scope);
1178
1171
  if (test instanceof LiteralValue) {
@@ -1181,13 +1174,13 @@ const WhileStatement = (c, scope, node) => {
1181
1174
  }
1182
1175
  return [null, lines];
1183
1176
  }
1184
- lines.push(startLoopLine, ...testLines, new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(scope, 0)), ...withAlwaysRuns(c.handle(scope, node.body), false)[1], new JumpInstruction(startLoopAddr, EJumpKind.Always), endLoopLine);
1177
+ 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);
1185
1178
  return [null, lines];
1186
1179
  };
1187
1180
  const DoWhileStatement = (c, scope, node) => {
1188
1181
  const lines = [];
1189
1182
  const [test, testLines] = c.handleConsume(scope, node.test);
1190
- const startLoopAddr = new LiteralValue(scope, null);
1183
+ const startLoopAddr = new LiteralValue(null);
1191
1184
  const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
1192
1185
  const [, bodyLines] = c.handle(scope, node.body);
1193
1186
  if (test instanceof LiteralValue) {
@@ -1203,7 +1196,7 @@ const DoWhileStatement = (c, scope, node) => {
1203
1196
  ],
1204
1197
  ];
1205
1198
  }
1206
- lines.push(startLoopLine, ...bodyLines, ...testLines, new JumpInstruction(startLoopAddr, EJumpKind.Equal, test, new LiteralValue(scope, 1)));
1199
+ lines.push(startLoopLine, ...bodyLines, ...testLines, new JumpInstruction(startLoopAddr, EJumpKind.Equal, test, new LiteralValue(1)));
1207
1200
  return [null, lines];
1208
1201
  };
1209
1202
 
@@ -1212,10 +1205,10 @@ const ForStatement = (c, scope, node) => {
1212
1205
  const initInst = node.init ? c.handle(scope, node.init)[1] : [];
1213
1206
  const [test, testLines] = node.test
1214
1207
  ? c.handleConsume(scope, node.test)
1215
- : [new LiteralValue(scope, 1), []];
1208
+ : [new LiteralValue(1), []];
1216
1209
  const updateLines = node.update ? c.handle(scope, node.update)[1] : [];
1217
- const startLoopAddr = new LiteralValue(scope, null);
1218
- const endLoopAddr = new LiteralValue(scope, null);
1210
+ const startLoopAddr = new LiteralValue(null);
1211
+ const endLoopAddr = new LiteralValue(null);
1219
1212
  const startLoopLine = new AddressResolver(startLoopAddr).bindContinue(scope);
1220
1213
  const endLoopLine = new AddressResolver(endLoopAddr).bindBreak(scope);
1221
1214
  return [
@@ -1224,7 +1217,7 @@ const ForStatement = (c, scope, node) => {
1224
1217
  ...initInst,
1225
1218
  startLoopLine,
1226
1219
  ...testLines,
1227
- new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(scope, 0)),
1220
+ new JumpInstruction(endLoopAddr, EJumpKind.Equal, test, new LiteralValue(0)),
1228
1221
  ...withAlwaysRuns(c.handle(scope, node.body), false)[1],
1229
1222
  ...updateLines,
1230
1223
  new JumpInstruction(startLoopAddr, EJumpKind.Always),
@@ -1234,20 +1227,20 @@ const ForStatement = (c, scope, node) => {
1234
1227
  };
1235
1228
 
1236
1229
  class FunctionValue extends VoidValue {
1237
- constructor({ scope, params, body, c, node, }) {
1238
- super(scope);
1230
+ constructor({ scope, params, body, c, }) {
1231
+ super();
1239
1232
  this.mutability = EMutability.constant;
1240
1233
  this.macro = true;
1241
1234
  this.paramOwners = [];
1242
1235
  this.bundled = false;
1243
1236
  this.initialized = false;
1237
+ this.scope = scope;
1244
1238
  this.body = body;
1245
1239
  this.c = c;
1246
- this.node = node;
1247
1240
  this.params = params;
1248
1241
  }
1249
- typeof(scope) {
1250
- return [new LiteralValue(scope, "function"), []];
1242
+ typeof() {
1243
+ return [new LiteralValue("function"), []];
1251
1244
  }
1252
1245
  initScope(name) {
1253
1246
  this.childScope = this.scope.createFunction(name);
@@ -1275,7 +1268,7 @@ class FunctionValue extends VoidValue {
1275
1268
  this.initialized = true;
1276
1269
  const { name } = this.owner;
1277
1270
  this.initScope(name);
1278
- this.addr = new LiteralValue(this.childScope, null);
1271
+ this.addr = new LiteralValue(null);
1279
1272
  this.temp = new ValueOwner({
1280
1273
  scope: this.childScope,
1281
1274
  name: `${internalPrefix}f${name}`,
@@ -1309,7 +1302,7 @@ class FunctionValue extends VoidValue {
1309
1302
  if (!this.bundled)
1310
1303
  this.childScope.inst.push(...this.inst);
1311
1304
  this.bundled = true;
1312
- const callAddressLiteral = new LiteralValue(scope, null);
1305
+ const callAddressLiteral = new LiteralValue(null);
1313
1306
  const inst = this.paramOwners
1314
1307
  .map(({ value: param }, i) => param["="](scope, args[i])[1])
1315
1308
  .reduce((s, c) => s.concat(c), [])
@@ -1347,7 +1340,7 @@ class FunctionValue extends VoidValue {
1347
1340
  name: owner.name,
1348
1341
  }));
1349
1342
  });
1350
- this.inlineEnd = new LiteralValue(scope, null);
1343
+ this.inlineEnd = new LiteralValue(null);
1351
1344
  this.tryingInline = true;
1352
1345
  let inst = this.c.handle(fnScope, this.body)[1];
1353
1346
  this.tryingInline = false;
@@ -1406,7 +1399,6 @@ function handleFunctionNode(c, scope, node) {
1406
1399
  }
1407
1400
  return [
1408
1401
  new FunctionValue({
1409
- node,
1410
1402
  scope,
1411
1403
  params: params,
1412
1404
  body,
@@ -1452,8 +1444,8 @@ const NewExpression = CallExpression;
1452
1444
  const TaggedTemplateExpression = (c, scope, node) => {
1453
1445
  const [tag, tagInst] = c.handleConsume(scope, node.tag);
1454
1446
  const template = node.quasi;
1455
- const stringsObject = ObjectValue.fromArray(scope, template.quasis.map(quasi => new LiteralValue(scope, quasi.value.cooked ?? "")), {
1456
- raw: ObjectValue.fromArray(scope, template.quasis.map(quasi => new LiteralValue(scope, quasi.value.raw))),
1447
+ const stringsObject = ObjectValue.fromArray(template.quasis.map(quasi => new LiteralValue(quasi.value.cooked ?? "")), {
1448
+ raw: ObjectValue.fromArray(template.quasis.map(quasi => new LiteralValue(quasi.value.raw))),
1457
1449
  });
1458
1450
  const expressions = [];
1459
1451
  const expressionInsts = [];
@@ -1498,7 +1490,7 @@ const ObjectExpression = (c, scope, node) => {
1498
1490
  data[index] = member;
1499
1491
  inst.push(...memberInst);
1500
1492
  }
1501
- return [new ObjectValue(scope, data), inst];
1493
+ return [new ObjectValue(data), inst];
1502
1494
  };
1503
1495
  const ArrayExpression = (c, scope, node) => {
1504
1496
  const items = [];
@@ -1510,13 +1502,13 @@ const ArrayExpression = (c, scope, node) => {
1510
1502
  items.push(value);
1511
1503
  inst.push(...valueInst);
1512
1504
  });
1513
- return [ObjectValue.fromArray(scope, items), inst];
1505
+ return [ObjectValue.fromArray(items), inst];
1514
1506
  };
1515
1507
  const MemberExpression = (c, scope, node) => {
1516
1508
  const [obj, objInst] = c.handleConsume(scope, node.object);
1517
1509
  const [prop, propInst] = node.computed
1518
1510
  ? c.handleConsume(scope, node.property)
1519
- : [new LiteralValue(scope, node.property.name), []];
1511
+ : [new LiteralValue(node.property.name), []];
1520
1512
  const [got, gotInst] = obj.get(scope, prop);
1521
1513
  return [got, [...objInst, ...propInst, ...gotInst]];
1522
1514
  };
@@ -1531,9 +1523,9 @@ const ArrayPattern = (c, scope, node) => {
1531
1523
  if (!valueInst[0])
1532
1524
  throw new CompilerError("Destructuring element must resolve to a value", element);
1533
1525
  inst.push(...valueInst[1]);
1534
- members.set(new LiteralValue(scope, i), valueInst[0]);
1526
+ members.set(new LiteralValue(i), valueInst[0]);
1535
1527
  }
1536
- return [new DestructuringValue(scope, members), inst];
1528
+ return [new DestructuringValue(members), inst];
1537
1529
  };
1538
1530
  const ObjectPattern = (c, scope, node) => {
1539
1531
  const inst = [];
@@ -1545,7 +1537,7 @@ const ObjectPattern = (c, scope, node) => {
1545
1537
  continue;
1546
1538
  const { key } = prop;
1547
1539
  const keyInst = !prop.computed && key.type === "Identifier"
1548
- ? [new LiteralValue(scope, key.name), []]
1540
+ ? [new LiteralValue(key.name), []]
1549
1541
  : c.handleConsume(scope, prop.key);
1550
1542
  inst.push(...keyInst[1]);
1551
1543
  const valueInst = c.handle(scope, prop.value);
@@ -1554,7 +1546,7 @@ const ObjectPattern = (c, scope, node) => {
1554
1546
  inst.push(...valueInst[1]);
1555
1547
  members.set(keyInst[0], valueInst[0]);
1556
1548
  }
1557
- return [new DestructuringValue(scope, members), inst];
1549
+ return [new DestructuringValue(members), inst];
1558
1550
  };
1559
1551
 
1560
1552
  const TemplateLiteral = () => {
@@ -1594,7 +1586,7 @@ const TSEnumDeclaration = (c, scope, node) => {
1594
1586
  throw new CompilerError("This enum member must be initialized", member);
1595
1587
  const [value] = member.initializer
1596
1588
  ? c.handleEval(scope, member.initializer)
1597
- : [new LiteralValue(scope, counter)];
1589
+ : [new LiteralValue(counter)];
1598
1590
  if (!(value instanceof LiteralValue))
1599
1591
  throw new CompilerError("Enum members must contain literal values", member);
1600
1592
  if (typeof value.data === "number") {
@@ -1609,7 +1601,7 @@ const TSEnumDeclaration = (c, scope, node) => {
1609
1601
  }
1610
1602
  scope.set(new ValueOwner({
1611
1603
  scope,
1612
- value: new ObjectValue(scope, data),
1604
+ value: new ObjectValue(data),
1613
1605
  constant: true,
1614
1606
  identifier: node.id.name,
1615
1607
  name: nodeName(node, !c.compactNames && node.id.name),
@@ -1670,14 +1662,14 @@ var handlers = /*#__PURE__*/Object.freeze({
1670
1662
  });
1671
1663
 
1672
1664
  class MacroFunction extends VoidValue {
1673
- constructor(scope, fn) {
1674
- super(scope);
1665
+ constructor(fn) {
1666
+ super();
1675
1667
  this.macro = true;
1676
1668
  this.constant = true;
1677
1669
  this.fn = fn;
1678
1670
  }
1679
1671
  call(scope, args) {
1680
- return this.fn.apply(this, args);
1672
+ return this.fn.apply(this, [scope, ...args]);
1681
1673
  }
1682
1674
  eval(_scope) {
1683
1675
  return [this, []];
@@ -1708,16 +1700,16 @@ const mathOperations = {
1708
1700
  sqrt: a => Math.sqrt(a),
1709
1701
  rand: null,
1710
1702
  };
1711
- function createMacroMathOperations(scope) {
1703
+ function createMacroMathOperations() {
1712
1704
  const macroMathOperations = {};
1713
1705
  for (const key in mathOperations) {
1714
1706
  const fn = mathOperations[key];
1715
- macroMathOperations[key] = new MacroFunction(scope, (a, b) => {
1707
+ macroMathOperations[key] = new MacroFunction((scope, a, b) => {
1716
1708
  if (b) {
1717
1709
  if (fn && a instanceof LiteralValue && b instanceof LiteralValue) {
1718
1710
  if (typeof a.data !== "number" || typeof b.data !== "number")
1719
1711
  throw new CompilerError("Cannot do math operation with non-numerical literals.");
1720
- return [new LiteralValue(scope, fn(a.num, b.num)), []];
1712
+ return [new LiteralValue(fn(a.num, b.num)), []];
1721
1713
  }
1722
1714
  const temp = new StoreValue(scope);
1723
1715
  return [temp, [new OperationInstruction(key, temp, a, b)]];
@@ -1725,7 +1717,7 @@ function createMacroMathOperations(scope) {
1725
1717
  if (fn && a instanceof LiteralValue) {
1726
1718
  if (typeof a.data !== "number")
1727
1719
  throw new CompilerError("Cannot do math operation with non-numerical literal.");
1728
- return [new LiteralValue(scope, fn(a.num)), []];
1720
+ return [new LiteralValue(fn(a.num)), []];
1729
1721
  }
1730
1722
  const temp = new StoreValue(scope);
1731
1723
  return [temp, [new OperationInstruction(key, temp, a, b)]];
@@ -1734,21 +1726,21 @@ function createMacroMathOperations(scope) {
1734
1726
  return macroMathOperations;
1735
1727
  }
1736
1728
  class MlogMath extends ObjectValue {
1737
- constructor(scope) {
1738
- super(scope, createMacroMathOperations(scope));
1729
+ constructor() {
1730
+ super(createMacroMathOperations());
1739
1731
  }
1740
1732
  }
1741
1733
  // op angle result a b
1742
1734
  // op len result a b
1743
1735
 
1744
1736
  class Concat extends MacroFunction {
1745
- constructor(scope) {
1746
- super(scope, (...values) => {
1737
+ constructor() {
1738
+ super((scope, ...values) => {
1747
1739
  for (const value of values)
1748
1740
  if (!(value instanceof LiteralValue))
1749
1741
  throw new CompilerError("Concat arguments must all be literal values.");
1750
1742
  return [
1751
- new LiteralValue(scope, values.map(v => v.data).join("")),
1743
+ new LiteralValue(values.map(v => v.data).join("")),
1752
1744
  [],
1753
1745
  ];
1754
1746
  });
@@ -1803,18 +1795,18 @@ function assertObjectFields(value, fields) {
1803
1795
  }
1804
1796
 
1805
1797
  /** Used to create namespaces that contain multiple methods that map into instructions */
1806
- function createOverloadNamespace({ scope, overloads, handler, }) {
1798
+ function createOverloadNamespace({ overloads, handler, }) {
1807
1799
  const result = {};
1808
1800
  for (const key in overloads) {
1809
1801
  const { named, args } = overloads[key];
1810
1802
  if (named) {
1811
- result[key] = new MacroFunction(scope, options => {
1803
+ result[key] = new MacroFunction((scope, options) => {
1812
1804
  assertIsObjectMacro(options, named);
1813
- return handler(key, ...assertObjectFields(options, args));
1805
+ return handler(scope, key, ...assertObjectFields(options, args));
1814
1806
  });
1815
1807
  continue;
1816
1808
  }
1817
- result[key] = new MacroFunction(scope, (...params) => {
1809
+ result[key] = new MacroFunction((scope, ...params) => {
1818
1810
  const handlerParams = [];
1819
1811
  // validate the paramters
1820
1812
  for (let i = 0; i < args.length; i++) {
@@ -1831,16 +1823,15 @@ function createOverloadNamespace({ scope, overloads, handler, }) {
1831
1823
  arg.validate?.(param);
1832
1824
  handlerParams.push(param);
1833
1825
  }
1834
- return handler(key, ...handlerParams);
1826
+ return handler(scope, key, ...handlerParams);
1835
1827
  });
1836
1828
  }
1837
1829
  return result;
1838
1830
  }
1839
1831
 
1840
1832
  class Draw extends ObjectValue {
1841
- constructor(scope) {
1833
+ constructor() {
1842
1834
  const data = createOverloadNamespace({
1843
- scope,
1844
1835
  overloads: {
1845
1836
  clear: {
1846
1837
  args: ["r", "g", "b"],
@@ -1877,17 +1868,17 @@ class Draw extends ObjectValue {
1877
1868
  args: ["x", "y", "image", "size", "rotation"],
1878
1869
  },
1879
1870
  },
1880
- handler(overload, ...args) {
1871
+ handler(scope, overload, ...args) {
1881
1872
  return [null, [new InstructionBase("draw", overload, ...args)]];
1882
1873
  },
1883
1874
  });
1884
- super(scope, data);
1875
+ super(data);
1885
1876
  }
1886
1877
  }
1887
1878
 
1888
1879
  class Print extends MacroFunction {
1889
- constructor(scope) {
1890
- super(scope, (...values) => {
1880
+ constructor() {
1881
+ super((scope, ...values) => {
1891
1882
  const [first] = values;
1892
1883
  const inst = [];
1893
1884
  if (!isTemplateObjectArray(first)) {
@@ -1900,12 +1891,12 @@ class Print extends MacroFunction {
1900
1891
  // maybe this should be checked in another way?
1901
1892
  const { length } = first.data;
1902
1893
  for (let i = 1; i < values.length; i++) {
1903
- const [string] = first.get(scope, new LiteralValue(scope, i - 1));
1894
+ const [string] = first.get(scope, new LiteralValue(i - 1));
1904
1895
  if (string.data)
1905
1896
  inst.push(new InstructionBase("print", string));
1906
1897
  inst.push(new InstructionBase("print", values[i]));
1907
1898
  }
1908
- const [tail] = first.get(scope, new LiteralValue(scope, length.data - 1));
1899
+ const [tail] = first.get(scope, new LiteralValue(length.data - 1));
1909
1900
  if (tail.data)
1910
1901
  inst.push(new InstructionBase("print", tail));
1911
1902
  return [null, inst];
@@ -1915,8 +1906,8 @@ class Print extends MacroFunction {
1915
1906
 
1916
1907
  const defaultTargetName$1 = "message1";
1917
1908
  class PrintFlush extends MacroFunction {
1918
- constructor(scope) {
1919
- super(scope, (target) => {
1909
+ constructor() {
1910
+ super((scope, target) => {
1920
1911
  if (!target)
1921
1912
  return [null, [new InstructionBase("printflush", defaultTargetName$1)]];
1922
1913
  if (!(target instanceof SenseableValue))
@@ -1928,8 +1919,8 @@ class PrintFlush extends MacroFunction {
1928
1919
 
1929
1920
  const defaultTargetName = "display1";
1930
1921
  class DrawFlush extends MacroFunction {
1931
- constructor(scope) {
1932
- super(scope, (target) => {
1922
+ constructor() {
1923
+ super((scope, target) => {
1933
1924
  if (!target)
1934
1925
  return [null, [new InstructionBase("drawflush", defaultTargetName)]];
1935
1926
  if (!(target instanceof SenseableValue))
@@ -1940,16 +1931,15 @@ class DrawFlush extends MacroFunction {
1940
1931
  }
1941
1932
 
1942
1933
  class GetBlock extends ObjectValue {
1943
- constructor(scope) {
1934
+ constructor() {
1944
1935
  const data = createOverloadNamespace({
1945
- scope,
1946
1936
  overloads: {
1947
1937
  floor: { args: ["x", "y"] },
1948
1938
  ore: { args: ["x", "y"] },
1949
1939
  block: { args: ["x", "y"] },
1950
1940
  building: { args: ["x", "y"] },
1951
1941
  },
1952
- handler(overload, x, y) {
1942
+ handler(scope, overload, x, y) {
1953
1943
  const output = overload === "building"
1954
1944
  ? new SenseableValue(scope)
1955
1945
  : new StoreValue(scope);
@@ -1959,13 +1949,13 @@ class GetBlock extends ObjectValue {
1959
1949
  ];
1960
1950
  },
1961
1951
  });
1962
- super(scope, data);
1952
+ super(data);
1963
1953
  }
1964
1954
  }
1965
1955
 
1966
1956
  class GetLink extends MacroFunction {
1967
- constructor(scope) {
1968
- super(scope, (index) => {
1957
+ constructor() {
1958
+ super((scope, index) => {
1969
1959
  if (!(index instanceof StoreValue) &&
1970
1960
  (!(index instanceof LiteralValue) || typeof index.data !== "number"))
1971
1961
  throw new CompilerError("The getlink index must be a number literal or a store");
@@ -1976,9 +1966,8 @@ class GetLink extends MacroFunction {
1976
1966
  }
1977
1967
 
1978
1968
  class Control extends ObjectValue {
1979
- constructor(scope) {
1980
- super(scope, createOverloadNamespace({
1981
- scope,
1969
+ constructor() {
1970
+ super(createOverloadNamespace({
1982
1971
  overloads: {
1983
1972
  enabled: { args: ["building", "value"] },
1984
1973
  shoot: {
@@ -1992,7 +1981,7 @@ class Control extends ObjectValue {
1992
1981
  config: { args: ["building", "value"] },
1993
1982
  color: { args: ["building", "r", "g", "b"] },
1994
1983
  },
1995
- handler(overload, ...args) {
1984
+ handler(scope, overload, ...args) {
1996
1985
  return [null, [new InstructionBase("control", overload, ...args)]];
1997
1986
  },
1998
1987
  }));
@@ -2017,8 +2006,8 @@ const validRadarSorts = [
2017
2006
  "maxHealth",
2018
2007
  ];
2019
2008
  class Radar extends MacroFunction {
2020
- constructor(scope) {
2021
- super(scope, options => {
2009
+ constructor() {
2010
+ super((scope, options) => {
2022
2011
  assertIsObjectMacro(options, "The radar options");
2023
2012
  const { building, filters, order, sort } = options.data;
2024
2013
  if (!(building instanceof SenseableValue))
@@ -2049,8 +2038,8 @@ class Radar extends MacroFunction {
2049
2038
  }
2050
2039
 
2051
2040
  class Sensor extends MacroFunction {
2052
- constructor(scope) {
2053
- super(scope, (property, target) => {
2041
+ constructor() {
2042
+ super((scope, property, target) => {
2054
2043
  if (!(property instanceof StoreValue))
2055
2044
  throw new CompilerError("The sensor property must be a store");
2056
2045
  if (!(target instanceof SenseableValue))
@@ -2064,8 +2053,8 @@ class Sensor extends MacroFunction {
2064
2053
  }
2065
2054
 
2066
2055
  class Wait extends MacroFunction {
2067
- constructor(scope) {
2068
- super(scope, seconds => {
2056
+ constructor() {
2057
+ super((scope, seconds) => {
2069
2058
  if (!(seconds instanceof StoreValue) &&
2070
2059
  !(seconds instanceof LiteralValue && typeof seconds.data === "number"))
2071
2060
  throw new CompilerError("The wait seconds must be either a number literal or a store");
@@ -2075,16 +2064,15 @@ class Wait extends MacroFunction {
2075
2064
  }
2076
2065
 
2077
2066
  class Lookup extends ObjectValue {
2078
- constructor(scope) {
2067
+ constructor() {
2079
2068
  const data = createOverloadNamespace({
2080
- scope,
2081
2069
  overloads: {
2082
2070
  block: { args: ["index"] },
2083
2071
  unit: { args: ["index"] },
2084
2072
  item: { args: ["index"] },
2085
2073
  liquid: { args: ["index"] },
2086
2074
  },
2087
- handler(overload, index) {
2075
+ handler(scope, overload, index) {
2088
2076
  const output = new StoreValue(scope);
2089
2077
  return [
2090
2078
  output,
@@ -2092,13 +2080,13 @@ class Lookup extends ObjectValue {
2092
2080
  ];
2093
2081
  },
2094
2082
  });
2095
- super(scope, data);
2083
+ super(data);
2096
2084
  }
2097
2085
  }
2098
2086
 
2099
2087
  class PackColor extends MacroFunction {
2100
- constructor(scope) {
2101
- super(scope, (...args) => {
2088
+ constructor() {
2089
+ super((scope, ...args) => {
2102
2090
  if (args.length !== 4) {
2103
2091
  throw new CompilerError(`Expected 4 arguments, received ${args.length}`);
2104
2092
  }
@@ -2113,15 +2101,14 @@ class PackColor extends MacroFunction {
2113
2101
  }
2114
2102
 
2115
2103
  class End extends MacroFunction {
2116
- constructor(scope) {
2117
- super(scope, () => [null, [new EndInstruction()]]);
2104
+ constructor() {
2105
+ super(() => [null, [new EndInstruction()]]);
2118
2106
  }
2119
2107
  }
2120
2108
 
2121
2109
  class SetBlock extends ObjectValue {
2122
- constructor(scope) {
2110
+ constructor() {
2123
2111
  const data = createOverloadNamespace({
2124
- scope,
2125
2112
  overloads: {
2126
2113
  floor: { args: ["x", "y", "to"] },
2127
2114
  ore: { args: ["x", "y", "to"] },
@@ -2130,7 +2117,7 @@ class SetBlock extends ObjectValue {
2130
2117
  args: ["x", "y", "to", "team", { key: "rotation", default: "0" }],
2131
2118
  },
2132
2119
  },
2133
- handler(overload, x, y, to, team, rotation) {
2120
+ handler(scope, overload, x, y, to, team, rotation) {
2134
2121
  return [
2135
2122
  null,
2136
2123
  [
@@ -2139,13 +2126,13 @@ class SetBlock extends ObjectValue {
2139
2126
  ];
2140
2127
  },
2141
2128
  });
2142
- super(scope, data);
2129
+ super(data);
2143
2130
  }
2144
2131
  }
2145
2132
 
2146
2133
  class SpawnUnit extends MacroFunction {
2147
- constructor(scope) {
2148
- super(scope, options => {
2134
+ constructor() {
2135
+ super((scope, options) => {
2149
2136
  assertIsObjectMacro(options, "The options");
2150
2137
  const { type, x, y, team, rotation } = options.data;
2151
2138
  assertIsRuntimeValue(type, "type");
@@ -2164,14 +2151,14 @@ class SpawnUnit extends MacroFunction {
2164
2151
  }
2165
2152
 
2166
2153
  class Stop extends MacroFunction {
2167
- constructor(scope) {
2168
- super(scope, () => [null, [new InstructionBase("stop")]]);
2154
+ constructor() {
2155
+ super(() => [null, [new InstructionBase("stop")]]);
2169
2156
  }
2170
2157
  }
2171
2158
 
2172
2159
  class UnitBind extends MacroFunction {
2173
- constructor(scope) {
2174
- super(scope, type => {
2160
+ constructor() {
2161
+ super((scope, type) => {
2175
2162
  if (!(type instanceof StoreValue))
2176
2163
  throw new CompilerError("The unitBind type must be a store");
2177
2164
  return [null, [new InstructionBase("ubind", type)]];
@@ -2180,9 +2167,8 @@ class UnitBind extends MacroFunction {
2180
2167
  }
2181
2168
 
2182
2169
  class UnitControl extends ObjectValue {
2183
- constructor(scope) {
2170
+ constructor() {
2184
2171
  const data = createOverloadNamespace({
2185
- scope,
2186
2172
  overloads: {
2187
2173
  idle: { args: [] },
2188
2174
  stop: { args: [] },
@@ -2211,21 +2197,21 @@ class UnitControl extends ObjectValue {
2211
2197
  args: ["x", "y", "radius"],
2212
2198
  },
2213
2199
  },
2214
- handler(overload, ...args) {
2200
+ handler(scope, overload, ...args) {
2215
2201
  let result = null;
2216
2202
  let extraArgs = [];
2217
2203
  switch (overload) {
2218
2204
  case "getBlock": {
2219
2205
  const outType = new StoreValue(scope);
2220
2206
  const outBuilding = new SenseableValue(scope);
2221
- result = ObjectValue.fromArray(scope, [outType, outBuilding]);
2222
- extraArgs = [outType, outBuilding, new LiteralValue(scope, 0)];
2207
+ result = ObjectValue.fromArray([outType, outBuilding]);
2208
+ extraArgs = [outType, outBuilding, new LiteralValue(0)];
2223
2209
  break;
2224
2210
  }
2225
2211
  case "within": {
2226
2212
  const temp = new StoreValue(scope);
2227
2213
  result = temp;
2228
- extraArgs = [temp, new LiteralValue(scope, 0)];
2214
+ extraArgs = [temp, new LiteralValue(0)];
2229
2215
  break;
2230
2216
  }
2231
2217
  }
@@ -2235,13 +2221,13 @@ class UnitControl extends ObjectValue {
2235
2221
  ];
2236
2222
  },
2237
2223
  });
2238
- super(scope, data);
2224
+ super(data);
2239
2225
  }
2240
2226
  }
2241
2227
 
2242
2228
  class UnitRadar extends MacroFunction {
2243
- constructor(scope) {
2244
- super(scope, options => {
2229
+ constructor() {
2230
+ super((scope, options) => {
2245
2231
  assertIsObjectMacro(options, "The radar options");
2246
2232
  const { filters, order, sort } = options.data;
2247
2233
  assertIsArrayMacro(filters, "filters");
@@ -2282,9 +2268,8 @@ const validBuildingGroups = [
2282
2268
  "reactor",
2283
2269
  ];
2284
2270
  class UnitLocate extends ObjectValue {
2285
- constructor(scope) {
2271
+ constructor() {
2286
2272
  const data = createOverloadNamespace({
2287
- scope,
2288
2273
  overloads: {
2289
2274
  ore: {
2290
2275
  args: ["ore"],
@@ -2297,7 +2282,7 @@ class UnitLocate extends ObjectValue {
2297
2282
  args: [],
2298
2283
  },
2299
2284
  },
2300
- handler(overload, ...args) {
2285
+ handler(scope, overload, ...args) {
2301
2286
  const outFound = new StoreValue(scope);
2302
2287
  const outX = new StoreValue(scope);
2303
2288
  const outY = new StoreValue(scope);
@@ -2325,7 +2310,7 @@ class UnitLocate extends ObjectValue {
2325
2310
  }
2326
2311
  }
2327
2312
  return [
2328
- ObjectValue.fromArray(scope, [
2313
+ ObjectValue.fromArray([
2329
2314
  outFound,
2330
2315
  outX,
2331
2316
  outY,
@@ -2335,7 +2320,7 @@ class UnitLocate extends ObjectValue {
2335
2320
  ];
2336
2321
  },
2337
2322
  });
2338
- super(scope, data);
2323
+ super(data);
2339
2324
  }
2340
2325
  }
2341
2326
 
@@ -2356,16 +2341,15 @@ const validEffects = [
2356
2341
  "blasted",
2357
2342
  ];
2358
2343
  class ApplyStatus extends ObjectValue {
2359
- constructor(scope) {
2344
+ constructor() {
2360
2345
  const data = createOverloadNamespace({
2361
- scope,
2362
2346
  overloads: {
2363
2347
  apply: {
2364
2348
  args: ["status", "unit", { key: "duration", default: "10" }],
2365
2349
  },
2366
2350
  clear: { args: ["status", "unit"] },
2367
2351
  },
2368
- handler(overload, effect, unit, duration) {
2352
+ handler(scope, overload, effect, unit, duration) {
2369
2353
  if (!(effect instanceof LiteralValue))
2370
2354
  throw new CompilerError("The status effect must be a string literal");
2371
2355
  assertLiteralOneOf(effect, validEffects, "The status effect");
@@ -2377,13 +2361,13 @@ class ApplyStatus extends ObjectValue {
2377
2361
  ];
2378
2362
  },
2379
2363
  });
2380
- super(scope, data);
2364
+ super(data);
2381
2365
  }
2382
2366
  }
2383
2367
 
2384
2368
  class SpawnWave extends MacroFunction {
2385
- constructor(scope) {
2386
- super(scope, (natural, x, y) => {
2369
+ constructor() {
2370
+ super((scope, natural, x, y) => {
2387
2371
  if (!(natural instanceof LiteralValue) ||
2388
2372
  (natural.data !== 1 && natural.data !== 0))
2389
2373
  throw new CompilerError("The 'natural' argument must be a boolean literal");
@@ -2398,9 +2382,8 @@ class SpawnWave extends MacroFunction {
2398
2382
  }
2399
2383
 
2400
2384
  class SetRule extends ObjectValue {
2401
- constructor(scope) {
2385
+ constructor() {
2402
2386
  const data = createOverloadNamespace({
2403
- scope,
2404
2387
  overloads: {
2405
2388
  currentWaveTime: { args: ["seconds"] },
2406
2389
  waveTimer: { args: ["enabled"] },
@@ -2424,7 +2407,7 @@ class SetRule extends ObjectValue {
2424
2407
  rtsMinWeight: { args: ["team", "value"] },
2425
2408
  rtsMinSquad: { args: ["team", "value"] },
2426
2409
  },
2427
- handler(overload, ...args) {
2410
+ handler(scope, overload, ...args) {
2428
2411
  const params = ["10", "0", "0", "100", "100"];
2429
2412
  switch (overload) {
2430
2413
  case "mapArea": {
@@ -2453,49 +2436,47 @@ class SetRule extends ObjectValue {
2453
2436
  return [null, [new InstructionBase("setrule", overload, ...params)]];
2454
2437
  },
2455
2438
  });
2456
- super(scope, data);
2439
+ super(data);
2457
2440
  }
2458
2441
  }
2459
2442
 
2460
2443
  class FlushMessage extends ObjectValue {
2461
- constructor(scope) {
2444
+ constructor() {
2462
2445
  const data = createOverloadNamespace({
2463
- scope,
2464
2446
  overloads: {
2465
2447
  notify: { args: [] },
2466
2448
  mission: { args: [] },
2467
2449
  announce: { args: ["duration"] },
2468
2450
  toast: { args: ["duration"] },
2469
2451
  },
2470
- handler(overload, duration) {
2452
+ handler(scope, overload, duration) {
2471
2453
  return [null, [new InstructionBase("message", overload, duration)]];
2472
2454
  },
2473
2455
  });
2474
- super(scope, data);
2456
+ super(data);
2475
2457
  }
2476
2458
  }
2477
2459
 
2478
2460
  class Cutscene extends ObjectValue {
2479
- constructor(scope) {
2461
+ constructor() {
2480
2462
  const data = createOverloadNamespace({
2481
- scope,
2482
2463
  overloads: {
2483
2464
  pan: { named: "options", args: ["x", "y", "speed"] },
2484
2465
  zoom: { args: ["level"] },
2485
2466
  stop: { args: [] },
2486
2467
  },
2487
- handler(overload, ...args) {
2468
+ handler(scope, overload, ...args) {
2488
2469
  const params = Object.assign(["100", "100", "0.06", "0"], args);
2489
2470
  return [null, [new InstructionBase("cutscene", overload, ...params)]];
2490
2471
  },
2491
2472
  });
2492
- super(scope, data);
2473
+ super(data);
2493
2474
  }
2494
2475
  }
2495
2476
 
2496
2477
  class Explosion extends MacroFunction {
2497
- constructor(scope) {
2498
- super(scope, options => {
2478
+ constructor() {
2479
+ super((scope, options) => {
2499
2480
  assertIsObjectMacro(options, "The options");
2500
2481
  const params = assertObjectFields(options, [
2501
2482
  "team",
@@ -2513,15 +2494,14 @@ class Explosion extends MacroFunction {
2513
2494
  }
2514
2495
 
2515
2496
  class SetRate extends MacroFunction {
2516
- constructor(scope) {
2517
- super(scope, ipt => [null, [new InstructionBase("setrate", ipt)]]);
2497
+ constructor() {
2498
+ super((scope, ipt) => [null, [new InstructionBase("setrate", ipt)]]);
2518
2499
  }
2519
2500
  }
2520
2501
 
2521
2502
  class Fetch extends ObjectValue {
2522
- constructor(scope) {
2503
+ constructor() {
2523
2504
  const data = createOverloadNamespace({
2524
- scope,
2525
2505
  overloads: {
2526
2506
  unit: { args: ["team", "index"] },
2527
2507
  unitCount: { args: ["team"] },
@@ -2532,7 +2512,7 @@ class Fetch extends ObjectValue {
2532
2512
  build: { args: ["team", "index", "block"] },
2533
2513
  buildCount: { args: ["team", "block"] },
2534
2514
  },
2535
- handler(overload, team, ...rest) {
2515
+ handler(scope, overload, team, ...rest) {
2536
2516
  const output = new SenseableValue(scope);
2537
2517
  const params = ["0", "@conveyor"];
2538
2518
  if (overload === "buildCount") {
@@ -2547,13 +2527,13 @@ class Fetch extends ObjectValue {
2547
2527
  ];
2548
2528
  },
2549
2529
  });
2550
- super(scope, data);
2530
+ super(data);
2551
2531
  }
2552
2532
  }
2553
2533
 
2554
2534
  class GetFlag extends MacroFunction {
2555
- constructor(scope) {
2556
- super(scope, flag => {
2535
+ constructor() {
2536
+ super((scope, flag) => {
2557
2537
  const result = new StoreValue(scope);
2558
2538
  return [result, [new InstructionBase("getflag", result, flag)]];
2559
2539
  });
@@ -2561,8 +2541,8 @@ class GetFlag extends MacroFunction {
2561
2541
  }
2562
2542
 
2563
2543
  class SetFlag extends MacroFunction {
2564
- constructor(scope) {
2565
- super(scope, (flag, value) => {
2544
+ constructor() {
2545
+ super((scope, flag, value) => {
2566
2546
  if (!flag)
2567
2547
  throw new CompilerError("Missing flag argument");
2568
2548
  if (!value)
@@ -2572,36 +2552,48 @@ class SetFlag extends MacroFunction {
2572
2552
  }
2573
2553
  }
2574
2554
 
2575
- class MemoryEntry extends ObjectValue {
2555
+ class MemoryEntry extends BaseValue {
2576
2556
  constructor(scope, mem, prop) {
2577
- super(scope, {
2578
- $eval: new MacroFunction(scope, () => {
2579
- if (this.store)
2580
- return [this.store, []];
2581
- const temp = new StoreValue(scope);
2582
- return [temp, [new InstructionBase("read", temp, mem.cell, prop)]];
2583
- }),
2584
- $consume: new MacroFunction(scope, () => {
2585
- if (this.store)
2586
- return [this.store, []];
2587
- this.ensureOwned();
2588
- this.store = new StoreValue(scope);
2589
- this.owner.own(this.store);
2590
- return [
2591
- this.store,
2592
- [new InstructionBase("read", this.store, mem.cell, prop)],
2593
- ];
2594
- }),
2595
- "$=": new MacroFunction(scope, value => {
2596
- const [data, dataInst] = value.consume(scope);
2597
- return [
2598
- data,
2599
- [...dataInst, new InstructionBase("write", data, mem.cell, prop)],
2600
- ];
2601
- }),
2602
- });
2557
+ super();
2558
+ this.scope = scope;
2559
+ this.mem = mem;
2560
+ this.prop = prop;
2561
+ this.macro = true;
2603
2562
  this.store = null;
2604
2563
  }
2564
+ eval(scope) {
2565
+ if (this.store)
2566
+ return [this.store, []];
2567
+ const temp = new StoreValue(scope);
2568
+ return [
2569
+ temp,
2570
+ [new InstructionBase("read", temp, this.mem.cell, this.prop)],
2571
+ ];
2572
+ }
2573
+ consume(scope) {
2574
+ if (this.store)
2575
+ return [this.store, []];
2576
+ this.ensureOwned();
2577
+ this.store = new StoreValue(scope);
2578
+ this.owner.own(this.store);
2579
+ return [
2580
+ this.store,
2581
+ [new InstructionBase("read", this.store, this.mem.cell, this.prop)],
2582
+ ];
2583
+ }
2584
+ "="(scope, value) {
2585
+ const [data, dataInst] = value.consume(scope);
2586
+ return [
2587
+ data,
2588
+ [
2589
+ ...dataInst,
2590
+ new InstructionBase("write", data, this.mem.cell, this.prop),
2591
+ ],
2592
+ ];
2593
+ }
2594
+ ensureOwned() {
2595
+ this.owner ??= new ValueOwner({ scope: this.scope, value: this });
2596
+ }
2605
2597
  }
2606
2598
  for (const operator of operators) {
2607
2599
  if (operator === "=")
@@ -2612,9 +2604,9 @@ for (const operator of operators) {
2612
2604
  };
2613
2605
  }
2614
2606
  class MemoryMacro extends ObjectValue {
2615
- constructor(scope, cell, size) {
2616
- super(scope, {
2617
- $get: new MacroFunction(scope, (prop) => {
2607
+ constructor(cell, size) {
2608
+ super({
2609
+ $get: new MacroFunction((scope, prop) => {
2618
2610
  if (prop instanceof LiteralValue && typeof prop.data !== "number")
2619
2611
  throw new CompilerError(`Invalid memory object property: "${prop.data}"`);
2620
2612
  const obj = new MemoryEntry(scope, this, prop);
@@ -2624,21 +2616,20 @@ class MemoryMacro extends ObjectValue {
2624
2616
  size,
2625
2617
  });
2626
2618
  this.cell = cell;
2627
- this.name = cell.toString();
2628
2619
  }
2629
2620
  toString() {
2630
- return this.name;
2621
+ return this.cell.toString();
2631
2622
  }
2632
2623
  }
2633
2624
  class MemoryBuilder extends ObjectValue {
2634
- constructor(scope) {
2635
- super(scope, {
2636
- $call: new MacroFunction(scope, (cell, size = new LiteralValue(scope, 64)) => {
2625
+ constructor() {
2626
+ super({
2627
+ $call: new MacroFunction((scope, cell, size = new LiteralValue(64)) => {
2637
2628
  if (!(cell instanceof SenseableValue))
2638
2629
  throw new CompilerError("Memory cell must be a senseable value.");
2639
2630
  if (!(size instanceof LiteralValue && typeof size.data === "number"))
2640
2631
  throw new CompilerError("The memory size must be a number literal.");
2641
- return [new MemoryMacro(scope, cell, size), []];
2632
+ return [new MemoryMacro(cell, size), []];
2642
2633
  }),
2643
2634
  });
2644
2635
  }
@@ -2646,9 +2637,9 @@ class MemoryBuilder extends ObjectValue {
2646
2637
 
2647
2638
  const dynamicVars = ["time", "tick"];
2648
2639
  class NamespaceMacro extends ObjectValue {
2649
- constructor(scope, { changeCasing = false } = {}) {
2650
- super(scope, {
2651
- $get: new MacroFunction(scope, prop => {
2640
+ constructor({ changeCasing = false } = {}) {
2641
+ super({
2642
+ $get: new MacroFunction((scope, prop) => {
2652
2643
  if (!(prop instanceof LiteralValue) || typeof prop.data !== "string")
2653
2644
  throw new CompilerError("Cannot use dynamic properties on namespace macros");
2654
2645
  const symbolName = this.changeCasing
@@ -2672,7 +2663,7 @@ class NamespaceMacro extends ObjectValue {
2672
2663
  }
2673
2664
  class VarsNamespace extends NamespaceMacro {
2674
2665
  constructor(scope) {
2675
- super(scope);
2666
+ super();
2676
2667
  Object.assign(this.data, {
2677
2668
  unit: new ValueOwner({
2678
2669
  scope,
@@ -2689,8 +2680,8 @@ class VarsNamespace extends NamespaceMacro {
2689
2680
  }
2690
2681
 
2691
2682
  class GetGlobal extends MacroFunction {
2692
- constructor(scope, mutability) {
2693
- super(scope, (name) => {
2683
+ constructor(mutability) {
2684
+ super((scope, name) => {
2694
2685
  if (!(name instanceof LiteralValue) || typeof name.data !== "string")
2695
2686
  throw new CompilerError("The name parameter must be a string literal.");
2696
2687
  const owner = new ValueOwner({
@@ -2706,22 +2697,77 @@ class GetGlobal extends MacroFunction {
2706
2697
  }
2707
2698
 
2708
2699
  class Asm extends MacroFunction {
2709
- constructor(scope) {
2710
- super(scope, (stringsArray, ...values) => {
2700
+ constructor() {
2701
+ super((scope, stringsArray, ...values) => {
2711
2702
  if (!isTemplateObjectArray(stringsArray))
2712
2703
  throw new CompilerError("Expected to receive a template strings array");
2713
2704
  const args = [];
2714
2705
  for (let i = 0; i < values.length; i++) {
2715
- const [item] = stringsArray.get(scope, new LiteralValue(scope, i));
2706
+ const [item] = stringsArray.get(scope, new LiteralValue(i));
2716
2707
  args.push(item.data);
2717
2708
  args.push(values[i]);
2718
2709
  }
2719
2710
  const { length } = stringsArray.data;
2720
- const [tail] = stringsArray.get(scope, new LiteralValue(scope, length.data - 1));
2711
+ const [tail] = stringsArray.get(scope, new LiteralValue(length.data - 1));
2721
2712
  args.push(tail.data);
2722
- return [null, [new ZeroSpaceInstruction(...args)]];
2713
+ return [null, formatInstructions(args)];
2723
2714
  });
2724
2715
  }
2716
+ }
2717
+ /** Splits multiline asm calls and formats each line. */
2718
+ function formatInstructions(args) {
2719
+ const instructions = [];
2720
+ let buffer = [];
2721
+ for (let i = 0; i < args.length; i++) {
2722
+ const arg = args[i];
2723
+ if (typeof arg !== "string" || !arg.includes("\n")) {
2724
+ buffer.push(arg);
2725
+ continue;
2726
+ }
2727
+ const segments = arg.split("\n");
2728
+ const params = [...buffer, segments[0]];
2729
+ if (validateInstructionArgs(params)) {
2730
+ instructions.push(new ZeroSpaceInstruction(...params));
2731
+ buffer = [];
2732
+ }
2733
+ // iterates over all segments except the first and last
2734
+ // the first segment was already processed above
2735
+ // the last segment will be added to the buffer because there might
2736
+ // be an interpolation after it
2737
+ // and putting it in the buffer makes sure it has a proper output format
2738
+ for (let i = 1; i < segments.length - 1; i++) {
2739
+ const trimmed = segments[i].trim();
2740
+ if (trimmed.length == 0)
2741
+ continue;
2742
+ instructions.push(new ZeroSpaceInstruction(trimmed));
2743
+ }
2744
+ if (segments.length > 1) {
2745
+ buffer.push(segments[segments.length - 1]);
2746
+ }
2747
+ }
2748
+ if (buffer.length > 0 && validateInstructionArgs(buffer)) {
2749
+ instructions.push(new ZeroSpaceInstruction(...buffer));
2750
+ }
2751
+ return instructions;
2752
+ }
2753
+ /** Determines if an asm line should be generated and trims it at the start and end */
2754
+ function validateInstructionArgs(args) {
2755
+ if (args.length === 0)
2756
+ return false;
2757
+ if (args.length === 1) {
2758
+ const item = args[0];
2759
+ if (typeof item !== "string")
2760
+ return true;
2761
+ args[0] = item.trim();
2762
+ return args[0].length !== 0;
2763
+ }
2764
+ const first = args[0];
2765
+ const last = args[args.length - 1];
2766
+ if (typeof first === "string")
2767
+ args[0] = first.trimStart();
2768
+ if (typeof last === "string")
2769
+ args[args.length - 1] = last.trimEnd();
2770
+ return true;
2725
2771
  }
2726
2772
 
2727
2773
  /**
@@ -2729,53 +2775,53 @@ class Asm extends MacroFunction {
2729
2775
  */
2730
2776
  function initScope(scope) {
2731
2777
  // namespaces
2732
- scope.hardSet("ControlKind", new NamespaceMacro(scope));
2778
+ scope.hardSet("ControlKind", new NamespaceMacro());
2733
2779
  scope.hardSet("Vars", new VarsNamespace(scope));
2734
- scope.hardSet("Teams", new NamespaceMacro(scope));
2735
- scope.hardSet("Items", new NamespaceMacro(scope, { changeCasing: true }));
2736
- scope.hardSet("Liquids", new NamespaceMacro(scope));
2737
- scope.hardSet("Units", new NamespaceMacro(scope, { changeCasing: true }));
2738
- scope.hardSet("LAccess", new NamespaceMacro(scope));
2739
- scope.hardSet("Blocks", new NamespaceMacro(scope, { changeCasing: true }));
2780
+ scope.hardSet("Teams", new NamespaceMacro());
2781
+ scope.hardSet("Items", new NamespaceMacro({ changeCasing: true }));
2782
+ scope.hardSet("Liquids", new NamespaceMacro());
2783
+ scope.hardSet("Units", new NamespaceMacro({ changeCasing: true }));
2784
+ scope.hardSet("LAccess", new NamespaceMacro());
2785
+ scope.hardSet("Blocks", new NamespaceMacro({ changeCasing: true }));
2740
2786
  // helper methods
2741
- scope.hardSet("getBuilding", new GetGlobal(scope, EMutability.constant));
2742
- scope.hardSet("getVar", new GetGlobal(scope, EMutability.mutable));
2743
- scope.hardSet("concat", new Concat(scope));
2744
- scope.hardSet("asm", new Asm(scope));
2745
- scope.hardSet("Math", new MlogMath(scope));
2746
- scope.hardSet("Memory", new MemoryBuilder(scope));
2787
+ scope.hardSet("getBuilding", new GetGlobal(EMutability.constant));
2788
+ scope.hardSet("getVar", new GetGlobal(EMutability.mutable));
2789
+ scope.hardSet("concat", new Concat());
2790
+ scope.hardSet("asm", new Asm());
2791
+ scope.hardSet("Math", new MlogMath());
2792
+ scope.hardSet("Memory", new MemoryBuilder());
2747
2793
  // commands
2748
- scope.hardSet("draw", new Draw(scope));
2749
- scope.hardSet("print", new Print(scope));
2750
- scope.hardSet("printFlush", new PrintFlush(scope));
2751
- scope.hardSet("drawFlush", new DrawFlush(scope));
2752
- scope.hardSet("getLink", new GetLink(scope));
2753
- scope.hardSet("control", new Control(scope));
2754
- scope.hardSet("radar", new Radar(scope));
2755
- scope.hardSet("sensor", new Sensor(scope));
2756
- scope.hardSet("wait", new Wait(scope));
2757
- scope.hardSet("lookup", new Lookup(scope));
2758
- scope.hardSet("packColor", new PackColor(scope));
2759
- scope.hardSet("endScript", new End(scope));
2760
- scope.hardSet("stopScript", new Stop(scope));
2761
- scope.hardSet("unitBind", new UnitBind(scope));
2762
- scope.hardSet("unitControl", new UnitControl(scope));
2763
- scope.hardSet("unitRadar", new UnitRadar(scope));
2764
- scope.hardSet("unitLocate", new UnitLocate(scope));
2794
+ scope.hardSet("draw", new Draw());
2795
+ scope.hardSet("print", new Print());
2796
+ scope.hardSet("printFlush", new PrintFlush());
2797
+ scope.hardSet("drawFlush", new DrawFlush());
2798
+ scope.hardSet("getLink", new GetLink());
2799
+ scope.hardSet("control", new Control());
2800
+ scope.hardSet("radar", new Radar());
2801
+ scope.hardSet("sensor", new Sensor());
2802
+ scope.hardSet("wait", new Wait());
2803
+ scope.hardSet("lookup", new Lookup());
2804
+ scope.hardSet("packColor", new PackColor());
2805
+ scope.hardSet("endScript", new End());
2806
+ scope.hardSet("stopScript", new Stop());
2807
+ scope.hardSet("unitBind", new UnitBind());
2808
+ scope.hardSet("unitControl", new UnitControl());
2809
+ scope.hardSet("unitRadar", new UnitRadar());
2810
+ scope.hardSet("unitLocate", new UnitLocate());
2765
2811
  // world processor commands
2766
- scope.hardSet("getBlock", new GetBlock(scope));
2767
- scope.hardSet("setBlock", new SetBlock(scope));
2768
- scope.hardSet("spawnUnit", new SpawnUnit(scope));
2769
- scope.hardSet("applyStatus", new ApplyStatus(scope));
2770
- scope.hardSet("spawnWave", new SpawnWave(scope));
2771
- scope.hardSet("setRule", new SetRule(scope));
2772
- scope.hardSet("flushMessage", new FlushMessage(scope));
2773
- scope.hardSet("cutscene", new Cutscene(scope));
2774
- scope.hardSet("explosion", new Explosion(scope));
2775
- scope.hardSet("setRate", new SetRate(scope));
2776
- scope.hardSet("fetch", new Fetch(scope));
2777
- scope.hardSet("getFlag", new GetFlag(scope));
2778
- scope.hardSet("setFlag", new SetFlag(scope));
2812
+ scope.hardSet("getBlock", new GetBlock());
2813
+ scope.hardSet("setBlock", new SetBlock());
2814
+ scope.hardSet("spawnUnit", new SpawnUnit());
2815
+ scope.hardSet("applyStatus", new ApplyStatus());
2816
+ scope.hardSet("spawnWave", new SpawnWave());
2817
+ scope.hardSet("setRule", new SetRule());
2818
+ scope.hardSet("flushMessage", new FlushMessage());
2819
+ scope.hardSet("cutscene", new Cutscene());
2820
+ scope.hardSet("explosion", new Explosion());
2821
+ scope.hardSet("setRate", new SetRate());
2822
+ scope.hardSet("fetch", new Fetch());
2823
+ scope.hardSet("getFlag", new GetFlag());
2824
+ scope.hardSet("setFlag", new SetFlag());
2779
2825
  }
2780
2826
 
2781
2827
  class Compiler {