mlogjs 0.3.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 (250) hide show
  1. package/dist/{types/Compiler.d.ts → Compiler.d.ts} +17 -4
  2. package/dist/CompilerError.d.ts +33 -0
  3. package/dist/{types/Scope.d.ts → Scope.d.ts} +0 -0
  4. package/dist/assertions.d.ts +28 -0
  5. package/dist/bin.cjs +7 -14
  6. package/dist/{types/bin.d.ts → bin.d.ts} +0 -0
  7. package/dist/{types/handlers → handlers}/BlockStatement.d.ts +0 -0
  8. package/dist/{types/handlers → handlers}/CallExpression.d.ts +1 -0
  9. package/dist/{types/handlers → handlers}/File.d.ts +0 -0
  10. package/dist/{types/handlers → handlers}/ForStatement.d.ts +0 -0
  11. package/dist/{types/handlers → handlers}/Function.d.ts +0 -0
  12. package/dist/{types/handlers → handlers}/Identifier.d.ts +0 -0
  13. package/dist/{types/handlers → handlers}/IfStatement.d.ts +0 -0
  14. package/dist/{types/handlers → handlers}/Literal.d.ts +0 -0
  15. package/dist/{types/handlers → handlers}/Object.d.ts +0 -0
  16. package/dist/{types/handlers → handlers}/OperationExpressions.d.ts +0 -0
  17. package/dist/{types/handlers → handlers}/Program.d.ts +0 -0
  18. package/dist/{types/handlers → handlers}/Statements.d.ts +0 -0
  19. package/dist/handlers/SwitchStatement.d.ts +2 -0
  20. package/dist/{types/handlers → handlers}/TemplateExpression.d.ts +0 -0
  21. package/dist/{types/handlers → handlers}/Typescript.d.ts +0 -0
  22. package/dist/{types/handlers → handlers}/VariableDeclaration.d.ts +0 -0
  23. package/dist/{types/handlers → handlers}/WhileStatement.d.ts +0 -0
  24. package/dist/{types/handlers → handlers}/index.d.ts +1 -0
  25. package/dist/index.cjs +1282 -514
  26. package/dist/{types/index.d.ts → index.d.ts} +1 -0
  27. package/dist/index.mjs +1282 -514
  28. package/dist/{types/initScope.d.ts → initScope.d.ts} +0 -0
  29. package/dist/{types/instructions → instructions}/AddressResolver.d.ts +0 -0
  30. package/dist/{types/instructions → instructions}/ControlInstructions.d.ts +3 -1
  31. package/dist/{types/instructions → instructions}/EndInstruction.d.ts +0 -0
  32. package/dist/{types/instructions → instructions}/InstructionBase.d.ts +5 -1
  33. package/dist/{types/instructions → instructions}/JumpInstruction.d.ts +1 -0
  34. package/dist/{types/instructions → instructions}/OperationInstruction.d.ts +0 -0
  35. package/dist/{types/instructions → instructions}/SetCounterInstruction.d.ts +0 -0
  36. package/dist/{types/instructions → instructions}/SetInstruction.d.ts +0 -0
  37. package/dist/{types/instructions → instructions}/ZeroSpaceInstruction.d.ts +0 -0
  38. package/dist/{types/instructions → instructions}/index.d.ts +0 -0
  39. package/dist/macros/Asm.d.ts +4 -0
  40. package/dist/{types/macros → macros}/Function.d.ts +2 -2
  41. package/dist/macros/GetGlobal.d.ts +5 -0
  42. package/dist/{types/macros → macros}/Math.d.ts +1 -2
  43. package/dist/{types/macros → macros}/Memory.d.ts +1 -2
  44. package/dist/{types/macros → macros}/Namespace.d.ts +1 -4
  45. package/dist/{types/macros → macros}/Other.d.ts +1 -2
  46. package/dist/macros/commands/ApplyStatus.d.ts +4 -0
  47. package/dist/macros/commands/Control.d.ts +4 -0
  48. package/dist/macros/commands/Cutscene.d.ts +4 -0
  49. package/dist/macros/commands/Draw.d.ts +4 -0
  50. package/dist/{types/macros → macros}/commands/DrawFlush.d.ts +1 -2
  51. package/dist/{types/macros → macros}/commands/End.d.ts +1 -2
  52. package/dist/macros/commands/Explosion.d.ts +4 -0
  53. package/dist/macros/commands/Fetch.d.ts +4 -0
  54. package/dist/macros/commands/FlushMessage.d.ts +4 -0
  55. package/dist/macros/commands/GetBlock.d.ts +4 -0
  56. package/dist/macros/commands/GetFlag.d.ts +4 -0
  57. package/dist/{types/macros → macros}/commands/GetLink.d.ts +1 -2
  58. package/dist/macros/commands/Lookup.d.ts +4 -0
  59. package/dist/macros/commands/PackColor.d.ts +4 -0
  60. package/dist/{types/macros → macros}/commands/Print.d.ts +1 -2
  61. package/dist/{types/macros → macros}/commands/PrintFlush.d.ts +1 -2
  62. package/dist/macros/commands/Radar.d.ts +6 -0
  63. package/dist/{types/macros → macros}/commands/Sensor.d.ts +1 -2
  64. package/dist/macros/commands/SetBlock.d.ts +4 -0
  65. package/dist/macros/commands/SetFlag.d.ts +4 -0
  66. package/dist/macros/commands/SetRate.d.ts +4 -0
  67. package/dist/macros/commands/SetRule.d.ts +4 -0
  68. package/dist/macros/commands/SpawnUnit.d.ts +4 -0
  69. package/dist/macros/commands/SpawnWave.d.ts +4 -0
  70. package/dist/macros/commands/Stop.d.ts +4 -0
  71. package/dist/{types/macros → macros}/commands/UnitBind.d.ts +1 -2
  72. package/dist/macros/commands/UnitControl.d.ts +4 -0
  73. package/dist/macros/commands/UnitLocate.d.ts +4 -0
  74. package/dist/{types/macros → macros}/commands/UnitRadar.d.ts +1 -2
  75. package/dist/{types/macros → macros}/commands/Wait.d.ts +1 -2
  76. package/dist/macros/commands/index.d.ts +30 -0
  77. package/dist/{types/macros → macros}/index.d.ts +0 -0
  78. package/dist/macros/util.d.ts +17 -0
  79. package/dist/{types/operators.d.ts → operators.d.ts} +0 -0
  80. package/dist/{types/types.d.ts → types.d.ts} +14 -1
  81. package/dist/utils.d.ts +47 -0
  82. package/dist/{types/values → values}/BaseValue.d.ts +3 -2
  83. package/dist/{types/values → values}/DestructuringValue.d.ts +1 -1
  84. package/dist/{types/values → values}/FunctionValue.d.ts +4 -5
  85. package/dist/{types/values → values}/LiteralValue.d.ts +3 -2
  86. package/dist/{types/values → values}/ObjectValue.d.ts +3 -3
  87. package/dist/{types/values → values}/SenseableValue.d.ts +0 -0
  88. package/dist/{types/values → values}/StoreValue.d.ts +4 -2
  89. package/dist/{types/values → values}/ValueOwner.d.ts +0 -0
  90. package/dist/{types/values → values}/VoidValue.d.ts +0 -2
  91. package/dist/{types/values → values}/index.d.ts +0 -0
  92. package/lib/commands.d.ts +847 -420
  93. package/lib/eslib/lib.es2015.core.d.ts +3 -0
  94. package/lib/globals.d.ts +331 -19
  95. package/lib/helpers.d.ts +14 -0
  96. package/lib/kinds.d.ts +3 -2
  97. package/lib/memory.d.ts +1 -1
  98. package/lib/traits.d.ts +6 -0
  99. package/lib/util.d.ts +16 -0
  100. package/package.json +16 -17
  101. package/build/Compiler.js +0 -105
  102. package/build/Compiler.js.map +0 -1
  103. package/build/CompilerError.js +0 -11
  104. package/build/CompilerError.js.map +0 -1
  105. package/build/Scope.js +0 -71
  106. package/build/Scope.js.map +0 -1
  107. package/build/bin.js +0 -75
  108. package/build/bin.js.map +0 -1
  109. package/build/handlers/BlockStatement.js +0 -14
  110. package/build/handlers/BlockStatement.js.map +0 -1
  111. package/build/handlers/CallExpression.js +0 -20
  112. package/build/handlers/CallExpression.js.map +0 -1
  113. package/build/handlers/File.js +0 -9
  114. package/build/handlers/File.js.map +0 -1
  115. package/build/handlers/ForStatement.js +0 -32
  116. package/build/handlers/ForStatement.js.map +0 -1
  117. package/build/handlers/Function.js +0 -47
  118. package/build/handlers/Function.js.map +0 -1
  119. package/build/handlers/Identifier.js +0 -8
  120. package/build/handlers/Identifier.js.map +0 -1
  121. package/build/handlers/IfStatement.js +0 -25
  122. package/build/handlers/IfStatement.js.map +0 -1
  123. package/build/handlers/Literal.js +0 -15
  124. package/build/handlers/Literal.js.map +0 -1
  125. package/build/handlers/Object.js +0 -55
  126. package/build/handlers/Object.js.map +0 -1
  127. package/build/handlers/OperationExpressions.js +0 -38
  128. package/build/handlers/OperationExpressions.js.map +0 -1
  129. package/build/handlers/Program.js +0 -9
  130. package/build/handlers/Program.js.map +0 -1
  131. package/build/handlers/Statements.js +0 -30
  132. package/build/handlers/Statements.js.map +0 -1
  133. package/build/handlers/TemplateExpression.js +0 -18
  134. package/build/handlers/TemplateExpression.js.map +0 -1
  135. package/build/handlers/VariableDeclaration.js +0 -72
  136. package/build/handlers/VariableDeclaration.js.map +0 -1
  137. package/build/handlers/WhileStatement.js +0 -23
  138. package/build/handlers/WhileStatement.js.map +0 -1
  139. package/build/handlers/index.js +0 -32
  140. package/build/handlers/index.js.map +0 -1
  141. package/build/index.js +0 -8
  142. package/build/index.js.map +0 -1
  143. package/build/initScope.js +0 -40
  144. package/build/initScope.js.map +0 -1
  145. package/build/instructions/AddressResolver.js +0 -31
  146. package/build/instructions/AddressResolver.js.map +0 -1
  147. package/build/instructions/ControlInstructions.js +0 -23
  148. package/build/instructions/ControlInstructions.js.map +0 -1
  149. package/build/instructions/EndInstruction.js +0 -11
  150. package/build/instructions/EndInstruction.js.map +0 -1
  151. package/build/instructions/InstructionBase.js +0 -21
  152. package/build/instructions/InstructionBase.js.map +0 -1
  153. package/build/instructions/JumpInstruction.js +0 -22
  154. package/build/instructions/JumpInstruction.js.map +0 -1
  155. package/build/instructions/OperationInstruction.js +0 -11
  156. package/build/instructions/OperationInstruction.js.map +0 -1
  157. package/build/instructions/SetCounterInstruction.js +0 -11
  158. package/build/instructions/SetCounterInstruction.js.map +0 -1
  159. package/build/instructions/SetInstruction.js +0 -11
  160. package/build/instructions/SetInstruction.js.map +0 -1
  161. package/build/instructions/ZeroSpaceInstruction.js +0 -11
  162. package/build/instructions/ZeroSpaceInstruction.js.map +0 -1
  163. package/build/instructions/index.js +0 -26
  164. package/build/instructions/index.js.map +0 -1
  165. package/build/macros/Building.js +0 -89
  166. package/build/macros/Building.js.map +0 -1
  167. package/build/macros/Function.js +0 -20
  168. package/build/macros/Function.js.map +0 -1
  169. package/build/macros/Math.js +0 -62
  170. package/build/macros/Math.js.map +0 -1
  171. package/build/macros/Memory.js +0 -63
  172. package/build/macros/Memory.js.map +0 -1
  173. package/build/macros/Namespace.js +0 -111
  174. package/build/macros/Namespace.js.map +0 -1
  175. package/build/macros/Other.js +0 -21
  176. package/build/macros/Other.js.map +0 -1
  177. package/build/macros/RawValue.js +0 -17
  178. package/build/macros/RawValue.js.map +0 -1
  179. package/build/macros/commands/Control.js +0 -26
  180. package/build/macros/commands/Control.js.map +0 -1
  181. package/build/macros/commands/Draw.js +0 -40
  182. package/build/macros/commands/Draw.js.map +0 -1
  183. package/build/macros/commands/DrawFlush.js +0 -18
  184. package/build/macros/commands/DrawFlush.js.map +0 -1
  185. package/build/macros/commands/GetLink.js +0 -25
  186. package/build/macros/commands/GetLink.js.map +0 -1
  187. package/build/macros/commands/Lookup.js +0 -25
  188. package/build/macros/commands/Lookup.js.map +0 -1
  189. package/build/macros/commands/Print.js +0 -18
  190. package/build/macros/commands/Print.js.map +0 -1
  191. package/build/macros/commands/PrintFlush.js +0 -18
  192. package/build/macros/commands/PrintFlush.js.map +0 -1
  193. package/build/macros/commands/Radar.js +0 -65
  194. package/build/macros/commands/Radar.js.map +0 -1
  195. package/build/macros/commands/Sensor.js +0 -21
  196. package/build/macros/commands/Sensor.js.map +0 -1
  197. package/build/macros/commands/UnitBind.js +0 -18
  198. package/build/macros/commands/UnitBind.js.map +0 -1
  199. package/build/macros/commands/UnitControl.js +0 -73
  200. package/build/macros/commands/UnitControl.js.map +0 -1
  201. package/build/macros/commands/UnitLocate.js +0 -76
  202. package/build/macros/commands/UnitLocate.js.map +0 -1
  203. package/build/macros/commands/UnitRadar.js +0 -48
  204. package/build/macros/commands/UnitRadar.js.map +0 -1
  205. package/build/macros/commands/Wait.js +0 -19
  206. package/build/macros/commands/Wait.js.map +0 -1
  207. package/build/macros/commands/index.js +0 -33
  208. package/build/macros/commands/index.js.map +0 -1
  209. package/build/macros/index.js +0 -40
  210. package/build/macros/index.js.map +0 -1
  211. package/build/operators.js +0 -102
  212. package/build/operators.js.map +0 -1
  213. package/build/types.js +0 -28
  214. package/build/types.js.map +0 -1
  215. package/build/utils.js +0 -18
  216. package/build/utils.js.map +0 -1
  217. package/build/values/BaseValue.js +0 -112
  218. package/build/values/BaseValue.js.map +0 -1
  219. package/build/values/FunctionValue.js +0 -116
  220. package/build/values/FunctionValue.js.map +0 -1
  221. package/build/values/LiteralValue.js +0 -89
  222. package/build/values/LiteralValue.js.map +0 -1
  223. package/build/values/ObjectValue.js +0 -55
  224. package/build/values/ObjectValue.js.map +0 -1
  225. package/build/values/StoreValue.js +0 -32
  226. package/build/values/StoreValue.js.map +0 -1
  227. package/build/values/TempValue.js +0 -78
  228. package/build/values/TempValue.js.map +0 -1
  229. package/build/values/VoidValue.js +0 -32
  230. package/build/values/VoidValue.js.map +0 -1
  231. package/build/values/index.js +0 -23
  232. package/build/values/index.js.map +0 -1
  233. package/dist/bin.cjs.map +0 -1
  234. package/dist/index.cjs.map +0 -1
  235. package/dist/index.mjs.map +0 -1
  236. package/dist/types/CompilerError.d.ts +0 -9
  237. package/dist/types/macros/Building.d.ts +0 -10
  238. package/dist/types/macros/Entities.d.ts +0 -11
  239. package/dist/types/macros/GetGlobal.d.ts +0 -5
  240. package/dist/types/macros/RawValue.d.ts +0 -5
  241. package/dist/types/macros/commands/Control.d.ts +0 -5
  242. package/dist/types/macros/commands/Draw.d.ts +0 -5
  243. package/dist/types/macros/commands/Lookup.d.ts +0 -5
  244. package/dist/types/macros/commands/Radar.d.ts +0 -7
  245. package/dist/types/macros/commands/UnitControl.d.ts +0 -5
  246. package/dist/types/macros/commands/UnitLocate.d.ts +0 -5
  247. package/dist/types/macros/commands/index.d.ts +0 -15
  248. package/dist/types/utils.d.ts +0 -30
  249. package/dist/types/values/StackValue.d.ts +0 -16
  250. package/dist/types/values/TempValue.d.ts +0 -19
@@ -7,20 +7,33 @@ export interface CompilerOptions {
7
7
  stackName?: string;
8
8
  /** Wether the compiler should preserve or compact variable and function names*/
9
9
  compactNames?: boolean;
10
+ sourcemap?: boolean;
10
11
  }
11
12
  export declare class Compiler {
12
13
  protected stackName?: string;
13
14
  protected usingStack: boolean;
14
15
  protected handlers: THandlerMap;
15
16
  readonly compactNames: boolean;
16
- constructor({ stackName, compactNames }?: CompilerOptions);
17
- compile(script: string): [string, null, es.Node[]] | [null, Error | CompilerError, es.Node[]];
17
+ readonly sourcemap: boolean;
18
+ constructor({ stackName, compactNames, sourcemap, }?: CompilerOptions);
19
+ compile(script: string): [string, null, es.SourceLocation[] | undefined] | [null, CompilerError];
18
20
  protected resolve(valueInst: TValueInstructions<IValue | null>): void;
19
21
  protected serialize(resLines: TValueInstructions<IValue | null>): string;
20
22
  protected parse(script: string): import("@babel/parser").ParseResult<es.File>;
21
- handle(scope: IScope, node: es.Node): TValueInstructions<IValue | null>;
23
+ protected mapSources(valueInst: TValueInstructions<IValue | null>): es.SourceLocation[];
24
+ handle(scope: IScope, node: es.Node, handler?: THandler<IValue | null> | undefined): TValueInstructions<IValue | null>;
22
25
  handleEval(scope: IScope, node: es.Node): TValueInstructions;
23
26
  handleConsume(scope: IScope, node: es.Node): TValueInstructions;
24
- handleMany<T extends es.Node>(scope: IScope, nodes: T[], handler?: (scope: IScope, node: T) => TValueInstructions<IValue | null>): TValueInstructions<null>;
27
+ /**
28
+ * Handles many nodes in order.
29
+ *
30
+ * The usage of this method over a regular loop over an array of nodes
31
+ * is only required if the code inside the loop generates
32
+ * instructions that are not tracked by the compiler
33
+ * handler methods ({@link handle}, {@link handleEval}, {@link handleConsume}
34
+ * and {@link handleMany})
35
+ *
36
+ */
37
+ handleMany<T extends es.Node>(scope: IScope, nodes: T[], handler?: (node: T) => TValueInstructions<IValue | null>): TValueInstructions<null>;
25
38
  }
26
39
  export {};
@@ -0,0 +1,33 @@
1
+ import { es } from "./types";
2
+ /**
3
+ * Error thrown by the babel parser.
4
+ *
5
+ * It doesn't export the type so we are writing it ourselves
6
+ */
7
+ export interface ParsingError extends Error {
8
+ code: string;
9
+ reasonCode: string;
10
+ loc: {
11
+ line: number;
12
+ column: number;
13
+ };
14
+ }
15
+ declare type CompilerErrorSource = es.Node | es.SourceLocation | {
16
+ line: number;
17
+ column: number;
18
+ };
19
+ export declare class CompilerError extends Error {
20
+ protected _loc?: es.SourceLocation;
21
+ /**
22
+ * The error that preceded this `CompilerError`.
23
+ *
24
+ * If it's not `undefined` it means that `this` is just wrapping the error to
25
+ * append extra data like the node stack
26
+ * */
27
+ inner?: unknown;
28
+ constructor(message: string, source?: CompilerErrorSource);
29
+ get loc(): es.SourceLocation | undefined;
30
+ set loc(value: CompilerErrorSource | undefined);
31
+ static from(error: unknown, source?: CompilerErrorSource): CompilerError;
32
+ }
33
+ export {};
File without changes
@@ -0,0 +1,28 @@
1
+ import { IValue } from "./types";
2
+ import { LiteralValue, ObjectValue, StoreValue } from "./values";
3
+ /** Asserts that `value` is a `LiteralValue` that contains a string */
4
+ export declare function assertStringLiteral(value: IValue | undefined, name: string): asserts value is LiteralValue & {
5
+ data: string;
6
+ };
7
+ /** Asserts that `value` is a string literal that is part of a given set of `members`*/
8
+ export declare function assertLiteralOneOf<T extends readonly string[]>(value: IValue | undefined, members: T, name: string): asserts value is LiteralValue & {
9
+ data: T[number];
10
+ };
11
+ /** Asserts that `value` is either a store or a literal */
12
+ export declare function assertIsRuntimeValue(value: IValue | undefined, name: string): asserts value is LiteralValue | StoreValue;
13
+ /** Asserts that `value` is an `ObjectValue` */
14
+ export declare function assertIsObjectMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
15
+ /** Asserts that `value` is an `ObjectValue` that has a length property */
16
+ export declare function assertIsArrayMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
17
+ /** Helper type used to describe the overloads of a macro function. See {@link assertObjectFields} */
18
+ export declare type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
19
+ /** Describes an object destructuring paremeter. Generally used with `assertObjectFields` */
20
+ export interface IParameterDescriptor {
21
+ key: string;
22
+ name?: string;
23
+ default?: string;
24
+ /** Throw an error on invalid values */
25
+ validate?(value: IValue): void;
26
+ }
27
+ /** Asserts that all of the fields described are present on `value`*/
28
+ export declare function assertObjectFields(value: ObjectValue, fields: (string | IParameterDescriptor)[]): (IValue | string)[];
package/dist/bin.cjs CHANGED
@@ -43,29 +43,22 @@ yargs__default["default"](helpers.hideBin(process.argv))
43
43
  compactNames: argv["compact-names"],
44
44
  });
45
45
  const code = fs.readFileSync(path$1, "utf8");
46
- const [output, error, [node]] = compiler.compile(code);
46
+ const [output, error] = compiler.compile(code);
47
47
  if (error) {
48
- if (!(error instanceof index_cjs.CompilerError)) {
49
- console.error(error);
48
+ if (!error.loc) {
49
+ console.log(error.inner ?? error);
50
50
  return;
51
51
  }
52
- let start = error.loc;
53
- let end = start;
54
- if (node) {
55
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
56
- start = node.loc.start;
57
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58
- end = node.loc.end;
59
- }
52
+ const { start, end } = error.loc;
60
53
  const lines = code.split("\n");
61
54
  console.log(chalk__default["default"].cyanBright([path.resolve(path$1), start.line, start.column].join(":")));
62
55
  for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
63
56
  const n = i + 1;
57
+ if (n !== start.line)
58
+ continue;
64
59
  const head = chalk__default["default"].gray(`${n} | `.padStart(6, " "));
65
60
  console.log(head + cliHighlight.highlight(lines[i], { language: "js" }));
66
- if (n === start.line) {
67
- console.log(chalk__default["default"].red(" ".repeat(6 + start.column) + "^ " + error.message));
68
- }
61
+ console.log(chalk__default["default"].red(" ".repeat(6 + start.column) + "^ " + error.message));
69
62
  }
70
63
  return;
71
64
  }
File without changes
@@ -1,3 +1,4 @@
1
1
  import { IValue, THandler } from "../types";
2
2
  export declare const CallExpression: THandler<IValue | null>;
3
3
  export declare const NewExpression: THandler<IValue | null>;
4
+ export declare const TaggedTemplateExpression: THandler<IValue | null>;
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const SwitchStatement: THandler<null>;
@@ -5,6 +5,7 @@ export * from "./OperationExpressions";
5
5
  export * from "./Identifier";
6
6
  export * from "./Statements";
7
7
  export * from "./IfStatement";
8
+ export * from "./SwitchStatement";
8
9
  export * from "./WhileStatement";
9
10
  export * from "./ForStatement";
10
11
  export * from "./Function";