[PATCH 1/9] Unify alignment for heterogeneous tuples.
[Thread Prev] | [Thread Next]
- Subject: [PATCH 1/9] Unify alignment for heterogeneous tuples.
- From: "S. Gilles" <sgilles@xxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Mon, 8 Jun 2020 00:21:08 -0400
- To: "myrddin-dev" <myrddin-dev@xxxxxxxxxxxxxx>
- Cc: "S. Gilles" <sgilles@xxxxxxx>
This only appears to come into play when trying to match memory layout
of tuples with structs, or when accessing deeply nested tuples.
---
6/typeinfo.c | 2 +-
lib/std/varargs.myr | 2 +-
test/fmtnest.myr | 18 ++++++++++++++++++
test/tests | 1 +
4 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 test/fmtnest.myr
diff --git a/6/typeinfo.c b/6/typeinfo.c
index c7bed274..f7ec797d 100644
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -331,7 +331,7 @@ tyalign(Type *ty)
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;
diff --git a/lib/std/varargs.myr b/lib/std/varargs.myr
index 90c29451..7a5e0360 100644
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -58,7 +58,7 @@ const vaenter = {ap
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)]
diff --git a/test/fmtnest.myr b/test/fmtnest.myr
new file mode 100644
index 00000000..1d1d5f23
--- /dev/null
+++ b/test/fmtnest.myr
@@ -0,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)
+}
diff --git a/test/tests b/test/tests
index 20b67fe9..cb496e15 100644
--- a/test/tests
+++ b/test/tests
@@ -176,5 +176,6 @@ B destructuretup E 0
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
--
2.26.2
| [PATCH 0/9] Handle small-aggregates via AMD64 abi | "S. Gilles" <sgilles@xxxxxxx> |
- Prev by Date: [PATCH 0/9] Handle small-aggregates via AMD64 abi
- Next by Date: [PATCH 2/9] Add isaggregate for later use with abi conformity.
- Previous by thread: [PATCH 0/9] Handle small-aggregates via AMD64 abi
- Next by thread: [PATCH 2/9] Add isaggregate for later use with abi conformity.
- Index(es):