| author | |
| committer | |
| log | ff3cdbc3a078de1d54c13737264ed62f77ff1f50 |
| tree | b2ff8f1a46a40a39268153b6f0971e6ee5403817 |
| parent | 4ad7d09ba5f6f021cb6b6c2045e26fe252f61a27 |
| signature | Commit is signed but in an unrecognized format. |
8 files changed, 37 insertions(+), 12 deletions(-)
src-self-hosted/stage1.zig+4| ... | @@ -25,3 +25,7 @@ export fn stage2_zen(ptr: *[*]const u8, len: *usize) void { | ... | @@ -25,3 +25,7 @@ export fn stage2_zen(ptr: *[*]const u8, len: *usize) void { |
| 25 | ptr.* = &info_zen; | 25 | ptr.* = &info_zen; |
| 26 | len.* = info_zen.len; | 26 | len.* = info_zen.len; |
| 27 | } | 27 | } |
| 28 | |||
| 29 | export fn stage2_panic(ptr: [*]const u8, len: usize) void { | ||
| 30 | @panic(ptr[0..len]); | ||
| 31 | } |
src/buffer.hpp-1| ... | @@ -10,7 +10,6 @@ | ... | @@ -10,7 +10,6 @@ |
| 10 | 10 | ||
| 11 | #include "list.hpp" | 11 | #include "list.hpp" |
| 12 | 12 | ||
| 13 | #include <assert.h> | ||
| 14 | #include <stdint.h> | 13 | #include <stdint.h> |
| 15 | #include <ctype.h> | 14 | #include <ctype.h> |
| 16 | #include <stdarg.h> | 15 | #include <stdarg.h> |
src/error.hpp+1-5| ... | @@ -8,8 +8,6 @@ | ... | @@ -8,8 +8,6 @@ |
| 8 | #ifndef ERROR_HPP | 8 | #ifndef ERROR_HPP |
| 9 | #define ERROR_HPP | 9 | #define ERROR_HPP |
| 10 | 10 | ||
| 11 | #include <assert.h> | ||
| 12 | |||
| 13 | enum Error { | 11 | enum Error { |
| 14 | ErrorNone, | 12 | ErrorNone, |
| 15 | ErrorNoMem, | 13 | ErrorNoMem, |
| ... | @@ -56,8 +54,6 @@ enum Error { | ... | @@ -56,8 +54,6 @@ enum Error { |
| 56 | 54 | ||
| 57 | const char *err_str(Error err); | 55 | const char *err_str(Error err); |
| 58 | 56 | ||
| 59 | static inline void assertNoError(Error err) { | 57 | #define assertNoError(err) assert((err) == ErrorNone); |
| 60 | assert(err == ErrorNone); | ||
| 61 | } | ||
| 62 | 58 | ||
| 63 | #endif | 59 | #endif |
src/list.hpp-2| ... | @@ -10,8 +10,6 @@ | ... | @@ -10,8 +10,6 @@ |
| 10 | 10 | ||
| 11 | #include "util.hpp" | 11 | #include "util.hpp" |
| 12 | 12 | ||
| 13 | #include <assert.h> | ||
| 14 | |||
| 15 | template<typename T> | 13 | template<typename T> |
| 16 | struct ZigList { | 14 | struct ZigList { |
| 17 | void deinit() { | 15 | void deinit() { |
src/userland.cpp+17-3| ... | @@ -2,9 +2,23 @@ | ... | @@ -2,9 +2,23 @@ |
| 2 | // src-self-hosted/stage1.zig | 2 | // src-self-hosted/stage1.zig |
| 3 | 3 | ||
| 4 | #include "userland.h" | 4 | #include "userland.h" |
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | void stage2_translate_c(void) { | ||
| 10 | const char *msg = "stage0 called stage2_translate_c"; | ||
| 11 | stage2_panic(msg, strlen(msg)); | ||
| 12 | } | ||
| 5 | 13 | ||
| 6 | void stage2_translate_c(void) {} | ||
| 7 | void stage2_zen(const char **ptr, size_t *len) { | 14 | void stage2_zen(const char **ptr, size_t *len) { |
| 8 | *ptr = nullptr; | 15 | const char *msg = "stage0 called stage2_zen"; |
| 9 | *len = 0; | 16 | stage2_panic(msg, strlen(msg)); |
| 17 | } | ||
| 18 | |||
| 19 | void stage2_panic(const char *ptr, size_t len) { | ||
| 20 | fwrite(ptr, 1, len, stderr); | ||
| 21 | fprintf(stderr, "\n"); | ||
| 22 | fflush(stderr); | ||
| 23 | abort(); | ||
| 10 | } | 24 | } |
src/userland.h+2| ... | @@ -20,4 +20,6 @@ ZIG_USERLAND_EXTERN_C void stage2_translate_c(void); | ... | @@ -20,4 +20,6 @@ ZIG_USERLAND_EXTERN_C void stage2_translate_c(void); |
| 20 | 20 | ||
| 21 | ZIG_USERLAND_EXTERN_C void stage2_zen(const char **ptr, size_t *len); | 21 | ZIG_USERLAND_EXTERN_C void stage2_zen(const char **ptr, size_t *len); |
| 22 | 22 | ||
| 23 | ZIG_USERLAND_EXTERN_C void stage2_panic(const char *ptr, size_t len); | ||
| 24 | |||
| 23 | #endif | 25 | #endif |
src/util.cpp+9-1| ... | @@ -10,17 +10,25 @@ | ... | @@ -10,17 +10,25 @@ |
| 10 | #include <stdarg.h> | 10 | #include <stdarg.h> |
| 11 | 11 | ||
| 12 | #include "util.hpp" | 12 | #include "util.hpp" |
| 13 | #include "userland.h" | ||
| 13 | 14 | ||
| 14 | void zig_panic(const char *format, ...) { | 15 | void zig_panic(const char *format, ...) { |
| 15 | va_list ap; | 16 | va_list ap; |
| 16 | va_start(ap, format); | 17 | va_start(ap, format); |
| 17 | vfprintf(stderr, format, ap); | 18 | vfprintf(stderr, format, ap); |
| 18 | fprintf(stderr, "\n"); | ||
| 19 | fflush(stderr); | 19 | fflush(stderr); |
| 20 | va_end(ap); | 20 | va_end(ap); |
| 21 | stage2_panic(nullptr, 0); | ||
| 21 | abort(); | 22 | abort(); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 25 | void assert(bool ok) { | ||
| 26 | if (!ok) { | ||
| 27 | const char *msg = "Assertion failed. This is a bug in the Zig compiler."; | ||
| 28 | stage2_panic(msg, strlen(msg)); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 24 | uint32_t int_hash(int i) { | 32 | uint32_t int_hash(int i) { |
| 25 | return (uint32_t)(i % UINT32_MAX); | 33 | return (uint32_t)(i % UINT32_MAX); |
| 26 | } | 34 | } |
src/util.hpp+4| ... | @@ -48,6 +48,10 @@ void zig_panic(const char *format, ...); | ... | @@ -48,6 +48,10 @@ void zig_panic(const char *format, ...); |
| 48 | 48 | ||
| 49 | #define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__) | 49 | #define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__) |
| 50 | 50 | ||
| 51 | // Assertions in stage1 are always on, and they call zig @panic. | ||
| 52 | #undef assert | ||
| 53 | void assert(bool ok); | ||
| 54 | |||
| 51 | #if defined(_MSC_VER) | 55 | #if defined(_MSC_VER) |
| 52 | static inline int clzll(unsigned long long mask) { | 56 | static inline int clzll(unsigned long long mask) { |
| 53 | unsigned long lz; | 57 | unsigned long lz; |