From 4dc1b1b535f39d155dc8f03a25711d68a9c2a2e0 Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Fri, 30 Jul 2021 16:47:53 +0000 Subject: [PATCH] misc --- pike.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/pike.c b/pike.c index e3f3279..bfee1fa 100644 --- a/pike.c +++ b/pike.c @@ -60,23 +60,6 @@ static char *uc_beg(char *beg, char *s) return s; } -typedef struct rinst rinst; -struct rinst -{ - int opcode; - int c; - int n; - rinst *x; - rinst *y; -}; - -typedef struct rprog rprog; -struct rprog -{ - rinst *start; - int len; -}; - typedef struct rcode rcode; struct rcode { @@ -87,12 +70,13 @@ struct rcode int insts[]; }; -enum /* rinst.opcode */ +enum { // Instructions which consume input bytes (and thus fail if none left) CHAR = 1, ANY, CLASS, + MATCH, // Assert position ASSERT, BOL, @@ -103,7 +87,6 @@ enum /* rinst.opcode */ RSPLIT, // Other (special) instructions SAVE, - MATCH, }; // Return codes for re_sizecode() and re_comp() @@ -114,7 +97,6 @@ enum { RE_UNSUPPORTED_SYNTAX = -4, }; -#define inst_is_consumer(inst) ((inst) < ASSERT) typedef struct rsub rsub; struct rsub { @@ -462,7 +444,9 @@ int re_comp(rcode *prog, const char *re) prog->insts[prog->unilen++] = SAVE; prog->insts[prog->unilen++] = 1; prog->insts[prog->unilen++] = MATCH; - prog->len += 2; + prog->insts[prog->unilen++] = CHAR; + prog->insts[prog->unilen++] = 0; + prog->len += 3; return RE_SUCCESS; } @@ -501,11 +485,12 @@ if (csub->ref > 1) { \ cont; \ } \ plist[pc - prog->insts] = gen; \ - switch(*pc) { \ - default: \ + if (*pc < ASSERT) { \ list->t[list->n].sub = sub; \ list->t[list->n++].pc = pc; \ goto rec_check##nn; \ + } \ + switch(*pc) { \ case JMP: \ pc += 2 + pc[1]; \ goto rec##nn; \ @@ -574,19 +559,14 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) for(i=0; in; i++) { npc = clist->t[i].pc; nsub = clist->t[i].sub; - // If we need to match a character, but there's none left, - // it's fail (we don't schedule current thread for continuation) - if (inst_is_consumer(*npc) && !*sp) { - if (i >= clist->n-1) - goto break_for; - continue; - } switch(*npc++) { case CHAR: if(c != *npc++) break; case ANY: addthread: + if (!c) + continue; addthread(2, nlist, npc, nsub, continue) case CLASS: if (!re_classmatch(npc, c)) @@ -600,7 +580,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) } nsub->ref--; } - if (!matched) { + if (!matched && c) { nsub = lsub; nsub->ref++; save(3, nsub)