Skip to content

Commit

Permalink
Make C(PP)Struct and CUnion properly support uint attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 21, 2022
1 parent 53e588e commit 06e1ebe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/6model/reprs/CPPStruct.c
Expand Up @@ -166,6 +166,7 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMSTable *st,
MVMint32 type_id = REPR(type)->ID;
if (spec->inlineable == MVM_STORAGE_SPEC_INLINED &&
(spec->boxed_primitive == MVM_STORAGE_SPEC_BP_INT ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_UINT64 ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_NUM)) {
/* It's a boxed int or num; pretty easy. It'll just live in the
* body of the struct. Instead of masking in i here (which
Expand Down Expand Up @@ -525,6 +526,14 @@ static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CPPStruct: invalid native get of object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
result_reg->u64 = attr_st->REPR->box_funcs.get_uint(tc, attr_st, root,
((char *)body->cppstruct) + repr_data->struct_offsets[slot]);
else
MVM_exception_throw_adhoc(tc, "CPPStruct: invalid native get of object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
result_reg->n64 = attr_st->REPR->box_funcs.get_num(tc, attr_st, root,
Expand Down Expand Up @@ -636,6 +645,14 @@ static void bind_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CPPStruct: invalid native binding to object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
attr_st->REPR->box_funcs.set_uint(tc, attr_st, root,
((char *)body->cppstruct) + repr_data->struct_offsets[slot], value_reg.u64);
else
MVM_exception_throw_adhoc(tc, "CPPStruct: invalid native binding to object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
attr_st->REPR->box_funcs.set_num(tc, attr_st, root,
Expand Down
17 changes: 17 additions & 0 deletions src/6model/reprs/CStruct.c
Expand Up @@ -180,6 +180,7 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in
MVMint32 type_id = REPR(type)->ID;
if (spec->inlineable == MVM_STORAGE_SPEC_INLINED &&
(spec->boxed_primitive == MVM_STORAGE_SPEC_BP_INT ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_UINT64 ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_NUM)) {
/* It's a boxed int or num; pretty easy. It'll just live in the
* body of the struct. Instead of masking in i here (which
Expand Down Expand Up @@ -553,6 +554,14 @@ static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CStruct: invalid native get of object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
result_reg->u64 = attr_st->REPR->box_funcs.get_uint(tc, attr_st, root,
((char *)body->cstruct) + repr_data->struct_offsets[slot]);
else
MVM_exception_throw_adhoc(tc, "CStruct: invalid native get of object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
result_reg->n64 = attr_st->REPR->box_funcs.get_num(tc, attr_st, root,
Expand Down Expand Up @@ -676,6 +685,14 @@ static void bind_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CStruct: invalid native binding to object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
attr_st->REPR->box_funcs.set_uint(tc, attr_st, root,
((char *)body->cstruct) + repr_data->struct_offsets[slot], value_reg.u64);
else
MVM_exception_throw_adhoc(tc, "CStruct: invalid native binding to object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
attr_st->REPR->box_funcs.set_num(tc, attr_st, root,
Expand Down
17 changes: 17 additions & 0 deletions src/6model/reprs/CUnion.c
Expand Up @@ -139,6 +139,7 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in
MVMint32 type_id = REPR(type)->ID;
if (spec->inlineable == MVM_STORAGE_SPEC_INLINED &&
(spec->boxed_primitive == MVM_STORAGE_SPEC_BP_INT ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_UINT64 ||
spec->boxed_primitive == MVM_STORAGE_SPEC_BP_NUM)) {
/* It's a boxed int or num; pretty easy. It'll just live in the
* body of the struct. Instead of masking in i here (which
Expand Down Expand Up @@ -485,6 +486,14 @@ static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CUnion: invalid native get of object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
result_reg->u64 = attr_st->REPR->box_funcs.get_uint(tc, attr_st, root,
((char *)body->cunion) + repr_data->struct_offsets[slot]);
else
MVM_exception_throw_adhoc(tc, "CUnion: invalid native get of object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
result_reg->n64 = attr_st->REPR->box_funcs.get_num(tc, attr_st, root,
Expand Down Expand Up @@ -584,6 +593,14 @@ static void bind_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVM_exception_throw_adhoc(tc, "CUnion: invalid native binding to object attribute");
break;
}
case MVM_reg_uint64: {
if (attr_st)
attr_st->REPR->box_funcs.set_uint(tc, attr_st, root,
((char *)body->cunion) + repr_data->struct_offsets[slot], value_reg.u64);
else
MVM_exception_throw_adhoc(tc, "CUnion: invalid native binding to object attribute");
break;
}
case MVM_reg_num64: {
if (attr_st)
attr_st->REPR->box_funcs.set_num(tc, attr_st, root,
Expand Down

0 comments on commit 06e1ebe

Please sign in to comment.