ref: 68a78ecc802088dfb7cdd1c477a4fa6340442b7b
parent: 2b3703665ad5e6c602c35394404f46972bc90b8d
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Dec 29 16:27:31 EST 2015
Fix union alignment. vaenter() doesn't know how to enter unions, since it doesn't know which sub-element to take. Hack around it with 'vaenterunion'.
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -384,8 +384,8 @@
sbfmt(sb, "]")
vabytes(ap)
| `Tyunion nc:
- subap = vaenter(ap)
i_val = (ap.args castto(int32#))#
+ subap = vaenterunion(ap, i_val)
for var i = 0; i < i_val; i++
ncnext(&nc)
;;
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -10,6 +10,7 @@
const vatype : (ap : valist# -> byte[:])
const vabytes : (ap : valist# -> byte[:])
const vaenter : (ap : valist# -> valist)
+ const vaenterunion : (ap : valist#, elt : int32 -> valist)
generic vanext : (ap : valist# -> @a)
;;
@@ -52,15 +53,29 @@
-> [.args = a, .tc = tc]
}
+extern const put : (fmt : byte[:], args : ... -> size)
const vaenter = {ap
match typedesc(vatype(ap))
| `Tyslice enc: -> [.args=sliceptr(ap.args), .tc=[.nelt=slicelen(ap.args), .rem=enc, .isiter=false]]
| `Tytuple tc: -> [.args=ap.args, .tc=tc]
| `Tystruct tc: -> [.args=ap.args, .tc=tc]
- | `Tyunion tc: -> [.args=addp(ap.args, 4), .tc=tc]
| `Tyarray (sz, enc): -> [.args=ap.args, .tc=[.nelt=sz, .rem=enc, .isiter=false]]
| `Tyname (name, enc): -> [.args=ap.args, .tc=typeenccursor(enc)]
- | _: std.die("unable to enter type")
+ | _: std.die("unable to enter type\n")
+ ;;
+}
+
+const vaenterunion = {ap, elt
+ var sub
+
+ match typedesc(vatype(ap))
+ | `Tyunion nc:
+ for var i = 0; i < elt; i++
+ ncnext(&nc)
+ ;;
+ (_, sub) = ncnext(&nc)
+ -> [.args=addp(ap.args, 4), .tc=typeenccursor(sub)]
+ | t: std.die("type is not a union\n")
;;
}