mlogjs 0.4.8 → 0.4.10
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/dist/Compiler.d.ts +1 -1
- package/dist/CompilerError.d.ts +1 -1
- package/dist/Scope.d.ts +6 -1
- package/dist/handlers/Object.d.ts +2 -1
- package/dist/handlers/OperationExpressions.d.ts +1 -0
- package/dist/handlers/Statements.d.ts +1 -0
- package/dist/index.cjs +177 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +177 -24
- package/dist/index.mjs.map +1 -1
- package/dist/macros/Function.d.ts +1 -1
- package/dist/macros/Unchecked.d.ts +7 -0
- package/dist/operators.d.ts +9 -8
- package/dist/types.d.ts +22 -5
- package/dist/utils/general.d.ts +2 -0
- package/dist/utils/value.d.ts +1 -1
- package/dist/values/BaseValue.d.ts +1 -0
- package/dist/values/DestructuringValue.d.ts +1 -1
- package/dist/values/FunctionValue.d.ts +1 -1
- package/dist/values/StoreValue.d.ts +4 -0
- package/package.json +1 -1
package/dist/operators.d.ts
CHANGED
|
@@ -2,24 +2,25 @@ export declare const arithmeticBinaryOperators: readonly ["*", "**", "+", "-", "
|
|
|
2
2
|
export declare const comparisonBinaryOperators: readonly ["!=", "!==", "<", "<=", "==", "===", ">", ">="];
|
|
3
3
|
export declare const bitwiseBinaryOperators: readonly ["&", "<<", ">>", ">>>", "^", "|"];
|
|
4
4
|
export declare const binaryOperators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in"];
|
|
5
|
-
export
|
|
5
|
+
export type BinaryOperator = typeof binaryOperators[number];
|
|
6
6
|
export declare const logicalOperators: readonly ["&&", "??", "||"];
|
|
7
|
-
export
|
|
7
|
+
export type LogicalOperator = typeof logicalOperators[number];
|
|
8
8
|
export declare const arithmeticAssignmentOperators: readonly ["%=", "&=", "*=", "**=", "+=", "-=", "/="];
|
|
9
9
|
export declare const logicalAssignmentOperators: readonly ["&&=", "||=", "??="];
|
|
10
10
|
export declare const bitwiseAssignmentOperators: readonly ["<<=", ">>=", ">>>=", "^=", "|="];
|
|
11
11
|
export declare const assignmentOperators: readonly ["%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "??=", "<<=", ">>=", ">>>=", "^=", "|=", "="];
|
|
12
|
-
export
|
|
12
|
+
export type AssignementOperator = typeof assignmentOperators[number];
|
|
13
13
|
export declare const leftRightOperators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "??=", "<<=", ">>=", ">>>=", "^=", "|=", "="];
|
|
14
|
-
export
|
|
14
|
+
export type LeftRightOperator = typeof leftRightOperators[number];
|
|
15
15
|
export declare const unaryOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~"];
|
|
16
|
-
export
|
|
16
|
+
export type UnaryOperator = typeof unaryOperators[number];
|
|
17
17
|
export declare const updateOperators: readonly ["++", "--"];
|
|
18
|
-
export
|
|
18
|
+
export type UpdateOperator = typeof updateOperators[number];
|
|
19
19
|
export declare const singleOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
|
|
20
|
-
export
|
|
20
|
+
export type SingleOperator = typeof singleOperators[number];
|
|
21
21
|
export declare const operators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "??=", "<<=", ">>=", ">>>=", "^=", "|=", "=", "!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
|
|
22
|
-
export
|
|
22
|
+
export type Operator = typeof operators[number];
|
|
23
23
|
export declare const operatorMap: {
|
|
24
24
|
[k in Exclude<BinaryOperator, "instanceof" | "in"> | Exclude<LogicalOperator, "??">]: string;
|
|
25
25
|
};
|
|
26
|
+
export declare const orderIndependentOperators: readonly Operator[];
|
package/dist/types.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface IInstruction {
|
|
|
35
35
|
*
|
|
36
36
|
* An IValue means that the handler should try to use `this` as the output value.
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
39
|
-
export
|
|
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
40
|
/**
|
|
41
41
|
* The scope manages the source code generated variables and their owners,
|
|
42
42
|
* as well as break and continue statements and they also work as function
|
|
@@ -63,6 +63,13 @@ export interface IScope {
|
|
|
63
63
|
function: IFunctionValue;
|
|
64
64
|
/** Counts the number of temp variables generated during compilaton */
|
|
65
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[]>;
|
|
66
73
|
/**
|
|
67
74
|
* Creates a new scope that has `this` as it's parent.
|
|
68
75
|
*/
|
|
@@ -109,6 +116,16 @@ export interface IScope {
|
|
|
109
116
|
copy(): IScope;
|
|
110
117
|
/** Creates a temporary mlog variable name */
|
|
111
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;
|
|
112
129
|
}
|
|
113
130
|
export interface IValueOperators {
|
|
114
131
|
"!"(scope: IScope, out?: TEOutput): TValueInstructions;
|
|
@@ -202,7 +219,7 @@ export interface IValue extends IValueOperators {
|
|
|
202
219
|
export interface INamedValue extends IValue {
|
|
203
220
|
name: string;
|
|
204
221
|
}
|
|
205
|
-
export
|
|
222
|
+
export type TLiteral = string | number;
|
|
206
223
|
export interface IBindableValue<T extends TLiteral | null = TLiteral> extends IValue {
|
|
207
224
|
data: T;
|
|
208
225
|
}
|
|
@@ -210,11 +227,11 @@ export interface IFunctionValue extends IValue {
|
|
|
210
227
|
return(scope: IScope, argument: IValue | null, out?: TEOutput): TValueInstructions<IValue | null>;
|
|
211
228
|
}
|
|
212
229
|
/** Contains a value and the instructions required to compute it */
|
|
213
|
-
export
|
|
230
|
+
export type TValueInstructions<Content extends IValue | null = IValue> = [
|
|
214
231
|
Content,
|
|
215
232
|
IInstruction[]
|
|
216
233
|
];
|
|
217
234
|
/** Map of overridable operators in object macros */
|
|
218
|
-
export
|
|
235
|
+
export type TOperatorMacroMap = {
|
|
219
236
|
[K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
|
|
220
237
|
};
|
package/dist/utils/general.d.ts
CHANGED
|
@@ -22,3 +22,5 @@ export declare function camelToDashCase(name: string): string;
|
|
|
22
22
|
export declare function assign<T extends {}>(obj: T, props: {
|
|
23
23
|
[K in keyof T as T[K] extends Function ? never : K]?: T[K];
|
|
24
24
|
}): T;
|
|
25
|
+
/** Lazily computes and caches an expression */
|
|
26
|
+
export declare function lazy<T>(fn: () => T): () => T;
|
package/dist/utils/value.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function assertIsObjectMacro(value: IValue | undefined, name: str
|
|
|
23
23
|
/** Asserts that `value` is an `ObjectValue` that has a length property */
|
|
24
24
|
export declare function assertIsArrayMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
|
|
25
25
|
/** Helper type used to describe the overloads of a macro function. See {@link assertObjectFields} */
|
|
26
|
-
export
|
|
26
|
+
export type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
|
|
27
27
|
/** Describes an object destructuring paremeter. Generally used with `assertObjectFields` */
|
|
28
28
|
export interface IParameterDescriptor {
|
|
29
29
|
key: string;
|
|
@@ -6,4 +6,5 @@ export declare class BaseValue extends VoidValue implements IValue {
|
|
|
6
6
|
"!"(scope: IScope, out?: TEOutput): TValueInstructions;
|
|
7
7
|
"~"(scope: IScope, out?: TEOutput): TValueInstructions;
|
|
8
8
|
"??"(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
|
|
9
|
+
"!=="(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
|
|
9
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IScope, IValue, TValueInstructions } from "../types";
|
|
2
2
|
import { VoidValue } from "./VoidValue";
|
|
3
|
-
export
|
|
3
|
+
export type TDestructuringMembers = Map<IValue, {
|
|
4
4
|
value: IValue;
|
|
5
5
|
/**
|
|
6
6
|
* Handles the input value, is responsible for the assignment.
|
|
@@ -2,7 +2,7 @@ import { Compiler } from "../Compiler";
|
|
|
2
2
|
import { EMutability, es, IFunctionValue, IScope, IValue, TEOutput, TValueInstructions } from "../types";
|
|
3
3
|
import { StoreValue } from "./StoreValue";
|
|
4
4
|
import { VoidValue } from "./VoidValue";
|
|
5
|
-
export
|
|
5
|
+
export type TFunctionValueInitParams = (childScope: IScope) => {
|
|
6
6
|
paramStores: StoreValue[];
|
|
7
7
|
paramNames: string[];
|
|
8
8
|
};
|
|
@@ -12,6 +12,10 @@ export declare class StoreValue extends BaseValue implements IValue {
|
|
|
12
12
|
static out(scope: IScope, out?: TEOutput, mutability?: EMutability): IValue;
|
|
13
13
|
typeof(): TValueInstructions;
|
|
14
14
|
"="(scope: IScope, value: IValue): TValueInstructions;
|
|
15
|
+
"=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
|
|
16
|
+
"==="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
|
|
17
|
+
"!="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
|
|
18
|
+
"!=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
|
|
15
19
|
eval(_scope: IScope): TValueInstructions;
|
|
16
20
|
toString(): string;
|
|
17
21
|
}
|