In perl.git, the branch sprout/lexsub has been created

<http://perl5.git.perl.org/perl.git/commitdiff/a3b7cee7e24aea7550d8182c85ec8452b11dc2c3?hp=0000000000000000000000000000000000000000>

        at  a3b7cee7e24aea7550d8182c85ec8452b11dc2c3 (commit)

- Log -----------------------------------------------------------------
commit a3b7cee7e24aea7550d8182c85ec8452b11dc2c3
Author: Father Chrysostomos <[email protected]>
Date:   Mon Aug 13 22:56:05 2012 -0700

    Preserve outside pointers of my subs with string eval
    
    The CvHASEVAL flag lets cv_clone know that the clone needs to have its
    CvOUTSIDE pointer set, for the sake of string evals’ being able to
    look up variables.
    
    It was only being set on anonymous subs.  It should be set for all
    clonable subs.  It doesn’t actually hurt to set it on all types of
    subs, whether clonable or not, since it has no effect on non-clon-
    able subs.

M       pad.c
M       t/cmd/lexsub.t

commit 454b3be6faf20c170cc2fb4b04bdc32ecf470ac7
Author: Father Chrysostomos <[email protected]>
Date:   Sun Aug 12 17:57:35 2012 -0700

    Fix up outside pointers for my subs
    
    I had not yet fixed Perl_pad_fixup_inner_anons to account for the
    fact that my sub prototype CVs are stored in magic attached to
    the SV slot in the pad, rather than directly in the pad.  It also
    did not like & entries that close over subs defined in outer
    or inner subs (‘my sub foo; sub bar; sub bar { &foo } }’ and
    ‘sub bar; sub bar { my sub foo; sub { sub foo { } } }’ respectively).
    
    This was resulting in assertion failures, unsurprisingly.
    
    Some of the tests I added, which were causing assertion failures, are
    now failing for other reasons, and are marked as to-do.

M       pad.c
M       t/cmd/lexsub.t

commit ee52e673a6d28821cd9838285d2be6941b267bc3
Author: Father Chrysostomos <[email protected]>
Date:   Fri Aug 3 18:01:06 2012 -0700

    perly.y: Remove MYSUB
    
    This token is not used any more.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit 1deaaa93e9aa76896fff6f80d7d6215b006c3de2
Author: Father Chrysostomos <[email protected]>
Date:   Fri Aug 3 12:41:11 2012 -0700

    CvNAME_HEK_set

M       cv.h
M       op.c
M       pad.c
M       scope.c

commit 831984c42c7a671c1b49922ccff2085851583679
Author: Father Chrysostomos <[email protected]>
Date:   Fri Aug 3 09:23:15 2012 -0700

    Clone my subs on scope entry
    
    The pad slot for a my sub now holds a stub with a prototype CV
    attached to it by proto magic.
    
    The prototype is cloned on scope entry.  The stub in the pad is used
    when cloning, so any code that references the sub before scope entry
    will be able to see that stub become defined, making these behave
    similarly:
    
        our $x;
        BEGIN { $x = \&foo }
        sub foo { }
    
        our $x;
        my sub foo { }
        BEGIN { $x = \&foo }
    
    Constants are currently not cloned, but that may cause bugs in
    pad_push.  I’ll have to look into that.
    
    On scope exit, lexical CVs go through leave_scope’s SAVEt_CLEARSV sec-
    tion, like lexical variables.  If the sub is referenced elsewhere, it
    is abandoned, and its proto magic is stolen and attached to a new stub
    stored in the pad.  If the sub is not referenced elsewhere, it is
    undefined via cv_undef.
    
    To clone my subs on scope entry, we create a sequence of introcv and
    clonecv ops.  See the huge comment in block_end that explains why we
    need two separate ops for each CV.
    
    To allow my subs to be defined in inner subs (my sub foo; sub { sub
    foo {} }), pad_add_name_pvn and S_pad_findlex now upgrade the entry
    for a my sub to a CV to begin with, so that fake entries added to pads
    (fake entries are those that reference outer pads) can share the same
    CV.  Otherwise newMYSUB would have to add the CV to every pad that
    closes over the ‘my sub’ declaration.  newMYSUB no longer throws away
    the initial value replacing it with a new one.
    
    Prototypes are not currently visible to sub calls at compile time,
    because the lexer sees the empty stub.  A future commit will
    solve that.
    
    When I added name heks to CV’s I made mistakes in a few places, by not
    turning on the CVf_NAMED flag, or by not clearing the field when free-
    ing the hek.  Those code paths were not exercised enough by state
    subs, so the problems did not show up till now.  So this commit fixes
    those, too.
    
    One of the tests in lexsub.t, involving foreach loops, was incorrect,
    and has been fixed.  Another test has been added to the end for a par-
    ticular case of state subs closing over my subs that I broke when ini-
    tially trying to get sibling my subs to close over each other, before
    I had separate introcv and clonecv ops.

M       embed.fnc
M       embed.h
M       op.c
M       pad.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       pp.c
M       proto.h
M       scope.c
M       t/cmd/lexsub.t

commit f6b497c3f0003654400601d6e4def82e60d1f6b2
Author: Father Chrysostomos <[email protected]>
Date:   Fri Aug 3 09:29:38 2012 -0700

    cv_clone: panic for no pad
    
    cv_clone has serendipitously gained the ability to clone CVs without
    pads.  It is not clear that we want to add this ability to this API
    function, because we would be stuck supporting it, even if we came up
    with a better interface.  It used to crash or fail an assertion if
    there was no pad.

M       pad.c

commit 90019d45988d3499cca116f5fd445e7f22844424
Author: Father Chrysostomos <[email protected]>
Date:   Thu Aug 2 13:45:31 2012 -0700

    pad.c: Let S_cv_clone clone stubs
    
    This will be used by cv_clone_into (which does not exist yet) in a
    later commit.  pp_clonecv will use cv_clone_into.
    
    Teasing out the pad-related and non-pad-related parts of cv_clone
    was the easiest way to do this.  Now the pad stuff is in a separate
    function.

M       pad.c

commit 1b1e0879405d2aee95677d0b27974ed5d30dd516
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 29 18:47:48 2012 -0700

    op.c: Remove proto storage optimisation for lex subs
    
    It was already #if 0’d out.  This optimisation, copied from package
    subs, only makes sense when there is autoloading, which lexical subs
    don’t do.  Hence, lexical stubs will be rare indeed, so having an
    optimisation for those just creates more nooks to hide bugs.

M       op.c

commit 5f5599ae87f79b43056d37f6334525312f999a32
Author: Father Chrysostomos <[email protected]>
Date:   Thu Aug 2 22:11:08 2012 -0700

    Add clonecv op type
    
    This will be used for cloning a ‘my’ sub on scope entry.
    I was going to use pp_padcv for this, but it would end up having a
    top-level if/else.

M       ext/Opcode/Opcode.pm
M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcode.pl
M       regen/opcodes

commit ca253a1e142d243ef047723d6e97c4c16682c529
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 26 18:21:02 2012 -0700

    Add introcv op type
    
    This will be used for introducing ‘my’ subs on scope entry, by turning
    off the stale flag.

M       ext/Opcode/Opcode.pm
M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcode.pl
M       regen/opcodes

commit eedfe427db603e6c8282f849633e1607b051b5ae
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 26 12:38:14 2012 -0700

    Let state sub fwd decls and nested subs work in anons
    
    I had this working:
    
    state sub foo;
    sub other {
        sub foo { # defines the state sub declared outside
            ...
        }
    }
    
    But it failed inside an anonymous subroutine:
    
    sub {
        state sub foo;
        sub other {
            sub foo { # defines the state sub declared outside
                ...
            }
        }
    }
    
    When an anonymous (or otherwise clonable) sub is cloned, any state
    vars, and, likewise, any state subs, inside it are cloned, too.
    
    In the first example above the state sub forward declaration creates
    a subroutine stub.  The ‘other’ sub’s ‘sub foo’ declaration 
creates a
    pad entry in other’s pad that closes over the outer foo immediately,
    so the same stub is visible in two pads.  The sub foo {} declaration
    uses that stub.
    
    When the outer sub containing the forward declaration is clonable,
    the pad entry is not closed over immediately at compile time, because
    the pad entry is just a prototype, not the actual value that will be
    shared by the clone and its nested subs.  So the inner pad entry does
    not contain the sub.
    
    So the actual creation of the sub, if it only looks at the inner
    pad (other’s pad), will not see the stub, and will not attach a
    body to it.
    
    This was the result:
    
    $ ./miniperl -e 'CORE::state sub foo; CORE::state sub bar { sub foo {warn 
called} }; foo()'
    called at -e line 1.
    $ ./miniperl -e 'sub { CORE::state sub foo; CORE::state sub bar { sub foo 
{warn called} }; foo() }->()'
    Undefined subroutine &foo called at -e line 1.
    
    This commit fixes that by having newMYSUB follow the CvOUTSIDE chain
    to find the original pad entry where it defines the sub, if the for-
    ward declaration is occurs outside and has not been closed over yet.

M       op.c
M       t/cmd/lexsub.t

commit 951923837ae431f94aa31244e325d341d4071890
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 12 23:31:52 2012 -0700

    Add proto magic type
    
    This will be used for storing the prototype CV of a ‘my’ sub.  The
    clone needs to occupy the pad entry so that padcv ops will be able to
    find it.  That means the clone has to displace its prototype.  In case
    the same sub is called recursively, we still need to be able to access
    the prototype.

M       mg_names.c
M       mg_raw.h
M       mg_vtable.h
M       pod/perlguts.pod
M       regen/mg_vtable.pl

commit 96f3a2a4dae4c1ab90075a75c1b20e9728a27e28
Author: Father Chrysostomos <[email protected]>
Date:   Tue Jul 10 20:18:48 2012 -0700

    First stab at my sub
    
    This does just enough to get things to compile.
    
    They currently do weird things in edge cases, including ‘Bizarre
    copy of CODE’.
    
    ‘my sub’ now produces a SUB token, and goes through the same grammar
    rule as ‘state sub’ and just plain ‘sub’.  The separate MYSUB branch
    of the barestmt rule will go soon, as it is now unused.

M       op.c
M       t/cmd/lexsub.t
M       t/lib/croak/op
M       toke.c

commit f7670c079fc31c150dfdf45254e8f296b23e1ccf
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 9 22:25:24 2012 -0700

    op.c:newMYSUB: Pop scope after creating sub
    
    I was popping the scope before creating the sub in order to expose the
    parent pad, where the new sub is to be stored.
    
    That can cause problems, since ops may still be created that get
    attached to the new sub.  Those ops will end up using the parent sub’s
    slab in that case.  If the parent sub does not finish compiling, due
    to an error, it may clean out its slab, freeing ops that the inner sub
    is using, so the inner sub, when freed, will try to free ops that are
    no longer in allocated memory, as the slab is gone.  Most of the time,
    the inner ops won’t have been reused for anything, so the op type will
    still be OP_FREED, and op_free will do nothing (except a single bad
    read).  But debugging builds detect that and fail an assertion.
    
    Popping the scope afterwards actually does simplify things, surpris-
    ingly enough.
    
    I was able to produce this bug with a one-liner, but it did not fail
    as part of the test suite.  So this fix includes no test.
    
    Since the o variable in newMYSUB is a padop, it can only be freed when
    its pad is active.  It is created before the sub, so it cannot be
    freed until the scope has been popped, so it has to go at the bot-
    tom.  If an error occurs during newMYSUB, opslab_force_free will take
    care of it.

M       op.c

commit dad15a3888470f446078d6a2ee26cb7ab70f4321
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 9 18:02:33 2012 -0700

    dump.c: Dump CvNAME_HEK

M       dump.c

commit 0d5129d8ad0607283fc23fcfdadf159dfcf997c6
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 9 13:00:28 2012 -0700

    Remove & from redef warnings for lex subs
    
    I started to write this, creating a special SV to hold the name with-
    out the ampersand, but then never used that SV.
    
    This is just for consistency with package subs.
    
    I also made this slightly more efficient when warnings are off.

M       op.c
M       t/cmd/lexsub.t

commit 4e7969c201f2b8eaf60169a4f4e0ca854271dddd
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 9 12:52:48 2012 -0700

    lexsub.t: Fix another test
    
    The problem with writing to-do tests is that it is very easy to get
    the tests wrong, such that they continue to fail even when the prob-
    lems they test for are fixed.

M       t/cmd/lexsub.t

commit e7ce64df1a81aa36e2468222069f3e9d2c1e3c5f
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 9 06:29:09 2012 -0700

    Clone state subs in anon subs
    
    Since state variables are not shared between closures, but only
    between invocations of the same closure, state subs should behave
    the same way.
    
    This was a little tricky.  When we clone a sub, we now clone inner
    state subs at the same time.  When walking through the pad, cloning
    items, we cannot simply clone the inner sub when we see it, because it
    may close over things we haven’t cloned yet:
    
        sub {
            state sub foo;
            my $x
            sub foo { $x }
        }
    
    We can’t just delay cloning it and do it afterwards, because they may
    be multiple subs closing over each other:
    
        sub {
           state sub foo;
           state sub bar;
           sub foo { \&bar }
           sub bar { \&foo }
        }
    
    So *all* the entries in the new pad must be filled before any inner
    subs can be cloned.
    
    So what we do is put a stub in place of the cloned sub.   And then
    in a second pass clone the inner subs, reusing the stubs from the
    first pass.

M       pad.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       t/cmd/lexsub.t

commit 4c8fdde987e998d6d3f199600004cf8ca2a3daf5
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 8 14:51:10 2012 -0700

    perldiag: closure referents → closure references
    
    This goes back to 2ba9eb46.

M       pod/perldiag.pod

commit d83fe604fb46dbea4a5f46e5fb40ab3ed9df12c5
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 8 14:42:39 2012 -0700

    Don’t say ‘variable &foo’ in warnings
    
    It should be ‘subroutine &foo’.  (It could be ‘subroutine foo’, but 
we
    use both forms elsewhere, and &foo is the easier to implement, the &
    already being contained in the pad name.)

M       pad.c
M       pod/perldiag.pod
M       t/cmd/lexsub.t

commit 8e98ec502ed7664350b66a8b73ee4b9a2e8a47e0
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 8 14:28:22 2012 -0700

    lexsub.t: Fix some tests
    
    I got this working a few commits ago, but the tests mentioned the
    wrong sub name.

M       t/cmd/lexsub.t

commit 7e65dc5cf8f54715914988cf2bb257112df7adb3
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 8 14:18:43 2012 -0700

    Make pad_fixup_inner_anons cope with closed-over subs
    
    When a sub starts being parsed, a new CV is created.  When it fin-
    ishes, it is stored in its final location.  If there is a stub there
    already, the pad is copied to the stub and the body attached thereto.
    
    Since there may be closures inside the sub whose CvOUTSIDE
    pointers point to the temporary CV used during compilation,
    pad_fixup_inner_anons is called, to reassign all those
    CvOUTSIDE pointers.
    
    This happens in cases like this:
    
        sub f;
        sub f { sub { } }
    
    When a sub closes over a lexical item in an outer sub, the inner sub
    gets its own pad entry with the same value as the outer pad entry.
    
    This means that, now that we have lexical subs (currently just state
    subs), we can end up with a pad entry (&s) holding a sub whose
    CvOUTSIDE does not point to the sub (f) that owns the pad:
    
        state sub s { }
        sub f { s() }
    
    If the f sub has to reuse a stub, then pad_fixup_inner_anons gets to
    see that, and complains bitterly:
    
    $ ./perl -Ilib -E 'state sub s; sub f; sub f { s() }'
    Assertion failed: (CvOUTSIDE(innercv) == old_cv), function 
Perl_pad_fixup_inner_anons, file pad.c, line 2095.
    Abort trap

M       pad.c
M       t/cmd/lexsub.t

commit edc8ab7e8c6e6e06f61daeb1765f5f4e60c29d1d
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 23:46:52 2012 -0700

    ‘Undefined subroutine &foo called’ for lex subs
    
    instead of just ‘Undefined subroutine called’ without the name.

M       pp_hot.c
M       t/cmd/lexsub.t

commit cedcf37d634826ed2ef43a86904e2aeb1e0d820d
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 23:12:20 2012 -0700

    op.c:newMYSUB: Remove unused vars

M       op.c

commit 398c556dfa9cd8f9ff78f923a1972ad15deaa009
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 23:11:23 2012 -0700

    op.c:newMYSUB: inline var used only once
    
    as of the previous commit

M       op.c

commit 93ac2ac50fb17fd9ee539d7f1568338cf1808019
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 23:07:55 2012 -0700

    Lexical stubs should not AUTOLOAD
    
    There is a feature that allows stubs to fall back to their GVs’
    CVs when called.  If I reference a stub, e.g., \&bar, and then
    bar is autoloaded, the AUTOLOAD sub assigning *bar = *foo or
    *bar = sub {...}, I can still call the stub to which I have a refer-
    ence, and it will fall back to the overloaded sub.
    
    That is all fine and dandy, but it causes any stub that references a
    GV via its CvGV pointer to call that GV’s CV.  If we name a lexical
    sub by pointing its CvGV pointer at the GV whose name we want it to
    have, then the lexical sub, if undefined, will try to fall back to an
    autoloaded sub.
    
    That causes things to gang agley in cases like this:
    
        use 5.01;
        sub foo { } # package sub
        state sub foo;
        foo(); # calls lexical sub; falls back to package sub
    
    While we could fix this by flagging the sub and checking for the flag
    in pp_entersub (as we do with anonymous subs), it is better simply to
    use a HEK, instead of a GV.  Since a GV is quite heavyweight for stor-
    ing just a name, I was going to do that anyway, eventually.  Doing it
    now fixes a bug.

M       op.c

commit 3f3c0df72721f2b700b808c26174628e0413bdac
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 17:35:10 2012 -0700

    Allow CVs to point to HEKs rather than GVs
    
    This will allow named lexical subs to exist independent of GVs.

M       cv.h
M       ext/B/B.xs
M       gv.c
M       pad.c
M       pp.c
M       sv.c
M       sv.h

commit d2d87a0981a8aba1c21e57c79c9d2f02491c8cf2
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jul 7 12:18:49 2012 -0700

    Implement padcv
    
    State subs can now be referenced and called.  Most of the tests in
    lexsub.t are now passing.  I noticed mistakes in a couple of the
    tests and corrected them.  In doing so I got an assertion failure
    during compilation, so the tests in question I wrapped in a skipped
    string eval.
    
    State subs are now mostly working, but there are a few things to
    clean up still.

M       op.c
M       pp.c
M       t/cmd/lexsub.t

commit ad7c40ba0619ce41decbdb352317e04a4847a1d0
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 5 23:28:43 2012 -0700

    Test state subs
    
    Most of these tests are still to-do.  The previous commit got every-
    thing compiling at least.  Then I went through putting eval{} around
    all the dying tests and marking the failing tests as to-do.
    
    At least this way I don’t have to do everything at once (even though
    that was how I wrote the tests).
    
    About the only thing that works is constant inlining, of all things.

M       t/cmd/lexsub.t

commit 3186e17137484e52d2054047e9a9237d5d6b99ac
Author: Father Chrysostomos <[email protected]>
Date:   Fri Jul 6 23:35:15 2012 -0700

    Look up state subs in the pad
    
    This commit does just enough to get things compiling.  The padcv op
    is still unimplemented (in fact, converting the padany to a padcv is
    still not done), so you can’t actually run the code yet.
    
    Bareword lookup in yylex now produces PRIVATEREF tokens for state
    subs, so the grammar has been adjusted to accept a ‘subname’ in sub
    calls (PRIVATEREF or WORD) where previously only a WORD was permitted.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit ef2900c430d2b7c7133c1ef1a1b781d536e526a8
Author: Father Chrysostomos <[email protected]>
Date:   Fri Jul 6 14:31:31 2012 -0700

    op.c:newMYSUB: disable stub optimisation
    
    It will be a lot easier to get things working without this, for now.
    It can be reënabled later.  It might not be worth it, though, as
    AUTOLOADing will ignore lexical subs, and this optimisation is mainly
    for AUTOLOAD stubs that are rarely used.

M       op.c

commit c565d45d7ce8bcd8c7066c5a2a7c085d919474c8
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 5 23:22:21 2012 -0700

    Store state subs in the pad
    
    In making ‘sub foo’ respect previous ‘our sub’ declarations in a
    recent commit, I actually made ‘state sub foo’ into a syntax error.
    (At the time, I patched up MYSUB in perly.y to keep the tests for ‘"my
    sub" not yet implemented’ still working.)  Basically, it was creat-
    ing an empty pad entry, but returning something that perly.y was not
    expecting.
    
    This commit adjusts the grammar to allow the SUB branch of barestmt to
    accept a PRIVATEREF for its subname, in addition to a WORD.  It reuses
    the subname rule that SUB used to use (before our subs were added),
    gutting it to remove the special block handling, which SUB now tokes
    care of.  That means the MYSUB rule will no longer turn on CvSPECIAL
    on the PL_compcv that is going to be thrown away anyway.
    
    The code for special blocks (BEGIN, END, etc.) that turns on CvSPECIAL
    now checks for state subs and skips those.  It only applies to our
    subs and package subs.
    
    newMYSUB has now actually been written.  It basically duplicates
    newATTRSUB, except for GV-specific things.  It does currently vivify a
    GV and set CvGV, but I am hoping to change that later.  I also hope to
    merge some of the code later, too.
    
    I changed the prototype of newMYSUB to make it easier to use.  It is
    not used anywhere on CPAN and has always simply died, so that should
    be all right.

M       embed.fnc
M       embed.h
M       op.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       proto.h

commit 8f998407f45540653bce5d1c7ef154930fc654c0
Author: Father Chrysostomos <[email protected]>
Date:   Thu Jul 5 10:41:05 2012 -0700

    lexsub.t: Add test name, test override from another pkg
    
    The bareword logic in toke.c looks up GVs in various places.  This
    tests that we are bypassing those correctly.

M       t/cmd/lexsub.t

commit 4c81e96027321f2c2aca2a0dd749d609ea1171d5
Author: Father Chrysostomos <[email protected]>
Date:   Wed Jul 4 23:18:32 2012 -0700

    Let barewords look up our subs
    
    These take precedence over built-in keywords (just as my $AUTOLOAD
    shadows the package var), but not the keyword plugin, as the latter
    takes precedence over labels, and these don’t.

M       t/cmd/lexsub.t
M       toke.c

commit 94235ff84e94897a3773e10a354043b1fb9cb929
Author: Father Chrysostomos <[email protected]>
Date:   Wed Jul 4 14:09:46 2012 -0700

    toke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
    
    There is no need to allocate a separate ‘tmpbuf’ and then copy it into
    PL_tokenbuf afterwards.

M       toke.c

commit 1353b1c8ee08dd139369e2eed700a6775c020f68
Author: Father Chrysostomos <[email protected]>
Date:   Wed Jul 4 09:13:17 2012 -0700

    Make ‘sub foo{}’ respect ‘our foo’
    
    This commit switches all sub definitions, whether with ‘our’ or not,
    to using S_force_ident_maybe_lex (formerly known as S_pending_ident).
    
    This means that an unqualified (no our/my/state or package prefix)
    ‘sub foo’ declaration does a pad lookup, just like $foo.
    
    It turns out that the vivification that I added to the then
    S_pending_ident for CVs was unnecessary and actually buggy.  We
    *don’t* want to autovivify GVs for CVs, because they might be con-
    stants or forward declarations, which are stored in a simpler form.
    
    I also had to change the subname rule used by MYSUB in perly.y, since
    it can now be fed a PRIVATEREF, which it does not expect.  This may
    prove to be temporary, but it keeps current tests passing.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       t/cmd/lexsub.t
M       toke.c

commit ef125cce350a48d5893952160bd1022b6e10b548
Author: Father Chrysostomos <[email protected]>
Date:   Wed Jul 4 06:23:16 2012 -0700

    Test initial tick in sub declaration

M       t/comp/parser.t

commit af46726f821d157ffde280fdc91e44ccbc4ee36d
Author: Father Chrysostomos <[email protected]>
Date:   Wed Jul 4 00:17:55 2012 -0700

    Fix our sub with proto
    
    yylex must emit exactly one token each time it is called.  Some-
    times yylex needs to parse several tokens at once.  That’s what
    the various force functions are for.  But that is also what
    PL_pending_ident is for.
    
    The various force_next, force_word, force_ident, etc., functions keep
    a stack of tokens (PL_nextval/PL_nexttype) that yylex will check imme-
    diately when called.
    
    PL_pending_ident is used to track a single identifier that yylex will
    hand off to S_pending_ident to handle.
    
    S_pending_ident is the only piece of code for resolving an identi-
    fier that could be lexical but could also be a package variable.
    force_ident assumes it is looking for a package variable.
    
    force_* takes precedence over PL_pending_ident.
    
    All this means that, if an identifier needs to be looked up in the pad
    on the next yylex invocation, it has to use PL_pending_ident, and the
    force_* functions cannot be used at the same time.
    
    Not realising that, when I made ‘our sub foo’ store the sub in the
    pad I also made ‘our sub foo ($)’ into a syntax error, because it
    was being parsed as ‘our sub ($) foo’ (the prototype being 
‘forced’);
    i.e., the pending tokens were being pulled out of the ‘queue’ in the
    wrong order.  (I put queue in quotes, because one queue and one unre-
    lated buffer together don’t exactly count as ‘a queue’.)
    
    Changing PL_pending_ident to have precedence over the force stack
    breaks ext/XS-APItest/t/swaptwostmts.t, because the statement-parsing
    interface does not localise PL_pending_ident.  It could be changed to
    do that, but I don’t think it is the right solution.
    
    Having two separate pending token mechanisms makes things need-
    lessly fragile.
    
    This commit eliminates the PL_pending_ident mechanism and
    modifies S_pending_ident (renaming it in the process to
    S_force_ident_maybe_lex) to work with the force mechanism.  I was
    going to merge it with force_ident, but the two make incompatible
    assumptions that just complicate the code if merged.  S_pending_ident
    needs the sigil in the same string buffer, to pass to the pad inter-
    face.  force_ident needs to be able to work without a sigil present.
    
    So now we only have one queue for pending tokens and the order is more
    predictable.

M       embed.fnc
M       parser.h
M       proto.h
M       sv.c
M       t/cmd/lexsub.t
M       toke.c

commit dbbfa536bd7f2506858f46ebd615b3d16e109f44
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 2 21:26:13 2012 -0700

    Make do sub() respect our declarations

M       t/cmd/lexsub.t
M       toke.c

commit adeb927814b8877ba4643d6691da273cf10750d1
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 2 12:29:48 2012 -0700

    lexsub.t: Fix a test
    
    This is not testing what I meant it to test: that ‘sub d’ will respect
    a preceding ‘our sub d;’.  If ‘sub d’ is in the same package, it 
makes
    no difference, so the test tests nothing.
    
    It turns out this does not work yet.

M       t/cmd/lexsub.t

commit c24c45a11061d8b4659bbccf26888fe451341d93
Author: Father Chrysostomos <[email protected]>
Date:   Mon Jul 2 09:07:31 2012 -0700

    Use test.pl in lexsub.t
    
    I thought cmd/ couldn’t use test.pl, but was mistaken.

M       t/cmd/lexsub.t

commit 577b722cadc8c53a90e393ad6c3f86da1428df39
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 1 23:05:21 2012 -0700

    Allow test_bootstrap.t to run from the top level

M       t/porting/test_bootstrap.t

commit e0c314be87c592557029bd0bcec7307948d56a99
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 1 22:53:41 2012 -0700

    Make &foo respect our sub
    
    This changes &foo to go through S_pending_ident (by setting
    PL_pending_ident, which causes yylex to defer to S_pending_ident for
    the next token) the way $foo and %foo do.
    
    This necessitated reducing the maximum identifier length of &foo from
    252 to 251, making it match @foo, $foo, etc.  So somebody’s JAPH might
    break. :-)

M       MANIFEST
A       t/cmd/lexsub.t
M       t/comp/parser.t
M       toke.c

commit 5265fe45d43ba700583ef340135e5a99e05a497d
Author: Father Chrysostomos <[email protected]>
Date:   Sun Jul 1 20:23:06 2012 -0700

    pad.c apidocs: Missing fullstop

M       pad.c

commit b259edfce608b4efbb36b25dbd694ecff48823a6
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jun 30 23:20:25 2012 -0700

    Allocate ‘our sub’ in the pad
    
    Currently the name is only allocated there.  Nothing fetches it yet.
    
    Notes on the implementation:
    
    S_pending_ident contains the logic for determining whether $foo or
    @foo refers to a lexical or package variable.
    
    yylex defers to S_pending_ident if PL_pending_ident is set.
    
    The KEY_sub case in yylex is changed to set PL_pending_ident instead
    of using force_word.  For package variables (including our),
    S_pending_ident returns a WORD token, which is the same thing that
    force_word produces.  So *that* aspect of this change does not affect
    the grammar.  However....
    
    The barestmt rule’s SUB branch begins with ‘SUB startsub subname’.
    startsub is a null rule that creates a new sub in PL_compcv via
    start_subparse().  subname is defined in terms of WORD and also checks
    whether this is a special block, turning on CvSPECIAL(PL_compcv) if
    it is.  That flag has to be visible during compilation of the sub.
    
    But for a lexical name, such as ‘our foo’, to be allocated in the
    right pad, it has to come *before* startsub, i.e., ‘SUB subname
    startsub’.
    
    But subname needs to modify the sub that startsub created, set-
    ting the flag.
    
    So I copied (not moved, because MYSUB still uses it) the name-checking
    code from the subname rule into the SUB branch of barestmt.  Now that
    uses WORD directly instead of invoking subname.  That allows the code
    there to set everything up in the right order.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit 7d605feab54aabf0ddf150f781154e9cb062144e
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jun 30 23:00:57 2012 -0700

    Increase $Opcode::VERSION to 1.24

M       ext/Opcode/Opcode.pm

commit ededa27a2e013b28f02c99250ad48a1e5fd21f5d
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jun 30 23:00:11 2012 -0700

    Add padcv to Opcode.pm

M       ext/Opcode/Opcode.pm

commit ba97a1556a19264f28eb5157ba8cfd4fc11ac171
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jun 30 22:29:28 2012 -0700

    padcv op type

M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcodes

commit 00cfb7460e34cf07e113c8e0077a1d056a8b7eff
Author: Father Chrysostomos <[email protected]>
Date:   Sat Jun 30 17:31:32 2012 -0700

    Don’t allow name after our/state sub
    
    It was a mistake that this was ever allowed.

M       pod/perldiag.pod
M       t/lib/croak/toke
M       toke.c
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to