shithub: mc

Download patch

ref: 8d7247af269b3b0ef283f3b01f31980f686ae217
parent: 9b864a2bc7fbdae40704708a6893e6f29ad48397
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jan 29 04:25:26 EST 2019

Remove pointless call overhead and casting.

--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -14,7 +14,7 @@
 ;;
 
 type valist = struct
-	args	: byte#
+	args	: intptr
 	tc	: typecursor
 ;;
 
@@ -28,7 +28,7 @@
  * force varargs onto the stack regardless.
  */
 const vastart = {args
-	var tc, a, ip
+	var tc, a
 
 	/*
 	pull out the args. These are on the stacks like so:
@@ -47,8 +47,7 @@
 	*/
 		
 	tc = typeenc(args)
-	ip = (args : intptr) + sizeof(byte#)
-	a = (ip : byte#)
+	a = (args : intptr) + sizeof(byte#)
 	-> [.args = a, .tc = tc]
 }
 
@@ -68,25 +67,21 @@
 }
 
 const cursoralign = {arg, ty
-	var ti, align, p
+	var ti, align
 
 	ti = typeinfo(ty)
 
 	/* apply the alignment to the arg pointer */
 	align = (ti.align : intptr)
-	p = (arg : intptr)
-	p = (p + align - 1) & ~(align - 1)
-	-> (p : byte#)
+	-> (arg + align - 1) & ~(align - 1)
 }
 
 const vaenterunion = {ap, elt
-	var sub, ti, p, align
+	var sub, ti, align
 
 	ti = typeinfo(tcpeek(&ap.tc))
 	align = (ti.align : intptr)
-	p = (ap.args : intptr)
-	p = (p + align - 1) & ~(align - 1)
-	ap.args = (p : byte#)
+	ap.args = (ap.args + align - 1) & ~(align - 1)
 	match typedesc(vatype(ap))
 	| `Tyunion nc:	
 		for var i = 0; i < elt; i++
@@ -93,7 +88,7 @@
 			ncnext(&nc)
 		;;
 		(_, sub) = ncnext(&nc)
-		-> [.args=addp(ap.args, 4), .tc=typeenccursor(sub)]
+		-> [.args=ap.args + 4, .tc=typeenccursor(sub)]
 	| t:	std.die("type is not a union\n")
 	;;
 }
@@ -103,56 +98,44 @@
 }
 
 const vabytes = {ap
-	var sl
-	var ti, align, sz
-	var p
+	var sl, ti, align, p
 
 	ti = typeinfo(tcpeek(&ap.tc))
 
 	/* apply the alignment to the arg pointer */
 	align = (ti.align : intptr)
-	p = (ap.args : intptr)
-	p = (p + align - 1) & ~(align - 1)
-	ap.args = (p : byte#)
+	p = (ap.args + align - 1) & ~(align - 1)
 
-	sl = ap.args[:ti.size]
+	sl = (ap.args : byte#)[:ti.size]
 	tcnext(&ap.tc)
 
-	sz = (ti.size : intptr)
-	ap.args = ((p : intptr) + sz : byte#)
+	ap.args = p + (ti.size : intptr)
 
 	-> sl
 }
 
 generic vanext = {ap -> @a
-	var ti
-	var align
-	var p
+	var ti, align, p
 
 	ti = typeinfo(tcpeek(&ap.tc))
 
 	/* apply the alignment to the arg pointer */
 	align = (ti.align : intptr)
-	p = (ap.args : intptr)
-	p = (p + align - 1) & ~(align - 1)
+	p = (ap.args + align - 1) & ~(align - 1)
 
 	/* TODO: check for type mismatch */
 	tcnext(&ap.tc)
 	/* only move on after we read through the value */
-	ap.args = ((p : intptr) + sizeof(@a) : byte#)
+	ap.args = p + sizeof(@a)
 	-> (p : @a#)#
 }
 
-const addp = {p, k
-	-> ((p : intptr) + k  : byte#)
-}
-
 const sliceptr = {pp
 	var p
 
 	p = (pp : intptr)
 	p = (p + 0x7) & ~0x7
-	-> (p : byte##)#
+	-> (p : intptr#)#
 }
 
 const slicelen = {pp