aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compile/declarations.c5
-rw-r--r--src/compile/functions.c7
-rw-r--r--src/parse/text.c1
-rw-r--r--src/stdlib/c_strings.c3
-rw-r--r--src/stdlib/files.c8
-rw-r--r--src/stdlib/fpconv.c3
-rw-r--r--src/stdlib/lists.c1
-rw-r--r--src/stdlib/paths.c3
-rw-r--r--src/stdlib/stdlib.c4
-rw-r--r--src/stdlib/text.c11
-rw-r--r--src/tomo.c6
-rw-r--r--src/types.c1
12 files changed, 22 insertions, 31 deletions
diff --git a/src/compile/declarations.c b/src/compile/declarations.c
index f1c59f73..3b80bade 100644
--- a/src/compile/declarations.c
+++ b/src/compile/declarations.c
@@ -36,10 +36,7 @@ Text_t compile_declared_value(env_t *env, ast_t *declare_ast) {
if (decl->value) {
Text_t val_code = compile_maybe_incref(env, decl->value, t);
- if (t->tag == FunctionType) {
- assert(promote(env, decl->value, &val_code, t, Type(ClosureType, t)));
- t = Type(ClosureType, t);
- }
+ if (t->tag == FunctionType) assert(promote(env, decl->value, &val_code, t, Type(ClosureType, t)));
return val_code;
} else {
Text_t val_code = compile_empty(t);
diff --git a/src/compile/functions.c b/src/compile/functions.c
index e1b9c89a..757df073 100644
--- a/src/compile/functions.c
+++ b/src/compile/functions.c
@@ -787,13 +787,6 @@ Text_t compile_function(env_t *env, Text_t name_code, ast_t *ast, Text_t *static
Text_t qualified_name = Text$from_str(function_name);
if (env->namespace && env->namespace->parent && env->namespace->name)
qualified_name = Texts(env->namespace->name, ".", qualified_name);
- Text_t text = Texts("func ", qualified_name, "(");
- for (arg_ast_t *arg = args; arg; arg = arg->next) {
- text = Texts(text, type_to_text(get_arg_ast_type(env, arg)));
- if (arg->next) text = Texts(text, ", ");
- }
- if (ret_t && ret_t->tag != VoidType) text = Texts(text, "->", type_to_text(ret_t));
- text = Texts(text, ")");
return definition;
}
diff --git a/src/parse/text.c b/src/parse/text.c
index 6f032c4c..7650955c 100644
--- a/src/parse/text.c
+++ b/src/parse/text.c
@@ -116,7 +116,6 @@ static ast_list_t *_parse_text_helper(parse_ctx_t *ctx, const char **out_pos) {
if (chunk.length > 0) {
ast_t *literal = NewAST(ctx->file, chunk_start, pos, TextLiteral, .text = chunk);
chunks = new (ast_list_t, .ast = literal, .next = chunks);
- chunk = EMPTY_TEXT;
}
REVERSE_LIST(chunks);
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index 2946ce58..54ea1e40 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -28,7 +28,8 @@ PUREFUNC public int32_t CString$compare(const void *x, const void *y, const Type
if (!*(const char **)x != !*(const char **)y) return (!*(const char **)y) - (!*(const char **)x);
- return strcmp(*(const char **)x, *(const char **)y);
+ const char *x_str = *(const char **)x, *y_str = *(const char **)y;
+ return (x_str == NULL) || (y_str == NULL) ? (x_str != NULL) - (y_str != NULL) : strcmp(x_str, y_str);
}
PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_t *type) {
diff --git a/src/stdlib/files.c b/src/stdlib/files.c
index 7fd4c2c7..88d78676 100644
--- a/src/stdlib/files.c
+++ b/src/stdlib/files.c
@@ -110,9 +110,11 @@ static file_t *_load_file(const char *filename, FILE *file) {
// Convert to relative path (if applicable)
char buf[PATH_MAX];
char *cwd = getcwd(buf, sizeof(buf));
- size_t cwd_len = strlen(cwd);
- if (strncmp(cwd, filename, cwd_len) == 0 && filename[cwd_len] == '/')
- ret->relative_filename = &filename[cwd_len + 1];
+ if (cwd != NULL) {
+ size_t cwd_len = strlen(cwd);
+ if (strncmp(cwd, filename, cwd_len) == 0 && filename[cwd_len] == '/')
+ ret->relative_filename = &filename[cwd_len + 1];
+ }
}
return ret;
}
diff --git a/src/stdlib/fpconv.c b/src/stdlib/fpconv.c
index 0781295d..eaae959a 100644
--- a/src/stdlib/fpconv.c
+++ b/src/stdlib/fpconv.c
@@ -117,7 +117,6 @@ static Fp multiply(Fp *a, Fp *b) {
static void round_digit(char *digits, int ndigits, uint64_t delta, uint64_t rem, uint64_t kappa, uint64_t frac) {
while (rem < frac && delta - rem >= kappa && (rem + kappa < frac || frac - rem > rem + kappa - frac)) {
-
digits[ndigits - 1]--;
rem += kappa;
}
@@ -153,7 +152,6 @@ static int generate_digits(Fp *fp, Fp *upper, Fp *lower, char *digits, int *K) {
if (tmp <= delta) {
*K += kappa;
round_digit(digits, idx, delta, tmp, div << -one.exp, wfrac);
-
return idx;
}
}
@@ -175,7 +173,6 @@ static int generate_digits(Fp *fp, Fp *upper, Fp *lower, char *digits, int *K) {
if (part2 < delta) {
*K += kappa;
round_digit(digits, idx, delta, part2, one.frac, wfrac * *unit);
-
return idx;
}
diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c
index 516f37e2..db514671 100644
--- a/src/stdlib/lists.c
+++ b/src/stdlib/lists.c
@@ -156,7 +156,6 @@ void List$insert_all(List_t *list, List_t to_insert, Int_t int_index, int64_t pa
if (list->stride == padded_item_size) {
memcpy(p, list->data + padded_item_size * (index - 1),
(size_t)(((int64_t)list->length - index + 1) * padded_item_size));
- p += ((int64_t)list->length - index + 1) * padded_item_size;
} else {
for (int64_t i = index - 1; i < (int64_t)list->length - 1; i++) {
memcpy(p, list->data + list->stride * i, (size_t)padded_item_size);
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index b6152ed4..76d0d629 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -130,7 +130,8 @@ Path_t Path$_concat(int n, Path_t items[n]) {
public
Path_t Path$resolved(Path_t path, Path_t relative_to) {
- if (path.type == PATHTYPE_RELATIVE && !(relative_to.type == PATHTYPE_RELATIVE && relative_to.components.length == 0)) {
+ if (path.type == PATHTYPE_RELATIVE
+ && !(relative_to.type == PATHTYPE_RELATIVE && relative_to.components.length == 0)) {
Path_t result = {.type = relative_to.type};
result.components = relative_to.components;
LIST_INCREF(result.components);
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c
index 0756eab3..5204194b 100644
--- a/src/stdlib/stdlib.c
+++ b/src/stdlib/stdlib.c
@@ -59,7 +59,8 @@ static _Noreturn void signal_handler(int sig, siginfo_t *info, void *userdata) {
public
void tomo_init(void) {
GC_INIT();
- USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO);
+ const char *color_env = getenv("COLOR");
+ USE_COLOR = color_env ? strcmp(color_env, "1") == 0 : isatty(STDOUT_FILENO);
if (getenv("NO_COLOR") && getenv("NO_COLOR")[0] != '\0') USE_COLOR = false;
setlocale(LC_ALL, "");
@@ -194,6 +195,7 @@ OptionalText_t ask(Text_t prompt, bool bold, bool force_tty) {
cleanup:
if (out && out != stdout) fclose(out);
if (in && in != stdin) fclose(in);
+ if (line != NULL) free(line);
return ret;
}
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 0f40aef9..a91490e6 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -224,17 +224,18 @@ int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_len) {
// synthetic graphemes store all of their information in a densely packed
// area with good cache locality:
static void *arena = NULL, *arena_end = NULL;
- // Eat up any space needed to make arena 32-bit aligned:
- if ((size_t)arena % __alignof__(ucs4_t) != 0) arena += __alignof__(ucs4_t) - ((size_t)arena % __alignof__(ucs4_t));
+ if (arena != NULL && (size_t)arena % __alignof__(ucs4_t) != 0)
+ arena += __alignof__(ucs4_t) - ((size_t)arena % __alignof__(ucs4_t));
// If we have filled up this arena, allocate a new one:
size_t needed_memory = sizeof(ucs4_t[1 + utf32_len]) + sizeof(uint8_t[u8_len + 1]);
- if (arena + needed_memory > arena_end) {
+ if (arena == NULL || arena + needed_memory > arena_end) {
// Do reasonably big chunks at a time, so most synthetic codepoints are
// nearby each other in memory and cache locality is good. This is a
// rough guess at a good size:
size_t chunk_size = MAX(needed_memory, 512);
arena = GC_MALLOC_ATOMIC(chunk_size);
+ assert(arena != NULL);
arena_end = arena + chunk_size;
}
@@ -497,9 +498,8 @@ static Text_t concat2(Text_t a, Text_t b) {
if (first_b < 0) {
memcpy(dest, GRAPHEME_CODEPOINTS(first_b), sizeof(ucs4_t[NUM_GRAPHEME_CODEPOINTS(first_b)]));
- dest += NUM_GRAPHEME_CODEPOINTS(first_b);
} else {
- *(dest++) = (ucs4_t)first_b;
+ *dest = (ucs4_t)first_b;
}
// Do a normalization run for these two codepoints and see if it looks different.
@@ -582,7 +582,6 @@ static Text_t Text$repeat_to_width(Text_t to_repeat, int64_t target_width, Text_
int64_t w = (int64_t)u8_strwidth((const uint8_t *)Text$as_c_string(c), lang_str);
if (repeated_width + w > target_width) {
repeated = concat2(repeated, Text$repeat(Text(" "), I(target_width - repeated_width)));
- repeated_width = target_width;
break;
}
repeated = concat2(repeated, c);
diff --git a/src/tomo.c b/src/tomo.c
index 0bddb426..46076ba2 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -136,8 +136,10 @@ int main(int argc, char *argv[]) {
ldlibs = Texts(ldlibs, Text(" -lexecinfo"));
#endif
- USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO);
- if (getenv("NO_COLOR") && getenv("NO_COLOR")[0] != '\0') USE_COLOR = false;
+ const char *color_env = getenv("COLOR");
+ USE_COLOR = color_env ? strcmp(color_env, "1") == 0 : isatty(STDOUT_FILENO);
+ const char *no_color_env = getenv("NO_COLOR");
+ if (no_color_env && no_color_env[0] != '\0') USE_COLOR = false;
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
arc4random_buf(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY));
diff --git a/src/types.c b/src/types.c
index d08755a2..33c5e55b 100644
--- a/src/types.c
+++ b/src/types.c
@@ -428,7 +428,6 @@ PUREFUNC size_t unpadded_struct_size(type_t *t) {
}
if (bit_offset > 0) {
size += 1;
- bit_offset = 0;
}
return size;
}