mlogjs 0.4.9 → 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.
- package/README.md +15 -11
- package/dist/Compiler.d.ts +38 -38
- package/dist/CompilerError.d.ts +33 -33
- package/dist/Scope.d.ts +31 -25
- package/dist/bin.cjs +99 -58
- package/dist/bin.d.ts +1 -1
- package/dist/handlers/BlockStatement.d.ts +2 -2
- package/dist/handlers/CallExpression.d.ts +4 -4
- package/dist/handlers/File.d.ts +2 -2
- package/dist/handlers/ForStatement.d.ts +2 -2
- package/dist/handlers/Function.d.ts +5 -5
- package/dist/handlers/Identifier.d.ts +2 -2
- package/dist/handlers/IfStatement.d.ts +2 -2
- package/dist/handlers/Literal.d.ts +5 -5
- package/dist/handlers/Object.d.ts +8 -7
- package/dist/handlers/OperationExpressions.d.ts +9 -9
- package/dist/handlers/Program.d.ts +2 -2
- package/dist/handlers/Statements.d.ts +7 -7
- package/dist/handlers/SwitchStatement.d.ts +2 -2
- package/dist/handlers/TemplateExpression.d.ts +2 -2
- package/dist/handlers/Typescript.d.ts +8 -7
- package/dist/handlers/VariableDeclaration.d.ts +3 -3
- package/dist/handlers/WhileStatement.d.ts +3 -3
- package/dist/handlers/index.d.ts +17 -17
- package/dist/index.cjs +4170 -3164
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +4164 -3158
- package/dist/initScope.d.ts +5 -5
- package/dist/instructions/AddressResolver.d.ts +12 -12
- package/dist/instructions/ControlInstructions.d.ts +10 -10
- package/dist/instructions/EndInstruction.d.ts +6 -4
- package/dist/instructions/InstructionBase.d.ts +15 -15
- package/dist/instructions/JumpInstruction.d.ts +22 -16
- package/dist/instructions/OperationInstruction.d.ts +5 -5
- package/dist/instructions/SetCounterInstruction.d.ts +5 -5
- package/dist/instructions/SetInstruction.d.ts +8 -8
- package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -4
- package/dist/instructions/index.d.ts +9 -9
- package/dist/macros/Asm.d.ts +4 -4
- package/dist/macros/DynamicArray.d.ts +30 -23
- package/dist/macros/Function.d.ts +14 -12
- package/dist/macros/GetGlobal.d.ts +5 -5
- package/dist/macros/Math.d.ts +4 -4
- package/dist/macros/Memory.d.ts +4 -4
- package/dist/macros/Namespace.d.ts +15 -12
- package/dist/macros/Other.d.ts +4 -4
- package/dist/macros/Unchecked.d.ts +7 -0
- package/dist/macros/commands/ApplyStatus.d.ts +4 -4
- package/dist/macros/commands/Control.d.ts +4 -4
- package/dist/macros/commands/Cutscene.d.ts +4 -4
- package/dist/macros/commands/Draw.d.ts +4 -4
- package/dist/macros/commands/DrawFlush.d.ts +4 -4
- package/dist/macros/commands/End.d.ts +4 -4
- package/dist/macros/commands/Explosion.d.ts +4 -4
- package/dist/macros/commands/Fetch.d.ts +4 -4
- package/dist/macros/commands/FlushMessage.d.ts +4 -4
- package/dist/macros/commands/GetBlock.d.ts +4 -4
- package/dist/macros/commands/GetFlag.d.ts +4 -4
- package/dist/macros/commands/GetLink.d.ts +4 -4
- package/dist/macros/commands/Lookup.d.ts +4 -4
- package/dist/macros/commands/PackColor.d.ts +4 -4
- package/dist/macros/commands/Print.d.ts +4 -4
- package/dist/macros/commands/PrintFlush.d.ts +4 -4
- package/dist/macros/commands/Radar.d.ts +6 -6
- package/dist/macros/commands/Sensor.d.ts +4 -4
- package/dist/macros/commands/SetBlock.d.ts +4 -4
- package/dist/macros/commands/SetFlag.d.ts +4 -4
- package/dist/macros/commands/SetRate.d.ts +4 -4
- package/dist/macros/commands/SetRule.d.ts +4 -4
- package/dist/macros/commands/SpawnUnit.d.ts +4 -4
- package/dist/macros/commands/SpawnWave.d.ts +4 -4
- package/dist/macros/commands/Stop.d.ts +4 -4
- package/dist/macros/commands/UnitBind.d.ts +4 -4
- package/dist/macros/commands/UnitControl.d.ts +4 -4
- package/dist/macros/commands/UnitLocate.d.ts +4 -4
- package/dist/macros/commands/UnitRadar.d.ts +4 -4
- package/dist/macros/commands/Wait.d.ts +4 -4
- package/dist/macros/commands/index.d.ts +30 -30
- package/dist/macros/index.d.ts +8 -6
- package/dist/macros/util.d.ts +17 -17
- package/dist/operators.d.ts +46 -25
- package/dist/types.d.ts +259 -220
- package/dist/utils/constants.d.ts +8 -6
- package/dist/utils/general.d.ts +26 -26
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/instruction.d.ts +9 -5
- package/dist/utils/value.d.ts +40 -36
- package/dist/values/AssignmentValue.d.ts +10 -0
- package/dist/values/BaseValue.d.ts +10 -10
- package/dist/values/DestructuringValue.d.ts +32 -30
- package/dist/values/FunctionValue.d.ts +57 -50
- package/dist/values/JumpOutValue.d.ts +36 -0
- package/dist/values/LazyValue.d.ts +11 -9
- package/dist/values/LiteralValue.d.ts +18 -14
- package/dist/values/ObjectValue.d.ts +23 -20
- package/dist/values/SenseableValue.d.ts +24 -24
- package/dist/values/StoreValue.d.ts +22 -21
- package/dist/values/VoidValue.d.ts +16 -13
- package/dist/values/index.d.ts +9 -8
- package/lib/commands.d.ts +59 -32
- package/lib/eslib/lib.es5.d.ts +36 -0
- package/lib/globals.d.ts +5 -5
- package/lib/helpers.d.ts +18 -2
- package/lib/index.d.ts +1 -1
- package/lib/macros.d.ts +150 -0
- package/lib/traits.d.ts +5 -5
- package/package.json +31 -27
- package/dist/assertions.d.ts +0 -28
- package/dist/bin.cjs.map +0 -1
- package/dist/discardedName.d.ts +0 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/utils.d.ts +0 -45
- package/lib/memory.d.ts +0 -17
package/dist/types.d.ts
CHANGED
|
@@ -1,220 +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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @param
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
export interface
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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";
|
package/dist/utils/general.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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 {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
|
|
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;
|