shithub: mc

Download patch

ref: b1b28999b0f574f815db036dd1ba8318fb1ec35a
parent: c66161595cd3e4638122777d550ab61dc100b973
author: Ori Bernstein <ori@markovcorp.com>
date: Tue Dec 26 07:35:18 EST 2017

Fix void slice formatting.

	Also cleans up agglomeration of unused variables.

--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -254,22 +254,6 @@
 
 const fallbackfmt = {sb, params, tyenc, ap : valist# -> void
 	/* value types */
-	var t_val : bool
-	var b_val : int8, ub_val : uint8
-	var w_val : int16, uw_val : uint16
-	var i_val : int32, ui_val : uint32
-	var l_val : int64, ul_val : uint64
-	var z_val : size
-	var p_val : byte#
-	var f_val : intptr[2]
-	var c_val : char
-	var s_val : byte[:]
-	var f32_val : flt32, f64_val : flt64
-	var i8 : int8, i16: int16, i32 : int32
-	var by : byte
-	var i : int, i64 : int64
-	var ui8 : int8, ui16: int16, ui32 : int32
-	var ui : int, ui64 : int64
 	var subap, subenc, subname
 	var inf, p
 
@@ -278,71 +262,72 @@
 	| `Tynone:
 	/* atomic types */
 	| `Tyvoid:
+		var val : void = vanext(ap)
 		sbputs(sb, "void")
 	| `Tybool:
-		t_val = vanext(ap)
-		if t_val
+		var val : bool = vanext(ap)
+		if val
 			sbputs(sb ,"true")
 		else
 			sbputs(sb, "false")
 		;;
 	| `Tychar:
-		c_val = vanext(ap)
-		sbputc(sb, c_val)
+		var val : char = vanext(ap)
+		sbputc(sb, val)
 	| `Tyint8:
-		b_val = vanext(ap)
-		intfmt(sb, intparams(params), true, b_val)
+		var val : int8 = vanext(ap)
+		intfmt(sb, intparams(params), true, val)
 	| `Tyint16:
-		w_val = vanext(ap)
-		intfmt(sb, intparams(params), true, w_val)
+		var val : int16 = vanext(ap)
+		intfmt(sb, intparams(params), true, val)
 	| `Tyint:
-		i_val = vanext(ap)
-		intfmt(sb, intparams(params), true, i_val)
+		var val : int = vanext(ap)
+		intfmt(sb, intparams(params), true, val)
 	| `Tyint32:
-		i_val = vanext(ap)
-		intfmt(sb, intparams(params), true, i_val)
+		var val : int32 = vanext(ap)
+		intfmt(sb, intparams(params), true, val)
 	| `Tyint64:
-		l_val = vanext(ap)
-		intfmt(sb, intparams(params), true, l_val)
+		var val : int64 = vanext(ap)
+		intfmt(sb, intparams(params), true, val)
 	| `Tybyte:
-		ub_val = vanext(ap)
-		intfmt(sb, intparams(params), false, ub_val)
+		var val : byte = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyuint8:
-		ub_val = vanext(ap)
-		intfmt(sb, intparams(params), false, ub_val)
+		var val : uint8 = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyuint16:
-		uw_val = vanext(ap)
-		intfmt(sb, intparams(params), false, uw_val)
+		var val : uint16 = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyuint:
-		ui_val = vanext(ap)
-		intfmt(sb, intparams(params), false, ui_val)
+		var val : uint = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyuint32:
-		ui_val = vanext(ap)
-		intfmt(sb, intparams(params), false, ui_val)
+		var val : uint32 = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyuint64:
-		ul_val = vanext(ap)
-		intfmt(sb, intparams(params), false, ul_val)
+		var val : uint64 = vanext(ap)
+		intfmt(sb, intparams(params), false, val)
 	| `Tyflt32:
-		f32_val = vanext(ap)
-		flt32bfmt(sb, f32_val, MNormal, 0)
+		var val : flt32 = vanext(ap)
+		flt32bfmt(sb, val, MNormal, 0)
 	| `Tyflt64:
-		f64_val = vanext(ap)
-		flt64bfmt(sb, f64_val, MNormal, 0)
+		var val : flt64 = vanext(ap)
+		flt64bfmt(sb, val, MNormal, 0)
 	| `Tyvalist:
 		sbputs(sb, "...")
 
 	/* compound types */
 	| `Typtr desc:
-		p_val = vanext(ap)
+		var val : void# = vanext(ap)
 		sbputs(sb, "0x")
 		intfmt(sb, \
 			[.base=16, .padto=2*sizeof(void#), .padfill='0'], \
-			false, (p_val : intptr))
+			false, (val : intptr))
 	| `Tyslice desc:
 		match typedesc(desc)
 		| `Tybyte:
-			s_val = vanext(ap)
-			strfmt(sb, s_val, params)
+			var val : byte[:] = vanext(ap)
+			strfmt(sb, val, params)
 		| _:
 			subap = vaenter(ap)
 			fmtslice(sb, subap, params)
@@ -349,15 +334,15 @@
 			vabytes(ap)
 		;;
 	| `Tyfunc tc:
-		f_val = vanext(ap)
+		var val : intptr[2] = vanext(ap)
 		sbputs(sb, "func{")
 		intfmt(sb, \
 			[.base=16, .padto=2*sizeof(void#), .padfill='0'], \
-			false, (f_val[0] : intptr))
+			false, (val[0] : intptr))
 		sbputs(sb, ", ")
 		intfmt(sb, \
 			[.base=16, .padto=2*sizeof(void#), .padfill='0'], \
-			false, (f_val[1] : intptr))
+			false, (val[1] : intptr))
 		sbputs(sb, "}")
 	| `Tyarray (sz, desc):
 		subap = vaenter(ap)
@@ -400,12 +385,13 @@
 		sbfmt(sb, "]")
 		vabytes(ap)
 	| `Tyunion nc:
+		var tag : int32
 		inf = typeinfo(tcpeek(&ap.tc))
 		p = (ap.args : size)
 		p = (p + inf.align - 1) & ~(inf.align - 1)
-		i_val = (p : int32#)#
-		subap = vaenterunion(ap, i_val)
-		for var i = 0; i < i_val; i++
+		tag = (p : int32#)#
+		subap = vaenterunion(ap, tag)
+		for var i = 0; i < tag; i++
 			ncnext(&nc)
 		;;
 		(subname, subenc) = ncnext(&nc)
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -39,6 +39,7 @@
 const builtins = {
 	var s : blah
 	var m : u
+	var v = [void, void][:]
 
 	/* basic types */
 	check("      abcd", "{w=10}", "abcd")
@@ -103,6 +104,10 @@
 	check("1,2,3 true", "{j=\\,} {}", [1,2,3][:], true)
 	check("1}2}3 true", "{j=\\}} {}", [1,2,3][:], true)
 	check("1... 2... 3 true", "{j=... } {}", [1,2,3][:], true)
+
+	check("[]", "{}", v[:0])
+	check("[void]", "{}", v[:1])
+	check("[void, void]", "{}", v[:2])
 }
 
 const installed = {