platform/upstream/perl.git
11 years agoUse the right outside for my subs defined in inner subs
Father Chrysostomos [Wed, 15 Aug 2012 01:10:40 +0000 (18:10 -0700)]
Use the right outside for my subs defined in inner subs

In this example,

{
  my sub foo;
  sub bar {
    sub foo { }
  }
}

the foo sub is cloned when the scope containing the ‘my sub’ declara-
tion is entered, but foo’s CvOUTSIDE pointer points to something other
than the active sub.  cv_clone assumes that the currently-running sub
is the right sub to close over (at least for subs; formats are another
matter).  That was true in the absence of my subs.  This commit
changes it to account.

I had to tweak the test, which was wrong, because sub foo was closing
over a stale var.

11 years agoFix Peek.t
Father Chrysostomos [Tue, 14 Aug 2012 19:24:43 +0000 (12:24 -0700)]
Fix Peek.t

11 years agoPreserve outside pointers of my subs with string eval
Father Chrysostomos [Tue, 14 Aug 2012 05:56:05 +0000 (22:56 -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.

11 years agoFix up outside pointers for my subs
Father Chrysostomos [Mon, 13 Aug 2012 00:57:35 +0000 (17:57 -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.

11 years agoperly.y: Remove MYSUB
Father Chrysostomos [Sat, 4 Aug 2012 01:01:06 +0000 (18:01 -0700)]
perly.y: Remove MYSUB

This token is not used any more.

11 years agoCvNAME_HEK_set
Father Chrysostomos [Fri, 3 Aug 2012 19:41:11 +0000 (12:41 -0700)]
CvNAME_HEK_set

11 years agoClone my subs on scope entry
Father Chrysostomos [Fri, 3 Aug 2012 16:23:15 +0000 (09:23 -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.

11 years agocv_clone: panic for no pad
Father Chrysostomos [Fri, 3 Aug 2012 16:29:38 +0000 (09:29 -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.

11 years agopad.c: Let S_cv_clone clone stubs
Father Chrysostomos [Thu, 2 Aug 2012 20:45:31 +0000 (13:45 -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.

11 years agoop.c: Remove proto storage optimisation for lex subs
Father Chrysostomos [Mon, 30 Jul 2012 01:47:48 +0000 (18:47 -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.

11 years agoAdd clonecv op type
Father Chrysostomos [Fri, 3 Aug 2012 05:11:08 +0000 (22:11 -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.

11 years agoAdd introcv op type
Father Chrysostomos [Fri, 27 Jul 2012 01:21:02 +0000 (18:21 -0700)]
Add introcv op type

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

11 years agoLet state sub fwd decls and nested subs work in anons
Father Chrysostomos [Thu, 26 Jul 2012 19:38:14 +0000 (12:38 -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.

11 years agoAdd proto magic type
Father Chrysostomos [Fri, 13 Jul 2012 06:31:52 +0000 (23:31 -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.

11 years agoFirst stab at my sub
Father Chrysostomos [Wed, 11 Jul 2012 03:18:48 +0000 (20:18 -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.

11 years agoop.c:newMYSUB: Pop scope after creating sub
Father Chrysostomos [Tue, 10 Jul 2012 05:25:24 +0000 (22:25 -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.

11 years agodump.c: Dump CvNAME_HEK
Father Chrysostomos [Tue, 10 Jul 2012 01:02:33 +0000 (18:02 -0700)]
dump.c: Dump CvNAME_HEK

11 years agoRemove & from redef warnings for lex subs
Father Chrysostomos [Mon, 9 Jul 2012 20:00:28 +0000 (13:00 -0700)]
Remove & from redef warnings for lex subs

This is just for consistency with package subs.

11 years agolexsub.t: Fix another test
Father Chrysostomos [Mon, 9 Jul 2012 19:52:48 +0000 (12:52 -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.

11 years agoClone state subs in anon subs
Father Chrysostomos [Mon, 9 Jul 2012 13:29:09 +0000 (06:29 -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.

11 years agoperldiag: closure referents → closure references
Father Chrysostomos [Sun, 8 Jul 2012 21:51:10 +0000 (14:51 -0700)]
perldiag: closure referents → closure references

This goes back to 2ba9eb46.

11 years agoDon’t say ‘variable &foo’ in warnings
Father Chrysostomos [Sun, 8 Jul 2012 21:42:39 +0000 (14:42 -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.)

11 years agolexsub.t: Fix some tests
Father Chrysostomos [Sun, 8 Jul 2012 21:28:22 +0000 (14:28 -0700)]
lexsub.t: Fix some tests

I got this working a few commits ago, but the tests mentioned the
wrong sub name.

11 years agoMake pad_fixup_inner_anons cope with closed-over subs
Father Chrysostomos [Sun, 8 Jul 2012 21:18:43 +0000 (14:18 -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

11 years ago‘Undefined subroutine &foo called’ for lex subs
Father Chrysostomos [Sun, 8 Jul 2012 06:46:52 +0000 (23:46 -0700)]
‘Undefined subroutine &foo called’ for lex subs

instead of just ‘Undefined subroutine called’ without the name.

11 years agoop.c:newMYSUB: inline var used only once
Father Chrysostomos [Sun, 8 Jul 2012 06:11:23 +0000 (23:11 -0700)]
op.c:newMYSUB: inline var used only once

as of the previous commit

11 years agoLexical stubs should not AUTOLOAD
Father Chrysostomos [Sun, 8 Jul 2012 06:07:55 +0000 (23:07 -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.

11 years agoAllow CVs to point to HEKs rather than GVs
Father Chrysostomos [Sun, 8 Jul 2012 00:35:10 +0000 (17:35 -0700)]
Allow CVs to point to HEKs rather than GVs

This will allow named lexical subs to exist independent of GVs.

11 years agoImplement padcv
Father Chrysostomos [Sat, 7 Jul 2012 19:18:49 +0000 (12:18 -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.

11 years agoTest state subs
Father Chrysostomos [Fri, 6 Jul 2012 06:28:43 +0000 (23:28 -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.

11 years agoLook up state subs in the pad
Father Chrysostomos [Sat, 7 Jul 2012 06:35:15 +0000 (23:35 -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.

11 years agoop.c:newMYSUB: disable stub optimisation
Father Chrysostomos [Fri, 6 Jul 2012 21:31:31 +0000 (14:31 -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.

11 years agoStore state subs in the pad
Father Chrysostomos [Fri, 6 Jul 2012 06:22:21 +0000 (23:22 -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.

11 years agolexsub.t: Add test name, test override from another pkg
Father Chrysostomos [Thu, 5 Jul 2012 17:41:05 +0000 (10:41 -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.

11 years agoLet barewords look up our subs
Father Chrysostomos [Thu, 5 Jul 2012 06:18:32 +0000 (23:18 -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.

11 years agotoke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
Father Chrysostomos [Wed, 4 Jul 2012 21:09:46 +0000 (14:09 -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.

11 years agoMake ‘sub foo{}’ respect ‘our foo’
Father Chrysostomos [Wed, 4 Jul 2012 16:13:17 +0000 (09:13 -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.

11 years agoFix our sub with proto
Father Chrysostomos [Wed, 4 Jul 2012 07:17:55 +0000 (00:17 -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.

11 years agoMake do sub() respect our declarations
Father Chrysostomos [Tue, 3 Jul 2012 04:26:13 +0000 (21:26 -0700)]
Make do sub() respect our declarations

11 years agolexsub.t: Fix a test
Father Chrysostomos [Mon, 2 Jul 2012 19:29:48 +0000 (12:29 -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.

11 years agoUse test.pl in lexsub.t
Father Chrysostomos [Mon, 2 Jul 2012 16:07:31 +0000 (09:07 -0700)]
Use test.pl in lexsub.t

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

11 years agoMake &foo respect our sub
Father Chrysostomos [Mon, 2 Jul 2012 05:53:41 +0000 (22:53 -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. :-)

11 years agoAllocate ‘our sub’ in the pad
Father Chrysostomos [Sun, 1 Jul 2012 06:20:25 +0000 (23:20 -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.

11 years agoAdd padcv to Opcode.pm
Father Chrysostomos [Sun, 1 Jul 2012 06:00:11 +0000 (23:00 -0700)]
Add padcv to Opcode.pm

11 years agopadcv op type
Father Chrysostomos [Sun, 1 Jul 2012 05:29:28 +0000 (22:29 -0700)]
padcv op type

11 years agoDon’t allow name after our/state sub
Father Chrysostomos [Sun, 1 Jul 2012 00:31:32 +0000 (17:31 -0700)]
Don’t allow name after our/state sub

It was a mistake that this was ever allowed.

11 years agoPATCH: [perl #82954] Make "Can't do {n,m} with n > m into warning
Karl Williamson [Sat, 15 Sep 2012 18:27:22 +0000 (12:27 -0600)]
PATCH: [perl #82954] Make "Can't do {n,m} with n > m into warning

This commit now causes this situation to warn instead of dying.  The
portion of the regular expression that can't match is optimized into an
OPFAIL.

11 years agoUpdate Sys-Syslog to CPAN version 0.32
Chris 'BinGOs' Williams [Sat, 15 Sep 2012 11:45:06 +0000 (12:45 +0100)]
Update Sys-Syslog to CPAN version 0.32

  [DELTA]

  0.32 -- 2012.09.14 -- Sebastien Aperghis-Tramoni (SAPER)
        [BUGFIX] CPAN-RT#69040: Don't modify @_ in syslog().
        [BUGFIX] Restore compatibility with Perl 5.6.0.
        [DOC] Perl-RT#81858: Fix some spelling errors (Peter J. Acklam).

11 years agoFix build under C++
Father Chrysostomos [Sat, 15 Sep 2012 05:55:56 +0000 (22:55 -0700)]
Fix build under C++

Commit 9ac6f7d90 was missing a few casts.

11 years ago[perl #114888] Localise PL_comppad_name in cv_clone
Father Chrysostomos [Sat, 15 Sep 2012 05:08:19 +0000 (22:08 -0700)]
[perl #114888] Localise PL_comppad_name in cv_clone

In 9ef8d56 I made closures share their pad name lists, and not just
the names themselves, for speed (no need to SvREFCNT_inc each name and
copy the list).

To make that work, I had to set PL_comppad_name in cv_clone, before
the pad_new call.  But I failed to move the PL_comppad_name localisa-
tion from pad_new to cv_clone.

So cv_clone would merrily clobber the previous value of
PL_comppad_name *before* localising it.

This only manifested itself in source filters.  Most of the time,
pp_anoncode is called at run time when either no code is being com-
piled (PL_comppad_name is only used at compile time) or inside a
BEGIN block which itself localises PL_comppad_name.  But inside a
Filter::Util::Call source filter there was no buffer like that to
protect it.

This meant that pad name creation (my $x) would create the name in the
PL_comppad_name belonging to the last-cloned sub.  A subsequent name
lookup ($x) would look in the correct place, as it uses the moral
equivalent of PadlistNAMES(CvPADLIST(PL_compcv)), not PL_comppad_name.
So it would not find it, resulting in a global variable or a stricture
violation.

11 years agoMake SUPER::method respect method changes in moved pkg
Father Chrysostomos [Fri, 14 Sep 2012 21:20:07 +0000 (14:20 -0700)]
Make SUPER::method respect method changes in moved pkg

->SUPER::method calls inside the Foo package cache the method for
reuse inside the stash Foo::SUPER.

Before the call, @Foo::SUPER::ISA is set to "Foo", so that those
caches will be invalidated properly.  (@ISA has the magic to make that
work.)  The actual value in @Foo::SUPER::ISA unused.

Now we have two types of package names.  If you alias the Foo package
and then clobber the original entry:

    *Bar:: = *Foo::;
    undef *Foo::;

__PACKAGE__ and HvNAME will return Foo still, but HvENAME (the effec-
tive name) will return Bar, because that is where the package is to be
found.

As of the previous commit, the package used for ISA is based on the
effective name, Bar::SUPER in this case.

But @Bar::SUPER::ISA is still set to Foo.  So even if we make changes
to methods inherited by what is now the Bar package, a previous method
cached in *Bar::SUPER::method will be reused.

BEGIN {
    *Bar:: = *Foo::;
    undef *Foo::;
}
package Bar;
@ISA = 'Baz';
*Baz::m = sub { "method 1" };
anthying->SUPER::m;
undef *Baz::m;
*Baz::m = sub { "method 2" };
warn anything->SUPER::m;
__END__
method 1 at - line 11.

11 years agoMake SUPER::method calls work in moved stashes
Father Chrysostomos [Fri, 14 Sep 2012 20:35:53 +0000 (13:35 -0700)]
Make SUPER::method calls work in moved stashes

BEGIN {
  *foo:: = *bar::;
  *bar:: = *baz;
}
package foo;
@ISA = 'door';
sub door::dohtem { 'dohtem' }
warn bar->SUPER::dohtem;
__END__
Can't locate object method "dohtem" via package "bar::SUPER" at - line 8.

When gv_fetchmethod_pvn_flags looks up a package it changes SUPER to
__PACKAGE__ . "::SUPER" first.  Then gv_fetchmeth_pvn uses HvNAME on
the package and strips off the ::SUPER suffix if any, before doing
isa lookup.

The problem with using __PACKAGE__ (actually HvNAME) is that it might
not be possible to find the current stash under that name.  HvENAME
should be used instead.

The above example happens to work if @ISA is changed to ‘our @ISA’,
but that is because of an @ISA bug.

11 years agoMake SUPER:: in main less sensitive
Father Chrysostomos [Fri, 14 Sep 2012 20:13:30 +0000 (13:13 -0700)]
Make SUPER:: in main less sensitive

$ perl -e '$main::SUPER::; sub bar::bar{} @ISA = bar; main->SUPER::bar'
$ perl -e '$SUPER::; sub bar::bar{} @ISA = bar; main->SUPER::bar'
Can't locate object method "bar" via package "main" at -e line 1.

(That’s 5.10.1.  More recent perls say package "SUPER".)

The only differnce that $SUPER:: variable makes is the name of
the SUPER:: package.  It ends up being called SUPER instead of
main::SUPER.

This causes problems because gv_fetchmeth_pvn, seeing a package end-
ing in ::SUPER, strips off the ::SUPER before doing isa lookup.

But SUPER does not end in ::SUPER, so this commit adjusts
gv_fetchmeth_pvn to account.

11 years agomethod.t: Add basic tests for SUPER
Father Chrysostomos [Fri, 14 Sep 2012 19:32:28 +0000 (12:32 -0700)]
method.t: Add basic tests for SUPER

11 years agomethod.t: Test more method-BLOCK edge cases
Father Chrysostomos [Fri, 14 Sep 2012 17:19:58 +0000 (10:19 -0700)]
method.t: Test more method-BLOCK edge cases

11 years agocop.h: Remove obsolete comment
Father Chrysostomos [Fri, 14 Sep 2012 17:12:33 +0000 (10:12 -0700)]
cop.h: Remove obsolete comment

623e6609 (2 Apr 2006) added this to cop.h:

+/* FIXME NATIVE_HINTS if this is changed from op_private (see perl.h)  */
+#define CopHINTS_get(c)                ((c)->op_private + 0)
+#define CopHINTS_set(c, h)     STMT_START {                            \
+                                   (c)->op_private                     \
+                                        = (U8)((h) & HINT_PRIVATE_MASK); \
+                               } STMT_END
+

d5ec2987 (20 May 2006) made this change, ignoring the FIXME:

 /* FIXME NATIVE_HINTS if this is changed from op_private (see perl.h)  */
-#define CopHINTS_get(c)                ((c)->op_private + 0)
+#define CopHINTS_get(c)                ((c)->cop_hints + 0)
 #define CopHINTS_set(c, h)     STMT_START {                            \
-                                   (c)->op_private                     \
-                                        = (U8)((h) & HINT_PRIVATE_MASK); \
+                                   (c)->cop_hints = (h);               \
                                } STMT_END

There is nothing to be fixed here, as vmsish.h uses ->op_private
directly, instead of using the CopHINTS macros.  Even having caller
return cop_hints instead of op_private doesn’t hurt, as newly-created
cops copy the vms hints from PL_hints to op_private.  So assigning
(caller $n)[8] to $^H will still work.

11 years agopp_ctl.c:caller: Remove obsolete comment
Father Chrysostomos [Fri, 14 Sep 2012 13:28:21 +0000 (06:28 -0700)]
pp_ctl.c:caller: Remove obsolete comment

This was added in f3aa04c29a, but stopped being relevant in
d5ec2987912.

11 years agoPrevent assertion failure with ‘no a a 3’
Father Chrysostomos [Fri, 14 Sep 2012 13:20:34 +0000 (06:20 -0700)]
Prevent assertion failure with ‘no a a 3’

This particular syntax error, whittled down from ‘no if $] >= 5.17.4
warnings => "deprecated"’ (which contains a type), causes the parser
to try to free an op from the new sub (for the BEGIN block) after
freeing the new sub.

This happens on line 526 of perly.c.  It should not be necessary for
the parser to free the op at this point, since after an error any ops
owned by incomplete subs’ slabs will be freed.

I’m leaving the other three instances of op_free in perly.c in place,
at least for now, since there are cases where the forced token stack
prevents ops from being freed when their subs are.

11 years agoIncrease $warnings::VERSION to 1.14
Father Chrysostomos [Fri, 14 Sep 2012 07:16:35 +0000 (00:16 -0700)]
Increase $warnings::VERSION to 1.14

11 years agoStop lexical warnings from turning off deprecations
Father Chrysostomos [Fri, 14 Sep 2012 06:46:46 +0000 (23:46 -0700)]
Stop lexical warnings from turning off deprecations

Some warnings, such as deprecation warnings, are on by default:

$ perl5.16.0 -e '$*'
$* is no longer supported at -e line 1.

But turning *on* other warnings will turn them off:

$ perl5.16.0 -e 'use warnings "void"; $*'
Useless use of a variable in void context at -e line 1.

Either all warnings in any given scope are controlled by lexical
hints, or none of them are.

When a single warnings category is turned on or off, if the warn-
ings were controlled by $^W, then all warnings are first turned on
lexically if $^W is 1 and all warnings are turned off lexically
if $^W is 0.

That has the unfortunate affect of turning off warnings when it was
only requested that warnings be turned on.

These categories contain default warnings:

ambiguous
debugging
deprecated
inplace
internal
io
malloc
utf8
redefine
syntax
glob
inplace
overflow
precedence
prototype
threads
misc

Most also contain regular warnings, but these contain *only*
default warnings:

debugging
deprecated
glob
inplace
malloc

So we can treat $^W==0 as equivalent to qw(debugging deprecated glob
inplace malloc) when enabling lexical warnings.

While this means that some default warnings will still be turned off
by ‘use warnings "void"’, it won’t be as many as before.  So at least
this is a step in the right direction.

(The real solution, of course, is to allow each warning to be turned
off or on on its own.)

11 years agoMake (caller $n)[9] respect std warnings
Father Chrysostomos [Fri, 14 Sep 2012 06:33:03 +0000 (23:33 -0700)]
Make (caller $n)[9] respect std warnings

In commit 7e4f04509c6 I forgot about caller.  This commit makes the
value returned by (caller $n)[9] assignable to ${^WARNING_BITS} to
produce exactly the same warnings settings, including warnings con-
trolled by $^W.

11 years agoperldiag: 13 years for reserved word deprec. is enough
Father Chrysostomos [Fri, 14 Sep 2012 04:23:34 +0000 (21:23 -0700)]
perldiag: 13 years for reserved word deprec. is enough

Use of ‘our’ (which was not a keyword yet) was deprecated in 1997 in
commit 85b81015bd, so that it could be used as a keyword later.

‘our’ variables were introduced in 1999 in commit 77ca0c92d2c, remov-
ing the deprecation warning.

The notice in perldiag survived, ...till now.

11 years agoperldiag: ‘Attempt to free unreffed scalar’ is S
Father Chrysostomos [Fri, 14 Sep 2012 01:01:44 +0000 (18:01 -0700)]
perldiag: ‘Attempt to free unreffed scalar’ is S

11 years agoperlhacktips.pod: readonly ops update (again)
Father Chrysostomos [Fri, 14 Sep 2012 00:50:15 +0000 (17:50 -0700)]
perlhacktips.pod: readonly ops update (again)

11 years agosv.c: %vd printf format microöptimisation
Father Chrysostomos [Thu, 13 Sep 2012 21:08:46 +0000 (14:08 -0700)]
sv.c: %vd printf format microöptimisation

The %vd printf format does not need to make two copies of a version
object’s stringification or stringify the object twice.

11 years agoFix %vd with alpha version
Father Chrysostomos [Thu, 13 Sep 2012 20:00:12 +0000 (13:00 -0700)]
Fix %vd with alpha version

There are five problems with it:

First, this warning is not suppressible, even with -X:

$ perl -Xe' sprintf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.

To keep the behaviour as close as possible to what it was already
without the incorrect behaviour, I have made it a default warning.

Secondly, putting it in the internal category does not make sense.
internal is a subset of severe, and contains warnings that indicate
internal inconsistencies, like ‘Scalars leaked’ and ‘Unbalanced string
table refcount’.  It should be in the printf warnings category.

Thirdly, if we turn warnings on explicitly, we see this:

$ perl -we '() = sprintf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.
Invalid conversion in printf: "%v" at -e line 1.

%vd is not invalid.  That warning is bogus.

Fourthly, %vd itself gets output when fed an alpha version:

$ perl -Xe 'printf "[%vd]\n", new version v1.1_1'
vector argument not supported with alpha versions at -e line 1.
[%vd]

If an argument is missing or invalid or what have you, the %-format
itself should not be output.  An empty string makes the most sense.

Fifthly, it leaks memory.  Run this and watch memory usage go up:

$ perl -e '
   warn $$; $SIG{__WARN__} = sub {}; $v = new version v1.1_1;
   sprintf "%vd", $v while 1
'

It does savesvpv before shortcircuiting for alphas.  But the corres-
ponding Safefree comes after the shortcircuiting, which skips it.

11 years agoperldiag: ‘Unbalanced string table’ is a default warning
Father Chrysostomos [Thu, 13 Sep 2012 15:35:39 +0000 (08:35 -0700)]
perldiag: ‘Unbalanced string table’ is a default warning

11 years agoperldiag: ‘Scalars leaked’ is a default warning
Father Chrysostomos [Thu, 13 Sep 2012 15:33:41 +0000 (08:33 -0700)]
perldiag: ‘Scalars leaked’ is a default warning

11 years agoAdd another include directory for the x2p files on VMS.
Craig A. Berry [Sat, 15 Sep 2012 00:43:05 +0000 (19:43 -0500)]
Add another include directory for the x2p files on VMS.

Because we now have:

  #include "../unicode_constants.h"

which is a Unix-style path and cannot be combined with [.x2p] and
get a valid result.

11 years ago[MERGE] eliminate PL_reginput
David Mitchell [Fri, 14 Sep 2012 07:53:26 +0000 (08:53 +0100)]
[MERGE] eliminate PL_reginput

The variable PL_reginput (which is actually part of the
global/per-interpreter variable PL_reg_state), is mainly used just
locally within the S_regmatch() function. In this role, it effectively
competes with the local-to-regmatch() variable locinput, as a pointer
that tracks the current match position.

Having two variables that do this is less efficient,and makes the code
harder to understand. So this series of commits:

1) removes PL_reginput, and replaces it with a var, reginput, local to
   regmatch();
2) successively removes more and uses of the reginput variable, until
3) it is eliminated altogether, leaving locinput as the sole 'here we are'
   pointer.

Looking at the CPU usage of running the t/re/*.t tests on a -O2,
non-threaded build, running each test suite 3 times, gives:

before: 55.35 55.66 55.69
after:  55.10 55.13 55.33

which indicates a small performance improvement of around 0.5%.

(The CPU usage of a single run of the whole perl test suite dropped from
783.31s to 777.23s).

11 years agoregmatch(): eliminate reginput variable
David Mitchell [Thu, 13 Sep 2012 21:41:02 +0000 (22:41 +0100)]
regmatch(): eliminate reginput variable

The remaining uses of reginput are all assignments; its value is
never used. So eliminate it.

Also, update the description of S_regrepeat(), which was woefully out of
date (but mentioned reginput).

11 years agoregmatch(): remove remaining reads of reginput
David Mitchell [Thu, 13 Sep 2012 19:28:01 +0000 (20:28 +0100)]
regmatch(): remove remaining reads of reginput

In the remaining place where the value of reginput is used, its value
should always be equal to locinput, so it can be eliminated there.

This is part of a campaign to eliminate the reginput variable.

11 years agoregmatch(): remove reginput from CURLY etc
David Mitchell [Thu, 13 Sep 2012 18:58:25 +0000 (19:58 +0100)]
regmatch(): remove reginput from CURLY etc

reginput mostly tracked locinput, except when regrepeat() was called.
With a bit of jiggling, it could be eliminated for these blocks of code.

This is part of a campaign to eliminate the reginput variable.

11 years agoregmatch(): remove reginput from CURLYM
David Mitchell [Thu, 13 Sep 2012 10:38:26 +0000 (11:38 +0100)]
regmatch(): remove reginput from CURLYM

reginput, locinput and st->locinput were being used in a little
ballet to determine the length of the first match.
This is now simply locinput - st->locinput, or its unicode equivalent;
so the code can be simplified.

Elsewhere in the block: where reginput was being used, locinput and/or
nextchr already contain the same info, so use them instead.

This is part of a campaign to eliminate the reginput variable.

11 years agoregmatch(): remove reginput from IFMATCH etc
David Mitchell [Thu, 13 Sep 2012 10:12:40 +0000 (11:12 +0100)]
regmatch(): remove reginput from IFMATCH etc

It was being used essentially as a temporary var within the branch,
so replace it with a temp var in a new block scope.

On return in IFMATCH_A / IFMATCH_A_fail, there's no need to set reginput
any more, so don't. The SUSPEND case used to set locinput = reginput, but
at that point, the two variables already always had the same value anyway.

This is part of a campaign to eliminate the reginput variable.

11 years agoregmatch(): remove reginput from TRIE_next_fail:
David Mitchell [Thu, 13 Sep 2012 09:28:11 +0000 (10:28 +0100)]
regmatch(): remove reginput from TRIE_next_fail:

It was being used essentially as a temporary var within the branch,
so replace it with a temp var in a new block scope.

This is part of a campaign to eliminate the reginput variable.

11 years agoregmatch(): make PUSH_STATE_GOTO dest explicit
David Mitchell [Thu, 13 Sep 2012 08:22:38 +0000 (09:22 +0100)]
regmatch(): make PUSH_STATE_GOTO dest explicit

Currently, the string position from where matching continues after a PUSH
is implicitly specified by the value of reginput, which is usually just
equal to locinput. Make this explicit by adding an extra argument to
PUSH_STATE_GOTO() etc.

This is part of a campaign to eliminate the reginput variable.

11 years agoeliminate PL_reginput
David Mitchell [Wed, 12 Sep 2012 19:10:44 +0000 (20:10 +0100)]
eliminate PL_reginput

PL_reginput (which is actually #defined to PL_reg_state.re_state_reginput)
is, to all intents and purposes, state that is only used within
S_regmatch().

The only other places it is referenced are in S_regtry() and S_regrepeat(),
where it is used to pass the current match position back and forth between
the subs.

Do this passing instead via function args, and bingo! PL_reginput is now
just a local var of S_regmatch().

11 years agoFix compilation for -DPERL_POISON and -DPERL_OLD_COPY_ON_WRITE together.
Nicholas Clark [Thu, 13 Sep 2012 20:22:29 +0000 (22:22 +0200)]
Fix compilation for -DPERL_POISON and -DPERL_OLD_COPY_ON_WRITE together.

These have been present since PERL_POISON was added in June 2005 by commit
94010e71b67db040. It seems that no-one has tried compiling with both defined
together.

11 years agoFix buggy -DPERL_POISON code in S_rxres_free(), exposed by a recent test.
Nicholas Clark [Thu, 13 Sep 2012 16:13:43 +0000 (18:13 +0200)]
Fix buggy -DPERL_POISON code in S_rxres_free(), exposed by a recent test.

The code had been buggily attempting to overwrite just-freed memory since
PERL_POISON was added by commit 94010e71b67db040 in June 2005. However, no
regression test exercised this code path until recently.

Also fix the offset in the array of UVs used by PERL_OLD_COPY_ON_WRITE to
store RX_SAVED_COPY(). It now uses p[2]. Previously it had used p[1],
directly conflicting with the use of p[1] to store RX_NPARENS().

The code is too intertwined to meaningfully do these as separate commits.

11 years agoRestore the build under -DPERL_OLD_COPY_ON_WRITE
Nicholas Clark [Thu, 13 Sep 2012 15:05:58 +0000 (17:05 +0200)]
Restore the build under -DPERL_OLD_COPY_ON_WRITE

This was broken as a side effect of commit 6502e08109cd003b, recently merged
to blead.

11 years agoRefactor t/op/push.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 02:25:24 +0000 (19:25 -0700)]
Refactor t/op/push.t to use test.pl instead of making TAP by hand.

11 years agoRefactor t/run/switch0.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 02:06:02 +0000 (19:06 -0700)]
Refactor t/run/switch0.t to use test.pl instead of making TAP by hand.

11 years agoRefactor t/op/overload_integer.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 01:54:13 +0000 (18:54 -0700)]
Refactor t/op/overload_integer.t to use test.pl instead of making TAP by hand.

With minor change from committer: Always assign $@ asap after an eval.

11 years agoRefactor t/op/exists_sub.t to use test.pl instead of making TAP by hand.
Colin Kuskie [Fri, 14 Sep 2012 01:42:37 +0000 (18:42 -0700)]
Refactor t/op/exists_sub.t to use test.pl instead of making TAP by hand.

11 years agoMerge branch for mostly regen/regcharclass.pl into blead
Karl Williamson [Fri, 14 Sep 2012 03:14:54 +0000 (21:14 -0600)]
Merge branch for mostly regen/regcharclass.pl into blead

I started this work planning to enhance regen/regcharclass.pl to accept
Unicode properties as input so that some small properties used in \X
could be compiled in, instead of having to be read from disk.  In doing
so, I saw some opportunities to move some EBCDIC dependencies down to a
more basic level, thus replacing quite a few existing ones with just a
couple at the lower levels.  This also led to my enhancing the macros
output by regcharclass.pl to be at least as good (in terms of numbers of
branches, etc) as the hand-coded ones it replaces.

I also spotted a few bugs in existing code that hadn't been triggered
yet.

11 years agoutf8.h: Use machine generated IS_UTF8_CHAR()
Karl Williamson [Thu, 6 Sep 2012 02:56:09 +0000 (20:56 -0600)]
utf8.h: Use machine generated IS_UTF8_CHAR()

This takes the output of regen/regcharclass.pl for all the 1-4 byte
UTF8-representations of Unicode code points, and replaces the current
hand-rolled definition there.  It does this only for ASCII platforms,
leaving EBCDIC to be machine generated when run on such a platform.

I would rather have both versions to be regenerated each time it is
needed to save an EBCDIC dependency, but it takes more than 10 minutes
on my computer to process the 2 billion code points that have to be
checked for on ASCII platforms, and currently t/porting/regen.t runs
this program every times; and that slow down would be unacceptable.  If
this is ever run under EBCDIC, the macro should be machine computed
(very slowly).  So, even though there is an EBCDIC dependency, it has
essentially been solved.

11 years agoregen/regcharclass.pl: Add ability to restrict platforms
Karl Williamson [Thu, 6 Sep 2012 02:48:15 +0000 (20:48 -0600)]
regen/regcharclass.pl: Add ability to restrict platforms

This adds the capability to skip definitions if they are for other than
a desired platform.

11 years agoutf8.h: Remove some EBCDIC dependencies
Karl Williamson [Thu, 6 Sep 2012 02:32:29 +0000 (20:32 -0600)]
utf8.h: Remove some EBCDIC dependencies

regen/regcharclass.pl has been enhanced in previous commits so that it
generates as good code as these hand-defined macro definitions for
various UTF-8 constructs.  And, it should be able to generate EBCDIC
ones as well.  By using its definitions, we can remove the EBCDIC
dependencies for them.  It is quite possible that the EBCDIC versions
were wrong, since they have never been tested.  Even if
regcharclass.pl has bugs under EBCDIC, it is easier to find and fix
those in one place, than all the sundry definitions.

11 years agoregen/regcharclass.pl: Add optimization
Karl Williamson [Wed, 5 Sep 2012 21:18:09 +0000 (15:18 -0600)]
regen/regcharclass.pl: Add optimization

On UTF-8 input known to be valid, continuation bytes must be in the
range 0x80 .. 0x9F.  Therefore, any tests for being within those bounds
will always be true, and may be omitted.

11 years agoregen/regcharclass.pl: White-space only
Karl Williamson [Wed, 5 Sep 2012 21:14:59 +0000 (15:14 -0600)]
regen/regcharclass.pl: White-space only

Indent a newly-formed block

11 years agoregen/regcharclass.pl: Extend previously added optimization
Karl Williamson [Wed, 5 Sep 2012 21:00:52 +0000 (15:00 -0600)]
regen/regcharclass.pl: Extend previously added optimization

A previous commit added an optimization to save a branch in the
generated code at the expense of an extra mask when the input class has
certain characteristics.  This extends that to the case where
sub-portions of the class have similar characteristics.  The first
optimization for the entire class is moved to right before the new loop
that checks each range in it.

11 years agoregen/regcharclass.pl: Rmv always true components from gen'd macro
Karl Williamson [Wed, 5 Sep 2012 15:30:34 +0000 (09:30 -0600)]
regen/regcharclass.pl: Rmv always true components from gen'd macro

This adds a test and returns 1 from a subroutine if the condition will
always match; and in the caller it adds a check for that, and omits the
condition from the generated macro.

11 years agoregen/regcharclass.pl: Add an optimization
Karl Williamson [Tue, 4 Sep 2012 20:54:26 +0000 (14:54 -0600)]
regen/regcharclass.pl: Add an optimization

Branches can be eliminated from the macros that are generated here
by using a mask in cases where applicable.  This adds checking to see if
this optimization is possible, and applies it if so.

11 years agoregen/regcharclass.pl: Rename a variable
Karl Williamson [Wed, 5 Sep 2012 16:26:22 +0000 (10:26 -0600)]
regen/regcharclass.pl: Rename a variable

I find it confusing that the array element name is the same as the full array

11 years agoregen/regcharclass.pl: Pass options deeper into call stack
Karl Williamson [Tue, 4 Sep 2012 20:12:13 +0000 (14:12 -0600)]
regen/regcharclass.pl: Pass options deeper into call stack

This is to prepare for future commits which will act differently at the
deep level depending on some of the options.

11 years agoUse macro not swash for utf8 quotemeta
Karl Williamson [Mon, 3 Sep 2012 22:59:09 +0000 (16:59 -0600)]
Use macro not swash for utf8 quotemeta

The rules for matching whether an above-Latin1 code point are now saved
in a macro generated from a trie by regen/regcharclass.pl, and these are
now used by pp.c to test these cases.  This allows removal of a wrapper
subroutine, and also there is no need for dynamic loading at run-time
into a swash.

This macro is about as big as I'm comfortable compiling in, but it
saves the building of a hash that can grow over time, and removes a
subroutine and interpreter variables.  Indeed, performance benchmarks
show that it is about the same speed as a hash, but it does not require
having to load the rules in from disk the first time it is used.

11 years agoregen/regcharclass.pl: Add new output macro type
Karl Williamson [Mon, 3 Sep 2012 22:54:56 +0000 (16:54 -0600)]
regen/regcharclass.pl: Add new output macro type

The new type 'high' is used on only above-Latin1 code points.  It is
designed for code that already knows the tested code point is not
Latin1, and avoids unnecessary tests.

11 years agoregen/regcharclass.pl: Add documentation
Karl Williamson [Mon, 3 Sep 2012 00:29:42 +0000 (18:29 -0600)]
regen/regcharclass.pl: Add documentation

11 years agoregen/regcharclass.pl: Error check input better
Karl Williamson [Mon, 3 Sep 2012 00:28:19 +0000 (18:28 -0600)]
regen/regcharclass.pl: Error check input better

This makes sure that the modifiers specified in the input are known to
the program.