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

Brainstorming user binary ops

Thread Next
James Mastros
July 15, 2009 23:35
Brainstorming user binary ops
Message ID:
I hope not to distract too badly from 5.10.1 prep, but at the same
time, I think we're smacking down everything that isn't suitable for
maint a little hard, so I'm posting this anyway.  This is a *very*
rough plan for adding user-definable, lexically scoped, binary
operations to perl, that I think is fairly practical.  (It's an edited
version of brainstorming I did overnight (british time) in #p5p.)

I've been thinking about toke.c and pluggability a bit.  What's to
stop us from, just before the switch (*s) at about toke.c line 3654,
from checking if PL_expect == XOPERATOR, and doing strncmp against the
keys of %^B (which would be a new var, scoped like %^H -- B for binary
operator), sorted by length then skipping the switch completely if it
matches one of them?
We'd then return a new token, depending on what associativity and
precedence the user wanted, and stick the value of the hash entry in
the token's semantic value slot.  (That'd require a new SV * or CV *
slot in the semantic value union, but it's a union, so that's not a
big deal.)  The parser then calls that CV.  From there, I'm not
completely sure what happens.  (Note that calling a CV while parsing,
while it sounds a bit off, is something we currently do fairly often
-- whenever there's a $SIG{__WARN__} or __DIE__.

While there's quite a number of steps I don't know how to do, I don't
think there's anything there that's all that diffficult for people who
actually know what they are doing -- would people who actually know
what they are doing care to correct me on that, or help fill in the
missing pieces -- especially, what we pass to the CV, and what we
expect back from it?  Can anybody poke a big hole in my plan?

  -=- James Mastros, theorbtwo

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