develooper Front page | perl.perl5.porters | Postings from July 2021

Thinking of adding OP_WEAKEN

Thread Next
Paul "LeoNerd" Evans
July 7, 2021 08:46
Thinking of adding OP_WEAKEN
Message ID:
I was surprised to note there isn't an OP_WEAKEN. I needed one in
Object::Pad, so I wrote:

  static OP *pp_weaken(pTHX)
    return NORMAL;

  #define newOP_WEAKEN(flags, first)  S_newOP_WEAKEN(aTHX_ flags, first)
  static OP *S_newOP_WEAKEN(pTHX_ U32 flags, OP *first)
    return newUNOP_CUSTOM(&pp_weaken, flags, first);

That's all it actually took.

I'm wondering about adding a real one to core perl.

While there isn't a core `weaken()` operator, it would still be useful
for 3rd party modules like Object::Pad. I'd also like to use it in
Scalar::Util, by installing an entersub checker around
Scalar::Util::weaken() to convert calls to that into that opcode
directly for performance.

(and while I'm there I'd probably make B::Deparse recognise it, and
also consider doing similar for the other Scalar::Util funcs)

Any thoughts?

Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About