shithub: mc

Download patch

ref: 8ccd239d70ff98001c857e8ebf8fb509b64477d4
parent: e12f1d5c28797ee73fba56e4adf86a40491fc779
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 17 07:21:08 EDT 2017

Misc 9front fixes.

--- a/lib/std/syswrap+plan9.myr
+++ b/lib/std/syswrap+plan9.myr
@@ -6,7 +6,6 @@
 use "result"
 use "cstrconv"
 use "strfind"
-use "getint"
 use "syswrap-ss"
 
 pkg std =
@@ -136,7 +135,7 @@
 	if sys.stat(path, buf[:]) < Stringsoff
 		-> `Err Emisc
 	;;
-	-> `Ok (getle32(buf[Mtimeoff:Mtimeoff + 8]) : time)
+	-> `Ok (_getle32(buf[Mtimeoff:Mtimeoff + 8]) : time)
 }
 
 const fsize = {path
@@ -145,7 +144,7 @@
 	if sys.stat(path, buf[:]) < Stringsoff
 		-> `Err Emisc
 	;;
-	-> `Ok (getle64(buf[Lengthoff:Lengthoff + 8]) : off)
+	-> `Ok (_getle64(buf[Lengthoff:Lengthoff + 8]) : off)
 }
 
 extern const put : (fmt : byte[:], args : ... -> int64)
@@ -155,7 +154,7 @@
 	if sys.stat(path, buf[:]) < Stringsoff
 		-> false
 	;;
-	-> (getle32(buf[Modeoff:Modeoff + 4]) & sys.Dmdir) != 0
+	-> (_getle32(buf[Modeoff:Modeoff + 4]) & sys.Dmdir) != 0
 }
 
 const fisreg = {path
@@ -166,8 +165,8 @@
 		-> false
 	;;
 
-	ty = getle16(buf[Typeoff:Typeoff + 2])
-	if (getle32(buf[Modeoff:Modeoff + 4]) & sys.Dmdir) != 0
+	ty = _getle16(buf[Typeoff:Typeoff + 2])
+	if (_getle32(buf[Modeoff:Modeoff + 4]) & sys.Dmdir) != 0
 		-> false
 	/* ugh. maybe this call should just be '!fisdir()' */
 	elif ty == '|' || ty == 's' || ty == 'm'
@@ -221,6 +220,8 @@
 	-> lasterr()
 }
 
+
+
 /* memory stuff */
 const getmem	= {sz
 	var endp, oldp
@@ -266,4 +267,28 @@
 	else
 		-> `Ok (e : @b)
 	;;
+}
+
+/* duplicated code to break dependency cycle */
+generic _getle16 = {buf
+	-> ((buf[0] : @a::(numeric,integral)) << 0) | \
+		((buf[1] : @a::(numeric,integral)) << 8)
+}
+
+generic _getle32 = {buf
+	-> ((buf[0] : @a::(numeric,integral)) << 0) | \
+		((buf[1] : @a::(numeric,integral)) << 8) | \
+		((buf[2] : @a::(numeric,integral)) << 16) | \
+		((buf[3] : @a::(numeric,integral)) << 24)
+}
+
+generic _getle64 = {buf
+	-> ((buf[0] : @a::(numeric,integral))  << 0) | \
+		((buf[1] : @a::(numeric,integral))  << 8) | \
+		((buf[2] : @a::(numeric,integral))  << 16) | \
+		((buf[3] : @a::(numeric,integral))  << 24) | \
+		((buf[4] : @a::(numeric,integral))  << 32) | \
+		((buf[5] : @a::(numeric,integral))  << 40) | \
+		((buf[6] : @a::(numeric,integral))  << 48) | \
+		((buf[7] : @a::(numeric,integral))  << 56)
 }
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -146,6 +146,7 @@
 	const segflush	: (va : void#, len : uint32 -> int64)
 	const unmount	: (name : byte[:], old : byte[:] -> int64)
 	const errstr	: (buf : byte[:] -> int64)
+	const _errstr	: (buf : byte[:] -> int64)
 	const stat	: (name : byte[:], edir : byte[:] -> int64)
 	const fstat	: (fd : fd, edir : byte[:] -> int64)
 	const wstat	: (name : byte[:], edir : byte[:] -> int64)
@@ -207,7 +208,7 @@
 const segfree	= {va, len;	-> syscall(Syssegfree, a(va), a(len))}
 const segflush	= {va, len;	-> syscall(Syssegfree, a(va), a(len))}
 const unmount	= {name, old;	-> syscall(Sysunmount, cstring(name), cstring(old))}
-const errstr	= {buf;		-> syscall(Syserrstr, p(buf), a(buf.len))}
+const _errstr	= {buf;		-> syscall(Syserrstr, p(buf), a(buf.len))}
 const stat	= {name, edir;	-> syscall(Sysstat, cstring(name), p(edir), a(edir.len))}
 const fstat	= {fd, edir;	-> syscall(Sysstat, a(fd), p(edir), a(edir.len))}
 const wstat	= {name, edir;	-> syscall(Syswstat, cstring(name), p(edir), a(edir.len))}
@@ -236,6 +237,23 @@
 	cargs[args.len] = (0 : byte#)
 	-> syscall(Sysexec, cstring(bin), a(cargs))
 }
+
+const errstr = {eb
+	var tmp : byte[128]
+	var n
+
+	n = 128
+	if eb.len < tmp.len
+		n = eb.len
+	;;
+	_errstr(tmp[:])
+	for var i = 0; i < n; i++
+		eb[i] = tmp[i]
+	;;
+	_errstr(tmp[:])
+	-> 0
+}
+	
 
 /*const fversion	= {fd, bufsz, vers, nvers;	-> syscall(Sysfversion, fd, bufsz, }*/
 const semacquire	= {addr, block; -> (syscall(Syssemacquire, a(addr), a(block)) : int)}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -109,7 +109,7 @@
 	if (n->type == Nexpr && exprtype(n) != NULL)
 		t = tyfix(st, NULL, exprtype(n), 1);
 	else if (n->type == Ndecl && decltype(n) != NULL)
-		t = tyfix(st, NULL, decltype(n), 1);
+		t = tyfix(st, n, decltype(n), 1);
 
 	if (t && tybase(t)->type != Tyvar)
 		return tystr(t);