mlogjs 0.5.2 → 0.6.0

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 (79) hide show
  1. package/README.md +2 -2
  2. package/dist/{index.cjs → Compiler-7GMG4MDr.js} +1746 -452
  3. package/dist/Compiler.d.ts +8 -12
  4. package/dist/CompilerError.d.ts +13 -3
  5. package/dist/Scope.d.ts +8 -8
  6. package/dist/bin/files.d.ts +18 -0
  7. package/dist/bin.mjs +170 -0
  8. package/dist/handlers/Import.d.ts +5 -0
  9. package/dist/handlers/Literal.d.ts +2 -2
  10. package/dist/handlers/Typescript.d.ts +2 -2
  11. package/dist/handlers/index.d.ts +1 -0
  12. package/dist/index.mjs +3 -4267
  13. package/dist/instructions/AddressResolver.d.ts +4 -4
  14. package/dist/instructions/ControlInstructions.d.ts +3 -3
  15. package/dist/instructions/InstructionBase.d.ts +1 -0
  16. package/dist/instructions/JumpInstruction.d.ts +5 -5
  17. package/dist/instructions/index.d.ts +0 -1
  18. package/dist/macros/DynamicArray.d.ts +4 -4
  19. package/dist/macros/Function.d.ts +2 -2
  20. package/dist/macros/GetBuildings.d.ts +4 -0
  21. package/dist/macros/GetColor.d.ts +4 -0
  22. package/dist/macros/Marker.d.ts +4 -0
  23. package/dist/macros/Namespace.d.ts +16 -0
  24. package/dist/macros/Queries.d.ts +10 -0
  25. package/dist/macros/StringView.d.ts +4 -0
  26. package/dist/macros/commands/Effect.d.ts +4 -0
  27. package/dist/macros/commands/Format.d.ts +4 -0
  28. package/dist/macros/commands/LocalePrint.d.ts +4 -0
  29. package/dist/macros/commands/PlayMusic.d.ts +4 -0
  30. package/dist/macros/commands/PlaySound.d.ts +4 -0
  31. package/dist/macros/commands/PrintChar.d.ts +4 -0
  32. package/dist/macros/commands/Query.d.ts +4 -0
  33. package/dist/macros/commands/SetProp.d.ts +4 -0
  34. package/dist/macros/commands/SpawnBullet.d.ts +4 -0
  35. package/dist/macros/commands/Sync.d.ts +6 -0
  36. package/dist/macros/commands/UnpackColor.d.ts +4 -0
  37. package/dist/macros/commands/WeatherSense.d.ts +4 -0
  38. package/dist/macros/commands/WeatherSet.d.ts +4 -0
  39. package/dist/macros/commands/index.d.ts +13 -0
  40. package/dist/macros/index.d.ts +7 -1
  41. package/dist/macros/util.d.ts +5 -2
  42. package/dist/modules.d.ts +8 -0
  43. package/dist/operators.d.ts +1 -1
  44. package/dist/types.d.ts +84 -59
  45. package/dist/utils/constants.d.ts +9 -4
  46. package/dist/utils/general.d.ts +8 -9
  47. package/dist/utils/instruction.d.ts +5 -1
  48. package/dist/utils/value.d.ts +14 -5
  49. package/dist/values/AssignmentValue.d.ts +1 -1
  50. package/dist/values/BaseValue.d.ts +4 -2
  51. package/dist/values/DestructuringValue.d.ts +5 -7
  52. package/dist/values/FunctionValue.d.ts +8 -6
  53. package/dist/values/JumpOutValue.d.ts +4 -4
  54. package/dist/values/LazyValue.d.ts +3 -3
  55. package/dist/values/LiteralValue.d.ts +2 -3
  56. package/dist/values/ObjectValue.d.ts +6 -11
  57. package/dist/values/StoreValue.d.ts +10 -5
  58. package/dist/values/VoidValue.d.ts +2 -1
  59. package/dist/values/index.d.ts +0 -1
  60. package/lib/commands.d.ts +776 -730
  61. package/lib/eslib/lib.es2015.collection.d.ts +50 -39
  62. package/lib/eslib/lib.es2015.core.d.ts +59 -0
  63. package/lib/eslib/lib.es2015.d.ts +0 -3
  64. package/lib/eslib/lib.es2015.generator.d.ts +54 -53
  65. package/lib/eslib/lib.es2015.iterable.d.ts +9 -6
  66. package/lib/eslib/lib.es5.d.ts +53 -6
  67. package/lib/globals.d.ts +309 -18
  68. package/lib/helpers.d.ts +86 -52
  69. package/lib/kinds.d.ts +42 -7
  70. package/lib/macros.d.ts +53 -18
  71. package/lib/traits.d.ts +308 -146
  72. package/lib/util.d.ts +144 -48
  73. package/lib/world.d.ts +1197 -0
  74. package/package.json +27 -35
  75. package/dist/bin.cjs +0 -111
  76. package/dist/initScope.d.ts +0 -5
  77. package/dist/instructions/ZeroSpaceInstruction.d.ts +0 -4
  78. package/dist/values/SenseableValue.d.ts +0 -24
  79. /package/dist/{bin.d.ts → bin/index.d.ts} +0 -0
@@ -2,24 +2,23 @@ import { es } from "../types";
2
2
  /**
3
3
  * Returns a string that has the format: [line]:[column].
4
4
  *
5
- * If `name` is provided, and it is a string, the resulting string will
6
- * have the format: [name]:[line]:[column].
5
+ * If `name` is provided, and it is a string, the resulting string will have the
6
+ * format: [name]:[line]:[column].
7
7
  */
8
8
  export declare function nodeName(node: es.Node, name?: false | string): string;
9
9
  /**
10
10
  * Converts a camel case string into a dash case one.
11
11
  *
12
12
  * As an example `camelCase` becomes `camel-case`
13
+ *
13
14
  * @example
14
- * ```
15
- * camelToDashCase("camelCase") // returns "camel-case"
16
- * ```
15
+ * ```
16
+ * camelToDashCase("camelCase") // returns "camel-case"
17
+ * ```;
17
18
  */
18
19
  export declare function camelToDashCase(name: string): string;
19
- /**
20
- * A more type safe version of `Object.assign`
21
- */
22
- export declare function assign<T extends {}>(obj: T, props: {
20
+ /** A more type safe version of `Object.assign` */
21
+ export declare function assign<T extends object>(obj: T, props: {
23
22
  [K in keyof T as T[K] extends Function ? never : K]?: T[K];
24
23
  }): T;
25
24
  /** Lazily computes and caches an expression */
@@ -4,6 +4,10 @@ export declare function appendSourceLocations<T extends IValue | null>(valueInst
4
4
  export declare function withAlwaysRuns<T extends IValue | null>(valueInst: TValueInstructions<T>, value: boolean): TValueInstructions<T>;
5
5
  /** Removes jump instructions that point right to the next line */
6
6
  export declare function hideRedundantJumps(inst: IInstruction[]): void;
7
- /** A helper that appends the instructions from `value` into `inst` and returns it's `IValue` instance */
7
+ /**
8
+ * A helper that appends the instructions from `value` into `inst` and returns
9
+ * it's `IValue` instance
10
+ */
8
11
  export declare function pipeInsts<T extends IValue | null>(value: TValueInstructions<T>, inst: IInstruction[]): T;
9
12
  export declare function usesAddressResolver(resolver: AddressResolver, instructions: IInstruction[]): boolean;
13
+ export declare function formatInstructionArgs(args: (IValue | string | null)[]): string[];
@@ -11,10 +11,13 @@ export declare function isTemplateObjectArray(value: IValue): value is ObjectVal
11
11
  };
12
12
  };
13
13
  export declare function extractOutName(out: TEOutput | undefined): string | undefined;
14
- export declare function extractDestrucuringOut(out: TEOutput | undefined, field: string | number): string | IValue | undefined;
14
+ export declare function extractDestrucuringOut(out: TEOutput | undefined, field: string | number): "&_" | IValue | undefined;
15
15
  /** Asserts that `value` is a `LiteralValue` that contains a string */
16
16
  export declare function assertStringLiteral(value: IValue | undefined, name: string): asserts value is LiteralValue<string>;
17
- /** Asserts that `value` is a string literal that is part of a given set of `members`*/
17
+ /**
18
+ * Asserts that `value` is a string literal that is part of a given set of
19
+ * `members`
20
+ */
18
21
  export declare function assertLiteralOneOf<T extends readonly string[]>(value: IValue | undefined, members: T, name: string): asserts value is LiteralValue<T[number]>;
19
22
  /** Asserts that `value` is either a store or a literal */
20
23
  export declare function assertIsRuntimeValue(value: IValue | undefined, name: string): asserts value is LiteralValue | StoreValue;
@@ -26,9 +29,15 @@ export declare function assertIsArrayMacro(value: IValue | undefined, name: stri
26
29
  length: LiteralValue<number>;
27
30
  };
28
31
  };
29
- /** Helper type used to describe the overloads of a macro function. See {@link assertObjectFields} */
32
+ /**
33
+ * Helper type used to describe the overloads of a macro function. See
34
+ * {@link assertObjectFields}
35
+ */
30
36
  export type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
31
- /** Describes an object destructuring paremeter. Generally used with `assertObjectFields` */
37
+ /**
38
+ * Describes an object destructuring paremeter. Generally used with
39
+ * `assertObjectFields`
40
+ */
32
41
  export interface IParameterDescriptor {
33
42
  key: string;
34
43
  name?: string;
@@ -36,6 +45,6 @@ export interface IParameterDescriptor {
36
45
  /** Throw an error on invalid values */
37
46
  validate?(value: IValue): void;
38
47
  }
39
- /** Asserts that all of the fields described are present on `value`*/
48
+ /** Asserts that all of the fields described are present on `value` */
40
49
  export declare function assertObjectFields(value: ObjectValue, fields: (string | IParameterDescriptor)[]): (IValue | string)[];
41
50
  export declare function isDiscardedOut(out: TEOutput | undefined): boolean;
@@ -7,5 +7,5 @@ export declare class AssignmentValue extends VoidValue {
7
7
  "="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
8
8
  toOut(): IValue;
9
9
  debugString(): string;
10
- toString(): string;
10
+ toMlogString(): string;
11
11
  }
@@ -1,10 +1,12 @@
1
- import { IScope, IValue, TEOutput, TValueInstructions } from "../types";
1
+ import { IScope, IValue, TEOutput, TLineRef, TValueInstructions } from "../types";
2
2
  import { VoidValue } from ".";
3
3
  export declare class BaseValue extends VoidValue implements IValue {
4
4
  "u-"(scope: IScope, out?: TEOutput): TValueInstructions;
5
5
  "u+"(scope: IScope, out?: TEOutput): TValueInstructions;
6
6
  "!"(scope: IScope, out?: TEOutput): TValueInstructions;
7
7
  "~"(scope: IScope, out?: TEOutput): TValueInstructions;
8
- "??"(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
8
+ "??"(scope: IScope, other: IValue, out?: TEOutput, endAddress?: TLineRef): TValueInstructions;
9
9
  "!=="(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
10
+ "&&"(scope: IScope, value: IValue, out?: TEOutput, endAddress?: TLineRef): TValueInstructions;
11
+ "||"(scope: IScope, value: IValue, out?: TEOutput, endAddress?: TLineRef): TValueInstructions;
10
12
  }
@@ -2,17 +2,15 @@ import { IScope, IValue, TValueInstructions } from "../types";
2
2
  import { VoidValue } from "./VoidValue";
3
3
  export type TDestructuringMembers = Map<IValue, {
4
4
  value: IValue;
5
- /**
6
- * Handles the input value, is responsible for the assignment.
7
- */
8
- handler(get: () => TValueInstructions, propExists: () => boolean, scope: IScope): TValueInstructions<IValue | null>;
5
+ /** Handles the input value, is responsible for the assignment. */
6
+ handler(this: void, get: () => TValueInstructions, propExists: () => boolean, scope: IScope): TValueInstructions<IValue | null>;
9
7
  }>;
10
8
  /**
11
9
  * Specific case class, required on the ArrayPattern and ObjectPattern handlers
12
10
  * in order to keep the separation of concerns and make the code more modular.
13
11
  *
14
- * When it is assign a value, it will get it's own properties and recursively assign
15
- * each of them to their counterparts on the right hand value.
12
+ * When it is assign a value, it will get it's own properties and recursively
13
+ * assign each of them to their counterparts on the right hand value.
16
14
  */
17
15
  export declare class DestructuringValue extends VoidValue {
18
16
  members: TDestructuringMembers;
@@ -28,5 +26,5 @@ export declare class DestructuringValue extends VoidValue {
28
26
  "="(scope: IScope, right: IValue): TValueInstructions;
29
27
  eval(_scope: IScope): TValueInstructions<IValue>;
30
28
  debugString(): string;
31
- toString(): string;
29
+ toMlogString(): string;
32
30
  }
@@ -1,16 +1,18 @@
1
1
  import { Compiler } from "../Compiler";
2
- import { EMutability, es, IFunctionValue, IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
+ import { EInlineType, EMutability, es, IFunctionValue, IScope, IValue, TEOutput, TValueInstructions } from "../types";
3
3
  import { StoreValue } from "./StoreValue";
4
4
  import { VoidValue } from "./VoidValue";
5
5
  export type TFunctionValueInitParams = (childScope: IScope) => {
6
6
  paramStores: StoreValue[];
7
7
  paramNames: string[];
8
8
  };
9
+ type FunctionParam = es.Function["params"][number];
9
10
  export declare class FunctionValue extends VoidValue implements IFunctionValue {
10
11
  name: string;
11
12
  mutability: EMutability;
12
13
  macro: boolean;
13
14
  scope: IScope;
15
+ inlineType: EInlineType;
14
16
  private childScope;
15
17
  private params;
16
18
  private paramValues;
@@ -23,7 +25,6 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
23
25
  private addr;
24
26
  private temp;
25
27
  private ret;
26
- private inline;
27
28
  private tryingInline;
28
29
  private body;
29
30
  private c;
@@ -32,14 +33,14 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
32
33
  private inlineEnd?;
33
34
  private bundled;
34
35
  private initialized;
35
- constructor({ scope, params, body, c, out, }: {
36
+ constructor({ scope, params, body, c, out, inlineType, }: {
36
37
  scope: IScope;
37
38
  body: es.BlockStatement;
38
39
  c: Compiler;
39
- params: es.Identifier[];
40
+ params: FunctionParam[];
40
41
  out?: TEOutput;
42
+ inlineType: EInlineType;
41
43
  });
42
- typeof(): TValueInstructions;
43
44
  private initScope;
44
45
  private ensureInit;
45
46
  private normalReturn;
@@ -51,7 +52,8 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
51
52
  eval(_scope: IScope): TValueInstructions;
52
53
  preCall(): readonly IValue[] | undefined;
53
54
  debugString(): string;
54
- toString(): string;
55
+ toMlogString(): string;
55
56
  private unwrapParameter;
56
57
  private hardSetParameter;
57
58
  }
59
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { EJumpKind, JumpInstruction } from "../instructions";
2
- import { es, IBindableValue, IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
+ import { es, IScope, IValue, TEOutput, TLineRef, TValueInstructions } from "../types";
3
3
  import { VoidValue } from "./VoidValue";
4
4
  declare const operatorMap: {
5
5
  readonly "!=": EJumpKind.NotEqual;
@@ -23,14 +23,14 @@ type TWhenFalseOperator = keyof typeof invertedOperatorMap;
23
23
  type TWhenTrueOperator = keyof typeof operatorMap;
24
24
  export declare class JumpOutValue extends VoidValue {
25
25
  node: es.Node;
26
- address: IBindableValue<number | null>;
26
+ address: TLineRef;
27
27
  whenTrue: boolean;
28
28
  macro: boolean;
29
- constructor(node: es.Node, address: IBindableValue<number | null>, whenTrue: boolean);
29
+ constructor(node: es.Node, address: TLineRef, whenTrue: boolean);
30
30
  canHandle(operator: string): operator is TWhenTrueOperator | TWhenFalseOperator;
31
31
  handle(operator: TWhenTrueOperator | TWhenFalseOperator, left: IValue, right: IValue): JumpInstruction;
32
32
  eval(_scope: IScope, _out?: TEOutput): TValueInstructions<IValue>;
33
33
  debugString(): string;
34
- toString(): string;
34
+ toMlogString(): string;
35
35
  }
36
36
  export {};
@@ -1,11 +1,11 @@
1
1
  import { IValue } from "../types";
2
2
  import { VoidValue } from "./VoidValue";
3
3
  /**
4
- * This class is used to handle some cases where the value
5
- * can't be directly evaluated by the node handler
4
+ * This class is used to handle some cases where the value can't be directly
5
+ * evaluated by the node handler
6
6
  */
7
7
  export declare class LazyValue extends VoidValue {
8
8
  constructor(evalutate: IValue["eval"]);
9
9
  debugString(): string;
10
- toString(): string;
10
+ toMlogString(): string;
11
11
  }
@@ -6,12 +6,11 @@ export declare class LiteralValue<T extends TLiteral | null = TLiteral> extends
6
6
  mutability: EMutability;
7
7
  constructor(data: T);
8
8
  eval(_scope: IScope): TValueInstructions;
9
- toString(): string;
9
+ toMlogString(): string;
10
10
  get(scope: IScope, name: IValue): TValueInstructions;
11
11
  hasProperty(scope: IScope, prop: IValue): boolean;
12
- get num(): 1 | 0 | (T & {});
12
+ get num(): number;
13
13
  "??"(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
14
- typeof(): TValueInstructions;
15
14
  isString(): this is LiteralValue<string>;
16
15
  isNumber(): this is LiteralValue<number>;
17
16
  debugString(): string;
@@ -1,10 +1,7 @@
1
- import { MacroFunction } from "../macros";
2
- import { EMutability, IScope, IValue, TEOutput, TOperatorMacroMap, TValueInstructions } from "../types";
1
+ import { EMutability, IScope, IValue, TEOutput, TValueInstructions } from "../types";
3
2
  import { VoidValue } from "./VoidValue";
4
- export interface IObjectValueData extends TOperatorMacroMap {
5
- [k: string]: IValue | undefined;
6
- $get?: MacroFunction<IValue>;
7
- $eval?: MacroFunction<IValue>;
3
+ export interface IObjectValueData {
4
+ [k: string]: IValue;
8
5
  }
9
6
  export declare class ObjectValue extends VoidValue {
10
7
  mutability: EMutability;
@@ -12,12 +9,10 @@ export declare class ObjectValue extends VoidValue {
12
9
  data: IObjectValueData;
13
10
  constructor(data?: IObjectValueData);
14
11
  static fromArray(items: IObjectValueData[keyof IObjectValueData][], initialData?: IObjectValueData): ObjectValue;
15
- typeof(scope: IScope, out?: TEOutput): TValueInstructions;
16
12
  get(scope: IScope, key: IValue, out?: TEOutput): TValueInstructions;
17
13
  hasProperty(scope: IScope, prop: IValue): boolean;
18
- eval(scope: IScope, out?: TEOutput): TValueInstructions;
19
- call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<IValue | null>;
20
- "??"(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
14
+ eval(): TValueInstructions;
15
+ "??"(): TValueInstructions;
21
16
  debugString(): string;
22
- toString(): string;
17
+ toMlogString(): string;
23
18
  }
@@ -1,22 +1,27 @@
1
1
  import { BaseValue } from ".";
2
2
  import { EMutability, IScope, IValue, TEOutput, TValueInstructions } from "../types";
3
3
  /**
4
- * `StoreValue` represents values unknown at compile time,
5
- * mostly used with mutable variables and temporary values
4
+ * `StoreValue` represents values unknown at compile time, mostly used with
5
+ * mutable variables and temporary values.
6
+ *
7
+ * Stores are mutable by default.
6
8
  */
7
9
  export declare class StoreValue extends BaseValue implements IValue {
8
10
  name: string;
9
11
  mutability: EMutability;
10
- constructor(name: string, mutability?: EMutability);
12
+ temporary: boolean;
13
+ constructor(name: string, mutability?: EMutability, { temporary, volatile, }?: Partial<Pick<StoreValue, "temporary" | "volatile">>);
11
14
  static from(scope: IScope, out?: TEOutput, mutability?: EMutability): StoreValue;
12
15
  static out(scope: IScope, out?: TEOutput, mutability?: EMutability): IValue;
13
- typeof(): TValueInstructions;
14
16
  "="(scope: IScope, value: IValue): TValueInstructions;
15
17
  "=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
16
18
  "==="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
17
19
  "!="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
18
20
  "!=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
19
21
  eval(_scope: IScope): TValueInstructions;
22
+ get(scope: IScope, prop: IValue, out?: TEOutput): TValueInstructions<IValue>;
23
+ hasProperty(scope: IScope, prop: IValue): boolean;
20
24
  debugString(): string;
21
- toString(): string;
25
+ toMlogString(): string;
22
26
  }
27
+ export declare function formatSenseablePropName(name: string): string;
@@ -3,6 +3,7 @@ export declare class VoidValue implements IValue {
3
3
  name?: string;
4
4
  mutability: EMutability;
5
5
  macro: boolean;
6
+ volatile: boolean;
6
7
  eval(_scope: IScope, _out?: TEOutput): TValueInstructions;
7
8
  call(_scope: IScope, _args: IValue[], _out?: TEOutput): TValueInstructions<IValue | null>;
8
9
  get(_scope: IScope, name: IValue): TValueInstructions;
@@ -11,7 +12,7 @@ export declare class VoidValue implements IValue {
11
12
  postCall(_scope: IScope): void;
12
13
  toOut(): IValue;
13
14
  debugString(): string;
14
- toString(): string;
15
+ toMlogString(): string;
15
16
  }
16
17
  export interface VoidValue extends IValueOperators {
17
18
  }
@@ -3,7 +3,6 @@ export * from "./BaseValue";
3
3
  export * from "./LiteralValue";
4
4
  export * from "./StoreValue";
5
5
  export * from "./ObjectValue";
6
- export * from "./SenseableValue";
7
6
  export * from "./DestructuringValue";
8
7
  export * from "./LazyValue";
9
8
  export * from "./AssignmentValue";