lots of miscellaneous things all in one big commit

* add `@compileLog(...)` builtin function
   - Helps debug code running at compile time
   - See #240
 * fix crash when there is an error on the start value of a slice
 * add implicit cast from int and float types to int and float
   literals if the value is known at compile time
 * make array concatenation work with slices in addition to
   arrays and c string literals
 * fix compile error message for something not having field access
 * fix crash when `@setDebugSafety()` was called from a
   function being evaluated at compile-time
 * fix compile-time evaluation of overflow math builtins.
 * avoid debug safety panic handler in builtin.o and compiler_rt.o
   since we use no debug safety in these modules anyway
 * add compiler_rt functions for division on ARM
   - Closes #254
 * move default panic handler to std.debug so users can
   call it manually
 * std.io.printf supports a width in the format specifier
This commit is contained in:
Andrew Kelley
2017-02-09 02:50:03 -05:00
parent 8a859afd58
commit fc100d7b3b
15 changed files with 622 additions and 78 deletions

View File

@@ -13,6 +13,27 @@ pub fn assert(ok: bool) {
if (!ok) @unreachable()
}
var panicking = false;
/// This is the default panic implementation.
pub coldcc fn panic(message: []const u8) -> unreachable {
// TODO
// if (@atomicRmw(AtomicOp.XChg, &panicking, true, AtomicOrder.SeqCst)) { }
if (panicking) {
// Panicked during a panic.
// TODO detect if a different thread caused the panic, because in that case
// we would want to return here instead of calling abort, so that the thread
// which first called panic can finish printing a stack trace.
os.abort();
} else {
panicking = true;
}
%%io.stderr.printf("{}\n", message);
%%printStackTrace();
os.abort();
}
pub fn printStackTrace() -> %void {
%return writeStackTrace(&io.stderr);
%return io.stderr.flush();