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

Thinking of adding OP_WEAKEN

Thread Next
From:
Paul "LeoNerd" Evans
Date:
July 7, 2021 08:46
Subject:
Thinking of adding OP_WEAKEN
Message ID:
20210707094608.703412b3@shy.leonerd.org.uk
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)
  {
    dSP;
    sv_rvweaken(POPs);
    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

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About