diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-19 17:17:28 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-19 17:22:12 -0400 |
commit | 1c8c80a7e0014a350da59a8e34e499ec1f241b6d (patch) | |
tree | 727ba0fe8ab793c9fd9f2355a9f27e4afbf59d48 | |
parent | b79c4e942dba34ee1b2e5ce907629c7f77f88f07 (diff) |
fixing some for loop stuff
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | misc.c | 7 | ||||
-rw-r--r-- | test.toc | 13 | ||||
-rw-r--r-- | types.c | 6 |
4 files changed, 12 insertions, 20 deletions
@@ -8,14 +8,8 @@ /* TODO: -allow annotating index type -things to check: - for x := x {} - for x: x = "hey" {} - for x:3+"foo" { a := x; } replace weird EXPR_FOR system with just a declaration- would make "for use p := points" easier. need to fix: - - cgen.c - eval.c - copy.c consider: don't do inference for function calls; get rid of was_expr -- now that we have struct params @@ -59,4 +59,9 @@ static inline bool strs_equal(const char *a, const char *b) { } #define plural_suffix(x) ((x) == 1 ? "" : "s") - +static char const *indefinite_article(char const *s) { + /* usually, words starting with "u" use "a" - "a unique thing", "a u64" */ + if (*s == 'a' || *s == 'e' || *s == 'i' || *s == 'o') + return "an"; + return "a"; +} @@ -1,15 +1,6 @@ #include "std/io.toc"; main ::= fn() { - a : [5][]char; - for x, i : (&[]char, u8) = &a { - *x = "foo"; - } - for y : []char = a { - puts(y); - } - for x, i := a { - puti(i); - puts(x); - } + for x : 3 = "foo" { a := x; } + } @@ -856,7 +856,9 @@ static Status type_resolve(Typer *tr, Type *t, Location where) { } } if (!is_tuple_of_types) { - err_print(expr->where, "This expression is not a type, but it's being used as one."); + char *s = type_to_str(&expr->type); + err_print(expr->where, "This expression is not a type (it's %s %s), but it's being used as a type.", indefinite_article(s), s); + free(s); return false; } } @@ -1583,7 +1585,7 @@ static Status types_expr(Typer *tr, Expression *e) { if (header->flags & DECL_ANNOTATES_TYPE) { Type *header_type = &header->type; if (!type_resolve(tr, header_type, header->where)) - return false; + goto for_fail; if (annotated_index) { if (header_type->kind != TYPE_TUPLE || arr_len(header_type->tuple) != 2) { char *s = type_to_str(header_type); |