shithub: mc

Download patch

ref: 58a13c39b7f3e6ab0bf950908e98b9f0dfb7c951
parent: de1eabd91024f360845dfe7382581e0acbc368e1
author: S. Gilles <sgilles@umd.edu>
date: Sun Jun 7 01:17:13 EDT 2020

Unify alignment for heterogeneous tuples.

This only appears to come into play when trying to match memory layout
of tuples with structs, or when accessing deeply nested tuples.

--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -331,7 +331,7 @@
 		break;
 	case Tytuple:
 		for (i = 0; i < ty->nsub; i++)
-			align = max(align, tyalign(ty->sub[0]));
+			align = max(align, tyalign(ty->sub[i]));
 		break;
 	case Tyunion:
 		align = 4;
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -58,7 +58,7 @@
 	ty = vatype(ap)
 	match typedesc(ty)
 	| `Tyslice enc:	-> [.args=sliceptr(ap.args), .tc=[.nelt=slicelen(ap.args), .rem=enc, .isiter=false]]
-	| `Tytuple tc:	-> [.args=ap.args, .tc=tc]
+	| `Tytuple tc:	-> [.args=cursoralign(ap.args, ty), .tc=tc]
 	| `Tystruct tc:	-> [.args=cursoralign(ap.args, ty), .tc=tc]
 	| `Tyarray (sz, enc):	-> [.args=ap.args, .tc=[.nelt=sz, .rem=enc, .isiter=false]]
 	| `Tyname (name, enc):	-> [.args=ap.args, .tc=typeenccursor(enc)]
--- /dev/null
+++ b/test/fmtnest.myr
@@ -1,0 +1,18 @@
+use std
+
+type foo = struct
+        f2 : uint8
+        f3 : (uint8, flt64)
+;;
+
+const main = {
+        var f : foo = [  .f2 = 2, .f3 = (3, 4.4) ]
+        var str = std.fmt("{}", f)
+        for var j = 0; j < str.len; ++j
+                /* Try not to accidentally create any shell characters */
+                if str[j] == ('(' : byte) || str[j] == (')' : byte) || str[j] == ('[' : byte) || str[j] == (']' : byte) || str[j] == (' ' : byte) || str[j] == ('=' : byte)
+                        str[j] = ('_' : byte)
+                ;;
+        ;;
+        std.put("{}\n", str)
+}
--- a/test/tests
+++ b/test/tests
@@ -176,5 +176,6 @@
 B nestedgoto	E	0
 B initializer	E	0
 B fmtalign	E	0
+B fmtnest	P	_.f2_2,_.f3__3,_4.4__
 B implexpr	P	12,z,hello
 B implexpr-concrete	P	zigzag