diff options
Diffstat (limited to 'lpcode.c')
-rw-r--r-- | lpcode.c | 39 |
1 files changed, 5 insertions, 34 deletions
@@ -220,9 +220,6 @@ int checkaux (TTree *tree, int pred) { | |||
220 | if (checkaux(sib2(tree), pred)) return 1; | 220 | if (checkaux(sib2(tree), pred)) return 1; |
221 | /* else return checkaux(sib1(tree), pred); */ | 221 | /* else return checkaux(sib1(tree), pred); */ |
222 | tree = sib1(tree); goto tailcall; | 222 | tree = sib1(tree); goto tailcall; |
223 | case TLabChoice: /* labeled failure */ | ||
224 | /* we do not know whether sib2 will be evaluated */ | ||
225 | tree = sib1(tree); goto tailcall; | ||
226 | case TCapture: case TGrammar: case TRule: | 223 | case TCapture: case TGrammar: case TRule: |
227 | /* return checkaux(sib1(tree), pred); */ | 224 | /* return checkaux(sib1(tree), pred); */ |
228 | tree = sib1(tree); goto tailcall; | 225 | tree = sib1(tree); goto tailcall; |
@@ -264,7 +261,7 @@ int fixedlen (TTree *tree) { | |||
264 | /* else return fixedlen(sib2(tree)) + len; */ | 261 | /* else return fixedlen(sib2(tree)) + len; */ |
265 | len += n1; tree = sib2(tree); goto tailcall; | 262 | len += n1; tree = sib2(tree); goto tailcall; |
266 | } | 263 | } |
267 | case TChoice: case TLabChoice: { /* labeled failure */ | 264 | case TChoice: { |
268 | int n1 = fixedlen(sib1(tree)); | 265 | int n1 = fixedlen(sib1(tree)); |
269 | int n2 = fixedlen(sib2(tree)); | 266 | int n2 = fixedlen(sib2(tree)); |
270 | if (n1 != n2 || n1 < 0) | 267 | if (n1 != n2 || n1 < 0) |
@@ -314,7 +311,7 @@ static int getfirst (TTree *tree, const Charset *follow, Charset *firstset) { | |||
314 | loopset(i, firstset->cs[i] = follow->cs[i]); /* follow = fullset(?) */ | 311 | loopset(i, firstset->cs[i] = follow->cs[i]); /* follow = fullset(?) */ |
315 | return 1; | 312 | return 1; |
316 | } | 313 | } |
317 | case TChoice: case TLabChoice: { /*(?) labeled failure */ | 314 | case TChoice: { |
318 | Charset csaux; | 315 | Charset csaux; |
319 | int e1 = getfirst(sib1(tree), follow, firstset); | 316 | int e1 = getfirst(sib1(tree), follow, firstset); |
320 | int e2 = getfirst(sib2(tree), follow, &csaux); | 317 | int e2 = getfirst(sib2(tree), follow, &csaux); |
@@ -399,7 +396,7 @@ static int headfail (TTree *tree) { | |||
399 | if (!nofail(sib2(tree))) return 0; | 396 | if (!nofail(sib2(tree))) return 0; |
400 | /* else return headfail(sib1(tree)); */ | 397 | /* else return headfail(sib1(tree)); */ |
401 | tree = sib1(tree); goto tailcall; | 398 | tree = sib1(tree); goto tailcall; |
402 | case TChoice: case TLabChoice: /* labeled failure */ | 399 | case TChoice: |
403 | if (!headfail(sib1(tree))) return 0; | 400 | if (!headfail(sib1(tree))) return 0; |
404 | /* else return headfail(sib2(tree)); */ | 401 | /* else return headfail(sib2(tree)); */ |
405 | tree = sib2(tree); goto tailcall; | 402 | tree = sib2(tree); goto tailcall; |
@@ -419,7 +416,7 @@ static int needfollow (TTree *tree) { | |||
419 | case TChar: case TSet: case TAny: | 416 | case TChar: case TSet: case TAny: |
420 | case TFalse: case TTrue: case TAnd: case TNot: | 417 | case TFalse: case TTrue: case TAnd: case TNot: |
421 | case TRunTime: case TGrammar: case TCall: case TBehind: | 418 | case TRunTime: case TGrammar: case TCall: case TBehind: |
422 | case TThrow: case TLabChoice: /* (?)labeled failure */ | 419 | case TThrow: /* (?)labeled failure */ |
423 | return 0; | 420 | return 0; |
424 | case TChoice: case TRep: | 421 | case TChoice: case TRep: |
425 | return 1; | 422 | return 1; |
@@ -456,8 +453,6 @@ int sizei (const Instruction *i) { | |||
456 | return 2; | 453 | return 2; |
457 | case IThrowRec: /* labeled failure */ | 454 | case IThrowRec: /* labeled failure */ |
458 | return 3; | 455 | return 3; |
459 | case ILabChoice: | ||
460 | return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */ | ||
461 | 456 | ||
462 | default: return 1; | 457 | default: return 1; |
463 | } | 458 | } |
@@ -522,8 +517,7 @@ static int addinstruction (CompileState *compst, Opcode op, int aux) { | |||
522 | static int addoffsetinst (CompileState *compst, Opcode op) { | 517 | static int addoffsetinst (CompileState *compst, Opcode op) { |
523 | int i = addinstruction(compst, op, 0); /* instruction */ | 518 | int i = addinstruction(compst, op, 0); /* instruction */ |
524 | addinstruction(compst, (Opcode)0, 0); /* open space for offset */ | 519 | addinstruction(compst, (Opcode)0, 0); /* open space for offset */ |
525 | assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || | 520 | assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2); |
526 | op == ILabChoice); /* labeled failure */ | ||
527 | return i; | 521 | return i; |
528 | } | 522 | } |
529 | 523 | ||
@@ -746,24 +740,6 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | |||
746 | } | 740 | } |
747 | 741 | ||
748 | 742 | ||
749 | /* labeled failure begin */ | ||
750 | static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | ||
751 | const Charset *fl, const byte *cs) { | ||
752 | int emptyp2 = (p2->tag == TTrue); | ||
753 | int pcommit; | ||
754 | int test = NOINST; | ||
755 | int pchoice = addoffsetinst(compst, ILabChoice); | ||
756 | addcharset(compst, cs); | ||
757 | codegen(compst, p1, emptyp2, test, fullset); | ||
758 | pcommit = addoffsetinst(compst, ICommit); | ||
759 | jumptohere(compst, pchoice); | ||
760 | jumptohere(compst, test); | ||
761 | codegen(compst, p2, opt, NOINST, fl); | ||
762 | jumptohere(compst, pcommit); | ||
763 | } | ||
764 | /* labeled failure end */ | ||
765 | |||
766 | |||
767 | /* | 743 | /* |
768 | ** And predicate | 744 | ** And predicate |
769 | ** optimization: fixedlen(p) = n ==> <&p> == <p>; behind n | 745 | ** optimization: fixedlen(p) = n ==> <&p> == <p>; behind n |
@@ -1001,10 +977,6 @@ static void codegen (CompileState *compst, TTree *tree, int opt, int tt, | |||
1001 | codethrow(compst, tree); | 977 | codethrow(compst, tree); |
1002 | break; | 978 | break; |
1003 | } | 979 | } |
1004 | case TLabChoice: { /* labeled failure */ | ||
1005 | codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); | ||
1006 | break; | ||
1007 | } | ||
1008 | default: assert(0); | 980 | default: assert(0); |
1009 | } | 981 | } |
1010 | } | 982 | } |
@@ -1027,7 +999,6 @@ static void peephole (CompileState *compst) { | |||
1027 | switch (code[i].i.code) { | 999 | switch (code[i].i.code) { |
1028 | case IChoice: case ICall: case ICommit: case IPartialCommit: | 1000 | case IChoice: case ICall: case ICommit: case IPartialCommit: |
1029 | case IBackCommit: case ITestChar: case ITestSet: | 1001 | case IBackCommit: case ITestChar: case ITestSet: |
1030 | case ILabChoice: /* labeled failure */ | ||
1031 | case ITestAny: { /* instructions with labels */ | 1002 | case ITestAny: { /* instructions with labels */ |
1032 | jumptothere(compst, i, finallabel(code, i)); /* optimize label */ | 1003 | jumptothere(compst, i, finallabel(code, i)); /* optimize label */ |
1033 | break; | 1004 | break; |