shithub: libmujs

Download patch

ref: 55ad332621a4761674ef84fc9a78e890b8cdc8dd
parent: d50c934fec01b67f6c6803bb4994f6c7038d7c7c
author: Tor Andersson <tor@ccxvii.net>
date: Mon Feb 24 10:33:50 EST 2014

Rename some regex opcodes.

--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 
 CFLAGS = -Wall -g
 
-default: build js
+default: build js re
 
 build:
 	mkdir -p build
--- a/regex.c
+++ b/regex.c
@@ -529,10 +529,10 @@
 /* Compile */
 
 enum {
-	I_MATCH, I_JUMP, I_SPLIT, I_PLA, I_NLA,
+	I_END, I_JUMP, I_SPLIT, I_PLA, I_NLA,
 	I_ANY, I_CHAR, I_CCLASS, I_NCCLASS, I_REF,
 	I_BOL, I_EOL, I_WORD, I_NWORD,
-	I_PAR, I_ENDPAR
+	I_LPAR, I_RPAR
 };
 
 struct Reinst {
@@ -650,31 +650,31 @@
 	case P_NWORD: emit(prog, I_NWORD); break;
 
 	case P_PAR:
-		inst = emit(prog, I_PAR);
+		inst = emit(prog, I_LPAR);
 		inst->n = node->n;
 		compile(prog, node->x);
-		inst = emit(prog, I_ENDPAR);
+		inst = emit(prog, I_RPAR);
 		inst->n = node->n;
 		break;
 	case P_PLA:
 		split = emit(prog, I_PLA);
-		inst = emit(prog, I_PAR);
+		inst = emit(prog, I_LPAR);
 		inst->n = node->n;
 		compile(prog, node->x);
-		inst = emit(prog, I_ENDPAR);
+		inst = emit(prog, I_RPAR);
 		inst->n = node->n;
-		emit(prog, I_MATCH);
+		emit(prog, I_END);
 		split->x = split + 1;
 		split->y = prog->end;
 		break;
 	case P_NLA:
 		split = emit(prog, I_NLA);
-		inst = emit(prog, I_PAR);
+		inst = emit(prog, I_LPAR);
 		inst->n = node->n;
 		compile(prog, node->x);
-		inst = emit(prog, I_ENDPAR);
+		inst = emit(prog, I_RPAR);
 		inst->n = node->n;
-		emit(prog, I_MATCH);
+		emit(prog, I_END);
 		split->x = split + 1;
 		split->y = prog->end;
 		break;
@@ -744,7 +744,7 @@
 	for (i = 0, inst = prog->start; inst < prog->end; ++i, ++inst) {
 		printf("% 5d: ", i);
 		switch (inst->opcode) {
-		case I_MATCH: puts("match"); break;
+		case I_END: puts("end"); break;
 		case I_JUMP: printf("jump %d\n", (int)(inst->x - prog->start)); break;
 		case I_SPLIT: printf("split %d %d\n", (int)(inst->x - prog->start), (int)(inst->y - prog->start)); break;
 		case I_PLA: printf("pla %d %d\n", (int)(inst->x - prog->start), (int)(inst->y - prog->start)); break;
@@ -758,8 +758,8 @@
 		case I_EOL: puts("eol"); break;
 		case I_WORD: puts("word"); break;
 		case I_NWORD: puts("nword"); break;
-		case I_PAR: printf("par %d\n", inst->n); break;
-		case I_ENDPAR: printf("endpar %d\n", inst->n); break;
+		case I_LPAR: printf("lpar %d\n", inst->n); break;
+		case I_RPAR: printf("rpar %d\n", inst->n); break;
 		}
 	}
 }
@@ -798,10 +798,10 @@
 		die(&g, "syntax error");
 
 	g.prog->start = g.prog->end = malloc((count(node) + 3) * sizeof (Reinst));
-	emit(g.prog, I_PAR);
+	emit(g.prog, I_LPAR);
 	compile(g.prog, node);
-	emit(g.prog, I_ENDPAR);
-	emit(g.prog, I_MATCH);
+	emit(g.prog, I_RPAR);
+	emit(g.prog, I_END);
 
 #ifdef TEST
 	dumpnode(node);
@@ -887,7 +887,7 @@
 
 	for (;;) {
 		switch (pc->opcode) {
-		case I_MATCH:
+		case I_END:
 			return 1;
 		case I_JUMP:
 			pc = pc->x;
@@ -998,7 +998,7 @@
 			if (!n)
 				break;
 			return 0;
-		case I_PAR:
+		case I_LPAR:
 			p = g->m[pc->n].sp;
 			g->m[pc->n].sp = s;
 			if (match(g, pc + 1, s))
@@ -1005,7 +1005,7 @@
 				return 1;
 			g->m[pc->n].sp = p;
 			return 0;
-		case I_ENDPAR:
+		case I_RPAR:
 			p = g->m[pc->n].ep;
 			g->m[pc->n].ep = s;
 			if (match(g, pc + 1, s))