aboutsummaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2024-09-18 19:46:38 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2024-09-18 19:57:20 +0330
commitd6ba30b94a24607bce5db5e706eb20cc051a98f0 (patch)
tree146e74b0bc2e1636451257015210e3c7d1a0ecab /project
initial commit
Diffstat (limited to 'project')
-rwxr-xr-xproject87
1 files changed, 87 insertions, 0 deletions
diff --git a/project b/project
new file mode 100755
index 0000000..f642cb3
--- /dev/null
+++ b/project
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+project_name="felan"
+
+function compile(){
+ if [ ! -d build ]; then
+ if [ $(mkdir build) ]; then # if error
+ echo "cannot make 'build' dir"
+ exit
+ fi
+ fi
+
+ gcc -Wall -Wextra -std=gnu23 -I./src/ -O3 \
+ ./src/main.c \
+ ./src/compiler/lexer/lexer.c \
+ ./src/compiler/parser/parser.c \
+ ./src/compiler/code_generator/code_generator.c \
+ ./src/vm/runner/runner.c \
+ ./src/utils/memory/memory.c \
+ ./src/utils/file.c \
+ ./src/utils/time.c \
+ -o "build/$project_name"
+}
+
+function run(){
+ compile && "./build/$project_name" "$@"
+ printf "\n$?\n"
+}
+
+function make_lsp_files(){
+ bear -- ./project compile
+}
+
+function clean(){
+ if [ -d ./build ]; then
+ rm -r ./build/
+ fi
+ if [ "$(ls ./test/generated_output/)" ]; then
+ rm -r ./test/generated_output/*
+ fi
+}
+
+function test(){
+ clean && compile
+ if [ $? -ne 0 ]; then
+ echo "compile error"
+ exit
+ fi
+
+ for file_path in ./test/input/*; do
+ local file_name=$(basename "$file_path")
+ local start=`date +%s.%N`
+ local ret=$(eval "./build/$project_name $file_path > ./test/generated_output/$file_name")
+ local end=`date +%s.%N`
+ echo "$(jq -n $end-$start)s"
+ $ret && \
+ cmp --silent "./test/generated_output/$file_name" "./test/output/$file_name" && \
+ echo "PASSED $file_path" || \
+ echo "FAILED $file_path"
+ done
+}
+
+function val_test(){
+ clean && compile
+ if [ $? -ne 0 ]; then
+ echo "compile error"
+ exit
+ fi
+
+ for file_path in ./test/input/*; do
+ local file_name=$(basename "$file_path")
+ valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all -s "./build/$project_name" "$file_path" ./test/generated_output/ && \
+ cmp --silent "./test/generated_output/$file_name" "./test/output/$file_name" && \
+ echo "PASSED $file_path" || \
+ echo "FAILED $file_path"
+ done
+}
+
+function val_run(){
+ compile && valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all -s "./build/$project_name" "$@"
+ printf "\n$?\n"
+}
+
+function_name="$1"
+shift
+
+$function_name "$@"