From 6e86f7b9a3ca057640bcfaa4ea72872dcd8d3af4 Mon Sep 17 00:00:00 2001
From: A404M <ahmadmahmoudiprogrammer@gmail.com>
Date: Fri, 6 Jun 2025 03:19:06 +0330
Subject: fix when you disable statistics some more clean up

---
 src/compiler/ast-tree.c | 38 +++++++++++++++++++++++++-------------
 src/compiler/parser.c   |  4 ++++
 2 files changed, 29 insertions(+), 13 deletions(-)

(limited to 'src/compiler')

diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 65e7a4d..299f989 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -1836,8 +1836,12 @@ AstTreeRoots makeAstTree(const char *filePath
       .size = 0,
   };
 
-  if (getAstTreeRoot(strClone(filePath), &roots, lexingTime, parsingTime) ==
-      NULL) {
+  if (getAstTreeRoot(strClone(filePath), &roots
+#ifdef PRINT_STATISTICS
+                     ,
+                     lexingTime, parsingTime
+#endif
+                     ) == NULL) {
     goto RETURN_ERROR;
   }
 
@@ -1867,15 +1871,24 @@ AstTreeRoot *getAstTreeRoot(char *filePath, AstTreeRoots *roots
     }
   }
 
+#ifdef PRINT_STATISTICS
   Time start = get_time();
+#endif
 
-  ParserNode *parserNode = parserFromPath(filePath, lexingTime);
+  ParserNode *parserNode = parserFromPath(filePath
+#ifdef PRINT_STATISTICS
+                                          ,
+                                          lexingTime
+#endif
+  );
   if (parserNode == NULL) {
     goto RETURN_ERROR;
   }
 
+#ifdef PRINT_STATISTICS
   Time end = get_time();
   *parsingTime = time_add(*parsingTime, time_diff(end, start));
+#endif
   AstTreeRoot *root = makeAstRoot(parserNode, filePath);
   parserNodeDelete(parserNode);
   if (root == NULL) {
@@ -1959,15 +1972,6 @@ bool astTreeDoImport(AstTreeRoots *roots, AstTreeRoot *root, AstTree *tree,
         return false;
       }
 
-      AstTree *type = makeStringType();
-      if (!typeIsEqual(type, parameter->type, helper.scope)) {
-        printError(parameter->str_begin, parameter->str_end,
-                   "Type mismatch (must be a []u8 aka string)");
-        astTreeDelete(type);
-        return false;
-      }
-      astTreeDelete(type);
-
       char *str = u8ArrayToCString(parameter);
       astTreeDelete(parameter);
 
@@ -6869,6 +6873,14 @@ bool setTypesBuiltinImport(AstTree *tree, AstTreeSetTypesHelper helper,
       return false;
     }
 
+    AstTree *fileType = makeStringType();
+
+    if (!typeIsEqual(file->type, fileType, helper.scope)) {
+      astTreeDelete(fileType);
+      printError(file->str_begin, file->str_end, "Bad paramter");
+      return false;
+    }
+
     AstTreeTypeFunction *type_metadata = a404m_malloc(sizeof(*type_metadata));
     type_metadata->arguments_size = 1;
     type_metadata->arguments = a404m_malloc(type_metadata->arguments_size *
@@ -6878,7 +6890,7 @@ bool setTypesBuiltinImport(AstTree *tree, AstTreeSetTypesHelper helper,
     type_metadata->returnType = copyAstTree(&AST_TREE_NAMESPACE_TYPE);
 
     type_metadata->arguments[0] = (AstTreeTypeFunctionArgument){
-        .type = copyAstTree(file->type),
+        .type = fileType,
         .name_begin = PATH_STR,
         .name_end = PATH_STR + PATH_STR_SIZE,
         .str_begin = NULL,
diff --git a/src/compiler/parser.c b/src/compiler/parser.c
index d5906a5..a35800c 100644
--- a/src/compiler/parser.c
+++ b/src/compiler/parser.c
@@ -811,7 +811,9 @@ ParserNode *parserFromPath(const char *filePath
                            Time *lexingTime
 #endif
 ) {
+#ifdef PRINT_STATISTICS
   Time start = get_time();
+#endif
   char *code = readWholeFile(filePath);
   if (code == NULL) {
     return NULL;
@@ -821,8 +823,10 @@ ParserNode *parserFromPath(const char *filePath
   if (lexerNodeArrayIsError(lexed)) {
     return NULL;
   }
+#ifdef PRINT_STATISTICS
   Time end = get_time();
   *lexingTime = time_add(*lexingTime, time_diff(end, start));
+#endif
 
   ParserNode *root = parser(lexed);
   lexerNodeArrayDestroy(lexed);
-- 
cgit v1.2.3