aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSérgio Queiroz <sqmedeiros@gmail.com>2017-12-15 14:17:20 -0300
committerSérgio Queiroz <sqmedeiros@gmail.com>2017-12-15 14:17:20 -0300
commit0f53a65f4a32c8be2d84c4a8172b885065f7c1e5 (patch)
tree5d9f4535723c43f82451ad2e1e65da7810d4d082
parentbc071e9fe431347832fd424eb327357f38e60bfd (diff)
downloadlpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.tar.gz
lpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.tar.bz2
lpeglabel-0f53a65f4a32c8be2d84c4a8172b885065f7c1e5.zip
Removing code related to previous recovery operator //{}
-rw-r--r--lpcode.c43
-rw-r--r--lptree.c29
-rw-r--r--lptree.h5
-rw-r--r--lptree.obin35552 -> 0 bytes
-rw-r--r--lpvm.c13
-rw-r--r--lpvm.h5
-rw-r--r--lpvm.obin7760 -> 0 bytes
7 files changed, 15 insertions, 80 deletions
diff --git a/lpcode.c b/lpcode.c
index 82b8830..43e83b5 100644
--- a/lpcode.c
+++ b/lpcode.c
@@ -220,7 +220,7 @@ 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 TRecov: case TLabChoice: /* labeled failure */ 223 case TLabChoice: /* labeled failure */
224 /* we do not know whether sib2 will be evaluated */ 224 /* we do not know whether sib2 will be evaluated */
225 tree = sib1(tree); goto tailcall; 225 tree = sib1(tree); goto tailcall;
226 case TCapture: case TGrammar: case TRule: 226 case TCapture: case TGrammar: case TRule:
@@ -257,7 +257,7 @@ int fixedlen (TTree *tree) {
257 else 257 else
258 return len + n1; 258 return len + n1;
259 } 259 }
260 case TSeq: case TRecov: { /* labeled failure */ 260 case TSeq: {
261 int n1 = fixedlen(sib1(tree)); 261 int n1 = fixedlen(sib1(tree));
262 if (n1 < 0) 262 if (n1 < 0)
263 return -1; 263 return -1;
@@ -321,12 +321,6 @@ static int getfirst (TTree *tree, const Charset *follow, Charset *firstset) {
321 loopset(i, firstset->cs[i] |= csaux.cs[i]); 321 loopset(i, firstset->cs[i] |= csaux.cs[i]);
322 return e1 | e2; 322 return e1 | e2;
323 } 323 }
324 case TRecov: { /* labeled failure */
325 /* when p1 is not nullable, p2 has nothing to contribute;
326 and when p1 is nullable, then p2 will not match
327 return getfirst(sib1(tree), fullset, firstset); */
328 tree = sib1(tree); follow = fullset; goto tailcall;
329 }
330 case TSeq: { 324 case TSeq: {
331 if (!nullable(sib1(tree))) { 325 if (!nullable(sib1(tree))) {
332 /* when p1 is not nullable, p2 has nothing to contribute; 326 /* when p1 is not nullable, p2 has nothing to contribute;
@@ -405,7 +399,7 @@ static int headfail (TTree *tree) {
405 if (!nofail(sib2(tree))) return 0; 399 if (!nofail(sib2(tree))) return 0;
406 /* else return headfail(sib1(tree)); */ 400 /* else return headfail(sib1(tree)); */
407 tree = sib1(tree); goto tailcall; 401 tree = sib1(tree); goto tailcall;
408 case TChoice: case TRecov: case TLabChoice: /* labeled failure */ 402 case TChoice: case TLabChoice: /* labeled failure */
409 if (!headfail(sib1(tree))) return 0; 403 if (!headfail(sib1(tree))) return 0;
410 /* else return headfail(sib2(tree)); */ 404 /* else return headfail(sib2(tree)); */
411 tree = sib2(tree); goto tailcall; 405 tree = sib2(tree); goto tailcall;
@@ -425,7 +419,7 @@ static int needfollow (TTree *tree) {
425 case TChar: case TSet: case TAny: 419 case TChar: case TSet: case TAny:
426 case TFalse: case TTrue: case TAnd: case TNot: 420 case TFalse: case TTrue: case TAnd: case TNot:
427 case TRunTime: case TGrammar: case TCall: case TBehind: 421 case TRunTime: case TGrammar: case TCall: case TBehind:
428 case TThrow: case TRecov: case TLabChoice: /* (?)labeled failure */ 422 case TThrow: case TLabChoice: /* (?)labeled failure */
429 return 0; 423 return 0;
430 case TChoice: case TRep: 424 case TChoice: case TRep:
431 return 1; 425 return 1;
@@ -462,7 +456,7 @@ int sizei (const Instruction *i) {
462 return 2; 456 return 2;
463 case IThrowRec: /* labeled failure */ 457 case IThrowRec: /* labeled failure */
464 return 3; 458 return 3;
465 case IRecov: case ILabChoice: 459 case ILabChoice:
466 return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */ 460 return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */
467 461
468 default: return 1; 462 default: return 1;
@@ -529,7 +523,7 @@ static int addoffsetinst (CompileState *compst, Opcode op) {
529 int i = addinstruction(compst, op, 0); /* instruction */ 523 int i = addinstruction(compst, op, 0); /* instruction */
530 addinstruction(compst, (Opcode)0, 0); /* open space for offset */ 524 addinstruction(compst, (Opcode)0, 0); /* open space for offset */
531 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || 525 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 ||
532 op == IRecov || op == ILabChoice); /* labeled failure */ 526 op == ILabChoice); /* labeled failure */
533 return i; 527 return i;
534} 528}
535 529
@@ -753,22 +747,6 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
753 747
754 748
755/* labeled failure begin */ 749/* labeled failure begin */
756static void coderecovery (CompileState *compst, TTree *p1, TTree *p2, int opt,
757 const Charset *fl, const byte *cs) {
758 int emptyp2 = (p2->tag == TTrue);
759 int pcommit;
760 int test = NOINST;
761 int precovery = addoffsetinst(compst, IRecov);
762 addcharset(compst, cs);
763 codegen(compst, p1, emptyp2, test, fullset);
764 pcommit = addoffsetinst(compst, ICommit);
765 jumptohere(compst, precovery);
766 jumptohere(compst, test);
767 codegen(compst, p2, opt, NOINST, fl);
768 addinstruction(compst, IRet, 0);
769 jumptohere(compst, pcommit);
770}
771
772static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt, 750static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
773 const Charset *fl, const byte *cs) { 751 const Charset *fl, const byte *cs) {
774 int emptyp2 = (p2->tag == TTrue); 752 int emptyp2 = (p2->tag == TTrue);
@@ -1020,16 +998,9 @@ static void codegen (CompileState *compst, TTree *tree, int opt, int tt,
1020 tree = sib2(tree); goto tailcall; 998 tree = sib2(tree); goto tailcall;
1021 } 999 }
1022 case TThrow: { /* labeled failure */ 1000 case TThrow: { /* labeled failure */
1023 /*printf("TThrow %s top %d\n", lua_typename(compst->L, -1), lua_gettop(compst->L));*/
1024 /*lua_rawgeti(compst->L, -1, tree->key);*/
1025 /*printf("Throw2 lab = %s\n", lua_tostring(compst->L, -1));*/
1026 codethrow(compst, tree); 1001 codethrow(compst, tree);
1027 break; 1002 break;
1028 } 1003 }
1029 case TRecov: { /* labeled failure */
1030 coderecovery(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree));
1031 break;
1032 }
1033 case TLabChoice: { /* labeled failure */ 1004 case TLabChoice: { /* labeled failure */
1034 codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree)); 1005 codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree));
1035 break; 1006 break;
@@ -1056,7 +1027,7 @@ static void peephole (CompileState *compst) {
1056 switch (code[i].i.code) { 1027 switch (code[i].i.code) {
1057 case IChoice: case ICall: case ICommit: case IPartialCommit: 1028 case IChoice: case ICall: case ICommit: case IPartialCommit:
1058 case IBackCommit: case ITestChar: case ITestSet: 1029 case IBackCommit: case ITestChar: case ITestSet:
1059 case IRecov: case ILabChoice: /* labeled failure */ 1030 case ILabChoice: /* labeled failure */
1060 case ITestAny: { /* instructions with labels */ 1031 case ITestAny: { /* instructions with labels */
1061 jumptothere(compst, i, finallabel(code, i)); /* optimize label */ 1032 jumptothere(compst, i, finallabel(code, i)); /* optimize label */
1062 break; 1033 break;
diff --git a/lptree.c b/lptree.c
index 1e8de3e..90e82ef 100644
--- a/lptree.c
+++ b/lptree.c
@@ -527,10 +527,10 @@ static TTree *newroot2sib (lua_State *L, int tag) {
527 527
528 528
529/* labeled failure begin */ 529/* labeled failure begin */
530static TTree *newthrowleaf (lua_State *L, int lab) { 530static TTree *newthrowleaf (lua_State *L) {
531 TTree *tree = newtree(L, 1); 531 TTree *tree = newtree(L, 1);
532 tree->tag = TThrow; 532 tree->tag = TThrow;
533 tree->u.s.ps = 0; 533 tree->u.s.ps = 0; /* there is no recovery rule associated */
534 return tree; 534 return tree;
535} 535}
536 536
@@ -730,35 +730,15 @@ static int lp_behind (lua_State *L) {
730** Throws a label 730** Throws a label
731*/ 731*/
732static int lp_throw (lua_State *L) { 732static int lp_throw (lua_State *L) {
733 /*int label = luaL_checkinteger(L, -1);*/
734 /*luaL_argcheck(L, label >= 1 && label < MAXLABELS, -1, "the number of a label must be between 1 and 255");*/
735 TTree * tree; 733 TTree * tree;
736 luaL_checkstring(L, -1); 734 luaL_checkstring(L, -1);
737 tree = newthrowleaf(L, 0); 735 tree = newthrowleaf(L);
738 tree->key = addtonewktable(L, 0, 1); 736 tree->key = addtonewktable(L, 0, 1);
739 /*printf("lp_throw %d %s\n", tree->key, lua_tostring(L, 1));*/
740 return 1; 737 return 1;
741} 738}
742 739
743 740
744/* 741/*
745** labeled recovery function
746*/
747static int lp_recovery (lua_State *L) {
748 int n = lua_gettop(L);
749 TTree *tree = newrootlab2sib(L, TRecov);
750 int i;
751 luaL_argcheck(L, n >= 3, 3, "non-nil value expected");
752 for (i = 3; i <= n; i++) {
753 int d = luaL_checkinteger(L, i);
754 luaL_argcheck(L, d >= 1 && d < MAXLABELS, i, "the number of a label must be between 1 and 255");
755 setlabel(treelabelset(tree), (byte)d);
756 }
757 return 1;
758}
759
760
761/*
762** labeled choice function 742** labeled choice function
763*/ 743*/
764static int lp_labchoice (lua_State *L) { 744static int lp_labchoice (lua_State *L) {
@@ -1108,7 +1088,7 @@ static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed,
1108 return nb; 1088 return nb;
1109 /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */ 1089 /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */
1110 tree = sib2(tree); goto tailcall; 1090 tree = sib2(tree); goto tailcall;
1111 case TChoice: case TRecov: case TLabChoice: /* must check both children */ /* labeled failure */ 1091 case TChoice: case TLabChoice: /* must check both children */ /* labeled failure */
1112 nb = verifyrule(L, sib1(tree), passed, npassed, nb); 1092 nb = verifyrule(L, sib1(tree), passed, npassed, nb);
1113 /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ 1093 /* return verifyrule(L, sib2(tree), passed, npassed, nb); */
1114 tree = sib2(tree); goto tailcall; 1094 tree = sib2(tree); goto tailcall;
@@ -1364,7 +1344,6 @@ static struct luaL_Reg pattreg[] = {
1364 {"setmaxstack", lp_setmax}, 1344 {"setmaxstack", lp_setmax},
1365 {"type", lp_type}, 1345 {"type", lp_type},
1366 {"T", lp_throw}, /* labeled failure throw */ 1346 {"T", lp_throw}, /* labeled failure throw */
1367 {"Rec", lp_recovery}, /* labeled failure recovery */
1368 {"Lc", lp_labchoice}, /* labeled failure choice */ 1347 {"Lc", lp_labchoice}, /* labeled failure choice */
1369 {NULL, NULL} 1348 {NULL, NULL}
1370}; 1349};
diff --git a/lptree.h b/lptree.h
index bb53c84..2980821 100644
--- a/lptree.h
+++ b/lptree.h
@@ -35,10 +35,7 @@ typedef enum TTag {
35 'sib1' is capture body */ 35 'sib1' is capture body */
36 TRunTime, /* run-time capture: 'key' is Lua function; 36 TRunTime, /* run-time capture: 'key' is Lua function;
37 'sib1' is capture body */ 37 'sib1' is capture body */
38 TThrow, /* labeled failure: 'label' = l */ 38 TThrow, /* labeled failure: ktable[key] is label's */
39 TThrowRec, /* labeled failure: 'label' = l */
40 TRecov, /* labed failure: 'sib1' //{labels} 'sib2' */
41 /* the set of labels is stored in next CHARSETSIZE bytes */
42 TLabChoice /* labed failure: 'sib1' /{labels} 'sib2' */ 39 TLabChoice /* labed failure: 'sib1' /{labels} 'sib2' */
43 /* the set of labels is stored in next CHARSETSIZE bytes */ 40 /* the set of labels is stored in next CHARSETSIZE bytes */
44} TTag; 41} TTag;
diff --git a/lptree.o b/lptree.o
deleted file mode 100644
index 9e01066..0000000
--- a/lptree.o
+++ /dev/null
Binary files differ
diff --git a/lpvm.c b/lpvm.c
index c408e4c..dfbda74 100644
--- a/lpvm.c
+++ b/lpvm.c
@@ -288,17 +288,6 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
288 p += (CHARSETINSTSIZE - 1) + 2; 288 p += (CHARSETINSTSIZE - 1) + 2;
289 continue; 289 continue;
290 } 290 }
291 case IRecov: { /* labeled failure */
292 if (stack == stacklimit)
293 stack = doublestack(L, &stacklimit, ptop);
294 stack->p = p + getoffset(p);
295 stack->s = NULL;
296 stack->ls = (const Labelset *) ((p + 2)->buff);
297 stack->caplevel = captop;
298 stack++;
299 p += (CHARSETINSTSIZE - 1) + 2;
300 continue;
301 }
302 case ICall: { 291 case ICall: {
303 if (stack == stacklimit) 292 if (stack == stacklimit)
304 stack = doublestack(L, &stacklimit, ptop); 293 stack = doublestack(L, &stacklimit, ptop);
@@ -311,7 +300,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
311 } 300 }
312 case ICommit: { 301 case ICommit: {
313 assert(stack > getstackbase(L, ptop) && (stack - 1)->ls != NULL); /* labeled failure */ 302 assert(stack > getstackbase(L, ptop) && (stack - 1)->ls != NULL); /* labeled failure */
314 /*assert((stack - 1)->s != NULL); labeled failure: IRecov does not push s onto the stack */ 303 assert((stack - 1)->s != NULL);
315 stack--; 304 stack--;
316 p += getoffset(p); 305 p += getoffset(p);
317 continue; 306 continue;
diff --git a/lpvm.h b/lpvm.h
index c22e8d7..e4c5353 100644
--- a/lpvm.h
+++ b/lpvm.h
@@ -34,9 +34,8 @@ typedef enum Opcode {
34 IOpenCapture, /* start a capture */ 34 IOpenCapture, /* start a capture */
35 ICloseCapture, 35 ICloseCapture,
36 ICloseRunTime, 36 ICloseRunTime,
37 IThrow, /* "fails" with a specific label labeled failure */ 37 IThrow, /* fails with a given label */
38 IThrowRec, /* "fails" with a specific label labeled failure */ 38 IThrowRec, /* fails with a given label and call rule at 'offset' */
39 IRecov, /* stack a recovery; next fail with label 'f' will jump to 'offset' */
40 ILabChoice /* stack a choice; next fail with label 'f' will jump to 'offset' */ 39 ILabChoice /* stack a choice; next fail with label 'f' will jump to 'offset' */
41} Opcode; 40} Opcode;
42 41
diff --git a/lpvm.o b/lpvm.o
deleted file mode 100644
index 19a9b1c..0000000
--- a/lpvm.o
+++ /dev/null
Binary files differ