ref: b3b854e034d8822a8507aa3c199f77661b179218
parent: 1a7acb7c8d47f0145351a90d1781ba6ad1d60cde
author: Ori Bernstein <[email protected]>
date: Thu Aug 16 13:37:18 EDT 2012
Add comments.
--- a/alloc.myr
+++ b/alloc.myr
@@ -6,7 +6,7 @@
generic alloc : ( -> @a*)
generic free : (v:@a* -> void)
- generic mkslice : (n : size -> @a[:])
+ generic mkslice : (len : size -> @a[:])
generic freeslice: (sl : @a[:] -> void)
const bytealloc : (sz:size -> byte*)
@@ -53,11 +53,11 @@
bytefree(v castto(byte*), sizeof(@a))
}
-generic mkslice = {n
+generic mkslice = {len
var p
- p = bytealloc(n*sizeof(@a)) castto(@a*)
- -> p[0:n]
+ p = bytealloc(len*sizeof(@a)) castto(@a*)
+ -> p[0:len]
}
generic freeslice = {sl
--- a/varargs.myr
+++ b/varargs.myr
@@ -9,6 +9,15 @@
type valist = byte*
+/*
+ * a valist is really just a pointer to the varargs.
+ * we assume that these sit on the stack nicely,
+ * and don't need special handling to get to.
+ *
+ * This will be a problem when we switch to a
+ * register based convention. We might want to
+ * force varargs onto the stack regardless.
+ */
const vastart = {args
-> args castto(valist)
}
@@ -18,6 +27,12 @@
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
@@ -24,6 +39,7 @@
align = sizeof(@a)
;;
+ /* apply the alignment to the arg pointer */
p = ap castto(intptr)
p = (p + align - 1) & ~(align - 1)
ap = p castto(valist)
@@ -30,6 +46,7 @@
v = *(ap castto(@a*))
+ /* only move on after we read through the value */
ap = ((p castto(intptr)) + sizeof(@a)) castto(valist)
-> (v, ap)
}