From e578d80f05dc39e593cd3f820b71a897ea5ee748 Mon Sep 17 00:00:00 2001 From: PedroEdiaz Date: Mon, 9 Feb 2026 06:26:57 -0600 Subject: [PATCH] Make the ' Operator --- pikevm.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pikevm.h b/pikevm.h index 25118c9..c21d9b9 100644 --- a/pikevm.h +++ b/pikevm.h @@ -85,6 +85,7 @@ enum /* Other (special) instructions */ SAVE, /* Instructions which take relative offset as arg */ + NORAC, JMP, SPLIT, RSPLIT, @@ -131,6 +132,10 @@ void re_dumpcode(rcode *prog) printf("jmp %d (%d)\n", pc + code[pc] + 1, code[pc]); pc++; break; + case NORAC: + printf("norac %d (%d)\n", pc + code[pc] + 1, code[pc]); + pc++; + break; case CHAR: printf("char %c\n", code[pc]); pc++; @@ -315,6 +320,14 @@ static int compilecode(const char *re_loc, rcode *prog, int sizecode) if (nojmp == 2) goto zcase; break; + case '\'': + INSERT_CODE(term, 3, PC); + EMIT(PC++, MATCH); + EMIT(term, NORAC); + EMIT(term + 1, REL(term, PC)); + EMIT(term + 2, BOL); + EMIT(PC++, ANY); + break; case '?': if (PC == term) return -1; @@ -419,6 +432,7 @@ static int reg_comp(rcode *prog, const char *re, int nsubs) case RSPLIT: prog->insts[i] = -scnt; scnt += 2; + case NORAC: case JMP: case SAVE: case CHAR: @@ -526,6 +540,11 @@ if (spc > JMP) { \ npc += 2; \ pcs[si] = npc + npc[-1]; \ fastrec(nn, list, listidx) \ +} else if (spc == NORAC) { \ + if (re_pikevm(prog, _sp, NULL, 0, 2 + npc)) \ + deccheck(nn) \ + npc += 2 + npc[1]; \ + goto rec##nn; \ } else if (spc == SAVE) { \ save##list() \ nsub->sub[npc[1]] = _sp; \ @@ -570,12 +589,10 @@ clistidx = nlistidx; \ #define deccont() { decref(nsub) continue; } -static int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) +static int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp, int * start) { - if (!*s) - return 0; const char *sp = s, *_sp = s; - int *pcs[prog->splits], *npc, *pc, *insts = prog->insts; + int *pcs[prog->splits], *npc, *pc, *insts = start?start:prog->insts; rsub *subs[prog->splits]; rsub *nsub, *sub, *matched = NULL, *freesub = NULL; rthread _clist[prog->len], _nlist[prog->len];