Skip to content

Commit

Permalink
[demo] Work on an even smaller slice of CPython.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jan 9, 2020
1 parent 07405fc commit aa69c62
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,6 @@ count-c-lines() {
popd
}

"$@"
if test $(basename $0) = 'compile.sh'; then
"$@"
fi
186 changes: 186 additions & 0 deletions build/slice-2020.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/bin/bash
#
# Usage:
# ./slice-2020.sh <function name>

CFLAGS='-O0' # for speed

source build/compile.sh

set -o nounset
set -o pipefail
set -o errexit


_OVM_PYTHON_OBJS='
Python/_warnings.c
Python/bltinmodule.c
Python/ceval.c
Python/errors.c
Python/getargs.c
Python/getcompiler.c
Python/getplatform.c
Python/getversion.c
Python/import.c
Python/marshal.c
Python/modsupport.c
Python/mystrtoul.c
Python/mysnprintf.c
Python/pyarena.c
Python/pyctype.c
Python/pyfpe.c
Python/pystate.c
Python/pythonrun.c
Python/random.c
Python/structmember.c
Python/sysmodule.c
Python/traceback.c
Python/pystrtod.c
Python/dtoa.c
Python/pymath.c
'
# NOTE: pystrtod.c needs some floating point functions in pymath.c

_OBJECT_OBJS='
Objects/abstract.c
Objects/boolobject.c
Objects/bufferobject.c
Objects/bytes_methods.c
Objects/capsule.c
Objects/cellobject.c
Objects/classobject.c
Objects/cobject.c
Objects/codeobject.c
Objects/descrobject.c
Objects/enumobject.c
Objects/exceptions.c
Objects/genobject.c
Objects/fileobject.c
Objects/floatobject.c
Objects/frameobject.c
Objects/funcobject.c
Objects/intobject.c
Objects/iterobject.c
Objects/listobject.c
Objects/longobject.c
Objects/dictobject.c
Objects/methodobject.c
Objects/moduleobject.c
Objects/object.c
Objects/obmalloc.c
Objects/rangeobject.c
Objects/setobject.c
Objects/sliceobject.c
Objects/stringobject.c
Objects/structseq.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/weakrefobject.c
'

# Non-standard lib stuff.
_MODULE_OBJS='
Modules/gcmodule.c
'

# The stuff in Modules/Setup.dist, signalmodule.c. NOTE: In Python,
# signalmodule.c is specified in Modules/Setup.config, which comes from
# 'configure' output.
_MODOBJS='
Modules/errnomodule.c
Modules/_weakref.c
Modules/zipimport.c
Modules/signalmodule.c
'

# Parser/myreadline.c is needed for raw_input() to work. There is a dependency
# from Python/bltinmodule.c to it.
_OVM_LIBRARY_OBJS="
Modules/getbuildinfo.c
Parser/myreadline.c
$_OBJECT_OBJS
$_OVM_PYTHON_OBJS
$_MODULE_OBJS
$_MODOBJS
"

demo() {
local abs_out=$PWD/_tmp/demo
local main=$PWD/demo/py_object_main.c

# From ./configure
#local PREFIX=/usr/local

# HAVE_READLINE defined in detected-config.sh.
source-detected-config-or-die


pushd $PY27

# Note: all this defines MAIN_NAME and so forth.
#
# We want to get rid of ALL modules I suppose. Man that's a bunch of work.
# We're going to ONLY use objects.
#
# $abs_module_init \
# $abs_main_name \
# $c_module_src_list \

time $CC \
${BASE_CFLAGS} \
${CFLAGS} \
"${INCLUDE_PATHS[@]}" \
"${PREPROC_FLAGS[@]}" \
-D PREFIX="\"$PREFIX\"" \
-D EXEC_PREFIX="\"$PREFIX\"" \
-o $abs_out \
$_OVM_LIBRARY_OBJS \
$main \
-l m \
${BASE_LDFLAGS} \
${LDFLAGS} \
"$@" || true
}

# 35K lines of .c files, and 40K lines with headers
# of course we have some other dependencies like math and string libs.
source-files() {
egrep -v 'class|frame|set' <<EOF
Objects/boolobject.c
Objects/cellobject.c
Objects/classobject.c
Objects/cobject.c
Objects/enumobject.c
Objects/genobject.c
Objects/fileobject.c
Objects/floatobject.c
Objects/frameobject.c
Objects/funcobject.c
Objects/iterobject.c
Objects/listobject.c
Objects/longobject.c
Objects/dictobject.c
Objects/methodobject.c
Objects/moduleobject.c
Objects/object.c
Objects/rangeobject.c
Objects/setobject.c
Objects/sliceobject.c
Objects/stringobject.c
Objects/tupleobject.c
Objects/typeobject.c
EOF
#return

# These are mostly small
for f in Include/*object.h; do
echo $f
done
}

count() {
pushd $PY27
source-files | xargs wc -l | sort -n
}

"$@"
15 changes: 15 additions & 0 deletions demo/py_object_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Python.h"

struct _inittab _PyImport_Inittab[] = {
/* Sentinel */
{0, 0}
};


int main(int argc, char **argv) {
// TODO:
// - Create all types
// - Create objects of each type
// - Perform operations on them
return 42;
}

0 comments on commit aa69c62

Please sign in to comment.