mlogjs 0.4.10 → 0.5.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 (114) hide show
  1. package/README.md +15 -11
  2. package/dist/Compiler.d.ts +38 -38
  3. package/dist/CompilerError.d.ts +33 -33
  4. package/dist/Scope.d.ts +31 -30
  5. package/dist/bin.cjs +99 -58
  6. package/dist/bin.d.ts +1 -1
  7. package/dist/handlers/BlockStatement.d.ts +2 -2
  8. package/dist/handlers/CallExpression.d.ts +4 -4
  9. package/dist/handlers/File.d.ts +2 -2
  10. package/dist/handlers/ForStatement.d.ts +2 -2
  11. package/dist/handlers/Function.d.ts +5 -5
  12. package/dist/handlers/Identifier.d.ts +2 -2
  13. package/dist/handlers/IfStatement.d.ts +2 -2
  14. package/dist/handlers/Literal.d.ts +5 -5
  15. package/dist/handlers/Object.d.ts +8 -7
  16. package/dist/handlers/OperationExpressions.d.ts +9 -9
  17. package/dist/handlers/Program.d.ts +2 -2
  18. package/dist/handlers/Statements.d.ts +7 -7
  19. package/dist/handlers/SwitchStatement.d.ts +2 -2
  20. package/dist/handlers/TemplateExpression.d.ts +2 -2
  21. package/dist/handlers/Typescript.d.ts +8 -7
  22. package/dist/handlers/VariableDeclaration.d.ts +3 -3
  23. package/dist/handlers/WhileStatement.d.ts +3 -3
  24. package/dist/handlers/index.d.ts +17 -17
  25. package/dist/index.cjs +4170 -3263
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.mjs +4164 -3257
  28. package/dist/initScope.d.ts +5 -5
  29. package/dist/instructions/AddressResolver.d.ts +12 -12
  30. package/dist/instructions/ControlInstructions.d.ts +10 -10
  31. package/dist/instructions/EndInstruction.d.ts +6 -4
  32. package/dist/instructions/InstructionBase.d.ts +15 -15
  33. package/dist/instructions/JumpInstruction.d.ts +22 -16
  34. package/dist/instructions/OperationInstruction.d.ts +5 -5
  35. package/dist/instructions/SetCounterInstruction.d.ts +5 -5
  36. package/dist/instructions/SetInstruction.d.ts +8 -8
  37. package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -4
  38. package/dist/instructions/index.d.ts +9 -9
  39. package/dist/macros/Asm.d.ts +4 -4
  40. package/dist/macros/DynamicArray.d.ts +30 -23
  41. package/dist/macros/Function.d.ts +14 -12
  42. package/dist/macros/GetGlobal.d.ts +5 -5
  43. package/dist/macros/Math.d.ts +4 -4
  44. package/dist/macros/Memory.d.ts +4 -4
  45. package/dist/macros/Namespace.d.ts +15 -12
  46. package/dist/macros/Other.d.ts +4 -4
  47. package/dist/macros/Unchecked.d.ts +7 -7
  48. package/dist/macros/commands/ApplyStatus.d.ts +4 -4
  49. package/dist/macros/commands/Control.d.ts +4 -4
  50. package/dist/macros/commands/Cutscene.d.ts +4 -4
  51. package/dist/macros/commands/Draw.d.ts +4 -4
  52. package/dist/macros/commands/DrawFlush.d.ts +4 -4
  53. package/dist/macros/commands/End.d.ts +4 -4
  54. package/dist/macros/commands/Explosion.d.ts +4 -4
  55. package/dist/macros/commands/Fetch.d.ts +4 -4
  56. package/dist/macros/commands/FlushMessage.d.ts +4 -4
  57. package/dist/macros/commands/GetBlock.d.ts +4 -4
  58. package/dist/macros/commands/GetFlag.d.ts +4 -4
  59. package/dist/macros/commands/GetLink.d.ts +4 -4
  60. package/dist/macros/commands/Lookup.d.ts +4 -4
  61. package/dist/macros/commands/PackColor.d.ts +4 -4
  62. package/dist/macros/commands/Print.d.ts +4 -4
  63. package/dist/macros/commands/PrintFlush.d.ts +4 -4
  64. package/dist/macros/commands/Radar.d.ts +6 -6
  65. package/dist/macros/commands/Sensor.d.ts +4 -4
  66. package/dist/macros/commands/SetBlock.d.ts +4 -4
  67. package/dist/macros/commands/SetFlag.d.ts +4 -4
  68. package/dist/macros/commands/SetRate.d.ts +4 -4
  69. package/dist/macros/commands/SetRule.d.ts +4 -4
  70. package/dist/macros/commands/SpawnUnit.d.ts +4 -4
  71. package/dist/macros/commands/SpawnWave.d.ts +4 -4
  72. package/dist/macros/commands/Stop.d.ts +4 -4
  73. package/dist/macros/commands/UnitBind.d.ts +4 -4
  74. package/dist/macros/commands/UnitControl.d.ts +4 -4
  75. package/dist/macros/commands/UnitLocate.d.ts +4 -4
  76. package/dist/macros/commands/UnitRadar.d.ts +4 -4
  77. package/dist/macros/commands/Wait.d.ts +4 -4
  78. package/dist/macros/commands/index.d.ts +30 -30
  79. package/dist/macros/index.d.ts +8 -6
  80. package/dist/macros/util.d.ts +17 -17
  81. package/dist/operators.d.ts +46 -26
  82. package/dist/types.d.ts +259 -237
  83. package/dist/utils/constants.d.ts +8 -6
  84. package/dist/utils/general.d.ts +26 -26
  85. package/dist/utils/index.d.ts +4 -4
  86. package/dist/utils/instruction.d.ts +9 -5
  87. package/dist/utils/value.d.ts +40 -36
  88. package/dist/values/AssignmentValue.d.ts +10 -0
  89. package/dist/values/BaseValue.d.ts +10 -10
  90. package/dist/values/DestructuringValue.d.ts +32 -30
  91. package/dist/values/FunctionValue.d.ts +57 -50
  92. package/dist/values/JumpOutValue.d.ts +36 -0
  93. package/dist/values/LazyValue.d.ts +11 -9
  94. package/dist/values/LiteralValue.d.ts +18 -14
  95. package/dist/values/ObjectValue.d.ts +23 -20
  96. package/dist/values/SenseableValue.d.ts +24 -24
  97. package/dist/values/StoreValue.d.ts +22 -21
  98. package/dist/values/VoidValue.d.ts +16 -13
  99. package/dist/values/index.d.ts +9 -8
  100. package/lib/commands.d.ts +59 -32
  101. package/lib/eslib/lib.es5.d.ts +36 -0
  102. package/lib/globals.d.ts +5 -5
  103. package/lib/helpers.d.ts +18 -2
  104. package/lib/index.d.ts +1 -1
  105. package/lib/macros.d.ts +150 -0
  106. package/lib/traits.d.ts +5 -5
  107. package/package.json +31 -27
  108. package/dist/assertions.d.ts +0 -28
  109. package/dist/bin.cjs.map +0 -1
  110. package/dist/discardedName.d.ts +0 -5
  111. package/dist/index.cjs.map +0 -1
  112. package/dist/index.mjs.map +0 -1
  113. package/dist/utils.d.ts +0 -45
  114. package/lib/memory.d.ts +0 -17
package/dist/types.d.ts CHANGED
@@ -1,237 +1,259 @@
1
- export * as es from "@babel/types";
2
- import * as es from "@babel/types";
3
- import { Compiler } from "./Compiler";
4
- import { AddressResolver } from "./instructions";
5
- import { MacroFunction } from "./macros";
6
- import { LeftRightOperator, UnaryOperator, UpdateOperator } from "./operators";
7
- export declare enum EInstIntent {
8
- none = 0,
9
- break = 1,
10
- continue = 2,
11
- return = 3
12
- }
13
- export interface IInstruction {
14
- intent: EInstIntent;
15
- /**
16
- * Used by function values to check if a return instruction
17
- * originates from them or other function.
18
- */
19
- intentSource?: IValue;
20
- hidden: boolean;
21
- resolve(i: number): void;
22
- source?: es.SourceLocation;
23
- /**
24
- * Helps analyzing control flow, handlers should
25
- * indicate which instructions returned are guaranteed to run
26
- */
27
- alwaysRuns: boolean;
28
- }
29
- /**
30
- * The expression output, either a value or a value name.
31
- *
32
- * Knowing the output variable can be beneficial for static optimizations.
33
- *
34
- * A string means that the handler should create a value with the given name.
35
- *
36
- * An IValue means that the handler should try to use `this` as the output value.
37
- */
38
- export type TEOutput = IValue | string;
39
- export type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, out: TEOutput | undefined, arg: any) => TValueInstructions<T>;
40
- /**
41
- * The scope manages the source code generated variables and their owners,
42
- * as well as break and continue statements and they also work as function
43
- * bodies.
44
- */
45
- export interface IScope {
46
- /** Every scope except the top level one has a parent */
47
- parent: IScope | null;
48
- /** The registry of variables contained by this scope */
49
- data: Record<string, IValue | null>;
50
- name: string;
51
- /**
52
- * Additional instructions required by this scope, such as
53
- * the instructions that make the body of a function
54
- */
55
- inst: IInstruction[];
56
- /** The label applied to this scope */
57
- label?: string;
58
- /** Where to jump to on a break statement */
59
- break: AddressResolver;
60
- /** Where to jump to on a continue statement */
61
- continue: AddressResolver;
62
- /** The function linked to `this`, is `null` when the scope is not inside a function. */
63
- function: IFunctionValue;
64
- /** Counts the number of temp variables generated during compilaton */
65
- ntemp: number;
66
- /**
67
- * A record of the cached value operations, maps the id
68
- * of an operation to a previously computed value.
69
- */
70
- operationCache: Record<string, IValue>;
71
- /** Tracks the dependency relation beteween values and cached operations */
72
- cacheDependencies: Record<string, string[]>;
73
- /**
74
- * Creates a new scope that has `this` as it's parent.
75
- */
76
- createScope(): IScope;
77
- /**
78
- * Creates a new scope to be used by a function value, the scope has the following properties:
79
- * - uses `name` as it's primary name, it changes how variable names are formatted.
80
- * - it has `this` as it's parent
81
- * - independent variable registry
82
- * @param name The name of the scope
83
- * @param stacked
84
- */
85
- createFunction(name: string, stacked?: boolean): IScope;
86
- /** Checks if there is an owner registered with the specified identifier */
87
- has(identifier: string): boolean;
88
- /** Gets a value by their owner's identifier */
89
- get(identifier: string): INamedValue;
90
- /**
91
- * Registers `value` with an owner that uses `name` as both it's name and identifier,
92
- * throws an error if there already is an owner with the same identitifer.
93
- * @param name
94
- * @param value
95
- */
96
- set<T extends IValue>(name: string, value: T): T;
97
- /**
98
- * Registers `value` with an owner that uses `name` as both it's name and identifier,
99
- * overriding any preexisting variables with the same identifier.
100
- * @param name
101
- * @param value
102
- */
103
- hardSet<T extends IValue>(name: string, value: T): T;
104
- /**
105
- * Creates an owned store and registers it to this scope.
106
- * @param identifier The name of the variable that will hold the store
107
- * @param name The mlog name that the owner will have
108
- */
109
- make(identifier: string, name: string): IValue;
110
- /**
111
- * Creates a shallow copy of this scope.
112
- *
113
- * Be aware that since the copy is shallow, changes on object fields (except `data`)
114
- * reflect on the original scope. Note that changes to the children of data also follow this rule.
115
- */
116
- copy(): IScope;
117
- /** Creates a temporary mlog variable name */
118
- makeTempName(): string;
119
- /** Adds the result of an operation to the local cache */
120
- addCachedOperation(op: string, result: IValue, left: IValue, right?: IValue): void;
121
- /** Attempts to get an operation cached in this or in a parent scope. */
122
- getCachedOperation(op: string, left: IValue, right?: IValue): IValue | undefined;
123
- /**
124
- * Removes all cached operations dependent on the given value.
125
- *
126
- * Affects this scope and all of its parents.
127
- */
128
- clearDependentCache(value: IValue): void;
129
- }
130
- export interface IValueOperators {
131
- "!"(scope: IScope, out?: TEOutput): TValueInstructions;
132
- "u+"(scope: IScope, out?: TEOutput): TValueInstructions;
133
- "u-"(scope: IScope, out?: TEOutput): TValueInstructions;
134
- "delete"(scope: IScope, out?: TEOutput): TValueInstructions;
135
- "typeof"(scope: IScope, out?: TEOutput): TValueInstructions;
136
- "void"(scope: IScope, out?: TEOutput): TValueInstructions;
137
- "~"(scope: IScope, out?: TEOutput): TValueInstructions;
138
- "++"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
139
- "--"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
140
- "*"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
141
- "**"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
142
- "+"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
143
- "-"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
144
- "/"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
145
- "%"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
146
- "!="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
147
- "!=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
148
- "<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
149
- "<="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
150
- "=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
151
- "==="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
152
- ">"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
153
- ">="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
154
- "&"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
155
- "<<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
156
- ">>"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
157
- ">>>"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
158
- "^"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
159
- "|"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
160
- instanceof(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
161
- in(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
162
- "&&"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
163
- "??"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
164
- "||"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
165
- "%="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
166
- "&="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
167
- "*="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
168
- "**="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
169
- "+="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
170
- "-="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
171
- "/="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
172
- "&&="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
173
- "||="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
174
- "??="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
175
- "<<="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
176
- ">>="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
177
- ">>>="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
178
- "^="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
179
- "|="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
180
- "="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
181
- }
182
- /** Defines the possible types of mutability of a value */
183
- export declare enum EMutability {
184
- /**
185
- * The value can be changed by the user's code,
186
- * by the mlog runtime, or us
187
- */
188
- mutable = 0,
189
- /**
190
- * The value cannot be directly assigned,
191
- * but it's still not safe from mutations coming from the runtime.
192
- */
193
- readonly = 1,
194
- /** Constant values, won't change during execution */
195
- constant = 2,
196
- /** An immutable value that hasn't been initialized yet */
197
- init = 3
198
- }
199
- export interface IValue extends IValueOperators {
200
- /** The name is used by values that exist on some form in the runtime */
201
- name?: string;
202
- mutability: EMutability;
203
- macro: boolean;
204
- /**
205
- * Evaluates `this`, returning it's representation in a more basic
206
- * value like `StoreValue` with the instructions required to compute that value
207
- */
208
- eval(scope: IScope, out?: TEOutput): TValueInstructions;
209
- call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<IValue | null>;
210
- get(scope: IScope, name: IValue, out?: TEOutput): TValueInstructions;
211
- /**
212
- * Returns the output values for the arguments of a callable value, or `null`.
213
- *
214
- * This is used to allow the handler to optimize the argument instructions.
215
- */
216
- paramOuts(): readonly IValue[] | undefined;
217
- }
218
- /** Helper type that is used in some typescript assertions */
219
- export interface INamedValue extends IValue {
220
- name: string;
221
- }
222
- export type TLiteral = string | number;
223
- export interface IBindableValue<T extends TLiteral | null = TLiteral> extends IValue {
224
- data: T;
225
- }
226
- export interface IFunctionValue extends IValue {
227
- return(scope: IScope, argument: IValue | null, out?: TEOutput): TValueInstructions<IValue | null>;
228
- }
229
- /** Contains a value and the instructions required to compute it */
230
- export type TValueInstructions<Content extends IValue | null = IValue> = [
231
- Content,
232
- IInstruction[]
233
- ];
234
- /** Map of overridable operators in object macros */
235
- export type TOperatorMacroMap = {
236
- [K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
237
- };
1
+ export * as es from "@babel/types";
2
+ import * as es from "@babel/types";
3
+ import { Compiler } from "./Compiler";
4
+ import { AddressResolver } from "./instructions";
5
+ import { MacroFunction } from "./macros";
6
+ import { LeftRightOperator, UnaryOperator, UpdateOperator } from "./operators";
7
+ export declare enum EInstIntent {
8
+ none = 0,
9
+ break = 1,
10
+ continue = 2,
11
+ return = 3,
12
+ /**
13
+ * This is used by the `end` and `stop` instructions.
14
+ * Means that the processor will restart or shutdown.
15
+ */
16
+ exit = 4
17
+ }
18
+ export interface IInstruction {
19
+ intent: EInstIntent;
20
+ /**
21
+ * Used by function values to check if a return instruction
22
+ * originates from them or other function.
23
+ */
24
+ intentSource?: IValue;
25
+ hidden: boolean;
26
+ resolve(i: number): void;
27
+ source?: es.SourceLocation;
28
+ /**
29
+ * Helps analyzing control flow, handlers should
30
+ * indicate which instructions returned are guaranteed to run
31
+ */
32
+ alwaysRuns: boolean;
33
+ }
34
+ /**
35
+ * The expression output, either a value or a value name.
36
+ *
37
+ * Knowing the output variable can be beneficial for static optimizations.
38
+ *
39
+ * A string means that the handler should create a value with the given name.
40
+ *
41
+ * An IValue means that the handler should try to use `this` as the output value.
42
+ */
43
+ export type TEOutput = IValue | string;
44
+ export type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, out: TEOutput | undefined, arg: any) => TValueInstructions<T>;
45
+ /**
46
+ * The scope manages the source code generated variables and their owners,
47
+ * as well as break and continue statements and they also work as function
48
+ * bodies.
49
+ */
50
+ export interface IScope {
51
+ /** Every scope except the top level one has a parent */
52
+ parent: IScope | null;
53
+ /** The registry of variables contained by this scope */
54
+ data: Record<string, IValue | null>;
55
+ name: string;
56
+ /**
57
+ * Additional instructions required by this scope, such as
58
+ * the instructions that make the body of a function
59
+ */
60
+ inst: IInstruction[];
61
+ /** The label applied to this scope */
62
+ label?: string;
63
+ /** Where to jump to on a break statement */
64
+ break: AddressResolver;
65
+ /** Where to jump to on a continue statement */
66
+ continue: AddressResolver;
67
+ /** The function linked to `this`, is `null` when the scope is not inside a function. */
68
+ function: IFunctionValue;
69
+ /** Counts the number of temp variables generated during compilaton */
70
+ ntemp: number;
71
+ /**
72
+ * A record of the cached value operations, maps the id
73
+ * of an operation to a previously computed value.
74
+ */
75
+ operationCache: Record<string, IValue>;
76
+ /** Tracks the dependency relation beteween values and cached operations */
77
+ cacheDependencies: Record<string, string[]>;
78
+ /**
79
+ * Tells array macros whether to check index access performed.
80
+ * This field is mutable.
81
+ */
82
+ checkIndexes: boolean;
83
+ /**
84
+ * Creates a new scope that has `this` as it's parent.
85
+ */
86
+ createScope(): IScope;
87
+ /**
88
+ * Creates a new scope to be used by a function value, the scope has the following properties:
89
+ * - uses `name` as it's primary name, it changes how variable names are formatted.
90
+ * - it has `this` as it's parent
91
+ * - independent variable registry
92
+ * @param name The name of the scope
93
+ * @param stacked
94
+ */
95
+ createFunction(name: string, stacked?: boolean): IScope;
96
+ /** Checks if there is an owner registered with the specified identifier */
97
+ has(identifier: string): boolean;
98
+ /** Gets a value by their owner's identifier */
99
+ get(identifier: string): INamedValue;
100
+ /**
101
+ * Registers `value` with an owner that uses `name` as both it's name and identifier,
102
+ * throws an error if there already is an owner with the same identitifer.
103
+ * @param name
104
+ * @param value
105
+ */
106
+ set<T extends IValue>(name: string, value: T): T;
107
+ /**
108
+ * Registers `value` with an owner that uses `name` as both it's name and identifier,
109
+ * overriding any preexisting variables with the same identifier.
110
+ * @param name
111
+ * @param value
112
+ */
113
+ hardSet<T extends IValue>(name: string, value: T): T;
114
+ /**
115
+ * Creates an owned store and registers it to this scope.
116
+ * @param identifier The name of the variable that will hold the store
117
+ * @param name The mlog name that the owner will have
118
+ */
119
+ make(identifier: string, name: string): IValue;
120
+ /**
121
+ * Creates a shallow copy of this scope.
122
+ *
123
+ * Be aware that since the copy is shallow, changes on object fields (except `data`)
124
+ * reflect on the original scope. Note that changes to the children of data also follow this rule.
125
+ */
126
+ copy(): IScope;
127
+ /** Creates a temporary mlog variable name */
128
+ makeTempName(): string;
129
+ /** Adds the result of an operation to the local cache */
130
+ addCachedOperation(op: string, result: IValue, left: IValue, right?: IValue): void;
131
+ /** Attempts to get an operation cached in this or in a parent scope. */
132
+ getCachedOperation(op: string, left: IValue, right?: IValue): IValue | undefined;
133
+ /**
134
+ * Removes all cached operations dependent on the given value.
135
+ *
136
+ * Affects this scope and all of its parents.
137
+ */
138
+ clearDependentCache(value: IValue): void;
139
+ }
140
+ export interface IValueOperators {
141
+ "!"(scope: IScope, out?: TEOutput): TValueInstructions;
142
+ "u+"(scope: IScope, out?: TEOutput): TValueInstructions;
143
+ "u-"(scope: IScope, out?: TEOutput): TValueInstructions;
144
+ "delete"(scope: IScope, out?: TEOutput): TValueInstructions;
145
+ "typeof"(scope: IScope, out?: TEOutput): TValueInstructions;
146
+ "void"(scope: IScope, out?: TEOutput): TValueInstructions;
147
+ "~"(scope: IScope, out?: TEOutput): TValueInstructions;
148
+ "++"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
149
+ "--"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
150
+ "*"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
151
+ "**"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
152
+ "+"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
153
+ "-"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
154
+ "/"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
155
+ "%"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
156
+ "!="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
157
+ "!=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
158
+ "<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
159
+ "<="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
160
+ "=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
161
+ "==="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
162
+ ">"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
163
+ ">="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
164
+ "&"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
165
+ "<<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
166
+ ">>"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
167
+ ">>>"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
168
+ "^"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
169
+ "|"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
170
+ instanceof(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
171
+ in(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
172
+ "&&"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
173
+ "??"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
174
+ "||"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
175
+ "%="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
176
+ "&="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
177
+ "*="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
178
+ "**="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
179
+ "+="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
180
+ "-="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
181
+ "/="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
182
+ "&&="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
183
+ "||="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
184
+ "??="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
185
+ "<<="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
186
+ ">>="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
187
+ ">>>="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
188
+ "^="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
189
+ "|="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
190
+ "="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
191
+ }
192
+ /** Defines the possible types of mutability of a value */
193
+ export declare enum EMutability {
194
+ /**
195
+ * The value can be changed by the user's code,
196
+ * by the mlog runtime, or us
197
+ */
198
+ mutable = 0,
199
+ /**
200
+ * The value cannot be directly assigned,
201
+ * but it's still not safe from mutations coming from the runtime.
202
+ */
203
+ readonly = 1,
204
+ /** Constant values, won't change during execution */
205
+ constant = 2,
206
+ /** An immutable value that hasn't been initialized yet */
207
+ init = 3
208
+ }
209
+ export interface IValue extends IValueOperators {
210
+ /** The name is used by values that exist on some form in the runtime */
211
+ name?: string;
212
+ mutability: EMutability;
213
+ macro: boolean;
214
+ /**
215
+ * Evaluates `this`, returning it's representation in a more basic
216
+ * value like `StoreValue` with the instructions required to compute that value
217
+ */
218
+ eval(scope: IScope, out?: TEOutput): TValueInstructions;
219
+ call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<IValue | null>;
220
+ get(scope: IScope, name: IValue, out?: TEOutput): TValueInstructions;
221
+ /**
222
+ * Wether `this` has a given property.
223
+ * This method is used to know if it's safe to get a
224
+ * field of an object without errors.
225
+ */
226
+ hasProperty(scope: IScope, prop: IValue): boolean;
227
+ /**
228
+ * A hook that the CallExpression and related handlers call
229
+ * before evaluating the function parameters.
230
+ */
231
+ preCall(scope: IScope, out?: TEOutput): readonly TEOutput[] | undefined;
232
+ /**
233
+ * A hook that the CallExpression and related handlers call
234
+ * after the call has been evaluated.
235
+ */
236
+ postCall(scope: IScope): void;
237
+ /** The string representation of `this` in error messages. */
238
+ debugString(): string;
239
+ }
240
+ /** Helper type that is used in some typescript assertions */
241
+ export interface INamedValue extends IValue {
242
+ name: string;
243
+ }
244
+ export type TLiteral = string | number;
245
+ export interface IBindableValue<T extends TLiteral | null = TLiteral> extends IValue {
246
+ data: T;
247
+ }
248
+ export interface IFunctionValue extends IValue {
249
+ return(scope: IScope, argument: IValue | null, out?: TEOutput): TValueInstructions<IValue | null>;
250
+ }
251
+ /** Contains a value and the instructions required to compute it */
252
+ export type TValueInstructions<Content extends IValue | null = IValue> = [
253
+ Content,
254
+ IInstruction[]
255
+ ];
256
+ /** Map of overridable operators in object macros */
257
+ export type TOperatorMacroMap = {
258
+ [K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
259
+ };
@@ -1,6 +1,8 @@
1
- /**
2
- * The prefix for internal variables inside the compiler output
3
- */
4
- export declare const internalPrefix = "&";
5
- export declare const discardedName: string;
6
- export declare const itemNames: string[];
1
+ /**
2
+ * The prefix for internal variables inside the compiler output
3
+ */
4
+ export declare const internalPrefix = "&";
5
+ export declare const discardedName: string;
6
+ export declare const itemNames: string[];
7
+ /** The name of a special processor variable, controls the instruction pointer */
8
+ export declare const counterName = "@counter";
@@ -1,26 +1,26 @@
1
- import { es } from "../types";
2
- /**
3
- * Returns a string that has the format: [line]:[column].
4
- *
5
- * If `name` is provided, and it is a string, the resulting string will
6
- * have the format: [name]:[line]:[column].
7
- */
8
- export declare function nodeName(node: es.Node, name?: false | string): string;
9
- /**
10
- * Converts a camel case string into a dash case one.
11
- *
12
- * As an example `camelCase` becomes `camel-case`
13
- * @example
14
- * ```
15
- * camelToDashCase("camelCase") // returns "camel-case"
16
- * ```
17
- */
18
- 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: {
23
- [K in keyof T as T[K] extends Function ? never : K]?: T[K];
24
- }): T;
25
- /** Lazily computes and caches an expression */
26
- export declare function lazy<T>(fn: () => T): () => T;
1
+ import { es } from "../types";
2
+ /**
3
+ * Returns a string that has the format: [line]:[column].
4
+ *
5
+ * If `name` is provided, and it is a string, the resulting string will
6
+ * have the format: [name]:[line]:[column].
7
+ */
8
+ export declare function nodeName(node: es.Node, name?: false | string): string;
9
+ /**
10
+ * Converts a camel case string into a dash case one.
11
+ *
12
+ * As an example `camelCase` becomes `camel-case`
13
+ * @example
14
+ * ```
15
+ * camelToDashCase("camelCase") // returns "camel-case"
16
+ * ```
17
+ */
18
+ 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: {
23
+ [K in keyof T as T[K] extends Function ? never : K]?: T[K];
24
+ }): T;
25
+ /** Lazily computes and caches an expression */
26
+ export declare function lazy<T>(fn: () => T): () => T;
@@ -1,4 +1,4 @@
1
- export * from "./constants";
2
- export * from "./general";
3
- export * from "./instruction";
4
- export * from "./value";
1
+ export * from "./constants";
2
+ export * from "./general";
3
+ export * from "./instruction";
4
+ export * from "./value";
@@ -1,5 +1,9 @@
1
- import { es, IInstruction, IValue, TValueInstructions } from "../types";
2
- export declare function appendSourceLocations<T extends IValue | null>(valueInst: TValueInstructions<T>, node: es.Node): TValueInstructions<T>;
3
- export declare function withAlwaysRuns<T extends IValue | null>(valueInst: TValueInstructions<T>, value: boolean): TValueInstructions<T>;
4
- /** Removes jump instructions that point right to the next line */
5
- export declare function hideRedundantJumps(inst: IInstruction[]): void;
1
+ import { AddressResolver } from "../instructions";
2
+ import { es, IInstruction, IValue, TValueInstructions } from "../types";
3
+ export declare function appendSourceLocations<T extends IValue | null>(valueInst: TValueInstructions<T>, node: es.Node): TValueInstructions<T>;
4
+ export declare function withAlwaysRuns<T extends IValue | null>(valueInst: TValueInstructions<T>, value: boolean): TValueInstructions<T>;
5
+ /** Removes jump instructions that point right to the next line */
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 */
8
+ export declare function pipeInsts<T extends IValue | null>(value: TValueInstructions<T>, inst: IInstruction[]): T;
9
+ export declare function usesAddressResolver(resolver: AddressResolver, instructions: IInstruction[]): boolean;