forked from Matway/mpl-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.mpl
executable file
·340 lines (289 loc) · 9.56 KB
/
processor.mpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
"processor" module
"control" includeModule
"astNodeType" includeModule
CompilerPositionInfo: [{
column: -1 dynamic;
line: -1 dynamic;
offset: -1 dynamic;
fileNumber: 0 dynamic;
token: String;
}];
StringArray: [String Array];
ProcessorOptions: [{
mainPath: String;
fileNames: StringArray;
pointerSize: 64nx dynamic;
staticLiterals: TRUE dynamic;
debug: TRUE dynamic;
arrayChecks: TRUE dynamic;
autoRecursion: FALSE dynamic;
logs: FALSE dynamic;
verboseIR: FALSE dynamic;
callTrace: FALSE dynamic;
threadModel: 0 dynamic;
linkerOptions: String Array;
}];
ProcessorErrorInfo: [{
message: String;
missedModule: String;
position: CompilerPositionInfo Array;
}];
ProcessorResult: [{
success: TRUE dynamic;
findModuleFail: FALSE dynamic;
maxDepthExceeded: FALSE dynamic;
program: String;
errorInfo: ProcessorErrorInfo;
globalErrorInfo: ProcessorErrorInfo Array;
}];
makeInstruction: [{
enabled: TRUE dynamic;
alloca: FALSE dynamic;
fakePointer: FALSE dynamic;
code: copy;
}];
Instruction: [String makeInstruction];
ArgVirtual: [0n8 dynamic];
ArgGlobal: [1n8 dynamic];
ArgRef: [2n8 dynamic];
ArgCopy: [3n8 dynamic];
ArgReturn: [4n8 dynamic];
ArgRefDeref: [5n8 dynamic];
ArgReturnDeref: [6n8 dynamic];
Argument: [{
refToVar: RefToVar;
argCase: ArgRef;
}];
Capture: [{
refToVar: RefToVar;
argCase: ArgRef;
captureCase: NameCaseInvalid;
nameInfo: -1 dynamic;
nameOverload: -1 dynamic;
cntNameOverload: -1 dynamic;
cntNameOverloadParent: -1 dynamic;
}];
FieldCapture: [{
object: RefToVar;
capturingPoint: -1 dynamic; #index of code node where it was
captureCase: NameCaseInvalid;
nameInfo: -1 dynamic;
nameOverload: -1 dynamic;
cntNameOverload: -1 dynamic;
cntNameOverloadParent: -1 dynamic;
}];
IndexInfo: [{
overload: -1 dynamic;
index: -1 dynamic;
}];
IndexInfoArray: [IndexInfo Array];
NodeCaseEmpty: [0n8 dynamic];
NodeCaseCode: [1n8 dynamic];
NodeCaseDtor: [2n8 dynamic];
NodeCaseDeclaration: [3n8 dynamic];
NodeCaseDllDeclaration: [4n8 dynamic];
NodeCaseCodeRefDeclaration: [5n8 dynamic];
NodeCaseExport: [6n8 dynamic];
NodeCaseLambda: [7n8 dynamic];
NodeCaseList: [8n8 dynamic];
NodeCaseObject: [9n8 dynamic];
NodeStateNew: [0n8 dynamic];
NodeStateNoOutput: [1n8 dynamic]; #after calling NodeStateNew recursion with unknown output, node is uncompilable
NodeStateHasOutput: [2n8 dynamic]; #after merging "if" with output and without output, node can be compiled
NodeStateCompiled: [3n8 dynamic]; #node finished
NodeStateFailed: [4n8 dynamic]; #node finished
NodeRecursionStateNo: [0n8 dynamic];
NodeRecursionStateFail: [1n8 dynamic];
NodeRecursionStateNew: [2n8 dynamic];
NodeRecursionStateOld: [3n8 dynamic];
NodeRecursionStateFailDone: [4n8 dynamic];
CaptureNameResult: [{
refToVar: RefToVar;
object: RefToVar;
}];
NameWithOverload: [{
virtual NAME_WITH_OVERLOAD: ();
nameInfo: -1 dynamic;
nameOverload: -1 dynamic;
}];
NameWithOverloadAndRefToVar: [{
virtual NAME_WITH_OVERLOAD_AND_REF_TO_VAR: ();
nameInfo: -1 dynamic;
nameOverload: -1 dynamic;
cntNameOverload: -1 dynamic;
cntNameOverloadParent: -1 dynamic;
refToVar: RefToVar;
startPoint: -1 dynamic;
}];
=: ["NAME_WITH_OVERLOAD" has] [
n1:; n2:;
n1.nameInfo n2.nameInfo = n1.nameOverload n2.nameOverload = and
] pfunc;
hash: ["NAME_WITH_OVERLOAD" has] [
nameWithOverload:;
nameWithOverload.nameInfo 67n32 * nameWithOverload.nameOverload 17n32 * +
] pfunc;
RefToVarTable: [
RefToVar RefToVar HashTable
];
NameTable: [
elementConstructor:;
NameWithOverload @elementConstructor HashTable
];
IntTable: [Int32 Int32 HashTable];
MatchingInfo: [{
inputs: Argument Array;
preInputs: RefToVar Array;
captures: Capture Array;
fieldCaptures: FieldCapture Array;
hasStackUnderflow: FALSE dynamic;
unfoundedNames: Int32 Cond HashTable; #nameInfos
}];
CFunctionSignature: [{
inputs: RefToVar Array;
outputs: RefToVar Array;
variadic: FALSE dynamic;
convention: String;
}];
UsedModuleInfo: [{
used: FALSE dynamic;
position: CompilerPositionInfo;
}];
CodeNode: [{
root: FALSE dynamic;
parent: 0 dynamic;
nodeCase: NodeCaseCode;
position: CompilerPositionInfo;
stack: RefToVar Array; # we must compile node without touching parent
minStackDepth: 0 dynamic;
program: Instruction Array;
aliases: String Array;
variables: Variable Owner Array; # as unique_ptr...
lastLambdaName: Int32;
nextRecLambdaId: -1 dynamic;
nodeIsRecursive: FALSE dynamic;
nextLabelIsVirtual: FALSE dynamic;
nextLabelIsSchema: FALSE dynamic;
nextLabelIsConst: FALSE dynamic;
recursionState: NodeRecursionStateNo;
state: NodeStateNew;
struct: Struct;
irName: String;
header: String;
argTypes: String;
csignature: CFunctionSignature;
convention: String;
mplConvention: String;
signature: String;
nodeCompileOnce: FALSE dynamic;
empty: FALSE dynamic;
deleted: FALSE dynamic;
emptyDeclaration: FALSE dynamic;
uncompilable: FALSE dynamic;
variadic: FALSE dynamic;
hasNestedCall: FALSE dynamic;
countOfUCall: 0 dynamic;
declarationRefs: Cond Array;
buildingMatchingInfo: MatchingInfo;
matchingInfo: MatchingInfo;
outputs: Argument Array;
fromModuleNames: NameWithOverloadAndRefToVar Array;
labelNames: NameWithOverloadAndRefToVar Array;
captureNames: NameWithOverloadAndRefToVar Array;
fieldCaptureNames: NameWithOverloadAndRefToVar Array;
captureTable: RefToVar Cond HashTable;
fieldCaptureTable: RefToVar Cond HashTable;
candidatesToDie: RefToVar Array;
unprocessedAstNodes: IndexArray;
moduleName: String;
includedModules: Int32 Array; #ids in order
directlyIncludedModulesTable: Int32 Cond HashTable; # dont include twice plz
includedModulesTable: Int32 UsedModuleInfo HashTable; # dont include twice plz
usedModulesTable: Int32 UsedModuleInfo HashTable; # moduleID, hasUsedVars
usedOrIncludedModulesTable: Int32 Cond HashTable; # moduleID, hasUsedVars
refToVar: RefToVar; #refToVar of function with compiled node
varNameInfo: -1 dynamic; #variable name of imported function
moduleId: -1 dynamic;
indexArrayAddress: 0nx dynamic;
matchingInfoIndex: -1 dynamic;
exportDepth: 0 dynamic;
namedFunctions: String Int32 HashTable; # name -> node ID
capturedVars: RefToVar Array;
funcDbgIndex: -1 dynamic;
lastVarName: 0 dynamic;
lastBrLabelName: 0 dynamic;
variableCountDelta: 0 dynamic;
INIT: [];
DIE: [];
}];
MatchingNode: [{
unknownMplType: IndexArray;
byMplType: Int32 IndexArray HashTable; #first input MPL type
compilerPositionInfo: CompilerPositionInfo;
entries: Int32;
tries: Int32;
size: Int32;
}];
Processor: [{
options: ProcessorOptions;
nodes: CodeNode Owner Array;
matchingNodes: Natx MatchingNode HashTable;
recursiveNodesStack: Int32 Array;
nameInfos: NameInfo Array;
modules: String Int32 HashTable; # -1 no module, or Id of codeNode
nameToId: String Int32 HashTable; # id of nameInfo from parser
emptyNameInfo: -1 dynamic;
callNameInfo: -1 dynamic;
preNameInfo: -1 dynamic;
dieNameInfo: -1 dynamic;
initNameInfo: -1 dynamic;
assignNameInfo: -1 dynamic;
selfNameInfo: -1 dynamic;
closureNameInfo: -1 dynamic;
inputsNameInfo: -1 dynamic;
outputsNameInfo: -1 dynamic;
capturesNameInfo: -1 dynamic;
variadicNameInfo: -1 dynamic;
failProcNameInfo: -1 dynamic;
conventionNameInfo: -1 dynamic;
funcAliasCount: 0 dynamic;
globalVarCount: 0 dynamic;
globalVarId: 0 dynamic;
globalInitializer: -1 dynamic; # index of func for calling all initializers
globalDestructibleVars: RefToVar Array;
exportDepth: 0 dynamic;
stringNames: String RefToVar HashTable; #for string constants
typeNames: String Int32 HashTable; #mplType->irAliasId
nameBuffer: String Array;
nameTable: StringView Int32 HashTable; #strings->nameTag; strings from nameBuffer
depthOfRecursion: 0 dynamic;
maxDepthOfRecursion: 0 dynamic;
depthOfPre: 0 dynamic;
prolog: String Array;
debugInfo: {
strings: String Array;
locationIds: IntTable;
lastId: 0 dynamic;
unit: -1 dynamic;
unitStringNumber: -1 dynamic;
cuStringNumber: -1 dynamic;
fileNameIds: Int32 Array;
typeIdToDbgId: IntTable;
globals: Int32 Array;
};
lastStringId: 0 dynamic;
lastTypeId: 0 dynamic;
unitId: 0 dynamic; # number of compiling unit
namedFunctions: String Int32 HashTable; # name -> node ID
moduleFunctions: Int32 Array;
dtorFunctions: Int32 Array;
varCount: 0 dynamic;
structureVarCount: 0 dynamic;
fieldVarCount: 0 dynamic;
nodeCount: 0 dynamic;
deletedNodeCount: 0 dynamic;
deletedVarCount: 0 dynamic;
usedFloatBuiltins: FALSE dynamic;
INIT: [];
DIE: [];
}];