summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c10
-rw-r--r--parse.c29
-rw-r--r--test.toc26
-rw-r--r--tokenizer.c2
-rw-r--r--types.c2
-rw-r--r--types.h2
6 files changed, 37 insertions, 34 deletions
diff --git a/main.c b/main.c
index bfb3b50..004a5a2 100644
--- a/main.c
+++ b/main.c
@@ -1,19 +1,19 @@
/*
TODO:
-test ArrInt @= Arr(int);
-make sure fn(t @ Type, x : t) t works
-check fn(x @ int, y := x)
+test ArrInt ::= Arr(int);
+make sure fn(t :: Type, x : t) t works
+check fn(x :: int, y := x)
new version of copy_val for copying types??
there are probably places where we enter a function and never exit (in typing?) if there's an error
switch struct."field" to struct["field"]
packages
-X @= newtype(int); or something
+X ::= newtype(int); or something
don't allow while {3; 5} (once break is added)
any odd number of "s for a string
make sure futurely/currently-declared types are only used by pointer/slice
-allow omission of trailing ; in foo @= fn() {}?
+allow omission of trailing ; in foo ::= fn() {}?
*/
#ifdef __cplusplus
diff --git a/parse.c b/parse.c
index 0a1b5a9..d066959 100644
--- a/parse.c
+++ b/parse.c
@@ -192,10 +192,10 @@ static size_t type_to_str_(Type *t, char *buffer, size_t bufsize) {
switch (t->fn.constness[i]) {
case CONSTNESS_NO: break;
case CONSTNESS_SEMI:
- written += str_copy(buffer + written, bufsize - written, ":@");
+ written += str_copy(buffer + written, bufsize - written, ":::");
break;
case CONSTNESS_YES:
- written += str_copy(buffer + written, bufsize - written, "@");
+ written += str_copy(buffer + written, bufsize - written, "::");
break;
}
}
@@ -1122,7 +1122,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
}
}
- if (token_is_kw(t->token, KW_AT)) {
+ if (token_is_kw(t->token, KW_COLONCOLON)) {
tokr_err(t, "The variable(s) in a for loop cannot be constant.");
return false;
}
@@ -1735,18 +1735,19 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla
}
if (token_is_kw(t->token, KW_COLON)) {
t->token++;
- if (token_is_kw(t->token, KW_AT) && (flags & PARSE_DECL_ALLOW_SEMI_CONST)) {
- t->token++;
- d->flags |= DECL_SEMI_CONST;
- }
break;
}
- if (token_is_kw(t->token, KW_AT)) {
- d->flags |= DECL_IS_CONST;
+ if (token_is_kw(t->token, KW_COLONCOLON)) {
t->token++;
+ if (token_is_kw(t->token, KW_COLON) && (flags & PARSE_DECL_ALLOW_SEMI_CONST)) {
+ t->token++;
+ d->flags |= DECL_SEMI_CONST;
+ } else {
+ d->flags |= DECL_IS_CONST;
+ }
break;
}
- tokr_err(t, "Expected ',' to continue listing variables or ':' / '@' to indicate type.");
+ tokr_err(t, "Expected ',' to continue listing variables or ':' / '::' to indicate type.");
goto ret_false;
}
@@ -1809,7 +1810,7 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla
if ((d->flags & DECL_IS_CONST) && !(d->flags & DECL_HAS_EXPR) && !(flags & PARSE_DECL_ALLOW_CONST_WITH_NO_EXPR)) {
t->token--;
- /* disallowed constant without an expression, e.g. x @ int; */
+ /* disallowed constant without an expression, e.g. x :: int; */
tokr_err(t, "You must have an expression at the end of this constant declaration.");
goto ret_false;
}
@@ -1828,7 +1829,7 @@ static bool is_decl(Tokenizer *t) {
if (token->kind != TOKEN_IDENT) return false;
token++;
if (token->kind != TOKEN_KW) return false;
- if (token->kw == KW_COLON || token->kw == KW_AT)
+ if (token->kw == KW_COLON || token->kw == KW_COLONCOLON)
return true;
if (token->kw != KW_COMMA) return false;
token++;
@@ -2164,7 +2165,9 @@ static void fprint_decl(FILE *out, Declaration *d) {
fprint_ident(out, *ident);
}
if (d->flags & DECL_IS_CONST) {
- fprintf(out, "@");
+ fprintf(out, "::");
+ } else if (d->flags & DECL_SEMI_CONST) {
+ fprintf(out, ":::");
} else {
fprintf(out, ":");
}
diff --git a/test.toc b/test.toc
index 43db0c9..0cb9375 100644
--- a/test.toc
+++ b/test.toc
@@ -1,21 +1,21 @@
-puti @= fn(x: int) {
+puti ::= fn(x: int) {
#C("printf(\"%ld\\n\", (long)x);
");
};
-// putf @= fn(x: float) {
+// putf ::= fn(x: float) {
// #C("printf(\"%f\\n\", (double)x);
// ");
// };
-Arr @= fn (t @ Type) Type {
+Arr ::= fn (t :: Type) Type {
struct {
data : []t;
len, cap : int;
}
};
-// todo: test that t @ type doesn't cause problems
-arr_add @= fn(t @ Type, a : &Arr(t), x : t) {
+// todo: test that t :: type doesn't cause problems
+arr_add ::= fn(t :: Type, a : &Arr(t), x : t) {
if a.len >= a.cap {
a.cap = a.cap * 2 + 2;
new_data := new(t, a.cap);
@@ -30,24 +30,24 @@ arr_add @= fn(t @ Type, a : &Arr(t), x : t) {
-main @= fn() {
+main ::= fn() {
arr : Arr(int);
- arr_add(int, &arr, 5);
- arr_add(int, &arr, 10);
- arr_add(int, &arr, 20);
+ each i := 1..100 {
+ arr_add(int, &arr, i*i);
+ }
each i := 0..arr.len - 1 {
puti(arr.data[i]);
}
};
-// t @= fn(x @ Type) Type { struct { t: x; } };
+// t ::= fn(x :: Type) Type { struct { t: x; } };
// // pass the wrong thing to t, and the error is in the wrong place
-// f @= fn(x: t(int)) {};
+// f ::= fn(x: t(int)) {};
-// f @= fn(t @ Type, x : t) {
+// f ::= fn(t :: Type, x : t) {
// };
-// main @= fn() {
+// main ::= fn() {
// f(int,3);
// }; \ No newline at end of file
diff --git a/tokenizer.c b/tokenizer.c
index 595927f..ff0a11d 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -1,5 +1,5 @@
static const char *keywords[KW_COUNT] =
- {";", ":", "@", ",", "(", ")", "{", "}", "[", "]", "==",
+ {";", "::", ":", ",", "(", ")", "{", "}", "[", "]", "==",
"+=", "-=", "*=", "/=",
"!=", "<=", "<", ">=", ">",
"+", "-", "*", "!", "&", "/", "..", ".",
diff --git a/types.c b/types.c
index 253e0a4..7d104e7 100644
--- a/types.c
+++ b/types.c
@@ -383,7 +383,7 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) {
} else {
if (location_after(d->where, where)) {
char *s = ident_to_str(i);
- err_print(where, "Use of identifier %s before its declaration.\nNote that it is only possible to use a constant function before it is directly declared (e.g. x @= fn() {}).", s);
+ err_print(where, "Use of identifier %s before its declaration.\nNote that it is only possible to use a constant function before it is directly declared (e.g. x ::= fn() {}).", s);
info_print(d->where, "%s will be declared here.", s);
free(s);
} else {
diff --git a/types.h b/types.h
index b4dba53..43befe1 100644
--- a/types.h
+++ b/types.h
@@ -183,8 +183,8 @@ typedef enum {
typedef enum {
KW_SEMICOLON,
+ KW_COLONCOLON,
KW_COLON,
- KW_AT,
KW_COMMA,
KW_LPAREN,
KW_RPAREN,