aboutsummaryrefslogtreecommitdiff
path: root/project
blob: 4c91deb6bec765efce2d9d99342e3e4092e24135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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
  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 $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" "$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 "$@"