shithub: mc

Download patch

ref: 480b380507201923c5b0d4e8610499e23ee2bea6
parent: c4b6a1c57ece9e02c05f046f4dd472f6d8c6ec6b
author: Ori Bernstein <[email protected]>
date: Wed Apr 3 09:59:34 EDT 2013

Add fatal() and fatalv() functions.

    This means that we needed a putv() variant of put().

--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -19,17 +19,34 @@
 */
 
 pkg std =
-	const bfmt	: (buf : byte[:], fmt : byte[:], args:... -> size)
-	const bfmtv	: (buf : byte[:], fmt : byte[:], ap:valist -> size)
-	const put	: (fmt : byte[:], args:... -> size)
+	const bfmt	: (buf : byte[:], fmt : byte[:], args : ... -> size)
+	const bfmtv	: (buf : byte[:], fmt : byte[:], ap : valist -> size)
+	const put	: (fmt : byte[:], args : ... -> size)
+	const putv	: (fmt : byte[:], ap : valist -> size)
+	const fatal	: (status : int, fmt : byte[:], args : ... -> void)
+	const fatalv	: (status : int, fmt : byte[:], ap : valist -> void)
 ;;
 
-/* Writes a string of text up to 2 kb in size to stdout */
+const fatal = {status, fmt, args
+	putv(fmt, vastart(&args))
+	exit(status)
+}
+
+const fatalv = {status, fmt, ap
+	putv(fmt, ap)
+	exit(status)
+}
+
 const put = {fmt, args
+	-> putv(fmt, vastart(&args))
+}
+
+/* Writes a string of text up to 2 kb in size to stdout */
+const putv = {fmt, ap
 	var buf : byte[2048]
 	var n
 	
-	n = bfmtv(buf[:], fmt, vastart(&args))
+	n = bfmtv(buf[:], fmt, ap)
 	write(1, buf[:n])
 	-> n
 }
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -371,7 +371,7 @@
 	extern const syscall : (sc:scno, args:... -> int64)
 	extern const cstring : (str : byte[:] -> byte#)
 
-	const exit	: (status:int64 -> void)
+	const exit	: (status:int -> void)
 	const getpid	: ( -> int64)
 	const kill	: (pid:int64, sig:int64 -> int64)
 	const open	: (path:byte[:], opts:fdopt, mode:int64 -> int64)
@@ -385,7 +385,7 @@
 	const mmap	: (addr:byte#, len:size, prot:mprot, flags:mopt, fd:int64, off:off -> byte#)
 ;;
 
-const exit	= {status;		syscall(Sysexit, 1)}
+const exit	= {status;		syscall(Sysexit, status castto(int64))}
 const getpid	= {;			-> syscall(Sysgetpid, 1)}
 const kill	= {pid, sig;		-> syscall(Syskill, pid, sig)}
 const open	= {path, opts, mode;	-> syscall(Sysopen, cstring(path), opts, mode)}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -780,7 +780,7 @@
                 else if (s->decl.isconst)
                     t = s->decl.type;
                 else
-                    fatal(n->line, "Can't match against variables in nterns near %s", ctxstr(st, n));
+                    fatal(n->line, "Can't match against non-constant variables near %s", ctxstr(st, n));
             } else {
                 t = mktyvar(n->line);
                 s = mkdecl(n->line, n->expr.args[0], t);