Skip to content

Commit

Permalink
support C type sized P6ints and P6nums
Browse files Browse the repository at this point in the history
We can now ask the P6int repr to give us a an int, that is as wide as
a long in C on the current platform. This should solve the issues with
NativeCall on 32 bit machines. arnsholt++ and jnthn++ for the solution.
  • Loading branch information
FROGGS committed Feb 13, 2015
1 parent 2d7eddb commit 79b9b38
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/6model/reprs/P6int.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {

if (!MVM_is_null(tc, bits_o)) {
repr_data->bits = MVM_repr_get_int(tc, bits_o);

switch (repr_data->bits) {
case MVM_P6INT_C_TYPE_CHAR: repr_data->bits = sizeof(char); break;
case MVM_P6INT_C_TYPE_SHORT: repr_data->bits = sizeof(short); break;
case MVM_P6INT_C_TYPE_INT: repr_data->bits = sizeof(int); break;
case MVM_P6INT_C_TYPE_LONG: repr_data->bits = sizeof(long); break;
case MVM_P6INT_C_TYPE_LONGLONG: repr_data->bits = sizeof(long long); break;
}

if (repr_data->bits != 1 && repr_data->bits != 2 && repr_data->bits != 4 && repr_data->bits != 8
&& repr_data->bits != 16 && repr_data->bits != 32 && repr_data->bits != 64)
MVM_exception_throw_adhoc(tc, "MVMP6int: Unsupported int size (%dbit)", repr_data->bits);
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/P6int.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#define MVM_P6INT_C_TYPE_CHAR -1
#define MVM_P6INT_C_TYPE_SHORT -2
#define MVM_P6INT_C_TYPE_INT -3
#define MVM_P6INT_C_TYPE_LONG -4
#define MVM_P6INT_C_TYPE_LONGLONG -5

/* Representation used by P6 native ints. */
struct MVMP6intBody {
/* Integer storage slot. */
Expand Down
7 changes: 7 additions & 0 deletions src/6model/reprs/P6num.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info_hash) {

if (!MVM_is_null(tc, bits_o)) {
repr_data->bits = MVM_repr_get_int(tc, bits_o);

switch (repr_data->bits) {
case MVM_P6NUM_C_TYPE_FLOAT: repr_data->bits = sizeof(float); break;
case MVM_P6NUM_C_TYPE_DOUBLE: repr_data->bits = sizeof(double); break;
case MVM_P6NUM_C_TYPE_LONGDOUBLE: repr_data->bits = sizeof(long double); break;
}

if (repr_data->bits != 32 && repr_data->bits != 64)
MVM_exception_throw_adhoc(tc, "MVMP6num: Unsupported num size (%dbit)", repr_data->bits);
}
Expand Down
4 changes: 4 additions & 0 deletions src/6model/reprs/P6num.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#define MVM_P6NUM_C_TYPE_FLOAT -1
#define MVM_P6NUM_C_TYPE_DOUBLE -2
#define MVM_P6NUM_C_TYPE_LONGDOUBLE -3

/* Representation used by P6 nums. */
struct MVMP6numBody {
/* Float storage slot. */
Expand Down

0 comments on commit 79b9b38

Please sign in to comment.