@@ -567,43 +567,85 @@ static INTVAL hint_for(PARROT_INTERP, PMC *self, PMC *class_handle, STRING *name
567
567
/* Used with boxing. Sets an integer value, for representations that can hold
568
568
* one. */
569
569
static void set_int (PARROT_INTERP , PMC * self , PMC * obj , INTVAL value ) {
570
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
571
- "P6opaque cannot yet box a native int" );
570
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
571
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
572
+ if (repr -> unbox_int_offset ) {
573
+ set_int_at_offset (instance , repr -> unbox_int_offset , value );
574
+ }
575
+ else {
576
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
577
+ "This type cannot box a native integer" );
578
+ }
572
579
}
573
580
574
581
/* Used with boxing. Gets an integer value, for representations that can
575
582
* hold one. */
576
583
static INTVAL get_int (PARROT_INTERP , PMC * self , PMC * obj ) {
577
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
578
- "P6opaque cannot yet unbox to a native int" );
584
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
585
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
586
+ if (repr -> unbox_int_offset ) {
587
+ return get_int_at_offset (instance , repr -> unbox_int_offset );
588
+ }
589
+ else {
590
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
591
+ "This type cannot unbox to a native integer" );
592
+ }
579
593
}
580
594
581
595
/* Used with boxing. Sets a floating point value, for representations that can
582
596
* hold one. */
583
597
static void set_num (PARROT_INTERP , PMC * self , PMC * obj , FLOATVAL value ) {
584
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
585
- "P6opaque cannot yet box a native num" );
598
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
599
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
600
+ if (repr -> unbox_num_offset ) {
601
+ set_num_at_offset (instance , repr -> unbox_num_offset , value );
602
+ }
603
+ else {
604
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
605
+ "This type cannot box a native number" );
606
+ }
586
607
}
587
608
588
609
/* Used with boxing. Gets a floating point value, for representations that can
589
610
* hold one. */
590
611
static FLOATVAL get_num (PARROT_INTERP , PMC * self , PMC * obj ) {
591
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
592
- "P6opaque cannot yet unbox to a native num" );
612
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
613
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
614
+ if (repr -> unbox_num_offset ) {
615
+ return get_num_at_offset (instance , repr -> unbox_num_offset );
616
+ }
617
+ else {
618
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
619
+ "This type cannot unbox to a native number" );
620
+ }
593
621
}
594
622
595
623
/* Used with boxing. Sets a string value, for representations that can hold
596
624
* one. */
597
625
static void set_str (PARROT_INTERP , PMC * self , PMC * obj , STRING * value ) {
598
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
599
- "P6opaque cannot yet box a native string" );
626
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
627
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
628
+ if (repr -> unbox_str_offset ) {
629
+ set_str_at_offset (instance , repr -> unbox_str_offset , value );
630
+ }
631
+ else {
632
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
633
+ "This type cannot box a native string" );
634
+ }
600
635
}
601
636
602
637
/* Used with boxing. Gets a string value, for representations that can hold
603
638
* one. */
604
639
static STRING * get_str (PARROT_INTERP , PMC * self , PMC * obj ) {
605
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
606
- "P6opaque cannot yet unbox to a native string" );
640
+ P6opaqueInstance * instance = (P6opaqueInstance * )PMC_data (obj );
641
+ REPRP6opaque * repr = P6O_REPR_STRUCT (self );
642
+ if (repr -> unbox_str_offset ) {
643
+ return get_str_at_offset (instance , repr -> unbox_str_offset );
644
+ }
645
+ else {
646
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
647
+ "This type cannot unbox to a native string" );
648
+ }
607
649
}
608
650
609
651
/* This Parrot-specific addition to the API is used to mark an object. */
0 commit comments