diff options
| -rw-r--r-- | builtins/array.h | 4 | ||||
| -rw-r--r-- | builtins/functions.c | 8 | ||||
| -rw-r--r-- | builtins/table.h | 2 |
3 files changed, 8 insertions, 6 deletions
diff --git a/builtins/array.h b/builtins/array.h index 8884f794..84edcb41 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -10,8 +10,8 @@ // Convert negative indices to back-indexed without branching: index0 = index + (index < 0)*(len+1)) - 1 #define $Array_get(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \ int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \ - if (__builtin_expect($off < 0 && $off >= $arr->length, 0)) \ - fail("Invalid array index: %ld (array has length %ld)", $index, $arr->length); \ + if (__builtin_expect($off < 0 || $off >= $arr->length, 0)) \ + fail("Invalid array index: %ld (array has length %ld)\n", $index, $arr->length); \ *(type*)($arr->data + $arr->stride * $off);}) #define $Array_get_unchecked(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \ int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \ diff --git a/builtins/functions.c b/builtins/functions.c index 4a29af40..4ca91d3e 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -20,11 +20,13 @@ extern bool USE_COLOR; public const char *SSS_HASH_VECTOR = "sss hash vector ----------------------------------------------";; -public void fail(const char *fmt, ...) +public void fail(CORD fmt, ...) { va_list args; va_start(args, fmt); - vfprintf(stderr, fmt, args); + if (USE_COLOR) fputs("\x1b[31;7m FAIL: \x1b[m ", stderr); + else fputs("FAIL: ", stderr); + CORD_vfprintf(stderr, fmt, args); va_end(args); raise(SIGABRT); } @@ -145,7 +147,7 @@ public void __doctest(void *expr, TypeInfo *type, CORD expected, const char *fil if (!success) { if (filename && file) fprint_span(stderr, file, file->text+start, file->text+end, "\x1b[31;1m", 2, USE_COLOR); - fail(USE_COLOR ? "\x1b[31;1mExpected: \x1b[32;7m%s\x1b[0m\n\x1b[31;1m But got: \x1b[31;7m%s\x1b[0m\n" : "Expected: %s\n But got: %s\n", + fail(USE_COLOR ? "\x1b[31;1mDoctest failure:\nExpected: \x1b[32;7m%s\x1b[0m\n\x1b[31;1m But got: \x1b[31;7m%s\x1b[0m\n" : "Doctest failure:\nExpected: %s\n But got: %s\n", expected, expr_str); } } diff --git a/builtins/table.h b/builtins/table.h index 3f93da32..69d0aad9 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -21,7 +21,7 @@ #define $Table_get(table_expr, key_t, val_t, key_expr, info_expr) ({ \ const table_t *$t = table_expr; key_t $k = key_expr; const TypeInfo* $info = info_expr; \ const val_t *$v = Table_get($t, &$k, $info); \ - if (__builtin_expect($v == NULL, 0)) fail("The key %r is not in this table", generic_as_str(&$k, no, $info->TableInfo.key)); \ + if (__builtin_expect($v == NULL, 0)) fail("The key %r is not in this table\n", generic_as_str(&$k, USE_COLOR, $info->TableInfo.key)); \ *$v; }) |
