mlogjs 0.4.0 → 0.4.2

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.
Files changed (148) hide show
  1. package/dist/Scope.d.ts +1 -0
  2. package/dist/handlers/Statements.d.ts +1 -0
  3. package/dist/index.cjs +500 -350
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.mjs +500 -350
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/instructions/SetInstruction.d.ts +2 -0
  8. package/dist/macros/Asm.d.ts +1 -2
  9. package/dist/macros/Function.d.ts +4 -4
  10. package/dist/macros/GetGlobal.d.ts +2 -2
  11. package/dist/macros/Memory.d.ts +1 -2
  12. package/dist/macros/Namespace.d.ts +1 -1
  13. package/dist/macros/Other.d.ts +1 -2
  14. package/dist/macros/commands/ApplyStatus.d.ts +1 -2
  15. package/dist/macros/commands/Control.d.ts +1 -2
  16. package/dist/macros/commands/Cutscene.d.ts +1 -2
  17. package/dist/macros/commands/Draw.d.ts +1 -2
  18. package/dist/macros/commands/DrawFlush.d.ts +1 -2
  19. package/dist/macros/commands/End.d.ts +1 -2
  20. package/dist/macros/commands/Explosion.d.ts +1 -2
  21. package/dist/macros/commands/Fetch.d.ts +1 -2
  22. package/dist/macros/commands/FlushMessage.d.ts +1 -2
  23. package/dist/macros/commands/GetBlock.d.ts +1 -2
  24. package/dist/macros/commands/GetFlag.d.ts +1 -2
  25. package/dist/macros/commands/GetLink.d.ts +1 -2
  26. package/dist/macros/commands/Lookup.d.ts +1 -2
  27. package/dist/macros/commands/PackColor.d.ts +1 -2
  28. package/dist/macros/commands/Print.d.ts +1 -2
  29. package/dist/macros/commands/PrintFlush.d.ts +1 -2
  30. package/dist/macros/commands/Radar.d.ts +1 -2
  31. package/dist/macros/commands/Sensor.d.ts +1 -2
  32. package/dist/macros/commands/SetBlock.d.ts +1 -2
  33. package/dist/macros/commands/SetFlag.d.ts +1 -2
  34. package/dist/macros/commands/SetRate.d.ts +1 -2
  35. package/dist/macros/commands/SetRule.d.ts +1 -2
  36. package/dist/macros/commands/SpawnUnit.d.ts +1 -2
  37. package/dist/macros/commands/SpawnWave.d.ts +1 -2
  38. package/dist/macros/commands/Stop.d.ts +1 -2
  39. package/dist/macros/commands/UnitBind.d.ts +1 -2
  40. package/dist/macros/commands/UnitControl.d.ts +1 -2
  41. package/dist/macros/commands/UnitLocate.d.ts +1 -2
  42. package/dist/macros/commands/UnitRadar.d.ts +1 -2
  43. package/dist/macros/commands/Wait.d.ts +1 -2
  44. package/dist/macros/util.d.ts +2 -3
  45. package/dist/operators.d.ts +4 -4
  46. package/dist/types.d.ts +3 -1
  47. package/dist/values/BaseValue.d.ts +2 -2
  48. package/dist/values/DestructuringValue.d.ts +1 -1
  49. package/dist/values/FunctionValue.d.ts +3 -4
  50. package/dist/values/LiteralValue.d.ts +3 -2
  51. package/dist/values/ObjectValue.d.ts +3 -3
  52. package/dist/values/StoreValue.d.ts +4 -2
  53. package/dist/values/VoidValue.d.ts +0 -2
  54. package/lib/commands.d.ts +306 -40
  55. package/lib/eslib/lib.es5.d.ts +23 -0
  56. package/lib/globals.d.ts +2 -3
  57. package/lib/helpers.d.ts +2 -1
  58. package/lib/kinds.d.ts +5 -2
  59. package/lib/traits.d.ts +10 -6
  60. package/package.json +2 -7
  61. package/dist/types/Compiler.d.ts +0 -39
  62. package/dist/types/CompilerError.d.ts +0 -33
  63. package/dist/types/Scope.d.ts +0 -24
  64. package/dist/types/assertions.d.ts +0 -28
  65. package/dist/types/bin.d.ts +0 -1
  66. package/dist/types/handlers/BlockStatement.d.ts +0 -2
  67. package/dist/types/handlers/CallExpression.d.ts +0 -4
  68. package/dist/types/handlers/File.d.ts +0 -2
  69. package/dist/types/handlers/ForStatement.d.ts +0 -2
  70. package/dist/types/handlers/Function.d.ts +0 -5
  71. package/dist/types/handlers/Identifier.d.ts +0 -2
  72. package/dist/types/handlers/IfStatement.d.ts +0 -2
  73. package/dist/types/handlers/Literal.d.ts +0 -5
  74. package/dist/types/handlers/Object.d.ts +0 -6
  75. package/dist/types/handlers/OperationExpressions.d.ts +0 -8
  76. package/dist/types/handlers/Program.d.ts +0 -2
  77. package/dist/types/handlers/Statements.d.ts +0 -5
  78. package/dist/types/handlers/SwitchStatement.d.ts +0 -2
  79. package/dist/types/handlers/TemplateExpression.d.ts +0 -2
  80. package/dist/types/handlers/Typescript.d.ts +0 -7
  81. package/dist/types/handlers/VariableDeclaration.d.ts +0 -3
  82. package/dist/types/handlers/WhileStatement.d.ts +0 -3
  83. package/dist/types/handlers/index.d.ts +0 -17
  84. package/dist/types/index.d.ts +0 -3
  85. package/dist/types/initScope.d.ts +0 -5
  86. package/dist/types/instructions/AddressResolver.d.ts +0 -12
  87. package/dist/types/instructions/ControlInstructions.d.ts +0 -10
  88. package/dist/types/instructions/EndInstruction.d.ts +0 -4
  89. package/dist/types/instructions/InstructionBase.d.ts +0 -14
  90. package/dist/types/instructions/JumpInstruction.d.ts +0 -16
  91. package/dist/types/instructions/OperationInstruction.d.ts +0 -5
  92. package/dist/types/instructions/SetCounterInstruction.d.ts +0 -5
  93. package/dist/types/instructions/SetInstruction.d.ts +0 -6
  94. package/dist/types/instructions/ZeroSpaceInstruction.d.ts +0 -4
  95. package/dist/types/instructions/index.d.ts +0 -9
  96. package/dist/types/macros/Asm.d.ts +0 -5
  97. package/dist/types/macros/Function.d.ts +0 -13
  98. package/dist/types/macros/GetGlobal.d.ts +0 -5
  99. package/dist/types/macros/Math.d.ts +0 -5
  100. package/dist/types/macros/Memory.d.ts +0 -5
  101. package/dist/types/macros/Namespace.d.ts +0 -13
  102. package/dist/types/macros/Other.d.ts +0 -5
  103. package/dist/types/macros/commands/ApplyStatus.d.ts +0 -5
  104. package/dist/types/macros/commands/Control.d.ts +0 -5
  105. package/dist/types/macros/commands/Cutscene.d.ts +0 -5
  106. package/dist/types/macros/commands/Draw.d.ts +0 -5
  107. package/dist/types/macros/commands/DrawFlush.d.ts +0 -5
  108. package/dist/types/macros/commands/End.d.ts +0 -5
  109. package/dist/types/macros/commands/Explosion.d.ts +0 -5
  110. package/dist/types/macros/commands/Fetch.d.ts +0 -5
  111. package/dist/types/macros/commands/FlushMessage.d.ts +0 -5
  112. package/dist/types/macros/commands/GetBlock.d.ts +0 -5
  113. package/dist/types/macros/commands/GetFlag.d.ts +0 -5
  114. package/dist/types/macros/commands/GetLink.d.ts +0 -5
  115. package/dist/types/macros/commands/Lookup.d.ts +0 -5
  116. package/dist/types/macros/commands/PackColor.d.ts +0 -5
  117. package/dist/types/macros/commands/Print.d.ts +0 -5
  118. package/dist/types/macros/commands/PrintFlush.d.ts +0 -5
  119. package/dist/types/macros/commands/Radar.d.ts +0 -7
  120. package/dist/types/macros/commands/Sensor.d.ts +0 -5
  121. package/dist/types/macros/commands/SetBlock.d.ts +0 -5
  122. package/dist/types/macros/commands/SetFlag.d.ts +0 -5
  123. package/dist/types/macros/commands/SetRate.d.ts +0 -5
  124. package/dist/types/macros/commands/SetRule.d.ts +0 -5
  125. package/dist/types/macros/commands/SpawnUnit.d.ts +0 -5
  126. package/dist/types/macros/commands/SpawnWave.d.ts +0 -5
  127. package/dist/types/macros/commands/Stop.d.ts +0 -5
  128. package/dist/types/macros/commands/UnitBind.d.ts +0 -5
  129. package/dist/types/macros/commands/UnitControl.d.ts +0 -5
  130. package/dist/types/macros/commands/UnitLocate.d.ts +0 -5
  131. package/dist/types/macros/commands/UnitRadar.d.ts +0 -5
  132. package/dist/types/macros/commands/Wait.d.ts +0 -5
  133. package/dist/types/macros/commands/index.d.ts +0 -30
  134. package/dist/types/macros/index.d.ts +0 -6
  135. package/dist/types/macros/util.d.ts +0 -18
  136. package/dist/types/operators.d.ts +0 -25
  137. package/dist/types/types.d.ts +0 -238
  138. package/dist/types/utils.d.ts +0 -47
  139. package/dist/types/values/BaseValue.d.ts +0 -9
  140. package/dist/types/values/DestructuringValue.d.ts +0 -17
  141. package/dist/types/values/FunctionValue.d.ts +0 -47
  142. package/dist/types/values/LiteralValue.d.ts +0 -13
  143. package/dist/types/values/ObjectValue.d.ts +0 -23
  144. package/dist/types/values/SenseableValue.d.ts +0 -23
  145. package/dist/types/values/StoreValue.d.ts +0 -15
  146. package/dist/types/values/ValueOwner.d.ts +0 -27
  147. package/dist/types/values/VoidValue.d.ts +0 -16
  148. package/dist/types/values/index.d.ts +0 -7
@@ -1,5 +0,0 @@
1
- import { MacroFunction } from "..";
2
- import { IScope } from "../../types";
3
- export declare class Sensor extends MacroFunction {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { ObjectValue } from "../../values";
3
- export declare class SetBlock extends ObjectValue {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { MacroFunction } from "../Function";
3
- export declare class SetFlag extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { MacroFunction } from "../Function";
3
- export declare class SetRate extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { ObjectValue } from "../../values";
3
- export declare class SetRule extends ObjectValue {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { MacroFunction } from "../Function";
3
- export declare class SpawnUnit extends MacroFunction {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { MacroFunction } from "../Function";
3
- export declare class SpawnWave extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { MacroFunction } from "../Function";
3
- export declare class Stop extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { MacroFunction } from "..";
2
- import { IScope } from "../../types";
3
- export declare class UnitBind extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { ObjectValue } from "../../values";
3
- export declare class UnitControl extends ObjectValue {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { IScope } from "../../types";
2
- import { ObjectValue } from "../../values";
3
- export declare class UnitLocate extends ObjectValue {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { MacroFunction } from "..";
2
- import { IScope } from "../../types";
3
- export declare class UnitRadar extends MacroFunction {
4
- constructor(scope: IScope);
5
- }
@@ -1,5 +0,0 @@
1
- import { MacroFunction } from "..";
2
- import { IScope } from "../../types";
3
- export declare class Wait extends MacroFunction<null> {
4
- constructor(scope: IScope);
5
- }
@@ -1,30 +0,0 @@
1
- export * from "./Draw";
2
- export * from "./Print";
3
- export * from "./PrintFlush";
4
- export * from "./DrawFlush";
5
- export * from "./GetBlock";
6
- export * from "./GetLink";
7
- export * from "./Control";
8
- export { Radar } from "./Radar";
9
- export * from "./Sensor";
10
- export * from "./Wait";
11
- export * from "./Lookup";
12
- export * from "./PackColor";
13
- export * from "./End";
14
- export * from "./SetBlock";
15
- export * from "./SpawnUnit";
16
- export * from "./Stop";
17
- export * from "./UnitBind";
18
- export * from "./UnitControl";
19
- export * from "./UnitRadar";
20
- export * from "./UnitLocate";
21
- export * from "./ApplyStatus";
22
- export * from "./SpawnWave";
23
- export * from "./SetRule";
24
- export * from "./FlushMessage";
25
- export * from "./Cutscene";
26
- export * from "./Explosion";
27
- export * from "./SetRate";
28
- export * from "./Fetch";
29
- export * from "./GetFlag";
30
- export * from "./SetFlag";
@@ -1,6 +0,0 @@
1
- export * from "./Function";
2
- export * from "./Math";
3
- export * from "./Other";
4
- export * as commands from "./commands";
5
- export * from "./Memory";
6
- export { NamespaceMacro, VarsNamespace } from "./Namespace";
@@ -1,18 +0,0 @@
1
- import { IParameterDescriptor } from "../assertions";
2
- import { IScope, IValue, TValueInstructions } from "../types";
3
- import { MacroFunction } from "./Function";
4
- interface IOverloadNamespaceOptions<K extends string> {
5
- scope: IScope;
6
- overloads: Record<K, {
7
- /**
8
- * Pass the name of the options argument to tell if this overload uses
9
- * named parameters.
10
- */
11
- named?: string;
12
- args: (IParameterDescriptor | string)[];
13
- }>;
14
- handler(overload: K, ...args: (IValue | string)[]): TValueInstructions<IValue | null>;
15
- }
16
- /** Used to create namespaces that contain multiple methods that map into instructions */
17
- export declare function createOverloadNamespace<K extends string>({ scope, overloads, handler, }: IOverloadNamespaceOptions<K>): Record<string, MacroFunction<IValue | null>>;
18
- export {};
@@ -1,25 +0,0 @@
1
- export declare const arithmeticBinaryOperators: readonly ["*", "**", "+", "-", "/", "%"];
2
- export declare const comparisonBinaryOperators: readonly ["!=", "!==", "<", "<=", "==", "===", ">", ">="];
3
- export declare const bitwiseBinaryOperators: readonly ["&", "<<", ">>", ">>>", "^", "|"];
4
- export declare const binaryOperators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in"];
5
- export declare type BinaryOperator = typeof binaryOperators[number];
6
- export declare const logicalOperators: readonly ["&&", "??", "||"];
7
- export declare type LogicalOperator = typeof logicalOperators[number];
8
- export declare const arithmeticAssignmentOperators: readonly ["%=", "&=", "*=", "**=", "+=", "-=", "/="];
9
- export declare const logicalAssignmentOperators: readonly ["&&=", "||="];
10
- export declare const bitwiseAssignmentOperators: readonly ["<<=", ">>=", ">>>=", "^=", "|="];
11
- export declare const assignmentOperators: readonly ["%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "<<=", ">>=", ">>>=", "^=", "|=", "="];
12
- export declare type AssignementOperator = typeof assignmentOperators[number];
13
- export declare const leftRightOperators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "<<=", ">>=", ">>>=", "^=", "|=", "="];
14
- export declare type LeftRightOperator = typeof leftRightOperators[number];
15
- export declare const unaryOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~"];
16
- export declare type UnaryOperator = typeof unaryOperators[number];
17
- export declare const updateOperators: readonly ["++", "--"];
18
- export declare type UpdateOperator = typeof updateOperators[number];
19
- export declare const singleOperators: readonly ["!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
20
- export declare type SingleOperator = typeof singleOperators[number];
21
- export declare const operators: readonly ["*", "**", "+", "-", "/", "%", "!=", "!==", "<", "<=", "==", "===", ">", ">=", "&", "<<", ">>", ">>>", "^", "|", "instanceof", "in", "&&", "??", "||", "%=", "&=", "*=", "**=", "+=", "-=", "/=", "&&=", "||=", "<<=", ">>=", ">>>=", "^=", "|=", "=", "!", "u+", "u-", "delete", "typeof", "void", "~", "++", "--"];
22
- export declare type Operator = typeof operators[number];
23
- export declare const operatorMap: {
24
- [k in Exclude<BinaryOperator, "instanceof" | "in"> | Exclude<LogicalOperator, "??">]: string;
25
- };
@@ -1,238 +0,0 @@
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
- export interface IInstruction {
14
- intent: EInstIntent;
15
- hidden: boolean;
16
- resolve(i: number): void;
17
- source?: es.SourceLocation;
18
- /**
19
- * Helps analyzing control flow, handlers should
20
- * indicate which instructions returned are guaranteed to run
21
- */
22
- alwaysRuns: boolean;
23
- }
24
- export declare type THandler<T extends IValue | null = IValue> = (compiler: Compiler, scope: IScope, node: any, arg: any) => TValueInstructions<T>;
25
- /**
26
- * The scope manages the source code generated variables and their owners,
27
- * as well as break and continue statements and they also work as function
28
- * bodies.
29
- */
30
- export interface IScope {
31
- /** Every scope except the top level one has a parent */
32
- parent: IScope | null;
33
- /** The registry of variables contained by this scope */
34
- data: Record<string, IValueOwner | null>;
35
- name: string;
36
- /**
37
- * Additional instructions required by this scope, such as
38
- * the instructions that make the body of a function
39
- */
40
- inst: IInstruction[];
41
- /** Where to jump to on a break statement */
42
- break: AddressResolver;
43
- /** Where to jump to on a continue statement */
44
- continue: AddressResolver;
45
- /** The function linked to `this`, is `null` when the scope is not inside a function. */
46
- function: IFunctionValue;
47
- /** Counts the number of temp variables generated during compilaton */
48
- ntemp: number;
49
- /**
50
- * Creates a new scope that has `this` as it's parent.
51
- */
52
- createScope(): IScope;
53
- /**
54
- * Creates a new scope to be used by a function value, the scope has the following properties:
55
- * - uses `name` as it's primary name, it changes how variable names are formatted.
56
- * - it has `this` as it's parent
57
- * - independent variable registry
58
- * @param name The name of the scope
59
- * @param stacked
60
- */
61
- createFunction(name: string, stacked?: boolean): IScope;
62
- /** Checks if there is an owner registered with the specified identifier */
63
- has(identifier: string): boolean;
64
- /** Gets a value by their owner's identifier */
65
- get(identifier: string): IOwnedValue;
66
- /**
67
- * Registers `value` with an owner that uses `name` as both it's name and identifier,
68
- * throws an error if there already is an owner with the same identitifer.
69
- * @param name
70
- * @param value
71
- */
72
- set<T extends IValue>(name: string, value: T): T;
73
- /**
74
- * Registers `owner` and it's inner value, throws an error
75
- * if there already is an owner with the same identifier.
76
- */
77
- set<T extends IValue>(owner: IValueOwner<T>): T;
78
- /**
79
- * Registers `value` with an owner that uses `name` as both it's name and identifier,
80
- * overriding any preexisting variables with the same identifier.
81
- * @param name
82
- * @param value
83
- */
84
- hardSet<T extends IValue>(name: string, value: T): T;
85
- /**
86
- * Registers `owner` and it's inner value, overriding
87
- * any preexisting variables with the same identifier.
88
- * @param owner
89
- */
90
- hardSet<T extends IValue>(owner: IValueOwner<T>): T;
91
- /**
92
- * Creates an owned store and registers it to this scope.
93
- * @param identifier The name of the variable that will hold the store
94
- * @param name The mlog name that the owner will have
95
- */
96
- make(identifier: string, name: string): IValue;
97
- /**
98
- * Creates a shallow copy of this scope.
99
- *
100
- * Be aware that since the copy is shallow, changes on object fields (except `data`)
101
- * reflect on the original scope. Note that changes to the children of data also follow this rule.
102
- */
103
- copy(): IScope;
104
- /** Creates a temporary mlog variable name */
105
- makeTempName(): string;
106
- }
107
- /**
108
- * Owners track how variables will behave when it comes to their usage.
109
- *
110
- * As an example, Stores use their owners to determine what to do during
111
- * assignments, like making a compile time alias, moving the values or generating
112
- * a `set` instruction.
113
- */
114
- export interface IValueOwner<T extends IValue = IValue> {
115
- scope: IScope;
116
- constant: boolean;
117
- value: T;
118
- /** The name of the variable on the source code that generated this value owner */
119
- identifier?: string;
120
- /** The name this owner has in it's mlog representation */
121
- name: string;
122
- /** Whether this owner is temporary or persistent */
123
- persistent: boolean;
124
- /** Set of values owned by this, can be used to get the owned value count */
125
- owned: Set<T>;
126
- /** Adds `target` to the {@link owned set of owned values} and sets its owner to `this` */
127
- own(target: T): void;
128
- /** Replaces the currently held value by `target` */
129
- replace(target: T): void;
130
- /** Moves all values owned by `this` into `owner` */
131
- moveInto(owner: IValueOwner<T>): void;
132
- }
133
- export interface IValueOperators {
134
- "!"(scope: IScope): TValueInstructions;
135
- "u+"(scope: IScope): TValueInstructions;
136
- "u-"(scope: IScope): TValueInstructions;
137
- "delete"(scope: IScope): TValueInstructions;
138
- "typeof"(scope: IScope): TValueInstructions;
139
- "void"(scope: IScope): TValueInstructions;
140
- "~"(scope: IScope): TValueInstructions;
141
- "++"(scope: IScope, prefix: boolean): TValueInstructions;
142
- "--"(scope: IScope, prefix: boolean): TValueInstructions;
143
- "*"(scope: IScope, value: IValue): TValueInstructions;
144
- "**"(scope: IScope, value: IValue): 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
- instanceof(scope: IScope, value: IValue): TValueInstructions;
164
- in(scope: IScope, value: IValue): TValueInstructions;
165
- "&&"(scope: IScope, value: IValue): TValueInstructions;
166
- "??"(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
- }
184
- /** Defines the possible types of mutability of a value */
185
- export declare enum EMutability {
186
- /**
187
- * The value can be changed by the user's code,
188
- * by the mlog runtime, or us
189
- */
190
- mutable = 0,
191
- /**
192
- * The value cannot be directly assigned,
193
- * but it's still not safe from mutations coming from the runtime.
194
- */
195
- readonly = 1,
196
- /** Constant values, won't change during execution */
197
- constant = 2
198
- }
199
- export interface IValue extends IValueOperators {
200
- owner: IValueOwner | null;
201
- scope: IScope;
202
- mutability: EMutability;
203
- macro: boolean;
204
- /**
205
- * Evaluates `this`, returning it's representation in a more basic
206
- * value like `StoreValue` with the instructions required to compute that value
207
- */
208
- eval(scope: IScope): TValueInstructions;
209
- /**
210
- * Does the same thing as {@link IValue.eval eval}, but ensures that the resulting value has an owner.
211
- *
212
- * This behaviour is required when dealing with temporary values inside expressions like comparations.
213
- */
214
- consume(scope: IScope): TValueInstructions;
215
- call(scope: IScope, args: IValue[]): TValueInstructions<IValue | null>;
216
- get(scope: IScope, name: IValue): TValueInstructions;
217
- ensureOwned(): asserts this is IOwnedValue;
218
- }
219
- /** Helper type that is used in some typescript assertions */
220
- export interface IOwnedValue extends IValue {
221
- owner: Exclude<IValue["owner"], null>;
222
- }
223
- export declare type TLiteral = string | number;
224
- export interface IBindableValue extends IValue {
225
- data: TLiteral;
226
- }
227
- export interface IFunctionValue extends IValue {
228
- return(scope: IScope, argument: IValue | null): TValueInstructions<IValue | null>;
229
- }
230
- /** Contains a value and the instructions required to compute it */
231
- export declare type TValueInstructions<Content extends IValue | null = IValue> = [
232
- Content,
233
- IInstruction[]
234
- ];
235
- /** Map of overridable operators in object macros */
236
- export declare type TOperatorMacroMap = {
237
- [K in UnaryOperator | UpdateOperator | LeftRightOperator as `$${K}`]?: MacroFunction;
238
- };
@@ -1,47 +0,0 @@
1
- import { es, IValue, TValueInstructions } from "./types";
2
- import { IObjectValueData, LiteralValue, ObjectValue } from "./values";
3
- /**
4
- * The prefix for internal variables inside the compiler output
5
- */
6
- export declare const internalPrefix = "&";
7
- export declare const discardedName: string;
8
- /**
9
- * Returns a string that has the format: [line]:[column].
10
- *
11
- * If `name` is provided, and it is a string, the resulting string will
12
- * have the format: [name]:[line]:[column].
13
- */
14
- export declare function nodeName(node: es.Node, name?: false | string): string;
15
- /**
16
- * Converts a camel case string into a dash case one.
17
- *
18
- * As an example `camelCase` becomes `camel-case`
19
- * @example
20
- * ```
21
- * camelToDashCase("camelCase") // returns "camel-case"
22
- * ```
23
- */
24
- export declare function camelToDashCase(name: string): string;
25
- export declare const itemNames: string[];
26
- /**
27
- * A more type safe version of `Object.assign`
28
- */
29
- export declare function assign<T extends {}>(obj: T, props: {
30
- [K in keyof T as T[K] extends Function ? never : K]?: T[K];
31
- }): T;
32
- export declare function appendSourceLocations<T extends IValue | null>(valueInst: TValueInstructions<T>, node: es.Node): TValueInstructions<T>;
33
- export declare function withAlwaysRuns<T extends IValue | null>(valueInst: TValueInstructions<T>, value: boolean): TValueInstructions<T>;
34
- export declare function isTemplateObjectArray(value: IValue): value is ObjectValue & {
35
- data: IObjectValueData & {
36
- raw: ObjectValue & {
37
- data: IObjectValueData & {
38
- length: LiteralValue & {
39
- data: number;
40
- };
41
- };
42
- };
43
- length: LiteralValue & {
44
- data: number;
45
- };
46
- };
47
- };
@@ -1,9 +0,0 @@
1
- import { IOwnedValue, IScope, IValue, TValueInstructions } from "../types";
2
- import { VoidValue } from ".";
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
- ensureOwned(): asserts this is IOwnedValue;
9
- }
@@ -1,17 +0,0 @@
1
- import { IScope, IValue, TValueInstructions } from "../types";
2
- import { VoidValue } from "./VoidValue";
3
- /**
4
- * Specific case class, required on the ArrayPattern and ObjectPattern handlers
5
- * in order to keep the separation of concerns and make the code more modular.
6
- *
7
- * When it is assign a value, it will get it's own properties and recursively assign
8
- * each of them to their counterparts on the right hand value.
9
- */
10
- export declare class DestructuringValue extends VoidValue {
11
- members: Map<IValue, IValue>;
12
- macro: boolean;
13
- constructor(scope: IScope, members: Map<IValue, IValue>);
14
- "="(scope: IScope, right: IValue): TValueInstructions;
15
- eval(_scope: IScope): TValueInstructions<IValue>;
16
- consume(_scope: IScope): TValueInstructions<IValue>;
17
- }
@@ -1,47 +0,0 @@
1
- import { Compiler } from "../Compiler";
2
- import { EMutability, es, IFunctionValue, IScope, IValue, TValueInstructions } from "../types";
3
- import { StoreValue } from "./StoreValue";
4
- import { VoidValue } from "./VoidValue";
5
- export declare type TFunctionValueInitParams = (childScope: IScope) => {
6
- paramStores: StoreValue[];
7
- paramNames: string[];
8
- };
9
- export declare class FunctionValue extends VoidValue implements IFunctionValue {
10
- mutability: EMutability;
11
- macro: boolean;
12
- private node;
13
- private childScope;
14
- private params;
15
- private paramOwners;
16
- private inst;
17
- private addr;
18
- private temp;
19
- private ret;
20
- private inline;
21
- private tryingInline;
22
- private body;
23
- private c;
24
- private callSize;
25
- private inlineTemp;
26
- private inlineEnd?;
27
- private bundled;
28
- private initialized;
29
- constructor({ scope, params, body, c, node, }: {
30
- scope: IScope;
31
- body: es.BlockStatement;
32
- c: Compiler;
33
- node: es.Function;
34
- params: es.Identifier[];
35
- });
36
- typeof(scope: IScope): TValueInstructions;
37
- private initScope;
38
- private ensureInit;
39
- private normalReturn;
40
- private normalCall;
41
- private inlineReturn;
42
- private inlineCall;
43
- call(scope: IScope, args: IValue[]): TValueInstructions;
44
- return(scope: IScope, arg: IValue | null): TValueInstructions<IValue | null>;
45
- eval(_scope: IScope): TValueInstructions;
46
- consume(_scope: IScope): TValueInstructions;
47
- }
@@ -1,13 +0,0 @@
1
- import { IScope, IBindableValue, TLiteral, TValueInstructions, IValue, EMutability } from "../types";
2
- import { BaseValue } from ".";
3
- export declare class LiteralValue extends BaseValue implements IBindableValue {
4
- data: TLiteral;
5
- mutability: EMutability;
6
- constructor(scope: IScope, data: TLiteral);
7
- eval(_scope: IScope): TValueInstructions;
8
- consume(_scope: IScope): TValueInstructions;
9
- toString(): string;
10
- get(scope: IScope, name: IValue): TValueInstructions;
11
- get num(): number;
12
- typeof(scope: IScope): TValueInstructions;
13
- }
@@ -1,23 +0,0 @@
1
- import { MacroFunction } from "../macros";
2
- import { EMutability, IOwnedValue, IScope, IValue, TOperatorMacroMap, TValueInstructions } from "../types";
3
- import { LiteralValue } from "./LiteralValue";
4
- import { VoidValue } from "./VoidValue";
5
- export interface IObjectValueData extends TOperatorMacroMap {
6
- [k: string]: IValue | undefined;
7
- $get?: MacroFunction<IValue>;
8
- $eval?: MacroFunction<IValue>;
9
- $consume?: MacroFunction<IValue>;
10
- }
11
- export declare class ObjectValue extends VoidValue {
12
- mutability: EMutability;
13
- macro: boolean;
14
- data: IObjectValueData;
15
- constructor(scope: IScope, data?: IObjectValueData);
16
- static fromArray(scope: IScope, items: IObjectValueData[keyof IObjectValueData][], intialData?: IObjectValueData): ObjectValue;
17
- typeof(scope: IScope): 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;
23
- }
@@ -1,23 +0,0 @@
1
- import { EMutability, IScope, IValue, TValueInstructions } from "../types";
2
- import { StoreValue } from "./StoreValue";
3
- /**
4
- * Senseable values are "objects" in the mlog runtime that
5
- * have special properties that can be accessed
6
- * via the `sense` instruction.
7
- *
8
- * This class extends `StoreValue` to allow dynamic behavior
9
- * that is not possible with object macros.
10
- *
11
- * Note that these values are constant by default, so make sure
12
- * to set that field to `false` if you want them to be assignable. Example:
13
- * ```
14
- * const value = assign(new SenseableValue(scope), {
15
- * mutability: EMutability.mutable
16
- * })
17
- * ```
18
- */
19
- export declare class SenseableValue extends StoreValue {
20
- mutability: EMutability;
21
- constructor(scope: IScope);
22
- get(scope: IScope, prop: IValue): TValueInstructions<IValue>;
23
- }
@@ -1,15 +0,0 @@
1
- import { BaseValue } from ".";
2
- import { EMutability, IScope, IValue, TValueInstructions } from "../types";
3
- /**
4
- * `StoreValue` represents values unknown at compile time,
5
- * mostly used with mutable variables and temporary values
6
- */
7
- export declare class StoreValue extends BaseValue implements IValue {
8
- mutability: EMutability;
9
- constructor(scope: IScope);
10
- typeof(scope: IScope): TValueInstructions;
11
- "="(scope: IScope, value: IValue): TValueInstructions;
12
- eval(_scope: IScope): TValueInstructions;
13
- consume(_scope: IScope): TValueInstructions;
14
- toString(): string;
15
- }
@@ -1,27 +0,0 @@
1
- import { IScope, IValue, IValueOwner } from "../types";
2
- export interface IValueOwnerParams<T extends IValue> {
3
- scope: IScope;
4
- constant?: boolean;
5
- value: T;
6
- /** The identifier of the variable that `this` represents */
7
- identifier?: string;
8
- /** The name that the variable will have during transpilation to mlog */
9
- name?: string;
10
- }
11
- export declare class ValueOwner<T extends IValue = IValue> implements IValueOwner<T> {
12
- scope: IScope;
13
- constant: boolean;
14
- value: T;
15
- owned: Set<T>;
16
- identifier?: string;
17
- name: string;
18
- persistent: boolean;
19
- /**
20
- * Creates a new `ValueOwner`, if `value` is already owned,
21
- * `this` will be aliased to `value`, else `this` will own `value`
22
- */
23
- constructor({ scope, constant, value, identifier, name, }: IValueOwnerParams<T>);
24
- own(target: T): void;
25
- replace(target: T): void;
26
- moveInto(owner: IValueOwner<T>): void;
27
- }