mlogjs 0.4.6 → 0.4.8

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.
@@ -1,22 +1,22 @@
1
- import { IOwnedValue, IScope, IValue, TValueInstructions } from "../types";
1
+ import { IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
2
  import { LiteralValue, ObjectValue, SenseableValue, StoreValue } from "../values";
3
- import { ValueOwner } from "../values/ValueOwner";
4
3
  import { MacroFunction } from "./Function";
5
4
  export declare class DynamicArray extends ObjectValue {
6
5
  scope: IScope;
6
+ name: string;
7
7
  values: IValue[];
8
- valueTemp: ValueOwner<SenseableValue>;
9
- returnTemp: ValueOwner<StoreValue>;
10
- getterAddr: LiteralValue;
11
- setterAddr: LiteralValue;
8
+ getterTemp: SenseableValue;
9
+ setterTemp: SenseableValue;
10
+ returnTemp: StoreValue;
11
+ getterAddr: LiteralValue<number | null>;
12
+ setterAddr: LiteralValue<number | null>;
12
13
  bundledSetter: boolean;
13
14
  bundledGetter: boolean;
14
- constructor(scope: IScope, values: IValue[]);
15
- getValue(scope: IScope, index: IValue, checked: boolean): TValueInstructions;
15
+ constructor(scope: IScope, name: string, values: IValue[]);
16
+ getValue(scope: IScope, out: TEOutput | undefined, index: IValue, checked: boolean): TValueInstructions;
16
17
  setValue(scope: IScope, index: IValue, value: IValue, checked: boolean): TValueInstructions;
17
18
  initGetter(): void;
18
19
  initSetter(): void;
19
- ensureOwned(): asserts this is IOwnedValue;
20
20
  }
21
21
  export declare class DynamicArrayConstructor extends MacroFunction {
22
22
  constructor();
@@ -1,13 +1,12 @@
1
- import { EMutability, IScope, IValue, TValueInstructions } from "../types";
1
+ import { EMutability, IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
2
  import { VoidValue } from "../values";
3
- declare type TFunction<T extends IValue | null> = (scope: IScope, ...args: IValue[]) => TValueInstructions<T>;
3
+ declare type TFunction<T extends IValue | null> = (scope: IScope, out: TEOutput | undefined, ...args: IValue[]) => TValueInstructions<T>;
4
4
  export declare class MacroFunction<RT extends IValue | null = IValue> extends VoidValue {
5
5
  macro: boolean;
6
6
  mutability: EMutability;
7
7
  fn: TFunction<RT>;
8
8
  constructor(fn: TFunction<RT>);
9
- call(scope: IScope, args: IValue[]): TValueInstructions<RT>;
9
+ call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<RT>;
10
10
  eval(_scope: IScope): TValueInstructions;
11
- consume(_scope: IScope): TValueInstructions;
12
11
  }
13
12
  export {};
@@ -1,5 +1,4 @@
1
- import { IScope } from "../types";
2
1
  import { ObjectValue } from "../values";
3
2
  export declare class MlogMath extends ObjectValue {
4
- constructor(scope: IScope);
3
+ constructor();
5
4
  }
@@ -1,4 +1,3 @@
1
- import { IScope } from "../types";
2
1
  import { ObjectValue } from "../values";
3
2
  interface NamespaceMacroOptions {
4
3
  changeCasing?: boolean;
@@ -8,6 +7,6 @@ export declare class NamespaceMacro extends ObjectValue {
8
7
  constructor({ changeCasing }?: NamespaceMacroOptions);
9
8
  }
10
9
  export declare class VarsNamespace extends NamespaceMacro {
11
- constructor(scope: IScope);
10
+ constructor();
12
11
  }
13
12
  export {};
@@ -1,5 +1,5 @@
1
- import { IParameterDescriptor } from "../assertions";
2
- import { IScope, IValue, TValueInstructions } from "../types";
1
+ import { IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
+ import { IParameterDescriptor } from "../utils";
3
3
  import { MacroFunction } from "./Function";
4
4
  interface IOverloadNamespaceOptions<K extends string> {
5
5
  overloads: Record<K, {
@@ -10,7 +10,7 @@ interface IOverloadNamespaceOptions<K extends string> {
10
10
  named?: string;
11
11
  args: (IParameterDescriptor | string)[];
12
12
  }>;
13
- handler(scope: IScope, overload: K, ...args: (IValue | string)[]): TValueInstructions<IValue | null>;
13
+ handler(scope: IScope, overload: K, out: TEOutput | undefined, ...args: (IValue | string)[]): TValueInstructions<IValue | null>;
14
14
  }
15
15
  /** Used to create namespaces that contain multiple methods that map into instructions */
16
16
  export declare function createOverloadNamespace<K extends string>({ overloads, handler, }: IOverloadNamespaceOptions<K>): Record<string, MacroFunction<IValue | null>>;
package/dist/types.d.ts CHANGED
@@ -12,6 +12,11 @@ export declare enum EInstIntent {
12
12
  }
13
13
  export interface IInstruction {
14
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;
15
20
  hidden: boolean;
16
21
  resolve(i: number): void;
17
22
  source?: es.SourceLocation;
@@ -21,7 +26,17 @@ export interface IInstruction {
21
26
  */
22
27
  alwaysRuns: boolean;
23
28
  }
24
- export declare type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, arg: any) => TValueInstructions<T>;
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 declare type TEOutput = IValue | string;
39
+ export declare type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, out: TEOutput | undefined, arg: any) => TValueInstructions<T>;
25
40
  /**
26
41
  * The scope manages the source code generated variables and their owners,
27
42
  * as well as break and continue statements and they also work as function
@@ -31,7 +46,7 @@ export interface IScope {
31
46
  /** Every scope except the top level one has a parent */
32
47
  parent: IScope | null;
33
48
  /** The registry of variables contained by this scope */
34
- data: Record<string, IValueOwner | null>;
49
+ data: Record<string, IValue | null>;
35
50
  name: string;
36
51
  /**
37
52
  * Additional instructions required by this scope, such as
@@ -64,7 +79,7 @@ export interface IScope {
64
79
  /** Checks if there is an owner registered with the specified identifier */
65
80
  has(identifier: string): boolean;
66
81
  /** Gets a value by their owner's identifier */
67
- get(identifier: string): IOwnedValue;
82
+ get(identifier: string): INamedValue;
68
83
  /**
69
84
  * Registers `value` with an owner that uses `name` as both it's name and identifier,
70
85
  * throws an error if there already is an owner with the same identitifer.
@@ -72,11 +87,6 @@ export interface IScope {
72
87
  * @param value
73
88
  */
74
89
  set<T extends IValue>(name: string, value: T): T;
75
- /**
76
- * Registers `owner` and it's inner value, throws an error
77
- * if there already is an owner with the same identifier.
78
- */
79
- set<T extends IValue>(owner: IValueOwner<T>): T;
80
90
  /**
81
91
  * Registers `value` with an owner that uses `name` as both it's name and identifier,
82
92
  * overriding any preexisting variables with the same identifier.
@@ -84,12 +94,6 @@ export interface IScope {
84
94
  * @param value
85
95
  */
86
96
  hardSet<T extends IValue>(name: string, value: T): T;
87
- /**
88
- * Registers `owner` and it's inner value, overriding
89
- * any preexisting variables with the same identifier.
90
- * @param owner
91
- */
92
- hardSet<T extends IValue>(owner: IValueOwner<T>): T;
93
97
  /**
94
98
  * Creates an owned store and registers it to this scope.
95
99
  * @param identifier The name of the variable that will hold the store
@@ -106,83 +110,57 @@ export interface IScope {
106
110
  /** Creates a temporary mlog variable name */
107
111
  makeTempName(): string;
108
112
  }
109
- /**
110
- * Owners track how variables will behave when it comes to their usage.
111
- *
112
- * As an example, Stores use their owners to determine what to do during
113
- * assignments, like making a compile time alias, moving the values or generating
114
- * a `set` instruction.
115
- */
116
- export interface IValueOwner<T extends IValue = IValue> {
117
- scope: IScope;
118
- constant: boolean;
119
- value: T;
120
- /** The name of the variable on the source code that generated this value owner */
121
- identifier?: string;
122
- /** The name this owner has in it's mlog representation */
123
- name: string;
124
- /** Whether this owner is temporary or persistent */
125
- persistent: boolean;
126
- /** Set of values owned by this, can be used to get the owned value count */
127
- owned: Set<T>;
128
- /** Adds `target` to the {@link owned set of owned values} and sets its owner to `this` */
129
- own(target: T): void;
130
- /** Replaces the currently held value by `target` */
131
- replace(target: T): void;
132
- /** Moves all values owned by `this` into `owner` */
133
- moveInto(owner: IValueOwner<T>): void;
134
- }
135
113
  export interface IValueOperators {
136
- "!"(scope: IScope): TValueInstructions;
137
- "u+"(scope: IScope): TValueInstructions;
138
- "u-"(scope: IScope): TValueInstructions;
139
- "delete"(scope: IScope): TValueInstructions;
140
- "typeof"(scope: IScope): TValueInstructions;
141
- "void"(scope: IScope): TValueInstructions;
142
- "~"(scope: IScope): TValueInstructions;
143
- "++"(scope: IScope, prefix: boolean): TValueInstructions;
144
- "--"(scope: IScope, prefix: boolean): TValueInstructions;
145
- "*"(scope: IScope, value: IValue): TValueInstructions;
146
- "**"(scope: IScope, value: IValue): TValueInstructions;
147
- "+"(scope: IScope, value: IValue): TValueInstructions;
148
- "-"(scope: IScope, value: IValue): TValueInstructions;
149
- "/"(scope: IScope, value: IValue): TValueInstructions;
150
- "%"(scope: IScope, value: IValue): TValueInstructions;
151
- "!="(scope: IScope, value: IValue): TValueInstructions;
152
- "!=="(scope: IScope, value: IValue): TValueInstructions;
153
- "<"(scope: IScope, value: IValue): TValueInstructions;
154
- "<="(scope: IScope, value: IValue): TValueInstructions;
155
- "=="(scope: IScope, value: IValue): TValueInstructions;
156
- "==="(scope: IScope, value: IValue): TValueInstructions;
157
- ">"(scope: IScope, value: IValue): TValueInstructions;
158
- ">="(scope: IScope, value: IValue): TValueInstructions;
159
- "&"(scope: IScope, value: IValue): TValueInstructions;
160
- "<<"(scope: IScope, value: IValue): TValueInstructions;
161
- ">>"(scope: IScope, value: IValue): TValueInstructions;
162
- ">>>"(scope: IScope, value: IValue): TValueInstructions;
163
- "^"(scope: IScope, value: IValue): TValueInstructions;
164
- "|"(scope: IScope, value: IValue): TValueInstructions;
165
- instanceof(scope: IScope, value: IValue): TValueInstructions;
166
- in(scope: IScope, value: IValue): TValueInstructions;
167
- "&&"(scope: IScope, value: IValue): TValueInstructions;
168
- "??"(scope: IScope, value: IValue): TValueInstructions;
169
- "||"(scope: IScope, value: IValue): TValueInstructions;
170
- "%="(scope: IScope, value: IValue): TValueInstructions;
171
- "&="(scope: IScope, value: IValue): TValueInstructions;
172
- "*="(scope: IScope, value: IValue): TValueInstructions;
173
- "**="(scope: IScope, value: IValue): TValueInstructions;
174
- "+="(scope: IScope, value: IValue): TValueInstructions;
175
- "-="(scope: IScope, value: IValue): TValueInstructions;
176
- "/="(scope: IScope, value: IValue): TValueInstructions;
177
- "&&="(scope: IScope, value: IValue): TValueInstructions;
178
- "||="(scope: IScope, value: IValue): TValueInstructions;
179
- "??="(scope: IScope, value: IValue): TValueInstructions;
180
- "<<="(scope: IScope, value: IValue): TValueInstructions;
181
- ">>="(scope: IScope, value: IValue): TValueInstructions;
182
- ">>>="(scope: IScope, value: IValue): TValueInstructions;
183
- "^="(scope: IScope, value: IValue): TValueInstructions;
184
- "|="(scope: IScope, value: IValue): TValueInstructions;
185
- "="(scope: IScope, value: IValue): TValueInstructions;
114
+ "!"(scope: IScope, out?: TEOutput): TValueInstructions;
115
+ "u+"(scope: IScope, out?: TEOutput): TValueInstructions;
116
+ "u-"(scope: IScope, out?: TEOutput): TValueInstructions;
117
+ "delete"(scope: IScope, out?: TEOutput): TValueInstructions;
118
+ "typeof"(scope: IScope, out?: TEOutput): TValueInstructions;
119
+ "void"(scope: IScope, out?: TEOutput): TValueInstructions;
120
+ "~"(scope: IScope, out?: TEOutput): TValueInstructions;
121
+ "++"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
122
+ "--"(scope: IScope, prefix: boolean, out?: TEOutput): TValueInstructions;
123
+ "*"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
124
+ "**"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
125
+ "+"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
126
+ "-"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
127
+ "/"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
128
+ "%"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
129
+ "!="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
130
+ "!=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
131
+ "<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
132
+ "<="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
133
+ "=="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
134
+ "==="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
135
+ ">"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
136
+ ">="(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
137
+ "&"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
138
+ "<<"(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
139
+ ">>"(scope: IScope, value: IValue, 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
+ instanceof(scope: IScope, value: IValue, out?: TEOutput): TValueInstructions;
144
+ in(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
+ ">>>="(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;
186
164
  }
187
165
  /** Defines the possible types of mutability of a value */
188
166
  export declare enum EMutability {
@@ -197,37 +175,39 @@ export declare enum EMutability {
197
175
  */
198
176
  readonly = 1,
199
177
  /** Constant values, won't change during execution */
200
- constant = 2
178
+ constant = 2,
179
+ /** An immutable value that hasn't been initialized yet */
180
+ init = 3
201
181
  }
202
182
  export interface IValue extends IValueOperators {
203
- owner: IValueOwner | null;
183
+ /** The name is used by values that exist on some form in the runtime */
184
+ name?: string;
204
185
  mutability: EMutability;
205
186
  macro: boolean;
206
187
  /**
207
188
  * Evaluates `this`, returning it's representation in a more basic
208
189
  * value like `StoreValue` with the instructions required to compute that value
209
190
  */
210
- eval(scope: IScope): TValueInstructions;
191
+ eval(scope: IScope, out?: TEOutput): TValueInstructions;
192
+ call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<IValue | null>;
193
+ get(scope: IScope, name: IValue, out?: TEOutput): TValueInstructions;
211
194
  /**
212
- * Does the same thing as {@link IValue.eval eval}, but ensures that the resulting value has an owner.
195
+ * Returns the output values for the arguments of a callable value, or `null`.
213
196
  *
214
- * This behaviour is required when dealing with temporary values inside expressions like comparations.
197
+ * This is used to allow the handler to optimize the argument instructions.
215
198
  */
216
- consume(scope: IScope): TValueInstructions;
217
- call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
218
- get(scope: IScope, name: IValue): TValueInstructions;
219
- ensureOwned(): asserts this is IOwnedValue;
199
+ paramOuts(): readonly IValue[] | undefined;
220
200
  }
221
201
  /** Helper type that is used in some typescript assertions */
222
- export interface IOwnedValue extends IValue {
223
- owner: Exclude<IValue["owner"], null>;
202
+ export interface INamedValue extends IValue {
203
+ name: string;
224
204
  }
225
205
  export declare type TLiteral = string | number;
226
- export interface IBindableValue extends IValue {
227
- data: TLiteral;
206
+ export interface IBindableValue<T extends TLiteral | null = TLiteral> extends IValue {
207
+ data: T;
228
208
  }
229
209
  export interface IFunctionValue extends IValue {
230
- return(scope: IScope, argument: IValue | null): TValueInstructions<IValue | null>;
210
+ return(scope: IScope, argument: IValue | null, out?: TEOutput): TValueInstructions<IValue | null>;
231
211
  }
232
212
  /** Contains a value and the instructions required to compute it */
233
213
  export declare type TValueInstructions<Content extends IValue | null = IValue> = [
@@ -0,0 +1,6 @@
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[];
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,4 @@
1
+ export * from "./constants";
2
+ export * from "./general";
3
+ export * from "./instruction";
4
+ export * from "./value";
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,36 @@
1
+ import { IValue, TEOutput } from "../types";
2
+ import { IObjectValueData, LiteralValue, ObjectValue, StoreValue } from "../values";
3
+ export declare function isTemplateObjectArray(value: IValue): value is ObjectValue & {
4
+ data: IObjectValueData & {
5
+ raw: ObjectValue & {
6
+ data: IObjectValueData & {
7
+ length: LiteralValue<number>;
8
+ };
9
+ };
10
+ length: LiteralValue<number>;
11
+ };
12
+ };
13
+ export declare function extractOutName(out: TEOutput | undefined): string | undefined;
14
+ export declare function extractDestrucuringOut(out: TEOutput | undefined, field: string | number): string | IValue | undefined;
15
+ /** Asserts that `value` is a `LiteralValue` that contains a string */
16
+ export declare function assertStringLiteral(value: IValue | undefined, name: string): asserts value is LiteralValue<string>;
17
+ /** Asserts that `value` is a string literal that is part of a given set of `members`*/
18
+ export declare function assertLiteralOneOf<T extends readonly string[]>(value: IValue | undefined, members: T, name: string): asserts value is LiteralValue<T[number]>;
19
+ /** Asserts that `value` is either a store or a literal */
20
+ export declare function assertIsRuntimeValue(value: IValue | undefined, name: string): asserts value is LiteralValue | StoreValue;
21
+ /** Asserts that `value` is an `ObjectValue` */
22
+ export declare function assertIsObjectMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
23
+ /** Asserts that `value` is an `ObjectValue` that has a length property */
24
+ export declare function assertIsArrayMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
25
+ /** Helper type used to describe the overloads of a macro function. See {@link assertObjectFields} */
26
+ export declare type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
27
+ /** Describes an object destructuring paremeter. Generally used with `assertObjectFields` */
28
+ export interface IParameterDescriptor {
29
+ key: string;
30
+ name?: string;
31
+ default?: string;
32
+ /** Throw an error on invalid values */
33
+ validate?(value: IValue): void;
34
+ }
35
+ /** Asserts that all of the fields described are present on `value`*/
36
+ export declare function assertObjectFields(value: ObjectValue, fields: (string | IParameterDescriptor)[]): (IValue | string)[];
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { es, IValue, TValueInstructions } from "./types";
1
+ import { es, IValue, TEOutput, TValueInstructions } from "./types";
2
2
  import { IObjectValueData, LiteralValue, ObjectValue } from "./values";
3
3
  /**
4
4
  * The prefix for internal variables inside the compiler output
@@ -35,13 +35,11 @@ export declare function isTemplateObjectArray(value: IValue): value is ObjectVal
35
35
  data: IObjectValueData & {
36
36
  raw: ObjectValue & {
37
37
  data: IObjectValueData & {
38
- length: LiteralValue & {
39
- data: number;
40
- };
38
+ length: LiteralValue<number>;
41
39
  };
42
40
  };
43
- length: LiteralValue & {
44
- data: number;
45
- };
41
+ length: LiteralValue<number>;
46
42
  };
47
43
  };
44
+ export declare function extractOutName(out: TEOutput | undefined): string | undefined;
45
+ export declare function extractDestrucuringOut(out: TEOutput | undefined, field: string | number): string | IValue | undefined;
@@ -1,9 +1,9 @@
1
- import { IScope, IValue, TValueInstructions } from "../types";
1
+ import { IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
2
  import { VoidValue } from ".";
3
3
  export declare class BaseValue extends VoidValue implements IValue {
4
- "u-"(scope: IScope): TValueInstructions;
5
- "u+"(scope: IScope): TValueInstructions;
6
- "!"(scope: IScope): TValueInstructions;
7
- "~"(scope: IScope): TValueInstructions;
8
- "??"(scope: IScope, other: IValue): TValueInstructions;
4
+ "u-"(scope: IScope, out?: TEOutput): TValueInstructions;
5
+ "u+"(scope: IScope, out?: TEOutput): TValueInstructions;
6
+ "!"(scope: IScope, out?: TEOutput): TValueInstructions;
7
+ "~"(scope: IScope, out?: TEOutput): TValueInstructions;
8
+ "??"(scope: IScope, other: IValue, out?: TEOutput): TValueInstructions;
9
9
  }
@@ -1,5 +1,12 @@
1
1
  import { IScope, IValue, TValueInstructions } from "../types";
2
2
  import { VoidValue } from "./VoidValue";
3
+ export declare type TDestructuringMembers = Map<IValue, {
4
+ value: IValue;
5
+ /**
6
+ * Handles the input value, is responsible for the assignment.
7
+ */
8
+ handler(get: () => TValueInstructions): TValueInstructions<IValue | null>;
9
+ }>;
3
10
  /**
4
11
  * Specific case class, required on the ArrayPattern and ObjectPattern handlers
5
12
  * in order to keep the separation of concerns and make the code more modular.
@@ -8,10 +15,16 @@ import { VoidValue } from "./VoidValue";
8
15
  * each of them to their counterparts on the right hand value.
9
16
  */
10
17
  export declare class DestructuringValue extends VoidValue {
11
- members: Map<IValue, IValue>;
18
+ members: TDestructuringMembers;
12
19
  macro: boolean;
13
- constructor(members: Map<IValue, IValue>);
20
+ /**
21
+ * Contains the keys that are constant strings with their respective values.
22
+ *
23
+ * This is used by some macros to avoid creating unecessary temporary values
24
+ * if the output value is a destructuring value.
25
+ */
26
+ fields: Record<string, IValue>;
27
+ constructor(members: TDestructuringMembers);
14
28
  "="(scope: IScope, right: IValue): TValueInstructions;
15
29
  eval(_scope: IScope): TValueInstructions<IValue>;
16
- consume(_scope: IScope): TValueInstructions<IValue>;
17
30
  }
@@ -1,5 +1,5 @@
1
1
  import { Compiler } from "../Compiler";
2
- import { EMutability, es, IFunctionValue, IScope, IValue, TValueInstructions } from "../types";
2
+ import { EMutability, es, IFunctionValue, IScope, IValue, TEOutput, TValueInstructions } from "../types";
3
3
  import { StoreValue } from "./StoreValue";
4
4
  import { VoidValue } from "./VoidValue";
5
5
  export declare type TFunctionValueInitParams = (childScope: IScope) => {
@@ -7,12 +7,15 @@ export declare type TFunctionValueInitParams = (childScope: IScope) => {
7
7
  paramNames: string[];
8
8
  };
9
9
  export declare class FunctionValue extends VoidValue implements IFunctionValue {
10
+ name: string;
10
11
  mutability: EMutability;
11
12
  macro: boolean;
12
13
  scope: IScope;
14
+ private out?;
13
15
  private childScope;
14
16
  private params;
15
- private paramOwners;
17
+ private paramValues;
18
+ private paramNames;
16
19
  private inst;
17
20
  private addr;
18
21
  private temp;
@@ -26,11 +29,12 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
26
29
  private inlineEnd?;
27
30
  private bundled;
28
31
  private initialized;
29
- constructor({ scope, params, body, c, }: {
32
+ constructor({ scope, params, body, c, out, }: {
30
33
  scope: IScope;
31
34
  body: es.BlockStatement;
32
35
  c: Compiler;
33
36
  params: es.Identifier[];
37
+ out?: TEOutput;
34
38
  });
35
39
  typeof(): TValueInstructions;
36
40
  private initScope;
@@ -39,8 +43,8 @@ export declare class FunctionValue extends VoidValue implements IFunctionValue {
39
43
  private normalCall;
40
44
  private inlineReturn;
41
45
  private inlineCall;
42
- call(scope: IScope, args: IValue[]): TValueInstructions;
46
+ call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions;
43
47
  return(scope: IScope, arg: IValue | null): TValueInstructions<IValue | null>;
44
48
  eval(_scope: IScope): TValueInstructions;
45
- consume(_scope: IScope): TValueInstructions;
49
+ paramOuts(): readonly IValue[] | undefined;
46
50
  }
@@ -5,5 +5,5 @@ import { VoidValue } from "./VoidValue";
5
5
  * can't be directly evaluated by the node handler
6
6
  */
7
7
  export declare class LazyValue extends VoidValue {
8
- constructor(options: Pick<IValue, "eval" | "consume">);
8
+ constructor(evalutate: IValue["eval"]);
9
9
  }
@@ -1,14 +1,14 @@
1
1
  import { IScope, IBindableValue, TLiteral, TValueInstructions, IValue, EMutability } from "../types";
2
2
  import { BaseValue } from ".";
3
- export declare class LiteralValue extends BaseValue implements IBindableValue {
4
- data: TLiteral;
3
+ export declare class LiteralValue<T extends TLiteral | null = TLiteral> extends BaseValue implements IBindableValue<T> {
4
+ data: T;
5
5
  mutability: EMutability;
6
- constructor(data: TLiteral);
6
+ constructor(data: T);
7
7
  eval(_scope: IScope): TValueInstructions;
8
- consume(_scope: IScope): TValueInstructions;
9
8
  toString(): string;
10
9
  get(scope: IScope, name: IValue): TValueInstructions;
11
- get num(): number;
10
+ get num(): 1 | 0 | (T & {});
12
11
  typeof(): TValueInstructions;
13
- ensureOwned(): void;
12
+ isString(): this is LiteralValue<string>;
13
+ isNumber(): this is LiteralValue<number>;
14
14
  }
@@ -1,12 +1,11 @@
1
1
  import { MacroFunction } from "../macros";
2
- import { EMutability, IOwnedValue, IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
2
+ import { EMutability, IScope, IValue, TEOutput, 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>;
10
9
  }
11
10
  export declare class ObjectValue extends VoidValue {
12
11
  mutability: EMutability;
@@ -14,10 +13,8 @@ export declare class ObjectValue extends VoidValue {
14
13
  data: IObjectValueData;
15
14
  constructor(data?: IObjectValueData);
16
15
  static fromArray(items: IObjectValueData[keyof IObjectValueData][], intialData?: IObjectValueData): ObjectValue;
17
- typeof(): TValueInstructions;
18
- get(scope: IScope, key: LiteralValue): TValueInstructions;
19
- eval(scope: IScope): TValueInstructions;
20
- consume(scope: IScope): TValueInstructions;
21
- call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
22
- ensureOwned(): asserts this is IOwnedValue;
16
+ typeof(scope: IScope, out?: TEOutput): TValueInstructions;
17
+ get(scope: IScope, key: LiteralValue, out?: TEOutput): TValueInstructions;
18
+ eval(scope: IScope, out?: TEOutput): TValueInstructions;
19
+ call(scope: IScope, args: IValue[], out?: TEOutput): TValueInstructions<IValue | null>;
23
20
  }
@@ -1,4 +1,4 @@
1
- import { EMutability, IScope, IValue, TValueInstructions } from "../types";
1
+ import { EMutability, IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
2
  import { StoreValue } from "./StoreValue";
3
3
  /**
4
4
  * Senseable values are "objects" in the mlog runtime that
@@ -17,7 +17,8 @@ import { StoreValue } from "./StoreValue";
17
17
  * ```
18
18
  */
19
19
  export declare class SenseableValue extends StoreValue {
20
- mutability: EMutability;
21
- constructor(scope: IScope);
22
- get(scope: IScope, prop: IValue): TValueInstructions<IValue>;
20
+ constructor(name: string, mutability?: EMutability);
21
+ static from(scope: IScope, out?: TEOutput, mutability?: EMutability): SenseableValue;
22
+ static out(scope: IScope, out?: TEOutput, mutability?: EMutability): IValue;
23
+ get(scope: IScope, prop: IValue, out?: TEOutput): TValueInstructions<IValue>;
23
24
  }