diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-05-24 00:49:48 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-05-24 00:49:48 +0330 |
commit | 547074407aa154cc82ecff647603254f2eaf46f6 (patch) | |
tree | 94900126df946fa89b741a699db9cbe9ca743fe3 | |
parent | 3c9aea642e3b2f4083705f1cd42fa911d35ee696 (diff) |
add a good example for calling c functions
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | code/main.felan | 25 |
2 files changed, 30 insertions, 4 deletions
@@ -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) @@ -73,8 +73,11 @@ test/big.felan: Makefile echo "main :: () -> void {" > $@ for((n = 0;n < 1000000;n++)); do echo " print('1');" >> $@; done echo "};" >> $@ + echo "libc :: @c_library(\"/lib/libc.so.6\");" >> $@ + echo "putchar :: @c_function(libc,\"putchar\",(i32)->i32);" >> $@ echo "print :: (value:u8) -> void {" >> $@ - echo " @putc(value);" >> $@ + echo " putchar(@cast(value,i32));" >> $@ + # echo " @putc(value);" >> $@ echo "};" >> $@ # $@ = left hand of : diff --git a/code/main.felan b/code/main.felan index dffcf15..969d1b6 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,11 +1,34 @@ +@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); + +raylib :: @c_library("/lib/libraylib.so.5.5.0"); +InitWindow :: @c_function(raylib,"InitWindow",(i32,i32,*u8)->void); +WindowShouldClose :: @c_function(raylib,"WindowShouldClose",()->bool); +BeginDrawing :: @c_function(raylib,"BeginDrawing",()->void); +EndDrawing :: @c_function(raylib,"EndDrawing",()->void); +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"; - puts(&(b[0])); + str := &(b[0]); + puts(str); + screenWidth :i32: 800; + screenHeight :i32: 450; + InitWindow(screenWidth,screenHeight,str); + test := WindowShouldClose(); + while test == false { + BeginDrawing(); + ClearBackground(@cast(4294967295,u32)); + EndDrawing(); + test = WindowShouldClose(); + } + CloseWindow(); }; |