@minduscript/compiler 1.0.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.
- package/.npmignore +2 -0
- package/dist/asm/gen-asm.d.ts +2 -0
- package/dist/asm/gen-asm.js +432 -0
- package/dist/counter.d.ts +5 -0
- package/dist/counter.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/ir/build-ir.d.ts +3 -0
- package/dist/ir/build-ir.js +1057 -0
- package/dist/ir/gather-macros.d.ts +8 -0
- package/dist/ir/gather-macros.js +204 -0
- package/dist/ir/ir.d.ts +478 -0
- package/dist/ir/ir.js +120 -0
- package/dist/ir/project.d.ts +24 -0
- package/dist/ir/project.js +339 -0
- package/dist/ir/symbol-table.d.ts +19 -0
- package/dist/ir/symbol-table.js +385 -0
- package/dist/macro/check-macro.d.ts +14 -0
- package/dist/macro/check-macro.js +136 -0
- package/dist/macro/expand-macros.d.ts +6 -0
- package/dist/macro/expand-macros.js +285 -0
- package/dist/optimizer/default-passes.d.ts +2 -0
- package/dist/optimizer/default-passes.js +20 -0
- package/dist/optimizer/merge-labels.d.ts +2 -0
- package/dist/optimizer/merge-labels.js +45 -0
- package/dist/optimizer/optimizer.d.ts +4 -0
- package/dist/optimizer/optimizer.js +26 -0
- package/dist/optimizer/passes/constant-folding.d.ts +2 -0
- package/dist/optimizer/passes/constant-folding.js +160 -0
- package/dist/optimizer/passes/control-flow.d.ts +5 -0
- package/dist/optimizer/passes/control-flow.js +138 -0
- package/dist/optimizer/passes/copy-propagation.d.ts +2 -0
- package/dist/optimizer/passes/copy-propagation.js +127 -0
- package/dist/optimizer/passes/dead-code.d.ts +2 -0
- package/dist/optimizer/passes/dead-code.js +200 -0
- package/dist/optimizer/passes/merge-labels-pass.d.ts +2 -0
- package/dist/optimizer/passes/merge-labels-pass.js +14 -0
- package/dist/optimizer/types.d.ts +10 -0
- package/dist/optimizer/types.js +3 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +14 -0
- package/package.json +22 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Project } from './project';
|
|
2
|
+
export type MacroName = {
|
|
3
|
+
name: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
};
|
|
6
|
+
export type MacroNameMap = Record<string, Record<string, MacroName>>;
|
|
7
|
+
declare const gatherMacros: (project: Project) => MacroNameMap;
|
|
8
|
+
export { gatherMacros };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.gatherMacros = void 0;
|
|
7
|
+
const counter_1 = require("../counter");
|
|
8
|
+
const parser_1 = require("@minduscript/parser");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const gatherMacros = (project) => {
|
|
11
|
+
counter_1.counter.reset();
|
|
12
|
+
const nameMap = {};
|
|
13
|
+
const entrySource = project.sources[project.entryPath];
|
|
14
|
+
if (!entrySource) {
|
|
15
|
+
return nameMap;
|
|
16
|
+
}
|
|
17
|
+
const ensureSourceMap = (sourcePath) => {
|
|
18
|
+
if (!nameMap[sourcePath]) {
|
|
19
|
+
nameMap[sourcePath] = {};
|
|
20
|
+
}
|
|
21
|
+
return nameMap[sourcePath];
|
|
22
|
+
};
|
|
23
|
+
const resolveSourcePath = (fromPath, importerPath) => {
|
|
24
|
+
const basePath = path_1.default.dirname(importerPath);
|
|
25
|
+
const candidate = path_1.default.isAbsolute(fromPath)
|
|
26
|
+
? fromPath
|
|
27
|
+
: fromPath.startsWith('.')
|
|
28
|
+
? path_1.default.resolve(basePath, fromPath)
|
|
29
|
+
: path_1.default.resolve(project.rootPath, fromPath);
|
|
30
|
+
const normalized = path_1.default.normalize(candidate);
|
|
31
|
+
const candidates = path_1.default.extname(normalized) ? [normalized] : [normalized, `${normalized}.minduscript`];
|
|
32
|
+
for (const sourcePath of candidates) {
|
|
33
|
+
if (project.sources[sourcePath]) {
|
|
34
|
+
return sourcePath;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
const sourceContextMap = new Map();
|
|
40
|
+
const getSourceContext = (sourcePath) => {
|
|
41
|
+
const existing = sourceContextMap.get(sourcePath);
|
|
42
|
+
if (existing) {
|
|
43
|
+
return existing;
|
|
44
|
+
}
|
|
45
|
+
const source = project.sources[sourcePath];
|
|
46
|
+
const context = {
|
|
47
|
+
localMacroMap: new Map(),
|
|
48
|
+
importMacroMap: new Map(),
|
|
49
|
+
};
|
|
50
|
+
if (source) {
|
|
51
|
+
for (const statement of source.ast.statementList) {
|
|
52
|
+
if (statement.statementType !== parser_1.StatementType.MACRO_DEFINE) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
context.localMacroMap.set(statement.name, statement);
|
|
56
|
+
}
|
|
57
|
+
for (const importStatement of source.ast.importList) {
|
|
58
|
+
const importedSourcePath = resolveSourcePath(importStatement.from, sourcePath);
|
|
59
|
+
if (!importedSourcePath) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
context.importMacroMap.set(importStatement.asName, {
|
|
63
|
+
sourcePath: importedSourcePath,
|
|
64
|
+
macroName: importStatement.name,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
sourceContextMap.set(sourcePath, context);
|
|
69
|
+
return context;
|
|
70
|
+
};
|
|
71
|
+
const resolveMacroDefinition = (sourcePath, macroName, aliasChain = []) => {
|
|
72
|
+
const nextAliasChain = [...aliasChain, { sourcePath, macroName }];
|
|
73
|
+
const sourceContext = getSourceContext(sourcePath);
|
|
74
|
+
const localMacro = sourceContext.localMacroMap.get(macroName);
|
|
75
|
+
if (localMacro) {
|
|
76
|
+
return {
|
|
77
|
+
sourcePath,
|
|
78
|
+
macroName,
|
|
79
|
+
macro: localMacro,
|
|
80
|
+
aliases: nextAliasChain,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const imported = sourceContext.importMacroMap.get(macroName);
|
|
84
|
+
if (!imported) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return resolveMacroDefinition(imported.sourcePath, imported.macroName, nextAliasChain);
|
|
88
|
+
};
|
|
89
|
+
const collectMacroCallsFromExpressionChild = (child, output) => {
|
|
90
|
+
switch (child.type) {
|
|
91
|
+
case parser_1.NodeType.UNARY_OP_EXPRESSION:
|
|
92
|
+
collectMacroCallsFromExpressionChild(child.child, output);
|
|
93
|
+
break;
|
|
94
|
+
case parser_1.NodeType.BINARY_OP_EXPRESSION:
|
|
95
|
+
collectMacroCallsFromExpressionChild(child.lChild, output);
|
|
96
|
+
collectMacroCallsFromExpressionChild(child.rChild, output);
|
|
97
|
+
break;
|
|
98
|
+
case parser_1.NodeType.FUNCTION_CALL_EXPRESSION:
|
|
99
|
+
child.args.forEach((arg) => collectMacroCallsFromExpressionChild(arg, output));
|
|
100
|
+
break;
|
|
101
|
+
case parser_1.NodeType.MACRO_CALL_EXPRESSION:
|
|
102
|
+
output.push(child.name);
|
|
103
|
+
child.inputArgs.forEach((arg) => collectMacroCallsFromExpressionChild(arg, output));
|
|
104
|
+
break;
|
|
105
|
+
case parser_1.NodeType.LITERAL_EXPRESSION:
|
|
106
|
+
case parser_1.NodeType.IDENTIFIER_EXPRESSION:
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
child;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const collectMacroCallsFromExpression = (expression, output) => {
|
|
113
|
+
collectMacroCallsFromExpressionChild(expression.child, output);
|
|
114
|
+
};
|
|
115
|
+
const collectMacroCallsFromStatement = (statement, output) => {
|
|
116
|
+
switch (statement.statementType) {
|
|
117
|
+
case parser_1.StatementType.EMPTY:
|
|
118
|
+
case parser_1.StatementType.LOOP_CONTROL:
|
|
119
|
+
case parser_1.StatementType.BIND:
|
|
120
|
+
break;
|
|
121
|
+
case parser_1.StatementType.VARIABLE_DEFINE:
|
|
122
|
+
case parser_1.StatementType.ASSIGN:
|
|
123
|
+
case parser_1.StatementType.RETURN:
|
|
124
|
+
collectMacroCallsFromExpression(statement.expression, output);
|
|
125
|
+
break;
|
|
126
|
+
case parser_1.StatementType.CONTROL:
|
|
127
|
+
for (const value of Object.values(statement)) {
|
|
128
|
+
if (value && typeof value === 'object' && 'type' in value && value.type === parser_1.NodeType.EXPRESSION) {
|
|
129
|
+
collectMacroCallsFromExpression(value, output);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case parser_1.StatementType.MACRO_CALL:
|
|
134
|
+
output.push(statement.name);
|
|
135
|
+
statement.inputArgs.forEach((arg) => collectMacroCallsFromExpression(arg, output));
|
|
136
|
+
break;
|
|
137
|
+
case parser_1.StatementType.MACRO_DEFINE:
|
|
138
|
+
break;
|
|
139
|
+
case parser_1.StatementType.IF:
|
|
140
|
+
collectMacroCallsFromExpression(statement.condition, output);
|
|
141
|
+
statement.ifBody.forEach((child) => collectMacroCallsFromStatement(child, output));
|
|
142
|
+
break;
|
|
143
|
+
case parser_1.StatementType.IF_ELSE:
|
|
144
|
+
collectMacroCallsFromExpression(statement.condition, output);
|
|
145
|
+
statement.ifBody.forEach((child) => collectMacroCallsFromStatement(child, output));
|
|
146
|
+
statement.elseBody.forEach((child) => collectMacroCallsFromStatement(child, output));
|
|
147
|
+
break;
|
|
148
|
+
case parser_1.StatementType.FOR:
|
|
149
|
+
collectMacroCallsFromStatement(statement.init, output);
|
|
150
|
+
collectMacroCallsFromExpression(statement.condition, output);
|
|
151
|
+
if (statement.increment) {
|
|
152
|
+
collectMacroCallsFromStatement(statement.increment, output);
|
|
153
|
+
}
|
|
154
|
+
statement.body.forEach((child) => collectMacroCallsFromStatement(child, output));
|
|
155
|
+
break;
|
|
156
|
+
case parser_1.StatementType.WHILE:
|
|
157
|
+
collectMacroCallsFromExpression(statement.condition, output);
|
|
158
|
+
statement.body.forEach((child) => collectMacroCallsFromStatement(child, output));
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
statement;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const visited = new Set();
|
|
165
|
+
const visiting = new Set();
|
|
166
|
+
const toMacroKey = (sourcePath, macroName) => `${sourcePath}\u0000${macroName}`;
|
|
167
|
+
const visitMacro = (sourcePath, macroName) => {
|
|
168
|
+
const resolved = resolveMacroDefinition(sourcePath, macroName);
|
|
169
|
+
if (!resolved) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const key = toMacroKey(resolved.sourcePath, resolved.macroName);
|
|
173
|
+
if (visited.has(key)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// 递归宏调用在 parseProject 阶段已被校验,这里只做保护以避免异常输入导致死循环。
|
|
177
|
+
if (visiting.has(key)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const existingRenamed = resolved.aliases
|
|
181
|
+
.map((alias) => nameMap[alias.sourcePath]?.[alias.macroName]?.name)
|
|
182
|
+
.find((renamed) => typeof renamed === 'string');
|
|
183
|
+
const renamed = existingRenamed ?? `${counter_1.counter.next()}`;
|
|
184
|
+
for (const alias of resolved.aliases) {
|
|
185
|
+
const sourceMap = ensureSourceMap(alias.sourcePath);
|
|
186
|
+
sourceMap[alias.macroName] = {
|
|
187
|
+
name: renamed,
|
|
188
|
+
filePath: resolved.sourcePath,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
visiting.add(key);
|
|
192
|
+
const calledMacros = [];
|
|
193
|
+
resolved.macro.body.forEach((statement) => collectMacroCallsFromStatement(statement, calledMacros));
|
|
194
|
+
calledMacros.forEach((calledMacroName) => visitMacro(resolved.sourcePath, calledMacroName));
|
|
195
|
+
visiting.delete(key);
|
|
196
|
+
visited.add(key);
|
|
197
|
+
};
|
|
198
|
+
const entryCalls = [];
|
|
199
|
+
entrySource.ast.statementList.forEach((statement) => collectMacroCallsFromStatement(statement, entryCalls));
|
|
200
|
+
entryCalls.forEach((macroName) => visitMacro(project.entryPath, macroName));
|
|
201
|
+
return nameMap;
|
|
202
|
+
};
|
|
203
|
+
exports.gatherMacros = gatherMacros;
|
|
204
|
+
//# sourceMappingURL=gather-macros.js.map
|
package/dist/ir/ir.d.ts
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import type { RadarCondition, RadarSortConfig, UnitLocateBuildingGroup } from '@minduscript/parser';
|
|
2
|
+
export declare enum IRNodeType {
|
|
3
|
+
READ = 0,
|
|
4
|
+
WRITE = 1,
|
|
5
|
+
DRAW_CLEAR = 2,
|
|
6
|
+
DRAW_COLOR = 3,
|
|
7
|
+
DRAW_COL = 4,
|
|
8
|
+
DRAW_STROKE = 5,
|
|
9
|
+
DRAW_LINE = 6,
|
|
10
|
+
DRAW_RECT = 7,
|
|
11
|
+
DRAW_LINE_RECT = 8,
|
|
12
|
+
DRAW_POLY = 9,
|
|
13
|
+
DRAW_LINE_POLY = 10,
|
|
14
|
+
DRAW_TRIANGLE = 11,
|
|
15
|
+
DRAW_IMAGE = 12,
|
|
16
|
+
PRINT = 13,
|
|
17
|
+
DRAW_FLUSH = 14,
|
|
18
|
+
PRINT_FLUSH = 15,
|
|
19
|
+
GET_LINK = 16,
|
|
20
|
+
SET_ENABLED = 17,
|
|
21
|
+
SET_SHOOT = 18,
|
|
22
|
+
SET_SHOOT_P = 19,
|
|
23
|
+
SET_CONFIG = 20,
|
|
24
|
+
SET_COLOR = 21,
|
|
25
|
+
RADAR = 22,
|
|
26
|
+
SENSOR = 23,
|
|
27
|
+
PACK_COLOR = 24,
|
|
28
|
+
WAIT = 25,
|
|
29
|
+
CPU_STOP = 26,
|
|
30
|
+
UNIT_BIND = 27,
|
|
31
|
+
UNIT_RADAR = 28,
|
|
32
|
+
UNIT_LOCATE_ORE = 29,
|
|
33
|
+
UNIT_LOCATE_BUILDING = 30,
|
|
34
|
+
UNIT_LOCATE_SPAWN = 31,
|
|
35
|
+
UNIT_LOCATE_DAMAGED = 32,
|
|
36
|
+
IDLE = 33,
|
|
37
|
+
STOP = 34,
|
|
38
|
+
MOVE = 35,
|
|
39
|
+
APPROACH = 36,
|
|
40
|
+
PATH_FIND = 37,
|
|
41
|
+
AUTO_PATH_FIND = 38,
|
|
42
|
+
BOOST = 39,
|
|
43
|
+
TARGET = 40,
|
|
44
|
+
TARGET_P = 41,
|
|
45
|
+
ITEM_DROP = 42,
|
|
46
|
+
ITEM_TAKE = 43,
|
|
47
|
+
PAY_DROP = 44,
|
|
48
|
+
PAY_TAKE = 45,
|
|
49
|
+
PAY_ENTER = 46,
|
|
50
|
+
MINE = 47,
|
|
51
|
+
FLAG = 48,
|
|
52
|
+
BUILD = 49,
|
|
53
|
+
GET_BLOCK = 50,
|
|
54
|
+
WITHIN = 51,
|
|
55
|
+
UNBIND = 52,
|
|
56
|
+
ASSIGN = 53,
|
|
57
|
+
FLIP = 54,
|
|
58
|
+
AND = 55,
|
|
59
|
+
EQ = 56,
|
|
60
|
+
NE = 57,
|
|
61
|
+
LESS = 58,
|
|
62
|
+
LE = 59,
|
|
63
|
+
GREATER = 60,
|
|
64
|
+
GE = 61,
|
|
65
|
+
STRICT_EQ = 62,
|
|
66
|
+
BITOR = 63,
|
|
67
|
+
XOR = 64,
|
|
68
|
+
BITAND = 65,
|
|
69
|
+
SHL = 66,
|
|
70
|
+
SHR = 67,
|
|
71
|
+
ADD = 68,
|
|
72
|
+
SUB = 69,
|
|
73
|
+
MUL = 70,
|
|
74
|
+
DIV = 71,
|
|
75
|
+
IDIV = 72,
|
|
76
|
+
MOD = 73,
|
|
77
|
+
POW = 74,
|
|
78
|
+
MAX = 75,
|
|
79
|
+
MIN = 76,
|
|
80
|
+
ANGLE = 77,
|
|
81
|
+
ANGLE_DIFF = 78,
|
|
82
|
+
LEN = 79,
|
|
83
|
+
NOISE = 80,
|
|
84
|
+
ABS = 81,
|
|
85
|
+
LOG = 82,
|
|
86
|
+
LOG10 = 83,
|
|
87
|
+
FLOOR = 84,
|
|
88
|
+
CEIL = 85,
|
|
89
|
+
SQRT = 86,
|
|
90
|
+
RAND = 87,
|
|
91
|
+
SIN = 88,
|
|
92
|
+
COS = 89,
|
|
93
|
+
TAN = 90,
|
|
94
|
+
ASIN = 91,
|
|
95
|
+
ACOS = 92,
|
|
96
|
+
ATAN = 93,
|
|
97
|
+
LABEL = 94,
|
|
98
|
+
JUMP = 95,
|
|
99
|
+
CONDITIONAL_JUMP = 96,
|
|
100
|
+
MACRO_CALL = 97,
|
|
101
|
+
MACRO_CALL_ASSIGN = 98,
|
|
102
|
+
BIND = 99
|
|
103
|
+
}
|
|
104
|
+
export type Value = {
|
|
105
|
+
isLiteral: true;
|
|
106
|
+
value: number | string | boolean | null;
|
|
107
|
+
} | {
|
|
108
|
+
isLiteral: false;
|
|
109
|
+
name: string;
|
|
110
|
+
isMindustry: boolean;
|
|
111
|
+
};
|
|
112
|
+
export type ReadNode = {
|
|
113
|
+
type: IRNodeType.READ;
|
|
114
|
+
output: string;
|
|
115
|
+
memoryName: Value;
|
|
116
|
+
memoryIndex: Value;
|
|
117
|
+
};
|
|
118
|
+
export type WriteNode = {
|
|
119
|
+
type: IRNodeType.WRITE;
|
|
120
|
+
value: Value;
|
|
121
|
+
memoryName: Value;
|
|
122
|
+
memoryIndex: Value;
|
|
123
|
+
};
|
|
124
|
+
export type DrawClearNode = {
|
|
125
|
+
type: IRNodeType.DRAW_CLEAR;
|
|
126
|
+
r: Value;
|
|
127
|
+
g: Value;
|
|
128
|
+
b: Value;
|
|
129
|
+
};
|
|
130
|
+
export type DrawColorNode = {
|
|
131
|
+
type: IRNodeType.DRAW_COLOR;
|
|
132
|
+
r: Value;
|
|
133
|
+
g: Value;
|
|
134
|
+
b: Value;
|
|
135
|
+
a: Value;
|
|
136
|
+
};
|
|
137
|
+
export type DrawColNode = {
|
|
138
|
+
type: IRNodeType.DRAW_COL;
|
|
139
|
+
color: Value;
|
|
140
|
+
};
|
|
141
|
+
export type DrawStrokeNode = {
|
|
142
|
+
type: IRNodeType.DRAW_STROKE;
|
|
143
|
+
width: Value;
|
|
144
|
+
};
|
|
145
|
+
export type DrawLineNode = {
|
|
146
|
+
type: IRNodeType.DRAW_LINE;
|
|
147
|
+
x: Value;
|
|
148
|
+
y: Value;
|
|
149
|
+
x2: Value;
|
|
150
|
+
y2: Value;
|
|
151
|
+
};
|
|
152
|
+
export type DrawRectNode = {
|
|
153
|
+
type: IRNodeType.DRAW_RECT;
|
|
154
|
+
x: Value;
|
|
155
|
+
y: Value;
|
|
156
|
+
width: Value;
|
|
157
|
+
height: Value;
|
|
158
|
+
};
|
|
159
|
+
export type DrawLineRectNode = {
|
|
160
|
+
type: IRNodeType.DRAW_LINE_RECT;
|
|
161
|
+
x: Value;
|
|
162
|
+
y: Value;
|
|
163
|
+
width: Value;
|
|
164
|
+
height: Value;
|
|
165
|
+
};
|
|
166
|
+
export type DrawPolyNode = {
|
|
167
|
+
type: IRNodeType.DRAW_POLY;
|
|
168
|
+
x: Value;
|
|
169
|
+
y: Value;
|
|
170
|
+
sides: Value;
|
|
171
|
+
radius: Value;
|
|
172
|
+
rotation: Value;
|
|
173
|
+
};
|
|
174
|
+
export type DrawLinePolyNode = {
|
|
175
|
+
type: IRNodeType.DRAW_LINE_POLY;
|
|
176
|
+
x: Value;
|
|
177
|
+
y: Value;
|
|
178
|
+
sides: Value;
|
|
179
|
+
radius: Value;
|
|
180
|
+
rotation: Value;
|
|
181
|
+
};
|
|
182
|
+
export type DrawTriangleNode = {
|
|
183
|
+
type: IRNodeType.DRAW_TRIANGLE;
|
|
184
|
+
x: Value;
|
|
185
|
+
y: Value;
|
|
186
|
+
x2: Value;
|
|
187
|
+
y2: Value;
|
|
188
|
+
x3: Value;
|
|
189
|
+
y3: Value;
|
|
190
|
+
};
|
|
191
|
+
export type DrawImageNode = {
|
|
192
|
+
type: IRNodeType.DRAW_IMAGE;
|
|
193
|
+
x: Value;
|
|
194
|
+
y: Value;
|
|
195
|
+
image: Value;
|
|
196
|
+
size: Value;
|
|
197
|
+
rotation: Value;
|
|
198
|
+
};
|
|
199
|
+
export type PrintNode = {
|
|
200
|
+
type: IRNodeType.PRINT;
|
|
201
|
+
value: Value;
|
|
202
|
+
};
|
|
203
|
+
export type DrawFlushNode = {
|
|
204
|
+
type: IRNodeType.DRAW_FLUSH;
|
|
205
|
+
target: Value;
|
|
206
|
+
};
|
|
207
|
+
export type PrintFlushNode = {
|
|
208
|
+
type: IRNodeType.PRINT_FLUSH;
|
|
209
|
+
target: Value;
|
|
210
|
+
};
|
|
211
|
+
export type GetLinkNode = {
|
|
212
|
+
type: IRNodeType.GET_LINK;
|
|
213
|
+
result: string;
|
|
214
|
+
id: Value;
|
|
215
|
+
};
|
|
216
|
+
export type SetEnabledNode = {
|
|
217
|
+
type: IRNodeType.SET_ENABLED;
|
|
218
|
+
building: Value;
|
|
219
|
+
enabled: Value;
|
|
220
|
+
};
|
|
221
|
+
export type SetShootNode = {
|
|
222
|
+
type: IRNodeType.SET_SHOOT;
|
|
223
|
+
building: Value;
|
|
224
|
+
x: Value;
|
|
225
|
+
y: Value;
|
|
226
|
+
shoot: Value;
|
|
227
|
+
};
|
|
228
|
+
export type SetShootPNode = {
|
|
229
|
+
type: IRNodeType.SET_SHOOT_P;
|
|
230
|
+
building: Value;
|
|
231
|
+
unit: Value;
|
|
232
|
+
shoot: Value;
|
|
233
|
+
};
|
|
234
|
+
export type SetConfigNode = {
|
|
235
|
+
type: IRNodeType.SET_CONFIG;
|
|
236
|
+
building: Value;
|
|
237
|
+
config: Value;
|
|
238
|
+
};
|
|
239
|
+
export type SetColorNode = {
|
|
240
|
+
type: IRNodeType.SET_COLOR;
|
|
241
|
+
building: Value;
|
|
242
|
+
color: Value;
|
|
243
|
+
};
|
|
244
|
+
export type RadarNode = {
|
|
245
|
+
type: IRNodeType.RADAR;
|
|
246
|
+
building: Value;
|
|
247
|
+
condition1: RadarCondition;
|
|
248
|
+
condition2: RadarCondition;
|
|
249
|
+
condition3: RadarCondition;
|
|
250
|
+
order: Value;
|
|
251
|
+
sort: RadarSortConfig;
|
|
252
|
+
result: string;
|
|
253
|
+
};
|
|
254
|
+
export type SensorNode = {
|
|
255
|
+
type: IRNodeType.SENSOR;
|
|
256
|
+
target: Value;
|
|
257
|
+
building: Value;
|
|
258
|
+
result: string;
|
|
259
|
+
};
|
|
260
|
+
export type PackColorNode = {
|
|
261
|
+
type: IRNodeType.PACK_COLOR;
|
|
262
|
+
result: string;
|
|
263
|
+
r: Value;
|
|
264
|
+
g: Value;
|
|
265
|
+
b: Value;
|
|
266
|
+
a: Value;
|
|
267
|
+
};
|
|
268
|
+
export type WaitNode = {
|
|
269
|
+
type: IRNodeType.WAIT;
|
|
270
|
+
time: Value;
|
|
271
|
+
};
|
|
272
|
+
export type CpuStopNode = {
|
|
273
|
+
type: IRNodeType.CPU_STOP;
|
|
274
|
+
};
|
|
275
|
+
export type UnitBindNode = {
|
|
276
|
+
type: IRNodeType.UNIT_BIND;
|
|
277
|
+
unit: Value;
|
|
278
|
+
};
|
|
279
|
+
export type UnitRadarNode = {
|
|
280
|
+
type: IRNodeType.UNIT_RADAR;
|
|
281
|
+
condition1: RadarCondition;
|
|
282
|
+
condition2: RadarCondition;
|
|
283
|
+
condition3: RadarCondition;
|
|
284
|
+
order: Value;
|
|
285
|
+
sort: RadarSortConfig;
|
|
286
|
+
result: string;
|
|
287
|
+
};
|
|
288
|
+
export type UnitLocateOreNode = {
|
|
289
|
+
type: IRNodeType.UNIT_LOCATE_ORE;
|
|
290
|
+
target: Value;
|
|
291
|
+
outX: string;
|
|
292
|
+
outY: string;
|
|
293
|
+
found: string;
|
|
294
|
+
};
|
|
295
|
+
export type UnitLocateBuildingNode = {
|
|
296
|
+
type: IRNodeType.UNIT_LOCATE_BUILDING;
|
|
297
|
+
group: UnitLocateBuildingGroup;
|
|
298
|
+
enemy: Value;
|
|
299
|
+
outX: string;
|
|
300
|
+
outY: string;
|
|
301
|
+
found: string;
|
|
302
|
+
building: string;
|
|
303
|
+
};
|
|
304
|
+
export type UnitLocateSpawnNode = {
|
|
305
|
+
type: IRNodeType.UNIT_LOCATE_SPAWN;
|
|
306
|
+
outX: string;
|
|
307
|
+
outY: string;
|
|
308
|
+
found: string;
|
|
309
|
+
building: string;
|
|
310
|
+
};
|
|
311
|
+
export type UnitLocateDamagedNode = {
|
|
312
|
+
type: IRNodeType.UNIT_LOCATE_DAMAGED;
|
|
313
|
+
outX: string;
|
|
314
|
+
outY: string;
|
|
315
|
+
found: string;
|
|
316
|
+
building: string;
|
|
317
|
+
};
|
|
318
|
+
export type IdleNode = {
|
|
319
|
+
type: IRNodeType.IDLE;
|
|
320
|
+
};
|
|
321
|
+
export type StopNode = {
|
|
322
|
+
type: IRNodeType.STOP;
|
|
323
|
+
};
|
|
324
|
+
export type MoveNode = {
|
|
325
|
+
type: IRNodeType.MOVE;
|
|
326
|
+
x: Value;
|
|
327
|
+
y: Value;
|
|
328
|
+
};
|
|
329
|
+
export type ApproachNode = {
|
|
330
|
+
type: IRNodeType.APPROACH;
|
|
331
|
+
x: Value;
|
|
332
|
+
y: Value;
|
|
333
|
+
distance: Value;
|
|
334
|
+
};
|
|
335
|
+
export type PathFindNode = {
|
|
336
|
+
type: IRNodeType.PATH_FIND;
|
|
337
|
+
x: Value;
|
|
338
|
+
y: Value;
|
|
339
|
+
};
|
|
340
|
+
export type AutoPathFindNode = {
|
|
341
|
+
type: IRNodeType.AUTO_PATH_FIND;
|
|
342
|
+
};
|
|
343
|
+
export type BoostNode = {
|
|
344
|
+
type: IRNodeType.BOOST;
|
|
345
|
+
enabled: Value;
|
|
346
|
+
};
|
|
347
|
+
export type TargetNode = {
|
|
348
|
+
type: IRNodeType.TARGET;
|
|
349
|
+
x: Value;
|
|
350
|
+
y: Value;
|
|
351
|
+
shoot: Value;
|
|
352
|
+
};
|
|
353
|
+
export type TargetPNode = {
|
|
354
|
+
type: IRNodeType.TARGET_P;
|
|
355
|
+
unit: Value;
|
|
356
|
+
shoot: Value;
|
|
357
|
+
};
|
|
358
|
+
export type ItemDropNode = {
|
|
359
|
+
type: IRNodeType.ITEM_DROP;
|
|
360
|
+
building: Value;
|
|
361
|
+
amount: Value;
|
|
362
|
+
};
|
|
363
|
+
export type ItemTakeNode = {
|
|
364
|
+
type: IRNodeType.ITEM_TAKE;
|
|
365
|
+
building: Value;
|
|
366
|
+
item: Value;
|
|
367
|
+
amount: Value;
|
|
368
|
+
};
|
|
369
|
+
export type PayDropNode = {
|
|
370
|
+
type: IRNodeType.PAY_DROP;
|
|
371
|
+
};
|
|
372
|
+
export type PayTakeNode = {
|
|
373
|
+
type: IRNodeType.PAY_TAKE;
|
|
374
|
+
takeUnits: Value;
|
|
375
|
+
};
|
|
376
|
+
export type PayEnterNode = {
|
|
377
|
+
type: IRNodeType.PAY_ENTER;
|
|
378
|
+
};
|
|
379
|
+
export type MineNode = {
|
|
380
|
+
type: IRNodeType.MINE;
|
|
381
|
+
x: Value;
|
|
382
|
+
y: Value;
|
|
383
|
+
};
|
|
384
|
+
export type FlagNode = {
|
|
385
|
+
type: IRNodeType.FLAG;
|
|
386
|
+
flag: Value;
|
|
387
|
+
};
|
|
388
|
+
export type BuildNode = {
|
|
389
|
+
type: IRNodeType.BUILD;
|
|
390
|
+
x: Value;
|
|
391
|
+
y: Value;
|
|
392
|
+
block: Value;
|
|
393
|
+
rotation: Value;
|
|
394
|
+
config: Value;
|
|
395
|
+
};
|
|
396
|
+
export type GetBlockNode = {
|
|
397
|
+
type: IRNodeType.GET_BLOCK;
|
|
398
|
+
x: Value;
|
|
399
|
+
y: Value;
|
|
400
|
+
outType: string;
|
|
401
|
+
building: string;
|
|
402
|
+
floor: string;
|
|
403
|
+
};
|
|
404
|
+
export type WithinNode = {
|
|
405
|
+
type: IRNodeType.WITHIN;
|
|
406
|
+
x: Value;
|
|
407
|
+
y: Value;
|
|
408
|
+
radius: Value;
|
|
409
|
+
result: string;
|
|
410
|
+
};
|
|
411
|
+
export type UnbindNode = {
|
|
412
|
+
type: IRNodeType.UNBIND;
|
|
413
|
+
};
|
|
414
|
+
export type UnaryOpNode = {
|
|
415
|
+
type: IRNodeType.ASSIGN | IRNodeType.FLIP | IRNodeType.ABS | IRNodeType.LOG | IRNodeType.LOG10 | IRNodeType.FLOOR | IRNodeType.CEIL | IRNodeType.SQRT | IRNodeType.RAND | IRNodeType.SIN | IRNodeType.COS | IRNodeType.TAN | IRNodeType.ASIN | IRNodeType.ACOS | IRNodeType.ATAN;
|
|
416
|
+
target: string;
|
|
417
|
+
value: Value;
|
|
418
|
+
};
|
|
419
|
+
export type BinaryOpNode = {
|
|
420
|
+
type: IRNodeType.AND | IRNodeType.EQ | IRNodeType.NE | IRNodeType.LESS | IRNodeType.LE | IRNodeType.GREATER | IRNodeType.GE | IRNodeType.STRICT_EQ | IRNodeType.BITOR | IRNodeType.XOR | IRNodeType.BITAND | IRNodeType.SHL | IRNodeType.SHR | IRNodeType.ADD | IRNodeType.SUB | IRNodeType.MUL | IRNodeType.DIV | IRNodeType.IDIV | IRNodeType.MOD | IRNodeType.POW | IRNodeType.MAX | IRNodeType.MIN | IRNodeType.ANGLE | IRNodeType.ANGLE_DIFF | IRNodeType.LEN | IRNodeType.NOISE;
|
|
421
|
+
target: string;
|
|
422
|
+
left: Value;
|
|
423
|
+
right: Value;
|
|
424
|
+
};
|
|
425
|
+
export type LabelNode = {
|
|
426
|
+
type: IRNodeType.LABEL;
|
|
427
|
+
name: string;
|
|
428
|
+
};
|
|
429
|
+
export type JumpNode = {
|
|
430
|
+
type: IRNodeType.JUMP;
|
|
431
|
+
label: string;
|
|
432
|
+
};
|
|
433
|
+
export declare enum JumpCondition {
|
|
434
|
+
EQ = 0,
|
|
435
|
+
NE = 1,
|
|
436
|
+
LESS = 2,
|
|
437
|
+
LE = 3,
|
|
438
|
+
GREATER = 4,
|
|
439
|
+
GE = 5,
|
|
440
|
+
STRICT_EQ = 6
|
|
441
|
+
}
|
|
442
|
+
export type ConditionalJumpNode = {
|
|
443
|
+
type: IRNodeType.CONDITIONAL_JUMP;
|
|
444
|
+
condition: JumpCondition;
|
|
445
|
+
left: Value;
|
|
446
|
+
right: Value;
|
|
447
|
+
label: string;
|
|
448
|
+
};
|
|
449
|
+
export type MacroCallNode = {
|
|
450
|
+
type: IRNodeType.MACRO_CALL;
|
|
451
|
+
name: string;
|
|
452
|
+
inputArgs: Value[];
|
|
453
|
+
outputArgs: string[];
|
|
454
|
+
};
|
|
455
|
+
export type MacroCallAssignNode = {
|
|
456
|
+
type: IRNodeType.MACRO_CALL_ASSIGN;
|
|
457
|
+
name: string;
|
|
458
|
+
inputArgs: Value[];
|
|
459
|
+
outputArgs: string[];
|
|
460
|
+
returnTarget: string;
|
|
461
|
+
};
|
|
462
|
+
export type BindNode = {
|
|
463
|
+
type: IRNodeType.BIND;
|
|
464
|
+
name: string;
|
|
465
|
+
};
|
|
466
|
+
export type IRNode = ReadNode | WriteNode | DrawClearNode | DrawColorNode | DrawColNode | DrawStrokeNode | DrawLineNode | DrawRectNode | DrawLineRectNode | DrawPolyNode | DrawLinePolyNode | DrawTriangleNode | DrawImageNode | PrintNode | DrawFlushNode | PrintFlushNode | GetLinkNode | SetEnabledNode | SetShootNode | SetShootPNode | SetConfigNode | SetColorNode | RadarNode | SensorNode | PackColorNode | WaitNode | CpuStopNode | UnitBindNode | UnitRadarNode | UnitLocateOreNode | UnitLocateBuildingNode | UnitLocateSpawnNode | UnitLocateDamagedNode | IdleNode | StopNode | MoveNode | ApproachNode | PathFindNode | AutoPathFindNode | BoostNode | TargetNode | TargetPNode | ItemDropNode | ItemTakeNode | PayDropNode | PayTakeNode | PayEnterNode | MineNode | FlagNode | BuildNode | GetBlockNode | WithinNode | UnbindNode | UnaryOpNode | BinaryOpNode | LabelNode | JumpNode | ConditionalJumpNode | MacroCallNode | MacroCallAssignNode | BindNode;
|
|
467
|
+
export type IRMacro = {
|
|
468
|
+
name: string;
|
|
469
|
+
inputParams: string[];
|
|
470
|
+
outputParams: string[];
|
|
471
|
+
body: IRNode[];
|
|
472
|
+
dependencies: Set<string>;
|
|
473
|
+
};
|
|
474
|
+
export type IRProgram = {
|
|
475
|
+
macros: IRMacro[];
|
|
476
|
+
boundVariables: Set<string>;
|
|
477
|
+
main: IRNode[];
|
|
478
|
+
};
|