Skip to content
This repository
Browse code

Handle bit widths in nqp.ops.

  • Loading branch information...
commit d384d49fbe8f0fe566edc5d9d66e840e607a59ae 1 parent 009285a
Arne Skjærholt arnsholt authored

Showing 1 changed file with 60 additions and 4 deletions. Show diff stats Hide diff stats

  1. +60 4 src/ops/nqp.ops
64 src/ops/nqp.ops
@@ -552,7 +552,24 @@ inline op repr_get_attr_int(out INT, invar PMC, invar PMC, in STR) :base_core {
552 552 if ($2->vtable->base_type == smo_id) {
553 553 if (IS_CONCRETE($2)) {
554 554 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 + }
556 573 }
557 574 else
558 575 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 {
578 595 if ($2->vtable->base_type == smo_id) {
579 596 if (IS_CONCRETE($2)) {
580 597 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 + }
582 610 }
583 611 else
584 612 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
764 792 if ($2->vtable->base_type == smo_id) {
765 793 if (IS_CONCRETE($2)) {
766 794 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 + }
768 813 }
769 814 else
770 815 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
791 836 if ($2->vtable->base_type == smo_id) {
792 837 if (IS_CONCRETE($2)) {
793 838 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 + }
795 851 }
796 852 else
797 853 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,

0 comments on commit d384d49

Please sign in to comment.
Something went wrong with that request. Please try again.