#!/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/ -g \ ./src/main.c \ ./src/compiler/source_code/source_code.c \ ./src/compiler/error_helper/error_helper.c \ ./src/compiler/lexer/lexer.c \ ./src/compiler/parser/parser.c \ ./src/compiler/tree_parser/tree_parser.c \ ./src/compiler/code_generator/code_generator.c \ ./src/compiler/fasm_generator/fasm_generator.c \ ./src/fasm/lexer/lexer.c \ ./src/fasm/linker/linker.c \ ./src/fasm/code_generator/code_generator.c \ ./src/fasm/runner/runner.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 local RED='\033[0;31m' local GREEN='\033[0;32m' local NC='\033[0m' for file_path in ./test/input/*; do local file_name=$(basename "$file_path") local start=`date +%s.%N` local ret=$(eval "./build/$project_name run-felan $file_path > ./test/generated_output/$file_name") local end=`date +%s.%N` runtime="$(jq -n $end-$start)" $ret && \ cmp --silent "./test/generated_output/$file_name" "./test/output/$file_name" && \ printf "${GREEN}PASSED${NC} %.9fs $file_path\n" $runtime || \ printf "${RED}FAILED${NC} %.9fs $file_path\n" $runtime done } function val_test(){ clean && compile if [ $? -ne 0 ]; then echo "compile error" exit fi local RED='\033[0;31m' local GREEN='\033[0;32m' local NC='\033[0m' 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" run-felan "$file_path" ./test/generated_output/ && \ cmp --silent "./test/generated_output/$file_name" "./test/output/$file_name" && \ printf "${GREEN}PASSED${NC} $file_path\n" || \ printf "${RED}FAILED${NC} $file_path\n" 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 "$@"