pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
306 stars 72 forks source link

pragma nodestruct #258

Open YashasSamaga opened 6 years ago

YashasSamaga commented 6 years ago
new Tag:x;
#pragma nodestruct x

This should prevent the destructor from being called. While there is a workaround for this by using _: as tag and manually setting Tag: wherever needed, the neatness of the code won't be maintained.

The above dirty option is not possible for arguments as they would affect the function signature. An alternative would be to to set the values to invalid numbers add a check in the destructor code to ignore such cases. But this again is dirty.

The pragma directive will make it explicit and avoids the use of hacks. Moreover, this is vital to prevent destructors being called on arguments of complex assignment operator overloads.

YashasSamaga commented 6 years ago

I've tried something: https://github.com/YashasSamaga/pawn/commit/594095a710b3b8967561f93b8f5be171fc96ca73

Commit description:

Syntax:

#pragma nodestruct symbol1
#pragma nodestruct sym2, sym3, sym4

Notes: This is a beta commit.

TODOs:

  • error if symbols which cannot be destroyed are marked nodestruct

I am not sure what to do if a user tries to mark a global symbol or a symbol which doesn't have a destructor as nodestruct. A warning indicating that the pragma was ignored?

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.