From a5267bb8aeb70cf8b065d766156ccf4d9eb8dbaf Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 1 Jun 2022 13:23:21 +0200 Subject: [PATCH] Adding lvalue rvalue concept, Cleanup --- new_parse.cpp | 1 + typecheck.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/new_parse.cpp b/new_parse.cpp index 92a33f5..4f8ee60 100644 --- a/new_parse.cpp +++ b/new_parse.cpp @@ -149,6 +149,7 @@ function Ast_Expr *parse_expr(S64 rbp = 0); function Ast_Expr * parse_init_stmt(Ast_Expr *expr){ Token *token = token_get(); + if(token->kind == TK_ColonAssign && expr->kind != AST_IDENT) parsing_error(expr->pos, "Binding with [:=] to something that is not an identifier"); if(token_is_assign(token)){ token_next(); Ast_Expr *value = parse_expr(); diff --git a/typecheck.cpp b/typecheck.cpp index f3e6247..2060b62 100644 --- a/typecheck.cpp +++ b/typecheck.cpp @@ -404,13 +404,13 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res Operand result = {}; switch(node->op){ case TK_ColonAssign:{ + // @note: This is actually a statement so it doesn't need to return Operand assert(is_flag_set(node->flags, AST_STMT)); - // Operand left = resolve_expr(node->left); // needs to be lvalue - Operand right = resolve_expr(node->right); assert(node->left->kind == AST_IDENT); - Ast_Atom *atom = (Ast_Atom *)node->left; // @todo use left operand - Sym *sym = sym_new_resolved(SYM_VAR, atom->intern_val, right.type, right.value, node); - sym_insert(sym); + + Operand right = resolve_expr(node->right); + Ast_Atom *atom = (Ast_Atom *)node->left; + sym_insert(SYM_VAR, atom->intern_val, right.type, right.value, node); }break; case TK_Dot: { B32 required_to_be_const = false;