shithub: mc

Download patch

ref: b00a84d15d8e3dcf8a2558d2d3f615c738864125
parent: 5fe0859c8a8a801150efa772492db9b6f1baa631
author: Ori Bernstein <[email protected]>
date: Tue Oct 22 18:40:46 EDT 2013

Correctly pass the duplicated match slices over.

--- a/interp.myr
+++ b/interp.myr
@@ -14,8 +14,12 @@
 	re.strp = 0
 	re.matched = `std.None
 	mkthread(re, 0)
-	re.thr[0].mstart = std.slzalloc(re.nmatch)
-	re.thr[0].mend = std.slzalloc(re.nmatch)
+	re.thr[0].mstart = std.slalloc(re.nmatch)
+	re.thr[0].mend = std.slalloc(re.nmatch)
+	for i = 0; i < re.nmatch; i++
+		re.thr[0].mstart[i] = 0
+		re.thr[0].mend[i] = 0
+	;;
 	while re.nthr > 0
 		for i = 0; i < re.nthr; i++
 			trace(re, "tid=%z, ip=%z, c=b\n", re.thr[i].uid, re.thr[i].ip, str[re.strp])
@@ -28,7 +32,8 @@
 	match re.matched
 	`std.Some thr:	
 		for i = 0; i < re.nmatch; i++
-			std.put("match %i:[%z..%z]\n", i, thr.mstart[i], thr.mend[i])
+			std.put("match %z:", i)
+			std.put("[%z..%z]\n", thr.mstart[i], thr.mend[i])
 		;;
 		-> re.strp == str.len;;
 	`std.None:	-> false;;
@@ -38,6 +43,8 @@
 const step = {re, tid
 	var thr
 	var str
+	var mstart
+	var mend
 
 	thr = re.thr[tid]
 	str = re.str
@@ -76,6 +83,7 @@
 	 */
 	`Ilbra	m:
 		trace(re, "\t%i:\tLbra %z\n", thr.ip, m)
+		trace(re, "\t\tmatch start = %z\n", re.strp)
 		thr.mstart[m] = re.strp
 		thr.ip++
 		step(re, tid)
@@ -88,8 +96,10 @@
 		;;
 	`Ifork	(lip, rip):
 		trace(re, "\t%i:\tFork (%z, %z)\n", thr.ip, rip, lip)
+		mstart = std.sldup(thr.mstart)
+		mend = std.sldup(thr.mend)
 		jmp(re, tid, rip)
-		fork(re, thr, lip)
+		fork(re, thr, lip, mstart, mend)
 		;;
 	`Ijmp ip:
 		trace(re, "\t%i:\tJmp %z\n", thr.ip, ip)
@@ -127,12 +137,12 @@
 	-> tid
 }
 
-const fork = {re, thr, ip
+const fork = {re, thr, ip, mstart, mend
 	var tid
 
 	tid = mkthread(re, ip)
-	re.thr[tid].mstart = std.sldup(thr.mstart)
-	re.thr[tid].mend = std.sldup(thr.mend)
+	re.thr[tid].mstart = mstart
+	re.thr[tid].mend = mend
 	step(re, tid)
 }
 
@@ -142,6 +152,8 @@
 	   thread into the it's place in the thread list
 	*/
 	trace(re, "\t\tkill %z: %s\n", re.thr[tid].uid, msg)
+	std.slfree(re.thr[tid].mstart)
+	std.slfree(re.thr[tid].mend)
 	std.free(re.thr[tid])
 	re.thr[tid] = re.thr[re.nthr - 1]
 	re.nthr--
--- a/main.myr
+++ b/main.myr
@@ -5,7 +5,7 @@
 	var found
 	match regex.compile("(a|b)*s*")
 	`std.Success re:
-		found = regex.exec(re, "ababaasssss")
+		found = regex.exec(re, "a")
 		std.put("Found = %t: len = %z\n", found, re.strp)
 		-> 0
 		;;