mlogjs 0.2.0 → 0.2.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 (202) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +68 -18
  3. package/build/Compiler.d.ts +18 -18
  4. package/build/Compiler.js +99 -119
  5. package/build/Compiler.js.map +1 -1
  6. package/build/Scope.d.ts +26 -26
  7. package/build/Scope.js +60 -60
  8. package/build/Scope.js.map +1 -1
  9. package/build/bin.d.ts +2 -2
  10. package/build/bin.js +60 -41
  11. package/build/bin.js.map +1 -1
  12. package/build/handlers/BlockStatement.d.ts +2 -2
  13. package/build/handlers/BlockStatement.js +13 -13
  14. package/build/handlers/CallExpression.d.ts +3 -3
  15. package/build/handlers/CallExpression.js +19 -19
  16. package/build/handlers/ForStatement.d.ts +2 -2
  17. package/build/handlers/ForStatement.js +31 -31
  18. package/build/handlers/Function.d.ts +4 -4
  19. package/build/handlers/Function.js +35 -35
  20. package/build/handlers/Identifier.d.ts +2 -2
  21. package/build/handlers/Identifier.js +7 -7
  22. package/build/handlers/IfStatement.d.ts +2 -2
  23. package/build/handlers/IfStatement.js +24 -24
  24. package/build/handlers/Literal.d.ts +2 -2
  25. package/build/handlers/Literal.js +17 -17
  26. package/build/handlers/Object.d.ts +4 -4
  27. package/build/handlers/Object.js +43 -43
  28. package/build/handlers/OperationExpressions.d.ts +7 -7
  29. package/build/handlers/OperationExpressions.js +32 -32
  30. package/build/handlers/Program.d.ts +2 -2
  31. package/build/handlers/Program.js +8 -8
  32. package/build/handlers/Program.js.map +1 -1
  33. package/build/handlers/Statements.d.ts +5 -5
  34. package/build/handlers/Statements.js +29 -29
  35. package/build/handlers/TemplateExpression.d.ts +2 -2
  36. package/build/handlers/TemplateExpression.js +17 -17
  37. package/build/handlers/VariableDeclaration.d.ts +3 -3
  38. package/build/handlers/VariableDeclaration.js +55 -55
  39. package/build/handlers/WhileStatement.d.ts +2 -2
  40. package/build/handlers/WhileStatement.js +22 -22
  41. package/build/handlers/index.d.ts +14 -14
  42. package/build/handlers/index.js +30 -30
  43. package/build/index.d.ts +1 -1
  44. package/build/index.js +7 -7
  45. package/build/initScope.d.ts +2 -0
  46. package/build/initScope.js +40 -0
  47. package/build/initScope.js.map +1 -0
  48. package/build/instructions/AddressResolver.d.ts +12 -12
  49. package/build/instructions/AddressResolver.js +30 -30
  50. package/build/instructions/ControlInstructions.d.ts +11 -11
  51. package/build/instructions/ControlInstructions.js +22 -22
  52. package/build/instructions/EndInstruction.d.ts +4 -4
  53. package/build/instructions/EndInstruction.js +10 -10
  54. package/build/instructions/InstructionBase.d.ts +10 -10
  55. package/build/instructions/InstructionBase.js +20 -20
  56. package/build/instructions/JumpInstruction.d.ts +15 -15
  57. package/build/instructions/JumpInstruction.js +21 -21
  58. package/build/instructions/OperationInstruction.d.ts +5 -5
  59. package/build/instructions/OperationInstruction.js +10 -10
  60. package/build/instructions/SetCounterInstruction.d.ts +5 -5
  61. package/build/instructions/SetCounterInstruction.js +10 -10
  62. package/build/instructions/SetInstruction.d.ts +5 -5
  63. package/build/instructions/SetInstruction.js +10 -10
  64. package/build/instructions/ZeroSpaceInstruction.d.ts +4 -4
  65. package/build/instructions/ZeroSpaceInstruction.js +10 -10
  66. package/build/instructions/index.d.ts +9 -9
  67. package/build/instructions/index.js +25 -25
  68. package/build/macros/Building.d.ts +11 -11
  69. package/build/macros/Building.js +80 -80
  70. package/build/macros/Function.d.ts +12 -12
  71. package/build/macros/Function.js +19 -19
  72. package/build/macros/Math.d.ts +5 -5
  73. package/build/macros/Math.js +56 -56
  74. package/build/macros/Math.js.map +1 -1
  75. package/build/macros/Memory.d.ts +5 -5
  76. package/build/macros/Memory.js +60 -60
  77. package/build/macros/Namespace.d.ts +21 -21
  78. package/build/macros/Namespace.js +97 -97
  79. package/build/macros/Other.d.ts +5 -5
  80. package/build/macros/Other.js +19 -19
  81. package/build/macros/RawValue.d.ts +5 -5
  82. package/build/macros/RawValue.js +15 -15
  83. package/build/macros/commands/{control.d.ts → Control.d.ts} +5 -5
  84. package/build/macros/commands/{control.js → Control.js} +24 -24
  85. package/build/macros/commands/{control.js.map → Control.js.map} +0 -0
  86. package/build/macros/commands/Draw.d.ts +5 -5
  87. package/build/macros/commands/Draw.js +38 -38
  88. package/build/macros/commands/DrawFlush.d.ts +5 -5
  89. package/build/macros/commands/DrawFlush.js +16 -16
  90. package/build/macros/commands/GetLink.d.ts +5 -5
  91. package/build/macros/commands/GetLink.js +20 -20
  92. package/build/macros/commands/Lookup.d.ts +5 -5
  93. package/build/macros/commands/Lookup.js +23 -23
  94. package/build/macros/commands/Print.d.ts +5 -5
  95. package/build/macros/commands/Print.js +13 -13
  96. package/build/macros/commands/PrintFlush.d.ts +5 -5
  97. package/build/macros/commands/PrintFlush.js +16 -16
  98. package/build/macros/commands/Radar.d.ts +7 -7
  99. package/build/macros/commands/Radar.js +60 -60
  100. package/build/macros/commands/Sensor.d.ts +5 -5
  101. package/build/macros/commands/Sensor.js +19 -19
  102. package/build/macros/commands/UnitBind.d.ts +5 -5
  103. package/build/macros/commands/UnitBind.js +16 -16
  104. package/build/macros/commands/UnitControl.d.ts +5 -5
  105. package/build/macros/commands/UnitControl.js +67 -67
  106. package/build/macros/commands/UnitLocate.d.ts +5 -5
  107. package/build/macros/commands/UnitLocate.js +54 -54
  108. package/build/macros/commands/UnitRadar.d.ts +5 -5
  109. package/build/macros/commands/UnitRadar.js +40 -40
  110. package/build/macros/commands/Wait.d.ts +5 -5
  111. package/build/macros/commands/Wait.js +17 -17
  112. package/build/macros/commands/index.d.ts +14 -14
  113. package/build/macros/commands/index.js +32 -32
  114. package/build/macros/index.d.ts +7 -7
  115. package/build/macros/index.js +39 -39
  116. package/build/operators.d.ts +25 -25
  117. package/build/operators.js +101 -101
  118. package/build/types.d.ts +49 -49
  119. package/build/types.js +27 -27
  120. package/build/utils.d.ts +3 -3
  121. package/build/utils.js +12 -12
  122. package/build/values/BaseValue.d.ts +5 -5
  123. package/build/values/BaseValue.js +111 -111
  124. package/build/values/FunctionValue.d.ts +34 -34
  125. package/build/values/FunctionValue.js +103 -103
  126. package/build/values/LiteralValue.d.ts +12 -12
  127. package/build/values/LiteralValue.js +87 -87
  128. package/build/values/LiteralValue.js.map +1 -1
  129. package/build/values/ObjectValue.d.ts +17 -17
  130. package/build/values/ObjectValue.js +49 -49
  131. package/build/values/StoreValue.d.ts +11 -11
  132. package/build/values/StoreValue.js +30 -30
  133. package/build/values/TempValue.d.ts +12 -12
  134. package/build/values/TempValue.js +66 -66
  135. package/build/values/TempValue.js.map +1 -1
  136. package/build/values/VoidValue.d.ts +11 -11
  137. package/build/values/VoidValue.js +30 -30
  138. package/build/values/index.d.ts +6 -6
  139. package/build/values/index.js +22 -22
  140. package/dist/mlogjs.es.js +6366 -0
  141. package/dist/mlogjs.umd.js +8 -0
  142. package/lib/commands.d.ts +326 -326
  143. package/lib/eslib/index.d.ts +3 -3
  144. package/lib/eslib/lib.d.ts +9 -9
  145. package/lib/eslib/lib.es2015.collection.d.ts +89 -89
  146. package/lib/eslib/lib.es2015.core.d.ts +16 -16
  147. package/lib/eslib/lib.es2015.d.ts +30 -30
  148. package/lib/eslib/lib.es2015.generator.d.ts +79 -79
  149. package/lib/eslib/lib.es2015.iterable.d.ts +70 -70
  150. package/lib/eslib/lib.es5.d.ts +295 -295
  151. package/lib/eslib/lib.es6.d.ts +18 -18
  152. package/lib/globals.d.ts +328 -328
  153. package/lib/helpers.d.ts +23 -23
  154. package/lib/index.d.ts +7 -7
  155. package/lib/kinds.d.ts +36 -36
  156. package/lib/memory.d.ts +17 -17
  157. package/lib/traits.d.ts +121 -121
  158. package/lib/util.d.ts +32 -32
  159. package/package.json +73 -48
  160. package/build/macros/Blocks.d.ts +0 -5
  161. package/build/macros/Blocks.js +0 -143
  162. package/build/macros/Blocks.js.map +0 -1
  163. package/build/macros/Draw.d.ts +0 -5
  164. package/build/macros/Draw.js +0 -39
  165. package/build/macros/Draw.js.map +0 -1
  166. package/build/macros/Items.d.ts +0 -5
  167. package/build/macros/Items.js +0 -20
  168. package/build/macros/Items.js.map +0 -1
  169. package/build/macros/Liquids.d.ts +0 -5
  170. package/build/macros/Liquids.js +0 -18
  171. package/build/macros/Liquids.js.map +0 -1
  172. package/build/macros/Symbol.d.ts +0 -0
  173. package/build/macros/Symbol.js +0 -1
  174. package/build/macros/Symbol.js.map +0 -1
  175. package/build/macros/SymbolNamespace.d.ts +0 -0
  176. package/build/macros/SymbolNamespace.js +0 -1
  177. package/build/macros/SymbolNamespace.js.map +0 -1
  178. package/build/macros/TypeFactory.d.ts +0 -8
  179. package/build/macros/TypeFactory.js +0 -22
  180. package/build/macros/TypeFactory.js.map +0 -1
  181. package/build/macros/Units.d.ts +0 -5
  182. package/build/macros/Units.js +0 -18
  183. package/build/macros/Units.js.map +0 -1
  184. package/build/macros/Vars.d.ts +0 -5
  185. package/build/macros/Vars.js +0 -18
  186. package/build/macros/Vars.js.map +0 -1
  187. package/build/macros/commands/Asm.d.ts +0 -5
  188. package/build/macros/commands/Asm.js +0 -21
  189. package/build/macros/commands/Asm.js.map +0 -1
  190. package/build/macros/commands/io.d.ts +0 -8
  191. package/build/macros/commands/io.js +0 -47
  192. package/build/macros/commands/io.js.map +0 -1
  193. package/build/macros/helpers/GetBuilding.d.ts +0 -5
  194. package/build/macros/helpers/GetBuilding.js +0 -16
  195. package/build/macros/helpers/GetBuilding.js.map +0 -1
  196. package/build/macros/helpers/GetVar.d.ts +0 -5
  197. package/build/macros/helpers/GetVar.js +0 -16
  198. package/build/macros/helpers/GetVar.js.map +0 -1
  199. package/build/macros/helpers/index.d.ts +0 -2
  200. package/build/macros/helpers/index.js +0 -15
  201. package/build/macros/helpers/index.js.map +0 -1
  202. package/dist/bundle.js +0 -1
package/build/bin.js CHANGED
@@ -1,42 +1,61 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const fs_1 = require("fs");
8
- const _1 = require(".");
9
- const yargs_1 = __importDefault(require("yargs"));
10
- const helpers_1 = require("yargs/helpers");
11
- (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
12
- .command("$0 [path] [out]", "compiles your Javascript file to MLog", yargs => {
13
- return yargs
14
- .positional("path", {
15
- describe: "path of the file to compile",
16
- })
17
- .positional("out", {
18
- describe: "path of the output file",
19
- });
20
- }, argv => {
21
- const path = argv.path;
22
- const out = argv.out;
23
- if (!path)
24
- return console.log("missing required path argument");
25
- if (!out)
26
- return console.log("missing output path");
27
- if (!(0, fs_1.existsSync)(path))
28
- return console.log(`file at ${path} does not exist`);
29
- try {
30
- const compiled = (0, _1.compile)((0, fs_1.readFileSync)(path, { encoding: "utf-8" }));
31
- (0, fs_1.writeFileSync)(out, compiled);
32
- console.log(`Success: Compiled ${path}. Your compiled code is at ${out}.`);
33
- }
34
- catch (e) {
35
- console.log("Error: " + e.message);
36
- }
37
- })
38
- .help()
39
- .scriptName("mlogjs")
40
- .demandCommand()
41
- .parse();
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = require("fs");
8
+ const helpers_1 = require("yargs/helpers");
9
+ const _1 = require(".");
10
+ const cli_highlight_1 = require("cli-highlight");
11
+ const yargs_1 = __importDefault(require("yargs"));
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const path_1 = require("path");
14
+ (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
15
+ .command("$0 [path] [out]", "compiles your Javascript file to MLog", yargs => {
16
+ return yargs
17
+ .positional("path", {
18
+ describe: "path of the file to compile",
19
+ })
20
+ .positional("out", {
21
+ describe: "path of the output file",
22
+ });
23
+ }, argv => {
24
+ const path = argv.path;
25
+ const out = argv.out;
26
+ if (!path)
27
+ return console.log("missing required path argument");
28
+ if (!out)
29
+ return console.log("missing output path");
30
+ if (!(0, fs_1.existsSync)(path))
31
+ return console.log(`file at ${path} does not exist`);
32
+ const code = (0, fs_1.readFileSync)(path, "utf8");
33
+ const [output, error, [node]] = (0, _1.compile)(code);
34
+ if (error) {
35
+ // @ts-ignore
36
+ let start = error?.loc;
37
+ let end = start;
38
+ if (node) {
39
+ start = node.loc.start;
40
+ end = node.loc.end;
41
+ }
42
+ const lines = code.split("\n");
43
+ console.log(chalk_1.default.cyanBright([(0, path_1.resolve)(path), start.line, start.column].join(":")));
44
+ for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
45
+ const n = i + 1;
46
+ const head = chalk_1.default.gray((n + " | ").padStart(6, " "));
47
+ console.log(head + (0, cli_highlight_1.highlight)(lines[i], { language: "js" }));
48
+ if (n === start.line) {
49
+ console.log(chalk_1.default.red(" ".repeat(6 + start.column) + "^ " + error.message));
50
+ }
51
+ }
52
+ return;
53
+ }
54
+ (0, fs_1.writeFileSync)(out, output);
55
+ console.log(`Success: Compiled ${path}. Your compiled code is at ${out}.`);
56
+ })
57
+ .help()
58
+ .scriptName("mlogjs")
59
+ .demandCommand()
60
+ .parse();
42
61
  //# sourceMappingURL=bin.js.map
package/build/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;;;;;AACA,2BAA6D;AAC7D,wBAA4B;AAC5B,kDAA0B;AAC1B,2CAAwC;AAExC,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzB,OAAO,CACN,iBAAiB,EACjB,uCAAuC,EACvC,KAAK,CAAC,EAAE;IACN,OAAO,KAAK;SACT,UAAU,CAAC,MAAM,EAAE;QAClB,QAAQ,EAAE,6BAA6B;KACxC,CAAC;SACD,UAAU,CAAC,KAAK,EAAE;QACjB,QA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IAAI,CAAC,GAAG,CAAC,CAAC,CACtE,CAAC;QACF,KACE,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,EACnC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACxC,CAAC,EAAE,EACH;YACA,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChB,MAAM,IAAI,GAAG,eAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,IAAA,yBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,EAAE;gBACpB,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAC/D,CAAC;aACH;SACF;QAED,OAAO;KACR;IACD,IAAA,kBAAa,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CACT,qBAAqB,IAAI,8BAA8B,GAAG,GAAG,CAC9D,CAAC;AACJ,CAAC,CACF;KACA,IAAI,EAAE;KACN,UAAU,CAAC,QAAQ,CAAC;KACpB,aAAa,EAAE;KACf,KAAK,EAAE,CAAC"}
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const BlockStatement: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const BlockStatement: THandler;
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlockStatement = void 0;
4
- const BlockStatement = (c, scope, node) => {
5
- const [value, insts] = c.handleMany(scope.createScope(), node.body);
6
- // const cleanInst = []
7
- // for (const inst of insts) {
8
- // if (inst instanceof BreakInstruction || inst instanceof ContinueInstruction || inst instanceof ReturnInstruction || inst instanceof SetCounterInstruction) break
9
- // cleanInst.push(inst)
10
- // }
11
- return [value, insts];
12
- };
13
- exports.BlockStatement = BlockStatement;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlockStatement = void 0;
4
+ const BlockStatement = (c, scope, node) => {
5
+ const [value, insts] = c.handleMany(scope.createScope(), node.body);
6
+ // const cleanInst = []
7
+ // for (const inst of insts) {
8
+ // if (inst instanceof BreakInstruction || inst instanceof ContinueInstruction || inst instanceof ReturnInstruction || inst instanceof SetCounterInstruction) break
9
+ // cleanInst.push(inst)
10
+ // }
11
+ return [value, insts];
12
+ };
13
+ exports.BlockStatement = BlockStatement;
14
14
  //# sourceMappingURL=BlockStatement.js.map
@@ -1,3 +1,3 @@
1
- import { THandler } from "../types";
2
- export declare const CallExpression: THandler;
3
- export declare const NewExpression: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const CallExpression: THandler;
3
+ export declare const NewExpression: THandler;
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NewExpression = exports.CallExpression = void 0;
4
- const CallExpression = (c, scope, node) => {
5
- const inst = [];
6
- const args = node.arguments.map(node => {
7
- // TODO: this might be why t0 did not increment
8
- const [v, i] = c.handleEval(scope, node);
9
- inst.push(...i);
10
- return v;
11
- });
12
- const [callee, calleeInst] = c.handleEval(scope, node.callee);
13
- inst.push(...calleeInst);
14
- const [callValue, callInst] = callee.call(scope, args);
15
- inst.push(...callInst);
16
- return [callValue, inst];
17
- };
18
- exports.CallExpression = CallExpression;
19
- exports.NewExpression = exports.CallExpression;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NewExpression = exports.CallExpression = void 0;
4
+ const CallExpression = (c, scope, node) => {
5
+ const inst = [];
6
+ const args = node.arguments.map(node => {
7
+ // TODO: this might be why t0 did not increment
8
+ const [v, i] = c.handleEval(scope, node);
9
+ inst.push(...i);
10
+ return v;
11
+ });
12
+ const [callee, calleeInst] = c.handleEval(scope, node.callee);
13
+ inst.push(...calleeInst);
14
+ const [callValue, callInst] = callee.call(scope, args);
15
+ inst.push(...callInst);
16
+ return [callValue, inst];
17
+ };
18
+ exports.CallExpression = CallExpression;
19
+ exports.NewExpression = exports.CallExpression;
20
20
  //# sourceMappingURL=CallExpression.js.map
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const ForStatement: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const ForStatement: THandler;
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForStatement = void 0;
4
- const instructions_1 = require("../instructions");
5
- const values_1 = require("../values");
6
- const ForStatement = (c, scope, node) => {
7
- scope = scope.createScope();
8
- const initInst = node.init ? c.handle(scope, node.init)[1] : [];
9
- const [test, testLines] = node.test
10
- ? c.handleEval(scope, node.test)
11
- : [new values_1.LiteralValue(scope, 1), []];
12
- const updateLines = node.update ? c.handle(scope, node.update)[1] : [];
13
- const startLoopAddr = new values_1.LiteralValue(scope, null);
14
- const endLoopAddr = new values_1.LiteralValue(scope, null);
15
- const startLoopLine = new instructions_1.AddressResolver(startLoopAddr).bindContinue(scope);
16
- const endLoopLine = new instructions_1.AddressResolver(endLoopAddr).bindBreak(scope);
17
- return [
18
- null,
19
- [
20
- ...initInst,
21
- startLoopLine,
22
- ...testLines,
23
- new instructions_1.JumpInstruction(endLoopAddr, instructions_1.EJumpKind.Equal, test, new values_1.LiteralValue(scope, 0)),
24
- ...c.handle(scope, node.body)[1],
25
- ...updateLines,
26
- new instructions_1.JumpInstruction(startLoopAddr, instructions_1.EJumpKind.Always),
27
- endLoopLine,
28
- ],
29
- ];
30
- };
31
- exports.ForStatement = ForStatement;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForStatement = void 0;
4
+ const instructions_1 = require("../instructions");
5
+ const values_1 = require("../values");
6
+ const ForStatement = (c, scope, node) => {
7
+ scope = scope.createScope();
8
+ const initInst = node.init ? c.handle(scope, node.init)[1] : [];
9
+ const [test, testLines] = node.test
10
+ ? c.handleEval(scope, node.test)
11
+ : [new values_1.LiteralValue(scope, 1), []];
12
+ const updateLines = node.update ? c.handle(scope, node.update)[1] : [];
13
+ const startLoopAddr = new values_1.LiteralValue(scope, null);
14
+ const endLoopAddr = new values_1.LiteralValue(scope, null);
15
+ const startLoopLine = new instructions_1.AddressResolver(startLoopAddr).bindContinue(scope);
16
+ const endLoopLine = new instructions_1.AddressResolver(endLoopAddr).bindBreak(scope);
17
+ return [
18
+ null,
19
+ [
20
+ ...initInst,
21
+ startLoopLine,
22
+ ...testLines,
23
+ new instructions_1.JumpInstruction(endLoopAddr, instructions_1.EJumpKind.Equal, test, new values_1.LiteralValue(scope, 0)),
24
+ ...c.handle(scope, node.body)[1],
25
+ ...updateLines,
26
+ new instructions_1.JumpInstruction(startLoopAddr, instructions_1.EJumpKind.Always),
27
+ endLoopLine,
28
+ ],
29
+ ];
30
+ };
31
+ exports.ForStatement = ForStatement;
32
32
  //# sourceMappingURL=ForStatement.js.map
@@ -1,4 +1,4 @@
1
- import { THandler } from "../types";
2
- export declare const ArrowFunctionExpression: THandler;
3
- export declare const FunctionDeclaration: THandler;
4
- export declare const FunctionExpression: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const ArrowFunctionExpression: THandler;
3
+ export declare const FunctionDeclaration: THandler;
4
+ export declare const FunctionExpression: THandler;
@@ -1,36 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = void 0;
4
- const utils_1 = require("../utils");
5
- const FunctionValue_1 = require("../values/FunctionValue");
6
- const ArrowFunctionExpression = (c, scope, node) => {
7
- const name = (0, utils_1.nodeName)(node);
8
- scope = scope.createFunction(name);
9
- let { params, body } = node;
10
- if (node.expression) {
11
- body = {
12
- type: "BlockStatement",
13
- body: [{ type: "ReturnStatement", argument: body }],
14
- };
15
- }
16
- const paramNames = [];
17
- const paramStores = [];
18
- for (const id of params) {
19
- paramNames.push(id.name);
20
- paramStores.push(scope.make(id.name, (0, utils_1.nodeName)(id)));
21
- }
22
- return [
23
- new FunctionValue_1.FunctionValue(scope, name, paramNames, paramStores, body, c),
24
- [],
25
- ];
26
- };
27
- exports.ArrowFunctionExpression = ArrowFunctionExpression;
28
- const FunctionDeclaration = (c, scope, node) => {
29
- return [
30
- scope.set(node.id.name, (0, exports.ArrowFunctionExpression)(c, scope, node, null)[0]),
31
- [],
32
- ];
33
- };
34
- exports.FunctionDeclaration = FunctionDeclaration;
35
- exports.FunctionExpression = exports.ArrowFunctionExpression;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = void 0;
4
+ const utils_1 = require("../utils");
5
+ const FunctionValue_1 = require("../values/FunctionValue");
6
+ const ArrowFunctionExpression = (c, scope, node) => {
7
+ const name = (0, utils_1.nodeName)(node);
8
+ scope = scope.createFunction(name);
9
+ let { params, body } = node;
10
+ if (node.expression) {
11
+ body = {
12
+ type: "BlockStatement",
13
+ body: [{ type: "ReturnStatement", argument: body }],
14
+ };
15
+ }
16
+ const paramNames = [];
17
+ const paramStores = [];
18
+ for (const id of params) {
19
+ paramNames.push(id.name);
20
+ paramStores.push(scope.make(id.name, (0, utils_1.nodeName)(id)));
21
+ }
22
+ return [
23
+ new FunctionValue_1.FunctionValue(scope, name, paramNames, paramStores, body, c),
24
+ [],
25
+ ];
26
+ };
27
+ exports.ArrowFunctionExpression = ArrowFunctionExpression;
28
+ const FunctionDeclaration = (c, scope, node) => {
29
+ return [
30
+ scope.set(node.id.name, (0, exports.ArrowFunctionExpression)(c, scope, node, null)[0]),
31
+ [],
32
+ ];
33
+ };
34
+ exports.FunctionDeclaration = FunctionDeclaration;
35
+ exports.FunctionExpression = exports.ArrowFunctionExpression;
36
36
  //# sourceMappingURL=Function.js.map
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const Identifier: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const Identifier: THandler;
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Identifier = void 0;
4
- const Identifier = (c, scope, node) => {
5
- return [scope.get(node.name), []];
6
- };
7
- exports.Identifier = Identifier;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Identifier = void 0;
4
+ const Identifier = (c, scope, node) => {
5
+ return [scope.get(node.name), []];
6
+ };
7
+ exports.Identifier = Identifier;
8
8
  //# sourceMappingURL=Identifier.js.map
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const IfStatement: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const IfStatement: THandler;
@@ -1,25 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IfStatement = void 0;
4
- const instructions_1 = require("../instructions");
5
- const instructions_2 = require("../instructions");
6
- const values_1 = require("../values");
7
- const IfStatement = (c, scope, node) => {
8
- const inst = [];
9
- const [test, testInst] = c.handleEval(scope, node.test);
10
- if (test instanceof values_1.LiteralValue) {
11
- if (test.data)
12
- inst.push(...c.handle(scope, node.consequent)[1]);
13
- else if (node.alternate)
14
- inst.push(...c.handle(scope, node.alternate)[1]);
15
- return [null, inst];
16
- }
17
- const endIfAddr = new values_1.LiteralValue(scope, null);
18
- inst.push(...testInst, new instructions_1.JumpInstruction(endIfAddr, instructions_2.EJumpKind.Equal, test, new values_1.LiteralValue(scope, 0)), ...c.handle(scope, node.consequent)[1], new instructions_1.AddressResolver(endIfAddr));
19
- const endElseAddr = new values_1.LiteralValue(scope, null);
20
- if (node.alternate)
21
- inst.push(new instructions_1.JumpInstruction(endElseAddr, instructions_2.EJumpKind.Always), new instructions_1.AddressResolver(endIfAddr), ...c.handle(scope, node.alternate)[1], new instructions_1.AddressResolver(endElseAddr));
22
- return [null, inst];
23
- };
24
- exports.IfStatement = IfStatement;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IfStatement = void 0;
4
+ const instructions_1 = require("../instructions");
5
+ const instructions_2 = require("../instructions");
6
+ const values_1 = require("../values");
7
+ const IfStatement = (c, scope, node) => {
8
+ const inst = [];
9
+ const [test, testInst] = c.handleEval(scope, node.test);
10
+ if (test instanceof values_1.LiteralValue) {
11
+ if (test.data)
12
+ inst.push(...c.handle(scope, node.consequent)[1]);
13
+ else if (node.alternate)
14
+ inst.push(...c.handle(scope, node.alternate)[1]);
15
+ return [null, inst];
16
+ }
17
+ const endIfAddr = new values_1.LiteralValue(scope, null);
18
+ inst.push(...testInst, new instructions_1.JumpInstruction(endIfAddr, instructions_2.EJumpKind.Equal, test, new values_1.LiteralValue(scope, 0)), ...c.handle(scope, node.consequent)[1], new instructions_1.AddressResolver(endIfAddr));
19
+ const endElseAddr = new values_1.LiteralValue(scope, null);
20
+ if (node.alternate)
21
+ inst.push(new instructions_1.JumpInstruction(endElseAddr, instructions_2.EJumpKind.Always), new instructions_1.AddressResolver(endIfAddr), ...c.handle(scope, node.alternate)[1], new instructions_1.AddressResolver(endElseAddr));
22
+ return [null, inst];
23
+ };
24
+ exports.IfStatement = IfStatement;
25
25
  //# sourceMappingURL=IfStatement.js.map
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const Literal: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const Literal: THandler;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Literal = void 0;
4
- const values_1 = require("../values");
5
- const Literal = (c, scope, node) => {
6
- const { value } = node;
7
- if (value === null ||
8
- typeof value === "string" ||
9
- typeof value === "number") {
10
- return [new values_1.LiteralValue(scope, value), []];
11
- }
12
- if (typeof value === "boolean") {
13
- return [new values_1.LiteralValue(scope, +value), []];
14
- }
15
- throw Error("Cannot create literal " + typeof value);
16
- };
17
- exports.Literal = Literal;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Literal = void 0;
4
+ const values_1 = require("../values");
5
+ const Literal = (c, scope, node) => {
6
+ const { value } = node;
7
+ if (value === null ||
8
+ typeof value === "string" ||
9
+ typeof value === "number") {
10
+ return [new values_1.LiteralValue(scope, value), []];
11
+ }
12
+ if (typeof value === "boolean") {
13
+ return [new values_1.LiteralValue(scope, +value), []];
14
+ }
15
+ throw Error("Cannot create literal " + typeof value);
16
+ };
17
+ exports.Literal = Literal;
18
18
  //# sourceMappingURL=Literal.js.map
@@ -1,4 +1,4 @@
1
- import { THandler } from "../types";
2
- export declare const ObjectExpression: THandler;
3
- export declare const ArrayExpression: THandler;
4
- export declare const MemberExpression: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const ObjectExpression: THandler;
3
+ export declare const ArrayExpression: THandler;
4
+ export declare const MemberExpression: THandler;
@@ -1,44 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemberExpression = exports.ArrayExpression = exports.ObjectExpression = void 0;
4
- const values_1 = require("../values");
5
- const ObjectExpression = (c, scope, node) => {
6
- const data = {};
7
- const inst = [];
8
- for (const prop of node.properties) {
9
- if (prop.computed)
10
- throw new Error("Cannot handle computed property.");
11
- const { key, value } = prop;
12
- let index;
13
- if (key.type === "Identifier")
14
- index = key.name;
15
- else if (key.type === "Literal")
16
- index = "" + key.value;
17
- const [member, memberInst] = c.handleEval(scope, value);
18
- data[index] = member;
19
- inst.push(...memberInst);
20
- }
21
- return [new values_1.ObjectValue(scope, data), inst];
22
- };
23
- exports.ObjectExpression = ObjectExpression;
24
- const ArrayExpression = (c, scope, node) => {
25
- const data = {};
26
- const inst = [];
27
- node.elements.forEach((element, i) => {
28
- const [value, valueInst] = c.handleEval(scope, element);
29
- data[i] = value;
30
- inst.push(...valueInst);
31
- });
32
- return [new values_1.ObjectValue(scope, data), inst];
33
- };
34
- exports.ArrayExpression = ArrayExpression;
35
- const MemberExpression = (c, scope, node) => {
36
- const [obj, objInst] = c.handleEval(scope, node.object);
37
- const [prop, propInst] = node.computed
38
- ? c.handleEval(scope, node.property)
39
- : [new values_1.LiteralValue(scope, node.property.name), []];
40
- const [got, gotInst] = obj.get(scope, prop);
41
- return [got, [...objInst, ...propInst, ...gotInst]];
42
- };
43
- exports.MemberExpression = MemberExpression;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemberExpression = exports.ArrayExpression = exports.ObjectExpression = void 0;
4
+ const values_1 = require("../values");
5
+ const ObjectExpression = (c, scope, node) => {
6
+ const data = {};
7
+ const inst = [];
8
+ for (const prop of node.properties) {
9
+ if (prop.computed)
10
+ throw new Error("Cannot handle computed property.");
11
+ const { key, value } = prop;
12
+ let index;
13
+ if (key.type === "Identifier")
14
+ index = key.name;
15
+ else if (key.type === "Literal")
16
+ index = "" + key.value;
17
+ const [member, memberInst] = c.handleEval(scope, value);
18
+ data[index] = member;
19
+ inst.push(...memberInst);
20
+ }
21
+ return [new values_1.ObjectValue(scope, data), inst];
22
+ };
23
+ exports.ObjectExpression = ObjectExpression;
24
+ const ArrayExpression = (c, scope, node) => {
25
+ const data = {};
26
+ const inst = [];
27
+ node.elements.forEach((element, i) => {
28
+ const [value, valueInst] = c.handleEval(scope, element);
29
+ data[i] = value;
30
+ inst.push(...valueInst);
31
+ });
32
+ return [new values_1.ObjectValue(scope, data), inst];
33
+ };
34
+ exports.ArrayExpression = ArrayExpression;
35
+ const MemberExpression = (c, scope, node) => {
36
+ const [obj, objInst] = c.handleEval(scope, node.object);
37
+ const [prop, propInst] = node.computed
38
+ ? c.handleEval(scope, node.property)
39
+ : [new values_1.LiteralValue(scope, node.property.name), []];
40
+ const [got, gotInst] = obj.get(scope, prop);
41
+ return [got, [...objInst, ...propInst, ...gotInst]];
42
+ };
43
+ exports.MemberExpression = MemberExpression;
44
44
  //# sourceMappingURL=Object.js.map
@@ -1,7 +1,7 @@
1
- import { THandler } from "../types";
2
- export declare const LRExpression: THandler;
3
- export declare const BinaryExpression: THandler;
4
- export declare const LogicalExpression: THandler;
5
- export declare const AssignmentExpression: THandler;
6
- export declare const UnaryExpression: THandler;
7
- export declare const UpdateExpression: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const LRExpression: THandler;
3
+ export declare const BinaryExpression: THandler;
4
+ export declare const LogicalExpression: THandler;
5
+ export declare const AssignmentExpression: THandler;
6
+ export declare const UnaryExpression: THandler;
7
+ export declare const UpdateExpression: THandler;