shithub: mc

Download patch

ref: 3b5584581a79cec899c7f6a5233529a64a22ab5f
parent: cf50193c7dc0c13d373d60982e7cb95168e0167e
author: S. Gilles <sgilles@math.umd.edu>
date: Sat Sep 7 08:50:50 EDT 2019

Collect fltXYbfmt parameters into analogue of intparams

--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -14,14 +14,19 @@
 	pkglocal const MAbsolute = 1
 	pkglocal const MRelative = 2
 
-	pkglocal const flt64bfmt	: (sb : strbuf#, val : flt64, mode : int, precision : int -> void)
-	pkglocal const flt32bfmt	: (sb : strbuf#, val : flt32, mode : int, precision : int -> void)
+	pkglocal type fltparams = struct
+		mode	: int
+		prec	: int
+	;;
+
+	pkglocal const flt64bfmt	: (sb : strbuf#, opts : fltparams, val : flt64 -> void)
+	pkglocal const flt32bfmt	: (sb : strbuf#, opts : fltparams, val : flt32 -> void)
 ;;
 
 const Dblbias = 1023
 const Fltbias = 127
 
-const flt64bfmt = {sb, val, mode, precision
+const flt64bfmt = {sb, opts, val
 	var isneg, exp, mant
 
 	if isnan(val)
@@ -41,10 +46,10 @@
 	;;
 
 	exp = max(exp, 1 - Dblbias)
-	dragon4(sb, isneg, mant, exp - 52, Dblbias, mode, precision)
+	dragon4(sb, isneg, mant, exp - 52, Dblbias, opts.mode, opts.prec)
 }
 
-const flt32bfmt = {sb, val, mode, precision
+const flt32bfmt = {sb, opts, val
 	var isneg, exp, mant
 
 	if isnan(val)
@@ -64,7 +69,7 @@
 	;;
 
 	exp = (max((exp : int64), 1 - Fltbias) : int32)
-	dragon4(sb, isneg, (mant : uint64), (exp - 23 : int64), Fltbias, mode, precision)
+	dragon4(sb, isneg, (mant : uint64), (exp - 23 : int64), Fltbias, opts.mode, opts.prec)
 }
 
 /*
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -315,10 +315,10 @@
 		intfmt(sb, intparams(params), false, (val : uint64), 64)
 	| `Tyflt32:
 		var val : flt32 = vanext(ap)
-		flt32bfmt(sb, val, MNormal, 0)
+		flt32bfmt(sb, fltparams(params), val)
 	| `Tyflt64:
 		var val : flt64 = vanext(ap)
-		flt64bfmt(sb, val, MNormal, 0)
+		flt64bfmt(sb, fltparams(params), val)
 	| `Tyvalist:
 		sbputs(sb, "...")
 
@@ -446,6 +446,27 @@
 	if !joined
 		sbputs(sb, "]")
 	;;
+}
+
+const fltparams = {params
+	var fp : fltparams
+
+	fp = [
+		.mode = MNormal,
+		.prec = 0,
+	]
+
+	for p : params
+		match p
+		| (opt, arg):
+			std.write(2, "fmt: ")
+			std.write(2, opt)
+			std.write(2, "arg: ")
+			std.write(2, arg)
+			std.die("\nunreachable\n")
+		;;
+	;;
+	-> fp
 }
 
 type intparams = struct