summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval.c4
-rw-r--r--identifiers.c4
-rw-r--r--main.c10
-rw-r--r--parse.c4
-rw-r--r--test.toc3
-rw-r--r--types.c14
6 files changed, 18 insertions, 21 deletions
diff --git a/eval.c b/eval.c
index f8ef498..88e6f13 100644
--- a/eval.c
+++ b/eval.c
@@ -663,8 +663,8 @@ static Status eval_expr_ptr_at_index(Evaluator *ev, Expression *e, void **ptr, T
}
static Value *ident_val(Evaluator *ev, Identifier i, Location where) {
- assert(ident_is_declared(i));
Declaration *decl = i->decl;
+ assert(decl);
int idx = decl_ident_index(decl, i);
if (decl->type.kind == TYPE_UNKNOWN && ev->typer->err_ctx->have_errored)
return NULL; /* silently fail (something went wrong when we typed this decl) */
@@ -1016,7 +1016,7 @@ static bool val_is_nonnegative(Value v, Type *t) {
}
static Status eval_ident(Evaluator *ev, Identifier ident, Value *v, Location where) {
- if (!ident_is_declared(ident)) {
+ if (!ident) {
char *s = ident_to_str(ident);
err_print(where, "Undeclared identifier: %s.", s);
free(s);
diff --git a/identifiers.c b/identifiers.c
index 0f5d59a..828bed6 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -220,7 +220,3 @@ static Location ident_decl_location(Identifier i) {
return i->decl->where;
}
-static bool ident_is_declared(Identifier i) {
- return i && i->decl;
-}
-
diff --git a/main.c b/main.c
index 930d947..f7d5b02 100644
--- a/main.c
+++ b/main.c
@@ -8,14 +8,14 @@
/*
@TODO:
-do we need the possibility that IdentSlot.decl is NULL?
+test:
+ _ := 5;
+ _ := 6;
+don't allow use of the identifier _, e.g. puti(_+5) ok for fields i think
use
- use with struct members (e.g. SuperPoint ::= struct { use p: Point; })
maybe change to #define check(x) do { if_unlikely(x) return 0; } while (0);
always use pointers in cgen'd non-range for loops (sometimes also indices)
-test:
- _ := 5;
- _ := 6;
is there a problem where we can get TYPE_UNKNOWN in cgen, triggering an assert(0)?
-simple example, but maybe try other stuff: x := #C("5");
-also make sure you can't do x:#C("5");
@@ -25,9 +25,9 @@ allow `use ???;` if an error has already occurred
if something gets included into a namespace, and its typing fails, the namespace should still be of type namespace, not ???
make sure you can do a[i] where a is &[5]int or &[]char or something
do we consistently handle x := &some_array_or_slice; x.len
+&void
simplify eval macros with val_to_u/i64
#if should not create a block
-&void
&&, ||
start making a standard library... (printf; stringbuilder would be nice to have)
switch
diff --git a/parse.c b/parse.c
index d7bae47..66f092f 100644
--- a/parse.c
+++ b/parse.c
@@ -1011,7 +1011,7 @@ static Identifier parser_ident_insert(Parser *p, char *str) {
static Status check_ident_redecl(Parser *p, Identifier i) {
Tokenizer *t = p->tokr;
- if (ident_is_declared(i)) {
+ if (i->decl) {
char *s = ident_to_str(i);
tokr_err(t, "Redeclaration of identifier %s.", s);
info_print(ident_decl_location(i), "Previous declaration was here.");
@@ -2944,8 +2944,8 @@ static inline Type *decl_type_at_index(Declaration *d, int i) {
}
static inline bool ident_is_definitely_const(Identifier i) {
- assert(ident_is_declared(i));
Declaration *decl = i->decl;
+ assert(decl);
if (!(decl->flags & DECL_IS_CONST))
return false;
diff --git a/test.toc b/test.toc
index 1f6a725..a30d6ee 100644
--- a/test.toc
+++ b/test.toc
@@ -15,6 +15,7 @@ main ::= fn() {
*x = i;
}
puti(sum(numbers) as int);
+
}
*/
Point ::= struct {
@@ -23,5 +24,5 @@ Point ::= struct {
main ::= fn() {
p: Point;
- p.x = 12;
+ p.x = 12 + e;
}
diff --git a/types.c b/types.c
index 22e4350..6cb6e97 100644
--- a/types.c
+++ b/types.c
@@ -741,7 +741,7 @@ static Status add_block_to_struct(Typer *tr, Block *b, StructDef *s, Statement *
/* we need to translate d's identifiers to s's scope */
arr_foreach(d->idents, Identifier, ip) {
Identifier redeclared = ident_get(&s->body.idents, (*ip)->str);
- if (ident_is_declared(redeclared)) {
+ if (redeclared) {
char *str = ident_to_str(*ip);
err_print(d->where, "Redeclaration of struct member %s", str);
info_print(ident_decl_location(redeclared), "Previous declaration was here.");
@@ -1949,7 +1949,7 @@ static Status types_expr(Typer *tr, Expression *e) {
while (1) { /* for each block we are inside... */
/* @OPTIM: only hash once */
Identifier translated = ident_get_with_len(b ? &b->idents : tr->globals, i_str, i_len);
- if (ident_is_declared(translated)) {
+ if (translated) {
#if 0
printf("translated %s from\n", ident_to_str(i));
print_block_location(i->idents->body);
@@ -1985,7 +1985,7 @@ static Status types_expr(Typer *tr, Expression *e) {
StructDef *struc = struct_type->struc;
translated_use = ident_get_with_len(&struc->body.idents, i_str, i_len);
}
- if (ident_is_declared(translated_use)) {
+ if (translated_use) {
if (undeclared) {
previous_use_which_uses_i = use;
undeclared = false;
@@ -2030,13 +2030,13 @@ static Status types_expr(Typer *tr, Expression *e) {
break;
}
}
- e->ident = final_ident;
if (undeclared) {
- char *s = ident_to_str(e->ident);
+ char *s = cstr(e->ident_str.str, e->ident_str.len);
err_print(e->where, "Undeclared identifier \"%s\".", s);
free(s);
return false;
}
+ e->ident = final_ident;
if (!type_of_ident(tr, e->where, e->ident, t)) {
return false;
}
@@ -3127,7 +3127,7 @@ static Status types_expr(Typer *tr, Expression *e) {
StructDef *struc = struct_type->struc;
assert(struc->flags & STRUCT_DEF_RESOLVED);
Identifier struct_ident = ident_get_with_len(&struc->body.idents, rhs->ident_str.str, rhs->ident_str.len);
- if (ident_is_declared(struct_ident) && !(struct_ident->decl->flags & DECL_IS_CONST)) {
+ if (struct_ident && !(struct_ident->decl->flags & DECL_IS_CONST)) {
Field *field = struct_ident->decl->field;
field += ident_index_in_decl(struct_ident, struct_ident->decl);
e->binary.field = field;
@@ -3178,7 +3178,7 @@ static Status types_expr(Typer *tr, Expression *e) {
lhs->val.nms = nms;
String str = rhs->ident_str;
rhs->ident = ident_get_with_len(&nms->body.idents, str.str, str.len);
- if (!ident_is_declared(rhs->ident)) {
+ if (!rhs->ident) {
char *s = cstr(str.str, str.len);
err_print(e->where, "\"%s\" is not a member of this namespace.", s);
free(s);