summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-04-03 13:59:34 -0400
committerOri Bernstein <ori@eigenstate.org>2013-04-03 13:59:34 -0400
commit480b380507201923c5b0d4e8610499e23ee2bea6 (patch)
treece6d8e2283e3bf09b8ff9e674874e1468c7d1828
parentc4b6a1c57ece9e02c05f046f4dd472f6d8c6ec6b (diff)
downloadmc-480b380507201923c5b0d4e8610499e23ee2bea6.tar.gz
Add fatal() and fatalv() functions.
This means that we needed a putv() variant of put().
-rw-r--r--libstd/fmt.myr27
-rw-r--r--libstd/sys-linux.myr4
-rw-r--r--parse/infer.c2
3 files changed, 25 insertions, 8 deletions
diff --git a/libstd/fmt.myr b/libstd/fmt.myr
index ca77d28..4b2f51a 100644
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -19,17 +19,34 @@ use "extremum.use"
*/
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
}
diff --git a/libstd/sys-linux.myr b/libstd/sys-linux.myr
index e5aef80..70732c9 100644
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -371,7 +371,7 @@ pkg std =
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 @@ pkg std =
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)}
diff --git a/parse/infer.c b/parse/infer.c
index e58c4dd..0c6dbd5 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -780,7 +780,7 @@ static void inferpat(Inferstate *st, Node *n, Node *val, Node ***bind, size_t *n
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);