bugfixes with expression macro substitutions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 29 Aug 2021 01:31:54 +0000 (20:31 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 29 Aug 2021 01:31:54 +0000 (20:31 -0500)
bin/onyx
docs/todo
examples/08_enums.onyx
examples/11_map.onyx
examples/12_varargs.onyx
examples/14_overloaded_procs.onyx
examples/17_operator_overload.onyx
modules/ui/ui.onyx
src/onyxchecker.c

index a124e1379839d79e75cb1b5a98ed41908f01d3d6..30b2a89058ad1c5a5c3ee41d721357c527e38db3 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index a3445f3e22bce75fa660cd9f91981ba25678f177..ef21b9824493a9171a5d6d402b2978f1452a6151 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -109,7 +109,7 @@ Language Cohesion:
 
     [ ] Functions should return the correct value in all branches.
 
-    [ ] Add macros.
+    [X] Add macros.
 
     [ ] enum #flags should be able to be used as so:
         ```
index 0262ea2da3342e10acd1726c3642d16eb56ebf50..63449417fea75903b4a5058e39e4f8a28e226c93 100644 (file)
@@ -54,7 +54,7 @@ main :: (args: [] cstr) {
         // you can leave out the enum name from the lookup and just use a unary '.'.
         // For example,
         //
-        
+
         val := SimpleEnum.Value2;
 
         // Here .Value2 can be resolved from the context of "val".
index 94e9d984b4ac0a8b554fcb8450c88ca3ce24fc09..bba7b9e43ca97a61d3a2ccb4aad81a8cec04dd92 100644 (file)
@@ -2,7 +2,7 @@
 
 use package core
 
-main ::  (args: [] cstr) {
+main :: (args: [] cstr) {
     // Onyx does not have map type built into the language semantics,
     // but using polymorphic structs and overloaded procedures, it does
     // provide an 'any-to-any' hash map in it's core libraries.
index 34d9948e2c2b10bf879b48c2fc9a4768fb975b9f..dde67ff1a47d82314acb90b2bcc3027f2234f848 100644 (file)
@@ -20,7 +20,7 @@
 use package core
 
 main :: (args: [] cstr) {
-    
+
     // This is how you specify a fixed type variadic procedure. 'args' can be thought
     // of as a slice of integers, with data and count fields. You can iterate over the
     // varargs using a for-loop like any other array-like structure. Note, do not
index ad91d8f36aa320e3878f8aec6bfae6a8fd72a167..fd500a50c8e0d6cd2c27f533b5c715af548faa40 100644 (file)
@@ -14,7 +14,7 @@
 // multiple times. Instead, to do the above in Onyx, you create a explicitly
 // overloaded procedure,
 //
-//    foo :: proc {
+//    foo :: #match {
 //        (x: i32) { ... },
 //        (y: str) { ... },
 //    }
index 49f5e3030276b862f735db70bda5cac04ac14607..96cac6a383f5453d4e0bb764dd30467c2b3873ec 100644 (file)
@@ -16,7 +16,7 @@ use package core
 // a binary operator, you cannot pass a custom allocator.
 
 #operator + (x: str, y: str) -> str {
-    return string.concat(x, y); 
+    return string.concat(x, y);
 }
 
 main :: (args: [] cstr) {
@@ -35,7 +35,7 @@ main :: (args: [] cstr) {
 
     // As a side note, '==' is already overloaded for strings in the
     // standard library, so you can do this:
-    
+
     if array.contains(cast([] str) strings, "is ") {
         println("The array contains 'is '.");
     } else {
index 327efcc9c531504688d077e16ab6764be7a3f1d7..9b41a7e1b11c3ebfe60dc5c10f1437fa44808695 100644 (file)
@@ -196,7 +196,7 @@ has_active_animation :: () -> bool {
 
 
 // Utilities
-get_site_hash :: (site: CallSite, increment := 0) -> UI_Id {
+get_site_hash :: macro (site: CallSite, increment := 0) -> UI_Id {
     hash :: package core.hash
 
     file_hash   := hash.to_u32(site.file);
@@ -221,7 +221,7 @@ move_towards :: macro (value: ^$T, target: T, step: T) {
     if *value > target - step && *value < target + step do *value = target;
 }
 
-#private color_lerp :: (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 {
+#private color_lerp :: macro (t: f32, c1: gfx.Color4, c2: gfx.Color4) -> gfx.Color4 {
     return .{
         r = c1.r * (1 - t) + c2.r * t,
         g = c1.g * (1 - t) + c2.g * t,
index a2ff9458efcf0876968e4fc6896ba97b399df2cd..ce564b16429f5f97dbf18095611d2bd4de7b407d 100644 (file)
@@ -810,11 +810,11 @@ CheckStatus check_binaryop_assignment(AstBinaryOp* binop) {
         else if (binop->operation == Binary_Op_Assign_Sar)      operation = Binary_Op_Sar;
 
         AstBinaryOp* new_right = make_binary_op(context.ast_alloc, operation, binop->left, binop->right);
-        new_right->token = binop->token;
-        CHECK(binaryop, &new_right);
-
         binop->right = (AstTyped *) new_right;
+        new_right->token = binop->token;
         binop->operation = Binary_Op_Assign;
+
+        CHECK(binaryop, (AstBinaryOp **) &binop->right);
     }
 
     if (binop->right->type == NULL) {
@@ -1182,7 +1182,7 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) {
         char* err_msg = NULL;
         if (!fill_in_arguments(&sl->args, (AstNode *) sl, &err_msg)) {
             onyx_report_error(sl->token->pos, err_msg);
-            
+
             bh_arr_each(AstTyped *, value, sl->args.values) {
                 if (*value == NULL) {
                     i32 member_idx = value - sl->args.values; // Pointer subtraction hack
@@ -1434,10 +1434,10 @@ CheckStatus check_subscript(AstSubscript** psub) {
         }
     }
 
-    if (!type_is_array_accessible(sub->addr->type))
-        ERROR_(sub->token->pos,
-                "Expected pointer or array type for left of array access, got '%s'.",
-                node_get_type_name(sub->addr));
+    if (!type_is_array_accessible(sub->addr->type)) {
+        report_bad_binaryop((AstBinaryOp *) sub);
+        return Check_Error;
+    }
 
     if (types_are_compatible(sub->expr->type, builtin_range_type_type)) {
         Type *of = NULL;
@@ -1448,6 +1448,7 @@ CheckStatus check_subscript(AstSubscript** psub) {
         else {
             // FIXME: Slice creation should be allowed for slice types and dynamic array types, like it
             // is below, but this code doesn't look at that.
+            report_bad_binaryop((AstBinaryOp *) sub);
             ERROR(sub->token->pos, "Invalid type for left of slice creation.");
         }
 
@@ -1461,6 +1462,7 @@ CheckStatus check_subscript(AstSubscript** psub) {
     resolve_expression_type(sub->expr);
     if (sub->expr->type->kind != Type_Kind_Basic
             || (sub->expr->type->Basic.kind != Basic_Kind_I32 && sub->expr->type->Basic.kind != Basic_Kind_U32)) {
+        report_bad_binaryop((AstBinaryOp *) sub);
         ERROR_(sub->token->pos,
             "Expected type u32 or i32 for index, got '%s'.",
             node_get_type_name(sub->expr));
@@ -1486,6 +1488,7 @@ CheckStatus check_subscript(AstSubscript** psub) {
         sub->type = sub->addr->type->Pointer.elem;
     }
     else {
+        report_bad_binaryop((AstBinaryOp *) sub);
         ERROR(sub->token->pos, "Invalid type for left of array access.");
     }