diff options
Diffstat (limited to 'project')
-rwxr-xr-x | project | 87 |
1 files changed, 87 insertions, 0 deletions
@@ -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 "$@" |