forked from Matway/mpl-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeNode.mpl
executable file
·3875 lines (3314 loc) · 114 KB
/
codeNode.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
"codeNode" module
"control" useModule
"staticCall" includeModule
"variable" includeModule
"processor" includeModule
addOverload: [
copy nameInfo:;
nameInfo 0 < not [
currentNameInfo: nameInfo @[email protected];
Overload @[email protected]
currentNameInfo.stack.dataSize 1 -
] [
"bad overload index" makeStringView compilerError
-1
] if
];
getOverloadCount: [
copy nameInfo:;
overloads: nameInfo processor.nameInfos.at.stack;
overloads.getSize
];
addNameInfoWith: [
copy index:;
copy reg:;
copy overload:;
copy startPoint:;
copy addNameCase:;
refToVar:;
copy nameInfo:;
[addNameCase NameCaseFromModule = [refToVar noMatterToCopy] || [refToVar.hostId indexOfNode =] ||] "addNameInfo indexOfNode mismatch!" assert
nameInfo 0 < not [
currentNameInfo: nameInfo @[email protected];
currentNameInfo.stack.dataSize 0 = [
Overload @[email protected] # initialisation of nameInfo
] when
overload 0 < [
currentNameInfo.stack.dataSize 1 - @overload set
] when
addInfo: TRUE;
reg not [addNameCase NameCaseBuiltin =] || [
] [
nameWithOverload: NameWithOverloadAndRefToVar;
refToVar @nameWithOverload.@refToVar set
overload @nameWithOverload.@nameOverload set
nameInfo @nameWithOverload.@nameInfo set
startPoint @nameWithOverload.@startPoint set
addNameCase NameCaseLocal = [
nameWithOverload @[email protected]
] [
addNameCase NameCaseFromModule = [
nameWithOverload @[email protected]
] [
addNameCase NameCaseCapture = [addNameCase NameCaseSelfObjectCapture =] || [addNameCase NameCaseClosureObjectCapture =] || [
nameWithOverload @[email protected]
FALSE @addInfo set
] [
addNameCase NameCaseSelfMember = [addNameCase NameCaseClosureMember =] || [
nameWithOverload @[email protected]
] [
addNameCase NameCaseSelfObject = [addNameCase NameCaseClosureObject =] || [
# do nothing
] [
[FALSE] "wrong name info case" assert
] if
] if
] if
] if
] if
] if
addInfo [ # captures dont live in stack
nameInfoEntry: NameInfoEntry;
refToVar @nameInfoEntry.@refToVar set
addNameCase @nameInfoEntry.@nameCase set
startPoint @nameInfoEntry.@startPoint set
index @nameInfoEntry.@index set
cur: overload @[email protected];
nameInfoEntry @cur.pushBack
refToVar noMatterToCopy [
refToVar @[email protected] not [
refToVar TRUE @[email protected]
] when
] when
] when
] [
#we add "self" or "closure" but dont use them in program
] if
];
addNameInfo: [indexOfNode copy -1 dynamic TRUE -1 dynamic addNameInfoWith];
addNameInfoOverloaded: [TRUE -1 dynamic addNameInfoWith];
addNameInfoNoReg: [indexOfNode copy -1 dynamic FALSE -1 dynamic addNameInfoWith];
addNameInfoFieldNoReg: [
index: copy;
indexOfNode copy -1 dynamic FALSE index addNameInfoWith
];
getNameLastIndexInfo: [
nameInfo:;
currentNameInfo: nameInfo @[email protected];
result: IndexInfo;
currentNameInfo.stack.dataSize 1 - @result.@overload set
currentNameInfo.stack.last.dataSize 1 - @result.@index set
result
];
deleteNameInfoWithOverload: [
copy nameInfo:;
copy overloadId:;
currentNameInfo: nameInfo @[email protected];
overload: overloadId @[email protected];
@overload.popBack
[
currentNameInfo.stack.last.dataSize 0 = [currentNameInfo.stack.dataSize 1 >] && [
TRUE
] &&
] loop
];
deleteNameInfo: [
copy nameInfo:;
currentNameInfo: nameInfo @[email protected];
currentNameInfo.stack.dataSize 1 - nameInfo deleteNameInfoWithOverload
];
makeStaticness: [
copy staticness:;
refToVar:;
refToVar isVirtual not [
var: refToVar getVar;
staticness @var.@staticness set
staticness Virtual < not [
refToVar makeVariableType
] when
] when
refToVar copy
];
makeStorageStaticness: [
copy staticness:;
copy refToVar:;
refToVar isVirtual not [
staticness refToVar getVar.@storageStaticness set
] when
refToVar
];
createVariable: [
FALSE dynamic FALSE dynamic TRUE dynamic createVariableWithVirtual
];
createVariableWithVirtual: [
copy makeType:;
copy makeSchema:;
copy makeVirtual:;
copy tag:;
dataIsMoved: isMoved;
data:;
v: Variable;
tag @[email protected]
branch: tag @[email protected];
@data dataIsMoved moveIf @branch set
currentNode.parent 0 = @v.@global set
v.global [
processor.globalVarId @v.@globalId set
processor.globalVarId 1 + @processor.@globalVarId set
] when
@v move owner @[email protected]
# now forget about v
result: RefToVar;
currentNode.variables.dataSize 1 - @result.@varId set
indexOfNode @result.@hostId set
makeVirtual [
makeSchema [Schema][Virtual] if result getVar.@staticness set
] [
result isPlain [processor.options.staticLiterals not] && [
Weak result getVar.@staticness set
] [
Static result getVar.@staticness set
] if
] if
result result getVar.@capturedHead set
result result getVar.@capturedTail set
result isNonrecursiveType not [result isUnallocable not] && @result.@mutable set
makeType [result makeVariableType] when
result makeVariableIRName
processor.varCount 1 + @processor.@varCount set
tag VarStruct = [
processor.structureVarCount 1 + @processor.@structureVarCount set
processor.fieldVarCount VarStruct result getVar.data.get.get.fields.getSize + @processor.@fieldVarCount set
] when
result
];
push: [
entry:;
entry @[email protected]
];
getStackEntryForPreInput: [
copy depth:;
depth getStackDepth < [
entry: depth getStackEntry;
[entry.hostId indexOfNode = not] "Pre input is just in inputs!" assert
shadowBegin: RefToVar;
shadowEnd: RefToVar;
entry @shadowBegin @shadowEnd ShadowReasonInput makeShadows
shadowEnd
] [
RefToVar
] if
];
makeVarCode: [VarCode createVariable];
makeVarInt8: [VarInt8 checkValue VarInt8 createVariable createPlainIR];
makeVarInt16: [VarInt16 checkValue VarInt16 createVariable createPlainIR];
makeVarInt32: [VarInt32 checkValue VarInt32 createVariable createPlainIR];
makeVarInt64: [VarInt64 checkValue VarInt64 createVariable createPlainIR];
makeVarIntX: [VarIntX checkValue VarIntX createVariable createPlainIR];
makeVarNat8: [VarNat8 checkValue VarNat8 createVariable createPlainIR];
makeVarNat16: [VarNat16 checkValue VarNat16 createVariable createPlainIR];
makeVarNat32: [VarNat32 checkValue VarNat32 createVariable createPlainIR];
makeVarNat64: [VarNat64 checkValue VarNat64 createVariable createPlainIR];
makeVarNatX: [VarNatX checkValue VarNatX createVariable createPlainIR];
makeVarReal32: [VarReal32 checkValue VarReal32 createVariable createPlainIR];
makeVarReal64: [VarReal64 checkValue VarReal64 createVariable createPlainIR];
makeVarString: [
string:;
refToVar: RefToVar;
fr: string @[email protected];
fr.success [
fr.value @refToVar set
] [
topIndex: indexOfNode copy;
topNode: @currentNode;
[topIndex 0 = not] [
topNode.parent @topIndex set
topIndex @[email protected] !topNode
] while
indexOfNode: topIndex copy;
currentNode: @topNode;
string VarString createVariable @refToVar set
string refToVar createStringIR
string refToVar @[email protected]
refToVar fullUntemporize
refToVar getVar.mplNameId refToVar NameCaseLocal addNameInfo
] if
gnr: refToVar getVar.mplNameId getName;
cnr: gnr captureName;
cnr.refToVar copy
];
makeConst: [
var:;
FALSE dynamic @var.@mutable set
];
getPointeeForMatching: [
refToVar:;
var: refToVar getVar;
[var.data.getTag VarRef =] "Not a reference!" assert
pointee: VarRef @[email protected]; # reference
result: pointee copy;
refToVar.mutable pointee.mutable and @result.@mutable set # to deref is
result
];
getPointeeWith: [
copy dynamize:;
copy makeDerefIR:;
refToVar:;
var: refToVar getVar;
[var.data.getTag VarRef =] "Not a reference!" assert
refToVar isVirtualType [
refToVar copy
] [
pointee: VarRef @[email protected]; # reference
fromParent: pointee.hostId indexOfNode = not;
pointeeIsGlobal: FALSE dynamic;
needReallyDeref: FALSE dynamic;
refToVar staticnessOfVar Dynamic > not [
# create new var of dynamic dereference
fromParent [
pointeeCopy: pointee copyOneVar;
psBegin: RefToVar;
psEnd: RefToVar;
pointeeCopy @psBegin @psEnd ShadowReasonPointee makeShadowsDynamic
psBegin unglobalize
psEnd unglobalize
dynamize not [psEnd makeVarTreeDynamicStoraged] when
psEnd @pointee set
] [
pointeeCopy: pointee copyVar; # lost info that pointee is from parent # noMatterToCopy
pointeeCopy unglobalize
dynamize not [pointeeCopy makeVarTreeDynamicStoraged] when
pointeeCopy @pointee set
] if
TRUE @needReallyDeref set
] [
pointeeGDI: pointee getVar.globalDeclarationInstructionIndex;
fromParent [ # capture or argument
varShadow: refToVar copy;
refToVar noMatterToCopy not [
[var.shadowBegin.hostId 0 < not] "Ref got from parent, but dont have shadow!" assert
var.shadowBegin @varShadow set
] when
pointeeOfShadow: VarRef @varShadow [email protected];
pointeeOfShadow.hostId indexOfNode = [ # just made deref from another place
pointeeOfShadowVar: pointeeOfShadow getVar;
[pointeeOfShadowVar.shadowEnd.hostId 0 < not] "Pointee of shadow is not a shadow!" assert
pointeeOfShadowVar.shadowEnd @pointee set
] [
psBegin: RefToVar;
psEnd: RefToVar;
pointeeOfShadow pointee = [
pointeeOfShadow @psBegin @psEnd ShadowReasonPointee makeShadows
psBegin @pointeeOfShadow set
psEnd @pointee set
] [
#we changed ref, pointeeOFShadow is another pointer to another var!
pointee @psBegin @psEnd ShadowReasonPointee makeShadows
psEnd @pointee set
] if
psBegin fullUntemporize
psEnd fullUntemporize
TRUE @needReallyDeref set
] if
] when
pointee isGlobal [
TRUE @pointeeIsGlobal set
] when
] if
pointeeVar: pointee getVar;
pointeeVar.getInstructionIndex 0 < [pointeeIsGlobal not] && [
pointeeVar.allocationInstructionIndex 0 < [
TRUE @needReallyDeref set
] when
] [
FALSE @needReallyDeref set
] if
needReallyDeref makeDerefIR and [
refToVar pointeeVar.irNameId createDerefTo
currentNode.program.dataSize 1 - @pointeeVar.@getInstructionIndex set
] when
pointee fullUntemporize
result: pointee copy;
refToVar.mutable pointee.mutable and @result.@mutable set # to deref is
result
] if
];
getPointee: [TRUE FALSE getPointeeWith];
getPointeeNoDerefIR: [FALSE FALSE getPointeeWith];
getPointeeWhileDynamize: [FALSE TRUE getPointeeWith];
getFieldForMatching: [
refToVar:;
copy mplFieldIndex:;
var: refToVar getVar;
[var.data.getTag VarStruct =] "Not a combined!" assert
struct: VarStruct @[email protected];
mplFieldIndex 0 < not [
fieldRefToVar: mplFieldIndex struct.fields.at.refToVar copy;
refToVar.mutable @fieldRefToVar.@mutable set
fieldRefToVar variableIsDeleted not [
fieldRefToVar unglobalize
fieldVar: fieldRefToVar getVar;
fieldVar.data.getTag VarStruct = [
fieldStruct: VarStruct @[email protected];
struct.forgotten @fieldStruct.@forgotten set
] when
] when
fieldRefToVar
] [
"index is out of bounds" makeStringView compilerError
RefToVar
] if
];
getField: [
refToVar:;
copy mplFieldIndex:;
compileOnce
var: refToVar getVar;
[var.data.getTag VarStruct =] "Not a combined!" assert
struct: VarStruct @[email protected];
mplFieldIndex 0 < not [mplFieldIndex struct.fields.getSize <] && [
fieldRefToVar: mplFieldIndex @[email protected].@refToVar;
fieldVar: fieldRefToVar getVar;
fieldVar.data.getTag VarStruct = [
fieldStruct: VarStruct @[email protected];
struct.forgotten @fieldStruct.@forgotten set
] when
fieldRefToVar noMatterToCopy [fieldRefToVar.hostId indexOfNode =] || not [ # capture or argument
var.shadowBegin.hostId 0 < [
[refToVar noMatterToCopy] "Field got from parent, but dont have shadow!" assert
fieldRefToVar copyVarFromChild @fieldRefToVar set
] [
varShadow: var.shadowBegin getVar;
[varShadow.data.getTag VarStruct =] "Shadow is not a combined!" assert
structShadow: VarStruct @[email protected];
fieldShadow: mplFieldIndex @[email protected].@refToVar;
fieldShadow unglobalize
psBegin: RefToVar;
psEnd: RefToVar;
fieldShadow @psBegin @psEnd ShadowReasonField makeShadows
psBegin @fieldShadow set
psEnd @fieldRefToVar set
] if
var.staticness fieldRefToVar getVar.staticness < [
var.staticness fieldRefToVar getVar.@staticness set
] when
] when
refToVar.mutable @fieldRefToVar.@mutable set
@fieldRefToVar
] [
"index is out of bounds" makeStringView compilerError
failResult: RefToVar Ref;
@failResult
] if
];
captureEntireStruct: [
refToVar:;
unprocessed: RefToVar Array;
refToVar @unprocessed.pushBack
i: 0 dynamic;
[
i unprocessed.dataSize < [
current: i unprocessed.at copy;
currentVar: current getVar;
currentVar.data.getTag VarStruct = [current noMatterToCopy not] && [
branch: VarStruct currentVar.data.get.get;
f: 0 dynamic;
[
f branch.fields.dataSize < [
f current getField @unprocessed.pushBack
f 1 + @f set TRUE
] &&
] loop
] when
i 1 + @i set TRUE
] &&
] loop
];
setOneVar: [
copy first:;
refDst:;
refSrc:;
srcVar: refSrc getVar;
dstVar: refDst getVar;
[srcVar.data.getTag dstVar.data.getTag =] "Variable types mismatch!" assert
[refSrc isVirtual refDst isVirtual =] "Virtualness mismatch!" assert
[refDst.mutable copy] "Constness mismatch!" assert
srcVar.data.getTag VarStruct = not [
srcVar.data.getTag VarInvalid VarRef 1 + [
copy tag:;
tag srcVar.data.get
tag @[email protected] set
] staticCall
] when
refDst staticnessOfVar Dirty > [
staticness: refSrc staticnessOfVar;
staticness Weak = [refDst staticnessOfVar @staticness set] when
refDst staticness makeStaticness drop:;
] [
srcVar.data.getTag VarRef = [refSrc.mutable copy] && [VarRef srcVar.data.get.mutable copy] && [
staticness: refSrc staticnessOfVar;
refSrc makeVarTreeDirty
refSrc staticness makeStaticness drop:;
] when
] if
];
setVar: [
copy refDst:;
refSrc:;
uncopiedSrc: RefToVar Array;
uncopiedDst: RefToVar AsRef Array;
compileOnce
refSrc @uncopiedSrc.pushBack
@refDst AsRef @uncopiedDst.pushBack
i: 0 dynamic;
[
i uncopiedSrc.dataSize < [
currentSrc: i uncopiedSrc.at copy;
currentDst: i @uncopiedDst.at.@data;
currentSrc @currentDst i 0 = setOneVar
currentSrcVar: currentSrc getVar;
currentDstVar: currentDst getVar;
currentSrcVar.data.getTag VarStruct = [
branchSrc: VarStruct currentSrcVar.data.get.get;
branchDst: VarStruct currentDstVar.data.get.get;
f: 0 dynamic;
[
f branchSrc.fields.dataSize < [
fieldSrc: f currentSrc getField;
fieldDst: f currentDst getField;
fieldSrc @uncopiedSrc.pushBack
@fieldDst AsRef @uncopiedDst.pushBack
f 1 + @f set TRUE
] &&
] loop
] when
i 1 + @i set TRUE
] &&
] loop
];
createRefWith: [
copy createOperation:;
copy mutable:;
refToVar:;
refToVar isVirtual [
refToVar untemporize
refToVar copy #for dropping or getting callables for example
] [
pointee: refToVar copy;
var: pointee getVar;
pointee staticnessOfVar Weak = [Dynamic @var.@staticness set] when
pointee fullUntemporize
pointee.mutable [mutable copy] && @pointee.@mutable set
newRefToVar: pointee VarRef createVariable;
createOperation [pointee newRefToVar createRefOperation] when
newRefToVar
] if
];
createRef: [TRUE dynamic createRefWith];
createRefNoOp: [FALSE dynamic createRefWith];
createCheckedStaticGEP: [
refToStruct:;
copy index:;
fieldRef:;
fieldVar: fieldRef getVar;
fieldVar.getInstructionIndex 0 < [fieldVar.allocationInstructionIndex 0 <] && [
fieldRef unglobalize
fieldRef index refToStruct createStaticGEP
currentNode.program.dataSize 1 - @fieldVar.@getInstructionIndex set
] when
];
makeVirtualVarReal: [
refToVar:;
refToVar isVirtualType [
refToVar copy
] [
processor.options.verboseIR [("made virtual var real, type: " refToVar getMplType) assembleString createComent] when
realValue: refToVar getVar.@realValue;
unfinishedSrc: RefToVar Array;
unfinishedDst: RefToVar Array;
result: refToVar copyOneVar;
result isVirtualType not [
Static result getVar.@staticness set
refToVar @unfinishedSrc.pushBack
result @unfinishedDst.pushBack
# first pass: make new variable type
[
unfinishedSrc.dataSize 0 > [
lastSrc: unfinishedSrc.last copy;
lastDst: unfinishedDst.last copy;
@unfinishedSrc.popBack
@unfinishedDst.popBack
varSrc: lastSrc getVar;
varDst: lastDst getVar;
# noMatterToCopy
lastSrc.hostId indexOfNode = not [varDst.shadowBegin.hostId 0 <] && [
shadowBegin: lastDst copyOneVar;
shadowBeginVar: shadowBegin getVar;
lastDst @shadowBeginVar.@shadowEnd set
shadowBegin @varDst.@shadowBegin set
] when
varSrc.data.getTag VarStruct = [
struct: VarStruct varSrc.data.get.get;
j: 0 dynamic;
[
j struct.fields.dataSize < [
srcField: j struct.fields.at;
srcField.refToVar isVirtualField not [
srcField.refToVar @unfinishedSrc.pushBack
dstField: j lastDst getField;
dstField @unfinishedDst.pushBack
dstField unglobalize
] [
dstField: j lastDst getField;
dstField Virtual makeStaticness r:;
dstField unglobalize
] if
j 1 + @j set TRUE
] &&
] loop
] when
compilable
] &&
] loop
# second pass: create IR code for variable
@result makeVariableType
refToVar @unfinishedSrc.pushBack
result createAllocIR @unfinishedDst.pushBack
[
unfinishedSrc.dataSize 0 > [
lastSrc: unfinishedSrc.last copy;
lastDst: unfinishedDst.last copy;
@unfinishedSrc.popBack
@unfinishedDst.popBack
varSrc: lastSrc getVar;
varSrc.data.getTag VarStruct = [
struct: VarStruct varSrc.data.get.get;
j: 0 dynamic;
[
j struct.fields.dataSize < [
srcField: j struct.fields.at;
srcField.refToVar isVirtualField not [
srcField.refToVar @unfinishedSrc.pushBack
dstField: j lastDst getField;
dstField @unfinishedDst.pushBack
dstField unglobalize
dstField j lastDst createCheckedStaticGEP
] when
j 1 + @j set TRUE
] &&
] loop
] [
lastSrc isVirtualType not [
varSrc.data.getTag VarRef = [
] [
lastSrc isPlain [
lastSrc lastDst createStoreConstant
] when
] if
] when
] if
compilable
] &&
] loop
] when
FALSE @result.@mutable set
result @realValue set
realValue copy
] if
];
makeVarSchema: [
refToVar:;
refToVar Schema makeStaticness drop
];
makeVarVirtual: [
refToVar:;
unfinished: RefToVar Array;
refToVar @unfinished.pushBack
[
unfinished.dataSize 0 > [
cur: @unfinished.last copy;
@unfinished.popBack
curVar: cur getVar;
curVar.data.getTag VarStruct = [
cur isAutoStruct [
"can not virtualize automatic struct" makeStringView compilerError
] [
struct: VarStruct curVar.data.get.get;
j: 0 dynamic;
[
j struct.fields.dataSize < [compilable] && [
curField: j struct.fields.at;
curField.refToVar isVirtualField not [
curField.refToVar @unfinished.pushBack
] when
j 1 + @j set TRUE
] &&
] loop
] if
] [
curVar.data.getTag VarRef = [
VarRef curVar.data.get isUnallocable [
] [
"can not virtualize reference to local variable" makeStringView compilerError
] if
] [
cur staticnessOfVar Weak < [
"can not virtualize dynamic value" makeStringView compilerError
] when
] if
] if
compilable
] &&
] loop
compilable [
refToVar Virtual makeStaticness drop
] when
];
makeVarRealCaptured: [
refToVar:;
TRUE refToVar getVar.@capturedAsRealValue set
];
makeVarTreeDirty: [
refToVar:;
unfinishedVars: RefToVar Array;
refToVar @unfinishedVars.pushBack
[
unfinishedVars.dataSize 0 > [
lastRefToVar: unfinishedVars.last copy;
@unfinishedVars.popBack
var: lastRefToVar getVar;
lastRefToVar staticnessOfVar Virtual = ["can't dynamize virtual value" makeStringView compilerError] when
lastRefToVar staticnessOfVar Schema = ["can't dynamize schema" makeStringView compilerError] when
compilable [
var.data.getTag VarStruct = [
struct: VarStruct var.data.get.get;
j: 0 dynamic;
[
j struct.fields.dataSize < [
j struct.fields.at.refToVar isVirtualField not [
j lastRefToVar getField @unfinishedVars.pushBack
] when
j 1 + @j set TRUE
] &&
] loop
] [
var.data.getTag VarRef = [
lastRefToVar staticnessOfVar Static = [
pointee: lastRefToVar getPointeeWhileDynamize;
pointee.mutable [pointee @unfinishedVars.pushBack] when
] [
[lastRefToVar staticnessOfVar Dynamic > not] "Ref must be only Static or Dynamic!" assert
] if
] when
] if
var.data.getTag VarImport = not var.data.getTag VarString = not and [
lastRefToVar Dirty makeStaticness @lastRefToVar set
] when
] when
compilable
] &&
] loop
];
makePointeeDirtyIfRef: [
refToVar:;
var: refToVar getVar;
var.data.getTag VarRef = [var.staticness Static =] && [
pointee: refToVar getPointeeWhileDynamize;
pointee makeVarRealCaptured
pointee.mutable [pointee makeVarTreeDirty] when
] when
];
makeVarDynamicOrDirty: [
newStaticness:;
refToVar:;
refToVar staticnessOfVar Virtual = ["can't dynamize virtual value" makeStringView compilerError] when
refToVar makePointeeDirtyIfRef
msr: refToVar newStaticness makeStaticness;
];
makeVarDynamic: [Dynamic makeVarDynamicOrDirty];
makeVarDirty: [Dirty makeVarDynamicOrDirty];
makeVarTreeDynamicWith: [
copy dynamicStoraged:;
refToVar:;
unfinishedVars: RefToVar Array;
refToVar @unfinishedVars.pushBack
[
unfinishedVars.dataSize 0 > [
lastRefToVar: unfinishedVars.last copy;
@unfinishedVars.popBack
var: lastRefToVar getVar;
lastRefToVar staticnessOfVar Virtual = ["can't dynamize virtual value" makeStringView compilerError] when
var.data.getTag VarStruct = [
struct: VarStruct var.data.get.get;
j: 0 dynamic;
[
j struct.fields.dataSize < [
j struct.fields.at.refToVar isVirtualField not [
j lastRefToVar getField @unfinishedVars.pushBack
] when
j 1 + @j set TRUE
] &&
] loop
] [
var.data.getTag VarRef = [
lastRefToVar staticnessOfVar Static = [
dynamicStoraged not [
pointee: lastRefToVar getPointeeWhileDynamize;
pointee.mutable [pointee makeVarTreeDirty] when
] when # dynamic storaged data is not real
] [
[lastRefToVar staticnessOfVar Dynamic = lastRefToVar staticnessOfVar Dirty = or] "Ref must be only Static or Dirty or Dynamic!" assert
] if
] when
] if
dynamicStoraged [
lastRefToVar Dynamic makeStorageStaticness @lastRefToVar set
lastRefToVar Dirty makeStaticness @lastRefToVar set
] [
lastRefToVar Dynamic makeStaticness @lastRefToVar set
] if
compilable
] &&
] loop
];
makeVarTreeDynamic: [FALSE dynamic makeVarTreeDynamicWith];
makeVarTreeDynamicStoraged: [TRUE dynamic makeVarTreeDynamicWith];
addOverloadForPre: [
refToVar:;
copy nameInfo:;
var: refToVar getVar;
var.data.getTag VarStruct = [
struct: VarStruct @[email protected];
struct.hasPreField [
overload: nameInfo addOverload;
] when
] when
];
createNamedVariable: [
refToVar:;
copy nameInfo:;
compilable [
newRefToVar: refToVar copy;
staticness: refToVar staticnessOfVar;
var: newRefToVar getVar;
currentNode.nextLabelIsVirtual [
refToVar isVirtual not [
staticness Dynamic > not ["value for virtual label must be static" makeStringView compilerError] when
staticness Weak = [Static @var.@staticness set] when
] when
] when
isGlobalLabel: [
refToVar:;
currentNode.nextLabelIsVirtual not [refToVar isVirtual not] && [refToVar isGlobal] &&
];
var.temporary [refToVar isGlobalLabel] && [
refToVar makeVarTreeDirty
Dirty @staticness set
] when
var.temporary currentNode.nextLabelIsSchema not and [
staticness @var.@staticness set
staticness Weak = [Dynamic @var.@staticness set] when
] [
newRefToVar noMatterToCopy currentNode.nextLabelIsVirtual or newRefToVar isUnallocable not and [
refToVar copyVarToNew @newRefToVar set
] [
TRUE @var.@capturedAsMutable set #we need ref
refToVar TRUE currentNode.nextLabelIsSchema not createRefWith @newRefToVar set
newRefToVar isGlobalLabel [newRefToVar makeVarTreeDirty] when
] if
] if
TRUE dynamic @newRefToVar.@mutable set
nameInfo newRefToVar addOverloadForPre
newRefToVar fullUntemporize
FALSE newRefToVar getVar.@tref set
currentNode.nextLabelIsVirtual currentNode.nextLabelIsSchema or [
newRefToVar makeVariableType
currentNode.nextLabelIsSchema [newRefToVar makeVarSchema][newRefToVar makeVarVirtual] if
FALSE @currentNode.@nextLabelIsVirtual set
FALSE @currentNode.@nextLabelIsSchema set
] when
nameInfo newRefToVar NameCaseLocal addNameInfo
compilable [processor.options.debug copy] && [newRefToVar isVirtual not] && [
newRefToVar isGlobal [
d: nameInfo newRefToVar addGlobalVariableDebugInfo;
globalInstruction: newRefToVar getVar.globalDeclarationInstructionIndex @[email protected];
", !dbg !" @globalInstruction.cat
d @globalInstruction.cat
] [
nameInfo newRefToVar addVariableMetadata
] if