aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-06-08 12:19:42 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-06-08 12:19:42 +0330
commit47177fdfe2758789efe7941de6007a3fb7105f82 (patch)
treeba54d2534286d9ea734c724e03f286b4e4f86144
parent44cf97674be6da6790281d59f43b22c88a6360e6 (diff)
generalizing compiler instead of relaying on gcc
-rw-r--r--Makefile11
-rw-r--r--README.md4
-rw-r--r--src/compiler/ast-tree.c9
-rw-r--r--src/runner/runner.c12
4 files changed, 27 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 05c0f17..c896254 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
PROJECT_NAME := felan
-CC := gcc
+CC := cc
+# CC := gcc
# CC := tcc
# CC := clang
@@ -24,11 +25,11 @@ INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# OP_FLAG := -Oz
OP_FLAG := -g
-LINK_FLAGS := -lffi
+LDFLAGS := -lffi
-# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 $(LINK_FLAGS) -DPRINT_STATISTICS -DPRINT_COMPILE_TREE $(OP_FLAG)
-CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 $(LINK_FLAGS) -DPRINT_STATISTICS $(OP_FLAG)
-# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 $(LINK_FLAGS) $(OP_FLAG)
+# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -DPRINT_STATISTICS -DPRINT_COMPILE_TREE $(OP_FLAG)
+CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -DPRINT_STATISTICS $(OP_FLAG)
+# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 $(OP_FLAG)
EXEC_FILE := $(BUILD_DIR)/$(PROJECT_NAME)
diff --git a/README.md b/README.md
index 8187e6c..16c3f7d 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ A strongly statically typed programming language with a simple and friendly synt
* Linux or *nix like OS
* git
* gnu make
-* gcc (you can use clang or tcc but you have to change make for it)
+* c compiler (gcc, clang, tcc, ...)
* libffi (for calling C functions)
# How to use ?
@@ -67,6 +67,8 @@ main :: () -> void {
* ~Overloading [] operator~
* ~Add code injection~
* Add macro
+* Add \u and \x to char
+* Add vararg
* Add enum
* Compile AST to BBA
* Compile BBA to ASM
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index acbf8ed..b8365af 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -1686,6 +1686,7 @@ AstTree *copyAstTreeBack(AstTree *tree, AstTreeVariables oldVariables[],
}
printLog("Bad token %d", tree->token);
UNREACHABLE;
+ return NULL;
}
AstTreeVariable *copyAstTreeBackFindVariable(AstTreeVariable *variable,
@@ -2992,6 +2993,7 @@ AstTree *astTreeParseIntValue(const ParserNode *parserNode) {
}
}
UNREACHABLE;
+ return NULL;
}
AstTree *astTreeParseString(const ParserNode *parserNode) {
@@ -4058,6 +4060,7 @@ bool isConst(AstTree *tree) {
}
printLog("Unknown token '%d'", tree->token);
UNREACHABLE;
+ return NULL;
}
bool isLeftValue(AstTree *tree) {
@@ -4116,7 +4119,9 @@ bool isLeftValue(AstTree *tree) {
case AST_TREE_TOKEN_TYPE_U32:
case AST_TREE_TOKEN_TYPE_I64:
case AST_TREE_TOKEN_TYPE_U64:
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
+#endif
case AST_TREE_TOKEN_TYPE_F32:
case AST_TREE_TOKEN_TYPE_F64:
case AST_TREE_TOKEN_TYPE_F128:
@@ -7066,7 +7071,9 @@ bool setTypesBuiltinUnary(AstTree *tree, AstTreeSetTypesHelper helper,
case AST_TREE_TOKEN_TYPE_U32:
case AST_TREE_TOKEN_TYPE_I64:
case AST_TREE_TOKEN_TYPE_U64:
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
+#endif
case AST_TREE_TOKEN_TYPE_F32:
case AST_TREE_TOKEN_TYPE_F64:
case AST_TREE_TOKEN_TYPE_F128:
@@ -8462,7 +8469,9 @@ size_t getSizeOfType(AstTree *type) {
return 1;
case AST_TREE_TOKEN_TYPE_I16:
case AST_TREE_TOKEN_TYPE_U16:
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
+#endif
return 2;
case AST_TREE_TOKEN_TYPE_I32:
case AST_TREE_TOKEN_TYPE_U32:
diff --git a/src/runner/runner.c b/src/runner/runner.c
index e6dc2b8..2308904 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -7,8 +7,6 @@
#include "utils/type.h"
#include <dlfcn.h>
#include <ffi.h>
-#include <iso646.h>
-#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -77,7 +75,7 @@
} \
}
#else
-#define doCastAll(left, left_type, type, to) \
+#define doCastAll(left, left_type, to) \
{ \
const left_type value = *(left_type *)left->metadata; \
switch (to->token) { \
@@ -1932,9 +1930,11 @@ AstTree *toRawValue(AstTree *value, AstTreeScope *scope) {
const size_t size = getSizeOfType(value->type);
AstTreeRawValue *rawValue = a404m_malloc(size);
switch (value->token) {
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
*(f16 *)rawValue = *(f128 *)value->metadata;
break;
+#endif
case AST_TREE_TOKEN_TYPE_F32:
*(f32 *)rawValue = *(f128 *)value->metadata;
break;
@@ -2022,7 +2022,9 @@ AstTree *toRawValue(AstTree *value, AstTreeScope *scope) {
case AST_TREE_TOKEN_TYPE_U32:
case AST_TREE_TOKEN_TYPE_I64:
case AST_TREE_TOKEN_TYPE_U64:
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
+#endif
case AST_TREE_TOKEN_TYPE_F32:
case AST_TREE_TOKEN_TYPE_F64:
case AST_TREE_TOKEN_TYPE_F128:
@@ -2154,7 +2156,9 @@ AstTree *fromRawValue(AstTree *value) {
case AST_TREE_TOKEN_TYPE_U32:
case AST_TREE_TOKEN_TYPE_I64:
case AST_TREE_TOKEN_TYPE_U64:
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
+#endif
case AST_TREE_TOKEN_TYPE_F32:
case AST_TREE_TOKEN_TYPE_F64:
case AST_TREE_TOKEN_TYPE_F128:
@@ -2490,8 +2494,10 @@ ffi_type *toFFIType(AstTree *type) {
return &ffi_type_sint64;
case AST_TREE_TOKEN_TYPE_U64:
return &ffi_type_uint64;
+#ifdef FLOAT_16_SUPPORT
case AST_TREE_TOKEN_TYPE_F16:
NOT_IMPLEMENTED;
+#endif
case AST_TREE_TOKEN_TYPE_F32:
return &ffi_type_float;
case AST_TREE_TOKEN_TYPE_F64: