shithub: mc

ref: 95ef4b736bceda8dde3f907e15c084a727317c12
dir: /varargs.myr/

View raw version
use "types.use"

pkg std =
	type valist

	const vastart	: (args : ...* -> valist)
	generic vanext	: (ap : valist -> [@a, valist])
;;

type valist = byte*

const vastart = {args
	-> args castto(valist)
}

generic vanext = {ap -> [@a, valist]
	var v : @a
	var align
	var p

	if sizeof(@a) > 8
		align = 8
	else
		align = sizeof(@a)
	;;

	p = ap castto(intptr)
	p = (p + align - 1) & ~(align - 1)
	ap = p castto(valist)

	v = *(ap castto(@a*))

	ap = ((p castto(intptr)) + sizeof(@a)) castto(valist)
	-> (v, ap)
}