/
count.sh
executable file
·139 lines (109 loc) · 2.85 KB
/
count.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
#
# Count lines ofcode in various ways.
#
# Usage:
# ./count.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
filter-py() {
grep -E -v '__init__.py$|_test.py$'
}
# TODO: Sum up all the support material. It's more than Oil itself! Turn
# everything into an array. An hash table of arrays would be useful here.
all() {
echo 'BUILD AUTOMATION'
wc -l build/*.{sh,py} Makefile configure install | filter-py | sort --numeric
echo
echo 'TEST AUTOMATION'
wc -l test/*.{sh,py} | filter-py | sort --numeric
echo
echo 'RELEASE AUTOMATION'
wc -l scripts/release.sh | sort --numeric
echo
echo 'BENCHMARKS'
wc -l benchmarks/*.{sh,py,R} | sort --numeric
echo
echo 'SPEC TESTS'
wc -l spec/*.test.sh | sort --numeric
echo
echo 'GOLD TESTS'
wc -l gold/*.sh | sort --numeric
echo
echo 'ASDL'
wc -l asdl/{asdl_*,const,py_meta,encode,format}.py | sort --numeric
echo
echo 'CODE GENERATORS'
wc -l asdl/gen_*.py */*_gen.py | sort --numeric
echo
echo 'GENERATED CODE'
wc -l _devbuild/gen/*.{py,h} | sort --numeric
echo
echo 'TOOLS'
ls tools/*.py | filter-py | xargs wc -l | sort --numeric
echo
echo 'WEB'
ls web/*.js web/*/*.{js,py} | xargs wc -l | sort --numeric
echo
echo 'OTHER UNIT TESTS'
wc -l {build,test,asdl,tools}/*_test.py | sort --numeric
echo
echo 'OIL UNIT TESTS'
wc -l {osh,core,native,tools}/*_test.py | sort --numeric
echo
echo 'OIL'
{ ls {bin,osh,core}/*.py native/*.c osh/osh.asdl core/runtime.asdl; } |
filter-py | grep -E -v '_gen.py$|test_lib.py' |
xargs wc -l | sort --numeric
echo
return
# TODO: Import docs
echo 'DOCS'
wc -l README.md doc/* | sort --numeric
echo
}
# Just the parser
parser() {
# I'm counting brace detection/expansion here because it doesn't depend on
# runtime info.
echo 'Lexer/Parser'
wc -l osh/{*_parse.py,lex.py,parse_lib.py} core/{word,braces}.py | sort -n
echo
echo 'AST and IDs'
wc -l osh/osh.asdl core/id_kind.py | sort -n
echo
echo 'Common Algorithms'
wc -l core/{tdop,lexer}.py | sort -n
echo
echo 'Utilities'
wc -l core/{alloc,ui,reader}.py | sort -n
echo
}
# Stuff we might need to hand-port
parser-port() {
wc -l core/tdop.py osh/*_parse.py | sort -n
}
runtime() {
# NOTE: braces.py contains both parsing and runtime. It is a middle stage.
echo 'Core'
wc -l \
core/*_{exec,eval}.py core/{process,state}.py core/runtime.asdl | sort -n
echo
echo 'Builtins'
wc -l core/{builtin,test_builtin}.py
echo
echo 'Libraries'
wc -l core/{args,glob_}.py | sort -n
echo
}
# count instructions, for fun
instructions() {
# http://pepijndevos.nl/2016/08/24/x86-instruction-distribution.html
local bin=_tmp/oil
objdump -d $bin | cut -f3 | grep -oE "^[a-z]+" | sort | uniq -c | sort -n
}
imports() {
grep --no-filename import */*.py | sort | uniq -c | sort -n
}
"$@"