From ffe049371a64e0b41fdc777106f768b16b2cd9b2 Mon Sep 17 00:00:00 2001
From: A404M <ahmadmahmoudiprogrammer@gmail.com>
Date: Sat, 24 May 2025 02:36:58 +0330
Subject: fix some unintended stuff

---
 Makefile                |  4 ++--
 code/main.felan         | 13 +++----------
 src/compiler/ast-tree.c |  4 ++--
 src/runner/runner.c     | 12 ++++++------
 4 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile
index c7b3eec..c590681 100644
--- a/Makefile
+++ b/Makefile
@@ -20,9 +20,9 @@ INC_DIRS := $(SRC_DIR)
 INC_FLAGS := $(addprefix -I,$(INC_DIRS))
 
 # OP_FLAG := -Ofast
-OP_FLAG := -O3
+# OP_FLAG := -O3
 # OP_FLAG := -Oz
-# OP_FLAG := -g
+OP_FLAG := -g
 
 # CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -DPRINT_STATISTICS -DPRINT_COMPILE_TREE $(OP_FLAG)
 CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -lffi -DPRINT_STATISTICS $(OP_FLAG)
diff --git a/code/main.felan b/code/main.felan
index 969d1b6..d8c6ec3 100644
--- a/code/main.felan
+++ b/code/main.felan
@@ -1,9 +1,8 @@
 @import("basic.felan");
 
 libc :: @c_library("/lib/libc.so.6");
-putchar :: @c_function(libc,"putchar",(i32)->i32);
 puts :: @c_function(libc,"puts",(*u8)->i32);
-sleep :: @c_function(libc,"sleep",(i32)->void);
+sleep :: @c_function(libc,"sleep",(i32)->i32);
 
 raylib :: @c_library("/lib/libraylib.so.5.5.0");
 InitWindow :: @c_function(raylib,"InitWindow",(i32,i32,*u8)->void);
@@ -14,21 +13,15 @@ CloseWindow :: @c_function(raylib,"CloseWindow",()->void);
 ClearBackground :: @c_function(raylib,"ClearBackground",(color:u32)->void);
 
 main :: ()->void{
-  a :i32= 97;
-  a = putchar(a);
-  putchar(a);
   b := "hello\0";
-  str := &(b[0]);
-  puts(str);
+  str := &b[0];
   screenWidth :i32: 800;
   screenHeight :i32: 450;
   InitWindow(screenWidth,screenHeight,str);
-  test := WindowShouldClose();
-  while test == false {
+  while WindowShouldClose() == false {
     BeginDrawing();
     ClearBackground(@cast(4294967295,u32));
     EndDrawing();
-    test = WindowShouldClose();
   }
   CloseWindow();
 };
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 628784a..a4159d1 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -5842,7 +5842,7 @@ bool setTypesIf(AstTree *tree, AstTreeSetTypesHelper helper,
     return false;
   }
 
-  if (isConst(metadata->condition)) {
+  if (metadata->condition->token == AST_TREE_TOKEN_KEYWORD_COMPTIME) {
     AstTree *condition = getValue(metadata->condition, true);
     AstTree *result;
     bool condi = *(AstTreeBool *)condition->metadata;
@@ -5913,7 +5913,7 @@ bool setTypesWhile(AstTree *tree, AstTreeSetTypesHelper _helper,
     return false;
   }
 
-  if (isConst(metadata->condition)) {
+  if (metadata->condition->token == AST_TREE_TOKEN_KEYWORD_COMPTIME) {
     AstTree *condition = getValue(metadata->condition, true);
     bool condi = *(AstTreeBool *)condition->metadata;
     astTreeDelete(condition);
diff --git a/src/runner/runner.c b/src/runner/runner.c
index c5355cc..9cb67f8 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -991,15 +991,13 @@ AstTree *runAstTreeCFunction(AstTree *tree, AstTree **arguments,
     UNREACHABLE;
   }
 
-  ffi_cif cif;
-  ffi_type *args[arguments_size];
-  void *values[arguments_size];
-  ffi_arg rc;
-
   if (funcType->arguments_size != arguments_size) {
     UNREACHABLE;
   }
 
+  ffi_type *args[arguments_size];
+  void *values[arguments_size];
+
   for (size_t i = 0; i < arguments_size; ++i) {
     AstTreeTypeFunctionArgument arg = funcType->arguments[i];
     args[i] = toFFIType(arg.type);
@@ -1014,13 +1012,15 @@ AstTree *runAstTreeCFunction(AstTree *tree, AstTree **arguments,
     values[i] = arguments[i]->metadata;
   }
 
+  ffi_cif cif;
   if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, arguments_size,
                    toFFIType(funcType->returnType), args) == FFI_OK) {
+    ffi_arg rc;
     ffi_call(&cif, fun, &rc, values);
     if (typeIsEqual(funcType->returnType, &AST_TREE_VOID_TYPE)) {
       return &AST_TREE_VOID_TYPE;
     } else {
-      size_t size = getSizeOfType(funcType->returnType);
+      const size_t size = getSizeOfType(funcType->returnType);
       AstTreeRawValue *value = a404m_malloc(size);
       memcpy(value, &rc, size);
       return newAstTree(AST_TREE_TOKEN_RAW_VALUE, value,
-- 
cgit v1.2.3