summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-04-19 17:17:28 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-04-19 17:22:12 -0400
commit1c8c80a7e0014a350da59a8e34e499ec1f241b6d (patch)
tree727ba0fe8ab793c9fd9f2355a9f27e4afbf59d48
parentb79c4e942dba34ee1b2e5ce907629c7f77f88f07 (diff)
fixing some for loop stuff
-rw-r--r--main.c6
-rw-r--r--misc.c7
-rw-r--r--test.toc13
-rw-r--r--types.c6
4 files changed, 12 insertions, 20 deletions
diff --git a/main.c b/main.c
index d37938b..cd74872 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/misc.c b/misc.c
index f11c755..c38996f 100644
--- a/misc.c
+++ b/misc.c
@@ -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";
+}
diff --git a/test.toc b/test.toc
index cb0b448..1ce3f12 100644
--- a/test.toc
+++ b/test.toc
@@ -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; }
+
}
diff --git a/types.c b/types.c
index 9c83a87..9e07bc0 100644
--- a/types.c
+++ b/types.c
@@ -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);