This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·153 lines (124 loc) · 3.15 KB
/
run.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
#
# Usage:
# ./run.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
readonly PY27='Python-2.7.13'
readonly CC=${CC:-cc} # cc should be on POSIX systems
readonly BASE_CFLAGS='-fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes'
readonly INCLUDE_PATHS=(-I . -I Include)
readonly EMPTY_STR='""'
# Using OVM_SLICE instead of OVM_MAIN
# Stub out a few variables
readonly PREPROC_FLAGS=(
-D OVM_SLICE \
-D PYTHONPATH="$EMPTY_STR" \
-D VERSION="$EMPTY_STR" \
-D VPATH="$EMPTY_STR" \
-D Py_BUILD_CORE \
# Python already has support for disabling complex numbers!
-D WITHOUT_COMPLEX
)
readonly PREFIX=/usr/local
_build() {
mkdir -p _tmp
local out=$PWD/_tmp/ovm2
pushd $PY27
time $CC \
${BASE_CFLAGS} \
"${INCLUDE_PATHS[@]}" \
"${PREPROC_FLAGS[@]}" \
-D PREFIX="\"$PREFIX\"" \
-D EXEC_PREFIX="\"$PREFIX\"" \
-o $out \
-l m \
"$@"
popd
}
# Starting with longobject.c
# - It needs its typeobject.c -- do NOT want this. 6800 lines of the
# meta-object protocol.
# - It needs errors.c, which needs exceptions.c
# - exceptions seems to need dicts
# - dicts need garbage collection!
# Problem: I really want just a basic arbitrarily sized int, without
# reflection, subclassing, etc. No garbage collection either?
# Other stuff we might need:
# - ref counting
# - garbage collection
# - slices? Or could we reimplement that without the generic objects?
# - Stuff for the C API, e.g. args.c
# - TODO: Test native/libc.c, which mostly uses PyArg_ParseTuple() etc.
# Excluded:
# - classobject.c (old style and new style)
# - fileobject.c
# - for now: floats (brings in float to string conversion, etc.)
# - descriptors
# What about: bool? This is just int?
#Python/marshal.c \
#Objects/codeobject.c \
#Objects/typeobject.c
#Objects/weakrefobject.c # needed for gcmodule.c?
# NOTE: boolobject.c isn't technically necessary, but it's an easy way to
# reduce the number of link errors.
readonly FILES=(
Objects/longobject.c
# float causes more link errors?
#Objects/floatobject.c
Objects/boolobject.c
Objects/stringobject.c
Objects/dictobject.c
# set causes more link errors?
#Objects/setobject.c
Objects/listobject.c
Objects/sliceobject.c
Objects/tupleobject.c
Objects/object.c
Objects/abstract.c
Objects/exceptions.c
Objects/obmalloc.c
Python/errors.c
Python/mysnprintf.c
Python/sigcheck.c
Python/modsupport.c
Python/getargs.c
Modules/gcmodule.c
../ovm.c
)
build() {
local out=_tmp/build.log
set +o errexit
_build "${FILES[@]}" 2>&1 | tee $out
echo
wc -l $out
count-undefined $out
}
# link errors: undefined reference
count-undefined() {
egrep -o 'undefined reference to `.*' "$@" > _tmp/undefined.txt
cat _tmp/undefined.txt | sort | uniq -c | sort -n
echo
wc -l _tmp/undefined.txt
}
count() {
pushd $PY27 >/dev/null
wc -l "${FILES[@]}" | sort -n
popd >/dev/null
}
tag() {
pushd $PY27
ctags */*.[ch]
popd
}
grep-all() {
grep "$@" $PY27/{Python,Modules,Objects}/*.[ch]
}
grep-subset() {
local pat=$1
pushd $PY27 >/dev/null
grep "$@" "${FILES[@]}"
popd >/dev/null
}
"$@"