mlogjs 0.3.0-beta.0 → 0.3.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.
@@ -1,5 +1,5 @@
1
- import { IScope } from "../types";
1
+ import { EMutability, IScope } from "../types";
2
2
  import { MacroFunction } from "./Function";
3
3
  export declare class GetGlobal extends MacroFunction {
4
- constructor(scope: IScope);
4
+ constructor(scope: IScope, mutability: EMutability);
5
5
  }
@@ -167,10 +167,25 @@ export interface IValueOperators {
167
167
  "|="(scope: IScope, value: IValue): TValueInstructions;
168
168
  "="(scope: IScope, value: IValue): TValueInstructions;
169
169
  }
170
+ /** Defines the possible types of mutability of a value */
171
+ export declare enum EMutability {
172
+ /**
173
+ * The value can be changed by the user's code,
174
+ * by the mlog runtime, or us
175
+ */
176
+ mutable = 0,
177
+ /**
178
+ * The value cannot be directly assigned,
179
+ * but it's still not safe from mutations coming from the runtime.
180
+ */
181
+ readonly = 1,
182
+ /** Constant values, won't change during execution */
183
+ constant = 2
184
+ }
170
185
  export interface IValue extends IValueOperators {
171
186
  owner: IValueOwner | null;
172
187
  scope: IScope;
173
- constant: boolean;
188
+ mutability: EMutability;
174
189
  macro: boolean;
175
190
  /**
176
191
  * Evaluates `this`, returning it's representation in a more basic
@@ -22,3 +22,9 @@ export declare function nodeName(node: es.Node, name?: false | string): string;
22
22
  */
23
23
  export declare function camelToDashCase(name: string): string;
24
24
  export declare const itemNames: string[];
25
+ /**
26
+ * A more type safe version of `Object.assign`
27
+ */
28
+ export declare function assign<T>(obj: T, props: {
29
+ [K in keyof T as T[K] extends Function ? never : K]?: T[K];
30
+ }): T;
@@ -1,5 +1,5 @@
1
1
  import { Compiler } from "../Compiler";
2
- import { es, IFunctionValue, IScope, IValue, TValueInstructions } from "../types";
2
+ import { EMutability, es, IFunctionValue, IScope, IValue, TValueInstructions } from "../types";
3
3
  import { StoreValue } from "./StoreValue";
4
4
  import { VoidValue } from "./VoidValue";
5
5
  export declare type TFunctionValueInitParams = (childScope: IScope) => {
@@ -7,7 +7,7 @@ export declare type TFunctionValueInitParams = (childScope: IScope) => {
7
7
  paramNames: string[];
8
8
  };
9
9
  export declare class FunctionValue extends VoidValue implements IFunctionValue {
10
- constant: boolean;
10
+ mutability: EMutability;
11
11
  macro: boolean;
12
12
  private node;
13
13
  private childScope;
@@ -1,8 +1,8 @@
1
- import { IScope, IBindableValue, TLiteral, TValueInstructions, IValue } from "../types";
1
+ import { IScope, IBindableValue, TLiteral, TValueInstructions, IValue, EMutability } from "../types";
2
2
  import { BaseValue } from ".";
3
3
  export declare class LiteralValue extends BaseValue implements IBindableValue {
4
4
  data: TLiteral;
5
- constant: boolean;
5
+ mutability: EMutability;
6
6
  constructor(scope: IScope, data: TLiteral);
7
7
  eval(_scope: IScope): TValueInstructions;
8
8
  consume(_scope: IScope): TValueInstructions;
@@ -1,5 +1,5 @@
1
1
  import { MacroFunction } from "../macros";
2
- import { IOwnedValue, IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
2
+ import { EMutability, IOwnedValue, IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
3
3
  import { LiteralValue } from "./LiteralValue";
4
4
  import { VoidValue } from "./VoidValue";
5
5
  export interface IObjectValueData extends TOperatorMacroMap {
@@ -9,7 +9,7 @@ export interface IObjectValueData extends TOperatorMacroMap {
9
9
  $consume?: MacroFunction<IValue>;
10
10
  }
11
11
  export declare class ObjectValue extends VoidValue {
12
- constant: boolean;
12
+ mutability: EMutability;
13
13
  macro: boolean;
14
14
  data: IObjectValueData;
15
15
  constructor(scope: IScope, data?: IObjectValueData);
@@ -1,4 +1,4 @@
1
- import { IScope, IValue, TValueInstructions } from "../types";
1
+ import { EMutability, IScope, IValue, TValueInstructions } from "../types";
2
2
  import { StoreValue } from "./StoreValue";
3
3
  /**
4
4
  * Senseable values are "objects" in the mlog runtime that
@@ -11,13 +11,13 @@ import { StoreValue } from "./StoreValue";
11
11
  * Note that these values are constant by default, so make sure
12
12
  * to set that field to `false` if you want them to be assignable. Example:
13
13
  * ```
14
- * const value = new SenseableValue(scope)
15
- * value.constant = false
14
+ * const value = assign(new SenseableValue(scope), {
15
+ * mutability: EMutability.mutable
16
+ * })
16
17
  * ```
17
18
  */
18
19
  export declare class SenseableValue extends StoreValue {
19
- constant: boolean;
20
+ mutability: EMutability;
20
21
  constructor(scope: IScope);
21
22
  get(scope: IScope, prop: IValue): TValueInstructions<IValue>;
22
- typeof(scope: IScope): TValueInstructions<IValue>;
23
23
  }
@@ -1,11 +1,11 @@
1
1
  import { BaseValue } from ".";
2
- import { IScope, IValue, TValueInstructions } from "../types";
2
+ import { EMutability, IScope, IValue, TValueInstructions } from "../types";
3
3
  /**
4
4
  * `StoreValue` represents values unknown at compile time,
5
5
  * mostly used with mutable variables and temporary values
6
6
  */
7
7
  export declare class StoreValue extends BaseValue implements IValue {
8
- constant: boolean;
8
+ mutability: EMutability;
9
9
  constructor(scope: IScope);
10
10
  typeof(scope: IScope): TValueInstructions;
11
11
  "="(scope: IScope, value: IValue): TValueInstructions;
@@ -1,8 +1,8 @@
1
- import { IScope, IValue, IValueOperators, IValueOwner, TValueInstructions } from "../types";
1
+ import { EMutability, IScope, IValue, IValueOperators, IValueOwner, TValueInstructions } from "../types";
2
2
  export declare class VoidValue implements IValue {
3
3
  owner: IValueOwner | null;
4
4
  scope: IScope;
5
- constant: boolean;
5
+ mutability: EMutability;
6
6
  macro: boolean;
7
7
  constructor(scope: IScope);
8
8
  eval(_scope: IScope): TValueInstructions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mlogjs",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.3.0",
4
4
  "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",