1
1
#pragma warning( disable : 4244) // conversion from 'int ' to 'short ', possible loss of data
2
2
3
3
/*
4
- ** $Id: lpcode.c,v 1.21 2014/12 /12 17:01:29 roberto Exp $
4
+ ** $Id: lpcode.c,v 1.23 2015/06 /12 18:36:47 roberto Exp $
5
5
** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
6
6
*/
7
7
8
8
#include <limits.h>
9
9
10
-
11
10
#ifdef LUA_52
12
11
#include "..\..\..\lua52\src\lua.h"
13
12
#include "..\..\..\lua52\src\lauxlib.h"
@@ -438,11 +437,11 @@ typedef struct CompileState {
438
437
439
438
440
439
/*
441
- ** code generation is recursive; 'opt' indicates that the code is
442
- ** being generated under a 'IChoice' operator jumping to its end
443
- ** (that is, the match is "optional").
444
- ** 'tt' points to a previous test protecting this code. 'fl' is
445
- ** the follow set of the pattern.
440
+ ** code generation is recursive; 'opt' indicates that the code is being
441
+ ** generated as the last thing inside an optional pattern (so, if that
442
+ ** code is optional too, it can reuse the 'IChoice' already in place for
443
+ ** the outer pattern). 'tt' points to a previous test protecting this
444
+ ** code (or NOINST). 'fl' is the follow set of the pattern.
446
445
*/
447
446
static void codegen (CompileState * compst , TTree * tree , int opt , int tt ,
448
447
const Charset * fl );
@@ -645,13 +644,13 @@ static void codebehind (CompileState *compst, TTree *tree) {
645
644
646
645
/*
647
646
** Choice; optimizations:
648
- ** - when p1 is headfail
649
- ** - when first(p1) and first(p2) are disjoint; than
647
+ ** - when p1 is headfail or
648
+ ** when first(p1) and first(p2) are disjoint, than
650
649
** a character not in first(p1) cannot go to p1, and a character
651
650
** in first(p1) cannot go to p2 (at it is not in first(p2)).
652
651
** (The optimization is not valid if p1 accepts the empty string,
653
652
** as then there is no character at all...)
654
- ** - when p2 is empty and opt is true; a IPartialCommit can resuse
653
+ ** - when p2 is empty and opt is true; a IPartialCommit can reuse
655
654
** the Choice already active in the stack.
656
655
*/
657
656
static void codechoice (CompileState * compst , TTree * p1 , TTree * p2 , int opt ,
@@ -678,7 +677,7 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
678
677
}
679
678
else {
680
679
/* <p1 / p2> ==
681
- test(fail (p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
680
+ test(first (p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
682
681
int pcommit ;
683
682
int test = codetestset (compst , & cs1 , e1 );
684
683
int pchoice = addoffsetinst (compst , IChoice );
@@ -766,7 +765,7 @@ static void coderep (CompileState *compst, TTree *tree, int opt,
766
765
/* L1: test (fail(p1)) -> L2; <p>; jmp L1; L2: */
767
766
int jmp ;
768
767
int test = codetestset (compst , & st , 0 );
769
- codegen (compst , tree , opt , test , fullset );
768
+ codegen (compst , tree , 0 , test , fullset );
770
769
jmp = addoffsetinst (compst , IJmp );
771
770
jumptohere (compst , test );
772
771
jumptothere (compst , jmp , test );
0 commit comments