From d6ba30b94a24607bce5db5e706eb20cc051a98f0 Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 18 Sep 2024 19:46:38 +0330 Subject: initial commit --- project | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 project (limited to 'project') 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 "$@" -- cgit v1.2.3