/
dispatchers.nqp
4053 lines (3818 loc) Β· 201 KB
/
dispatchers.nqp
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
# Some maximum cache sizes we allow at a callsite before we switch to a
# megamorphic strategy.
my int $MEGA-TYPE-CALLSITE-SIZE := 16;
my int $MEGA-METH-CALLSITE-SIZE := 16;
# Return value decontainerization dispatcher. Often we have nothing at all
# to do, in which case we can make it identity. Other times, we need a
# decont. In a few, we need to re-wrap it.
{
my $container-fallback := -> $Iterable, $cont {
if nqp::isrwcont($cont) {
# It's an RW container, so we really need to decont it.
my $rv := nqp::decont($cont);
if nqp::istype($rv, $Iterable) {
my $rc := nqp::create(Scalar);
nqp::bindattr($rc, Scalar, '$!value', $rv);
$rc
}
else {
$rv
}
}
else {
# A read-only container, so just return it.
$cont
}
}
my $recont := -> $obj {
my $rc := nqp::create(Scalar);
nqp::bindattr($rc, Scalar, '$!value', nqp::decont($obj));
$rc
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-rv-decont', -> $capture {
# If it's heading megamorphic, then we'll install the fallback, without
# any conditions, which is faster than over-filling the cache and running
# this dispatch logic every time.
my int $cache-size := nqp::dispatch('boot-syscall', 'dispatcher-inline-cache-size');
if $cache-size >= $MEGA-TYPE-CALLSITE-SIZE {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, nqp::gethllsym('Raku', 'Iterable')),
0, $container-fallback));
}
else {
# We always need to guard on type and concreteness.
my $rv := nqp::captureposarg($capture, 0);
my $rv_arg := nqp::dispatch('boot-syscall', 'dispatcher-track-arg',
$capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $rv_arg);
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $rv_arg);
# Is it a container?
if nqp::isconcrete_nd($rv) && nqp::iscont($rv) {
# It's a container. We have special cases for Scalar.
if nqp::istype_nd($rv, Scalar) {
# Check if the descriptor is undefined, in which case it's read-only.
my $desc := nqp::getattr($rv, Scalar, '$!descriptor');
my $desc_arg := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$rv_arg, Scalar, '$!descriptor');
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $desc_arg);
if nqp::isconcrete($desc) {
# Writeable, so we may need to recontainerize the value if
# the type is iterable, otherwise we can decont it.
my $value := nqp::getattr($rv, Scalar, '$!value');
my $value_arg := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$rv_arg, Scalar, '$!value');
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $value_arg);
if nqp::istype_nd($value, nqp::gethllsym('Raku', 'Iterable')) {
# Need to recont in order to preserve item nature.
# Shuffle in the recont code to invoke. We already
# read the deconted value, so we insert that as the
# arg so it needn't be dereferenced again.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg',
nqp::dispatch('boot-syscall', 'dispatcher-drop-arg',
$capture, 0),
0, $value_arg),
0, $recont));
}
else {
# Decont, so just evaluate to the read attr (boot-value
# ignores all but the first argument).
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg',
$capture, 0, $value_arg));
}
}
else {
# Read-only, so identity will do.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
}
else {
# Delegate to non-Scalar container fallback.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, nqp::gethllsym('Raku', 'Iterable')),
0, $container-fallback));
}
}
else {
# Not containerizied, so identity shall do,
# Unless it is null, then we map it to Mu.
if nqp::isnull($rv) {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, Mu));
}
else {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
}
}
});
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-rv-decont-6c', -> $capture {
# This emulates a bug where Proxy was never decontainerized no
# matter what. The ecosystem came to depend on that, so we will
# accept it for now. We need to revisit this in the future.
my $rv := nqp::captureposarg($capture, 0);
if nqp::eqaddr(nqp::what_nd($rv), Proxy) && nqp::isconcrete_nd($rv) {
my $rv_arg := nqp::dispatch('boot-syscall', 'dispatcher-track-arg',
$capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $rv_arg);
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $rv_arg);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
else {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-rv-decont', $capture);
}
});
}
# Assignment dispatcher, which case-analyzes assignments and provides optimized
# paths for a range of common situations, and typically lifting type checks to
# be guards.
{
sub assign-type-error($desc, $value) {
Perl6::Metamodel::Configuration.throw_or_die(
'X::TypeCheck::Assignment',
"Type check failed in assignment",
:symbol($desc.name),
:$desc,
:got($value),
:expected($desc.of)
);
}
my $assign-fallback := -> $cont, $value {
nqp::assign($cont, $value)
}
my $assign-scalar-no-whence-no-typecheck := -> $cont, $value {
nqp::bindattr($cont, Scalar, '$!value', $value)
}
my $assign-scalar-nil-no-whence := -> $cont, $value {
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
nqp::bindattr($cont, Scalar, '$!value',
nqp::getattr($desc, ContainerDescriptor, '$!default'))
}
my $assign-scalar-no-whence := -> $cont, $value {
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
my $type := nqp::getattr($desc, ContainerDescriptor, '$!of');
if nqp::istype($value, $type) {
if nqp::how_nd($type).archetypes.coercive {
$value := nqp::dispatch('raku-coercion', $type, $value);
}
nqp::bindattr($cont, Scalar, '$!value', $value);
}
else {
assign-type-error($desc, $value);
}
}
my $assign-scalar-bindpos-no-typecheck := -> $cont, $value {
nqp::bindattr($cont, Scalar, '$!value', $value);
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
nqp::bindpos(
nqp::getattr($desc, ContainerDescriptor::BindArrayPos, '$!target'),
nqp::getattr_i($desc, ContainerDescriptor::BindArrayPos, '$!pos'),
$cont);
nqp::bindattr($cont, Scalar, '$!descriptor',
nqp::getattr($desc, ContainerDescriptor::BindArrayPos, '$!next-descriptor'));
}
my $assign-scalar-bindpos := -> $cont, $value {
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
my $next := nqp::getattr($desc, ContainerDescriptor::BindArrayPos, '$!next-descriptor');
my $type := nqp::getattr($next, ContainerDescriptor, '$!of');
if nqp::istype($value, $type) {
if nqp::how_nd($type).archetypes.coercive {
$value := nqp::dispatch('raku-coercion', $type, $value);
}
nqp::bindattr($cont, Scalar, '$!value', $value);
nqp::bindpos(
nqp::getattr($desc, ContainerDescriptor::BindArrayPos, '$!target'),
nqp::getattr_i($desc, ContainerDescriptor::BindArrayPos, '$!pos'),
$cont);
nqp::bindattr($cont, Scalar, '$!descriptor', $next);
}
else {
assign-type-error($next, $value);
}
}
my $assign-scalar-uninit-no-typecheck := -> $cont, $value {
nqp::bindattr($cont, Scalar, '$!value', $value);
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
nqp::bindattr($cont, Scalar, '$!descriptor',
nqp::getattr($desc, ContainerDescriptor::UninitializedAttribute,
'$!next-descriptor'));
}
my $assign-scalar-uninit := -> $cont, $value {
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
my $next := nqp::getattr($desc, ContainerDescriptor::UninitializedAttribute,
'$!next-descriptor');
my $type := nqp::getattr($next, ContainerDescriptor, '$!of');
if nqp::istype($value, $type) {
if nqp::how_nd($type).archetypes.coercive {
$value := nqp::dispatch('raku-coercion', $type, $value);
}
nqp::bindattr($cont, Scalar, '$!value', $value);
nqp::bindattr($cont, Scalar, '$!descriptor', $next);
}
else {
assign-type-error($next, $value);
}
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-assign', -> $capture {
# Whatever we do, we'll guard on the type of the container and its
# concreteness.
my $tracked-cont := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-cont);
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $tracked-cont);
# We have various fast paths for an assignment to a Scalar.
my int $optimized := 0;
my $cont := nqp::captureposarg($capture, 0);
if nqp::eqaddr(nqp::what_nd($cont), Scalar) && nqp::isconcrete_nd($cont) {
# Now see what the Scalar descriptor type is.
my $tracked-desc := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$tracked-cont, Scalar, '$!descriptor');
my $desc := nqp::getattr($cont, Scalar, '$!descriptor');
my $tracked-value := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 1);
my $value := nqp::captureposarg($capture, 1);
if nqp::eqaddr($desc.WHAT, ContainerDescriptor) && nqp::isconcrete($desc) {
# Simple assignment, no whence. But is Nil being assigned?
my $of := $desc.of;
if nqp::eqaddr($value, Nil) {
# Yes; just copy in the default, provided we've a simple type.
if $of.HOW.archetypes.nominal {
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-value);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-desc);
my $tracked-of := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$tracked-desc, ContainerDescriptor, '$!of');
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal', $tracked-of);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $assign-scalar-nil-no-whence));
$optimized := 1;
}
}
else {
# No whence, no Nil. Is it a nominal type? If yes, we can check
# it here.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-desc);
if $of.HOW.archetypes.nominal && nqp::istype($value, $of) {
# Nominal and passes type check; stack up gurads and delegate to
# simple bind.
my $tracked-of := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$tracked-desc, ContainerDescriptor, '$!of');
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal', $tracked-of);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-value);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $assign-scalar-no-whence-no-typecheck));
$optimized := 1;
}
else {
# Non-nominal or type check error.
nqp::dispatch('boot-syscall', 'dispatcher-guard-not-literal-obj', $tracked-value, Nil);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $assign-scalar-no-whence));
$optimized := 1;
}
}
}
elsif nqp::eqaddr($desc.WHAT, ContainerDescriptor::Untyped) && nqp::isconcrete($desc) {
if nqp::eqaddr($value, Nil) {
# Nil case is NYI.
}
else {
# Assignment to an untyped container descriptor; no type check
# is required, just bind the value into place.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-desc);
nqp::dispatch('boot-syscall', 'dispatcher-guard-not-literal-obj',
$tracked-value, Nil);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $assign-scalar-no-whence-no-typecheck));
$optimized := 1;
}
}
elsif nqp::eqaddr($desc.WHAT, ContainerDescriptor::UninitializedAttribute)
&& nqp::isconcrete($desc) {
# First assignment to an attribute where we care about whether it
# was assigned to. We can produce a fast path for this, though
# should check what the ultimate descriptor is. It really should
# be a normal, boring, container descriptor.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-desc);
my $next := nqp::getattr($desc, ContainerDescriptor::UninitializedAttribute,
'$!next-descriptor');
if nqp::eqaddr($next.WHAT, ContainerDescriptor) ||
nqp::eqaddr($next.WHAT, ContainerDescriptor::Untyped) {
# Ensure we're not assigning Nil (not yet fast-pathed, but
# probably not terribly likely).
unless nqp::eqaddr($value.WHAT, Nil) {
# Go by whether we can type check the target.
my $tracked-next := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$tracked-desc, ContainerDescriptor::UninitializedAttribute,
'$!next-descriptor');
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal',
$tracked-next);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-value);
my $of := $next.of;
my $delegate := $of.HOW.archetypes.nominal &&
(nqp::eqaddr($of, Mu) || nqp::istype($value, $of))
?? $assign-scalar-uninit-no-typecheck
!! $assign-scalar-uninit;
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $delegate));
$optimized := 1;
}
}
}
elsif nqp::eqaddr($desc.WHAT, ContainerDescriptor::BindArrayPos) {
# Bind into an array. We can produce a fast path for this, though
# should check what the ultimate descriptor is. It really should
# be a normal, boring, container descriptor.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-desc);
my $next := nqp::getattr($desc, ContainerDescriptor::BindArrayPos,
'$!next-descriptor');
if nqp::eqaddr($next.WHAT, ContainerDescriptor) ||
nqp::eqaddr($next.WHAT, ContainerDescriptor::Untyped) {
# Ensure we're not assigning Nil. (This would be very odd, as
# a Scalar starts off with its default value, and if we are
# vivifying we'll likely have a new container).
unless nqp::eqaddr($value.WHAT, Nil) {
# Go by whether we can type check the target.
my $tracked-next := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$tracked-desc, ContainerDescriptor::BindArrayPos,
'$!next-descriptor');
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal',
$tracked-next);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $tracked-value);
my $of := $next.of;
my $delegate := $of.HOW.archetypes.nominal &&
(nqp::eqaddr($of, Mu) || nqp::istype($value, $of))
?? $assign-scalar-bindpos-no-typecheck
!! $assign-scalar-bindpos;
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $delegate));
$optimized := 1;
}
}
}
}
# If nothing we could optimize, go for the fallback.
unless $optimized {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $assign-fallback));
}
});
}
# Binding type assertion dispatcher, used to do type checks of binds. Evaluates
# to the value itself when the type check passes, installing a guard along the
# way. Otherwise, throws.
{
sub bind-error($value, $type) {
Perl6::Metamodel::Configuration.throw_or_die(
'X::TypeCheck::Binding',
"Type check failed in binding; expected '" ~
nqp::how_nd($type).name($value) ~ "' but got '" ~
nqp::how_nd($value).name($value) ~ "'",
:got($value),
:expected($type)
);
}
my $bind-check := -> $value, $value-decont, $type {
nqp::istype_nd($value-decont, $type) ?? $value !! bind-error($value, $type)
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-bind-assert', -> $capture {
my $value-decont := nqp::captureposarg($capture, 1);
my $type := nqp::captureposarg($capture, 2);
if nqp::how_nd($type).archetypes.nominal {
if nqp::istype_nd($value-decont, $type) {
# Nominal, so a type guard on the decont'd value will suffice,
# then produce the original value.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 1));
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 2));
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
else {
my $value := nqp::captureposarg($capture, 0);
bind-error($value, $type)
}
}
else {
# Not a nominal type, can't guard it, so set up a call to do the
# check late-bound.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 2));
my $delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $capture, 0, $bind-check);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
$delegate);
}
});
}
# Object construction time checking of if a container is initialized. Done as
# a dispatcher primarily to intern .^mixin_type, but also for more compact
# bytecode size in generated BUILDALL.
my $array-init-check := -> $arr {
my $storage := nqp::getattr($arr, List, '$!reified');
nqp::isconcrete($storage) && nqp::elems($storage)
}
my $hash-init-check := -> $hash {
my $storage := nqp::getattr($hash, Map, '$!storage');
nqp::isconcrete($storage) && nqp::elems($storage)
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-is-attr-inited', -> $capture {
# If there's a non-concrete object observed, then we bound a non-container
# in place, so trivially initialized.
my $attr := nqp::captureposarg($capture, 0);
my $track-attr := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0);
my int $inited := 0;
my $need-elem-check;
if !nqp::isconcrete_nd($attr) {
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $track-attr);
$inited := 1;
}
# Otherwise, might be a container that was assigned.
else {
# Just try and read a descriptor. Also see if we have an array or
# hash, which needs an additional element check to handle an
# assignment to an individual element during BUILD.
my $base;
my $desc;
my $track-desc;
try {
$base := nqp::how_nd($attr).mixin_base($attr);
$desc := nqp::getattr($attr, $base, '$!descriptor');
$track-desc := nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$track-attr, $base, '$!descriptor');
}
# If we managed to track a descriptor, when we have a container to
# see if was uninitialized. The attribute tracking above will have
# established type/concreteness guards on the attribute, so don't
# repeat them.
if $track-desc {
# Guard on the descriptor type, then outcome depends on if if
# it's an uninitialized attribute descriptor. If it is, then
# for arrays and hashes we also need an extra check.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $track-desc);
$inited := !nqp::eqaddr($desc.WHAT, ContainerDescriptor::UninitializedAttribute);
if nqp::istype($base, Array) {
$need-elem-check := $array-init-check;
}
elsif nqp::istype($base, Hash) {
$need-elem-check := $hash-init-check;
}
}
# Otherwise, bound concrete value. Guard on type and concreteness,
# outcome is that it's initialized.
else {
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $track-attr);
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $track-attr);
$inited := 1;
}
}
# Evaluate to result.
if nqp::isconcrete($need-elem-check) && !$inited {
# The descriptor suggests it's not initialized by assignment to
# the entire array/hash, but individual elements may have been.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, $need-elem-check));
}
else {
# It's certainly initialized per the descriptor, so we're done.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-int',
$capture, 0, $inited));
}
});
# Sink dispatcher. Called in void context with the decontainerized value to sink.
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-sink', -> $capture {
# Guard on the type and concreteness.
my $sinkee := nqp::captureposarg($capture, 0);
my $track-sinkee := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $track-sinkee);
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $track-sinkee);
# Now consider what we're sinking.
if nqp::isconcrete_nd($sinkee) {
# Concrete. See if it has a `sink` method, and then also if it's not
# Mu.sink, which is a no-op.
my $meth := nqp::decont(nqp::how_nd($sinkee).find_method($sinkee, 'sink'));
if nqp::isconcrete($meth) && !nqp::eqaddr($meth, Mu.HOW.find_method(Mu, 'sink')) {
# Need to do a call to the sink method. Since sink is a Raku thing,
# assume we can go straight for the Raku method dispatcher.
my $with-name := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-str', $capture, 0, 'sink');
my $with-type := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $with-name, 0, nqp::what_nd($sinkee));
my $with-callee := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $with-type, 0, $meth);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $with-callee);
}
else {
# Nothing to do (use boot-value and let void context take care of
# discarding the value).
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
}
else {
# Not concrete, nothing to do.
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-value', $capture);
}
});
# Coercion dispatcher. The first argument is the value to coerce, the second
# is what to coerce it into.
{
sub coercion_error($from_name, $to_name) {
nqp::die("Unable to coerce the from $from_name to $to_name; " ~
"no coercion method defined");
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-coerce', -> $capture {
my $to_coerce := nqp::captureposarg($capture, 0);
my $coerce_type := nqp::captureposarg($capture, 1);
# See if there is a method named for the type.
my str $to_name := nqp::how_nd($coerce_type).name($coerce_type);
my $coerce_method := nqp::decont(nqp::how_nd($to_coerce).find_method($to_coerce, $to_name));
if nqp::isconcrete($coerce_method) {
# Delegate to the resolved method call dispatcher. We need to drop
# the arg of the coercion type, then insert three args:
# 1. The method we resolved to.
# 2. The type object of the coercion type (used in deferral)
# 3. The name of the method (used in deferral)
my $without_coerce_type := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg',
$capture, 1);
my $meth_capture := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-str',
$without_coerce_type,
0, $to_name),
0, nqp::what(to_coerce)),
0, $coerce_method);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $meth_capture);
}
else {
coercion_error(nqp::how_nd($to_coerce).name($to_coerce), $to_name);
}
});
}
# A standard call (such as `func($arg)`, `$obj($arg)`, etc.) It receives the
# decontainerized callee as the first argument, followed by the arguments. Its
# primary purpose is to deal with multi dispatch vs. single dispatch and then
# delegate on to the appropriate dispatcher. It also looks at if we are doing a
# call to a method (either because it was looked up separately, or because we
# are here via lang-call), and in that case sends it via the resolved method
# call dispatcher. This means it will have a working nextsame etc.
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-call', -> $capture {
# Guard on the type and, if it's a routine, on the dispatchees. (We assume
# that the set of dispatchees shall not change, even over closure clones -
# this may not always be a good assumption - and so we guard on that. If
# it's not a dispatcher, we'll be guarding on a literal type object.)
my $track_callee := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $track_callee);
my $callee := nqp::captureposarg($capture, 0);
if nqp::istype_nd($callee, Method) && (my str $meth-name := $callee.name) &&
(my $inv_param := try { $callee.signature.params.AT-POS(0) }) {
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal', $track_callee);
my $meth-type := $inv_param.type;
my $with-type := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 1, $meth-type);
my $with-name := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-str',
$with-type, 2, $meth-name);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-meth-call-resolved',
$with-name);
}
elsif nqp::istype_nd($callee, Routine) {
if nqp::can($callee, 'WRAPPERS') {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-invoke-wrapped', $capture);
}
elsif nqp::can($callee, 'CALL-ME') {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-invoke', $capture);
}
else {
my int $code-constant := nqp::dispatch('boot-syscall', 'dispatcher-is-arg-literal',
$capture, 0);
unless $code-constant {
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal',
nqp::dispatch('boot-syscall', 'dispatcher-track-attr',
$track_callee, Routine, '@!dispatchees'));
}
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
$callee.is_dispatcher ?? 'raku-multi' !! 'raku-invoke', $capture);
}
}
else {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-invoke', $capture);
}
});
# A standard method call of the form $obj.meth($arg); also used for the
# indirect form $obj."$name"($arg). It receives the decontainerized invocant,
# the method name, and the the args (starting with the invocant including any
# container).
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-call', -> $capture {
# See if this callsite is heading megamorphic due to loads of different
# method names or types; if so, we'll try to cope with that.
my $obj := nqp::captureposarg($capture, 0);
my str $name := nqp::captureposarg_s($capture, 1);
my $how := nqp::how_nd($obj);
my int $cache-size := nqp::dispatch('boot-syscall', 'dispatcher-inline-cache-size');
if $cache-size >= $MEGA-METH-CALLSITE-SIZE && nqp::istype($how, Perl6::Metamodel::ClassHOW) {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-meth-call-mega',
$capture);
}
else {
# See if we're making the method lookup on a pun; if so, rewrite the args
# to do the call on the pun.
if nqp::istype($how, Perl6::Metamodel::RolePunning) &&
$how.is_method_call_punned($obj, $name) {
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0));
$obj := $how.pun($obj);
$how := $obj.HOW;
$capture := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0),
0, $obj);
$capture := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 2),
2, $obj);
}
# Try to resolve the method call.
# TODO Assorted optimizations are possible here later on to speed up some
# kinds of dispatch, including:
# * Using the dispatcher to directly rewrite args and invoke FALLBACK if
# needed
# * Handling some forms of delegation via the dispatcher mechanism
my $meth := nqp::decont($how.find_method($obj, $name));
# Report an error if there is no such method.
unless nqp::isconcrete($meth) {
my $class := nqp::getlexcaller('$?CLASS');
report-method-not-found($obj, $name, $class, $how, nqp::iscont($obj));
}
# Establish a guard on the invocant type and method name (however the name
# may well be a literal, in which case this is free).
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0));
nqp::dispatch('boot-syscall', 'dispatcher-guard-literal',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 1));
# Add the resolved method and delegate to the resolved method dispatcher.
my $capture_delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $capture, 0, $meth);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $capture_delegate);
}
});
sub report-method-not-found($obj, $name, $class, $how, $containerized) {
my $msg := "Method '$name' not found for invocant of class '{$how.name($obj)}'";
if $name eq 'STORE' {
Perl6::Metamodel::Configuration.throw_or_die(
'X::Assignment::RO', $msg, :value($obj));
}
else {
Perl6::Metamodel::Configuration.throw_or_die(
'X::Method::NotFound',
$msg,
:invocant($obj),
:method($name),
:typename($how.name($obj)),
:private(nqp::hllboolfor(0, 'Raku')),
:in-class-call(nqp::hllboolfor(nqp::eqaddr(nqp::what($obj), $class), 'Raku')),
:containerized(nqp::hllboolfor($containerized, 'Raku'))
);
}
}
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-call-mega', -> $capture {
# We're megamorphic in both type and name. Make sure the type has a lookup
# table, and ensure the method exists. If it does not have a method table
# then we will not install this dispatcher; we may already have a type
# megamorphic handler in place and only missed it because we temporarily
# lacked the calculated flattened method table. This avoids us stacking
# up the same program repeatedly at the callsite.
my $obj := nqp::captureposarg($capture, 0);
my $how := nqp::how_nd($obj);
unless nqp::isconcrete(nqp::getattr($how, Perl6::Metamodel::ClassHOW,
'$!cached_all_method_table')) {
nqp::dispatch('boot-syscall', 'dispatcher-do-not-install');
}
my %lookup := $how.all_method_table($obj);
my str $name := nqp::captureposarg_s($capture, 1);
if nqp::isconcrete(nqp::atkey(%lookup, $name)) {
# It exists. We'll set up a dispatch program that tracks the HOW of
# the type, looks up the cached method table on it, and then tracks
# the resolution of the method.
my $track-obj := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0);
my $track-how := nqp::dispatch('boot-syscall', 'dispatcher-track-how', $track-obj);
my $track-table := nqp::dispatch('boot-syscall', 'dispatcher-track-attr', $track-how,
Perl6::Metamodel::ClassHOW, '$!cached_all_method_table');
my $track-name := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 1);
my $track-resolution := nqp::dispatch('boot-syscall',
'dispatcher-index-tracked-lookup-table', $track-table, $track-name);
# This is only a valid dispatch program if the method is found. (If
# not, we'll run this again to report the error.)
nqp::dispatch('boot-syscall', 'dispatcher-guard-concreteness', $track-resolution);
# Add the resolved method and delegate to the resolved method dispatcher.
my $capture-delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg', $capture, 0, $track-resolution);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $capture-delegate);
}
else {
# Probably method not found, but sometimes the cache ends up missing
# entries.
my $slowpath-found := $how.find_method($obj, $name);
if nqp::isconcrete($slowpath-found) {
nqp::dispatch('boot-syscall', 'dispatcher-do-not-install');
my $capture-delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $capture, 0, $slowpath-found);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $capture-delegate);
}
else {
my $class := nqp::getlexcaller('$?CLASS');
report-method-not-found($obj, $name, $class, $how, nqp::iscont($obj));
}
}
});
# Qualified method call dispatcher. This is used for calls of the form
# $foo.Some::ClassOrRole::bar($arg). It receives the decontainerized
# invocant, the method name, the type qualifier, and then the args
# (starting with the invocant including any container).
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-call-qualified', -> $capture {
# Lookup outers of the caller and locate the first occurence of the
# symbols of interest, which tell us about the caller type.
my $ctx := nqp::ctxcaller(nqp::ctx());
my $caller-type := nqp::null();
nqp::repeat_while(
nqp::isnull($caller-type) && !nqp::isnull($ctx),
nqp::stmts(
(my $pad := nqp::ctxlexpad($ctx)),
nqp::if(
nqp::existskey($pad, '$?CONCRETIZATION'),
($caller-type := nqp::atkey($pad, '$?CONCRETIZATION')),
nqp::if(
nqp::existskey($pad, '$?CLASS'),
($caller-type := nqp::atkey($pad, '$?CLASS')),
)
),
($ctx := nqp::ctxouterskipthunks($ctx)),
)
);
# Establish a guard on the invocant and qualifying type.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0));
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 2));
# Try to resolve the method.
my $obj := nqp::captureposarg($capture, 0);
my str $name := nqp::captureposarg_s($capture, 1);
my $type := nqp::captureposarg($capture, 2);
my $meth;
for ($caller-type, $obj.WHAT) {
if nqp::istype($_, $type) {
$meth := nqp::how_nd($_).find_method_qualified($_, $type, $name);
last if nqp::isconcrete($meth);
}
}
# If it's resolved, then:
# 1. Drop the invocant and type arguments targetted at this resolution
# 2. Insert the type we resolved the method against before those, for
# deferral (the name is retained ahead of this)
# 3. Finally, prepend the resolved method, and delegate to the resolved
# method dispatcher.
if nqp::isconcrete($meth) {
my $with_name_and_args := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg',
nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 2),
0);
my $with_resolution_start := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $with_name_and_args, 0, $type);
my $capture_delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $with_resolution_start, 0, $meth);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $capture_delegate);
}
# Otherwise, exception.
else {
Perl6::Metamodel::Configuration.throw_or_die(
'X::Method::InvalidQualifier',
"Cannot dispatch to method $name on " ~ nqp::how_nd($type).name($type) ~
" because it is not inherited or done by " ~ nqp::how_nd($obj).name($obj),
:method($name), :invocant($obj), :qualifier-type($type));
}
});
# Maybe method dispatch, of the form $obj.?foo.
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-call-me-maybe', -> $capture {
# Establish a guard on the invocant type.
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0));
# Try to find the method.
my $invocant := nqp::captureposarg($capture, 0);
my str $name := nqp::captureposarg_s($capture, 1);
my $meth := nqp::decont(nqp::how_nd($invocant).find_method($invocant, $name));
if nqp::isconcrete($meth) {
# Found it. Put in resolved method and leave the rest to the resolved
# method call dispatcher.
my $capture_delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj', $capture, 0, $meth);
nqp::dispatch('boot-syscall', 'dispatcher-delegate',
'raku-meth-call-resolved', $capture_delegate);
}
else {
# Not found. Insert a Nil value at the start (boot-constant ignores
# the rest of the args).
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, Nil));
}
});
# Private method dispatch. This is actually a fallback, since in the best
# case we can resolve the private method into a constant at code-gen time
# and just invoke that. This happens with private methods in roles.
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-private', -> $capture {
# Find the private method.
my $type := nqp::captureposarg($capture, 0);
my str $name := nqp::captureposarg_s($capture, 1);
my $meth := nqp::how_nd($type).find_private_method($type, $name);
# If it's found, then we drop the first two arguments, insert the
# resolved callee, and invoke it. This goes directly to invoke, as
# there's no deferral (due to no inheritance relationship) or multi
# dispatch for private methods.
if nqp::isconcrete($meth) {
nqp::dispatch('boot-syscall', 'dispatcher-guard-type',
nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0));
my $capture_delegate := nqp::dispatch('boot-syscall',
'dispatcher-insert-arg-literal-obj',
nqp::dispatch('boot-syscall', 'dispatcher-drop-n-args',
$capture, 0, 2),
0, $meth);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'raku-invoke',
$capture_delegate);
}
else {
# TODO typed exception
nqp::die("No such private method '$name' on " ~ nqp::how_nd($type).name($type));
}
});
# A linked list is used to model the state of a dispatch that is deferring
# through a set of methods or wrappers (a similar approach is used for
# multi dispatch, but it needs more types of node). The Exhausted class
# is used as a sentinel for the end of the chain (or for dispatchers in
# general that have nothing more to contribute). The current state of the
# dispatch points into the linked list at the appropriate point; the chain
# itself is immutable, and shared over (runtime) dispatches.
my class DeferralChain {
has $!code;
has $!next;
method new($code, $next) {
my $obj := nqp::create(self);
nqp::bindattr($obj, DeferralChain, '$!code', $code);
nqp::bindattr($obj, DeferralChain, '$!next', $next);
$obj
}
method code() { $!code }
method next() { $!next }
};
my class Exhausted {};
# We also need a strategy for `callwith`. The complication is that arguments
# given to `callwith` should trigger a resumption of the innermost dispatch
# (for example, a wrap), but should also influence the arguments of outer
# dispatches too (for example, a multi and/or method dispatch). The overall
# strategy for `callwith` is:
# 1. Dispatchers for resumable dispatches are always broken into two parts:
# one that manages the initial dispatch when there is no resume, and
# another that walks through the candidates.
# 2. When we do a `callwith`, the current innermost of those dispatchers
# marks itself exhausted. It then re-enters itself, passing along a
# resumption of kind PROPAGATE_CALLWITH. This includes the information
# required to put the next immediate call of the innermost dispatch
# into effect (more in a moment on this).
# 3. The re-entered dispatcher sets its resume init args up using the
# arguments from the callwith propagation, so that a later `callsame`
# will use the correct arguments.
# 4. It then tries to use next-resumption to pass the callwith propagation
# to any enclosing dispatcher. This always uses a common protocol: the
# arguments are a kind (the PROPAGATE_CALLWITH integer constant), a
# dispatcher name (string argument), a flag for if the arguments include
# the invocant (an integer), followed by (typically) some arguments to
# the named dispatcher. This is the information required to send the
# dispatch to the destination determined by the *innermost* dispatcher.
# 5. If there is no next resumption, then we do that call.
# 6. Any outer dispatcher, upon receiving a PROPAGATE_CALLWITH, will mark
# itself exhausted and re-enter itself with the new arguments. It then
# continues with the above process from step 4.
# Thus, a callwith in the case there is an active wrap, multi, and method
# dispatch, ends up with all the previous resumable dispatchers for these
# marked as exhausted, and new ones created, with the updated arguments.
# One all of these updated dispatchers are in place, then finally the next
# candidate of the innermost dispatch is invoked.
sub nil-or-callwith-propagation-terminal($capture) {
unless nqp::dispatch('boot-syscall', 'dispatcher-next-resumption', $capture) {
if nqp::captureposarg_i($capture, 0) == nqp::const::DISP_PROPAGATE_CALLWITH {
my str $dispatcher := nqp::captureposarg_s($capture, 1);
my $invoke-args := nqp::dispatch('boot-syscall', 'dispatcher-drop-n-args',
$capture, 0, 3);
nqp::dispatch('boot-syscall', 'dispatcher-delegate', $dispatcher, $invoke-args);
}
else {
nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant',
nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj',
$capture, 0, Nil));
}
}
}
# Resolved method call dispatcher. This is used to call a method, once we have
# already resolved it to a callee. Its first arg is the callee, the second and
# third are the type and name (used in deferral), and the rest are the args to
# the method.
nqp::dispatch('boot-syscall', 'dispatcher-register', 'raku-meth-call-resolved',
# Initial dispatch
-> $capture {
# Save dispatch state for resumption. We don't need the method that will
# be called now, so drop it.
my $resume-capture := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg',
$capture, 0);
nqp::dispatch('boot-syscall', 'dispatcher-set-resume-init-args', $resume-capture);
# Drop the dispatch start type and name, and delegate to multi-dispatch or
# just invoke if it's single dispatch.
my $delegate_capture := nqp::dispatch('boot-syscall', 'dispatcher-drop-n-args',
$capture, 1, 2);
my $method := nqp::captureposarg($delegate_capture, 0);
my int $code-constant := nqp::dispatch('boot-syscall', 'dispatcher-is-arg-literal',