From 02b6a1c85b9b9329bfd8f2e2275460054cd58f55 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 1 Jun 2022 13:28:38 +0200 Subject: [PATCH] RValue, LValue concept working, Assigning to numbers is now illegal! --- lambdas.kl | 2 +- main.cpp | 4 ++-- order2.kl | 4 ++-- typecheck.cpp | 4 +--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lambdas.kl b/lambdas.kl index cd34c06..7c2509b 100644 --- a/lambdas.kl +++ b/lambdas.kl @@ -14,7 +14,7 @@ if_stmt :: (cond: int): type for_stmt :: () - for i := 0, i + 10, i + for i := 0, i + 10, i+=1 pass add_10 :: (size: int): int diff --git a/main.cpp b/main.cpp index 1114c49..762dea7 100644 --- a/main.cpp +++ b/main.cpp @@ -93,12 +93,12 @@ int main(){ printf("%s", result.str); result = compile_file("enums.kl"_s); printf("%s", result.str); - result = compile_file("lambdas.kl"_s); - printf("%s", result.str); result = compile_file("order1.kl"_s); printf("%s", result.str); result = compile_file("order2.kl"_s); printf("%s", result.str); + result = compile_file("lambdas.kl"_s); + printf("%s", result.str); __debugbreak(); } diff --git a/order2.kl b/order2.kl index 8b56e3f..43cb604 100644 --- a/order2.kl +++ b/order2.kl @@ -56,11 +56,11 @@ test_assignments :: () i >>= 2 i <<= 2 - i + 4 = 32 - 8 = 32 j: *int *j = 1 /* invalid + 8 = 32 + i + 4 = 32 i += "String" */ diff --git a/typecheck.cpp b/typecheck.cpp index 2060b62..2fa0d27 100644 --- a/typecheck.cpp +++ b/typecheck.cpp @@ -73,9 +73,8 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){ sym_insert(sym); } else if(token_is_assign(node->op)){ - // @todo: assign value to constant - // @todo: lvalue concept, passing down syms to change (constants) Operand left = resolve_expr(node->left); + if(!left.is_lvalue) parsing_error(node->pos, "Assigning to rvalue"); Operand right = resolve_expr(node->right); if(left.type != right.type) parsing_error(node->pos, "Different types"); } @@ -89,7 +88,6 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){ } CASE(FOR, For){ - // @todo: I think we need to bring back the Ast_Init, it was not an expression resolve_expr(node->init, ret); Operand cond = resolve_expr(node->cond); // @todo: typechecking resolve_expr(node->iter, ret);