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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 STR1Z
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Wei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,18 +1,68 @@
1
- # MlogJS
2
-
3
- MlogJS is a compiler that allows users to compile complex JavaScript programs into Mindustry Logic Code.
4
-
5
- ## Discord
6
-
7
- You can join the Discord server for more information and help.
8
-
9
- https://discord.gg/SvgjCtZnR5
10
-
11
- ## Getting started!
12
-
13
- ```
14
- npm i mlogjs -g
15
- ```
16
-
17
- After installing the package from NPM, please visit the docs.
18
- https://weisrc.github.io/mlogjs/
1
+ <div markdown="1" align="center">
2
+
3
+ [![mlogjs](https://weisrc.github.io/mlogjs/logo.png)][docs]
4
+
5
+ # **JavaScript [MLog](https://mindustrygame.github.io/wiki/logic/0-introduction/) Compiler**
6
+
7
+ [![ci](https://github.com/weisrc/mlogjs/actions/workflows/ci.yml/badge.svg)][ci]
8
+ [![npm](https://img.shields.io/npm/v/mlogjs?color=cb3837&logo=npm)][npm]
9
+ [![docs](https://img.shields.io/badge/docs-mlogjs-41B883?logo=readthedocs)][docs]
10
+
11
+ </div>
12
+
13
+ ## Features
14
+
15
+ - Optimzing compiler
16
+ - Easy to use
17
+ - Fully Typed API
18
+ - Macros
19
+ - All Instructions and Variables
20
+
21
+ ## Installation
22
+
23
+ #### In the terminal
24
+
25
+ ```sh
26
+ npm i -g mlogjs
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ #### Creating `hello.js`
32
+
33
+ ```js
34
+ const message1 = getBuilding("message1")
35
+ print("Hello world")
36
+ printFlush(message1)
37
+ ```
38
+
39
+ #### Compile
40
+
41
+ ```sh
42
+ mlogjs hello.js hello.mlog
43
+ ```
44
+
45
+ ## Resources
46
+
47
+ - [Discord](https://discord.gg/SvgjCtZnR5)
48
+ - [Documentation][docs]
49
+ - [NPM package][npm]
50
+ - [GitHub Action CI][ci]
51
+
52
+ ## Maintainers
53
+
54
+ Massive thanks to [@JeanJPNM](https://github.com/JeanJPNM) for adding new features!
55
+
56
+ ## Contribute
57
+
58
+ Help and suggestions are welcomed!
59
+
60
+ ## License
61
+
62
+ MIT
63
+
64
+ <!-- url -->
65
+
66
+ [npm]: https://www.npmjs.com/package/mlogjs
67
+ [ci]: https://github.com/weisrc/mlogjs/actions/workflows/ci.yml
68
+ [docs]: https://weisrc.github.io/mlogjs
@@ -1,18 +1,18 @@
1
- import { es, IScope, THandler, TValueInstructions } from "./types";
2
- declare type THandlerMap = {
3
- [k in es.Node["type"]]?: THandler;
4
- };
5
- export declare class Compiler {
6
- protected stackName?: string;
7
- protected usingStack: boolean;
8
- protected handlers: THandlerMap;
9
- constructor(stackName?: string);
10
- compile(script: string): string;
11
- protected resolve(valueInst: TValueInstructions): void;
12
- protected serialize(resLines: TValueInstructions): string;
13
- protected parse(script: string): import("esprima").Program;
14
- handle(scope: IScope, node: es.Node): TValueInstructions;
15
- handleEval(scope: IScope, node: es.Node): TValueInstructions;
16
- handleMany(scope: IScope, nodes: es.Node[], handler?: typeof Compiler.prototype.handle): TValueInstructions;
17
- }
18
- export {};
1
+ import { es, IScope, THandler, TValueInstructions } from "./types";
2
+ declare type THandlerMap = {
3
+ [k in es.Node["type"]]?: THandler;
4
+ };
5
+ export declare class Compiler {
6
+ protected stackName?: string;
7
+ protected usingStack: boolean;
8
+ protected handlers: THandlerMap;
9
+ constructor(stackName?: string);
10
+ compile(script: string): [string, Error, es.Node[]];
11
+ protected resolve(valueInst: TValueInstructions): void;
12
+ protected serialize(resLines: TValueInstructions): string;
13
+ protected parse(script: string): es.Node;
14
+ handle(scope: IScope, node: es.Node): TValueInstructions;
15
+ handleEval(scope: IScope, node: es.Node): TValueInstructions;
16
+ handleMany(scope: IScope, nodes: es.Node[], handler?: typeof Compiler.prototype.handle): TValueInstructions;
17
+ }
18
+ export {};
package/build/Compiler.js CHANGED
@@ -1,120 +1,100 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Compiler = void 0;
27
- const handlers = __importStar(require("./handlers"));
28
- const esprima_1 = require("esprima");
29
- const instructions_1 = require("./instructions");
30
- const Scope_1 = require("./Scope");
31
- const macros_1 = require("./macros");
32
- const utils_1 = require("./utils");
33
- const Namespace_1 = require("./macros/Namespace");
34
- const RawValue_1 = require("./macros/RawValue");
35
- class Compiler {
36
- constructor(stackName) {
37
- this.handlers = handlers;
38
- this.usingStack = !!stackName;
39
- this.stackName = stackName;
40
- }
41
- compile(script) {
42
- const program = this.parse(script);
43
- const scope = new Scope_1.Scope({});
44
- // namespaces
45
- scope.hardSet("ControlKind", new Namespace_1.NamespaceMacro(scope));
46
- scope.hardSet("Vars", new Namespace_1.VarsNamespace(scope));
47
- scope.hardSet("Items", new Namespace_1.NamespaceMacro(scope, { changeCasing: true }));
48
- scope.hardSet("Liquids", new Namespace_1.NamespaceMacro(scope));
49
- scope.hardSet("Units", new Namespace_1.NamespaceMacro(scope));
50
- scope.hardSet("LAccess", new Namespace_1.NamespaceMacro(scope));
51
- scope.hardSet("UnitCommands", new Namespace_1.UCommandsNamespace(scope));
52
- scope.hardSet("Blocks", new Namespace_1.NamespaceMacro(scope, { changeCasing: true }));
53
- // helper methods
54
- scope.hardSet("getBuilding", new macros_1.BuildingBuilder(scope));
55
- scope.hardSet("getVar", new RawValue_1.RawValueMacro(scope));
56
- scope.hardSet("concat", new macros_1.Concat(scope));
57
- scope.hardSet("Math", new macros_1.MlogMath(scope));
58
- scope.hardSet("Memory", new macros_1.MemoryBuilder(scope));
59
- // commands
60
- scope.hardSet("draw", new macros_1.commands.Draw(scope));
61
- scope.hardSet("print", new macros_1.commands.Print(scope));
62
- scope.hardSet("printFlush", new macros_1.commands.PrintFlush(scope));
63
- scope.hardSet("drawFlush", new macros_1.commands.DrawFlush(scope));
64
- scope.hardSet("getLink", new macros_1.commands.GetLink(scope));
65
- scope.hardSet("control", new macros_1.commands.Control(scope));
66
- scope.hardSet("radar", new macros_1.commands.Radar(scope));
67
- scope.hardSet("sensor", new macros_1.commands.Sensor(scope));
68
- scope.hardSet("wait", new macros_1.commands.Wait(scope));
69
- scope.hardSet("lookup", new macros_1.commands.Lookup(scope));
70
- scope.hardSet("unitBind", new macros_1.commands.UnitBind(scope));
71
- scope.hardSet("unitControl", new macros_1.commands.UnitControl(scope));
72
- scope.hardSet("unitRadar", new macros_1.commands.UnitRadar(scope));
73
- scope.hardSet("unitLocate", new macros_1.commands.UnitLocate(scope));
74
- const valueInst = this.handle(scope, program);
75
- valueInst[1].push(new instructions_1.EndInstruction(), ...scope.inst);
76
- this.resolve(valueInst);
77
- return this.serialize(valueInst) + "\n";
78
- }
79
- resolve(valueInst) {
80
- let i = 0;
81
- for (const inst of valueInst[1]) {
82
- inst.resolve(i);
83
- if (!inst.hidden)
84
- i++;
85
- }
86
- }
87
- serialize(resLines) {
88
- const [_, inst] = resLines;
89
- return inst.filter(l => !l.hidden).join("\n");
90
- }
91
- parse(script) {
92
- return (0, esprima_1.parseScript)(script, { loc: true });
93
- }
94
- handle(scope, node) {
95
- try {
96
- const handler = this.handlers[node.type];
97
- if (!handler)
98
- throw Error("Missing handler for " + node.type);
99
- return handler(this, scope, node, null);
100
- }
101
- catch (error) {
102
- throw new Error(`${node.type} ${(0, utils_1.nodeName)(node)} > ${error.message}`);
103
- }
104
- }
105
- handleEval(scope, node) {
106
- const [res, inst] = this.handle(scope, node);
107
- const [evaluated, evaluatedLines] = res.eval(scope);
108
- return [evaluated, [...inst, ...evaluatedLines]];
109
- }
110
- handleMany(scope, nodes, handler = this.handle.bind(this)) {
111
- const lines = [];
112
- for (const node of nodes) {
113
- const [_, nodeLines] = handler(scope, node);
114
- lines.push(...nodeLines);
115
- }
116
- return [null, lines];
117
- }
118
- }
119
- exports.Compiler = Compiler;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Compiler = void 0;
27
+ const acorn_1 = require("acorn");
28
+ const handlers = __importStar(require("./handlers"));
29
+ const initScope_1 = require("./initScope");
30
+ const instructions_1 = require("./instructions");
31
+ const Scope_1 = require("./Scope");
32
+ class Compiler {
33
+ constructor(stackName) {
34
+ this.handlers = handlers;
35
+ this.usingStack = !!stackName;
36
+ this.stackName = stackName;
37
+ }
38
+ compile(script) {
39
+ let output;
40
+ try {
41
+ const program = this.parse(script);
42
+ const scope = new Scope_1.Scope({});
43
+ (0, initScope_1.initScope)(scope);
44
+ const valueInst = this.handle(scope, program);
45
+ valueInst[1].push(new instructions_1.EndInstruction(), ...scope.inst);
46
+ this.resolve(valueInst);
47
+ output = this.serialize(valueInst) + "\n";
48
+ }
49
+ catch (error) {
50
+ return [null, error, error?.nodeStack ?? []];
51
+ }
52
+ return [output, null, []];
53
+ }
54
+ resolve(valueInst) {
55
+ let i = 0;
56
+ for (const inst of valueInst[1]) {
57
+ inst.resolve(i);
58
+ if (!inst.hidden)
59
+ i++;
60
+ }
61
+ }
62
+ serialize(resLines) {
63
+ const [_, inst] = resLines;
64
+ return inst.filter(l => !l.hidden).join("\n");
65
+ }
66
+ parse(script) {
67
+ return (0, acorn_1.parse)(script, {
68
+ locations: true,
69
+ ecmaVersion: "latest",
70
+ });
71
+ }
72
+ handle(scope, node) {
73
+ try {
74
+ const handler = this.handlers[node.type];
75
+ if (!handler)
76
+ throw Error("Missing handler for " + node.type);
77
+ return handler(this, scope, node, null);
78
+ }
79
+ catch (error) {
80
+ error.nodeStack ??= [];
81
+ error.nodeStack.push(node);
82
+ throw error;
83
+ }
84
+ }
85
+ handleEval(scope, node) {
86
+ const [res, inst] = this.handle(scope, node);
87
+ const [evaluated, evaluatedLines] = res.eval(scope);
88
+ return [evaluated, [...inst, ...evaluatedLines]];
89
+ }
90
+ handleMany(scope, nodes, handler = this.handle.bind(this)) {
91
+ const lines = [];
92
+ for (const node of nodes) {
93
+ const [_, nodeLines] = handler(scope, node);
94
+ lines.push(...nodeLines);
95
+ }
96
+ return [null, lines];
97
+ }
98
+ }
99
+ exports.Compiler = Compiler;
120
100
  //# sourceMappingURL=Compiler.js.map
@@ -1 +1 @@
1
- {"version":3,"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AC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,IAAa;QACrC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC7C,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpD,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,UAAU,CACR,KAAa,EACb,KAAgB,EAChB,UAA4C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAElE,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;CACF;AA9ED,4BA8EC"}
package/build/Scope.d.ts CHANGED
@@ -1,26 +1,26 @@
1
- import { AddressResolver } from "./instructions";
2
- import { IFunctionValue, IInstruction, IScope, IValue } from "./types";
3
- export declare class Scope implements IScope {
4
- parent: IScope;
5
- name: string;
6
- data: {
7
- [k: string]: IValue;
8
- };
9
- stacked: boolean;
10
- ntemp: number;
11
- inst: IInstruction[];
12
- break: AddressResolver;
13
- continue: AddressResolver;
14
- function: IFunctionValue;
15
- constructor(values: {
16
- [k: string]: IValue;
17
- }, parent?: IScope, stacked?: boolean, ntemp?: number, name?: string, inst?: any[]);
18
- copy(): IScope;
19
- createScope(): IScope;
20
- createFunction(name: string, stacked?: boolean): IScope;
21
- has(name: string): boolean;
22
- get(name: string): IValue;
23
- set(name: string, value: IValue): IValue;
24
- hardSet(name: string, value: IValue): IValue;
25
- make(name: string, storeName: string): IValue;
26
- }
1
+ import { AddressResolver } from "./instructions";
2
+ import { IFunctionValue, IInstruction, IScope, IValue } from "./types";
3
+ export declare class Scope implements IScope {
4
+ parent: IScope;
5
+ name: string;
6
+ data: {
7
+ [k: string]: IValue;
8
+ };
9
+ stacked: boolean;
10
+ ntemp: number;
11
+ inst: IInstruction[];
12
+ break: AddressResolver;
13
+ continue: AddressResolver;
14
+ function: IFunctionValue;
15
+ constructor(values: {
16
+ [k: string]: IValue;
17
+ }, parent?: IScope, stacked?: boolean, ntemp?: number, name?: string, inst?: any[]);
18
+ copy(): IScope;
19
+ createScope(): IScope;
20
+ createFunction(name: string, stacked?: boolean): IScope;
21
+ has(name: string): boolean;
22
+ get(name: string): IValue;
23
+ set(name: string, value: IValue): IValue;
24
+ hardSet(name: string, value: IValue): IValue;
25
+ make(name: string, storeName: string): IValue;
26
+ }
package/build/Scope.js CHANGED
@@ -1,61 +1,61 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Scope = void 0;
4
- const values_1 = require("./values");
5
- class Scope {
6
- constructor(values, parent = null, stacked = false, ntemp = 0, name = "", inst = []) {
7
- this.stacked = false;
8
- this.ntemp = 0;
9
- this.data = values;
10
- this.parent = parent;
11
- this.stacked = stacked;
12
- this.ntemp = ntemp;
13
- this.name = name;
14
- this.inst = inst;
15
- }
16
- copy() {
17
- const scope = new Scope(Object.assign({}, this.data), this.parent, this.stacked, this.ntemp, this.name, this.inst);
18
- scope.break = this.break;
19
- scope.continue = this.continue;
20
- scope.function = this.function;
21
- return scope;
22
- }
23
- createScope() {
24
- const scope = this.copy();
25
- scope.data = {};
26
- scope.parent = this;
27
- return scope;
28
- }
29
- createFunction(name, stacked) {
30
- return new Scope({}, this, stacked !== null && stacked !== void 0 ? stacked : this.stacked, 0, name, this.inst);
31
- }
32
- has(name) {
33
- if (name in this.data)
34
- return true;
35
- if (this.parent)
36
- return this.parent.has(name);
37
- return false;
38
- }
39
- get(name) {
40
- const value = this.data[name];
41
- if (value)
42
- return value;
43
- if (this.parent)
44
- return this.parent.get(name);
45
- throw Error(`${name} is not declared.`);
46
- }
47
- set(name, value) {
48
- if (name in this.data)
49
- throw Error(`${name} is already declared.`);
50
- return this.hardSet(name, value);
51
- }
52
- hardSet(name, value) {
53
- this.data[name] = value;
54
- return value;
55
- }
56
- make(name, storeName) {
57
- return this.set(name, this.stacked ? null : new values_1.StoreValue(this, storeName));
58
- }
59
- }
60
- exports.Scope = Scope;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scope = void 0;
4
+ const values_1 = require("./values");
5
+ class Scope {
6
+ constructor(values, parent = null, stacked = false, ntemp = 0, name = "", inst = []) {
7
+ this.stacked = false;
8
+ this.ntemp = 0;
9
+ this.data = values;
10
+ this.parent = parent;
11
+ this.stacked = stacked;
12
+ this.ntemp = ntemp;
13
+ this.name = name;
14
+ this.inst = inst;
15
+ }
16
+ copy() {
17
+ const scope = new Scope({ ...this.data }, this.parent, this.stacked, this.ntemp, this.name, this.inst);
18
+ scope.break = this.break;
19
+ scope.continue = this.continue;
20
+ scope.function = this.function;
21
+ return scope;
22
+ }
23
+ createScope() {
24
+ const scope = this.copy();
25
+ scope.data = {};
26
+ scope.parent = this;
27
+ return scope;
28
+ }
29
+ createFunction(name, stacked) {
30
+ return new Scope({}, this, stacked ?? this.stacked, 0, name, this.inst);
31
+ }
32
+ has(name) {
33
+ if (name in this.data)
34
+ return true;
35
+ if (this.parent)
36
+ return this.parent.has(name);
37
+ return false;
38
+ }
39
+ get(name) {
40
+ const value = this.data[name];
41
+ if (value)
42
+ return value;
43
+ if (this.parent)
44
+ return this.parent.get(name);
45
+ throw Error(`${name} is not declared.`);
46
+ }
47
+ set(name, value) {
48
+ if (name in this.data)
49
+ throw Error(`${name} is already declared.`);
50
+ return this.hardSet(name, value);
51
+ }
52
+ hardSet(name, value) {
53
+ this.data[name] = value;
54
+ return value;
55
+ }
56
+ make(name, storeName) {
57
+ return this.set(name, this.stacked ? null : new values_1.StoreValue(this, storeName));
58
+ }
59
+ }
60
+ exports.Scope = Scope;
61
61
  //# sourceMappingURL=Scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Scope.js","sourceRoot":"","sources":["../src/Scope.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAItC,MAAa,KAAK;IAUhB,YACE,MAA+B,EAC/B,SAAiB,IAAI,EACrB,OAAO,GAAG,KAAK,EACf,KAAK,GAAG,CAAC,EACT,IAAI,GAAG,EAAE,EACT,IAAI,GAAG,EAAE;QAZX,YAAO,GAAY,KAAK,CAAC;QACzB,UAAK,GAAW,CAAC,CAAC;QAahB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,IAAI;QACF,MAAM,KAAK,GAAG,IAAI,KAAK,mBAChB,IAAI,CAAC,IAAI,GACd,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,CACV,CAAC;QACF,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,WAAW;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC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