minor cleanups
This commit is contained in:
28
pike.c
28
pike.c
@@ -102,7 +102,7 @@ struct rsub
|
|||||||
typedef struct rthread rthread;
|
typedef struct rthread rthread;
|
||||||
struct rthread
|
struct rthread
|
||||||
{
|
{
|
||||||
int *pc;
|
const int *pc;
|
||||||
rsub *sub;
|
rsub *sub;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -467,13 +467,14 @@ if (--csub->ref == 0) { \
|
|||||||
freesub = csub; \
|
freesub = csub; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define addthread(nn, list, listidx, _pc, _sub, cont) \
|
#define addthread(nn, list, listidx, _pc, _sub) \
|
||||||
{ \
|
{ \
|
||||||
int i = 0, *pc = _pc; \
|
int i = 0; \
|
||||||
|
const int *pc = _pc; \
|
||||||
const char *_sp = sp+l; \
|
const char *_sp = sp+l; \
|
||||||
rsub *sub = _sub; \
|
rsub *sub = _sub; \
|
||||||
rec##nn: \
|
rec##nn: \
|
||||||
if(plist[pc - prog->insts] == gen) { \
|
if(plist[pc - insts] == gen) { \
|
||||||
dec_check##nn: \
|
dec_check##nn: \
|
||||||
decref(sub) \
|
decref(sub) \
|
||||||
rec_check##nn: \
|
rec_check##nn: \
|
||||||
@@ -482,9 +483,9 @@ if (--csub->ref == 0) { \
|
|||||||
sub = subs[i]; \
|
sub = subs[i]; \
|
||||||
goto rec##nn; \
|
goto rec##nn; \
|
||||||
} \
|
} \
|
||||||
cont; \
|
continue; \
|
||||||
} \
|
} \
|
||||||
plist[pc - prog->insts] = gen; \
|
plist[pc - insts] = gen; \
|
||||||
if (*pc < ASSERT) { \
|
if (*pc < ASSERT) { \
|
||||||
list[listidx].sub = sub; \
|
list[listidx].sub = sub; \
|
||||||
list[listidx++].pc = pc; \
|
list[listidx++].pc = pc; \
|
||||||
@@ -532,12 +533,13 @@ if (--csub->ref == 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, gen = 1, subidx = 1;
|
||||||
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
|
||||||
int clistidx = 0, nlistidx = 0;
|
int clistidx = 0, nlistidx = 0;
|
||||||
const char *sp = s;
|
const char *sp = s;
|
||||||
|
const int *insts = prog->insts;
|
||||||
int plist[prog->unilen];
|
int plist[prog->unilen];
|
||||||
int *pcs[prog->splits];
|
const int *pcs[prog->splits], *npc;
|
||||||
rsub *subs[prog->splits];
|
rsub *subs[prog->splits];
|
||||||
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;
|
||||||
@@ -554,8 +556,6 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
|
|
||||||
gen = 1;
|
gen = 1;
|
||||||
nsub->ref = 2;
|
nsub->ref = 2;
|
||||||
newsub(nsub);
|
|
||||||
nsub->sub[0] = sp;
|
|
||||||
goto jmp_start;
|
goto jmp_start;
|
||||||
for(;; sp += l) {
|
for(;; sp += l) {
|
||||||
gen++; uc_len(l, sp) uc_code(c, sp)
|
gen++; uc_len(l, sp) uc_code(c, sp)
|
||||||
@@ -568,7 +568,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
break;
|
break;
|
||||||
case ANY:
|
case ANY:
|
||||||
addthread:
|
addthread:
|
||||||
addthread(2, nlist, nlistidx, npc, nsub, continue)
|
addthread(2, nlist, nlistidx, npc, nsub)
|
||||||
case CLASS:
|
case CLASS:
|
||||||
if (!re_classmatch(npc, c))
|
if (!re_classmatch(npc, c))
|
||||||
break;
|
break;
|
||||||
@@ -592,12 +592,10 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
if (!matched) {
|
if (!matched) {
|
||||||
nsub = lsub;
|
nsub = lsub;
|
||||||
nsub->ref++;
|
nsub->ref++;
|
||||||
|
jmp_start:
|
||||||
newsub(nsub)
|
newsub(nsub)
|
||||||
nsub->sub[0] = sp + l;
|
nsub->sub[0] = sp + l;
|
||||||
jmp_start:
|
addthread(1, clist, clistidx, insts, nsub)
|
||||||
while (1)
|
|
||||||
addthread(1, clist, clistidx, prog->insts, nsub, break)
|
|
||||||
continue;
|
|
||||||
} else if (!clistidx)
|
} else if (!clistidx)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
2
test.sh
2
test.sh
@@ -275,7 +275,6 @@ expect="\
|
|||||||
(0,0)
|
(0,0)
|
||||||
"
|
"
|
||||||
|
|
||||||
gcc pike.c -pedantic -Wall -Wfatal-errors -std=c99
|
|
||||||
c=1
|
c=1
|
||||||
echo "$regex" | tr '\n' | while read re; do
|
echo "$regex" | tr '\n' | while read re; do
|
||||||
inp=$(echo "$input" | awk -v c=$c 'BEGIN{ RS = "" ; FS = "\n" }{print $c}')
|
inp=$(echo "$input" | awk -v c=$c 'BEGIN{ RS = "" ; FS = "\n" }{print $c}')
|
||||||
@@ -294,3 +293,4 @@ echo "$regex" | tr '\n' | while read re; do
|
|||||||
c=$((c+1))
|
c=$((c+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
gcc pike.c -pedantic -Wall -Wfatal-errors -std=c99
|
||||||
|
|||||||
Reference in New Issue
Block a user