shithub: mc

Download patch

ref: f507c7ee81391e004d492d1095ca4263d3ee1830
parent: 363389e2b3fc56ad52922dc1903ca96129a3f5ed
author: Ori Bernstein <[email protected]>
date: Tue Oct 22 10:53:19 EDT 2013

Don't grab the first character when creating.

    We end up not incrementing the string when stepping, and this
    is bad.

--- a/compile.myr
+++ b/compile.myr
@@ -47,6 +47,7 @@
 		gen(re, t)
 		append(re, `Imatch)
 		idump(re)
+		-> `std.Success re
 		;;
 	;;
 	-> `std.Failure (`Noimpl)
--- a/interp.myr
+++ b/interp.myr
@@ -12,13 +12,16 @@
 	re.str = str
 	re.strp = 0
 	re.matched = `std.None
-	spawn(re, 0)
+	mkthread(re, 0)
+	std.put("tid %z, ip %z, strp %z\n", re.thr[0].uid, re.thr[0].ip, re.strp)
 	while re.nthr > 0
 		for i = 0; i < re.nthr; i++
+			std.put("Switch to %i\n", i)
 			std.put("tid %z, ip %z, strp %z\n", re.thr[i].uid, re.thr[i].ip, re.strp)
 			step(re, i)
 		;;
 		if re.nthr > 0
+			std.put("Step forward\n")
 			re.strp++
 		;;
 	;;
@@ -37,7 +40,11 @@
 	match re.prog[thr.ip]
 	/* Char matching. Consume exactly one byte from the string. */
 	`Ibyte b:
-		if !in(re, str) || b != str[re.strp]
+		if !in(re, str)
+			kill(re, tid, "end of string")
+		elif b != str[re.strp]
+			std.put("re.strp: %i\n", re.strp)
+			std.put("\tb: %b (%c), str[re.strp]: %b (%c)\n", b, b castto(char), str[re.strp], str[re.strp] castto(char))
 			kill(re, tid, "not right char")
 		else
 			std.put("matched %b with %b\n", b, str[re.strp])
@@ -78,7 +85,8 @@
 }
 
 var uid = 0
-const spawn = {re, ip
+
+const mkthread = {re, ip
 	var thr : rethread#
 	var tid
 
@@ -94,7 +102,11 @@
 
 	re.thr[re.nthr] = thr
 	re.nthr++
-	step(re, tid)
+	-> tid
+}
+
+const spawn = {re, ip
+	step(re, mkthread(re, ip))
 }
 
 const kill = {re, tid, msg
--- a/main.myr
+++ b/main.myr
@@ -2,12 +2,17 @@
 use std
 
 const main = {
-	regex.compile("a+")
-	/*
-	var re
 	var found
-	found = regex.exec(re, "aaa")
-	std.put("Found: len = %z\n", re.strp, found)
-	*/
+	match regex.compile("foolish")
+	`std.Success re:
+		found = regex.exec(re, "foolish")
+		std.put("Found = %t: len = %z\n", found, re.strp)
+		-> 0
+		;;
+	`std.Failure err:
+		std.put("failed to compile regex")
+		-> 1
+		;;
+	;;
 }