shithub: mc

Download patch

ref: 06eda1f65daa7508f1a5e269f234046287b95c93
parent: 3ec885ae37703028d40d8308bfe1a017307a5e4e
parent: 5045a7db15fc9cee696c319889b1f81e464b12a3
author: Ori Bernstein <[email protected]>
date: Sat Jan 25 10:51:38 EST 2014

Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc

--- a/libstd/floatbits.myr
+++ b/libstd/floatbits.myr
@@ -3,8 +3,58 @@
 	const float32bits	: (flt : float32 -> uint32)
 	const float64frombits	: (bits : uint64 -> float64)
 	const float32frombits	: (bits : uint32 -> float32)
+	const float64explode	: (flt : float64 -> [bool, uint64, int32])
+	const float32explode	: (flt : float64 -> [bool, uint64, int32])
 ;;
+
 const float64bits	= {flt;	-> (&flt castto(uint64#))#}
 const float32bits	= {flt;	-> (&flt castto(uint32#))#}
 const float64frombits	= {bits;	-> (&bits castto(float64#))#}
 const float32frombits	= {bits;	-> (&bits castto(float32#))#}
+
+const float64explode = {flt
+	var bits, isneg, mant, exp
+
+	bits = float64bits(flt)
+	isneg = (bits >> 63) == 0  	/* msb is sign bit */
+	exp = (bits >> 52) & 0x7ff 	/* exp is in bits [52..63] */
+	mant = bits & ((1ul << 52) - 1) /* msb is in bits [..51] */
+
+	/* add back the implicit bit if this is not a denormal */
+	if exp != 0
+		mant |= 1ul << 52
+	else
+		exp = 1
+	;;
+	/*
+	   adjust for exponent bias. nb: because we are
+	   treating the mantissa as m.0 instead of 0.m,
+	   our exponent bias needs to be offset by the
+	   size of m
+	*/
+	-> (isneg, mant, (exp castto(int32)) - 1075)
+}
+
+const float32explode = {flt
+	var bits, isneg, mant, exp
+
+	bits = float64bits(flt) castto(uint64)
+	isneg = (bits >> 31) == 0  	/* msb is sign bit */
+	exp = (bits >> 22) & 0xff 	/* exp is in bits [23..30] */
+	mant = bits & ((1ul << 52) - 1) /* msb is in bits [0..22] */
+
+	/* add back the implicit bit if this is not a denormal */
+	if exp != 0
+		mant |= 1ul << 22
+	else
+		exp = 1
+	;;
+	/*
+	   adjust for exponent bias. nb: because we are
+	   treating the mantissa as m.0 instead of 0.m,
+	   our exponent bias needs to be offset by the
+	   size of m
+	*/
+	-> (isneg, mant, (exp castto(int32)) - 149)
+}
+
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -142,11 +142,11 @@
 	var f_val : float64, F_val : float32
 
 	n = 0
-	base = 10
-	signed = true
 	while fmt.len
 		(c, fmt) = striter(fmt)
 		if c == '%'
+			base = 10
+			signed = true
 			(c, fmt) = striter(fmt)
 			/* modifiers */
 			if fmt.len > 0
--- /dev/null
+++ b/test/emptytrait.myr
@@ -1,0 +1,14 @@
+use std
+
+trait fooable @a =
+;;
+impl fooable int
+
+generic foo = {x : @a::fooable
+	-> x
+}
+
+const main = {
+	std.exit(foo(123))
+}
+
--- a/test/tests
+++ b/test/tests
@@ -72,6 +72,7 @@
 B generic	E	42
 B genericval	E	42
 B trait-builtin	E	42
+# E emptytrait	E	123	## BUGGERED
 B nestucon	P	asdf
 B mkunion	E	0
 B genericcall	E	42