summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-07 09:36:04 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-07 09:36:04 -0700
commit41a66f79ac8284bbffb9820deb8655b6bdda1c9b (patch)
tree1e867ca3a5ffe98bf4b132ad0c7160b6ecbb1117 /libstd
parentac965251351332f405c9e5390e00d436fa467ff4 (diff)
downloadmc-41a66f79ac8284bbffb9820deb8655b6bdda1c9b.tar.gz
Add vabytes() function.
This gets an arbitrary blob with the type data.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/fmt2.myr5
-rw-r--r--libstd/varargs.myr38
2 files changed, 30 insertions, 13 deletions
diff --git a/libstd/fmt2.myr b/libstd/fmt2.myr
index 19e5d27..41423c3 100644
--- a/libstd/fmt2.myr
+++ b/libstd/fmt2.myr
@@ -272,11 +272,14 @@ const fallbackfmt = {sb, params, tyenc, ap : valist# -> void
sbputs(sb, "array")
/* aggregate types */
| `Tytuple typecursor:
+ vabytes(ap)
sbputs(sb, "tuple")
| `Tystruct namecursor:
+ vabytes(ap)
sbputs(sb, "struct")
| `Tyunion namecursor:
- sbputs(sb, "struct")
+ vabytes(ap)
+ sbputs(sb, "union")
| `Tyname (name, desc):
fallbackfmt(sb, params, desc, ap)
;;
diff --git a/libstd/varargs.myr b/libstd/varargs.myr
index bb44345..e0948a6 100644
--- a/libstd/varargs.myr
+++ b/libstd/varargs.myr
@@ -8,7 +8,7 @@ pkg std =
const vastart : (args : ...# -> valist)
const vatype : (ap : valist# -> byte[:])
- const vaskip : (ap : valist# -> byte[:])
+ const vabytes : (ap : valist# -> byte[:])
generic vanext : (ap : valist# -> @a)
;;
@@ -55,24 +55,38 @@ const vatype = {ap
-> tcpeek(&ap.tc)
}
+const vabytes = {ap
+ var sl
+ var ti, align, sz
+ var p
+
+ ti = typeinfo(tcpeek(&ap.tc))
+
+ /* apply the alignment to the arg pointer */
+ align = ti.align castto(intptr)
+ p = ap.args castto(intptr)
+ p = (p + align - 1) & ~(align - 1)
+ ap.args = p castto(byte#)
+
+ sl = ap.args[:ti.size]
+ tcnext(&ap.tc)
+
+ sz = ti.size castto(intptr)
+ ap.args = ((p castto(intptr)) + sz) castto(byte#)
+
+ -> sl
+}
+
generic vanext = {ap -> @a
var v : @a
+ var ti
var align
var p
- /*
- Assumptions about the ABI:
- * all types smaller than a word are
- * aligned to their own size. Larger
- * types are aligned to word size.
- */
- if sizeof(@a) > 8
- align = 8
- else
- align = sizeof(@a)
- ;;
+ ti = typeinfo(tcpeek(&ap.tc))
/* apply the alignment to the arg pointer */
+ align = ti.align castto(intptr)
p = ap.args castto(intptr)
p = (p + align - 1) & ~(align - 1)
ap.args = p castto(byte#)