diff options
Diffstat (limited to 'lpcode.c')
-rw-r--r-- | lpcode.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lpcode.c,v 1.21 2014/12/12 17:01:29 roberto Exp $ | 2 | ** $Id: lpcode.c,v 1.23 2015/06/12 18:36:47 roberto Exp $ |
3 | ** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license) | 3 | ** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license) |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -192,7 +192,7 @@ int checkaux (TTree *tree, int pred) { | |||
192 | if (!checkaux(sib1(tree), pred)) return 0; | 192 | if (!checkaux(sib1(tree), pred)) return 0; |
193 | /* else return checkaux(sib2(tree), pred); */ | 193 | /* else return checkaux(sib2(tree), pred); */ |
194 | tree = sib2(tree); goto tailcall; | 194 | tree = sib2(tree); goto tailcall; |
195 | case TChoice: | 195 | case TChoice: |
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; |
@@ -425,9 +425,9 @@ int sizei (const Instruction *i) { | |||
425 | case ITestChar: case ITestAny: case IChoice: case IJmp: case ICall: | 425 | case ITestChar: case ITestAny: case IChoice: case IJmp: case ICall: |
426 | case IOpenCall: case ICommit: case IPartialCommit: case IBackCommit: | 426 | case IOpenCall: case ICommit: case IPartialCommit: case IBackCommit: |
427 | case IThrow: /* labeled failure */ | 427 | case IThrow: /* labeled failure */ |
428 | return 2; | ||
429 | case ILabChoice: return 3; /* labeled failure */ | ||
430 | return 2; | 428 | return 2; |
429 | case ILabChoice: | ||
430 | return 3; /* labeled failure */ | ||
431 | default: return 1; | 431 | default: return 1; |
432 | } | 432 | } |
433 | } | 433 | } |
@@ -444,11 +444,11 @@ typedef struct CompileState { | |||
444 | 444 | ||
445 | 445 | ||
446 | /* | 446 | /* |
447 | ** code generation is recursive; 'opt' indicates that the code is | 447 | ** code generation is recursive; 'opt' indicates that the code is being |
448 | ** being generated under a 'IChoice' operator jumping to its end | 448 | ** generated as the last thing inside an optional pattern (so, if that |
449 | ** (that is, the match is "optional"). | 449 | ** code is optional too, it can reuse the 'IChoice' already in place for |
450 | ** 'tt' points to a previous test protecting this code. 'fl' is | 450 | ** the outer pattern). 'tt' points to a previous test protecting this |
451 | ** the follow set of the pattern. | 451 | ** code (or NOINST). 'fl' is the follow set of the pattern. |
452 | */ | 452 | */ |
453 | static void codegen (CompileState *compst, TTree *tree, int opt, int tt, | 453 | static void codegen (CompileState *compst, TTree *tree, int opt, int tt, |
454 | const Charset *fl); | 454 | const Charset *fl); |
@@ -669,13 +669,13 @@ static void codebehind (CompileState *compst, TTree *tree) { | |||
669 | 669 | ||
670 | /* | 670 | /* |
671 | ** Choice; optimizations: | 671 | ** Choice; optimizations: |
672 | ** - when p1 is headfail | 672 | ** - when p1 is headfail or |
673 | ** - when first(p1) and first(p2) are disjoint; than | 673 | ** when first(p1) and first(p2) are disjoint, than |
674 | ** a character not in first(p1) cannot go to p1, and a character | 674 | ** a character not in first(p1) cannot go to p1, and a character |
675 | ** in first(p1) cannot go to p2 (at it is not in first(p2)). | 675 | ** in first(p1) cannot go to p2 (at it is not in first(p2)). |
676 | ** (The optimization is not valid if p1 accepts the empty string, | 676 | ** (The optimization is not valid if p1 accepts the empty string, |
677 | ** as then there is no character at all...) | 677 | ** as then there is no character at all...) |
678 | ** - when p2 is empty and opt is true; a IPartialCommit can resuse | 678 | ** - when p2 is empty and opt is true; a IPartialCommit can reuse |
679 | ** the Choice already active in the stack. | 679 | ** the Choice already active in the stack. |
680 | */ | 680 | */ |
681 | static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | 681 | static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, |
@@ -702,7 +702,7 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, | |||
702 | } | 702 | } |
703 | else { | 703 | else { |
704 | /* <p1 / p2> == | 704 | /* <p1 / p2> == |
705 | test(fail(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */ | 705 | test(first(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */ |
706 | int pcommit; | 706 | int pcommit; |
707 | int test = codetestset(compst, &cs1, e1); | 707 | int test = codetestset(compst, &cs1, e1); |
708 | int pchoice = addoffsetinst(compst, IChoice); | 708 | int pchoice = addoffsetinst(compst, IChoice); |
@@ -808,7 +808,7 @@ static void coderep (CompileState *compst, TTree *tree, int opt, | |||
808 | /* L1: test (fail(p1)) -> L2; <p>; jmp L1; L2: */ | 808 | /* L1: test (fail(p1)) -> L2; <p>; jmp L1; L2: */ |
809 | int jmp; | 809 | int jmp; |
810 | int test = codetestset(compst, &st, 0); | 810 | int test = codetestset(compst, &st, 0); |
811 | codegen(compst, tree, opt, test, fullset); | 811 | codegen(compst, tree, 0, test, fullset); |
812 | jmp = addoffsetinst(compst, IJmp); | 812 | jmp = addoffsetinst(compst, IJmp); |
813 | jumptohere(compst, test); | 813 | jumptohere(compst, test); |
814 | jumptothere(compst, jmp, test); | 814 | jumptothere(compst, jmp, test); |