removed assignments in an expression
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Jul 2020 21:56:34 +0000 (16:56 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 20 Jul 2020 21:56:34 +0000 (16:56 -0500)
misc/onyx.vim
onyx
progs/structs.onyx
src/onyxchecker.c

index bf1fdd66aeb33f43e317f2db0ad95749646b3e0a..a546576595d99a22bc4e30f99395968dc2d89d39 100644 (file)
@@ -14,7 +14,7 @@ syn keyword onyxKeyword struct proc use global
 syn keyword onyxKeyword if elseif else
 syn keyword onyxKeyword for while do
 syn keyword onyxKeyword break continue return
-syn keyword onyxKeyword as
+syn keyword onyxKeyword as sizeof
 
 syn keyword onyxType unknown bool void
 syn keyword onyxType i8 u8
diff --git a/onyx b/onyx
index 3bb5101005244791d12aaa0c1156ef0d3cf541cf..91945452d1234bb1987909f35894949e666073fe 100755 (executable)
Binary files a/onyx and b/onyx differ
index 4bd171aa4f9cc013789de74be6c85fa1513cec1e..ad96f3cec34ce6336d85915682a42fa8a82d76f4 100644 (file)
@@ -123,6 +123,5 @@ link_test :: proc #export "main2" {
     link_create(3, node_head);
     link_create(4, node_head);
 
-
     link_print(*node_head);
 }
\ No newline at end of file
index 3a4f2096aa2a43e10cd4a45c5b3fa4c4fd6657b8..604989c3ccedeaed5dc1b3fe4a0aec98b4fc9cbd 100644 (file)
@@ -13,7 +13,7 @@ CHECK(if, AstIf* ifnode);
 CHECK(while, AstWhile* whilenode);
 CHECK(for, AstFor* fornode);
 CHECK(call, AstCall* call);
-CHECK(binaryop, AstBinaryOp* binop);
+CHECK(binaryop, AstBinaryOp* binop, b32 assignment_is_ok);
 CHECK(expression, AstTyped* expr);
 CHECK(address_of, AstAddressOf* aof);
 CHECK(dereference, AstDereference* deref);
@@ -289,11 +289,18 @@ CHECK(call, AstCall* call) {
     return 0;
 }
 
-CHECK(binaryop, AstBinaryOp* binop) {
+CHECK(binaryop, AstBinaryOp* binop, b32 assignment_is_ok) {
     if (check_expression(binop->left)) return 1;
     if (check_expression(binop->right)) return 1;
 
     if (binop_is_assignment(binop)) {
+        if (!assignment_is_ok) {
+            onyx_message_add(Msg_Type_Literal,
+                binop->token->pos,
+                "assignment not valid in expression");
+            return 1;
+        }
+
         if (!is_lval((AstNode *) binop->left)) {
             onyx_message_add(Msg_Type_Not_Lval,
                     binop->left->token->pos,
@@ -481,7 +488,7 @@ CHECK(expression, AstTyped* expr) {
 
     i32 retval = 0;
     switch (expr->kind) {
-        case Ast_Kind_Binary_Op: retval = check_binaryop((AstBinaryOp *) expr); break;
+        case Ast_Kind_Binary_Op: retval = check_binaryop((AstBinaryOp *) expr, 0); break;
 
         case Ast_Kind_Unary_Op:
             retval = check_expression(((AstUnaryOp *) expr)->expr);
@@ -574,6 +581,7 @@ CHECK(statement, AstNode* stmt) {
         case Ast_Kind_For:        return check_for((AstFor *) stmt);
         case Ast_Kind_Call:       return check_call((AstCall *) stmt);
         case Ast_Kind_Block:      return check_block((AstBlock *) stmt);
+        case Ast_Kind_Binary_Op:  return check_binaryop((AstBinaryOp *) stmt, 1);
 
         case Ast_Kind_Break:      return 0;
         case Ast_Kind_Continue:   return 0;
@@ -726,7 +734,7 @@ CHECK(node, AstNode* node) {
         case Ast_Kind_If:                   return check_if((AstIf *) node);
         case Ast_Kind_While:                return check_while((AstWhile *) node);
         case Ast_Kind_Call:                 return check_call((AstCall *) node);
-        case Ast_Kind_Binary_Op:            return check_binaryop((AstBinaryOp *) node);
+        case Ast_Kind_Binary_Op:            return check_binaryop((AstBinaryOp *) node, 1);
         default:                            return check_expression((AstTyped *) node);
     }
 }