aboutsummaryrefslogtreecommitdiff
path: root/lpcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lpcode.c')
-rw-r--r--lpcode.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/lpcode.c b/lpcode.c
index 2a85e02..9fa8867 100644
--- a/lpcode.c
+++ b/lpcode.c
@@ -11,7 +11,7 @@
11 11
12#include "lptypes.h" 12#include "lptypes.h"
13#include "lpcode.h" 13#include "lpcode.h"
14 14#include "lpprint.h" /* labeled failure */
15 15
16/* signals a "no-instruction */ 16/* signals a "no-instruction */
17#define NOINST -1 17#define NOINST -1
@@ -424,10 +424,11 @@ int sizei (const Instruction *i) {
424 case ITestSet: return CHARSETINSTSIZE + 1; 424 case ITestSet: return CHARSETINSTSIZE + 1;
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 */
428 return 2; 427 return 2;
428 case IThrow: /* labeled failure */
429 return 1;
429 case ILabChoice: 430 case ILabChoice:
430 return 3; /* labeled failure */ 431 return (CHARSETINSTSIZE - 1) + 2; /* labeled failure */
431 default: return 1; 432 default: return 1;
432 } 433 }
433} 434}
@@ -491,27 +492,24 @@ static int addinstruction (CompileState *compst, Opcode op, int aux) {
491static int addoffsetinst (CompileState *compst, Opcode op) { 492static int addoffsetinst (CompileState *compst, Opcode op) {
492 int i = addinstruction(compst, op, 0); /* instruction */ 493 int i = addinstruction(compst, op, 0); /* instruction */
493 addinstruction(compst, (Opcode)0, 0); /* open space for offset */ 494 addinstruction(compst, (Opcode)0, 0); /* open space for offset */
494 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2); 495 assert(op == ITestSet || sizei(&getinstr(compst, i)) == 2 || op == ILabChoice); /* labeled failure */
495 return i; 496 return i;
496} 497}
497 498
498/* labeled failure begin */ 499/* labeled failure begin */
499static int addthrowinstruction (CompileState *compst, Labelset ls) { 500static int addthrowinstruction (CompileState *compst, byte lab) {
500 int i = nextinstruction(compst); 501 return addinstruction(compst, IThrow, lab);
501 getinstr(compst, i).i.code = IThrow;
502 i = nextinstruction(compst);
503 getinstr(compst, i).labels = ls;
504 return i;
505} 502}
506 503
507static int addoffsetlabinst (CompileState *compst, Labelset ls) { 504/*static int addoffsetlabinst (CompileState *compst, const byte *cs) {
508 int j; 505 int j;
509 int i = addinstruction(compst, ILabChoice, 0); /* instruction */ 506 int i = addinstruction(compst, ILabChoice, 0);
510 addinstruction(compst, (Opcode)0, 0); /* open space for offset */ 507 addinstruction(compst, (Opcode)0, 0);
511 j = nextinstruction(compst); /* open space for labels */ 508 j = nextinstruction(compst);
512 getinstr(compst, j).labels = ls; 509 getinstr(compst, j).labels = cs;
510
513 return i; 511 return i;
514} 512}*/
515/* labeled failure end */ 513/* labeled failure end */
516 514
517/* 515/*
@@ -718,18 +716,21 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
718 716
719/* labeled failure begin */ 717/* labeled failure begin */
720static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt, 718static void codelabchoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
721 const Charset *fl, Labelset ls) { 719 const Charset *fl, const byte *cs) {
722 int emptyp2 = (p2->tag == TTrue); 720 int emptyp2 = (p2->tag == TTrue);
723 int pcommit; 721 int pcommit;
724 int test = NOINST; 722 int test = NOINST;
725 int pchoice = addoffsetlabinst(compst, ls); 723 /* int pchoice = addoffsetlabinst(compst, cs);*/
724 int pchoice = addoffsetinst(compst, ILabChoice);
725 addcharset(compst, cs);
726 codegen(compst, p1, emptyp2, test, fullset); 726 codegen(compst, p1, emptyp2, test, fullset);
727 pcommit = addoffsetinst(compst, ICommit); 727 pcommit = addoffsetinst(compst, ICommit);
728 jumptohere(compst, pchoice); 728 jumptohere(compst, pchoice);
729 jumptohere(compst, test); 729 jumptohere(compst, test);
730 /*printf("vou codificar codelabchoice %d\n", p2->tag);*/
730 codegen(compst, p2, opt, NOINST, fl); 731 codegen(compst, p2, opt, NOINST, fl);
731 jumptohere(compst, pcommit); 732 jumptohere(compst, pcommit);
732 733 /*printf("fim codelabchoice\n");*/
733} 734}
734/* labeled failure end */ 735/* labeled failure end */
735 736
@@ -961,11 +962,11 @@ static void codegen (CompileState *compst, TTree *tree, int opt, int tt,
961 tree = sib2(tree); goto tailcall; 962 tree = sib2(tree); goto tailcall;
962 } 963 }
963 case TThrow: { /* labeled failure */ 964 case TThrow: { /* labeled failure */
964 addthrowinstruction(compst, tree->labels); 965 addthrowinstruction(compst, (byte) tree->u.label);
965 break; 966 break;
966 } 967 }
967 case TLabChoice: { /* labeled failure */ 968 case TLabChoice: { /* labeled failure */
968 codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, tree->labels); 969 codelabchoice(compst, sib1(tree), sib2(tree), opt, fl, treelabelset(tree));
969 break; 970 break;
970 } 971 }
971 default: assert(0); 972 default: assert(0);