]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libregexp/regcomp.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libregexp / regcomp.c
index c937ee5c9a007d399127ad312f5eec22a9bd8840..3e3ba6ae529841dcbe4f411074f2d4376ed4c12d 100644 (file)
@@ -78,14 +78,17 @@ e2(Parselex *plex)
        Renode *n;
 
        n = e3(plex);
-       if(lex(plex) == LREP) {
+       while(lex(plex) == LREP) {
                switch(plex->rune) {
                case L'*':
-                       return node(plex, TSTAR, n, nil);
+                       n = node(plex, TSTAR, n, nil);
+                       break;
                case L'+':
-                       return node(plex, TPLUS, n, nil);
+                       n = node(plex, TPLUS, n, nil);
+                       break;
                case L'?':
-                       return node(plex, TQUES, n, nil);
+                       n = node(plex, TQUES, n, nil);
+                       break;
                }
        }
        plex->peek = 1;
@@ -153,17 +156,6 @@ initplex(Parselex *plex, char *regstr, int lit)
        return plex;
 }
 
-static int
-maxthreads(Renode *tree)
-{
-       tree = tree->left;
-       if(tree->op == TCAT)
-               tree = tree->left;
-       if(tree->op == TBOL)
-               return 2;
-       return -1;
-}
-
 static Reprog*
 regcomp1(char *regstr, int nl, int lit)
 {
@@ -184,7 +176,7 @@ regcomp1(char *regstr, int nl, int lit)
                return nil;
        }
 
-       maxthr = regstrlen;
+       maxthr = regstrlen + 1;
        parsetr = node(&plex, TSUB, e0(&plex), nil);
 
 //     prtree(parsetr, 0, 1);
@@ -301,12 +293,13 @@ Tailcall:
 static Reinst*
 compile(Renode *parsetr, Reprog *reprog, int nl)
 {
-       Reinst *reinst;
+       Reinst *reinst, *end;
        int sub;
 
        sub = 0;
        reinst = (Reinst*)(reprog+1);
-       compile1(parsetr, reinst, &sub, nl);
+       end = compile1(parsetr, reinst, &sub, nl);
+       assert(reinst + reprog->len == end);
        return reinst;
 }