mlogjs 0.2.2 → 0.3.0-beta.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 (188) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/build/Compiler.js +105 -0
  4. package/build/Compiler.js.map +1 -0
  5. package/build/CompilerError.js +11 -0
  6. package/build/CompilerError.js.map +1 -0
  7. package/build/Scope.js +71 -0
  8. package/build/Scope.js.map +1 -0
  9. package/build/bin.js +75 -0
  10. package/build/bin.js.map +1 -0
  11. package/build/handlers/BlockStatement.js +14 -0
  12. package/build/handlers/BlockStatement.js.map +1 -0
  13. package/build/handlers/CallExpression.js +20 -0
  14. package/build/handlers/CallExpression.js.map +1 -0
  15. package/build/handlers/File.js +9 -0
  16. package/build/handlers/File.js.map +1 -0
  17. package/build/handlers/ForStatement.js +32 -0
  18. package/build/handlers/ForStatement.js.map +1 -0
  19. package/build/handlers/Function.js +47 -0
  20. package/build/handlers/Function.js.map +1 -0
  21. package/build/handlers/Identifier.js +8 -0
  22. package/build/handlers/Identifier.js.map +1 -0
  23. package/build/handlers/IfStatement.js +25 -0
  24. package/build/handlers/IfStatement.js.map +1 -0
  25. package/build/handlers/Literal.js +15 -0
  26. package/build/handlers/Literal.js.map +1 -0
  27. package/build/handlers/Object.js +55 -0
  28. package/build/handlers/Object.js.map +1 -0
  29. package/build/handlers/OperationExpressions.js +38 -0
  30. package/build/handlers/OperationExpressions.js.map +1 -0
  31. package/build/handlers/Program.js +9 -0
  32. package/build/handlers/Program.js.map +1 -0
  33. package/build/handlers/Statements.js +30 -0
  34. package/build/handlers/Statements.js.map +1 -0
  35. package/build/handlers/TemplateExpression.js +18 -0
  36. package/build/handlers/TemplateExpression.js.map +1 -0
  37. package/build/handlers/VariableDeclaration.js +72 -0
  38. package/build/handlers/VariableDeclaration.js.map +1 -0
  39. package/build/handlers/WhileStatement.js +23 -0
  40. package/build/handlers/WhileStatement.js.map +1 -0
  41. package/build/handlers/index.js +32 -0
  42. package/build/handlers/index.js.map +1 -0
  43. package/build/index.js +8 -0
  44. package/build/index.js.map +1 -0
  45. package/build/initScope.js +40 -0
  46. package/build/initScope.js.map +1 -0
  47. package/build/instructions/AddressResolver.js +31 -0
  48. package/build/instructions/AddressResolver.js.map +1 -0
  49. package/build/instructions/ControlInstructions.js +23 -0
  50. package/build/instructions/ControlInstructions.js.map +1 -0
  51. package/build/instructions/EndInstruction.js +11 -0
  52. package/build/instructions/EndInstruction.js.map +1 -0
  53. package/build/instructions/InstructionBase.js +21 -0
  54. package/build/instructions/InstructionBase.js.map +1 -0
  55. package/build/instructions/JumpInstruction.js +22 -0
  56. package/build/instructions/JumpInstruction.js.map +1 -0
  57. package/build/instructions/OperationInstruction.js +11 -0
  58. package/build/instructions/OperationInstruction.js.map +1 -0
  59. package/build/instructions/SetCounterInstruction.js +11 -0
  60. package/build/instructions/SetCounterInstruction.js.map +1 -0
  61. package/build/instructions/SetInstruction.js +11 -0
  62. package/build/instructions/SetInstruction.js.map +1 -0
  63. package/build/instructions/ZeroSpaceInstruction.js +11 -0
  64. package/build/instructions/ZeroSpaceInstruction.js.map +1 -0
  65. package/build/instructions/index.js +26 -0
  66. package/build/instructions/index.js.map +1 -0
  67. package/build/macros/Building.js +89 -0
  68. package/build/macros/Building.js.map +1 -0
  69. package/build/macros/Function.js +20 -0
  70. package/build/macros/Function.js.map +1 -0
  71. package/build/macros/Math.js +62 -0
  72. package/build/macros/Math.js.map +1 -0
  73. package/build/macros/Memory.js +63 -0
  74. package/build/macros/Memory.js.map +1 -0
  75. package/build/macros/Namespace.js +111 -0
  76. package/build/macros/Namespace.js.map +1 -0
  77. package/build/macros/Other.js +21 -0
  78. package/build/macros/Other.js.map +1 -0
  79. package/build/macros/RawValue.js +17 -0
  80. package/build/macros/RawValue.js.map +1 -0
  81. package/build/macros/commands/Control.js +26 -0
  82. package/build/macros/commands/Control.js.map +1 -0
  83. package/build/macros/commands/Draw.js +40 -0
  84. package/build/macros/commands/Draw.js.map +1 -0
  85. package/build/macros/commands/DrawFlush.js +18 -0
  86. package/build/macros/commands/DrawFlush.js.map +1 -0
  87. package/build/macros/commands/GetLink.js +25 -0
  88. package/build/macros/commands/GetLink.js.map +1 -0
  89. package/build/macros/commands/Lookup.js +25 -0
  90. package/build/macros/commands/Lookup.js.map +1 -0
  91. package/build/macros/commands/Print.js +18 -0
  92. package/build/macros/commands/Print.js.map +1 -0
  93. package/build/macros/commands/PrintFlush.js +18 -0
  94. package/build/macros/commands/PrintFlush.js.map +1 -0
  95. package/build/macros/commands/Radar.js +65 -0
  96. package/build/macros/commands/Radar.js.map +1 -0
  97. package/build/macros/commands/Sensor.js +21 -0
  98. package/build/macros/commands/Sensor.js.map +1 -0
  99. package/build/macros/commands/UnitBind.js +18 -0
  100. package/build/macros/commands/UnitBind.js.map +1 -0
  101. package/build/macros/commands/UnitControl.js +73 -0
  102. package/build/macros/commands/UnitControl.js.map +1 -0
  103. package/build/macros/commands/UnitLocate.js +76 -0
  104. package/build/macros/commands/UnitLocate.js.map +1 -0
  105. package/build/macros/commands/UnitRadar.js +48 -0
  106. package/build/macros/commands/UnitRadar.js.map +1 -0
  107. package/build/macros/commands/Wait.js +19 -0
  108. package/build/macros/commands/Wait.js.map +1 -0
  109. package/build/macros/commands/index.js +33 -0
  110. package/build/macros/commands/index.js.map +1 -0
  111. package/build/macros/index.js +40 -0
  112. package/build/macros/index.js.map +1 -0
  113. package/build/operators.js +102 -0
  114. package/build/operators.js.map +1 -0
  115. package/build/types.js +28 -0
  116. package/build/types.js.map +1 -0
  117. package/build/utils.js +18 -0
  118. package/build/utils.js.map +1 -0
  119. package/build/values/BaseValue.js +112 -0
  120. package/build/values/BaseValue.js.map +1 -0
  121. package/build/values/FunctionValue.js +116 -0
  122. package/build/values/FunctionValue.js.map +1 -0
  123. package/build/values/LiteralValue.js +89 -0
  124. package/build/values/LiteralValue.js.map +1 -0
  125. package/build/values/ObjectValue.js +55 -0
  126. package/build/values/ObjectValue.js.map +1 -0
  127. package/build/values/StoreValue.js +32 -0
  128. package/build/values/StoreValue.js.map +1 -0
  129. package/build/values/TempValue.js +78 -0
  130. package/build/values/TempValue.js.map +1 -0
  131. package/build/values/VoidValue.js +32 -0
  132. package/build/values/VoidValue.js.map +1 -0
  133. package/build/values/index.js +23 -0
  134. package/build/values/index.js.map +1 -0
  135. package/dist/bin.cjs +17 -4
  136. package/dist/bin.cjs.map +1 -0
  137. package/dist/index.cjs +940 -570
  138. package/dist/index.cjs.map +1 -0
  139. package/dist/index.mjs +918 -569
  140. package/dist/index.mjs.map +1 -0
  141. package/dist/types/Compiler.d.ts +11 -3
  142. package/dist/types/CompilerError.d.ts +9 -0
  143. package/dist/types/Scope.d.ts +10 -9
  144. package/dist/types/handlers/File.d.ts +2 -0
  145. package/dist/types/handlers/Function.d.ts +1 -0
  146. package/dist/types/handlers/Literal.d.ts +4 -1
  147. package/dist/types/handlers/Object.d.ts +2 -0
  148. package/dist/types/handlers/OperationExpressions.d.ts +1 -0
  149. package/dist/types/handlers/Typescript.d.ts +7 -0
  150. package/dist/types/handlers/VariableDeclaration.d.ts +2 -2
  151. package/dist/types/handlers/WhileStatement.d.ts +1 -0
  152. package/dist/types/handlers/index.d.ts +2 -0
  153. package/dist/types/index.d.ts +2 -1
  154. package/dist/types/initScope.d.ts +3 -0
  155. package/dist/types/instructions/ControlInstructions.d.ts +0 -3
  156. package/dist/types/instructions/InstructionBase.d.ts +2 -2
  157. package/dist/types/instructions/SetInstruction.d.ts +1 -0
  158. package/dist/types/macros/Building.d.ts +1 -2
  159. package/dist/types/macros/Entities.d.ts +11 -0
  160. package/dist/types/macros/Function.d.ts +2 -1
  161. package/dist/types/macros/GetGlobal.d.ts +5 -0
  162. package/dist/types/macros/Namespace.d.ts +0 -5
  163. package/dist/types/macros/commands/End.d.ts +5 -0
  164. package/dist/types/macros/commands/index.d.ts +1 -0
  165. package/dist/types/macros/index.d.ts +0 -1
  166. package/dist/types/operators.d.ts +1 -1
  167. package/dist/types/types.d.ts +121 -12
  168. package/dist/types/utils.d.ts +22 -1
  169. package/dist/types/values/BaseValue.d.ts +3 -1
  170. package/dist/types/values/DestructuringValue.d.ts +17 -0
  171. package/dist/types/values/FunctionValue.d.ts +21 -8
  172. package/dist/types/values/LiteralValue.d.ts +2 -1
  173. package/dist/types/values/ObjectValue.d.ts +5 -1
  174. package/dist/types/values/SenseableValue.d.ts +23 -0
  175. package/dist/types/values/StackValue.d.ts +16 -0
  176. package/dist/types/values/StoreValue.d.ts +7 -3
  177. package/dist/types/values/TempValue.d.ts +9 -2
  178. package/dist/types/values/ValueOwner.d.ts +27 -0
  179. package/dist/types/values/VoidValue.d.ts +8 -5
  180. package/dist/types/values/index.d.ts +2 -1
  181. package/lib/commands.d.ts +242 -36
  182. package/lib/globals.d.ts +172 -159
  183. package/lib/helpers.d.ts +2 -2
  184. package/lib/memory.d.ts +1 -1
  185. package/lib/traits.d.ts +130 -109
  186. package/package.json +23 -18
  187. package/build/bin.cjs +0 -69
  188. package/doc/README.md +0 -9
@@ -1,39 +1,122 @@
1
- export * as es from "estree";
1
+ export * as es from "@babel/types";
2
2
  import { Compiler } from "./Compiler";
3
3
  import { AddressResolver } from "./instructions";
4
4
  import { MacroFunction } from "./macros";
5
5
  import { LeftRightOperator, UnaryOperator, UpdateOperator } from "./operators";
6
- import { StoreValue } from "./values";
7
6
  export interface IInstruction {
8
7
  hidden: boolean;
9
8
  resolve(i: number): void;
10
9
  }
11
10
  export declare type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, arg: any) => TValueInstructions<T>;
11
+ /**
12
+ * The scope manages the source code generated variables and their owners,
13
+ * as well as break and continue statements and they also work as function
14
+ * bodies.
15
+ */
12
16
  export interface IScope {
17
+ /** Every scope except the top level one has a parent */
13
18
  parent: IScope | null;
14
- data: {};
19
+ /** The registry of variables contained by this scope */
20
+ data: Record<string, IValueOwner | null>;
15
21
  name: string;
22
+ /**
23
+ * Additional instructions required by this scope, such as
24
+ * the instructions that make the body of a function
25
+ */
16
26
  inst: IInstruction[];
27
+ /** Where to jump to on a break statement */
17
28
  break: AddressResolver;
29
+ /** Where to jump to on a continue statement */
18
30
  continue: AddressResolver;
31
+ /** The function linked to `this`, is `null` when the scope is not inside a function. */
19
32
  function: IFunctionValue;
33
+ /** Counts the number of temp variables generated during compilaton */
20
34
  ntemp: number;
35
+ /**
36
+ * Creates a new scope that has `this` as it's parent.
37
+ */
21
38
  createScope(): IScope;
39
+ /**
40
+ * Creates a new scope to be used by a function value, the scope has the following properties:
41
+ * - uses `name` as it's primary name, it changes how variable names are formatted.
42
+ * - it has `this` as it's parent
43
+ * - independent variable registry
44
+ * @param name The name of the scope
45
+ * @param stacked
46
+ */
22
47
  createFunction(name: string, stacked?: boolean): IScope;
23
- has(name: string): boolean;
24
- get(name: string): IValue;
48
+ /** Checks if there is an owner registered with the specified identifier */
49
+ has(identifier: string): boolean;
50
+ /** Gets a value by their owner's identifier */
51
+ get(identifier: string): IOwnedValue;
52
+ /**
53
+ * Registers `value` with an owner that uses `name` as both it's name and identifier,
54
+ * throws an error if there already is an owner with the same identitifer.
55
+ * @param name
56
+ * @param value
57
+ */
25
58
  set<T extends IValue>(name: string, value: T): T;
59
+ /**
60
+ * Registers `owner` and it's inner value, throws an error
61
+ * if there already is an owner with the same identifier.
62
+ */
63
+ set<T extends IValue>(owner: IValueOwner<T>): T;
64
+ /**
65
+ * Registers `value` with an owner that uses `name` as both it's name and identifier,
66
+ * overriding any preexisting variables with the same identifier.
67
+ * @param name
68
+ * @param value
69
+ */
26
70
  hardSet<T extends IValue>(name: string, value: T): T;
27
- make(name: string, storeName: string): StoreValue;
71
+ /**
72
+ * Registers `owner` and it's inner value, overriding
73
+ * any preexisting variables with the same identifier.
74
+ * @param owner
75
+ */
76
+ hardSet<T extends IValue>(owner: IValueOwner<T>): T;
77
+ /**
78
+ * Creates an owned store and registers it to this scope.
79
+ * @param identifier The name of the variable that will hold the store
80
+ * @param name The mlog name that the owner will have
81
+ */
82
+ make(identifier: string, name: string): IValue;
83
+ /**
84
+ * Creates a shallow copy of this scope.
85
+ *
86
+ * Be aware that since the copy is shallow, changes on object fields (except `data`)
87
+ * reflect on the original scope. Note that changes to the children of data also follow this rule.
88
+ */
28
89
  copy(): IScope;
90
+ /** Creates a temporary mlog variable name */
91
+ makeTempName(): string;
29
92
  }
30
- export interface IValue {
93
+ /**
94
+ * Owners track how variables will behave when it comes to their usage.
95
+ *
96
+ * As an example, Stores use their owners to determine what to do during
97
+ * assignments, like making a compile time alias, moving the values or generating
98
+ * a `set` instruction.
99
+ */
100
+ export interface IValueOwner<T extends IValue = IValue> {
31
101
  scope: IScope;
32
102
  constant: boolean;
33
- macro: boolean;
34
- eval(scope: IScope): TValueInstructions;
35
- call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
36
- get(scope: IScope, name: IValue): TValueInstructions;
103
+ value: T;
104
+ /** The name of the variable on the source code that generated this value owner */
105
+ identifier?: string;
106
+ /** The name this owner has in it's mlog representation */
107
+ name: string;
108
+ /** Whether this owner is temporary or persistent */
109
+ persistent: boolean;
110
+ /** Set of values owned by this, can be used to get the owned value count */
111
+ owned: Set<T>;
112
+ /** Adds `target` to the {@link owned set of owned values} and sets its owner to `this` */
113
+ own(target: T): void;
114
+ /** Replaces the currently held value by `target` */
115
+ replace(target: T): void;
116
+ /** Moves all values owned by `this` into `owner` */
117
+ moveInto(owner: IValueOwner<T>): void;
118
+ }
119
+ export interface IValueOperators {
37
120
  "!"(scope: IScope): TValueInstructions;
38
121
  "u+"(scope: IScope): TValueInstructions;
39
122
  "u-"(scope: IScope): TValueInstructions;
@@ -84,17 +167,43 @@ export interface IValue {
84
167
  "|="(scope: IScope, value: IValue): TValueInstructions;
85
168
  "="(scope: IScope, value: IValue): TValueInstructions;
86
169
  }
170
+ export interface IValue extends IValueOperators {
171
+ owner: IValueOwner | null;
172
+ scope: IScope;
173
+ constant: boolean;
174
+ macro: boolean;
175
+ /**
176
+ * Evaluates `this`, returning it's representation in a more basic
177
+ * value like `StoreValue` with the instructions required to compute that value
178
+ */
179
+ eval(scope: IScope): TValueInstructions;
180
+ /**
181
+ * Does the same thing as {@link IValue.eval eval}, but ensures that the resulting value has an owner.
182
+ *
183
+ * This behaviour is required when dealing with temporary values inside expressions like comparations.
184
+ */
185
+ consume(scope: IScope): TValueInstructions;
186
+ call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
187
+ get(scope: IScope, name: IValue): TValueInstructions;
188
+ ensureOwned(): asserts this is IOwnedValue;
189
+ }
190
+ /** Helper type that is used in some typescript assertions */
191
+ export interface IOwnedValue extends IValue {
192
+ owner: Exclude<IValue["owner"], null>;
193
+ }
87
194
  export declare type TLiteral = string | number;
88
195
  export interface IBindableValue extends IValue {
89
196
  data: TLiteral;
90
197
  }
91
198
  export interface IFunctionValue extends IValue {
92
- return(scope: IScope, argument: IValue): TValueInstructions<IValue | null>;
199
+ return(scope: IScope, argument: IValue | null): TValueInstructions<IValue | null>;
93
200
  }
201
+ /** Contains a value and the instructions required to compute it */
94
202
  export declare type TValueInstructions<Content extends IValue | null = IValue> = [
95
203
  Content,
96
204
  IInstruction[]
97
205
  ];
206
+ /** Map of overridable operators in object macros */
98
207
  export declare type TOperatorMacroMap = {
99
208
  [K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
100
209
  };
@@ -1,3 +1,24 @@
1
1
  import { es } from "./types";
2
- export declare function nodeName(node: es.Node): string;
2
+ /**
3
+ * The prefix for internal variables inside the compiler output
4
+ */
5
+ export declare const internalPrefix = "&";
6
+ export declare const discardedName: string;
7
+ /**
8
+ * Returns a string that has the format: [line]:[column].
9
+ *
10
+ * If `name` is provided, and it is a string, the resulting string will
11
+ * have the format: [name]:[line]:[column].
12
+ */
13
+ export declare function nodeName(node: es.Node, name?: false | string): string;
14
+ /**
15
+ * Converts a camel case string into a dash case one.
16
+ *
17
+ * As an example `camelCase` becomes `camel-case`
18
+ * @example
19
+ * ```
20
+ * camelToDashCase("camelCase") // returns "camel-case"
21
+ * ```
22
+ */
3
23
  export declare function camelToDashCase(name: string): string;
24
+ export declare const itemNames: string[];
@@ -1,5 +1,7 @@
1
- import { IScope, IValue, TValueInstructions } from "../types";
1
+ import { IOwnedValue, IScope, IValue, TValueInstructions } from "../types";
2
2
  import { VoidValue } from ".";
3
3
  export declare class BaseValue extends VoidValue implements IValue {
4
4
  "u-"(scope: IScope): TValueInstructions;
5
+ "u+"(scope: IScope): TValueInstructions;
6
+ ensureOwned(): asserts this is IOwnedValue;
5
7
  }
@@ -0,0 +1,17 @@
1
+ import { IScope, IValue, TValueInstructions } from "../types";
2
+ import { VoidValue } from "./VoidValue";
3
+ /**
4
+ * Specific case class, required on the ArrayPattern and ObjectPattern handlers
5
+ * in order to keep the separation of concerns and make the code more modular.
6
+ *
7
+ * When it is assign a value, it will get it's own properties and recursively assign
8
+ * each of them to their counterparts on the right hand value.
9
+ */
10
+ export declare class DestructuringValue extends VoidValue {
11
+ members: Map<IValue, IValue>;
12
+ macro: boolean;
13
+ constructor(scope: IScope, members: Map<IValue, IValue>);
14
+ "="(scope: IScope, right: IValue): TValueInstructions;
15
+ eval(_scope: IScope): TValueInstructions<IValue>;
16
+ consume(_scope: IScope): TValueInstructions<IValue>;
17
+ }
@@ -2,11 +2,17 @@ import { Compiler } from "../Compiler";
2
2
  import { es, IFunctionValue, IScope, IValue, TValueInstructions } from "../types";
3
3
  import { StoreValue } from "./StoreValue";
4
4
  import { VoidValue } from "./VoidValue";
5
+ export declare type TFunctionValueInitParams = (childScope: IScope) => {
6
+ paramStores: StoreValue[];
7
+ paramNames: string[];
8
+ };
5
9
  export declare class FunctionValue extends VoidValue implements IFunctionValue {
6
10
  constant: boolean;
7
11
  macro: boolean;
8
- private paramStores;
9
- private paramNames;
12
+ private node;
13
+ private childScope;
14
+ private params;
15
+ private paramOwners;
10
16
  private inst;
11
17
  private addr;
12
18
  private temp;
@@ -14,21 +20,28 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
14
20
  private inline;
15
21
  private tryingInline;
16
22
  private body;
17
- private name;
18
23
  private c;
19
24
  private callSize;
20
25
  private inlineTemp;
21
26
  private inlineEnd;
22
27
  private bundled;
23
- private createValues;
28
+ private initialized;
29
+ constructor({ scope, params, body, c, node, }: {
30
+ scope: IScope;
31
+ body: es.BlockStatement;
32
+ c: Compiler;
33
+ node: es.Function;
34
+ params: es.Identifier[];
35
+ });
24
36
  typeof(scope: IScope): TValueInstructions;
25
- private createInst;
26
- constructor(scope: IScope, name: string, paramNames: string[], paramStores: StoreValue[], body: es.BlockStatement, c: Compiler);
37
+ private initScope;
38
+ private ensureInit;
27
39
  private normalReturn;
28
40
  private normalCall;
29
41
  private inlineReturn;
30
42
  private inlineCall;
31
43
  call(scope: IScope, args: IValue[]): TValueInstructions;
32
- return(scope: IScope, arg: IValue): TValueInstructions<IValue | null>;
33
- eval(scope: IScope): TValueInstructions;
44
+ return(scope: IScope, arg: IValue | null): TValueInstructions<IValue | null>;
45
+ eval(_scope: IScope): TValueInstructions;
46
+ consume(_scope: IScope): TValueInstructions;
34
47
  }
@@ -4,7 +4,8 @@ export declare class LiteralValue extends BaseValue implements IBindableValue {
4
4
  data: TLiteral;
5
5
  constant: boolean;
6
6
  constructor(scope: IScope, data: TLiteral);
7
- eval(scope: IScope): TValueInstructions;
7
+ eval(_scope: IScope): TValueInstructions;
8
+ consume(_scope: IScope): TValueInstructions;
8
9
  toString(): string;
9
10
  get(scope: IScope, name: IValue): TValueInstructions;
10
11
  get num(): number;
@@ -1,19 +1,23 @@
1
1
  import { MacroFunction } from "../macros";
2
- import { IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
2
+ import { IOwnedValue, IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
3
3
  import { LiteralValue } from "./LiteralValue";
4
4
  import { VoidValue } from "./VoidValue";
5
5
  export interface IObjectValueData extends TOperatorMacroMap {
6
6
  [k: string]: IValue | undefined;
7
7
  $get?: MacroFunction<IValue>;
8
8
  $eval?: MacroFunction<IValue>;
9
+ $consume?: MacroFunction<IValue>;
9
10
  }
10
11
  export declare class ObjectValue extends VoidValue {
11
12
  constant: boolean;
12
13
  macro: boolean;
13
14
  data: IObjectValueData;
14
15
  constructor(scope: IScope, data?: IObjectValueData);
16
+ static fromArray(scope: IScope, items: IObjectValueData[keyof IObjectValueData][]): ObjectValue;
15
17
  typeof(scope: IScope): TValueInstructions;
16
18
  get(scope: IScope, key: LiteralValue): TValueInstructions;
17
19
  eval(scope: IScope): TValueInstructions;
20
+ consume(scope: IScope): TValueInstructions;
18
21
  call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
22
+ ensureOwned(): asserts this is IOwnedValue;
19
23
  }
@@ -0,0 +1,23 @@
1
+ import { IScope, IValue, TValueInstructions } from "../types";
2
+ import { StoreValue } from "./StoreValue";
3
+ /**
4
+ * Senseable values are "objects" in the mlog runtime that
5
+ * have special properties that can be accessed
6
+ * via the `sense` instruction.
7
+ *
8
+ * This class extends `StoreValue` to allow dynamic behavior
9
+ * that is not possible with object macros.
10
+ *
11
+ * Note that these values are constant by default, so make sure
12
+ * to set that field to `false` if you want them to be assignable. Example:
13
+ * ```
14
+ * const value = new SenseableValue(scope)
15
+ * value.constant = false
16
+ * ```
17
+ */
18
+ export declare class SenseableValue extends StoreValue {
19
+ constant: boolean;
20
+ constructor(scope: IScope);
21
+ get(scope: IScope, prop: IValue): TValueInstructions<IValue>;
22
+ typeof(scope: IScope): TValueInstructions<IValue>;
23
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseValue } from ".";
2
+ import { IScope, IValue, TValueInstructions } from "../types";
3
+ /**
4
+ * `StackValue` represents values unknown at compile time inside a stack memory,
5
+ * mostly used with mutable variables and temporary values
6
+ */
7
+ export declare class StackValue extends BaseValue implements IValue {
8
+ constant: boolean;
9
+ offset: number;
10
+ constructor(scope: IScope);
11
+ typeof(scope: IScope): TValueInstructions;
12
+ "="(scope: IScope, value: IValue): TValueInstructions;
13
+ eval(scope: IScope): TValueInstructions;
14
+ consume(_scope: IScope): TValueInstructions;
15
+ toString(): string;
16
+ }
@@ -1,11 +1,15 @@
1
1
  import { BaseValue } from ".";
2
2
  import { IScope, IValue, TValueInstructions } from "../types";
3
+ /**
4
+ * `StoreValue` represents values unknown at compile time,
5
+ * mostly used with mutable variables and temporary values
6
+ */
3
7
  export declare class StoreValue extends BaseValue implements IValue {
4
- name: string;
5
8
  constant: boolean;
6
- constructor(scope: IScope, name: string);
9
+ constructor(scope: IScope);
7
10
  typeof(scope: IScope): TValueInstructions;
8
11
  "="(scope: IScope, value: IValue): TValueInstructions;
9
- eval(scope: IScope): TValueInstructions;
12
+ eval(_scope: IScope): TValueInstructions;
13
+ consume(_scope: IScope): TValueInstructions;
10
14
  toString(): string;
11
15
  }
@@ -1,12 +1,19 @@
1
1
  import { IInstruction, IScope, IValue, TValueInstructions } from "../types";
2
2
  import { StoreValue } from "./";
3
- export declare class TempValue extends StoreValue {
3
+ export interface TempValueOptions {
4
+ scope: IScope;
5
+ name?: string;
6
+ renameable?: boolean;
7
+ }
8
+ export declare class TempValue extends StoreValue implements IValue {
4
9
  proxied: IValue;
5
10
  canProxy: boolean;
6
11
  setInst: IInstruction;
7
- constructor(scope: IScope, name?: string);
12
+ renameable: boolean;
13
+ constructor({ scope, name, renameable }: TempValueOptions);
8
14
  eval(scope: IScope): TValueInstructions;
9
15
  "="(scope: IScope, value: IValue): TValueInstructions;
10
16
  proxy(value: IValue): TValueInstructions;
11
17
  noProxy(): void;
18
+ rename(name: string): void;
12
19
  }
@@ -0,0 +1,27 @@
1
+ import { IScope, IValue, IValueOwner } from "../types";
2
+ export interface IValueOwnerParams<T extends IValue> {
3
+ scope: IScope;
4
+ constant?: boolean;
5
+ value: T;
6
+ /** The identifier of the variable that `this` represents */
7
+ identifier?: string;
8
+ /** The name that the variable will have during transpilation to mlog */
9
+ name?: string;
10
+ }
11
+ export declare class ValueOwner<T extends IValue = IValue> implements IValueOwner<T> {
12
+ scope: IScope;
13
+ constant: boolean;
14
+ value: T;
15
+ owned: Set<T>;
16
+ identifier?: string;
17
+ name: string;
18
+ persistent: boolean;
19
+ /**
20
+ * Creates a new `ValueOwner`, if `value` is already owned,
21
+ * `this` will be aliased to `value`, else `this` will own `value`
22
+ */
23
+ constructor({ scope, constant, value, identifier, name, }: IValueOwnerParams<T>);
24
+ own(target: T): void;
25
+ replace(target: T): void;
26
+ moveInto(owner: IValueOwner<T>): void;
27
+ }
@@ -1,13 +1,16 @@
1
- import { IScope, IValue, TValueInstructions } from "../types";
1
+ import { IScope, IValue, IValueOperators, IValueOwner, TValueInstructions } from "../types";
2
2
  export declare class VoidValue implements IValue {
3
+ owner: IValueOwner | null;
3
4
  scope: IScope;
4
5
  constant: boolean;
5
6
  macro: boolean;
6
7
  constructor(scope: IScope);
7
- eval(scope: IScope): TValueInstructions;
8
- call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
9
- get(scope: IScope, name: IValue): TValueInstructions;
8
+ eval(_scope: IScope): TValueInstructions;
9
+ consume(_scope: IScope): TValueInstructions<IValue>;
10
+ call(_scope: IScope, _args: IValue[]): TValueInstructions<IValue | null>;
11
+ get(_scope: IScope, _name: IValue): TValueInstructions;
12
+ ensureOwned(): void;
10
13
  toString(): string;
11
14
  }
12
- export interface VoidValue extends IValue {
15
+ export interface VoidValue extends IValueOperators {
13
16
  }
@@ -2,5 +2,6 @@ export * from "./VoidValue";
2
2
  export * from "./BaseValue";
3
3
  export * from "./LiteralValue";
4
4
  export * from "./StoreValue";
5
- export * from "./TempValue";
6
5
  export * from "./ObjectValue";
6
+ export * from "./SenseableValue";
7
+ export * from "./DestructuringValue";