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

Sugar to wrap C++ classes #32

Open
sanko opened this issue Mar 25, 2023 · 2 comments
Open

Sugar to wrap C++ classes #32

sanko opened this issue Mar 25, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@sanko
Copy link
Owner

sanko commented Mar 25, 2023

With Itanium mangling somewhat functional, defining and calling this methods should be handled internally.

@sanko sanko added the enhancement New feature or request label Mar 25, 2023
@sanko sanko self-assigned this Mar 25, 2023
@sanko
Copy link
Owner Author

sanko commented Mar 25, 2023

typedef 'MyClass' => Class[
    [ speed => 'set_speed' ] => Method [ [Int] => Void ],
    speed                    => Method [ []    => Int ],
    private                  => [ fuel => Float ],
    speed                    => Int,
    driver                   => Str
];

Something like this? Usage would be something like...

my $car = MyClass->new( speed => 0, driver => 'Mike' );
$car->set_speed(100);
print $car->speed;
  • So a method new( ... ) would take values and return a blessed pointer
  • A private value fuel would take up space in the pointer but not exposed somehow
  • Methods would automatically be made with THIS calling conventions and can be renamed ([ speed => 'set_speed' ] => ...) to avoid collisions
  • Should multiple methods with the same name be wrapped in a code ref that called the correct one based on the type of values passed? I'd need a way to test parameter types beyond advisory...

Edit: In the above examples, MyClass::speed() would be _ZN7MyClass5speedEv and MyClass::set_speed($) would be _ZN7MyClass5speedEi in Itanium.

@sanko
Copy link
Owner Author

sanko commented Aug 18, 2023

As of this comment, C++ class support includes:

  • defined with CPPStruct[ ... ] (borrowing from Raku)
  • constructors are simply wrapped with affix/wrap with names such as MyClass::MyClass or MyClass::new which attach to the the proper endpoint through mangling and proper handling of this pointer internally
  • destructors are MyClass::DESTROY and handled internally
  • no direct access to struct members (public or private)

I haven't wrapped a full C++ yet to test how unwieldy that is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant