about summary refs log tree commit diff
path: root/boot/tree.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-07-18 01:39:28 +0200
committerMel <mel@rnrd.eu>2025-07-18 01:39:28 +0200
commita37262c61fd577e0e620e024007e0139929e3926 (patch)
treef8069c772d6649067c9165863184fb9e4fe5cdee /boot/tree.c
parent9a89772396f13ef27f29e71901a75e4760930cf2 (diff)
downloadcatskill-a37262c61fd577e0e620e024007e0139929e3926.tar.zst
catskill-a37262c61fd577e0e620e024007e0139929e3926.zip
Separate call/construct expression back into parts
This makes it easier to decide whether subject should be interpreted as a type of expression.

Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tree.c')
-rw-r--r--boot/tree.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/boot/tree.c b/boot/tree.c
index 4320279..228bbd4 100644
--- a/boot/tree.c
+++ b/boot/tree.c
@@ -423,6 +423,19 @@ struct Function_Header_Node
     struct Cursor location;
 };
 
+// a group of arguments, used in function calls and
+// constructions.
+// styled as either `1, 2, 3` or, when optional names
+// are given `a = 1, b = 2, c = 3`.
+struct Argument_Group_Node
+{
+    // 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;
+};
+
 // a declaration of a variable, constant, or other binding, without a mutability
 // signifier, like `let` or `var`.
 // the mutability is determined by some outside context, where
@@ -698,7 +711,8 @@ enum Expression_Kind
     EXPRESSION_BINARY_OPERATION,
 
     EXPRESSION_GROUP,
-    EXPRESSION_CALL_OR_CONSTRUCT,
+    EXPRESSION_CONSTRUCT,
+    EXPRESSION_CALL,
     EXPRESSION_SUBSCRIPT,
     EXPRESSION_MEMBER,
     EXPRESSION_INCREMENT_DECREMENT,
@@ -752,14 +766,18 @@ struct Expression_Group
     struct Expression* inner_expression;
 };
 
-struct Expression_Call_Or_Construct
+struct Expression_Call
 {
     struct Expression* subject;
-    // 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 Argument_Group_Node argument_group;
+};
+
+struct Expression_Construct
+{
+    // this should be the type to construct, e.g. `int` or `string` or a generic like `Maybe(X)`
+    // right now, we can't guarantee it fully.
+    struct Expression* subject;
+    struct Argument_Group_Node argument_group;
 };
 
 struct Expression_Subscript
@@ -813,7 +831,8 @@ union Expression_Value
     struct Expression_Unary_Operator unary_operator;
     struct Expression_Binary_Operator binary_operator;
     struct Expression_Group group;
-    struct Expression_Call_Or_Construct call_or_construct;
+    struct Expression_Call call;
+    struct Expression_Construct construct;
     struct Expression_Subscript subscript;
     struct Expression_Member member;
     struct Expression_Increment_Decrement increment_decrement;