From 378aa3eee5db8c85b94f0d1852b82a259800fd40 Mon Sep 17 00:00:00 2001
From: A404M <ahmadmahmoudiprogrammer@gmail.com>
Date: Tue, 28 Jan 2025 05:19:39 +0330
Subject: add automatic type finding to u64 values

---
 src/compiler/ast-tree.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

(limited to 'src/compiler')

diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index b03754d..f26d1b5 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -683,23 +683,28 @@ bool astTreeParseConstant(ParserNode *parserNode, AstTreeVariables **variables,
                           size_t variables_size) {
   ParserNodeVariableMetadata *node_metadata = parserNode->metadata;
 
-  if (node_metadata->value == NULL || node_metadata->type == NULL ||
+  if (node_metadata->value == NULL ||
       node_metadata->name->token != PARSER_TOKEN_IDENTIFIER) {
-    printLog("Not yet supported");
+    printLog("Not supported");
     return NULL;
   }
 
-  AstTree *type = astTreeParse(node_metadata->type, variables, variables_size);
-  if (type == NULL) {
-    goto RETURN_ERROR;
-  }
-
   AstTree *value =
       astTreeParse(node_metadata->value, variables, variables_size);
   if (value == NULL) {
     goto RETURN_ERROR;
   }
 
+  AstTree *type;
+  if (node_metadata->type == NULL) {
+    type = makeTypeOf(value);
+  } else {
+    type = astTreeParse(node_metadata->type, variables, variables_size);
+    if (type == NULL) {
+      goto RETURN_ERROR;
+    }
+  }
+
   AstTreeVariable *variable = a404m_malloc(sizeof(*variable));
   variable->type = type;
   variable->value = value;
-- 
cgit v1.2.3