shithub: mc

Download patch

ref: 2907edc929cb7681744567214296ecc3c48699ce
parent: 6f329f4bad91511ade5355a473241d41332b6ad8
author: Ori Bernstein <[email protected]>
date: Tue Oct 29 19:05:41 EDT 2013

Clean up code a bit.

--- a/compile.myr
+++ b/compile.myr
@@ -220,7 +220,6 @@
 		/* Char matching. Consume exactly one byte from the string. */
 		| `Ibyte b:		std.put("`Ibyte %b (%c)\n", b, b castto(char)) 
 		| `Irange (start, end):	std.put("`Irange (%b,%b)\n", start, end) 
-		| `Idot:	std.put("`Idot\n") 
 		/* capture groups */
 		| `Ilbra m:		std.put("`Ilbra %z\n", m) 
 		| `Irbra m:		std.put("`Irbra %z\n", m) 
--- a/interp.myr
+++ b/interp.myr
@@ -39,7 +39,7 @@
 	;;
 	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, re.str[re.strp])
+			trace(re, re.thr[i], "\ntid=%z, ip=%z, c=b\n", re.thr[i].uid, re.thr[i].ip, re.str[re.strp])
 			step(re, i)
 		;;
 		if re.nthr > 0
@@ -59,7 +59,7 @@
 	match re.prog[thr.ip]
 	/* Char matching. Consume exactly one byte from the string. */
 	| `Ibyte b:
-		trace(re, "\t%z:\tByte %b\n", thr.ip, b)
+		trace(re, thr, "\t%z:\tByte %b\n", thr.ip, b)
 		if !in(re, str)
 			kill(re, tid, "end of string")
 		elif b != str[re.strp]
@@ -66,28 +66,21 @@
 			kill(re, tid, "not right char")
 		else
 			thr.ip++
-			trace(re, "\t\tmatched %b with %b\n", b, str[re.strp])
+			trace(re, thr, "\t\tmatched %b with %b\n", b, str[re.strp])
 		;;
 	| `Irange (start, end):
-		trace(re, "\t%z:\tRange (%b, %b)\t", thr.ip, start, end)
+		trace(re, thr, "\t%z:\tRange (%b, %b)\n", thr.ip, start, end)
 		if !in(re, str) || start > str[re.strp] || end < str[re.strp]
 			kill(re, tid, "bad range")
 		else
 			thr.ip++
 		;;
-	| `Idot:
-		trace(re, "\t%z:\tDot\n", thr.ip)
-		if in(re, str)
-			kill(re, tid, "past end")
-		else
-			thr.ip++
-		;;
 	/*
 	  Non-consuming. All of these recursively call step() until
 	  exactly one byte is consumed from the string.
 	 */
 	| `Ibol:
-		trace(re, "\t%z:\tBol\n", thr.ip)
+		trace(re, thr, "\t%z:\tBol\n", thr.ip)
 		if re.strp == 0 || str[re.strp - 1] == '\n' castto(byte)
 			thr.ip++
 			step(re, tid)
@@ -95,7 +88,7 @@
 			kill(re, tid, "not beginning of line")
 		;;
 	| `Ieol:
-		trace(re, "\t%z:\tEol\n", thr.ip)
+		trace(re, thr, "\t%z:\tEol\n", thr.ip)
 		if re.strp == str.len || str[re.strp] == '\n' castto(byte)
 			step(re, tid)
 		else
@@ -102,27 +95,27 @@
 			kill(re, tid, "not end of line")
 		;;
 	| `Ilbra m:
-		trace(re, "\t%z:\tLbra %z\n", thr.ip, m)
-		trace(re, "\t\tmatch start = %z\n", re.strp)
+		trace(re, thr, "\t%z:\tLbra %z\n", thr.ip, m)
+		trace(re, thr, "\t\tmatch start = %z\n", re.strp)
 		thr.mstart[m] = re.strp
 		thr.ip++
 		step(re, tid)
 	| `Irbra m:
-		trace(re, "\t%z:\tRbra %z\n", thr.ip, m)
+		trace(re, thr, "\t%z:\tRbra %z\n", thr.ip, m)
 		thr.mend[m] = re.strp
 		thr.ip++
 		step(re, tid)
 	| `Ifork (lip, rip):
-		trace(re, "\t%z:\tFork (%z, %z)\n", thr.ip, rip, lip)
+		trace(re, thr, "\t%z:\tFork (%z, %z)\n", thr.ip, lip, rip)
 		mstart = std.sldup(thr.mstart)
 		mend = std.sldup(thr.mend)
-		jmp(re, tid, rip)
-		fork(re, thr, lip, mstart, mend)
+		jmp(re, tid, lip)
+		fork(re, thr, rip, mstart, mend)
 	| `Ijmp ip:
-		trace(re, "\t%z:\tJmp %z\n", thr.ip, ip)
+		trace(re, thr, "\t%z:\tJmp %z\n", thr.ip, ip)
 		jmp(re, tid, ip)
 	| `Imatch:
-		trace(re, "\t%z:\tMatch\n", thr.ip)
+		trace(re, thr, "\t%z:\tMatch\n", thr.ip)
 		finish(re, tid)
 	;;
 }
@@ -166,7 +159,7 @@
 	   free the dying thread, and shuffle the last
 	   thread into the it's place in the thread list
 	*/
-	trace(re, "\t\tkill %z: %s\n", re.thr[tid].uid, msg)
+	trace(re, re.thr[tid], "\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])
@@ -175,7 +168,7 @@
 }
 
 const finish = {re, tid
-	trace(re, "finish\n", tid)
+	trace(re, re.thr[tid], "finish\n", tid)
 	match re.matched
 	| `std.None:
 	| `std.Some thr:	std.free(thr)
@@ -189,8 +182,9 @@
 	-> re.strp < str.len
 }
 
-const trace : (re : regex#, msg : byte[:], args : ...) = {re, msg, args
+const trace : (re : regex#, thr : rethread#, msg : byte[:], args : ...) = {re, thr, msg, args
 	if re.debug
+		std.put("\tthr %i: ", thr.uid)
 		std.putv(msg, std.vastart(&args))
 	;;
 }
--- a/main.myr
+++ b/main.myr
@@ -4,15 +4,13 @@
 const main = {
 	var found
 	match regex.compile(".*bc")
-	`std.Success re:
+	| `std.Success re:
 		found = regex.exec(re, "Abc")
 		std.put("Found = %t: len = %z\n", found, re.strp)
 		-> 0
-		;;
-	`std.Failure err:
+	| `std.Failure err:
 		std.put("failed to compile regex")
 		-> 1
-		;;
 	;;
 }
 
--- a/types.myr
+++ b/types.myr
@@ -36,7 +36,6 @@
 		/* direct consumers */
 		`Ibyte	byte
 		`Irange	[byte, byte]
-		`Idot
 
 		/* groups */
 		`Ilbra	std.size