From a240a3d14660f6b33f839a3ebf142e20aac3e80a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 28 Dec 2018 13:31:06 +0000 Subject: `static` variable declarations (Experimental) --- src/check_stmt.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/check_stmt.cpp') diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 811f59907..b6e0a7f58 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1667,6 +1667,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { if (!is_blank_ident(str)) { found = scope_lookup_current(ctx->scope, str); new_name_count += 1; + } else if (vd->is_static) { + error(name, "'static' is now allowed to be applied to '_'"); } if (found == nullptr) { entity = alloc_entity_variable(ctx->scope, token, nullptr, false); @@ -1678,6 +1680,9 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { entity->Variable.is_foreign = true; entity->Variable.foreign_library_ident = fl; } + if (vd->is_static) { + entity->flags |= EntityFlag_Static; + } } else { TokenPos pos = found->token.pos; error(token, @@ -1780,6 +1785,17 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { } else { map_set(fp, key, e); } + } else if (e->flags & EntityFlag_Static) { + if (vd->values.count > 0) { + if (entity_count != vd->values.count) { + error(e->token, "A static variable declaration with a default value must be constant"); + } else { + Ast *value = vd->values[i]; + if (value->tav.mode != Addressing_Constant) { + error(e->token, "A static variable declaration with a default value must be constant"); + } + } + } } add_entity(ctx->checker, ctx->scope, e->identifier, e); } -- cgit v1.2.3