aboutsummaryrefslogtreecommitdiff
path: root/lpcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lpcode.c')
-rw-r--r--lpcode.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/lpcode.c b/lpcode.c
index 2987cfc..b2dbba2 100644
--- a/lpcode.c
+++ b/lpcode.c
@@ -196,7 +196,7 @@ int checkaux (TTree *tree, int pred) {
196 if (checkaux(sib2(tree), pred)) return 1; 196 if (checkaux(sib2(tree), pred)) return 1;
197 /* else return checkaux(sib1(tree), pred); */ 197 /* else return checkaux(sib1(tree), pred); */
198 tree = sib1(tree); goto tailcall; 198 tree = sib1(tree); goto tailcall;
199 case TLabChoice: case TRecov: /* labeled failure */ 199 case TRecov: /* labeled failure */
200 /* we do not know whether sib2 will be evaluated */ 200 /* we do not know whether sib2 will be evaluated */
201 tree = sib1(tree); goto tailcall; 201 tree = sib1(tree); goto tailcall;
202 case TCapture: case TGrammar: case TRule: 202 case TCapture: case TGrammar: case TRule:
@@ -218,10 +218,10 @@ int fixedlenx (TTree *tree, int count, int len) {
218 switch (tree->tag) { 218 switch (tree->tag) {
219 case TChar: case TSet: case TAny: 219 case TChar: case TSet: case TAny:
220 return len + 1; 220 return len + 1;
221 case TFalse: case TTrue: case TNot: case TAnd: case TBehind: 221 case TFalse: case TTrue: case TNot: case TAnd: case TBehind:
222 case TThrow: /* labeled failure */
223 return len; 222 return len;
224 case TRep: case TRunTime: case TOpenCall: 223 case TRep: case TRunTime: case TOpenCall:
224 case TThrow: /* labeled failure */
225 return -1; 225 return -1;
226 case TCapture: case TRule: case TGrammar: 226 case TCapture: case TRule: case TGrammar:
227 /* return fixedlenx(sib1(tree), count); */ 227 /* return fixedlenx(sib1(tree), count); */
@@ -237,7 +237,7 @@ int fixedlenx (TTree *tree, int count, int len) {
237 /* else return fixedlenx(sib2(tree), count, len); */ 237 /* else return fixedlenx(sib2(tree), count, len); */
238 tree = sib2(tree); goto tailcall; 238 tree = sib2(tree); goto tailcall;
239 } 239 }
240 case TChoice: case TLabChoice: { /* labeled failure */ 240 case TChoice: {
241 int n1, n2; 241 int n1, n2;
242 n1 = fixedlenx(sib1(tree), count, len); 242 n1 = fixedlenx(sib1(tree), count, len);
243 if (n1 < 0) return -1; 243 if (n1 < 0) return -1;
@@ -287,7 +287,7 @@ static int getfirst (TTree *tree, const Charset *follow, Charset *firstset) {
287 loopset(i, firstset->cs[i] = follow->cs[i]); /* follow = fullset(?) */ 287 loopset(i, firstset->cs[i] = follow->cs[i]); /* follow = fullset(?) */
288 return 1; 288 return 1;
289 } 289 }
290 case TChoice: case TLabChoice: { /*(?) labeled failure */ 290 case TChoice: {
291 Charset csaux; 291 Charset csaux;
292 int e1 = getfirst(sib1(tree), follow, firstset); 292 int e1 = getfirst(sib1(tree), follow, firstset);
293 int e2 = getfirst(sib2(tree), follow, &csaux); 293 int e2 = getfirst(sib2(tree), follow, &csaux);
@@ -378,7 +378,7 @@ static int headfail (TTree *tree) {
378 if (!nofail(sib2(tree))) return 0; 378 if (!nofail(sib2(tree))) return 0;
379 /* else return headfail(sib1(tree)); */ 379 /* else return headfail(sib1(tree)); */
380 tree = sib1(tree); goto tailcall; 380 tree = sib1(tree); goto tailcall;
381 case TChoice: case TLabChoice: case TRecov: /* labeled failure */ 381 case TChoice: case TRecov: /* labeled failure */
382 if (!headfail(sib1(tree))) return 0; 382 if (!headfail(sib1(tree))) return 0;
383 /* else return headfail(sib2(tree)); */ 383 /* else return headfail(sib2(tree)); */
384 tree = sib2(tree); goto tailcall; 384 tree = sib2(tree); goto tailcall;
@@ -398,7 +398,7 @@ static int needfollow (TTree *tree) {
398 case TChar: case TSet: case TAny: 398 case TChar: case TSet: case TAny:
399 case TFalse: case TTrue: case TAnd: case TNot: 399 case TFalse: case TTrue: case TAnd: case TNot:
400 case TRunTime: case TGrammar: case TCall: case TBehind: 400 case TRunTime: case TGrammar: case TCall: case TBehind:
401 case TThrow: case TLabChoice: case TRecov: /* (?)labeled failure */ 401 case TThrow: case TRecov: /* (?)labeled failure */
402 return 0; 402 return 0;
403 case TChoice: case TRep: 403 case TChoice: case TRep:
404 return 1; 404 return 1;
@@ -433,7 +433,7 @@ int sizei (const Instruction *i) {
433 return 2; 433 return 2;
434 case IThrow: /* labeled failure */ 434 case IThrow: /* labeled failure */
435 return 1; 435 return 1;
436 case ILabChoice: case IRecov: 436 case IRecov:
437 return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */ 437 return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */
438 default: return 1; 438 default: return 1;
439 } 439 }
@@ -499,7 +499,7 @@ static int addoffsetinst (CompileState *compst, Opcode op) {
499 int i = addinstruction(compst, op, 0); /* instruction */ 499 int i = addinstruction(compst, op, 0); /* instruction */
500 addinstruction(compst, (Opcode)0, 0); /* open space for offset */ 500 addinstruction(compst, (Opcode)0, 0); /* open space for offset */
501 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || 501 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 ||
502 op == IRecov || op == ILabChoice); /* labeled failure */ 502 op == IRecov); /* labeled failure */
503 return i; 503 return i;
504} 504}
505 505
@@ -707,21 +707,6 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
707 707
708 708
709/* labeled failure begin */ 709/* labeled failure begin */
710static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
711 const Charset *fl, const byte *cs) {
712 int emptyp2 = (p2->tag == TTrue);
713 int pcommit;
714 int test = NOINST;
715 int pchoice = addoffsetinst(compst, ILabChoice);
716 addcharset(compst, cs);
717 codegen(compst, p1, emptyp2, test, fullset);
718 pcommit = addoffsetinst(compst, ICommit);
719 jumptohere(compst, pchoice);
720 jumptohere(compst, test);
721 codegen(compst, p2, opt, NOINST, fl);
722 jumptohere(compst, pcommit);
723}
724
725static void coderecovery (CompileState *compst, TTree *p1, TTree *p2, int opt, 710static void coderecovery (CompileState *compst, TTree *p1, TTree *p2, int opt,
726 const Charset *fl, const byte *cs) { 711 const Charset *fl, const byte *cs) {
727 int emptyp2 = (p2->tag == TTrue); 712 int emptyp2 = (p2->tag == TTrue);
@@ -734,6 +719,7 @@ static void coderecovery (CompileState *compst, TTree *p1, TTree *p2, int opt,
734 jumptohere(compst, precovery); 719 jumptohere(compst, precovery);
735 jumptohere(compst, test); 720 jumptohere(compst, test);
736 codegen(compst, p2, opt, NOINST, fl); 721 codegen(compst, p2, opt, NOINST, fl);
722 addinstruction(compst, IRet, 0);
737 jumptohere(compst, pcommit); 723 jumptohere(compst, pcommit);
738} 724}
739/* labeled failure end */ 725/* labeled failure end */
@@ -969,10 +955,6 @@ static void codegen (CompileState *compst, TTree *tree, int opt, int tt,
969 addinstruction(compst, IThrow, (byte) tree->u.label); 955 addinstruction(compst, IThrow, (byte) tree->u.label);
970 break; 956 break;
971 } 957 }
972 case TLabChoice: { /* labeled failure */
973 codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree));
974 break;
975 }
976 case TRecov: { /* labeled failure */ 958 case TRecov: { /* labeled failure */
977 coderecovery(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); 959 coderecovery(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree));
978 break; 960 break;
@@ -999,7 +981,7 @@ static void peephole (CompileState *compst) {
999 switch (code[i].i.code) { 981 switch (code[i].i.code) {
1000 case IChoice: case ICall: case ICommit: case IPartialCommit: 982 case IChoice: case ICall: case ICommit: case IPartialCommit:
1001 case IBackCommit: case ITestChar: case ITestSet: 983 case IBackCommit: case ITestChar: case ITestSet:
1002 case ILabChoice: case IRecov: /* labeled failure */ 984 case IRecov: /* labeled failure */
1003 case ITestAny: { /* instructions with labels */ 985 case ITestAny: { /* instructions with labels */
1004 jumptothere(compst, i, finallabel(code, i)); /* optimize label */ 986 jumptothere(compst, i, finallabel(code, i)); /* optimize label */
1005 break; 987 break;