get rid of rthreadlist
This commit is contained in:
37
pike.c
37
pike.c
@@ -111,13 +111,6 @@ struct rthread
|
|||||||
rsub *sub;
|
rsub *sub;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct rthreadlist rthreadlist;
|
|
||||||
struct rthreadlist
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
rthread t[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define INSERT_CODE(at, num, pc) \
|
#define INSERT_CODE(at, num, pc) \
|
||||||
if (code) \
|
if (code) \
|
||||||
memmove(code + at + num, code + at, (pc - at)*sizeof(int)); \
|
memmove(code + at + num, code + at, (pc - at)*sizeof(int)); \
|
||||||
@@ -469,7 +462,7 @@ if (--csub->ref == 0) { \
|
|||||||
freesub = csub; \
|
freesub = csub; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define addthread(nn, list, _pc, _sub, cont) \
|
#define addthread(nn, list, listidx, _pc, _sub, cont) \
|
||||||
{ \
|
{ \
|
||||||
int i = 0, *pc = _pc; \
|
int i = 0, *pc = _pc; \
|
||||||
const char *_sp = sp+l; \
|
const char *_sp = sp+l; \
|
||||||
@@ -487,8 +480,8 @@ if (--csub->ref == 0) { \
|
|||||||
} \
|
} \
|
||||||
plist[pc - prog->insts] = gen; \
|
plist[pc - prog->insts] = gen; \
|
||||||
if (*pc < ASSERT) { \
|
if (*pc < ASSERT) { \
|
||||||
list->t[list->n].sub = sub; \
|
list[listidx].sub = sub; \
|
||||||
list->t[list->n++].pc = pc; \
|
list[listidx++].pc = pc; \
|
||||||
goto rec_check##nn; \
|
goto rec_check##nn; \
|
||||||
} \
|
} \
|
||||||
switch(*pc) { \
|
switch(*pc) { \
|
||||||
@@ -527,12 +520,14 @@ if (--csub->ref == 0) { \
|
|||||||
tmp = clist; \
|
tmp = clist; \
|
||||||
clist = nlist; \
|
clist = nlist; \
|
||||||
nlist = tmp; \
|
nlist = tmp; \
|
||||||
nlist->n = 0; \
|
clistidx = nlistidx; \
|
||||||
|
nlistidx = 0; \
|
||||||
|
|
||||||
int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
||||||
{
|
{
|
||||||
int i, j, c, l = 0, *npc, gen = 1, subidx = 1;
|
int i, j, c, l = 0, *npc, gen = 1, subidx = 1;
|
||||||
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
||||||
|
int clistidx = 0, nlistidx = 0;
|
||||||
const char *sp = s;
|
const char *sp = s;
|
||||||
int plist[prog->unilen];
|
int plist[prog->unilen];
|
||||||
int *pcs[prog->splits];
|
int *pcs[prog->splits];
|
||||||
@@ -540,12 +535,10 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
char nsubs[rsubsize*256];
|
char nsubs[rsubsize*256];
|
||||||
rsub *nsub = (rsub*)nsubs, *lsub = nsub, *matched = NULL, *s1;
|
rsub *nsub = (rsub*)nsubs, *lsub = nsub, *matched = NULL, *s1;
|
||||||
rsub *freesub = NULL;
|
rsub *freesub = NULL;
|
||||||
rthreadlist _clist[1+prog->len];
|
rthread _clist[prog->len];
|
||||||
rthreadlist _nlist[1+prog->len];
|
rthread _nlist[prog->len];
|
||||||
rthreadlist *clist = _clist, *nlist = _nlist, *tmp;
|
rthread *clist = _clist, *nlist = _nlist, *tmp;
|
||||||
memset(plist, 0, prog->unilen*sizeof(plist[0]));
|
memset(plist, 0, prog->unilen*sizeof(plist[0]));
|
||||||
memset(clist, 0, (1+prog->len)*sizeof(rthread));
|
|
||||||
memset(nlist, 0, (1+prog->len)*sizeof(rthread));
|
|
||||||
|
|
||||||
for(i=0; i<nsubp; i++) {
|
for(i=0; i<nsubp; i++) {
|
||||||
subp[i] = NULL;
|
subp[i] = NULL;
|
||||||
@@ -557,18 +550,18 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
newsub(nsub);
|
newsub(nsub);
|
||||||
nsub->sub[0] = sp;
|
nsub->sub[0] = sp;
|
||||||
goto jmp_start;
|
goto jmp_start;
|
||||||
for(; clist->n; sp += l) {
|
for(; clistidx; sp += l) {
|
||||||
gen++; uc_len(l, sp) uc_code(c, sp)
|
gen++; uc_len(l, sp) uc_code(c, sp)
|
||||||
for(i=0; i<clist->n; i++) {
|
for(i = 0; i < clistidx; i++) {
|
||||||
npc = clist->t[i].pc;
|
npc = clist[i].pc;
|
||||||
nsub = clist->t[i].sub;
|
nsub = clist[i].sub;
|
||||||
switch(*npc++) {
|
switch(*npc++) {
|
||||||
case CHAR:
|
case CHAR:
|
||||||
if(c != *npc++)
|
if(c != *npc++)
|
||||||
break;
|
break;
|
||||||
case ANY:
|
case ANY:
|
||||||
addthread:
|
addthread:
|
||||||
addthread(2, nlist, npc, nsub, continue)
|
addthread(2, nlist, nlistidx, npc, nsub, continue)
|
||||||
case CLASS:
|
case CLASS:
|
||||||
if (!re_classmatch(npc, c))
|
if (!re_classmatch(npc, c))
|
||||||
break;
|
break;
|
||||||
@@ -592,7 +585,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
swaplist()
|
swaplist()
|
||||||
jmp_start:
|
jmp_start:
|
||||||
while (1)
|
while (1)
|
||||||
addthread(1, clist, prog->insts, nsub, break)
|
addthread(1, clist, clistidx, prog->insts, nsub, break)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
swaplist()
|
swaplist()
|
||||||
|
|||||||
3
test.sh
3
test.sh
@@ -58,6 +58,7 @@ abc$|c
|
|||||||
^(abc|kj)
|
^(abc|kj)
|
||||||
([^qwe]*rty)|(asd[^fgh]*)
|
([^qwe]*rty)|(asd[^fgh]*)
|
||||||
([^qwe]*rty+)|(asd[^fgh]*)
|
([^qwe]*rty+)|(asd[^fgh]*)
|
||||||
|
((abc))(fv)
|
||||||
"
|
"
|
||||||
input="\
|
input="\
|
||||||
abcdef
|
abcdef
|
||||||
@@ -117,6 +118,7 @@ kj
|
|||||||
jhdfh kj hhd
|
jhdfh kj hhd
|
||||||
qweasd qqqq fff
|
qweasd qqqq fff
|
||||||
qwehh sjsjsj rtyyyyyyyyyj sdj
|
qwehh sjsjsj rtyyyyyyyyyj sdj
|
||||||
|
abcfv
|
||||||
"
|
"
|
||||||
expect="\
|
expect="\
|
||||||
(0,3)
|
(0,3)
|
||||||
@@ -176,6 +178,7 @@ expect="\
|
|||||||
-nomatch-
|
-nomatch-
|
||||||
(3,16)(?,?)(3,16)
|
(3,16)(?,?)(3,16)
|
||||||
(3,25)(3,25)(?,?)
|
(3,25)(3,25)(?,?)
|
||||||
|
(0,5)(0,3)(0,3)(3,5)
|
||||||
(0,0)
|
(0,0)
|
||||||
"
|
"
|
||||||
c=1
|
c=1
|
||||||
|
|||||||
Reference in New Issue
Block a user