In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/ded4dd2add376b302c561318612805c584ef9e6a?hp=1404b48744cfa915e3f54775feb4e9b6c10f3b91>
- Log ----------------------------------------------------------------- commit ded4dd2add376b302c561318612805c584ef9e6a Author: Nicholas Clark <[email protected]> Date: Wed Mar 17 17:16:24 2010 +0000 Convert REGNODE_{SIMPLE,VARIES} to a bitmask lookup, from a strchr() lookup. This is O(1) with no branching, instead of O(n) with branching. Deprecate the old implementation's externally visible variables PL_simple and PL_varies. Google codesearch suggests that nothing outside the core regexp code was using these. M regcomp.pl M regnodes.h commit 93882df08ca38a02b0381419b29fff019ec87ef7 Author: Nicholas Clark <[email protected]> Date: Wed Mar 17 16:41:27 2010 +0000 Change regcomp.pl to 0-based indexing for its arrays and loops. M regcomp.pl commit e52fc5395a9d11f134b6e4ecacde7782d1af6b26 Author: Nicholas Clark <[email protected]> Date: Wed Mar 17 13:58:25 2010 +0000 Encapsulate lookups in PL_{varies,simple} within macros REGNODE_{VARIES,SIMPLE} This allows the implementation of the lookup mechanism to change. M regcomp.c M regcomp.pl M regnodes.h commit f9ef50a71935a8e93b4030c12dcd1206ccab71ab Author: Nicholas Clark <[email protected]> Date: Wed Mar 17 13:33:48 2010 +0000 Generate PL_simple[] and PL_varies[] with regcomp.pl, rather than hard-coding. Add a new flags column to regcomp.sym, with V if the node type is in PL_varies, S if it is in PL_simple, and . if a placeholder is needed because subsequent optional columns are present. M regcomp.h M regcomp.pl M regcomp.sym M regnodes.h commit f8abb37e5b952f76a9e019137369e3f8ef5a58ae Author: Nicholas Clark <[email protected]> Date: Tue Mar 16 10:22:04 2010 +0000 Re-work the regcomp.sym to remove use of hard tabs. No data change. The tab separating name and type is replaced with whitespace, the tab marking the start of the description is replaced by a semicolon. M regcomp.pl M regcomp.sym commit 5014f7dab1e8d50a8f9ba9b88aa6446cfc8189ab Author: Nicholas Clark <[email protected]> Date: Tue Mar 16 09:50:29 2010 +0000 Correct the node numbers in comments. Really, should we be maintaining these manually? M regcomp.sym commit 20832bc55b5c8a1f61c1270e40b964ff1488847d Author: Nicholas Clark <[email protected]> Date: Tue Mar 16 09:48:35 2010 +0000 Remove stray tab character in definition for VERB. As VERB is "Used only for the type field of verbs" this is only a cosmetic change, causing that correct description to appear in the comment in regnodes.h. The change to regarglen doesn't affect anything, as the VERB type is never actually used for compiled nodes. M regcomp.sym M regnodes.h ----------------------------------------------------------------------- Summary of changes: regcomp.c | 8 +- regcomp.h | 31 -------- regcomp.pl | 108 ++++++++++++++++++++------ regcomp.sym | 247 +++++++++++++++++++++++++++++------------------------------ regnodes.h | 48 +++++++++++- 5 files changed, 257 insertions(+), 185 deletions(-) diff --git a/regcomp.c b/regcomp.c index c8c47e9..c290fbd 100644 --- a/regcomp.c +++ b/regcomp.c @@ -3116,7 +3116,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, } flags &= ~SCF_DO_STCLASS; } - else if (strchr((const char*)PL_varies,OP(scan))) { + else if (REGNODE_VARIES(OP(scan))) { I32 mincount, maxcount, minnext, deltanext, fl = 0; I32 f = flags, pos_before = 0; regnode * const oscan = scan; @@ -3268,7 +3268,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, /* Skip open. */ nxt = regnext(nxt); - if (!strchr((const char*)PL_simple,OP(nxt)) + if (!REGNODE_SIMPLE(OP(nxt)) && !(PL_regkind[OP(nxt)] == EXACT && STR_LEN(nxt) == 1)) goto nogo; @@ -3527,7 +3527,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, data->longest = &(data->longest_float); } } - else if (strchr((const char*)PL_simple,OP(scan))) { + else if (REGNODE_SIMPLE(OP(scan))) { int value = 0; if (flags & SCF_DO_SUBSTR) { @@ -4604,7 +4604,7 @@ reStudy: ri->regstclass = trie_op; } #endif - else if (strchr((const char*)PL_simple,OP(first))) + else if (REGNODE_SIMPLE(OP(first))) ri->regstclass = first; else if (PL_regkind[OP(first)] == BOUND || PL_regkind[OP(first)] == NBOUND) diff --git a/regcomp.h b/regcomp.h index a20d6e1..ad9a2cc 100644 --- a/regcomp.h +++ b/regcomp.h @@ -447,37 +447,6 @@ START_EXTERN_C #include "regnodes.h" #endif -/* The following have no fixed length. U8 so we can do strchr() on it. */ -#ifndef DOINIT -EXTCONST U8 PL_varies[]; -#else -EXTCONST U8 PL_varies[] = { - BRANCH, BACK, STAR, PLUS, CURLY, CURLYX, REF, REFF, REFFL, - WHILEM, CURLYM, CURLYN, BRANCHJ, IFTHEN, SUSPEND, CLUMP, - NREF, NREFF, NREFFL, - 0 -}; -#endif - -/* The following always have a length of 1. U8 we can do strchr() on it. */ -/* (Note that length 1 means "one character" under UTF8, not "one octet".) */ -#ifndef DOINIT -EXTCONST U8 PL_simple[]; -#else -EXTCONST U8 PL_simple[] = { - REG_ANY, SANY, CANY, - ANYOF, - ALNUM, ALNUML, - NALNUM, NALNUML, - SPACE, SPACEL, - NSPACE, NSPACEL, - DIGIT, NDIGIT, - VERTWS, NVERTWS, - HORIZWS, NHORIZWS, - 0 -}; -#endif - #ifndef PLUGGABLE_RE_EXTENSION #ifndef DOINIT EXTCONST regexp_engine PL_core_reg_engine; diff --git a/regcomp.pl b/regcomp.pl index 7fdbd13..9370487 100644 --- a/regcomp.pl +++ b/regcomp.pl @@ -24,7 +24,7 @@ use warnings; open DESC, 'regcomp.sym'; my $ind = 0; -my (@name,@rest,@type,@code,@args,@longj); +my (@name,@rest,@type,@code,@args,@flags,@longj); my ($desc,$lastregop); while (<DESC>) { s/#.*$//; @@ -35,12 +35,12 @@ while (<DESC>) { next; } unless ($lastregop) { - $ind++; - ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3; - ($type[$ind], $code[$ind], $args[$ind], $longj[$ind]) - = split /[,\s]\s*/, $desc, 4; + ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+)\s*;\s*(.*)/; + ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind]) + = split /[,\s]\s*/, $desc; + ++$ind; } else { - my ($type,@lists)=split /\s*\t+\s*/, $_; + my ($type,@lists)=split /\s+/, $_; die "No list? $type" if !...@lists; foreach my $list (@lists) { my ($names,$special)=split /:/, $list , 2; @@ -60,10 +60,10 @@ while (<DESC>) { die "unknown :type ':$special'"; } foreach my $suffix (@suffix) { - $ind++; $name[$ind]="$real$suffix"; $type[$ind]=$type; $rest[$ind]="state for $type"; + ++$ind; } } } @@ -79,6 +79,55 @@ close DESC; die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!" if $lastregop>256; +sub process_flags { + my ($flag, $varname, $comment) = @_; + $comment = '' unless defined $comment; + + $ind = 0; + my @selected; + my $bitmap = ''; + do { + my $set = $flags[$ind] && $flags[$ind] eq $flag ? 1 : 0; + # Whilst I could do this with vec, I'd prefer to do longhand the arithmetic + # ops in the C code. + my $current = do { + no warnings 'uninitialized'; + ord do { + no warnings 'substr'; + substr $bitmap, ($ind >> 3); + } + }; + substr $bitmap, ($ind >> 3), 1, chr($current | ($set << ($ind & 7))); + + push @selected, $name[$ind] if $set; + } while (++$ind < $lastregop); + my $out_string = join ', ', @selected, 0; + $out_string =~ s/(.{1,70},) /$1\n /g; + + my $out_mask = join ', ', map {sprintf "0x%02X", ord $_} split '', $bitmap; + + return $comment . <<"EOP"; +#define REGNODE_\U$varname\E(node) (PL_${varname}_bitmask[(node) >> 3] & (1 << ((node) & 7))) + +#ifndef DOINIT +EXTCONST U8 PL_${varname}[] __attribute__deprecated__; +#else +EXTCONST U8 PL_${varname}[] __attribute__deprecated__ = { + $out_string +}; +#endif /* DOINIT */ + +#ifndef DOINIT +EXTCONST U8 PL_${varname}_bitmask[]; +#else +EXTCONST U8 PL_${varname}_bitmask[] = { + $out_mask +}; +#endif /* DOINIT */ + +EOP +} + my $tmp_h = 'regnodes.h-new'; unlink $tmp_h if -f $tmp_h; @@ -103,15 +152,14 @@ EOP ; -for ($ind=1; $ind <= $lastregop ; $ind++) { - my $oind = $ind - 1; +for ($ind=0; $ind < $lastregop ; ++$ind) { printf $out "#define\t%*s\t%d\t/* %#04x %s */\n", - -$width, $name[$ind], $ind-1, $ind-1, $rest[$ind]; + -$width, $name[$ind], $ind, $ind, $rest[$ind]; } print $out "\t/* ------------ States ------------- */\n"; -for ( ; $ind <= $tot ; $ind++) { +for ( ; $ind < $tot ; $ind++) { printf $out "#define\t%*s\t(REGNODE_MAX + %d)\t/* %s */\n", - -$width, $name[$ind], $ind - $lastregop, $rest[$ind]; + -$width, $name[$ind], $ind - $lastregop + 1, $rest[$ind]; } print $out <<EOP; @@ -125,12 +173,12 @@ EXTCONST U8 PL_regkind[] = { EOP $ind = 0; -while (++$ind <= $tot) { +do { printf $out "\t%*s\t/* %*s */\n", -1-$twidth, "$type[$ind],", -$width, $name[$ind]; print $out "\t/* ------------ States ------------- */\n" - if $ind == $lastregop and $lastregop != $tot; -} + if $ind + 1 == $lastregop and $lastregop != $tot; +} while (++$ind < $tot); print $out <<EOP; }; @@ -143,13 +191,13 @@ static const U8 regarglen[] = { EOP $ind = 0; -while (++$ind <= $lastregop) { +do { my $size = 0; $size = "EXTRA_SIZE(struct regnode_$args[$ind])" if $args[$ind]; printf $out "\t%*s\t/* %*s */\n", -37, "$size,",-$rwidth,$name[$ind]; -} +} while (++$ind < $lastregop); print $out <<EOP; }; @@ -160,12 +208,12 @@ static const char reg_off_by_arg[] = { EOP $ind = 0; -while (++$ind <= $lastregop) { +do { my $size = $longj[$ind] || 0; printf $out "\t%d,\t/* %*s */\n", $size, -$rwidth, $name[$ind] -} +} while (++$ind < $lastregop); print $out <<EOP; }; @@ -181,20 +229,20 @@ EXTCONST char * const PL_reg_name[] = { EOP $ind = 0; -my $ofs = 1; +my $ofs = 0; my $sym = ""; -while (++$ind <= $tot) { +do { my $size = $longj[$ind] || 0; printf $out "\t%*s\t/* $sym%#04x */\n", -3-$width,qq("$name[$ind]",), $ind - $ofs; - if ($ind == $lastregop and $lastregop != $tot) { + if ($ind + 1 == $lastregop and $lastregop != $tot) { print $out "\t/* ------------ States ------------- */\n"; - $ofs = $lastregop; + $ofs = $lastregop - 1; $sym = 'REGNODE_MAX +'; } -} +} while (++$ind < $tot); print $out <<EOP; }; @@ -236,6 +284,18 @@ print $out <<EOP; }; #endif /* DOINIT */ +EOP + +print $out process_flags('V', 'varies', <<'EOC'); +/* The following have no fixed length. U8 so we can do strchr() on it. */ +EOC + +print $out process_flags('S', 'simple', <<'EOC'); +/* The following always have a length of 1. U8 we can do strchr() on it. */ +/* (Note that length 1 means "one character" under UTF8, not "one octet".) */ +EOC + +print $out <<EOP; /* ex: set ro: */ EOP safer_close($out); diff --git a/regcomp.sym b/regcomp.sym index b0b9faf..ac1c2e0 100644 --- a/regcomp.sym +++ b/regcomp.sym @@ -9,7 +9,7 @@ # Note that the order in this file is important. # # Format for first section: -# NAME \t TYPE, arg-description [num-args] [longjump-len] \t DESCRIPTION +# NAME \s+ TYPE, arg-description [flags] [num-args] [longjump-len] ; DESCRIPTION # # # run perl regen.pl after editing this file @@ -18,181 +18,180 @@ #* Exit points (0,1) -END END, no End of program. -SUCCEED END, no Return from a subroutine, basically. +END END, no ; End of program. +SUCCEED END, no ; Return from a subroutine, basically. #* Anchors: (2..13) -BOL BOL, no Match "" at beginning of line. -MBOL BOL, no Same, assuming multiline. -SBOL BOL, no Same, assuming singleline. -EOS EOL, no Match "" at end of string. -EOL EOL, no Match "" at end of line. -MEOL EOL, no Same, assuming multiline. -SEOL EOL, no Same, assuming singleline. -BOUND BOUND, no Match "" at any word boundary -BOUNDL BOUND, no Match "" at any word boundary -NBOUND NBOUND, no Match "" at any word non-boundary -NBOUNDL NBOUND, no Match "" at any word non-boundary -GPOS GPOS, no Matches where last m//g left off. +BOL BOL, no ; Match "" at beginning of line. +MBOL BOL, no ; Same, assuming multiline. +SBOL BOL, no ; Same, assuming singleline. +EOS EOL, no ; Match "" at end of string. +EOL EOL, no ; Match "" at end of line. +MEOL EOL, no ; Same, assuming multiline. +SEOL EOL, no ; Same, assuming singleline. +BOUND BOUND, no ; Match "" at any word boundary +BOUNDL BOUND, no ; Match "" at any word boundary +NBOUND NBOUND, no ; Match "" at any word non-boundary +NBOUNDL NBOUND, no ; Match "" at any word non-boundary +GPOS GPOS, no ; Matches where last m//g left off. #* [Special] alternatives: (14..30) -REG_ANY REG_ANY, no Match any one character (except newline). -SANY REG_ANY, no Match any one character. -CANY REG_ANY, no Match any one byte. -ANYOF ANYOF, sv Match character in (or not in) this class. -ALNUM ALNUM, no Match any alphanumeric character -ALNUML ALNUM, no Match any alphanumeric char in locale -NALNUM NALNUM, no Match any non-alphanumeric character -NALNUML NALNUM, no Match any non-alphanumeric char in locale -SPACE SPACE, no Match any whitespace character -SPACEL SPACE, no Match any whitespace char in locale -NSPACE NSPACE, no Match any non-whitespace character -NSPACEL NSPACE, no Match any non-whitespace char in locale -DIGIT DIGIT, no Match any numeric character -DIGITL DIGIT, no Match any numeric character in locale -NDIGIT NDIGIT, no Match any non-numeric character -NDIGITL NDIGIT, no Match any non-numeric character in locale -CLUMP CLUMP, no Match any combining character sequence +REG_ANY REG_ANY, no 0 S ; Match any one character (except newline). +SANY REG_ANY, no 0 S ; Match any one character. +CANY REG_ANY, no 0 S ; Match any one byte. +ANYOF ANYOF, sv 0 S ; Match character in (or not in) this class. +ALNUM ALNUM, no 0 S ; Match any alphanumeric character +ALNUML ALNUM, no 0 S ; Match any alphanumeric char in locale +NALNUM NALNUM, no 0 S ; Match any non-alphanumeric character +NALNUML NALNUM, no 0 S ; Match any non-alphanumeric char in locale +SPACE SPACE, no 0 S ; Match any whitespace character +SPACEL SPACE, no 0 S ; Match any whitespace char in locale +NSPACE NSPACE, no 0 S ; Match any non-whitespace character +NSPACEL NSPACE, no 0 S ; Match any non-whitespace char in locale +DIGIT DIGIT, no 0 S ; Match any numeric character +DIGITL DIGIT, no ; Match any numeric character in locale +NDIGIT NDIGIT, no 0 S ; Match any non-numeric character +NDIGITL NDIGIT, no ; Match any non-numeric character in locale +CLUMP CLUMP, no 0 V ; Match any combining character sequence #* Alternation (31) -# BRANCH The set of branches constituting a single choice are hooked -# together with their "next" pointers, since precedence prevents -# anything being concatenated to any individual branch. The -# "next" pointer of the last BRANCH in a choice points to the -# thing following the whole choice. This is also where the -# final "next" pointer of each individual branch points; each -# branch starts with the operand node of a BRANCH node. +# BRANCH The set of branches constituting a single choice are hooked +# together with their "next" pointers, since precedence prevents +# anything being concatenated to any individual branch. The +# "next" pointer of the last BRANCH in a choice points to the +# thing following the whole choice. This is also where the +# final "next" pointer of each individual branch points; each +# branch starts with the operand node of a BRANCH node. # -BRANCH BRANCH, node Match this alternative, or the next... +BRANCH BRANCH, node 0 V ; Match this alternative, or the next... #*Back pointer (32) -# BACK Normal "next" pointers all implicitly point forward; BACK -# exists to make loop structures possible. +# BACK Normal "next" pointers all implicitly point forward; BACK +# exists to make loop structures possible. # not used -BACK BACK, no Match "", "next" ptr points backward. +BACK BACK, no 0 V ; Match "", "next" ptr points backward. #*Literals (33..35) -EXACT EXACT, str Match this string (preceded by length). -EXACTF EXACT, str Match this string, folded (prec. by length). -EXACTFL EXACT, str Match this string, folded in locale (w/len). +EXACT EXACT, str ; Match this string (preceded by length). +EXACTF EXACT, str ; Match this string, folded (prec. by length). +EXACTFL EXACT, str ; Match this string, folded in locale (w/len). #*Do nothing types (36..37) -NOTHING NOTHING,no Match empty string. +NOTHING NOTHING, no ; Match empty string. # A variant of above which delimits a group, thus stops optimizations -TAIL NOTHING,no Match empty string. Can jump here from outside. +TAIL NOTHING, no ; Match empty string. Can jump here from outside. #*Loops (38..44) -# STAR,PLUS '?', and complex '*' and '+', are implemented as circular -# BRANCH structures using BACK. Simple cases (one character -# per match) are implemented with STAR and PLUS for speed -# and to minimize recursive plunges. +# STAR,PLUS '?', and complex '*' and '+', are implemented as circular +# BRANCH structures using BACK. Simple cases (one character +# per match) are implemented with STAR and PLUS for speed +# and to minimize recursive plunges. # -STAR STAR, node Match this (simple) thing 0 or more times. -PLUS PLUS, node Match this (simple) thing 1 or more times. +STAR STAR, node 0 V ; Match this (simple) thing 0 or more times. +PLUS PLUS, node 0 V ; Match this (simple) thing 1 or more times. -CURLY CURLY, sv 2 Match this simple thing {n,m} times. -CURLYN CURLY, no 2 Capture next-after-this simple thing -CURLYM CURLY, no 2 Capture this medium-complex thing {n,m} times. -CURLYX CURLY, sv 2 Match this complex thing {n,m} times. +CURLY CURLY, sv 2 V ; Match this simple thing {n,m} times. +CURLYN CURLY, no 2 V ; Capture next-after-this simple thing +CURLYM CURLY, no 2 V ; Capture this medium-complex thing {n,m} times. +CURLYX CURLY, sv 2 V ; Match this complex thing {n,m} times. # This terminator creates a loop structure for CURLYX -WHILEM WHILEM, no Do curly processing and see if rest matches. +WHILEM WHILEM, no 0 V ; Do curly processing and see if rest matches. #*Buffer related (45..49) -# OPEN,CLOSE,GROUPP ...are numbered at compile time. -OPEN OPEN, num 1 Mark this point in input as start of #n. -CLOSE CLOSE, num 1 Analogous to OPEN. +# OPEN,CLOSE,GROUPP ...are numbered at compile time. +OPEN OPEN, num 1 ; Mark this point in input as start of #n. +CLOSE CLOSE, num 1 ; Analogous to OPEN. -REF REF, num 1 Match some already matched string -REFF REF, num 1 Match already matched string, folded -REFFL REF, num 1 Match already matched string, folded in loc. +REF REF, num 1 V ; Match some already matched string +REFF REF, num 1 V ; Match already matched string, folded +REFFL REF, num 1 V ; Match already matched string, folded in loc. -#*Grouping assertions (50..54) -IFMATCH BRANCHJ,off 1 2 Succeeds if the following matches. -UNLESSM BRANCHJ,off 1 2 Fails if the following matches. -SUSPEND BRANCHJ,off 1 1 "Independent" sub-RE. -IFTHEN BRANCHJ,off 1 1 Switch, should be preceeded by switcher . -GROUPP GROUPP, num 1 Whether the group matched. +IFMATCH BRANCHJ, off 1 . 2 ; Succeeds if the following matches. +UNLESSM BRANCHJ, off 1 . 2 ; Fails if the following matches. +SUSPEND BRANCHJ, off 1 V 1 ; "Independent" sub-RE. +IFTHEN BRANCHJ, off 1 V 1 ; Switch, should be preceeded by switcher . +GROUPP GROUPP, num 1 ; Whether the group matched. #*Support for long RE (55..56) -LONGJMP LONGJMP,off 1 1 Jump far away. -BRANCHJ BRANCHJ,off 1 1 BRANCH with long offset. +LONGJMP LONGJMP, off 1 . 1 ; Jump far away. +BRANCHJ BRANCHJ, off 1 V 1 ; BRANCH with long offset. -#*The heavy worker (57..58) +#*The heavy worker (57) -EVAL EVAL, evl 1 Execute some Perl code. +EVAL EVAL, evl 1 ; Execute some Perl code. -#*Modifiers (59..60) +#*Modifiers (58..59) -MINMOD MINMOD, no Next operator is not greedy. -LOGICAL LOGICAL,no Next opcode should set the flag only. +MINMOD MINMOD, no ; Next operator is not greedy. +LOGICAL LOGICAL, no ; Next opcode should set the flag only. -# This is not used yet (61) -RENUM BRANCHJ,off 1 1 Group with independently numbered parens. +# This is not used yet (60) +RENUM BRANCHJ, off 1 . 1 ; Group with independently numbered parens. -#*Trie Related (62..64) +#*Trie Related (61..62) # Behave the same as A|LIST|OF|WORDS would. The '..C' variants have # inline charclass data (ascii only), the 'C' store it in the structure. # NOTE: the relative order of the TRIE-like regops is signifigant -TRIE TRIE, trie 1 Match many EXACT(FL?)? at once. flags==type -TRIEC TRIE,trie charclass Same as TRIE, but with embedded charclass data +TRIE TRIE, trie 1 ; Match many EXACT(FL?)? at once. flags==type +TRIEC TRIE,trie charclass ; Same as TRIE, but with embedded charclass data # For start classes, contains an added fail table. -AHOCORASICK TRIE, trie 1 Aho Corasick stclass. flags==type -AHOCORASICKC TRIE,trie charclass Same as AHOCORASICK, but with embedded charclass data +AHOCORASICK TRIE, trie 1 ; Aho Corasick stclass. flags==type +AHOCORASICKC TRIE,trie charclass ; Same as AHOCORASICK, but with embedded charclass data #*Regex Subroutines (65..66) -GOSUB GOSUB, num/ofs 2L recurse to paren arg1 at (signed) ofs arg2 -GOSTART GOSTART, no recurse to start of pattern +GOSUB GOSUB, num/ofs 2L ; recurse to paren arg1 at (signed) ofs arg2 +GOSTART GOSTART, no ; recurse to start of pattern #*Named references (67..69) -NREF REF, no-sv 1 Match some already matched string -NREFF REF, no-sv 1 Match already matched string, folded -NREFFL REF, no-sv 1 Match already matched string, folded in loc. +NREF REF, no-sv 1 V ; Match some already matched string +NREFF REF, no-sv 1 V ; Match already matched string, folded +NREFFL REF, no-sv 1 V ; Match already matched string, folded in loc. #*Special conditionals (70..72) -NGROUPP NGROUPP, no-sv 1 Whether the group matched. -INSUBP INSUBP, num 1 Whether we are in a specific recurse. -DEFINEP DEFINEP, none 1 Never execute directly. +NGROUPP NGROUPP, no-sv 1 ; Whether the group matched. +INSUBP INSUBP, num 1 ; Whether we are in a specific recurse. +DEFINEP DEFINEP, none 1 ; Never execute directly. #*Bactracking Verbs -ENDLIKE ENDLIKE, none Used only for the type field of verbs -OPFAIL ENDLIKE, none Same as (?!) -ACCEPT ENDLIKE, parno 1 Accepts the current matched string. +ENDLIKE ENDLIKE, none ; Used only for the type field of verbs +OPFAIL ENDLIKE, none ; Same as (?!) +ACCEPT ENDLIKE, parno 1 ; Accepts the current matched string. #*Verbs With Arguments -VERB VERB, no-sv 1 Used only for the type field of verbs -PRUNE VERB, no-sv 1 Pattern fails at this startpoint if no-backtracking through this -MARKPOINT VERB, no-sv 1 Push the current location for rollback by cut. -SKIP VERB, no-sv 1 On failure skip forward (to the mark) before retrying -COMMIT VERB, no-sv 1 Pattern fails outright if backtracking through this -CUTGROUP VERB, no-sv 1 On failure go to the next alternation in the group +VERB VERB, no-sv 1 ; Used only for the type field of verbs +PRUNE VERB, no-sv 1 ; Pattern fails at this startpoint if no-backtracking through this +MARKPOINT VERB, no-sv 1 ; Push the current location for rollback by cut. +SKIP VERB, no-sv 1 ; On failure skip forward (to the mark) before retrying +COMMIT VERB, no-sv 1 ; Pattern fails outright if backtracking through this +CUTGROUP VERB, no-sv 1 ; On failure go to the next alternation in the group #*Control what to keep in $&. -KEEPS KEEPS, no $& begins here. +KEEPS KEEPS, no ; $& begins here. #*New charclass like patterns -LNBREAK LNBREAK, none generic newline pattern -VERTWS VERTWS, none vertical whitespace (Perl 6) -NVERTWS NVERTWS, none not vertical whitespace (Perl 6) -HORIZWS HORIZWS, none horizontal whitespace (Perl 6) -NHORIZWS NHORIZWS, none not horizontal whitespace (Perl 6) +LNBREAK LNBREAK, none ; generic newline pattern +VERTWS VERTWS, none 0 S ; vertical whitespace (Perl 6) +NVERTWS NVERTWS, none 0 S ; not vertical whitespace (Perl 6) +HORIZWS HORIZWS, none 0 S ; horizontal whitespace (Perl 6) +NHORIZWS NHORIZWS, none 0 S ; not horizontal whitespace (Perl 6) -FOLDCHAR FOLDCHAR, codepoint 1 codepoint with tricky case folding properties. +FOLDCHAR FOLDCHAR, codepoint 1 ; codepoint with tricky case folding properties. # NEW STUFF ABOVE THIS LINE @@ -202,14 +201,14 @@ FOLDCHAR FOLDCHAR, codepoint 1 codepoint with tricky case folding properties. # This is not really a node, but an optimized away piece of a "long" node. # To simplify debugging output, we mark it as if it were a node -OPTIMIZED NOTHING,off Placeholder for dump. +OPTIMIZED NOTHING, off ; Placeholder for dump. # Special opcode with the property that no opcode in a compiled program # will ever be of this type. Thus it can be used as a flag value that # no other opcode has been seen. END is used similarly, in that an END # node cant be optimized. So END implies "unoptimizable" and PSEUDO mean # "not seen anything to optimize yet". -PSEUDO PSEUDO,off Pseudo opcode for internal use. +PSEUDO PSEUDO, off ; Pseudo opcode for internal use. ------------------------------------------------------------------------------- # Format for second section: @@ -221,16 +220,16 @@ PSEUDO PSEUDO,off Pseudo opcode for internal use. # Anything below is a state # # -TRIE next:FAIL -EVAL AB:FAIL -CURLYX end:FAIL -WHILEM A_pre,A_min,A_max,B_min,B_max:FAIL -BRANCH next:FAIL -CURLYM A,B:FAIL -IFMATCH A:FAIL -CURLY B_min_known,B_min,B_max:FAIL -COMMIT next:FAIL -MARKPOINT next:FAIL -SKIP next:FAIL -CUTGROUP next:FAIL -KEEPS next:FAIL +TRIE next:FAIL +EVAL AB:FAIL +CURLYX end:FAIL +WHILEM A_pre,A_min,A_max,B_min,B_max:FAIL +BRANCH next:FAIL +CURLYM A,B:FAIL +IFMATCH A:FAIL +CURLY B_min_known,B_min,B_max:FAIL +COMMIT next:FAIL +MARKPOINT next:FAIL +SKIP next:FAIL +CUTGROUP next:FAIL +KEEPS next:FAIL diff --git a/regnodes.h b/regnodes.h index 79de061..348410c 100644 --- a/regnodes.h +++ b/regnodes.h @@ -85,7 +85,7 @@ #define ENDLIKE 73 /* 0x49 Used only for the type field of verbs */ #define OPFAIL 74 /* 0x4a Same as (?!) */ #define ACCEPT 75 /* 0x4b Accepts the current matched string. */ -#define VERB 76 /* 0x4c no-sv 1 Used only for the type field of verbs */ +#define VERB 76 /* 0x4c Used only for the type field of verbs */ #define PRUNE 77 /* 0x4d Pattern fails at this startpoint if no-backtracking through this */ #define MARKPOINT 78 /* 0x4e Push the current location for rollback by cut. */ #define SKIP 79 /* 0x4f On failure skip forward (to the mark) before retrying */ @@ -363,7 +363,7 @@ static const U8 regarglen[] = { 0, /* ENDLIKE */ 0, /* OPFAIL */ EXTRA_SIZE(struct regnode_1), /* ACCEPT */ - 0, /* VERB */ + EXTRA_SIZE(struct regnode_1), /* VERB */ EXTRA_SIZE(struct regnode_1), /* PRUNE */ EXTRA_SIZE(struct regnode_1), /* MARKPOINT */ EXTRA_SIZE(struct regnode_1), /* SKIP */ @@ -661,4 +661,48 @@ EXTCONST char * const PL_reg_extflags_name[] = { }; #endif /* DOINIT */ +/* The following have no fixed length. U8 so we can do strchr() on it. */ +#define REGNODE_VARIES(node) (PL_varies_bitmask[(node) >> 3] & (1 << ((node) & 7))) + +#ifndef DOINIT +EXTCONST U8 PL_varies[] __attribute__deprecated__; +#else +EXTCONST U8 PL_varies[] __attribute__deprecated__ = { + CLUMP, BRANCH, BACK, STAR, PLUS, CURLY, CURLYN, CURLYM, CURLYX, WHILEM, + REF, REFF, REFFL, SUSPEND, IFTHEN, BRANCHJ, NREF, NREFF, NREFFL, + 0 +}; +#endif /* DOINIT */ + +#ifndef DOINIT +EXTCONST U8 PL_varies_bitmask[]; +#else +EXTCONST U8 PL_varies_bitmask[] = { + 0x00, 0x00, 0x00, 0xC0, 0xC1, 0x9F, 0x33, 0x01, 0x38, 0x00, 0x00, 0x00 +}; +#endif /* DOINIT */ + +/* The following always have a length of 1. U8 we can do strchr() on it. */ +/* (Note that length 1 means "one character" under UTF8, not "one octet".) */ +#define REGNODE_SIMPLE(node) (PL_simple_bitmask[(node) >> 3] & (1 << ((node) & 7))) + +#ifndef DOINIT +EXTCONST U8 PL_simple[] __attribute__deprecated__; +#else +EXTCONST U8 PL_simple[] __attribute__deprecated__ = { + REG_ANY, SANY, CANY, ANYOF, ALNUM, ALNUML, NALNUM, NALNUML, SPACE, + SPACEL, NSPACE, NSPACEL, DIGIT, NDIGIT, VERTWS, NVERTWS, HORIZWS, + NHORIZWS, + 0 +}; +#endif /* DOINIT */ + +#ifndef DOINIT +EXTCONST U8 PL_simple_bitmask[]; +#else +EXTCONST U8 PL_simple_bitmask[] = { + 0x00, 0xC0, 0xFF, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00 +}; +#endif /* DOINIT */ + /* ex: set ro: */ -- Perl5 Master Repository
