aboutsummaryrefslogtreecommitdiff
path: root/lpcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
commit3f7797419e4d7493e1364290a5b127d1cb45e3bf (patch)
tree8dd91b0d008d5ea9f9c96eada86510495c97d1e3 /lpcode.c
parentd9f83dded93a35fb333c4e1bd371c401f7129fd1 (diff)
downloadlpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.gz
lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.bz2
lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.zip
Removed 'unsigned char' limit on number of rules in grammars
Added a new tree-type node 'TXInfo', which follows 'TRule' nodes, to store extra information about a node. (In this case, the rule number, with an 'unsigned short' field.)
Diffstat (limited to 'lpcode.c')
-rw-r--r--lpcode.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lpcode.c b/lpcode.c
index 3923459..5fddfab 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 TCapture: case TGrammar: case TRule: 223 case TCapture: case TGrammar: case TRule: case TXInfo:
224 /* return checkaux(sib1(tree), pred); */ 224 /* return checkaux(sib1(tree), pred); */
225 tree = sib1(tree); goto tailcall; 225 tree = sib1(tree); goto tailcall;
226 case TCall: /* return checkaux(sib2(tree), pred); */ 226 case TCall: /* return checkaux(sib2(tree), pred); */
@@ -243,7 +243,7 @@ int fixedlen (TTree *tree) {
243 return len; 243 return len;
244 case TRep: case TRunTime: case TOpenCall: 244 case TRep: case TRunTime: case TOpenCall:
245 return -1; 245 return -1;
246 case TCapture: case TRule: case TGrammar: 246 case TCapture: case TRule: case TGrammar: case TXInfo:
247 /* return fixedlen(sib1(tree)); */ 247 /* return fixedlen(sib1(tree)); */
248 tree = sib1(tree); goto tailcall; 248 tree = sib1(tree); goto tailcall;
249 case TCall: { 249 case TCall: {
@@ -334,7 +334,7 @@ static int getfirst (TTree *tree, const Charset *follow, Charset *firstset) {
334 loopset(i, firstset->cs[i] |= follow->cs[i]); 334 loopset(i, firstset->cs[i] |= follow->cs[i]);
335 return 1; /* accept the empty string */ 335 return 1; /* accept the empty string */
336 } 336 }
337 case TCapture: case TGrammar: case TRule: { 337 case TCapture: case TGrammar: case TRule: case TXInfo: {
338 /* return getfirst(sib1(tree), follow, firstset); */ 338 /* return getfirst(sib1(tree), follow, firstset); */
339 tree = sib1(tree); goto tailcall; 339 tree = sib1(tree); goto tailcall;
340 } 340 }
@@ -382,7 +382,7 @@ static int headfail (TTree *tree) {
382 case TTrue: case TRep: case TRunTime: case TNot: 382 case TTrue: case TRep: case TRunTime: case TNot:
383 case TBehind: 383 case TBehind:
384 return 0; 384 return 0;
385 case TCapture: case TGrammar: case TRule: case TAnd: 385 case TCapture: case TGrammar: case TRule: case TXInfo: case TAnd:
386 tree = sib1(tree); goto tailcall; /* return headfail(sib1(tree)); */ 386 tree = sib1(tree); goto tailcall; /* return headfail(sib1(tree)); */
387 case TCall: 387 case TCall:
388 tree = sib2(tree); goto tailcall; /* return headfail(sib2(tree)); */ 388 tree = sib2(tree); goto tailcall; /* return headfail(sib2(tree)); */
@@ -874,8 +874,10 @@ static void codegrammar (CompileState *compst, TTree *grammar) {
874 int start = gethere(compst); /* here starts the initial rule */ 874 int start = gethere(compst); /* here starts the initial rule */
875 jumptohere(compst, firstcall); 875 jumptohere(compst, firstcall);
876 for (rule = sib1(grammar); rule->tag == TRule; rule = sib2(rule)) { 876 for (rule = sib1(grammar); rule->tag == TRule; rule = sib2(rule)) {
877 TTree *r = sib1(rule);
878 assert(r->tag == TXInfo);
877 positions[rulenumber++] = gethere(compst); /* save rule position */ 879 positions[rulenumber++] = gethere(compst); /* save rule position */
878 codegen(compst, sib1(rule), 0, NOINST, fullset); /* code rule */ 880 codegen(compst, sib1(r), 0, NOINST, fullset); /* code rule */
879 addinstruction(compst, IRet, 0); 881 addinstruction(compst, IRet, 0);
880 } 882 }
881 assert(rule->tag == TTrue); 883 assert(rule->tag == TTrue);
@@ -886,8 +888,8 @@ static void codegrammar (CompileState *compst, TTree *grammar) {
886 888
887static void codecall (CompileState *compst, TTree *call) { 889static void codecall (CompileState *compst, TTree *call) {
888 int c = addoffsetinst(compst, IOpenCall); /* to be corrected later */ 890 int c = addoffsetinst(compst, IOpenCall); /* to be corrected later */
889 getinstr(compst, c).i.key = sib2(call)->cap; /* rule number */ 891 assert(sib1(sib2(call))->tag == TXInfo);
890 assert(sib2(call)->tag == TRule); 892 getinstr(compst, c).i.key = sib1(sib2(call))->u.n; /* rule number */
891} 893}
892 894
893 895
@@ -971,7 +973,7 @@ static void peephole (CompileState *compst) {
971 case IRet: case IFail: case IFailTwice: 973 case IRet: case IFail: case IFailTwice:
972 case IEnd: { /* instructions with unconditional implicit jumps */ 974 case IEnd: { /* instructions with unconditional implicit jumps */
973 code[i] = code[ft]; /* jump becomes that instruction */ 975 code[i] = code[ft]; /* jump becomes that instruction */
974 code[i + 1].i.code = IAny; /* 'no-op' for target position */ 976 code[i + 1].i.code = IEmpty; /* 'no-op' for target position */
975 break; 977 break;
976 } 978 }
977 case ICommit: case IPartialCommit: 979 case ICommit: case IPartialCommit: