diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-02-09 02:50:03 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-02-09 03:09:25 -0500 |
| commit | fc100d7b3b27bd514dca4e02c160e5b96d4da648 (patch) | |
| tree | b365fbdf02c7a35d81d9037a15e1e3917a6e77de /src/analyze.cpp | |
| parent | 8a859afd580f438f549ee69a3e3487eb5d119fad (diff) | |
| download | zig-fc100d7b3b27bd514dca4e02c160e5b96d4da648.tar.gz zig-fc100d7b3b27bd514dca4e02c160e5b96d4da648.zip | |
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
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 7fd1fee675..984fa32a83 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3439,7 +3439,8 @@ void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue * void render_const_value(Buf *buf, ConstExprValue *const_val) { switch (const_val->special) { case ConstValSpecialRuntime: - zig_unreachable(); + buf_appendf(buf, "(runtime value)"); + return; case ConstValSpecialUndef: buf_appendf(buf, "undefined"); return; @@ -3522,7 +3523,28 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) { } case TypeTableEntryIdArray: { + TypeTableEntry *child_type = canon_type->data.array.child_type; uint64_t len = canon_type->data.array.len; + + // if it's []u8, assume UTF-8 and output a string + if (child_type->id == TypeTableEntryIdInt && + child_type->data.integral.bit_count == 8 && + !child_type->data.integral.is_signed) + { + buf_append_char(buf, '"'); + for (uint64_t i = 0; i < len; i += 1) { + ConstExprValue *child_value = &const_val->data.x_array.elements[i]; + uint64_t x = child_value->data.x_bignum.data.x_uint; + if (x == '"') { + buf_append_str(buf, "\\\""); + } else { + buf_append_char(buf, x); + } + } + buf_append_char(buf, '"'); + return; + } + buf_appendf(buf, "%s{", buf_ptr(&canon_type->name)); for (uint64_t i = 0; i < len; i += 1) { if (i != 0) |
