mlogjs 0.4.9 → 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.
@@ -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 declare type BinaryOperator = typeof binaryOperators[number];
5
+ export type BinaryOperator = typeof binaryOperators[number];
6
6
  export declare const logicalOperators: readonly ["&&", "??", "||"];
7
- export declare type LogicalOperator = typeof logicalOperators[number];
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 declare type AssignementOperator = typeof assignmentOperators[number];
12
+ export type AssignementOperator = typeof assignmentOperators[number];
13
13
  export declare const leftRightOperators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "??=", "<<=", ">>=", ">>>=", "^=", "|=", "="];
14
- export declare type LeftRightOperator = typeof leftRightOperators[number];
14
+ export type LeftRightOperator = typeof leftRightOperators[number];
15
15
  export declare const unaryOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~"];
16
- export declare type UnaryOperator = typeof unaryOperators[number];
16
+ export type UnaryOperator = typeof unaryOperators[number];
17
17
  export declare const updateOperators: readonly ["++", "--"];
18
- export declare type UpdateOperator = typeof updateOperators[number];
18
+ export type UpdateOperator = typeof updateOperators[number];
19
19
  export declare const singleOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
20
- export declare type SingleOperator = typeof singleOperators[number];
20
+ export type SingleOperator = typeof singleOperators[number];
21
21
  export declare const operators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "??=", "<<=", ">>=", ">>>=", "^=", "|=", "=", "!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
22
- export declare type Operator = typeof operators[number];
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 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>;
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 declare type TLiteral = string | number;
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 declare type TValueInstructions<Content extends IValue | null = IValue> = [
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 declare type TOperatorMacroMap = {
235
+ export type TOperatorMacroMap = {
219
236
  [K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
220
237
  };
@@ -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 declare type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
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;
@@ -1,6 +1,6 @@
1
1
  import { IScope, IValue, TValueInstructions } from "../types";
2
2
  import { VoidValue } from "./VoidValue";
3
- export declare type TDestructuringMembers = Map<IValue, {
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 declare type TFunctionValueInitParams = (childScope: IScope) => {
5
+ export type TFunctionValueInitParams = (childScope: IScope) => {
6
6
  paramStores: StoreValue[];
7
7
  paramNames: string[];
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mlogjs",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",