about summary refs log tree commit diff
path: root/boot/tree.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-06-24 20:07:41 +0200
committerMel <mel@rnrd.eu>2025-06-24 20:07:41 +0200
commit47c5a0ecc6fccc3bfe0b5394d7297e635ab23184 (patch)
treebd99364fa76cfff6664b233a1e6682a63fdbd020 /boot/tree.c
parenta63977f56a4c3dc4c53f0befe65c8252cc5c9b0b (diff)
downloadcatskill-47c5a0ecc6fccc3bfe0b5394d7297e635ab23184.tar.zst
catskill-47c5a0ecc6fccc3bfe0b5394d7297e635ab23184.zip
Parse named arguments, thus enabling type constructions
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tree.c')
-rw-r--r--boot/tree.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/boot/tree.c b/boot/tree.c
index e4d0272..2e046da 100644
--- a/boot/tree.c
+++ b/boot/tree.c
@@ -665,7 +665,7 @@ enum Expression_Kind
     EXPRESSION_BINARY_OPERATION,
 
     EXPRESSION_GROUP,
-    EXPRESSION_CALL,
+    EXPRESSION_CALL_OR_CONSTRUCT,
     EXPRESSION_SUBSCRIPT,
     EXPRESSION_MEMBER,
     EXPRESSION_INCREMENT_DECREMENT,
@@ -717,10 +717,14 @@ struct Expression_Group
     struct Expression* inner_expression;
 };
 
-struct Expression_Call
+struct Expression_Call_Or_Construct
 {
     struct Expression* subject;
-    struct Expression* arguments; // linked list of expressions.
+    // linked list of argument expressions.
+    struct Expression* arguments;
+    // names of the arguments, if given.
+    // an unnamed argument is represented as an empty string.
+    struct String_Array argument_names;
 };
 
 struct Expression_Subscript
@@ -764,7 +768,7 @@ union Expression_Value
     struct Expression_Unary_Operator unary_operator;
     struct Expression_Binary_Operator binary_operator;
     struct Expression_Group group;
-    struct Expression_Call call;
+    struct Expression_Call_Or_Construct call_or_construct;
     struct Expression_Subscript subscript;
     struct Expression_Member member;
     struct Expression_Increment_Decrement increment_decrement;
@@ -867,16 +871,26 @@ expression_print(const struct Expression* expression)
         expression_print(expression->value.group.inner_expression);
         printf(")");
         break;
-    case EXPRESSION_CALL:
-        printf("(call ");
-        expression_print(expression->value.call.subject);
-        FOR_EACH(struct Expression*, argument, expression->value.call.arguments)
+    case EXPRESSION_CALL_OR_CONSTRUCT: {
+        const struct Expression_Call_Or_Construct* coc =
+            &expression->value.call_or_construct;
+        printf("(call/construct ");
+        expression_print(coc->subject);
+        uint i = 0;
+        FOR_EACH(struct Expression*, argument, coc->arguments)
         {
-            printf(" ");
+            struct String name = string_array_at(&coc->argument_names, i++);
+            if (!string_is_empty(name)) {
+                printf(" (named arg '%s' ", name.data);
+            } else {
+                printf(" (arg ");
+            }
             expression_print(argument);
+            printf(")");
         }
         printf(")");
         break;
+    }
     case EXPRESSION_SUBSCRIPT:
         printf("(subscript ");
         expression_print(expression->value.subscript.subject);