Skip to content

Commit

Permalink
[test/syscall] Measured number of processes to run CPython configure
Browse files Browse the repository at this point in the history
osh matches dash, and bash is only 4 processes more.  So not much to
optimize.

Unrelated: misc refactoring for translation.
  • Loading branch information
Andy Chu committed Apr 21, 2020
1 parent 41b2367 commit 9662848
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
3 changes: 1 addition & 2 deletions bin/osh_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def main(argv):
cmd_ev.tracer = tracer
cmd_ev.shell_ex = ex

if 0:
cmd_ev.ExecuteAndCatch(node)
cmd_ev.ExecuteAndCatch(node)

return 0

Expand Down
2 changes: 1 addition & 1 deletion frontend/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
VISIBLE_SHOPT_NAMES = option_def.VISIBLE_SHOPT_NAMES
PARSE_OPTION_NAMES = option_def.PARSE_OPTION_NAMES

BUILTIN_NAMES = builtin_def.BUILTIN_NAMES
BUILTIN_NAMES = builtin_def.BUILTIN_NAMES # Used by builtin_comp.py


def GetKind(id_):
Expand Down
27 changes: 15 additions & 12 deletions frontend/consts_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys

from frontend import id_kind_def
from frontend import builtin_def


def _CreateModule(id_spec, ids):
Expand All @@ -33,6 +34,15 @@ def _CreateModule(id_spec, ids):
return schema_ast


def GenBuiltinLookup(b, func_name, kind, f):
f.write("""\
builtin_t %s(Str* s) {
assert(0);
}
""" % func_name)


def main(argv):
try:
action = argv[1]
Expand Down Expand Up @@ -260,20 +270,13 @@ def out(fmt, *args):
}
}
""")
out("""\
builtin_t LookupNormalBuiltin(Str* s) {
assert(0);
}
builtin_t LookupAssignBuiltin(Str* s) {
assert(0);
}

builtin_t LookupSpecialBuiltin(Str* s) {
assert(0);
}
b = builtin_def.BuiltinDict()
GenBuiltinLookup(b, 'LookupNormalBuiltin', 'normal', f)
GenBuiltinLookup(b, 'LookupAssignBuiltin', 'assign', f)
GenBuiltinLookup(b, 'LookupSpecialBuiltin', 'special', f)

out("""\
Tuple2<runtime_asdl::state_t, runtime_asdl::emit_t> IfsEdge(runtime_asdl::state_t state, runtime_asdl::char_kind_t ch) {
assert(0);
}
Expand Down
9 changes: 7 additions & 2 deletions frontend/lexer_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,14 @@ def main(argv):
pairs = [(opt.name, opt.index) for opt in option_def.All()]
StringToInt('MatchOption', pairs)

# TODO: Don't need this?
# I think consts::LookupAssignBuiltin should be moved to
# match::LookupAssignBuiltin
# And generated right here.

# e.g. "echo" -> builtin_i::echo
pairs = [(b.name, b.index) for b in builtin_def.All()]
StringToInt('MatchBuiltin', pairs)
#pairs = [(b.name, b.index) for b in builtin_def.All()]
#StringToInt('MatchBuiltin', pairs)

TranslateRegexToPredicate(lexer_def.VAR_NAME_RE, 'IsValidVarName')
TranslateRegexToPredicate(lexer_def.SHOULD_HIJACK_RE, 'ShouldHijack')
Expand Down
31 changes: 31 additions & 0 deletions test/syscall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,36 @@ run-for-release() {
echo 'OK'
}

#
# Real World
#
# $ ls|grep dash|wc -l
# 6098
# $ ls|grep bash|wc -l
# 6102
# $ ls|grep osh|wc -l
# 6098
#
# So Oil is already at dash level for CPython's configure, and bash isn't
# far off. So autoconf-generated scripts probably already use constructs
# that are already "optimal" in most shells.

readonly PY27_DIR=$PWD/Python-2.7.13

cpython-configure() {
local raw_dir=$PWD/$RAW_DIR/real
mkdir -p $raw_dir

pushd $PY27_DIR
#for sh in "${SHELLS[@]}"; do
for sh in bash dash osh; do
local out_prefix=$raw_dir/cpython-$sh
echo "--- $sh"

# TODO: Use a different dir
count-procs $out_prefix $sh -c './configure'
done
popd
}

"$@"

0 comments on commit 9662848

Please sign in to comment.