Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make CPPStruct accept unmapped attributes. #5517

Open
p6rt opened this issue Aug 2, 2016 · 2 comments
Open

make CPPStruct accept unmapped attributes. #5517

p6rt opened this issue Aug 2, 2016 · 2 comments

Comments

@p6rt
Copy link

p6rt commented Aug 2, 2016

Migrated from rt.perl.org#128815 (status was 'new')

Searchable as RT128815$

@p6rt
Copy link
Author

p6rt commented Aug 2, 2016

From vlmarek@volny.cz

class A is repr<CPPStruct>{
  has $x;
}

I don't want $x mapped to C++ object attribute, I want it to be only part of it's perl 6 representation. I was thinking about adding a trait, something like.

multi sub trait_mod​:<is>(Attribute $r, :$native-private!) is export(​:DEFAULT){}
class A is repr<CPPStruct>{
  has $x is native-private;
}

But I'm not enough skilled to implement it :) I was not able to find in CPPStruct.c how to detect that attribute has given trait. So I have tried to disable the warnings

Inline Patch
diff --git a/src/6model/reprs/CPPStruct.c b/src/6model/reprs/CPPStruct.c
index f987734..5c0d6a5 100644
--- a/src/6model/reprs/CPPStruct.c
+++ b/src/6model/reprs/CPPStruct.c
@@ -235,8 +235,8 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in
                     repr_data->member_types[i] = type;
                 }
                 else {
-                    MVM_exception_throw_adhoc(tc,
-                        "CPPStruct representation only handles int, num, CArray, CPointer, CStruct, CPPStruct and CUnion");
+//                    MVM_exception_throw_adhoc(tc,
+//                       "CPPStruct representation only handles int, num, CArray, CPointer, CStruct, CPPStruct and CUnion");
                 }
             }
             else {
@@ -393,8 +393,8 @@ static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
             MVMint32 real_slot = repr_data->attribute_locations[slot] >> MVM_CPPSTRUCT_ATTR_SHIFT;
 
             if (type == MVM_CPPSTRUCT_ATTR_IN_STRUCT) {
-                MVM_exception_throw_adhoc(tc,
-                    "CPPStruct can't perform boxed get on flattened attributes yet");
+//                MVM_exception_throw_adhoc(tc,
+//                    "CPPStruct can't perform boxed get on flattened attributes yet");
             }
             else {
                 MVMObject *typeobj = repr_data->member_types[slot];



That at first seems to work:

class A is repr<CPPStruct>{
  has $x;

  method m() {
  $x //= do {
  my $s = Supplier.new;
  $s.Supply;
  }
  }
}

my $x=A.new();
say $x.m();

But now my method does not return Supply.new, but rather A.new;

If I replace 'has $x' by 'my $x', it returns what I would expect - Supply.new

And I got stuck :)

Thank you
__
  Vlad

@p6rt
Copy link
Author

p6rt commented Aug 2, 2016

From vlmarek@volny.cz

Also if the class A is not repr<CPPStruct>, $x.m() returns Supply.new.

@p6rt p6rt added the NativeCall label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant