/
program.c
1843 lines (1752 loc) · 82.8 KB
/
program.c
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
#include "moar.h"
/* Debug dumping, to figure out what we're recording and what programs we are
* inferring from those recordings. */
#define DUMP_RECORDINGS 0
#define DUMP_PROGRAMS 0
#if DUMP_RECORDINGS
static void dump_recording_capture(MVMThreadContext *tc,
MVMDispProgramRecordingCapture *capture, MVMuint32 indent,
MVMDispProgramRecording *rec) {
char *indent_str = alloca(indent + 1);
memset(indent_str, ' ', indent);
indent_str[indent] = '\0';
switch (capture->transformation) {
case MVMDispProgramRecordingInitial:
fprintf(stderr, "%sInitial\n", indent_str);
break;
case MVMDispProgramRecordingDrop:
fprintf(stderr, "%sDrop argument %d\n", indent_str, capture->index);
break;
case MVMDispProgramRecordingInsert:
fprintf(stderr, "%sInsert value %d at %d\n", indent_str, capture->value_index,
capture->index);
break;
default:
fprintf(stderr, "%sUnknown transforamtion\n", indent_str);
break;
}
if (capture->capture == rec->outcome_capture)
fprintf(stderr, "%s Used as args for invoke result\n", indent_str);
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->resume_inits); i++) {
if (rec->resume_inits[i].capture == capture->capture) {
char *disp_id = MVM_string_utf8_encode_C_string(tc, rec->resume_inits[i].disp->id);
fprintf(stderr, "%s Used as resume init args for %s\n", indent_str, disp_id);
MVM_free(disp_id);
}
}
for (i = 0; i < MVM_VECTOR_ELEMS(capture->captures); i++)
dump_recording_capture(tc, &(capture->captures[i]), indent + 2, rec);
}
static void dump_recording_values(MVMThreadContext *tc, MVMDispProgramRecording *rec) {
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->values); i++) {
MVMDispProgramRecordingValue *v = &(rec->values[i]);
switch (v->source) {
case MVMDispProgramRecordingCaptureValue:
fprintf(stderr, " %d Initial argument %d\n", i, v->capture.index);
break;
case MVMDispProgramRecordingLiteralValue:
switch (v->literal.kind) {
case MVM_CALLSITE_ARG_OBJ:
fprintf(stderr, " %d Literal object of type %s\n", i,
v->literal.value.o->st->debug_name);
break;
case MVM_CALLSITE_ARG_INT:
fprintf(stderr, " %d Literal int value %"PRId64"\n", i,
v->literal.value.i64);
break;
case MVM_CALLSITE_ARG_NUM:
fprintf(stderr, " %d Literal num value %g\n", i,
v->literal.value.n64);
break;
case MVM_CALLSITE_ARG_STR:
fprintf(stderr, " %d Literal str value\n", i);
break;
default:
fprintf(stderr, " %d Literal value of unknown kind\n", i);
}
break;
case MVMDispProgramRecordingAttributeValue:
fprintf(stderr, " %d Attribute value from offset %d of value %d \n", i,
v->attribute.offset, v->attribute.from_value);
break;
default:
fprintf(stderr, " %d Unknown\n", i);
}
if (v->guard_literal) {
fprintf(stderr, " Guard literal value\n");
}
else {
if (v->guard_type && v->guard_concreteness)
fprintf(stderr, " Guard type and concreteness\n");
else if (v->guard_type)
fprintf(stderr, " Guard type\n");
else if (v->guard_concreteness)
fprintf(stderr, " Guard concreteness\n");
}
}
};
static void dump_recording(MVMThreadContext *tc, MVMCallStackDispatchRecord *record) {
fprintf(stderr, "Dispatch recording\n");
fprintf(stderr, " Captures:\n");
dump_recording_capture(tc, &(record->rec.initial_capture), 4, &(record->rec));
fprintf(stderr, " Values:\n");
dump_recording_values(tc, &(record->rec));
fprintf(stderr, " Outcome:\n");
switch (record->outcome.kind) {
case MVM_DISP_OUTCOME_VALUE:
printf(" Value %d\n", record->rec.outcome_value);
break;
case MVM_DISP_OUTCOME_BYTECODE:
printf(" Run bytecode of value %d\n", record->rec.outcome_value);
break;
case MVM_DISP_OUTCOME_CFUNCTION:
printf(" Run C function of value %d\n", record->rec.outcome_value);
break;
default:
printf(" Unknown\n");
}
}
#else
#define dump_recording(tc, r) do {} while (0)
#endif
#if DUMP_PROGRAMS
static void dump_program(MVMThreadContext *tc, MVMDispProgram *dp) {
if (dp->first_args_temporary == dp->num_temporaries)
fprintf(stderr, "Dispatch program (%d temporaries)\n", dp->num_temporaries);
else
fprintf(stderr, "Dispatch program (%d temporaries, args from %d)\n",
dp->num_temporaries, dp->first_args_temporary);
MVMuint32 i;
for (i = 0; i < dp->num_ops; i++) {
MVMDispProgramOp *op = &(dp->ops[i]);
switch (op->code) {
/* Opcodes that guard on values in argument slots */
case MVMDispOpcodeGuardArgType:
fprintf(stderr, " Guard arg %d (type=%s)\n",
op->arg_guard.arg_idx,
((MVMSTable *)dp->gc_constants[op->arg_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardArgTypeConc:
fprintf(stderr, " Guard arg %d (type=%s, concrete)\n",
op->arg_guard.arg_idx,
((MVMSTable *)dp->gc_constants[op->arg_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardArgTypeTypeObject:
fprintf(stderr, " Guard arg %d (type=%s, type object)\n",
op->arg_guard.arg_idx,
((MVMSTable *)dp->gc_constants[op->arg_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardArgConc:
fprintf(stderr, " Guard arg %d (concrete)\n",
op->arg_guard.arg_idx);
break;
case MVMDispOpcodeGuardArgTypeObject:
fprintf(stderr, " Guard arg %d (type object)\n",
op->arg_guard.arg_idx);
break;
case MVMDispOpcodeGuardArgLiteralObj:
fprintf(stderr, " Guard arg %d (literal object of type %s)\n",
op->arg_guard.arg_idx,
STABLE(((MVMObject *)dp->gc_constants[op->arg_guard.checkee]))->debug_name);
break;
case MVMDispOpcodeGuardArgLiteralStr: {
char *c_str = MVM_string_utf8_encode_C_string(tc,
((MVMString *)dp->gc_constants[op->arg_guard.checkee]));
fprintf(stderr, " Guard arg %d (literal string '%s')\n",
op->arg_guard.arg_idx, c_str);
MVM_free(c_str);
break;
}
case MVMDispOpcodeGuardArgLiteralInt:
fprintf(stderr, " Guard arg %d (literal integer %"PRIi64")\n",
op->arg_guard.arg_idx,
dp->constants[op->arg_guard.checkee].i64);
break;
case MVMDispOpcodeGuardArgLiteralNum:
fprintf(stderr, " Guard arg %d (literal number %g)\n",
op->arg_guard.arg_idx,
dp->constants[op->arg_guard.checkee].n64);
break;
case MVMDispOpcodeGuardArgNotLiteralObj:
fprintf(stderr, " Guard arg %d (not literal object of type %s)\n",
op->arg_guard.arg_idx,
STABLE(((MVMObject *)dp->gc_constants[op->arg_guard.checkee]))->debug_name);
break;
/* Opcodes that guard on values in temporaries */
case MVMDispOpcodeGuardTempType:
fprintf(stderr, " Guard temp %d (type=%s)\n",
op->temp_guard.temp,
((MVMSTable *)dp->gc_constants[op->temp_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardTempTypeConc:
fprintf(stderr, " Guard temp %d (type=%s, concrete)\n",
op->temp_guard.temp,
((MVMSTable *)dp->gc_constants[op->temp_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardTempTypeTypeObject:
fprintf(stderr, " Guard temp %d (type=%s, type object)\n",
op->temp_guard.temp,
((MVMSTable *)dp->gc_constants[op->temp_guard.checkee])->debug_name);
break;
case MVMDispOpcodeGuardTempConc:
fprintf(stderr, " Guard temp %d (concrete)\n",
op->temp_guard.temp);
break;
case MVMDispOpcodeGuardTempTypeObject:
fprintf(stderr, " Guard temp %d (type object)\n",
op->temp_guard.temp);
break;
case MVMDispOpcodeGuardTempLiteralObj:
fprintf(stderr, " Guard temp %d (literal object of type %s)\n",
op->temp_guard.temp,
STABLE(((MVMObject *)dp->gc_constants[op->temp_guard.checkee]))->debug_name);
break;
case MVMDispOpcodeGuardTempLiteralStr: {
char *c_str = MVM_string_utf8_encode_C_string(tc,
((MVMString *)dp->gc_constants[op->temp_guard.checkee]));
fprintf(stderr, " Guard temp %d (literal string '%s')\n",
op->temp_guard.temp, c_str);
MVM_free(c_str);
break;
}
case MVMDispOpcodeGuardTempLiteralInt:
fprintf(stderr, " Guard temp %d (literal integer %"PRIi64")\n",
op->temp_guard.temp,
dp->constants[op->temp_guard.checkee].i64);
break;
case MVMDispOpcodeGuardTempLiteralNum:
fprintf(stderr, " Guard temp %d (literal number %g)\n",
op->temp_guard.temp,
dp->constants[op->temp_guard.checkee].n64);
break;
case MVMDispOpcodeGuardTempNotLiteralObj:
fprintf(stderr, " Guard temp %d (not literal object of type %s)\n",
op->temp_guard.temp,
STABLE(((MVMObject *)dp->gc_constants[op->temp_guard.checkee]))->debug_name);
break;
/* Opcodes that load values into temporaries. */
case MVMDispOpcodeLoadCaptureValue:
fprintf(stderr, " Load argument %d into temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadConstantObjOrStr:
fprintf(stderr, " Load collectable constant at index %d into temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadConstantInt:
fprintf(stderr, " Load integer constant at index %d into temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadConstantNum:
fprintf(stderr, " Load number constant at index %d into temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadAttributeObj:
fprintf(stderr, " Deference object attribute at offset %d in temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadAttributeInt:
fprintf(stderr, " Deference integer attribute at offset %d in temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadAttributeNum:
fprintf(stderr, " Deference number attribute at offset %d in temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeLoadAttributeStr:
fprintf(stderr, " Deference string attribute at offset %d in temporary %d\n",
op->load.idx, op->load.temp);
break;
case MVMDispOpcodeSet:
fprintf(stderr, " Copy temporary %d into temporary %d\n",
op->load.idx, op->load.temp);
break;
/* Opcodes that set a result value */
case MVMDispOpcodeResultValueObj:
fprintf(stderr, " Set result object value from temporary %d\n",
op->res_value.temp);
break;
case MVMDispOpcodeResultValueStr:
fprintf(stderr, " Set result string value from temporary %d\n",
op->res_value.temp);
break;
case MVMDispOpcodeResultValueInt:
fprintf(stderr, " Set result integer value from temporary %d\n",
op->res_value.temp);
break;
case MVMDispOpcodeResultValueNum:
fprintf(stderr, " Set result num value from temporary %d\n",
op->res_value.temp);
break;
/* Opcodes that handle invocation results. */
case MVMDispOpcodeUseArgsTail:
fprintf(stderr, " Skip first %d args of incoming capture; callsite from %d\n",
op->use_arg_tail.skip_args, op->use_arg_tail.callsite_idx);
break;
case MVMDispOpcodeCopyArgsTail:
fprintf(stderr, " Copy final %d args of incoming capture; callsite from %d\n",
op->copy_arg_tail.tail_args, op->copy_arg_tail.callsite_idx);
break;
case MVMDispOpcodeResultBytecode:
fprintf(stderr, " Invoke MVMCode in temporary %d\n",
op->res_code.temp_invokee);
break;
case MVMDispOpcodeResultCFunction:
fprintf(stderr, " Invoke MVMCFunction in temporary %d\n",
op->res_code.temp_invokee);
break;
default:
fprintf(stderr, " UNKNOWN OP %d\n", op->code);
}
}
}
#else
#define dump_program(tc, dp) do {} while (0)
#endif
/* Run a dispatch callback, which will record a dispatch program. */
static MVMFrame * find_calling_frame(MVMCallStackRecord *prev) {
/* Typically, we'll have the frame right off, but if there was flattening,
* we need to skip that frame between the two. */
while (prev->kind == MVM_CALLSTACK_RECORD_FLATTENING ||
prev->kind == MVM_CALLSTACK_RECORD_START_REGION)
prev = prev->prev;
return MVM_callstack_record_to_frame(prev);
}
static void run_dispatch(MVMThreadContext *tc, MVMCallStackDispatchRecord *record,
MVMDispDefinition *disp, MVMObject *capture, MVMuint32 *thunked) {
MVMCallsite *disp_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);
record->current_disp = disp;
record->current_capture.o = capture;
MVMArgs dispatch_args = {
.callsite = disp_callsite,
.source = &(record->current_capture),
.map = MVM_args_identity_map(tc, disp_callsite)
};
MVMObject *dispatch = disp->dispatch;
if (REPR(dispatch)->ID == MVM_REPR_ID_MVMCFunction) {
record->outcome.kind = MVM_DISP_OUTCOME_FAILED;
((MVMCFunction *)dispatch)->body.func(tc, dispatch_args);
MVM_callstack_unwind_dispatch_record(tc, thunked);
}
else if (REPR(dispatch)->ID == MVM_REPR_ID_MVMCode) {
record->outcome.kind = MVM_DISP_OUTCOME_EXPECT_DELEGATE;
record->outcome.delegate_disp = NULL;
record->outcome.delegate_capture = NULL;
tc->cur_frame = find_calling_frame(tc->stack_top->prev);
MVM_frame_dispatch(tc, (MVMCode *)dispatch, dispatch_args, -1);
if (thunked)
*thunked = 1;
}
else {
MVM_panic(1, "dispatch callback only supported as a MVMCFunction or MVMCode");
}
}
void MVM_disp_program_run_dispatch(MVMThreadContext *tc, MVMDispDefinition *disp,
MVMObject *capture, MVMDispInlineCacheEntry **ic_entry_ptr,
MVMDispInlineCacheEntry *ic_entry, MVMStaticFrame *update_sf) {
/* Push a dispatch recording frame onto the callstack; this is how we'll
* keep track of the current recording state. */
MVMCallStackDispatchRecord *record = MVM_callstack_allocate_dispatch_record(tc);
record->rec.initial_capture.capture = capture;
record->rec.initial_capture.transformation = MVMDispProgramRecordingInitial;
MVM_VECTOR_INIT(record->rec.initial_capture.captures, 8);
MVM_VECTOR_INIT(record->rec.values, 16);
MVM_VECTOR_INIT(record->rec.resume_inits, 4);
record->rec.outcome_capture = NULL;
record->ic_entry_ptr = ic_entry_ptr;
record->ic_entry = ic_entry;
record->update_sf = update_sf;
run_dispatch(tc, record, disp, capture, NULL);
}
/* Calculates the path to a capture. If the capture is not found, then an
* exception will be thrown. The caller should pass in a pointer to a
* CapturePath, which will be populated with the path to that capture. */
typedef struct {
MVM_VECTOR_DECL(MVMDispProgramRecordingCapture *, path);
} CapturePath;
static MVMuint32 find_capture(MVMThreadContext *tc, MVMDispProgramRecordingCapture *current,
MVMObject *searchee, CapturePath *p) {
MVM_VECTOR_PUSH(p->path, current);
if (current->capture == searchee)
return 1;
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(current->captures); i++)
if (find_capture(tc, &(current->captures[i]), searchee, p))
return 1;
MVM_VECTOR_POP(p->path);
return 0;
}
static void calculate_capture_path(MVMThreadContext *tc, MVMCallStackDispatchRecord *record,
MVMObject *capture, CapturePath *p) {
if (!find_capture(tc, &(record->rec.initial_capture), capture, p)) {
MVM_VECTOR_DESTROY(p->path);
MVM_exception_throw_adhoc(tc,
"Can only use manipulate a capture known in this dispatch");
}
}
static void ensure_known_capture(MVMThreadContext *tc, MVMCallStackDispatchRecord *record,
MVMObject *capture) {
CapturePath p;
MVM_VECTOR_INIT(p.path, 8);
calculate_capture_path(tc, record, capture, &p);
MVM_VECTOR_DESTROY(p.path);
}
/* Ensures we have a constant recorded as a value. If there already is such
* an entry, we re-use it and return its index. If not, we add a value entry. */
static MVMuint32 value_index_constant(MVMThreadContext *tc, MVMDispProgramRecording *rec,
MVMCallsiteFlags kind, MVMRegister value) {
/* Look for an existing such value. */
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->values); i++) {
MVMDispProgramRecordingValue *v = &(rec->values[i]);
if (v->source == MVMDispProgramRecordingLiteralValue && v->literal.kind == kind) {
switch (kind) {
case MVM_CALLSITE_ARG_OBJ:
if (v->literal.value.o == value.o)
return i;
break;
case MVM_CALLSITE_ARG_INT:
if (v->literal.value.i64 == value.i64)
return i;
break;
case MVM_CALLSITE_ARG_NUM:
if (v->literal.value.n64 == value.n64)
return i;
break;
case MVM_CALLSITE_ARG_STR:
if (v->literal.value.s == value.s)
return i;
break;
default:
MVM_oops(tc, "Unknown kind of literal value in dispatch constant");
}
}
}
/* Otherwise, we need to create the value entry. */
MVMDispProgramRecordingValue new_value;
memset(&new_value, 0, sizeof(MVMDispProgramRecordingValue));
new_value.source = MVMDispProgramRecordingLiteralValue;
new_value.literal.kind = kind;
new_value.literal.value = value;
MVM_VECTOR_PUSH(rec->values, new_value);
return MVM_VECTOR_ELEMS(rec->values) - 1;
}
/* Ensures we have a values used entry for the specified argument index. */
static MVMuint32 value_index_capture(MVMThreadContext *tc, MVMDispProgramRecording *rec,
MVMuint32 index) {
/* Look for an existing such value. */
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->values); i++) {
MVMDispProgramRecordingValue *v = &(rec->values[i]);
if (v->source == MVMDispProgramRecordingCaptureValue && v->capture.index == index)
return i;
}
/* Otherwise, we need to create the value entry. */
MVMDispProgramRecordingValue new_value;
memset(&new_value, 0, sizeof(MVMDispProgramRecordingValue));
new_value.source = MVMDispProgramRecordingCaptureValue;
new_value.capture.index = index;
MVM_VECTOR_PUSH(rec->values, new_value);
return MVM_VECTOR_ELEMS(rec->values) - 1;
}
/* Ensures we have a values used entry for the specified attribute read. */
static MVMuint32 value_index_attribute(MVMThreadContext *tc, MVMDispProgramRecording *rec,
MVMuint32 from_value, MVMuint32 offset, MVMCallsiteFlags kind) {
/* Look for an existing such value. */
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->values); i++) {
MVMDispProgramRecordingValue *v = &(rec->values[i]);
if (v->source == MVMDispProgramRecordingAttributeValue &&
v->attribute.from_value == from_value &&
v->attribute.offset == offset &&
v->attribute.kind == kind)
return i;
}
/* Otherwise, we need to create the value entry. */
MVMDispProgramRecordingValue new_value;
memset(&new_value, 0, sizeof(MVMDispProgramRecordingValue));
new_value.source = MVMDispProgramRecordingAttributeValue;
new_value.attribute.from_value = from_value;
new_value.attribute.offset = offset;
new_value.attribute.kind = kind;
MVM_VECTOR_PUSH(rec->values, new_value);
return MVM_VECTOR_ELEMS(rec->values) - 1;
}
/* Resolves a tracked value to a value index, throwing if it's not found. */
static MVMuint32 find_tracked_value_index(MVMThreadContext *tc,
MVMDispProgramRecording *rec, MVMObject *tracked) {
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(rec->values); i++)
if (rec->values[i].tracked == tracked)
return i;
MVM_exception_throw_adhoc(tc, "Dispatcher tracked value not found");
}
/* Start tracking an argument from the specified capture. This allows us to
* apply guards against it. */
MVMObject * MVM_disp_program_record_track_arg(MVMThreadContext *tc, MVMObject *capture,
MVMuint32 index) {
/* Obtain the value from the capture. This ensures that it is in range. */
MVMRegister value;
MVMCallsiteFlags kind;
MVM_capture_arg_pos(tc, capture, index, &value, &kind);
/* Ensure the incoming capture is known. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
CapturePath p;
MVM_VECTOR_INIT(p.path, 8);
calculate_capture_path(tc, record, capture, &p);
/* Walk the capture path to resolve the index. We start at the deepest
* point and work upward in the tree. */
MVMint32 i;
MVMuint32 real_index = index;
MVMint32 found_value_index = -1;
for (i = MVM_VECTOR_ELEMS(p.path) - 1; i >= 0; i--) {
switch (p.path[i]->transformation) {
case MVMDispProgramRecordingInsert:
/* It's an insert. Was the insert at the index we are dealing
* with? */
if (p.path[i]->index == real_index) {
/* Yes, and so it will have a value_index, which is what
* we ultimately need. */
found_value_index = p.path[i]->value_index;
break;
}
else {
/* No, so we may need to adjust the offset. Before this
* operation we had:
* before1, before2, after1, after2
* And now have:
* before1, before2, inserted, after1, after2
* Thus we need to adjust the current index by subtracting
* 1 if it's after the insertion point. */
if (real_index > p.path[i]->index)
real_index--;
}
break;
case MVMDispProgramRecordingDrop:
/* An argument was dropped here. Before the drop, we'd have
* had:
* before1, before2, dropped, after1, after2
* And now we have:
* before1, before2, after1, after2
* And so any index greater than or equal to the drop index
* needs to have 1 added to get its previous index. */
if (real_index >= p.path[i]->index)
real_index++;
break;
case MVMDispProgramRecordingInitial:
/* We have reached the initial capture, and so the index is
* for it. */
break;
}
}
MVM_VECTOR_DESTROY(p.path);
/* If we didn't find a value index, then we're referencing the original
* capture; ensure there's a value index for that. */
if (found_value_index < 0)
found_value_index = value_index_capture(tc, &(record->rec), real_index);
/* Ensure there is a tracked value object and return it. */
if (!record->rec.values[found_value_index].tracked)
record->rec.values[found_value_index].tracked = MVM_tracked_create(tc, value, kind);
return record->rec.values[found_value_index].tracked;
}
/* Start tracking an attribute read against the given tracked object. This
* lets us read the attribute in the dispatch program and use it in a result
* capture, for example. */
MVMObject * MVM_disp_program_record_track_attr(MVMThreadContext *tc, MVMObject *tracked_in,
MVMObject *class_handle, MVMString *name) {
/* Ensure the tracked value is an object type. */
if (((MVMTracked *)tracked_in)->body.kind != MVM_CALLSITE_ARG_OBJ)
MVM_exception_throw_adhoc(tc, "Can only use dispatcher-track-attr on a tracked object");
/* Resolve the tracked value. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked_in);
/* Obtain the object and ensure it is a concrete P6opaque; also track its
* type and concreteness since attr read safety depends on this. */
MVMObject *read_from = ((MVMTracked *)tracked_in)->body.value.o;
if (REPR(read_from)->ID != MVM_REPR_ID_P6opaque)
MVM_exception_throw_adhoc(tc, "Can only use dispatcher-track-attr on a P6opaque");
if (!IS_CONCRETE(read_from))
MVM_exception_throw_adhoc(tc, "Can only use dispatcher-track-attr on a concrete object");
record->rec.values[value_index].guard_type = 1;
record->rec.values[value_index].guard_concreteness = 1;
/* Work out the index that the value lives at, along with its kind, and
* then read the value. */
size_t offset;
MVMCallsiteFlags attr_kind;
MVM_p6opaque_attr_offset_and_arg_type(tc, read_from, class_handle, name, &offset, &attr_kind);
MVMRegister attr_value;
switch (attr_kind) {
case MVM_CALLSITE_ARG_OBJ:
attr_value.o = MVM_p6opaque_read_object(tc, read_from, offset);
if (attr_value.o == NULL) /* Hopefully this can be an error eventually */
attr_value.o = tc->instance->VMNull;
break;
case MVM_CALLSITE_ARG_INT:
attr_value.i64 = MVM_p6opaque_read_int64(tc, read_from, offset);
break;
case MVM_CALLSITE_ARG_NUM:
attr_value.n64 = MVM_p6opaque_read_num64(tc, read_from, offset);
break;
case MVM_CALLSITE_ARG_STR:
attr_value.s = MVM_p6opaque_read_str(tc, read_from, offset);
break;
default:
MVM_oops(tc, "Unhandled attribute kind when trying to track attribute");
}
/* Ensure that we have this attribute read in the values table, and make
* a tracked object if not. */
MVMuint32 result_value_index = value_index_attribute(tc, &(record->rec),
value_index, (MVMuint32)offset, attr_kind);
if (!record->rec.values[result_value_index].tracked)
record->rec.values[result_value_index].tracked = MVM_tracked_create(tc,
attr_value, attr_kind);
return record->rec.values[result_value_index].tracked;
}
/* Record a guard of the current type of the specified tracked value. */
void MVM_disp_program_record_guard_type(MVMThreadContext *tc, MVMObject *tracked) {
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
record->rec.values[value_index].guard_type = 1;
}
/* Record a guard of the current concreteness of the specified tracked value. */
void MVM_disp_program_record_guard_concreteness(MVMThreadContext *tc, MVMObject *tracked) {
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
record->rec.values[value_index].guard_concreteness = 1;
}
/* Record a guard of the current value of the specified tracked value. */
void MVM_disp_program_record_guard_literal(MVMThreadContext *tc, MVMObject *tracked) {
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
record->rec.values[value_index].guard_literal = 1;
}
/* Record a guard that the specified tracked value must not be a certain object
* literal. */
void MVM_disp_program_record_guard_not_literal_obj(MVMThreadContext *tc,
MVMObject *tracked, MVMObject *object) {
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
MVM_VECTOR_PUSH(record->rec.values[value_index].not_literal_guards, object);
}
/* Record that we drop an argument from a capture. Also perform the drop,
* resulting in a new capture without that argument. */
MVMObject * MVM_disp_program_record_capture_drop_arg(MVMThreadContext *tc, MVMObject *capture,
MVMuint32 idx) {
/* Lookup the path to the incoming capture. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
CapturePath p;
MVM_VECTOR_INIT(p.path, 8);
calculate_capture_path(tc, record, capture, &p);
/* Calculate the new capture and add a record for it. */
MVMObject *new_capture = MVM_capture_drop_arg(tc, capture, idx);
MVMDispProgramRecordingCapture new_capture_record = {
.capture = new_capture,
.transformation = MVMDispProgramRecordingDrop,
.index = idx
};
MVM_VECTOR_INIT(new_capture_record.captures, 0);
MVMDispProgramRecordingCapture *update = p.path[MVM_VECTOR_ELEMS(p.path) - 1];
MVM_VECTOR_PUSH(update->captures, new_capture_record);
MVM_VECTOR_DESTROY(p.path);
/* Evaluate to the new capture, for the running dispatch function. */
return new_capture;
}
/* Record that we insert a tracked value into a capture. Also perform the insert
* on the value that was read. */
MVMObject * MVM_disp_program_record_capture_insert_arg(MVMThreadContext *tc,
MVMObject *capture, MVMuint32 idx, MVMObject *tracked) {
/* Lookup the index of the tracked value. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
/* Also look up the path to the incoming capture. */
CapturePath p;
MVM_VECTOR_INIT(p.path, 8);
calculate_capture_path(tc, record, capture, &p);
/* Calculate the new capture and add a record for it. */
MVMObject *new_capture = MVM_capture_insert_arg(tc, capture, idx,
((MVMTracked *)tracked)->body.kind, ((MVMTracked *)tracked)->body.value);
MVMDispProgramRecordingCapture new_capture_record = {
.capture = new_capture,
.transformation = MVMDispProgramRecordingInsert,
.index = idx,
.value_index = value_index
};
MVM_VECTOR_INIT(new_capture_record.captures, 0);
MVMDispProgramRecordingCapture *update = p.path[MVM_VECTOR_ELEMS(p.path) - 1];
MVM_VECTOR_PUSH(update->captures, new_capture_record);
MVM_VECTOR_DESTROY(p.path);
/* Evaluate to the new capture, for the running dispatch function. */
return new_capture;
}
/* Record that we insert a new constant argument from a capture. Also perform the
* insert, resulting in a new capture without a new argument inserted at the
* given index. */
MVMObject * MVM_disp_program_record_capture_insert_constant_arg(MVMThreadContext *tc,
MVMObject *capture, MVMuint32 idx, MVMCallsiteFlags kind, MVMRegister value) {
/* Lookup the path to the incoming capture. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
CapturePath p;
MVM_VECTOR_INIT(p.path, 8);
calculate_capture_path(tc, record, capture, &p);
/* Obtain a new value index for the constant. */
MVMuint32 value_index = value_index_constant(tc, &(record->rec), kind, value);
/* Calculate the new capture and add a record for it. */
MVMObject *new_capture = MVM_capture_insert_arg(tc, capture, idx, kind, value);
MVMDispProgramRecordingCapture new_capture_record = {
.capture = new_capture,
.transformation = MVMDispProgramRecordingInsert,
.index = idx,
.value_index = value_index
};
MVM_VECTOR_INIT(new_capture_record.captures, 0);
MVMDispProgramRecordingCapture *update = p.path[MVM_VECTOR_ELEMS(p.path) - 1];
MVM_VECTOR_PUSH(update->captures, new_capture_record);
MVM_VECTOR_DESTROY(p.path);
/* Evaluate to the new capture, for the running dispatch function. */
return new_capture;
}
/* Record the setting of the dispatch resume init args (the arguments that
* should be made available for initializing resumption). */
void MVM_disp_program_record_set_resume_init_args(MVMThreadContext *tc, MVMObject *capture) {
/* Make sure we're in a resumable dispatcher and that the capture is
* tracked. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
if (!record->current_disp->resume)
MVM_exception_throw_adhoc(tc,
"Can only use dispatcher-set-resume-init-args in a resumable dispatcher");
ensure_known_capture(tc, record, capture);
/* Record the saving of the resume init state for this dispatcher, making
* sure we didn't already do so. */
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(record->rec.resume_inits); i++)
if (record->rec.resume_inits[i].disp == record->current_disp)
MVM_exception_throw_adhoc(tc, "Already set resume init args for this dispatcher");
MVMDispProgramRecordingResumeInit new_resume_init;
new_resume_init.disp = record->current_disp;
new_resume_init.capture = capture;
MVM_VECTOR_PUSH(record->rec.resume_inits, new_resume_init);
}
/* Record the getting of the dispatch rsume init args. */
MVMObject * MVM_disp_program_record_get_resume_init_args(MVMThreadContext *tc) {
/* Make sure we're in a dispatcher. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVM_panic(1, "get resume init args nyi");
}
/* Record a delegation from one dispatcher to another. */
void MVM_disp_program_record_delegate(MVMThreadContext *tc, MVMString *dispatcher_id,
MVMObject *capture) {
/* We can only do a single dispatcher delegation. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
if (record->outcome.delegate_disp != NULL)
MVM_exception_throw_adhoc(tc,
"Can only call dispatcher-delegate once in a dispatch callback");
/* Resolve the dispatcher we wish to delegate to, and ensure that this
* capture is one we know about. Then stash the info. */
MVMDispDefinition *disp = MVM_disp_registry_find(tc, dispatcher_id);
ensure_known_capture(tc, record, capture);
record->outcome.delegate_disp = disp;
record->outcome.delegate_capture = capture;
}
/* Record a program terminator that is a constant object value. */
void MVM_disp_program_record_result_constant(MVMThreadContext *tc, MVMCallsiteFlags kind,
MVMRegister value) {
/* Record the result action. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
record->rec.outcome_value = value_index_constant(tc, &(record->rec), kind, value);
/* Put the return value in place. */
record->outcome.kind = MVM_DISP_OUTCOME_VALUE;
record->outcome.result_value = value;
switch (kind) {
case MVM_CALLSITE_ARG_OBJ: record->outcome.result_kind = MVM_reg_obj; break;
case MVM_CALLSITE_ARG_INT: record->outcome.result_kind = MVM_reg_int64; break;
case MVM_CALLSITE_ARG_NUM: record->outcome.result_kind = MVM_reg_num64; break;
case MVM_CALLSITE_ARG_STR: record->outcome.result_kind = MVM_reg_str; break;
default: MVM_oops(tc, "Unknown capture value type in boot-constant dispatch");
}
}
/* Record a program terminator that reads the value from an argument capture. */
void MVM_disp_program_record_result_tracked_value(MVMThreadContext *tc, MVMObject *tracked) {
/* Look up the tracked value and note it as the outcome value. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
MVMuint32 value_index = find_tracked_value_index(tc, &(record->rec), tracked);
record->rec.outcome_value = value_index;
/* Put the return value in place. */
record->outcome.kind = MVM_DISP_OUTCOME_VALUE;
record->outcome.result_value = ((MVMTracked *)tracked)->body.value;
switch (((MVMTracked *)tracked)->body.kind) {
case MVM_CALLSITE_ARG_OBJ: record->outcome.result_kind = MVM_reg_obj; break;
case MVM_CALLSITE_ARG_INT: record->outcome.result_kind = MVM_reg_int64; break;
case MVM_CALLSITE_ARG_NUM: record->outcome.result_kind = MVM_reg_num64; break;
case MVM_CALLSITE_ARG_STR: record->outcome.result_kind = MVM_reg_str; break;
default: MVM_oops(tc, "Unknown capture value type in boot-value dispatch");
}
}
/* Record a program terminator that invokes an MVMCode object, which is to be
* considered a constant (e.g. so long as the guards that come before this
* point match, the thing to invoke is always this code object). */
void MVM_disp_program_record_code_constant(MVMThreadContext *tc, MVMCode *result, MVMObject *capture) {
/* Record the result action. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
ensure_known_capture(tc, record, capture);
MVMRegister value = { .o = (MVMObject *)result };
record->rec.outcome_value = value_index_constant(tc, &(record->rec),
MVM_CALLSITE_ARG_OBJ, value);
record->rec.outcome_capture = capture;
/* Set up the invoke outcome. */
MVMCallsite *callsite = ((MVMCapture *)capture)->body.callsite;
record->outcome.kind = MVM_DISP_OUTCOME_BYTECODE;
record->outcome.code = result;
record->outcome.args.callsite = callsite;
record->outcome.args.map = MVM_args_identity_map(tc, callsite);
record->outcome.args.source = ((MVMCapture *)capture)->body.args;
}
/* Record a program terminator that invokes an MVMCFunction object, which is to be
* considered a constant. */
void MVM_disp_program_record_c_code_constant(MVMThreadContext *tc, MVMCFunction *result,
MVMObject *capture) {
/* Record the result action. */
MVMCallStackDispatchRecord *record = MVM_callstack_find_topmost_dispatch_recording(tc);
ensure_known_capture(tc, record, capture);
MVMRegister value = { .o = (MVMObject *)result };
record->rec.outcome_value = value_index_constant(tc, &(record->rec),
MVM_CALLSITE_ARG_OBJ, value);
record->rec.outcome_capture = capture;
/* Set up the invoke outcome. */
MVMCallsite *callsite = ((MVMCapture *)capture)->body.callsite;
record->outcome.kind = MVM_DISP_OUTCOME_CFUNCTION;
record->outcome.c_func = result->body.func;
record->outcome.args.callsite = callsite;
record->outcome.args.map = MVM_args_identity_map(tc, callsite);
record->outcome.args.source = ((MVMCapture *)capture)->body.args;
}
/* Process a recorded program. */
typedef struct {
MVMDispProgramRecording *rec;
MVM_VECTOR_DECL(MVMCollectable *, gc_constants);
MVM_VECTOR_DECL(MVMDispProgramConstant, constants);
MVM_VECTOR_DECL(MVMDispProgramOp, ops);
/* A map of the temporaries, and which values they hold. This only covers
* those involved in executing the guard program, not in building up a
* final result capture. For now, we don't try and re-use temporaries. */
MVM_VECTOR_DECL(MVMDispProgramRecordingValue *, value_temps);
/* If we need to have further temporaries for an args buffer. */
MVMuint32 args_buffer_temps;
} compile_state;
static MVMuint32 add_program_constant_int(MVMThreadContext *tc, compile_state *cs,
MVMint64 value) {
MVMDispProgramConstant c = { .i64 = value };
MVM_VECTOR_PUSH(cs->constants, c);
return MVM_VECTOR_ELEMS(cs->constants) - 1;
}
static MVMuint32 add_program_constant_num(MVMThreadContext *tc, compile_state *cs,
MVMnum64 value) {
MVMDispProgramConstant c = { .n64 = value };
MVM_VECTOR_PUSH(cs->constants, c);
return MVM_VECTOR_ELEMS(cs->constants) - 1;
}
static MVMuint32 add_program_constant_callsite(MVMThreadContext *tc, compile_state *cs,
MVMCallsite *value) {
/* The callsite must be interned to be used in a dispatch program. */
if (!value->is_interned)
MVM_callsite_intern(tc, &value, 1, 0);
MVMDispProgramConstant c = { .cs = value };
MVM_VECTOR_PUSH(cs->constants, c);
return MVM_VECTOR_ELEMS(cs->constants) - 1;
}
static MVMuint32 add_program_gc_constant(MVMThreadContext *tc, compile_state *cs,
MVMCollectable *value) {
MVMuint32 i;
for (i = 0; i < MVM_VECTOR_ELEMS(cs->gc_constants); i++)
if (cs->gc_constants[i] == value)
return i;
MVM_VECTOR_PUSH(cs->gc_constants, value);
return MVM_VECTOR_ELEMS(cs->gc_constants) - 1;
}
static MVMuint32 add_program_constant_obj(MVMThreadContext *tc, compile_state *cs,
MVMObject *value) {
return add_program_gc_constant(tc, cs, (MVMCollectable *)value);
}
static MVMuint32 add_program_constant_str(MVMThreadContext *tc, compile_state *cs,
MVMString *value) {
return add_program_gc_constant(tc, cs, (MVMCollectable *)value);
}
static MVMuint32 add_program_constant_stable(MVMThreadContext *tc, compile_state *cs,
MVMSTable *value) {
return add_program_gc_constant(tc, cs, (MVMCollectable *)value);
}
static MVMuint32 get_temp_holding_value(MVMThreadContext *tc, compile_state *cs,
MVMuint32 value_index) {
/* See if we already loaded it. */
MVMuint32 i;
MVMDispProgramRecordingValue *v = &(cs->rec->values[value_index]);
for (i = 0; i < MVM_VECTOR_ELEMS(cs->value_temps); i++)
if (cs->value_temps[i] == v)
return i;
/* Otherwise, we need to allocate a temporary and emit a load. */
MVMDispProgramOp op;
op.load.temp = MVM_VECTOR_ELEMS(cs->value_temps);
MVM_VECTOR_PUSH(cs->value_temps, v);
switch (v->source) {
case MVMDispProgramRecordingCaptureValue:
op.code = MVMDispOpcodeLoadCaptureValue;
op.load.idx = v->capture.index;
break;
case MVMDispProgramRecordingLiteralValue:
switch (v->literal.kind) {
case MVM_CALLSITE_ARG_OBJ:
op.code = MVMDispOpcodeLoadConstantObjOrStr;
op.load.idx = add_program_constant_obj(tc, cs, v->literal.value.o);
break;
case MVM_CALLSITE_ARG_STR:
op.code = MVMDispOpcodeLoadConstantObjOrStr;
op.load.idx = add_program_constant_str(tc, cs, v->literal.value.s);
break;
case MVM_CALLSITE_ARG_INT:
op.code = MVMDispOpcodeLoadConstantInt;
op.load.idx = add_program_constant_int(tc, cs, v->literal.value.i64);
break;
case MVM_CALLSITE_ARG_NUM:
op.code = MVMDispOpcodeLoadConstantNum;
op.load.idx = add_program_constant_num(tc, cs, v->literal.value.n64);
break;
default:
MVM_oops(tc, "Unhandled kind of literal value in recorded dispatch");
}
break;
case MVMDispProgramRecordingAttributeValue: {
/* We first need to make sure that we load the dependent value (we
* surely will have due to it needing to be guarded). */
MVMuint32 from_temp = get_temp_holding_value(tc, cs, v->attribute.from_value);
/* Reading an attribute happens in two steps. First we copy the from
* value into the target temporary. */
op.code = MVMDispOpcodeSet;
op.load.idx = from_temp;
MVM_VECTOR_PUSH(cs->ops, op);
/* Then we do the attribute access. */
switch (v->attribute.kind) {
case MVM_CALLSITE_ARG_OBJ:
op.code = MVMDispOpcodeLoadAttributeObj;
break;
case MVM_CALLSITE_ARG_STR:
op.code = MVMDispOpcodeLoadAttributeStr;
break;
case MVM_CALLSITE_ARG_INT:
op.code = MVMDispOpcodeLoadAttributeInt;
break;
case MVM_CALLSITE_ARG_NUM:
op.code = MVMDispOpcodeLoadAttributeNum;
break;
default: