-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocessSubNodes.mpl
2489 lines (2114 loc) · 82.2 KB
/
processSubNodes.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
# Copyright (C) 2021 Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"Array" use
"HashTable" use
"String" use
"algorithm" use
"control" use
"Block" use
"MplFile" use
"Var" use
"astNodeType" use
"codeNode" use
"debugWriter" use
"declarations" use
"defaultImpl" use
"irWriter" use
"logger" use
"processor" use
"staticCall" use
"variable" use
{processorResult: ProcessorResult Ref; cachedGlobalErrorInfoSize: Int32;} () {} [
cachedGlobalErrorInfoSize: processorResult:;;
TRUE @processorResult.!success
FALSE @processorResult.!findModuleFail
FALSE @processorResult.!passErrorThroughPRE
String @processorResult.!program
ProcessorErrorInfo @processorResult.!errorInfo
cachedGlobalErrorInfoSize 0 < ~ [
cachedGlobalErrorInfoSize @[email protected]
] when
] "clearProcessorResult" exportFunction
{processor: Processor Cref; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [
stackEntry: cacheEntry: processor:;;;
cacheEntry isGlobal [
stackEntry isGlobal [
cacheEntry getVar.globalId
stackEntry getVar.globalId =
] &&
] [
stackEntry isGlobal ~
] if
] "variablesHaveSameGlobality" exportFunction
varibaleAreEqualBody: [
e1Checker: e2Checker: ;;
stackEntry: cacheEntry: makeMessage: comparingMessage: processor: ;;;;;
stackDynamicBorder: Weak;
cacheEntry stackEntry variablesAreSame ~ [
makeMessage ["variables has different type" toString @comparingMessage set] when
FALSE
] [
cacheEntry stackEntry processor variablesHaveSameGlobality ~ [
makeMessage ["variables has different globality" toString @comparingMessage set] when
FALSE
] [
cacheEntryVar: cacheEntry getVar;
stackEntryVar: stackEntry getVar;
cacheEntryVar.storageStaticity stackEntryVar.storageStaticity = ~ [
makeMessage [
("variables has different storageStaticity; was " cacheEntryVar.storageStaticity " but now " stackEntryVar.storageStaticity) assembleString @comparingMessage set
] when
FALSE
] [
stackEntryVar.data.getTag VarStruct = [
cacheStaticity: cacheEntryVar.staticity e1Checker new;
stackStaticity: stackEntryVar.staticity e2Checker new;
cacheStaticity Dynamic = [Static !cacheStaticity] when
stackStaticity Dynamic = [Static !stackStaticity] when
cacheStaticity stackStaticity = ~ [
makeMessage [
("variables has different staticity; was " cacheStaticity " but now " stackStaticity) assembleString @comparingMessage set
] when
FALSE
] [
cacheStruct: VarStruct cacheEntryVar.data.get.get;
cacheStruct.hasDestructor [cacheEntry varIsMoved stackEntry varIsMoved = ~] && [
makeMessage ["variables has different moveness" toString @comparingMessage set] when
FALSE
] [
TRUE
] if
] if
] [
cacheStaticity: cacheEntryVar.staticity e1Checker new;
stackStaticity: stackEntryVar.staticity e2Checker new;
cacheStaticity Weak > ~ stackStaticity stackDynamicBorder > ~ and [
# both dynamic
cacheStaticity Dirty = stackStaticity Dirty = = [
TRUE
] [
makeMessage [
("variables has different staticity; was " cacheStaticity " but now " stackStaticity) assembleString @comparingMessage set
] when
FALSE
] if
] [
cacheStaticity Weak > stackStaticity stackDynamicBorder > and [
# both static
cacheEntry isPlain [
result: TRUE;
cacheEntryVar.data.getTag VarCond VarReal64 1 + [
tag:;
cacheValue: tag cacheEntryVar.data.get;
stackValue: tag stackEntryVar.data.get;
cacheValue e1Checker
stackValue e2Checker =
!result
] staticCall
result ~ makeMessage and ["variables has different values" toString @comparingMessage set] when
result
] [
TRUE # go recursive
] if
] [
makeMessage [
("variables has different staticity; was " cacheStaticity " but now " stackStaticity) assembleString @comparingMessage set
] when
FALSE
] if
] if
] if
] if
] if
] if
];
{processor: Processor Cref; comparingMessage: String Ref; makeMessage: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [
[.begin] [.begin] @varibaleAreEqualBody ucall
] "variablesAreEqualForTree" exportFunction
{processor: Processor Cref; comparingMessage: String Ref; makeMessage: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [
[.begin] [.end] @varibaleAreEqualBody ucall
] "variablesAreEqualForMatching" exportFunction
{forLoop: Cond; processor: Processor Cref; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref; } Cond {} [
stackEntry: cacheEntry: processor: forLoop: ;;;;
cacheEntry stackEntry variablesAreSame [cacheEntry stackEntry processor variablesHaveSameGlobality] && [
cacheEntryVar: cacheEntry getVar;
stackEntryVar: stackEntry getVar;
stackEntryVar.data.getTag VarStruct = [
cacheStaticity: cacheEntryVar.staticity.end new;
stackStaticity: stackEntryVar.staticity.end new;
cacheStaticity Dynamic = [Static !cacheStaticity] when
stackStaticity Dynamic = [Static !stackStaticity] when
cacheStaticity stackStaticity = [
cacheStruct: VarStruct cacheEntryVar.data.get.get;
cacheStruct.hasDestructor ~ [cacheEntry varIsMoved stackEntry varIsMoved =] ||
] &&
] [
cacheStaticity: cacheEntryVar.staticity.end new;
stackStaticity: stackEntryVar.staticity.end new;
forLoop [cacheStaticity Static = stackStaticity Dynamic > ~ and] && [ #was dynamic but after loop is static
TRUE
] [
cacheStaticity Weak > ~ stackStaticity Dynamic > ~ and [ # both dynamic
cacheStaticity Dirty = stackStaticity Dirty = =
] [
cacheStaticity Weak > stackStaticity Dynamic > and [ # both static
cacheEntry isPlain [
result: TRUE;
cacheEntryVar.data.getTag VarCond VarReal64 1 + [
tag:;
tag cacheEntryVar.data.get.end
tag stackEntryVar.data.get.end =
!result
] staticCall
result
] [
cacheEntryVar.data.getTag VarRef = [cacheEntry staticityOfVar Virtual <] && [
r1: VarRef cacheEntryVar.data.get.refToVar;
r2: VarRef stackEntryVar.data.get.refToVar;
r1.var r2.var is [r1.mutable r2.mutable =] && [r1 getVar.staticity.end r2 getVar.staticity.end =] &&
] [
TRUE # go recursive
] if
] if
] && # both static and are equal
] if
] if
] if
] &&
] "variablesAreEqualWith" exportFunction
variablesAreEqual: [FALSE variablesAreEqualWith];
variablesAreEqualForLoop: [TRUE variablesAreEqualWith];
{processor: Processor Cref; currentMatchingNode: Block Cref; refToVar: RefToVar Cref;} Cond {} [
refToVar: currentMatchingNode: processor:;;;
refToVar getVar.host currentMatchingNode is ~ [refToVar noMatterToCopy ~] &&
] "variableIsUnused" exportFunction
{processor: Processor Cref; makeMessage: Cond; comparingMessage: String Ref; checkConstness: Cond; forMatching: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [
stackEntry: cacheEntry: forMatching: checkConstness: comparingMessage: makeMessage: processor:;;;;;;;
checkConstness ~ [cacheEntry.mutable stackEntry.mutable =] || [
forMatching [
stackEntry cacheEntry makeMessage @comparingMessage processor variablesAreEqualForMatching
] [
stackEntry cacheEntry makeMessage @comparingMessage processor variablesAreEqualForTree
] if [
TRUE
] [
FALSE
] if
] [
makeMessage ["variables have different constness" toString @comparingMessage set] when
FALSE
] if
] "compareOnePair" exportFunction
getOverloadIndex: [
cap: block: file: forMathing: ;;;;
overloadDepth: cap.nameOverloadDepth new;
outOverloadDepth: 0;
index: -1;
[
index file cap.nameInfo processor.nameManager.findItem !index
index 0 < [
forMathing ~ [
("while matching cant call overload for name: " cap.nameInfo processor.nameManager.getText) assembleString @processor block compilerError
] when
FALSE
] [
overloadDepth 0 = [
FALSE
] [
oldGnr: cap.nameInfo index @processor @block file getNameWithOverloadIndex;
oldGnr.startPoint block.id = ~ [outOverloadDepth 1 + !outOverloadDepth] when
overloadDepth 1 - !overloadDepth
TRUE
] if
] if
] loop
index outOverloadDepth
];
catShadowEvents: [
index: currentMatchingNode: message: ;;;
index 1 + [
currentEvent: i currentMatchingNode.matchingInfo.shadowEvents.at;
(
ShadowReasonInput [
branch:;
("shadow event [" i "] input topology " branch.refToVar getVar.topologyIndex " type " branch.refToVar @processor @block getMplType LF) @message.catMany
]
ShadowReasonCapture [
branch:;
branch.stable [
("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText " as stable" LF) @message.catMany
] [
("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") index " branch.refToVar getVar.topologyIndex " type " branch.refToVar @processor @block getMplType LF) @message.catMany
branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) @message.catMany] when
] if
]
ShadowReasonPointee [
branch:;
("shadow event [" i "] pointee " branch.pointer getVar.topologyIndex " index " branch.pointee getVar.topologyIndex LF) @message.catMany
]
ShadowReasonField [
branch:;
("shadow event [" i "] field \"" branch.mplFieldIndex VarStruct branch.object getVar.data.get.get.fields.at.nameInfo processor.nameManager.getText "\" [" branch.mplFieldIndex "] of " branch.object getVar.topologyIndex " object type " branch.object @processor @block getMplType " index " branch.field getVar.buildingTopologyIndex LF) @message.catMany
]
[]
) currentEvent.visit
] times
];
addEventVarWhileMatching: [
stackEntry: cacheEntry: eventVars: ;;;
success: TRUE dynamic;
stackEntry noMatterToCopy ~ [
topologyIndex: cacheEntry getVar.topologyIndex copy;
[topologyIndex 0 < ~] "Shadow event index is negative!" assert
topologyIndex eventVars.size < [
topologyIndex stackEntry getVar.topologyIndexWhileMatching = ~ [
FALSE dynamic @success set
] when
] [
stackEntry getVar.topologyIndexWhileMatching 0 < ~ [
FALSE dynamic @success set
] [
[
topologyIndex eventVars.size = [
message: String;
currentMatchingNode.matchingInfo.shadowEvents.size 1 - @currentMatchingNode @message catShadowEvents
message print
FALSE
] ||
] "Topology indexes are not sequenced!" assert
topologyIndex 1 + @eventVars.enlarge
topologyIndex @stackEntry getVar.@topologyIndexWhileMatching set
stackEntry topologyIndex @eventVars.at set
] if
] if
] when
success
];
tryMatchNode: [
currentMatchingNode:;
comparingMessage: String;
currentMatchingNode.changedStableName [currentMatchingNode.nodeCompileOnce new] && [
"in compile-once node stable name changed" @processor block compilerError
] when
labmdaMismatch: currentMatchingNode.hasEmptyLambdas [
topNode: block.topNode;
[topNode.file nil? ~] "Topnode in nil file!" assert
topNode.file.usedInParams new
] &&;
labmdaMismatch [currentMatchingNode.nodeCompileOnce new] && [
"in compile-once node was empty lambda, because it was called from unused module" @processor block compilerError
] when
canMatch: currentMatchingNode.deleted ~ [currentMatchingNode.changedStableName ~] && [labmdaMismatch ~] && [
currentMatchingNode.state NodeStateCompiled =
currentMatchingNode.state NodeStateFailed = or [
#recursive condition
currentMatchingNode.nodeIsRecursive
[currentMatchingNode.recursionState NodeRecursionStateFail = ~] &&
[
currentMatchingNode.state NodeStateNew =
[currentMatchingNode.state NodeStateHasOutput = [currentMatchingNode.recursionState NodeRecursionStateOld =] &&] ||
[forceRealFunction new] ||
] &&
] ||
] &&;
goodReality:
forceRealFunction ~ [
currentMatchingNode.nodeCase NodeCaseDeclaration =
[currentMatchingNode.nodeCase NodeCaseCodeRefDeclaration =] ||
[currentMatchingNode.nodeCase NodeCaseExport =] ||
[currentMatchingNode.nodeCase NodeCaseLambda =] ||
] ||;
invisibleName: currentMatchingNode.nodeCase NodeCaseLambda = [currentMatchingNode.varNameInfo 0 < ~] && [
gnr: currentMatchingNode.varNameInfo @processor @block File Cref getNameForMatching;
gnr.refToVar.assigned ~
] &&;
canMatch invisibleName ~ and goodReality and
];
{processor: Processor Ref; block: Block Ref; forceRealFunction: Cond; astArrayIndex: Int32;} Int32 {} [
processor:;
block:;
overload failProc: processor block FailProcForProcessor;
forceRealFunction:;
astArrayIndex:;
compileOnce
astArrayIndex processor.matchingNodes.size < [astArrayIndex processor.matchingNodes.at.valid?] && [
matchingNode: astArrayIndex @[email protected];
matchingNode.entries 1 + @matchingNode.@entries set
findInIndexArray: [
where:;
result: -1 dynamic;
i: 0 dynamic;
[
i where.size < [
matchingNode.tries 1 + @matchingNode.@tries set
currentMatchingNodeIndex: i where.at;
currentMatchingNode: currentMatchingNodeIndex processor.blocks.at.get;
currentMatchingNode tryMatchNode [
currentMatchingNodeIndex @result set
currentMatchingNode.uncompilable ["nested node error" @processor block compilerError] when
FALSE
] [
i 1 + @i set processor compilable
] if
] &&
] loop
result
];
#find-in-tree way
result: -1 dynamic;
currentEntryIndex: 0 dynamic;
eventVars: @processor.acquireVarRefArray;
success: FALSE dynamic;
continueSearch: TRUE dynamic;
comparingMessage: String;
matchingNodeStackDepth: 0 dynamic;
addEventVar: [
stackEntry: eventVars: ;;
stackEntry noMatterToCopy ~ [
stackEntry getVar.topologyIndexWhileMatching 0 < [
eventVars.size @stackEntry getVar.@topologyIndexWhileMatching set
stackEntry @eventVars.append
] when
] when
];
[
currentMemory: currentEntryIndex matchingNode.treeMemory.at;
currentMemory.childIndices.size 0 = [
TRUE !success
FALSE !continueSearch
] [
pattern: 0 currentMemory.childIndices @ .childIndex matchingNode.treeMemory.at.parentEvent;
matchingFakeEvent: pattern new;
#step1: get our hash of event
(
ShadowReasonInput [
branch:;
stackEntry: matchingNodeStackDepth @processor block getStackEntryUnchecked;
stackEntry @branch.@refToVar set
stackEntry @eventVars addEventVar
matchingNodeStackDepth 1 + !matchingNodeStackDepth
]
ShadowReasonCapture [
branch:;
overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;;
gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex;
branch.file gnr processor nameResultIsStable @branch.@stable set
stackEntry: gnr.mplFieldIndex 0 < [gnr.refToVar] [gnr.object] if;
stackEntry @branch.@refToVar set
stackEntry @eventVars addEventVar
]
ShadowReasonPointee [
branch:;
stackPointer: branch.pointer getVar.topologyIndex eventVars.at;
stackEntry: stackPointer @processor @block getPointeeForMatching;
stackPointer @branch.@pointer set
stackEntry @branch.@pointee set
stackEntry @eventVars addEventVar
]
ShadowReasonField [
branch:;
stackObject: branch.object getVar.topologyIndex eventVars.at;
stackEntry: branch.mplFieldIndex stackObject @processor @block getFieldForMatching;
stackObject @branch.@object set
stackEntry @branch.@field set
stackEntry @eventVars addEventVar
]
ShadowReasonTreeSplitterLambda [
branch:;
processor.options.partial ~ [
topNode: block.topNode;
[topNode.file nil? ~] "Topnode in nil file!" assert
topNode.file.usedInParams new
] || @branch set
]
[]
) @matchingFakeEvent.visit
continueSearch [
eventHash: matchingFakeEvent TRUE dynamic @processor @block getShadowEventHash;
candidates: @currentMemory.@childIndices;
candidateIndex: -1 dynamic;
candidates [
prevVersion:;
candidateIndex 0 < [
eventHash prevVersion.eventHash = [
prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent;
matchingFakeEvent prevVersionEvent @comparingMessage TRUE dynamic @processor compareEvents
] && [
prevVersion.childIndex @candidateIndex set
] when
] when
] each
candidateIndex 0 < [
TRUE !success #may be we can find it in
FALSE !continueSearch
] [
currentMemory.nodeIndexes.size 0 > [
TRUE !success #may be we can find it in
FALSE !continueSearch
] [
candidateIndex @currentEntryIndex set
] if
] if
] when
] if
continueSearch new
] loop
eventVars [
refToVar:;
-1 @refToVar getVar.@topologyIndexWhileMatching set
] each
@eventVars @processor.releaseVarRefArray
success [
currentMemory: currentEntryIndex matchingNode.treeMemory.at;
currentMemory.nodeIndexes findInIndexArray @result set
] when
result
] [
-1
] if
] "tryMatchAllNodesWith" exportFunction
tryMatchAllNodes: [
processor: block: ;;
FALSE @block @processor tryMatchAllNodesWith
];
tryMatchAllNodesForRealFunction: [
processor: block: ;;
TRUE @block @processor tryMatchAllNodesWith
];
fixRecursionStack: [
i: block.id new;
[
processor.recursiveNodesStack.size 0 > [i newNodeIndex = ~] && [
current: i @[email protected];
i processor.recursiveNodesStack.last = [
NodeRecursionStateNo @current.@recursionState set
] when
current.parent @i set
[i 0 = ~] "NewNodeIndex is not a parent of block.id while fixRecursionStack!" assert
TRUE
] &&
] loop
];
changeNewNodeState: [
newNodeIndex: new;
newNode: newNodeIndex @[email protected];
newNode.state NodeStateNew = [
[newNode.nodeIsRecursive new] "new node must be recursive!" assert
fixRecursionStack
NodeRecursionStateNew @newNode.@recursionState set
processor.recursiveNodesStack.size 0 = [processor.recursiveNodesStack.last newNodeIndex = ~] || [
newNodeIndex @[email protected]
] when
NodeStateNoOutput @block.@state set
] [
newNode.state NodeStateNoOutput = [
NodeStateNoOutput @block.@state set
] [
newNode.recursionState NodeRecursionStateNo > [
[newNode.nodeIsRecursive new] "new node must be recursive!" assert
fixRecursionStack
] when
newNode.recursionState NodeRecursionStateFail > [newNode.state NodeStateHasOutput =] || [NodeStateHasOutput @block.@state set] when
] if
] if
];
changeNewExportNodeState: [
newNodeIndex: new;
newNode: newNodeIndex @[email protected];
newNode.state NodeStateNew = [
[newNode.nodeIsRecursive new] "new node must be recursive!" assert
fixRecursionStack
NodeRecursionStateNew @newNode.@recursionState set
processor.recursiveNodesStack.size 0 = [processor.recursiveNodesStack.last newNodeIndex = ~] || [
newNodeIndex @[email protected]
] when
NodeStateHasOutput @block.@state set
] [
newNode.state NodeStateNoOutput = [
NodeStateHasOutput @block.@state set
] [
newNode.recursionState NodeRecursionStateNo > [
[newNode.nodeIsRecursive new] "new node must be recursive!" assert
fixRecursionStack
] when
newNode.recursionState NodeRecursionStateFail > [newNode.state NodeStateHasOutput =] || [NodeStateHasOutput @block.@state set] when
] if
] if
];
fixRef: [
refToVar: appliedVars:; new;
var: @refToVar getVar;
wasVirtual: refToVar isVirtual;
makeDynamic: FALSE dynamic;
pointee: VarRef @[email protected].@refToVar;
pointeeVar: pointee getVar;
pointeeIsLocal: pointeeVar.capturedHead getVar.host currentChangesNode is;
pointeeWasNotUsed: pointeeVar.host currentChangesNode is ~;
fixed: pointee new;
pointeeWasNotUsed [
] [
pointeeIsLocal ~ [ # has shadow - captured from top
index: pointeeVar.topologyIndex new;
index 0 < ~ [
index appliedVars.stackVars.at @fixed set
] [
#pointee @processor @block copyVarFromChild @fixed set
#TRUE dynamic @makeDynamic set
] if
] [
# dont have shadow - to deref of captured dynamic pointer
# must by dynamic
var.staticity.end Static = [pointeeVar.storageStaticity Static =] && [
"returning pointer to local variable" @processor block compilerError
] when
#pointee getVar.host currentChangesNode is ~
#pointee @processor @block copyOneVarFromType Dynamic @processor @block makeStorageStaticity @fixed set
TRUE dynamic @makeDynamic set
] if
] if
@fixed.var @pointee.setVar
wasVirtual [
@refToVar Virtual @processor block makeStaticity @refToVar set
] when
@refToVar
];
hasGoodSource: [
refToVar:;
var: refToVar getVar;
var.host var.sourceOfValue getVar.host is
];
fixOutputRefsRec: [
stackEntry: appliedVars: ;;
unfinishedStack: @processor.acquireVarRefArray;
stackEntry @unfinishedStack.append
i: 0 dynamic;
[
i unfinishedStack.size < [
currentFromStack: i @unfinishedStack.at new;
stackEntryVar: @currentFromStack getVar;
sourceVar: stackEntryVar.sourceOfValue getVar;
currentFromStack noMatterToCopy [
#do nothing
] [
sourceVar.host block is [
[currentFromStack hasGoodSource] "Stack var source invariant failed!" assert
] [
sourceVar.host currentChangesNode is [
sourceIndex: sourceVar.topologyIndex new;
sourceIndex 0 < ~ [
sourceIndex appliedVars.stackVars.at @stackEntryVar.@sourceOfValue set
] [
currentFromStack @stackEntryVar.@sourceOfValue set
] if
] [
"Source of value is unknown!" failProc
] if
[currentFromStack hasGoodSource] "Stack var source invariant failed!" assert
stackEntryVar.data.getTag VarRef = [
stackPointee: VarRef @[email protected].@refToVar;
stackPointee getVar.host currentChangesNode is [
fixedPointer: currentFromStack appliedVars fixRef;
fixedPointer staticityOfVar Dynamic > [
fixed: fixedPointer @processor @block getPointeeNoDerefIR;
fixed @unfinishedStack.append
] when
] [
sourceVar.topologyIndex 0 < ~ [
stackEntryOfSource: sourceVar.topologyIndex @[email protected];
stackPointeeBySource: VarRef @stackEntryOfSource [email protected].@refToVar;
stackPointeeBySource getVar.host.id block.id = [
@stackPointeeBySource getVar @stackPointee.setVar
] when
] when
] if
] [
stackEntryVar.data.getTag VarStruct = [
stackStruct: VarStruct stackEntryVar.data.get.get;
j: 0 dynamic;
[
j stackStruct.fields.size < [
stackEntryVar.storageStaticity Static = [j stackStruct.fields.at.usedHere new] || [
stackField: j currentFromStack @processor @block getField;
stackField @unfinishedStack.append
] when
j 1 + @j set TRUE
] &&
] loop
] when
] if
] if
] if
i 1 + @i set processor compilable
] &&
] loop
@unfinishedStack @processor.releaseVarRefArray
];
fixCaptureRef: [
stackEntry: cacheEntry: appliedVars: ;;;
stackVar: @stackEntry getVar;
cacheVar: @cacheEntry getVar;
cacheEntry noMatterToCopy ~ [
cacheVar.data.getTag VarRef = [
topologyIndex: cacheVar.sourceOfValue getVar.topologyIndex;
cacheCopy: cacheEntry @processor @block copyOneVar;
cacheCopyVar: cacheCopy getVar;
cacheVar.staticity @cacheCopyVar.@staticity set #we need to copy begin and end
cacheEntry isGlobal [
TRUE @cacheCopyVar.@global set
cacheVar.globalId @cacheCopyVar.@globalId set
] when
topologyIndex 0 < [
#source is inner variable
cacheCopy @cacheCopyVar.@sourceOfValue set
cacheCopyVar.data.getTag VarRef = [
cacheCopyVar.staticity.end Dynamic > [
cachePointee: VarRef @[email protected].@refToVar;
topologyIndexOfPointee: cachePointee getVar.topologyIndex new;
topologyIndexOfPointee 0 < [
cachePointee getVar.storageStaticity Dynamic = [
#here dont need to do something
] [
cachePointee getVar.storageStaticity Virtual = [
cachePointee @processor @block getLastShadow getVar @cachePointee.setVar
] [
cachePointee isUnallocable [
#its ok
] [
"returning pointer to local variable" @processor block compilerError
] if
] if
] if
] [
#fixing here...
topologyIndexOfPointee appliedVars.stackVars.at getVar @cachePointee.setVar
] if
] when
] when
] [
#we know source of variable
topologyIndex appliedVars.stackVars.at @cacheCopyVar.@sourceOfValue set
cacheVar.data.getTag VarRef = [
VarRef cacheCopyVar.sourceOfValue getVar.data.get.refToVar
VarRef @[email protected].@refToVar set
] when
] if
cacheCopy @cacheEntry set #here cacheCopy is END
] [
stackEntry @stackVar.@sourceOfValue set
] if
] when
];
applyNodeChanges: [
compileOnce
currentChangesNode:;
appliedVars: {
stackVars: @processor.acquireVarRefArray;
cacheVars: @processor.acquireVarRefArray;
fixedOutputs: @processor.acquireVarRefArray;
DIE: [
@stackVars @processor.releaseVarRefArray
@cacheVars @processor.releaseVarRefArray
@fixedOutputs @processor.releaseVarRefArray
];
};
pops: @processor.acquireVarRefArray;
addAppliedVar: [
stackEntry: cacheEntry: appliedVars: ;;;
[stackEntry cacheEntry variablesAreSame
[
(
"Stack entry type is " stackEntry @processor @block getMplType LF
"cache entry type is " cacheEntry @processor @block getMplType LF
) printList
FALSE
] ||
] "Applied vars has different type!" assert
stackEntry noMatterToCopy ~ [
[stackEntry getVar.host.id block.id =] "Stack entry is not from here!" assert
topologyIndex: cacheEntry getVar.topologyIndex new;
[topologyIndex 0 < ~] "Shadow event index is negative!" assert
topologyIndex appliedVars.stackVars.size < ~ [
topologyIndex 1 + @[email protected]
topologyIndex 1 + @[email protected]
stackEntry topologyIndex @[email protected] set
cacheEntry topologyIndex @[email protected] set
[cacheEntry noMatterToCopy [cacheEntry getVar.host cacheEntry getVar.sourceOfValue getVar.host is] ||] "Val source incorrest!" assert
] when
cacheEntry getVar.capturedByPtr [
stackEntry makeVarPtrCaptured
] when
cacheEntry getVar.capturedAsRealValue [
stackEntry @processor @block makeVarRealCaptured
] when
cacheEntry getVar.capturedForDeref [
stackEntry makeVarDerefCaptured
] when
] when
];
currentChangesNode.matchingInfo.shadowEvents.size [
processor compilable [
shadowEventIndex: i new;
currentEvent: shadowEventIndex currentChangesNode.matchingInfo.shadowEvents.at;
(
ShadowReasonInput [
branch:;
stackEntry: @processor @block popForMatching;
cacheEntry: branch.refToVar;
stackEntry cacheEntry @appliedVars addAppliedVar
stackEntry @pops.append
]
ShadowReasonCapture [
branch:;
branch.stable [
branch.refToVar branch.nameInfo branch.nameOverloadDepth branch.file @processor @block addStableName
] [
cacheEntry: branch.refToVar;
overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;;
gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex;
cnr: gnr outOverloadDepth @processor @block branch.file captureName;
stackEntry: cnr.matchingEntry;
[stackEntry cacheEntry variablesAreSame
[
(
"astArrayIndex " currentChangesNode.astArrayIndex "; nodeIndex " currentChangesNode.id LF
"shadowEventIndex " shadowEventIndex " of " currentChangesNode.matchingInfo.shadowEvents.size LF
"capture name is " branch.nameInfo processor.nameManager.getText LF
"stack entry is " stackEntry @processor @block getMplType LF
"cache entry is " cacheEntry @processor @block getMplType LF) printList
currentChangesNode.astArrayIndex @processor @block printAstArrayTree
FALSE
] ||
] "Applied vars has different type!" assert
stackEntry cacheEntry @appliedVars addAppliedVar
] if
]
ShadowReasonPointee [
branch:;
cacheEntry: branch.pointee;
stackPointer: branch.pointer getVar.topologyIndex @[email protected];
stackEntry: @stackPointer @processor @block getPointeeNoDerefIR;
stackEntry cacheEntry @appliedVars addAppliedVar
]
ShadowReasonField [
branch:;
cacheObject: branch.object;
cacheEntry: branch.field;
stackObject: cacheObject getVar.topologyIndex appliedVars.stackVars.at;
[stackObject cacheObject variablesAreSame
[
(
"shadowEventIndex " shadowEventIndex " of " currentChangesNode.matchingInfo.shadowEvents.size LF
"cacheObject topologyIndex " cacheObject getVar.topologyIndex " of " appliedVars.stackVars.size LF
"stack object is " stackObject @processor @block getMplType LF
"cache object is " cacheObject @processor @block getMplType LF) printList
message: String;
shadowEventIndex currentChangesNode @message catShadowEvents
message print LF print
FALSE
] ||
] "Applied objects has different type!" assert
stackEntry: branch.mplFieldIndex stackObject @processor @block getField;
stackEntry cacheEntry @appliedVars addAppliedVar
]
ShadowReasonTreeSplitterLambda [
branch:;
branch new @processor @block addLambdaEvent
]
[]
) @currentEvent.visit
] when
] times
currentChangesNode.capturedFiles.size [
i currentChangesNode.capturedFiles.at [
i @block captureFileToBlock
] when
] times
currentChangesNode.hasEmptyLambdas [
@block setBlockEmptyLambdas
] when
i: 0 dynamic;
[
i pops.size < [
pops.size i - 1 - pops.at @block pushForMatching
i 1 + @i set processor compilable
] &&
] loop
appliedVars.stackVars.size [
stackEntryVar: i @[email protected] getVar;
i @stackEntryVar.@topologyIndexWhileMatching set
] times
i: 0 dynamic;
[
i currentChangesNode.outputs.size < [
currentOutput: i currentChangesNode.outputs.at;
outputRef: currentOutput.refToVar @processor @block copyVarFromChild; # output is to inner var
outputRef appliedVars fixOutputRefsRec # it is End