forked from Matway/mpl-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable.mpl
executable file
·1541 lines (1371 loc) · 39.5 KB
/
variable.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"variable" module
"HashTable" includeModule
"String" includeModule
"Variant" includeModule
"Owner" includeModule
"irWriter" includeModule
"debugWriter" includeModule
"processor" includeModule
Dirty: [0n8 dynamic];
Dynamic: [1n8 dynamic];
Weak: [2n8 dynamic];
Static: [3n8 dynamic];
Virtual: [4n8 dynamic];
Schema: [5n8 dynamic];
NameCaseInvalid: [ 0n8 dynamic];
NameCaseBuiltin: [ 1n8 dynamic];
NameCaseLocal: [ 2n8 dynamic];
NameCaseFromModule: [ 3n8 dynamic];
NameCaseCapture: [ 4n8 dynamic];
NameCaseSelfMember: [ 5n8 dynamic];
NameCaseClosureMember: [ 6n8 dynamic];
NameCaseSelfObject: [ 7n8 dynamic];
NameCaseClosureObject: [ 8n8 dynamic];
NameCaseSelfObjectCapture: [ 9n8 dynamic];
NameCaseClosureObjectCapture: [10n8 dynamic];
MemberCaseToObjectCase: [2n8 +];
MemberCaseToObjectCaptureCase: [4n8 +];
ShadowReasonNo: [0n8 dynamic];
ShadowReasonCapture: [1n8 dynamic];
ShadowReasonInput: [2n8 dynamic];
ShadowReasonField: [3n8 dynamic];
ShadowReasonPointee: [4n8 dynamic];
RefToVar: [{
virtual REF_TO_VAR: ();
varId: -1 dynamic;
hostId: -1 dynamic;
mutable: TRUE dynamic;
}];
=: ["REF_TO_VAR" has] [
refsAreEqual
] pfunc;
hash: ["REF_TO_VAR" has] [
refToVar:;
refToVar.hostId 0n32 cast 67n32 * refToVar.varId 0n32 cast 17n32 * +
] pfunc;
=: ["CODE_NODE_INFO" has] [
l:r:;;
l.index r.index =
] pfunc;
NameInfoEntry: [{
refToVar: RefToVar;
startPoint: -1 dynamic; # id of node
nameCase: NameCaseInvalid;
index: -1 dynamic; # for NameCaseSelfMember
}];
Overload: [NameInfoEntry Array];
makeNameInfo: [{
name: copy;
stack: Overload Array;
}];
NameInfo: [String makeNameInfo];
VarInvalid: [ 0 static];
VarCond: [ 1 static];
VarNat8: [ 2 static];
VarNat16: [ 3 static];
VarNat32: [ 4 static];
VarNat64: [ 5 static];
VarNatX: [ 6 static];
VarInt8: [ 7 static];
VarInt16: [ 8 static];
VarInt32: [ 9 static];
VarInt64: [10 static];
VarIntX: [11 static];
VarReal32: [12 static];
VarReal64: [13 static];
VarCode: [14 static];
VarBuiltin: [15 static];
VarImport: [16 static];
VarString: [17 static];
VarRef: [18 static];
VarStruct: [19 static];
VarEnd: [20 static];
Field: [{
nameInfo: -1 dynamic; # NameInfo id
nameOverload: -1 dynamic;
refToVar: RefToVar;
}];
FieldArray: [Field Array];
Struct: [{
fullVirtual: FALSE dynamic;
homogeneous: FALSE dynamic;
hasPreField: FALSE dynamic;
unableToDie: FALSE dynamic;
hasDestructor: FALSE dynamic;
forgotten: TRUE dynamic;
realFieldIndexes: Int32 Array;
fields: FieldArray;
structStorageSize: 0nx dynamic;
structAlignment: 0nx dynamic;
}]; #IDs of pointee vars
CodeNodeInfo: [{
CODE_NODE_INFO: ();
moduleId: Int32;
offset: Int32;
line: Int32;
column: Int32;
index: Int32;
}];
Variable: [{
VARIABLE: ();
mplNameId: -1 dynamic;
irNameId: -1 dynamic;
mplTypeId: -1 dynamic;
irTypeId: -1 dynamic;
dbgTypeId: -1 dynamic;
storageStaticness: Static;
staticness: Static;
global: FALSE dynamic;
temporary: TRUE dynamic;
usedInHeader: FALSE dynamic;
capturedAsMutable: FALSE dynamic;
capturedAsRealValue: FALSE dynamic;
tref: TRUE dynamic;
shadowReason: ShadowReasonNo;
globalId: -1 dynamic;
shadowBegin: RefToVar;
shadowEnd: RefToVar;
capturedHead: RefToVar;
capturedTail: RefToVar;
capturedPrev: RefToVar;
realValue: RefToVar;
globalDeclarationInstructionIndex: -1 dynamic;
allocationInstructionIndex: -1 dynamic;
getInstructionIndex: -1 dynamic;
data: (
Nat8 #VarInvalid
Cond #VarCond
Nat64 #VarNat8
Nat64 #VarNat16
Nat64 #VarNat32
Nat64 #VarNat64
Nat64 #VarNatX
Int64 #VarInt8
Int64 #VarInt16
Int64 #VarInt32
Int64 #VarInt64
Int64 #VarIntX
Real64 #VarReal32
Real64 #VarReal64
CodeNodeInfo #VarCode; id of node
Int32 #VarBuiltin
Int32 #VarImport
String #VarString
RefToVar #VarRef
Struct Owner #VarStruct
) Variant;
INIT: [];
DIE: [];
}];
compilable: [processorResult.success copy];
callBuiltin: [multiParserResult @currentNode indexOfNode @processor @processorResult callBuiltinImpl];
processFuncPtr: [multiParserResult @currentNode indexOfNode @processor @processorResult processFuncPtrImpl];
processPre: [multiParserResult @currentNode indexOfNode @processor @processorResult processPreImpl];
processCall: [multiParserResult @currentNode indexOfNode @processor @processorResult processCallImpl];
processExportFunction: [multiParserResult @currentNode indexOfNode @processor @processorResult processExportFunctionImpl];
processImportFunction: [multiParserResult @currentNode indexOfNode @processor @processorResult processImportFunctionImpl];
compareEntriesRec: [currentMatchingNodeIndex @nestedToCur @curToNested @comparingMessage multiParserResult @currentNode indexOfNode @processor @processorResult compareEntriesRecImpl];
makeVariableType: [multiParserResult @currentNode indexOfNode @processor @processorResult makeVariableTypeImpl];
compilerError: [makeStringView multiParserResult @currentNode indexOfNode @processor @processorResult compilerErrorImpl];
{
signature: CFunctionSignature Cref;
compilerPositionInfo: CompilerPositionInfo Cref;
multiParserResult: MultiParserResult Cref;
indexArray: IndexArray Cref;
processor: Processor Ref;
processorResult: ProcessorResult Ref;
nodeCase: NodeCaseCode;
parentIndex: 0;
functionName: StringView Cref;
} 0 {convention: cdecl;} "astNodeToCodeNode" importFunction
{
signature: CFunctionSignature Cref;
compilerPositionInfo: CompilerPositionInfo Cref;
multiParserResult: MultiParserResult Cref;
processor: Processor Ref;
processorResult: ProcessorResult Ref;
refToVar: RefToVar Cref;
} () {convention: cdecl;} "createDtorForGlobalVar" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
positionInfo: CompilerPositionInfo Cref;
name: StringView Cref;
nodeCase: NodeCaseCode;
indexArray: IndexArray Cref;
} () {convention: cdecl;} "processCallByIndexArrayImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
index: Int32;
} () {convention: cdecl;} "callBuiltinImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
refToVar: RefToVar Cref;
} () {convention: cdecl;} "processFuncPtrImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
preAstNodeIndex: Int32;
} Cond {convention: cdecl;} "processPreImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
name: StringView Cref;
callAstNodeIndex: Int32;
} () {convention: cdecl;} "processCallImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
asLambda: Cond;
name: StringView Cref;
astNode: AstNode Cref;
signature: CFunctionSignature Cref;
} Int32 {convention: cdecl;} "processExportFunctionImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
asCodeRef: Cond;
name: StringView Cref;
signature: CFunctionSignature Cref;
} Int32 {convention: cdecl;} "processImportFunctionImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
comparingMessage: String Ref;
curToNested: RefToVarTable Ref;
nestedToCur: RefToVarTable Ref;
currentMatchingNodeIndex: Int32;
cacheEntry: RefToVar Cref;
stackEntry: RefToVar Cref;
} Cond {convention: cdecl;} "compareEntriesRecImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
refToVar: RefToVar Cref;
} () {convention: cdecl;} "makeVariableTypeImpl" importFunction
{
forMatching: Cond;
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
result: RefToVar Ref;
} () {convention: cdecl;} "popImpl" importFunction
{
dynamicStoraged: Cond;
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
reason: Nat8;
end: RefToVar Ref;
begin: RefToVar Ref;
refToVar: RefToVar Cref;
} () {convention: cdecl;} "makeShadowsImpl" importFunction
{
processorResult: ProcessorResult Ref;
processor: Processor Ref;
indexOfNode: Int32;
currentNode: CodeNode Ref;
multiParserResult: MultiParserResult Cref;
message: StringView Cref;
} () {convention: cdecl;} "compilerErrorImpl" importFunction
# these functions require capture "processor"
variableIsDeleted: [
refToVar:;
refToVar.varId refToVar.hostId @[email protected][email protected] not
];
getVar: [
refToVar:;
[
refToVar.hostId 0 < not [refToVar.hostId processor.nodes.dataSize <] && [
node: refToVar.hostId @[email protected];
sz: node.variables.dataSize copy;
refToVar.varId 0 < not [refToVar.varId sz <] && [
refToVar.varId node.variables.at.assigned [
TRUE
] [
("deleted var data=" refToVar.hostId ":" refToVar.varId) addLog
FALSE
] if
] [
("invalid var id=" refToVar.varId " of " sz) addLog
FALSE
] if
] [
("invalid host id=" refToVar.hostId " of " processor.nodes.dataSize) addLog
FALSE
] if
] "Wrong refToVar!" assert
refToVar.varId refToVar.hostId @[email protected][email protected]
];
getNameById: [processor.nameBuffer.at makeStringView];
getMplName: [getVar.mplNameId processor.nameInfos.at.name makeStringView];
getIrName: [getVar.irNameId getNameById];
getMplType: [getVar.mplTypeId getNameById];
getIrType: [getVar.irTypeId getNameById];
getDbgType: [getVar.dbgTypeId getNameById];
getDebugType: [
dbgType: getDbgType;
splitted: dbgType.split;
splitted.success [
splitted.chars.getSize 1024 > [
1024 @[email protected]
"..." makeStringView @[email protected]
] when
] [
("Wrong dbgType name encoding" splitted.chars assembleString) assembleString compilerError
] if
result: (dbgType hash ".") assembleString;
splitted.chars @result.catMany
@result
];
deepPrintVar: [
refToVar:;
hasLogs [
unprinted: (RefToVar 0) Array;
(refToVar 0) @unprinted.pushBack
[
unprinted.dataSize 0 > [
current: unprinted.last deref;
curRef: 0n32 current @;
curPad: 1n32 current @;
@unprinted.popBack
curVar: curRef getVar;
curPad [" " stringMemory print] times
("ref is " makeStringView curRef.hostId 0 cast ":" makeStringView curRef.varId 0 cast "; tag=" makeStringView curVar.data.getTag 0 cast) printList printLF
curVar.data.getTag VarRef = [
(VarRef curVar.data.get curPad 1 +) @unprinted.pushBack
] [
curVar.data.getTag VarStruct = [
struct: VarStruct curVar.data.get.get;
f: 0 dynamic;
[
f struct.fields.dataSize < [
(f struct.fields.at.refToVar curPad 1 +) @unprinted.pushBack
f 1 + @f set TRUE
] &&
] loop
] when
] if
TRUE
] &&
] loop
] when
];
staticnessOfVar: [
refToVar:;
var: refToVar getVar;
var.staticness copy
];
maxStaticness: [
copy s1:;
copy s2:;
s1 s2 > [s1 copy][s2 copy] if
];
refsAreEqual: [
refToVar1:;
refToVar2:;
refToVar1.hostId refToVar2.hostId = [refToVar1.varId refToVar2.varId =] &&
];
variablesAreSame: [
refToVar1:;
refToVar2:;
refToVar1 getVar.mplTypeId refToVar2 getVar.mplTypeId = # id compare better than string compare!
];
isInt: [
var: getVar;
var.data.getTag VarInt8 =
[var.data.getTag VarInt16 =] ||
[var.data.getTag VarInt32 =] ||
[var.data.getTag VarInt64 =] ||
[var.data.getTag VarIntX =] ||
];
isNat: [
var: getVar;
var.data.getTag VarNat8 =
[var.data.getTag VarNat16 =] ||
[var.data.getTag VarNat32 =] ||
[var.data.getTag VarNat64 =] ||
[var.data.getTag VarNatX =] ||
];
isAnyInt: [
refToVar:;
refToVar isInt
[refToVar isNat] ||
];
isReal: [
var: getVar;
var.data.getTag VarReal32 =
[var.data.getTag VarReal64 =] ||
];
isNumber: [
refToVar:;
refToVar isReal
[refToVar isAnyInt] ||
];
isPlain: [
refToVar:;
refToVar isNumber [
var: refToVar getVar;
var.data.getTag VarCond =
] ||
];
isTinyArg: [
refToVar:;
refToVar isPlain [
var: refToVar getVar;
var.data.getTag VarRef =
] ||
];
isUnallocable: [
var: getVar;
var.data.getTag VarString =
[var.data.getTag VarImport =] ||
];
isStruct: [
var: getVar;
var.data.getTag VarStruct =
];
isAutoStruct: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarStruct =
[VarStruct var.data.get.get.hasDestructor copy] &&
];
markAsUnableToDie: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarStruct = [TRUE VarStruct @[email protected].@unableToDie set] when
];
markAsAbleToDie: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarStruct = [FALSE VarStruct @[email protected].@unableToDie set] when
];
isSingle: [
isStruct not
];
isStaticData: [
refToVar:;
var: refToVar getVar;
refToVar isVirtual not [var.data.getTag VarStruct =] && [
unfinished: RefToVar Array;
refToVar @unfinished.pushBack
result: TRUE dynamic;
[
result [unfinished.getSize 0 >] && [
current: unfinished.last copy;
@unfinished.popBack
current isVirtual [
] [
current isPlain [
current staticnessOfVar Weak < [
FALSE dynamic @result set
] when
] [
curVar: current getVar;
curVar.data.getTag VarStruct = [
struct: VarStruct curVar.data.get.get;
struct.fields [.value.refToVar @unfinished.pushBack] each
] [
FALSE dynamic @result set
] if
] if
] if
TRUE
] &&
] loop
result
] [
FALSE
] if
];
getSingleDataStorageSize: [
var: getVar;
var.data.getTag (
VarCond [1nx]
VarInt8 [1nx]
VarInt16 [2nx]
VarInt32 [4nx]
VarInt64 [8nx]
VarIntX [processor.options.pointerSize 8nx /]
VarNat8 [1nx]
VarNat16 [2nx]
VarNat32 [4nx]
VarNat64 [8nx]
VarNatX [processor.options.pointerSize 8nx /]
VarReal32 [4nx]
VarReal64 [8nx]
VarRef [processor.options.pointerSize 8nx /]
VarString [
"strings dont have storageSize and alignment" compilerError
0nx
]
VarImport [
"functions dont have storageSize and alignment" compilerError
0nx
]
[0nx]
) case
];
isNonrecursiveType: [
refToVar:;
refToVar isPlain [
var: refToVar getVar;
var.data.getTag VarString =
[var.data.getTag VarCode =] ||
[var.data.getTag VarBuiltin =] ||
[var.data.getTag VarImport =] ||
] ||
];
isSemiplainNonrecursiveType: [
refToVar:;
refToVar isPlain [
var: refToVar getVar;
var.data.getTag VarCode =
[var.data.getTag VarBuiltin =] ||
[var.data.getTag VarImport =] ||
] ||
];
getPlainDataIRType: [
var: getVar;
result: String;
var.data.getTag (
VarCond ["i1" toString @result set]
VarInt8 ["i8" toString @result set]
VarInt16 ["i16" toString @result set]
VarInt32 ["i32" toString @result set]
VarInt64 ["i64" toString @result set]
VarIntX [
processor.options.pointerSize 64nx = [
"i64" toString @result set
] [
"i32" toString @result set
] if
]
VarNat8 ["i8" toString @result set]
VarNat16 ["i16" toString @result set]
VarNat32 ["i32" toString @result set]
VarNat64 ["i64" toString @result set]
VarNatX [
processor.options.pointerSize 64nx = [
"i64" toString @result set
] [
"i32" toString @result set
] if
]
VarReal32 ["float" toString @result set]
VarReal64 ["double" toString @result set]
[
("Tag = " var.data.getTag) addLog
[FALSE] "Unknown plain struct while getting IR type" assert
]
) case
@result
];
getPlainDataMPLType: [
compileOnce
var: getVar;
result: String;
var.data.getTag (
VarCond ["i1" toString @result set]
VarInt8 ["i8" toString @result set]
VarInt16 ["i16" toString @result set]
VarInt32 ["i32" toString @result set]
VarInt64 ["i64" toString @result set]
VarIntX ["ix" toString @result set]
VarNat8 ["n8" toString @result set]
VarNat16 ["n16" toString @result set]
VarNat32 ["n32" toString @result set]
VarNat64 ["n64" toString @result set]
VarNatX ["nx" toString @result set]
VarReal32 ["r32" toString @result set]
VarReal64 ["r64" toString @result set]
[
("Tag = " var.data.getTag) addLog
[FALSE] "Unknown plain struct MPL type" assert
]
) case
@result
];
getNonrecursiveDataIRType: [
compileOnce
refToVar:;
refToVar isPlain [
refToVar getPlainDataIRType
] [
result: String;
var: refToVar getVar;
var.data.getTag VarString = [
"i8" toString @result set
] [
var.data.getTag VarImport = [
VarImport var.data.get getFuncIrType toString @result set
] [
var.data.getTag VarCode = [var.data.getTag VarBuiltin =] || [
"ERROR" toString @result set
] [
"Unknown nonrecursive struct" makeStringView compilerError
] if
] if
] if
@result
] if
];
getNonrecursiveDataMPLType: [
compileOnce
refToVar:;
refToVar isPlain [
refToVar getPlainDataMPLType
] [
result: String;
var: refToVar getVar;
var.data.getTag VarString = [
"s" toString @result set
] [
var.data.getTag VarCode = [
"c" toString @result set
] [
var.data.getTag VarBuiltin = [
"b" toString @result set
] [
var.data.getTag VarImport = [
("F" VarImport var.data.get getFuncMplType) assembleString @result set
] [
"Unknown nonrecursive struct" makeStringView compilerError
] if
] if
] if
] if
@result
] if
];
getNonrecursiveDataDBGType: [
compileOnce
refToVar:;
refToVar isPlain [
refToVar getPlainDataMPLType
] [
result: String;
var: refToVar getVar;
var.data.getTag VarString = [
"s" toString @result set
] [
var.data.getTag VarCode = [
"c" toString @result set
] [
var.data.getTag VarBuiltin = [
"b" toString @result set
] [
var.data.getTag VarImport = [
("F" VarImport var.data.get getFuncDbgType) assembleString @result set
] [
"Unknown nonrecursive struct" makeStringView compilerError
] if
] if
] if
] if
@result
] if
];
getStructStorageSize: [
refToVar:;
var: refToVar getVar;
struct: VarStruct var.data.get.get;
struct.structStorageSize copy
];
makeStructStorageSize: [
refToVar:;
result: 0nx;
var: refToVar getVar;
struct: VarStruct @[email protected];
maxA: 1nx;
j: 0;
[
j struct.fields.dataSize < [
curField: j struct.fields.at;
curField.refToVar isVirtual not [
curS: curField.refToVar getStorageSize;
curA: curField.refToVar getAlignment;
result
curA + 1nx - curA 1nx - not and
curS +
@result set
curA maxA > [curA @maxA set] when
] when
j 1 + @j set TRUE
] &&
] loop
result
maxA + 1nx - maxA 1nx - not and
@result set
result @struct.@structStorageSize set
];
getStorageSize: [
refToVar:;
refToVar isSingle [
refToVar getSingleDataStorageSize
] [
refToVar getStructStorageSize
] if
];
getStructAlignment: [
refToVar:;
var: refToVar getVar;
struct: VarStruct var.data.get.get;
struct.structAlignment copy
];
makeStructAlignment: [
refToVar:;
result: 0nx;
var: refToVar getVar;
struct: VarStruct @[email protected];
j: 0;
[
j struct.fields.dataSize < [
curField: j struct.fields.at;
curField.refToVar isVirtual not [
curA: curField.refToVar getAlignment;
result curA < [curA @result set] when
] when
j 1 + @j set TRUE
] &&
] loop
result @struct.@structAlignment set
];
getAlignment: [
refToVar:;
refToVar isSingle [
refToVar getSingleDataStorageSize
] [
refToVar getStructAlignment
] if
];
isGlobal: [
refToVar:;
var: refToVar getVar;
var.global copy
];
unglobalize: [
refToVar:;
var: refToVar getVar;
var.global [
FALSE @var.@global set
-1 dynamic @var.@globalId set
refToVar makeVariableIRName
] when
];
untemporize: [
refToVar:;
var: refToVar getVar;
FALSE @var.@temporary set
];
fullUntemporize: [
refToVar:;
var: refToVar getVar;
FALSE @var.@temporary set
var.data.getTag VarStruct = [
FALSE VarStruct @[email protected].@forgotten set
] when
];
isSchema: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarRef = [var.staticness Schema =] &&
];
isVirtualType: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarBuiltin =
[var.data.getTag VarCode =] ||
[var.data.getTag VarStruct = [VarStruct var.data.get.get.fullVirtual copy] &&] ||
[refToVar isSchema] ||
];
isVirtual: [
refToVar:;
var: refToVar getVar;
var.staticness Virtual < not
[refToVar isVirtualType] ||
];
noMatterToCopy: [
refToVar:;
refToVar isVirtual [refToVar isAutoStruct not] &&
];
isVirtualField: [
refToVar:;
var: refToVar getVar;
var.staticness Virtual < not
[refToVar isVirtualType] ||
];
isForgotten: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarStruct = [
VarStruct var.data.get.get.forgotten copy
] [
FALSE
] if
];
getVirtualValue: [
refToVar:;
recursive
var: refToVar getVar;
result: String;
var.data.getTag (
VarStruct [
"{" @result.cat
struct: VarStruct var.data.get.get;
struct.fields [
pair:;
pair.index 0 > ["," @result.cat] when
pair.value.refToVar isVirtualField not [
pair.value.refToVar getVirtualValue @result.cat
] when
] each
"}" @result.cat
]
VarCode [
info: VarCode var.data.get;
("\"" info.moduleId processor.options.fileNames.at getStringImplementation "\"/" info.line ":" info.column) @result.catMany
]
VarBuiltin [VarBuiltin var.data.get @result.cat]
VarRef [
pointee: VarRef var.data.get;
pointeeVar: pointee getVar;
var.staticness Schema = [
"." @result.cat
] [
pointeeVar.data.getTag (
VarString [
string: VarString pointeeVar.data.get;
(string textSize "_" string getStringImplementation) @result.catMany
]
VarImport [VarImport pointeeVar.data.get @result.cat]
[[FALSE] "Wrong type for virtual reference!" assert]
) case
] if
]
[
refToVar isPlain [
refToVar getPlainConstantIR @result.cat
] [
("Tag = " var.data.getTag) addLog
[FALSE] "Wrong type for virtual value!" assert
] if
]
) case
result
];
makeStringId: [
string:;
fr: string @[email protected];