-
Notifications
You must be signed in to change notification settings - Fork 131
/
nqp.ops
executable file
·3062 lines (2422 loc) · 94.2 KB
/
nqp.ops
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
BEGIN_OPS_PREAMBLE
#include <errno.h>
/* Parroty includes. */
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "parrot/dynext.h"
/* 6modely includes. */
#include "../6model/sixmodelobject.h"
#include "../6model/repr_registry.h"
#include "../6model/reprs/NFA.h"
#include "../6model/serialization_context.h"
#include "../guts/multi_dispatch.h"
#include "../pmc/pmc_nqplexinfo.h"
#include "pmc_sub.h"
/* SHA1 algorithm. */
#include "../../3rdparty/sha1/sha1.h"
#if PARROT_HAS_ICU
# include <unicode/uchar.h>
#endif
/* Did we do the dynop setup yet?
* XXX Relies on this happening once in a single thread at startup. */
static INTVAL initialized = 0;
/* Cached type IDs. */
static INTVAL stable_id = 0;
static INTVAL smo_id = 0;
static INTVAL disp_id = 0;
static INTVAL qrpa_id = 0;
static INTVAL ohash_id = 0;
/* Built-in meta-objects. */
static PMC *KnowHOW = NULL;
static PMC *KnowHOWAttribute = NULL;
/* FileHandle PMC for nqpevent */
static PMC *nqpevent_fh = NULL;
static INTVAL nqpdebflags_i = 0;
/* Objects we use every time we run an NFA; since we always run one NFA
* at a time, we can re-use these. */
static PMC *nfa_curst = NULL;
static PMC *nfa_nextst = NULL;
/* Serialization context upside-down stack (element 0 is the latest, new entries
* unshifted). Tracks the SC (if any) that we are currently in; stack because we
* may have multiple on the go due to compiling nested module dependencies. */
PMC *compiling_scs = NULL;
/* Disables the SC write barrier temporarily. Zero is enabled, otherwise it's the
* number of nested enable/disable we are in. */
INTVAL sc_write_barrier_off_depth = 0;
/* Empty hash, used in deconstruct op. */
static PMC *empty_hash = NULL;
/* SC write barrier for objects. */
static void SC_write_barrier_obj(PARROT_INTERP, PMC *obj) {
if (!sc_write_barrier_off_depth && VTABLE_get_bool(interp, compiling_scs)) {
PMC *comp_sc = VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0);
if (SC_PMC(obj) != comp_sc) {
SC_repossess_object(interp, comp_sc, SC_PMC(obj), obj);
SC_PMC(obj) = comp_sc;
/*printf("SC OBJECT WRITE BARRIER HIT (%s)\n",
Parrot_str_cstring(interp, VTABLE_name(interp, obj)));*/
}
}
}
/* SC write barrier for STables. */
static void SC_write_barrier_st(PARROT_INTERP, STable *st) {
if (!sc_write_barrier_off_depth && VTABLE_get_bool(interp, compiling_scs)) {
PMC *comp_sc = VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0);
if (st->sc != comp_sc) {
SC_repossess_stable(interp, comp_sc, st->sc, st->stable_pmc);
st->sc = comp_sc;
/*printf("SC STABLE WRITE BARRIER HIT (%s)\n",
Parrot_str_cstring(interp, VTABLE_name(interp, st->WHAT)));*/
}
}
}
/* Test for something being a list (RPA or QRPA). */
static INTVAL
nqp_islist(PMC *pmc) {
INTVAL type = pmc->vtable->base_type;
return (INTVAL)(type == qrpa_id || type == enum_class_ResizablePMCArray
|| type == enum_class_ResizableStringArray);
}
/* Test for something being a hash. */
static INTVAL
nqp_ishash(PMC *pmc) {
INTVAL type = pmc->vtable->base_type;
return (INTVAL)(type == enum_class_Hash || type == ohash_id);
}
/* This public-domain C quick sort implementation by Darel Rex Finley. */
static INTVAL
quicksort(INTVAL *arr, INTVAL elements) {
#define MAX_LEVELS 100
INTVAL piv, beg[MAX_LEVELS], end[MAX_LEVELS], i = 0, L, R ;
beg[0] = 0;
end[0] = elements;
while (i >= 0) {
L = beg[i];
R = end[i] - 1;
if (L < R) {
piv = arr[L];
if (i == MAX_LEVELS - 1)
return 0;
while (L < R) {
while (arr[R] >= piv && L < R)
R--;
if (L < R)
arr[L++] = arr[R];
while (arr[L] <= piv && L < R)
L++;
if (L < R)
arr[R--] =arr[L];
}
arr[L] = piv;
beg[i+1] = L + 1;
end[i+1] = end[i];
end[i++] = L;
}
else {
i--;
}
}
return 1;
}
/* Does a run of the NFA. Produces a list of integers indicating the
* chosen ordering. */
static INTVAL * nqp_nfa_run(PARROT_INTERP, NFABody *nfa, STRING *target, INTVAL offset, INTVAL *total_fates_out) {
INTVAL eos = Parrot_str_length(interp, target);
INTVAL gen = 1;
PMC *curst = nfa_curst;
PMC *nextst = nfa_nextst;
INTVAL *done, *fates;
INTVAL i, fate_arr_len, num_states, total_fates, prev_fates;
/* Allocate a "done states" array. */
num_states = nfa->num_states;
done = (INTVAL *)mem_sys_allocate_zeroed((num_states + 1) * sizeof(INTVAL));
/* Clear out other re-used arrays. */
VTABLE_set_integer_native(interp, curst, 0);
VTABLE_set_integer_native(interp, nextst, 0);
/* Allocate fates array. */
fate_arr_len = 1 + VTABLE_elements(interp, nfa->fates);
fates = (INTVAL *)mem_sys_allocate(sizeof(INTVAL) * fate_arr_len);
total_fates = 0;
VTABLE_push_integer(interp, nextst, 1);
while (VTABLE_elements(interp, nextst) && offset <= eos) {
/* Translation of:
* my @curst := @nextst;
* @nextst := [];
* But avoids an extra allocation per offset. */
PMC *temp = curst;
curst = nextst;
VTABLE_set_integer_native(interp, temp, 0);
nextst = temp;
/* Save how many fates we have before this position is considered. */
prev_fates = total_fates;
while (VTABLE_elements(interp, curst)) {
NFAStateInfo *edge_info;
INTVAL edge_info_elems;
INTVAL st = VTABLE_pop_integer(interp, curst);
if (st <= num_states) {
if (done[st] == gen)
continue;
done[st] = gen;
}
edge_info = nfa->states[st - 1];
edge_info_elems = nfa->num_state_edges[st - 1];
for (i = 0; i < edge_info_elems; i++) {
INTVAL act = edge_info[i].act;
INTVAL to = edge_info[i].to;
if (act == EDGE_FATE) {
/* Crossed a fate edge. Check if we already saw this, and
* if so bump the entry we already saw. */
INTVAL arg = edge_info[i].arg.i;
INTVAL j;
INTVAL found_fate = 0;
for (j = 0; j < total_fates; j++) {
if (found_fate)
fates[j - 1] = fates[j];
if (fates[j] == arg) {
found_fate = 1;
if (j < prev_fates)
prev_fates--;
}
}
if (found_fate) {
fates[total_fates - 1] = arg;
}
else {
if (total_fates >= fate_arr_len) {
fate_arr_len = total_fates + 1;
fates = (INTVAL *)mem_sys_realloc(fates,
sizeof(INTVAL) * fate_arr_len);
}
fates[total_fates++] = arg;
}
}
else if (act == EDGE_EPSILON && to <= num_states && done[to] != gen) {
VTABLE_push_integer(interp, curst, to);
}
else if (offset >= eos) {
/* Can't match, so drop state. */
}
else if (act == EDGE_CODEPOINT) {
UINTVAL arg = edge_info[i].arg.i;
if (STRING_ord(interp, target, offset) == arg)
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CODEPOINT_NEG) {
UINTVAL arg = edge_info[i].arg.i;
if (STRING_ord(interp, target, offset) != arg)
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CHARCLASS) {
INTVAL arg = edge_info[i].arg.i;
if (Parrot_str_is_cclass(interp, arg, target, offset))
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CHARCLASS_NEG) {
INTVAL arg = edge_info[i].arg.i;
if (!Parrot_str_is_cclass(interp, arg, target, offset))
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CHARLIST) {
STRING *arg = edge_info[i].arg.s;
STRING *chr = STRING_substr(interp, target, offset, 1);
if (STRING_index(interp, arg, chr, 0) >= 0)
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CHARLIST_NEG) {
STRING *arg = edge_info[i].arg.s;
STRING *chr = STRING_substr(interp, target, offset, 1);
if (STRING_index(interp, arg, chr, 0) < 0)
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CODEPOINT_I) {
UINTVAL uc_arg = edge_info[i].arg.uclc.uc;
UINTVAL lc_arg = edge_info[i].arg.uclc.lc;
UINTVAL ord = STRING_ord(interp, target, offset);
if (ord == lc_arg || ord == uc_arg)
VTABLE_push_integer(interp, nextst, to);
}
else if (act == EDGE_CODEPOINT_I_NEG) {
UINTVAL uc_arg = edge_info[i].arg.uclc.uc;
UINTVAL lc_arg = edge_info[i].arg.uclc.lc;
UINTVAL ord = STRING_ord(interp, target, offset);
if (ord != lc_arg && ord != uc_arg)
VTABLE_push_integer(interp, nextst, to);
}
}
}
/* Move to next character and generation. */
offset++;
gen++;
/* If we got multiple fates at this offset, sort them by the
* declaration order (represented by the fate number). In the
* future, we'll want to factor in longest literal prefix too. */
if (total_fates - prev_fates > 1) {
INTVAL char_fates = total_fates - prev_fates;
for (i = total_fates - char_fates; i < total_fates; i++)
fates[i] = -fates[i];
quicksort(&fates[total_fates - char_fates], char_fates);
for (i = total_fates - char_fates; i < total_fates; i++)
fates[i] = -fates[i];
}
}
mem_sys_free(done);
*total_fates_out = total_fates;
return fates;
}
/* Constants for values the type field above may have. */
#define BIND_VAL_INT 1
#define BIND_VAL_NUM 2
#define BIND_VAL_STR 3
#define BIND_VAL_OBJ 4
END_OPS_PREAMBLE
/*
=item nqp_dynop_setup()
Does various setup tasks for the benefit of the other dynops.
=cut
*/
inline op nqp_dynop_setup() :base_core {
if (!initialized) {
PMC *obj_sc_barrier, *st_sc_barrier, *global_context;
/* Look up and cache some type IDs. */
stable_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "STable", 0));
smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
qrpa_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "QRPA", 0));
ohash_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "OwnedHash", 0));
/* Initialize the object model. */
SixModelObject_initialize(interp, &KnowHOW, &KnowHOWAttribute);
/* Initialize compiling SCs list. */
compiling_scs = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
Parrot_pmc_gc_register(interp, compiling_scs);
/* Set up write barrier functions. */
/* XXX Really want a better, cheaper place to put them... */
obj_sc_barrier = Parrot_pmc_new(interp, enum_class_Pointer);
VTABLE_set_pointer(interp, obj_sc_barrier, SC_write_barrier_obj);
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
Parrot_str_new_constant(interp, "_OBJ_SC_BARRIER"), obj_sc_barrier);
st_sc_barrier = Parrot_pmc_new(interp, enum_class_Pointer);
VTABLE_set_pointer(interp, st_sc_barrier, SC_write_barrier_st);
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
Parrot_str_new_constant(interp, "_ST_SC_BARRIER"), st_sc_barrier);
/* Create and anchor NFA objects. */
nfa_curst = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
Parrot_pmc_gc_register(interp, nfa_curst);
nfa_nextst = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
Parrot_pmc_gc_register(interp, nfa_nextst);
/* Create and anchor empty hash. */
empty_hash = Parrot_pmc_new(interp, enum_class_Hash);
Parrot_pmc_gc_register(interp, empty_hash);
/* Save the global context to the Parrot root namespace and store all the
* things we just created in it. */
global_context = Parrot_pmc_new(interp, enum_class_Hash);
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
Parrot_str_new_constant(interp, "_GLOBAL_CONTEXT"), global_context);
VTABLE_set_pmc_keyed_str(interp, global_context,
Parrot_str_new_constant(interp, "hllConfig"), Parrot_pmc_new(interp, enum_class_Hash));
/* Mark initialized. */
initialized = 1;
}
}
/*
=item get_knowhow()
Returns the 6model core meta-object, KnowHOW.
=cut
*/
inline op get_knowhow(out PMC) :base_core {
if (KnowHOW)
$1 = KnowHOW;
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"6model not yet initialized; cannot use get_knowhow");
}
/*
=item get_knowhow_attribute()
Returns the 6model core meta-attribute, KnowHOWAttribute.
=cut
*/
inline op get_knowhow_attribute(out PMC) :base_core {
if (KnowHOWAttribute)
$1 = KnowHOWAttribute;
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"6model not yet initialized; cannot use get_knowhow_attribute");
}
/*
=item get_how(obj)
Gets the HOW for a 6model Object.
=cut
*/
inline op get_how(out PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = STABLE(var)->HOW;
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use get_how on a SixModelObject");
}
/*
=item get_what(obj)
Gets the WHAT for a 6model Object.
=cut
*/
inline op get_what(out PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = STABLE(var)->WHAT;
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use get_what on a SixModelObject");
}
/*
=item what_or_null(obj)
Gets the WHAT for a 6model Object, returns PMCNULL otherwise.
=cut
*/
inline op what_or_null(out PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = STABLE(var)->WHAT;
else
$1 = PMCNULL;
}
/*
=item get_who(obj)
Gets the WHO for a 6model Object.
=cut
*/
inline op get_who(out PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = STABLE(var)->WHO;
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use get_who on a SixModelObject");
}
/*
=item set_who(obj)
Sets the WHO for a 6model Object.
=cut
*/
inline op set_who(invar PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $1);
if (var->vtable->base_type == smo_id) {
STABLE(var)->WHO = $2;
PARROT_GC_WRITE_BARRIER(interp, STABLE_PMC(var));
ST_SC_WRITE_BARRIER(STABLE(var));
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use set_who on a SixModelObject");
}
/*
=item repr_type_object_for(how, repr_name)
Creates a type object associated with the given HOW and of the given
representation.
=cut
*/
inline op repr_type_object_for(out PMC, invar PMC, in STR) :base_core {
REPROps *REPR = REPR_get_by_name(interp, $3);
$1 = REPR->type_object_for(interp, decontainerize(interp, $2));
}
/*
=item repr_compose(type_obj, repr_info)
Triggers representation composition type for the specified type, passing the
specified information for it to compose by.
=cut
*/
inline op repr_compose(invar PMC, invar PMC) :base_core {
REPR($1)->compose(interp, STABLE($1), $2);
}
/*
=item repr_instance_of()
Instantiates a new object based on the given WHAT.
=cut
*/
inline op repr_instance_of(out PMC, invar PMC) :base_core {
if ($2->vtable->base_type == smo_id) {
$1 = REPR($2)->allocate(interp, STABLE($2));
REPR($1)->initialize(interp, STABLE($2), OBJECT_BODY($1));
PARROT_GC_WRITE_BARRIER(interp, $1);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_instance_of on a SixModelObject");
}
}
/*
=item repr_clone()
Clones an object. If it's a 6model object, uses repr_clone. If not, falls back to
Parrot's clone vtable.
=cut
*/
inline op repr_clone(out PMC, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id) {
$1 = REPR(var)->allocate(interp, STABLE(var));
if (IS_CONCRETE(var))
REPR(var)->copy_to(interp, STABLE(var), OBJECT_BODY(var), OBJECT_BODY($1));
else
MARK_AS_TYPE_OBJECT($1);
PARROT_GC_WRITE_BARRIER(interp, $1);
}
else {
$1 = VTABLE_clone(interp, var);
}
}
/*
=item repr_defined()
Checks the REPRs idea of definedness.
=cut
*/
inline op repr_defined(out INT, invar PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = IS_CONCRETE(var);
else
$1 = 1; /* Because other PMCs have no concept of type-object. */
}
/*
=item repr_get_attr_obj()
Gets the specified object attribute. Note that the attribute must be stored as
an object - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_obj(out PMC, invar PMC, invar PMC, in STR) :base_core {
PMC *ch = decontainerize(interp, $3);
if ($2->vtable->base_type == smo_id) {
if (IS_CONCRETE($2))
$1 = REPR($2)->attr_funcs->get_attribute_boxed(interp, STABLE($2), OBJECT_BODY($2), ch, $4, NO_HINT);
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_obj on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $2);
}
/*
=item repr_get_attr_int()
Gets the specified int attribute. Note that the attribute must be stored as
a native int - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_int(out INT, invar PMC, invar PMC, in STR) :base_core {
PMC *obj = decontainerize(interp, $2);
PMC *ch = decontainerize(interp, $3);
STRING *name = $4;
if (obj->vtable->base_type == smo_id) {
if (IS_CONCRETE(obj)) {
NativeValue value;
value.type = NATIVE_VALUE_INT;
REPR(obj)->attr_funcs->get_attribute_native(interp, STABLE(obj), OBJECT_BODY(obj), ch, name, NO_HINT, &value);
$1 = value.value.intval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_int on a SixModelObject");
}
/*
=item repr_get_attr_num()
Gets the specified num attribute. Note that the attribute must be stored as
a native num - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_num(out NUM, invar PMC, invar PMC, in STR) :base_core {
PMC *obj = decontainerize(interp, $2);
PMC *ch = decontainerize(interp, $3);
STRING *name = $4;
if (obj->vtable->base_type == smo_id) {
if (IS_CONCRETE(obj)) {
NativeValue value;
value.type = NATIVE_VALUE_FLOAT;
REPR(obj)->attr_funcs->get_attribute_native(interp, STABLE(obj), OBJECT_BODY(obj), ch, name, NO_HINT, &value);
$1 = value.value.floatval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_num on a SixModelObject");
}
}
/*
=item repr_get_attr_str()
Gets the specified str attribute. Note that the attribute must be stored as
a native str - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_str(out STR, invar PMC, invar PMC, in STR) :base_core {
PMC *ch = decontainerize(interp, $3);
if ($2->vtable->base_type == smo_id) {
if (IS_CONCRETE($2)) {
NativeValue value;
value.type = NATIVE_VALUE_STRING;
REPR($2)->attr_funcs->get_attribute_native(interp, STABLE($2), OBJECT_BODY($2), ch, $4, NO_HINT, &value);
$1 = value.value.stringval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_str on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $2);
}
/*
=item repr_bind_attr_obj()
Binds the specified object attribute. Note that the attribute must be stored as
an object - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_obj(invar PMC, invar PMC, in STR, invar PMC) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1))
REPR($1)->attr_funcs->bind_attribute_boxed(interp, STABLE($1), OBJECT_BODY($1), ch, $3, NO_HINT, $4);
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_obj on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $1);
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_bind_attr_int()
Binds the specified int attribute. Note that the attribute must be stored as
a native int - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_int(invar PMC, invar PMC, in STR, in INT) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1)) {
NativeValue value;
value.type = NATIVE_VALUE_INT;
value.value.intval = $4;
REPR($1)->attr_funcs->bind_attribute_native(interp, STABLE($1), OBJECT_BODY($1), ch, $3, NO_HINT, &value);
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_int on a SixModelObject");
}
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_bind_attr_num()
Binds the specified num attribute. Note that the attribute must be stored as
a native num - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_num(invar PMC, invar PMC, in STR, in NUM) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1)) {
NativeValue value;
value.type = NATIVE_VALUE_FLOAT;
value.value.floatval = $4;
REPR($1)->attr_funcs->bind_attribute_native(interp, STABLE($1), OBJECT_BODY($1), ch, $3, NO_HINT, &value);
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_num on a SixModelObject");
}
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_bind_attr_str()
Binds the specified str attribute. Note that the attribute must be stored as
a native str - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_str(invar PMC, invar PMC, in STR, in STR) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1)) {
NativeValue value;
value.type = NATIVE_VALUE_STRING;
value.value.stringval = $4;
REPR($1)->attr_funcs->bind_attribute_native(interp, STABLE($1), OBJECT_BODY($1), ch, $3, NO_HINT, &value);
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_str on a SixModelObject");
PARROT_GC_WRITE_BARRIER(interp, $1);
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_get_attr_obj()
Gets the specified object attribute. Note that the attribute must be stored as
an object - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_obj(out PMC, invar PMC, invar PMC, in STR, in INT) :base_core {
PMC *ch = decontainerize(interp, $3);
if ($2->vtable->base_type == smo_id) {
if (IS_CONCRETE($2))
$1 = REPR($2)->attr_funcs->get_attribute_boxed(interp, STABLE($2), OBJECT_BODY($2), ch, $4, $5);
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_obj on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $2);
}
/*
=item repr_get_attr_int()
Gets the specified int attribute. Note that the attribute must be stored as
a native int - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_int(out INT, invar PMC, invar PMC, in STR, in INT) :base_core {
PMC *obj = decontainerize(interp, $2);
PMC *ch = decontainerize(interp, $3);
STRING *name = $4;
if (obj->vtable->base_type == smo_id) {
if (IS_CONCRETE(obj)) {
NativeValue value;
value.type = NATIVE_VALUE_INT;
REPR(obj)->attr_funcs->get_attribute_native(interp, STABLE(obj), OBJECT_BODY(obj), ch, name, NO_HINT, &value);
$1 = value.value.intval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_int on a SixModelObject");
}
}
/*
=item repr_get_attr_num()
Gets the specified num attribute. Note that the attribute must be stored as
a native num - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_num(out NUM, invar PMC, invar PMC, in STR, in INT) :base_core {
PMC *obj = decontainerize(interp, $2);
PMC *ch = decontainerize(interp, $3);
STRING *name = $4;
if (obj->vtable->base_type == smo_id) {
if (IS_CONCRETE(obj)) {
NativeValue value;
value.type = NATIVE_VALUE_FLOAT;
REPR(obj)->attr_funcs->get_attribute_native(interp, STABLE(obj), OBJECT_BODY(obj), ch, name, NO_HINT, &value);
$1 = value.value.floatval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_num on a SixModelObject");
}
}
/*
=item repr_get_attr_str()
Gets the specified str attribute. Note that the attribute must be stored as
a native str - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_get_attr_str(out STR, invar PMC, invar PMC, in STR, in INT) :base_core {
PMC *ch = decontainerize(interp, $3);
if ($2->vtable->base_type == smo_id) {
if (IS_CONCRETE($2)) {
NativeValue value;
value.type = NATIVE_VALUE_STRING;
REPR($2)->attr_funcs->get_attribute_native(interp, STABLE($2), OBJECT_BODY($2), ch, $4, $5, &value);
$1 = value.value.stringval;
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot look up attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_get_attr_str on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $2);
}
/*
=item repr_bind_attr_obj()
Binds the specified object attribute. Note that the attribute must be stored as
an object - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_obj(invar PMC, invar PMC, in STR, in INT, invar PMC) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1))
REPR($1)->attr_funcs->bind_attribute_boxed(interp, STABLE($1), OBJECT_BODY($1), ch, $3, $4, $5);
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_obj on a SixModelObject");
}
PARROT_GC_WRITE_BARRIER(interp, $1);
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_bind_attr_int()
Binds the specified int attribute. Note that the attribute must be stored as
a native int - the repr is not obligated to do boxing/unboxing for you.
=cut
*/
inline op repr_bind_attr_int(invar PMC, invar PMC, in STR, in INT, in INT) :base_core {
PMC *ch = decontainerize(interp, $2);
if ($1->vtable->base_type == smo_id) {
if (IS_CONCRETE($1)) {
NativeValue value;
value.type = NATIVE_VALUE_INT;
value.value.intval = $5;
REPR($1)->attr_funcs->bind_attribute_native(interp, STABLE($1), OBJECT_BODY($1), ch, $3, $4, &value);
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot bind to attributes in a type object");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_bind_attr_int on a SixModelObject");
}
OBJ_SC_WRITE_BARRIER($1);
}
/*
=item repr_bind_attr_num()