Skip to content

Commit d384d49

Browse files
committed
Handle bit widths in nqp.ops.
1 parent 009285a commit d384d49

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

src/ops/nqp.ops

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,24 @@ inline op repr_get_attr_int(out INT, invar PMC, invar PMC, in STR) :base_core {
552552
if ($2->vtable->base_type == smo_id) {
553553
if (IS_CONCRETE($2)) {
554554
INTVAL bits = 0;
555-
$1 = *((INTVAL *)REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT));
555+
void *ptr = REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT);
556+
switch(bits) {
557+
case 8:
558+
$1 = (INTVAL) *((Parrot_Int1 *) ptr);
559+
break;
560+
case 16:
561+
$1 = (INTVAL) *((Parrot_Int2 *) ptr);
562+
break;
563+
case 32:
564+
$1 = (INTVAL) *((Parrot_Int4 *) ptr);
565+
break;
566+
case 64:
567+
$1 = (INTVAL) *((Parrot_Int8 *) ptr);
568+
break;
569+
default:
570+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
571+
"repr_get_attr_int can only handle 8, 16, 32 and 64 bit ints");
572+
}
556573
}
557574
else
558575
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
@@ -578,7 +595,18 @@ inline op repr_get_attr_num(out NUM, invar PMC, invar PMC, in STR) :base_core {
578595
if ($2->vtable->base_type == smo_id) {
579596
if (IS_CONCRETE($2)) {
580597
INTVAL bits = 0;
581-
$1 = *((FLOATVAL *)REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT));
598+
void *ptr = REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT);
599+
switch(bits) {
600+
case 32:
601+
$1 = (FLOATVAL) *((Parrot_Float4 *) ptr);
602+
break;
603+
case 64:
604+
$1 = (FLOATVAL) *((Parrot_Float8 *) ptr);
605+
break;
606+
default:
607+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
608+
"repr_get_attr_num can only handle 32 and 64 bit ints");
609+
}
582610
}
583611
else
584612
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
@@ -764,7 +792,24 @@ inline op repr_get_attr_int(out INT, invar PMC, invar PMC, in STR, in INT) :base
764792
if ($2->vtable->base_type == smo_id) {
765793
if (IS_CONCRETE($2)) {
766794
INTVAL bits = 0;
767-
$1 = *((INTVAL *)REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, $5));
795+
void *ptr = REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT);
796+
switch(bits) {
797+
case 8:
798+
$1 = (INTVAL) *((Parrot_Int1 *) ptr);
799+
break;
800+
case 16:
801+
$1 = (INTVAL) *((Parrot_Int2 *) ptr);
802+
break;
803+
case 32:
804+
$1 = (INTVAL) *((Parrot_Int4 *) ptr);
805+
break;
806+
case 64:
807+
$1 = (INTVAL) *((Parrot_Int8 *) ptr);
808+
break;
809+
default:
810+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
811+
"repr_get_attr_int can only handle 8, 16, 32 and 64 bit ints");
812+
}
768813
}
769814
else
770815
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
@@ -791,7 +836,18 @@ inline op repr_get_attr_num(out NUM, invar PMC, invar PMC, in STR, in INT) :base
791836
if ($2->vtable->base_type == smo_id) {
792837
if (IS_CONCRETE($2)) {
793838
INTVAL bits = 0;
794-
$1 = *((FLOATVAL *)REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, $5));
839+
void *ptr = REPR($2)->attr_funcs->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, &bits, NO_HINT);
840+
switch(bits) {
841+
case 32:
842+
$1 = (FLOATVAL) *((Parrot_Float4 *) ptr);
843+
break;
844+
case 64:
845+
$1 = (FLOATVAL) *((Parrot_Float8 *) ptr);
846+
break;
847+
default:
848+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
849+
"repr_get_attr_num can only handle 32 and 64 bit ints");
850+
}
795851
}
796852
else
797853
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,

0 commit comments

Comments
 (0)