-
Notifications
You must be signed in to change notification settings - Fork 4
/
defaultImpl.mpl
894 lines (774 loc) · 26 KB
/
defaultImpl.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
# 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
"String" use
"algorithm" use
"control" use
"conventions" use
"Block" use
"Var" use
"declarations" use
"processor" use
"staticCall" use
FailProcForProcessor: [{
processor: block: ;;
CALL: [
overload failProc: [print " - fail while handling fail" print];
"INTERNAL COMPILER ERROR" print LF print
print
trace: getCallTrace;
[
trace storageAddress 0nx = [
FALSE
] [
(trace.name trace.line new trace.column new) " in %s at %i:%i\n\00" printf drop
trace.prev trace addressToReference !trace
TRUE
] if
] loop
"\nWhile compiling:\n" print
processor block defaultPrintStackTrace
"\nCommand line:\n" print
processor.options.fullLine print
"\n" print
2 exit
];
} dynamic];
pop: [
processor: block: ;;
result: RefToVar;
@result FALSE @processor @block popWith
@result
];
createRef: [processor: block:;; TRUE dynamic @processor @block createRefWith];
createRefNoOp: [processor: block:;; FALSE dynamic @processor @block createRefWith];
compilable: [processor:; processor.result.success new];
makeVarRealCaptured: [
refToVar: processor: block: ;;;
refToVar getVar.storageStaticity Virtual = [
"accessing nullptr" @processor @block compilerError
] when
TRUE @refToVar getVar.@capturedAsRealValue set
];
makeVarPtrCaptured: [
refToVar:;
TRUE @refToVar getVar.@capturedByPtr set
];
makeVarDerefCaptured: [
refToVar:;
TRUE @refToVar getVar.@capturedForDeref set
];
defaultFailProc: [
processor: block: ;;
text: @processor @block pop;
];
defaultSet: [
processor: block: ;;
refToDst: @processor @block pop;
refToSrc: @processor @block pop;
processor compilable [
refToDst refToSrc variablesAreSame [
refToSrc getVar.data.getTag VarImport = [
"functions cannot be copied" @processor block compilerError
] [
refToSrc getVar.data.getTag VarString = [
"builtin-strings cannot be copied" @processor block compilerError
] [
refToDst.mutable [
[refToDst staticityOfVar Weak = ~] "Destination is weak!" assert
refToSrc.mutable [refToSrc isVirtual ~ [refToSrc getVar .data.getTag VarStruct =] &&] && [
TRUE @refToSrc.setMoved
] when
@refToSrc @refToDst @processor @block createCopyToExists
] [
"destination is immutable" @processor block compilerError
] if
] if
] if
] [
refToDst.mutable ~ [
"destination is immutable" @processor block compilerError
] [
lambdaCastResult: @refToSrc @refToDst @processor @block tryImplicitLambdaCast;
lambdaCastResult.success [
newSrc: @lambdaCastResult.@refToVar TRUE @processor @block createRef;
@newSrc @refToDst @processor @block createCopyToExists
] [
("types mismatch, src is " refToSrc @processor block getMplType "," LF "dst is " refToDst @processor block getMplType) assembleString @processor block compilerError
] if
] if
] if
] when
];
defaultRef: [
mutable: processor: block: ;;;
refToVar: @processor @block pop;
processor compilable [
@refToVar mutable @processor @block createRef @block push
] when
];
setRef: [
processor: block: ;;
refToVar:; # destination
compileOnce
var: refToVar getVar;
var.data.getTag VarRef = [
refToVar isVirtual [
"can not write to virtual" @processor block compilerError
] [
pointee: VarRef var.data.get.refToVar;
pointee.mutable ~ [
FALSE @processor @block defaultMakeConstWith #source
] when
processor compilable [
src: @processor @block pop;
processor compilable [
src pointee variablesAreSame [
src @block push
@src makeVarPtrCaptured
TRUE @processor @block defaultRef #source
refToVar @block push
@processor @block defaultSet
] [
src @block push
refToVar @block push
@processor @block defaultSet
] if
] when
] when
] if
] [
#rewrite value case!
src: @processor @block pop;
processor compilable [
src getVar.temporary [
src @block push
refToVar @block push
@processor @block defaultSet
] [
"rewrite value works only with temporary values" @processor block compilerError
] if
] when
] if
];
defaultMakeConstWith: [
check: processor: block: ;;;
refToVar: @processor @block pop;
processor compilable [
check [refToVar getVar.temporary new] && [
"temporary objects cannot be set const" @processor block compilerError
] [
FALSE @refToVar.setMutable
refToVar @block push
] if
] when
];
getStackEntryWith: [
depth: check: processor: block: ;; new; new;
result: @block isConst [processor.varForFails] [@processor.@varForFails] uif;
currentBlock: @block; [
currentBlock.root [
check [
"stack underflow" @processor block compilerError
] when
FALSE
] [
depth currentBlock.stack.size < [
currentBlock.stack.size 1 - depth - @[email protected] !result
check [result getVar.data.getTag VarInvalid =] && [
"stack underflow" @processor block compilerError
] when
FALSE
] [
depth currentBlock.stack.size - currentBlock.buildingMatchingInfo.inputs.size + @depth set
currentBlock.parent @[email protected] !currentBlock
TRUE
] if
] if
] loop
@result
];
getStackEntry: [depth: processor: block:;; new; depth TRUE @processor @block getStackEntryWith];
getStackEntryUnchecked: [depth: processor: block:;; new; depth FALSE processor block getStackEntryWith];
getStackDepth: [
processor: block:;;
depth: 0 dynamic;
inputsCount: 0 dynamic;
[
block.root ~ [
depth block.stack.size + @depth set
inputsCount block.buildingMatchingInfo.inputs.size + @inputsCount set
block.parent processor.blocks.at.get !block
TRUE
] &&
] loop
[inputsCount depth > ~] "Missed stack overflow!" assert
depth inputsCount -
];
{
block: Block Cref;
processor: Processor Cref;
} () {} [
processor: block:;;
hasInvalid: FALSE dynamic;
depth: 0 dynamic;
@processor @block getStackDepth [
hasInvalid ~ [
entry: i @processor block getStackEntryUnchecked;
entry getVar.data.getTag VarInvalid = [
TRUE !hasInvalid
] [
depth 1 + !depth
] if
] when
] times
("stack:" LF "depth=" depth LF) printList
depth [
entry: i @processor block getStackEntryUnchecked;
(entry @processor block getMplType entry.mutable ["R"] ["C"] if entry getVar.temporary ["T"] [""] if
entry isPlain [entry getPlainValueInformation] [String] if LF) printList
] times
] "defaultPrintStack" exportFunction
{
block: Block Cref;
processor: Processor Cref;
} () {} [
processor: block: ;;
processor.positions.size [
currentPosition: processor.positions.size 1 - i - processor.positions.at;
processor.options.hidePrefixes [currentPosition.file.name swap beginsWith ~] all [
(
"at fileName: " currentPosition.file.name
", token: " currentPosition.token
", line: " currentPosition.line
", column: " currentPosition.column LF
) printList
] when
] times
@processor block defaultPrintStack
] "defaultPrintStackTrace" exportFunction
printShadowEvent: [
event: index: building: processor: block: ;;;;;
getFileName: [
file:; file nil? ["NIL" makeStringView] [file.name makeStringView] if
];
getTopologyIndex: [
building [
.buildingTopologyIndex
] [
.topologyIndex
] if
];
(
ShadowReasonInput [
branch:;
("shadow event [" index "] input as " branch.refToVar getVar getTopologyIndex LF) printList
]
ShadowReasonCapture [
branch:;
branch.stable [
("shadow event [" index "] capture " branch.nameInfo processor.nameManager.getText " as stable name" "(" branch.nameOverloadDepth ") in " branch.file getFileName "; type " branch.refToVar @processor @block getMplType LF) printList
] [
("shadow event [" index "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar getTopologyIndex " type " branch.refToVar @processor @block getMplType LF) printList
branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) printList] when
] if
]
ShadowReasonPointee [
branch:;
("shadow event [" index "] pointee " branch.pointer getVar getTopologyIndex " as " branch.pointee getVar getTopologyIndex LF) printList
]
ShadowReasonField [
branch:;
("shadow event [" index "] field " branch.object getVar getTopologyIndex " [" branch.mplFieldIndex "] as " branch.field getVar getTopologyIndex LF) printList
]
ShadowReasonTreeSplitterLambda [
branch:;
("shadow event [" index "] tree splitter lambda " branch LF) printList
]
[]
) event.visit
];
printAstArrayTree: [
astArrayIndex: processor: block: ;;;
("Print astArrayTree for " astArrayIndex LF) printList
matchingMode: astArrayIndex processor.matchingNodes.at.get;
matchingMode.treeMemory.size [
entry: i matchingMode.treeMemory.at;
(i " nodeIndexes: ") printList
entry.nodeIndexes [v:; (v " ") printList] each
(" childs: ") printList
entry.childIndices [v:; (v.childIndex " ") printList] each
LF print
] times
];
findNameInfo: [
processor:;
];
addStackUnderflowInfo: [
processor: block:;;
newEvent: ShadowEvent;
ShadowReasonInput @newEvent.setTag
branch: ShadowReasonInput @newEvent.get;
processor.varForFails @branch.@refToVar set
ArgMeta @branch.@argCase set
@newEvent @processor @block addShadowEvent
];
nodeHasCode: [
node:;
node.emptyDeclaration ~ [node.uncompilable ~] && [node.empty ~] && [node.deleted ~] && [node.nodeCase NodeCaseCodeRefDeclaration = ~] &&
];
addBlockIdTo: [
whereNames: nameInfo: nameOverloadDepth: file: processor: block: ;;;;;;
addToLine: [
line:;
index: line.size 1 -;
result: TRUE dynamic;
[
index 0 < [index line.at.block block is ~] || [
FALSE #no such item
] [
index line.at.file file is [
FALSE !result #we have such item
FALSE
] [
index 1 - !index
TRUE #find deeper
] if
] if
] loop
result [
NameInfoCoord @line.append
block @[email protected]
file @[email protected]
nameWithOverload: NameWithOverload;
nameInfo @nameWithOverload.@nameInfo set
nameOverloadDepth @nameWithOverload.@nameOverloadDepth set
#other fields does not matter
nameWithOverload @[email protected]
] when
result
];
nameInfo whereNames.simpleNames.size < ~ [nameInfo 1 + @[email protected]] when
whereOverloads: nameInfo @[email protected];
nameOverloadDepth whereOverloads.size < ~ [nameOverloadDepth 1 + @whereOverloads.resize] when
whereIds: nameOverloadDepth @whereOverloads.at;
@whereIds addToLine
];
addEmptyCapture: [
processor: block: ;;
nameInfo: nameOverloadDepth: ;;
file:;
@processor.@captureTable nameInfo nameOverloadDepth file @processor @block addBlockIdTo [
newEvent: ShadowEvent;
ShadowReasonCapture @newEvent.setTag
branch: ShadowReasonCapture @newEvent.get;
-1 @branch.@mplFieldIndex set
processor.varForFails @branch.@refToVar set
nameInfo @branch.@nameInfo set
nameOverloadDepth @branch.@nameOverloadDepth set
file @[email protected]
ArgMeta @branch.@argCase set
@newEvent @processor @block addShadowEvent
] when
];
getShadowEventHash: [
event: whileMatching: processor: block: ;;;;
apply: [
value:;
result 0x8088405n32 * 1n32 + value xor !result
];
applyRefToVar: [
refToVar: checkMutable: ;;
var: refToVar getVar;
whileMatching [
var.topologyIndexWhileMatching Nat32 cast apply
var.staticity.end Nat32 cast apply
] [
var.buildingTopologyIndex Nat32 cast apply
var.staticity.begin Nat32 cast apply
] if
var.mplSchemaId Nat32 cast apply
var.globalId Nat32 cast apply
var.storageStaticity Nat32 cast apply
checkMutable [
refToVar.mutable [5n32][4n32] if apply
] when
refToVar isAutoStruct [
refToVar.moved [3n32][2n32] if apply
] when
refToVar isPlain [
currentStaticity: whileMatching [var.staticity.end new] [var.staticity.begin new] if;
currentStaticity Dynamic > [
var.data.getTag VarCond VarReal64 1 + [
tag:;
applyData: 0n64;
value: whileMatching [tag var.data.get.end new] [tag var.data.get.begin new] if;
value applyData storageAddress @value addressToReference set
applyData 32n32 rshift applyData 48n32 rshift xor applyData xor Nat32 cast apply
] staticCall
] when
] when
];
result: 0n32;
event.getTag Nat32 cast apply
(
ShadowReasonInput [
branch:;
# key - none
branch.refToVar TRUE applyRefToVar
]
ShadowReasonCapture [
branch:;
# key - nameInfo
branch.stable [
0n32 apply
branch.refToVar TRUE applyRefToVar
] [
10n32 apply
branch.mplFieldIndex Nat32 cast apply
branch.refToVar TRUE applyRefToVar
] if
]
ShadowReasonPointee [
branch:;
# key - pointer topologyIndex
branch.pointee TRUE applyRefToVar
]
ShadowReasonField [
branch:;
# key - object topologyIndex, object mplFieldIndex
branch.field FALSE applyRefToVar
]
ShadowReasonTreeSplitterLambda [
branch:;
# key - node
branch [0n32] [1n32] if apply
]
[]
) event.visit
result
];
sameEvents: [
event1: event2: ;;
event1.getTag event2.getTag = [
event1.getTag (
ShadowReasonInput [
# key - none
TRUE
]
ShadowReasonCapture [
# key - nameInfo
branch1: ShadowReasonCapture event1.get;
branch2: ShadowReasonCapture event2.get;
branch1.nameInfo branch2.nameInfo =
[branch1.nameOverloadDepth branch2.nameOverloadDepth =] &&
[branch1.file branch2.file is] && [
TRUE
] [
getFileName: [
file:;
file nil? ["NIL" makeStringView] [file.name makeStringView] if
];
("Capture events are different; "
LF branch1.nameInfo processor.nameManager.getText ":" branch1.nameOverloadDepth ":" branch1.file getFileName
LF branch2.nameInfo processor.nameManager.getText ":" branch2.nameOverloadDepth ":" branch2.file getFileName
LF) printList
FALSE
] if
]
ShadowReasonPointee [
# key - pointer topologyIndex
branch1: ShadowReasonPointee event1.get;
branch2: ShadowReasonPointee event2.get;
pointer1: branch1.pointer getVar;
pointer2: branch2.pointer getVar;
pointer1.buildingTopologyIndex pointer2.topologyIndex = [
TRUE
] [
("Pointee events are different; " pointer1.buildingTopologyIndex " and " pointer2.topologyIndex LF) printList
FALSE
] if
]
ShadowReasonField [
# key - object topologyIndex
branch1: ShadowReasonField event1.get;
branch2: ShadowReasonField event2.get;
object1: branch1.object getVar;
object2: branch2.object getVar;
object1.buildingTopologyIndex object2.topologyIndex =
[branch1.mplFieldIndex branch2.mplFieldIndex =] && [
TRUE
] [
("Field events are different; " object1.buildingTopologyIndex ":" branch1.mplFieldIndex " and " object2.topologyIndex ":" branch2.mplFieldIndex LF) printList
FALSE
] if
]
ShadowReasonTreeSplitterLambda [
# key - none
TRUE
]
[
("Event tags are invalid; " event1.getTag LF) printList
FALSE
]
) case
] [
("Event tags are different; " event1.getTag " and " event2.getTag LF) printList
FALSE
] if
];
compareShadows: [
processor:;
comparingMessage:;
whileMatching:;
checkConstness:;
refToVar2:;
refToVar1:;
refToVar1 refToVar2 whileMatching checkConstness @comparingMessage FALSE @processor compareOnePair
];
compareTopologyIndex: [
refToVar1: refToVar2: whileMatching: ;;;
var1: refToVar1 getVar;
var2: refToVar2 getVar;
ti1: refToVar1 noMatterToCopy [-1][
whileMatching [
var1.topologyIndexWhileMatching new
] [
var1.buildingTopologyIndex new
] if
] if;
ti2: refToVar2 noMatterToCopy [-1][
whileMatching [
var2.topologyIndex new
] [
var2.topologyIndex new
] if
] if;
ti1 ti2 =
];
compareEvents: [
event1: event2: comparingMessage: whileMatching: processor: ;;;;;
result: TRUE;
event1.getTag event2.getTag = [
event1.getTag (
ShadowReasonInput [
branch1: ShadowReasonInput event1.get;
branch2: ShadowReasonInput event2.get;
branch1.refToVar branch2.refToVar whileMatching compareTopologyIndex
[branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [
FALSE !result
] when
]
ShadowReasonCapture [
branch1: ShadowReasonCapture event1.get;
branch2: ShadowReasonCapture event2.get;
branch1.stable branch2.stable and [
branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows ~ [
FALSE !result
] when
] [
branch1.stable ~ branch2.stable ~ and
[branch1.refToVar branch2.refToVar whileMatching compareTopologyIndex] &&
[branch1.mplFieldIndex branch2.mplFieldIndex =] &&
[branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [
FALSE !result
] when
] if
]
ShadowReasonPointee [
branch1: ShadowReasonPointee event1.get;
branch2: ShadowReasonPointee event2.get;
branch1.pointee branch2.pointee whileMatching compareTopologyIndex
[branch1.pointee branch2.pointee TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [
FALSE !result
] when
]
ShadowReasonField [
branch1: ShadowReasonField event1.get;
branch2: ShadowReasonField event2.get;
branch1.field branch2.field whileMatching compareTopologyIndex
[branch1.field branch2.field FALSE whileMatching @comparingMessage @processor compareShadows] && ~ [
FALSE !result
] when
]
ShadowReasonTreeSplitterLambda [
branch1: ShadowReasonTreeSplitterLambda event1.get;
branch2: ShadowReasonTreeSplitterLambda event2.get;
branch1 branch2 = ~ [
FALSE !result
] when
]
[]
) case
] [
FALSE !result
] if
result
];
deleteMatchingNodeFrom: [
processor: block: matchingChindIndex: full: ;;;;
matchingChindIndex 0 < ~ [
astArrayIndex: block.astArrayIndex new;
matchingNode: astArrayIndex @[email protected];
currentMemory: matchingChindIndex @[email protected];
index: -1 dynamic;
i: currentMemory.nodeIndexes.size 1 -;
[i 0 < ~ index 0 < and] [
i currentMemory.nodeIndexes.at block.id = [
i @index set
] when
i 1 - !i
] while
full [
index: matchingChindIndex new;
[
parentIndex: index matchingNode.treeMemory.at.parentIndex new;
parentIndex 0 < ~ [
parentNode: parentIndex @[email protected];
parentNode.childIndices.size 1 = [
i: parentNode.childIndices.size 1 -;
[i 0 < ~ [i parentNode.childIndices.at.childIndex index = ~] &&] [
i 1 - !i
] while
[i 0 < ~] "No such child in parent in matchingTree!" assert
parentIndex @index set
TRUE
] &&
] &&
] loop
] when
index 0 < ~ [
index @[email protected]
] when
] when
];
deleteMatchingNode: [
processor: block: full: ;;;
block.matchingChindIndex 0 < ~ [
@processor @block block.matchingChindIndex full deleteMatchingNodeFrom
-1 @block.@matchingChindIndex set
] when
];
addShadowEvent: [
event: processor: block: ;;;
block.astArrayIndex 0 < ~ [
#begin of var go to matching
event @block.@[email protected]
block.state NodeStateNew = [
event @block.@[email protected]
] when
block.recursionState NodeRecursionStateNew = [
] [
addChild: [
event: machingMemoryNode:;;
matchingNodePair: MatchingNodePair;
result: matchingNode.treeMemory.size;
eventHash @matchingNodePair.@eventHash set
result @matchingNodePair.@childIndex set
@matchingNodePair @[email protected]
newMatchingNodeEntry: MatchingNodeEntry;
event @newMatchingNodeEntry.@parentEvent set
currentEntryIndex @newMatchingNodeEntry.@parentIndex set
@newMatchingNodeEntry @[email protected]
result
];
currentEntryIndex: block.matchingChindIndex new;
comparingMessage: String;
matchingNode: block.astArrayIndex @[email protected];
currentMemory: currentEntryIndex @[email protected];
eventHash: event FALSE dynamic @processor @block getShadowEventHash;
currentMemory.childIndices.size 0 = [
event @currentMemory addChild @currentEntryIndex set
] [
pattern: 0 currentMemory.childIndices @ .childIndex matchingNode.treeMemory.at.parentEvent;
[
event pattern sameEvents [
("First event is new event; second is pattern; astNode index = " block.astArrayIndex LF) printList
("Current try matching events: " LF) printList
block.buildingMatchingInfo.shadowEvents.size [
event: i block.buildingMatchingInfo.shadowEvents.at;
getFileName: [
file:; file nil? ["NIL" makeStringView] [file.name makeStringView] if
];
(
ShadowReasonInput [
branch:;
("shadow event [" i "] input as " branch.refToVar getVar.buildingTopologyIndex LF) printList
]
ShadowReasonCapture [
branch:;
branch.stable [
("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText " as stable name" LF) printList
] [
("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar.buildingTopologyIndex " type " branch.refToVar @processor @block getMplType LF) printList
branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) printList] when
] if
]
ShadowReasonPointee [
branch:;
("shadow event [" i "] pointee " branch.pointer getVar.buildingTopologyIndex " as " branch.pointee getVar.buildingTopologyIndex LF) printList
]
ShadowReasonField [
branch:;
("shadow event [" i "] field " branch.object getVar.buildingTopologyIndex " [" branch.mplFieldIndex "] as " branch.field getVar.buildingTopologyIndex LF) printList
]
ShadowReasonTreeSplitterLambda [
branch:;
("shadow event [" i "] tree splitter lambda " branch LF) printList
]
[]
) event.visit
] times
FALSE
] ||
] "Matching events are not consistent" assert
candidates: @currentMemory.@childIndices;
prevEventIndex: -1 dynamic;
candidates [
prevVersion:;
prevEventIndex 0 < [
prevVersion.eventHash eventHash = [
prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent;
event prevVersionEvent @comparingMessage FALSE dynamic @processor compareEvents
] && [
prevVersion.childIndex @prevEventIndex set
] when
] when
] each
prevEventIndex 0 < [
candidates [
prevVersion:;
prevEventIndex 0 < [
prevVersion.eventHash eventHash = [
prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent;
event prevVersionEvent @comparingMessage FALSE dynamic @processor compareEvents
] && [
prevVersion.childIndex @prevEventIndex set
] when
] when
] each
event @currentMemory addChild @currentEntryIndex set
] [
prevEventIndex @currentEntryIndex set
] if
] if
@processor @block FALSE deleteMatchingNode
currentEntryIndex @block.@matchingChindIndex set
currentMemory: currentEntryIndex @[email protected];
block.id @[email protected]
] if
] when
];
getTopNode: [
processor: topNode:;;
[topNode.parent 0 = ~] [
topNode.parent @[email protected] !topNode
] while
@topNode
];