Skip to content

Commit

Permalink
[translation] Fix runtime::NO_SPID problem.
Browse files Browse the repository at this point in the history
1 compile error left for bin/osh_parse
  • Loading branch information
Andy Chu committed Nov 21, 2019
1 parent 8ea2408 commit 08c621b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/osh_parse.py
Expand Up @@ -18,7 +18,7 @@
from frontend import reader
from mycpp import mylib

from typing import List, Dict, Any, TYPE_CHECKING
from typing import List, Dict, TYPE_CHECKING
if TYPE_CHECKING:
from osh.cmd_parse import CommandParser
from pgen2.grammar import Grammar
Expand Down
7 changes: 0 additions & 7 deletions build/mycpp.sh
Expand Up @@ -124,13 +124,6 @@ osh-parse-preamble() {
echo '// osh_parse: TODO'

echo "$PGEN2_DEMO_PREAMBLE"

cat <<EOF
// HACK for a global constant.
namespace runtime {
int NO_SPID = -1;
}
EOF
}

osh-parse() {
Expand Down
22 changes: 19 additions & 3 deletions mycpp/mycpp_main.py
Expand Up @@ -58,12 +58,26 @@ def get_mypy_config(paths: List[str],


def ModulesToCompile(result, mod_names):
# HACK TO PUT asdl/runtime FIRST. It has runtime::SPID.
#
# Another fix is to hoist those to the declaration phase? Not sure if that
# makes sense.

# Somehow the MyPy builder reorders the modules.
for name, module in result.files.items():
if name == 'asdl.runtime':
yield name, module

for name, module in result.files.items():
# Only translate files that were mentioned on the command line
suffix = name.split('.')[-1]
if suffix not in mod_names:
continue

# Don't do it a second time!
if name == 'asdl.runtime':
continue

# Why do I get oil.asdl.tdop in addition to asdl.tdop? This seems to
# work.
if name.startswith('oil.'):
Expand Down Expand Up @@ -135,6 +149,11 @@ def main(argv):
pass1 = const_pass.Collect(result.types, const_lookup, const_code)

to_compile = list(ModulesToCompile(result, mod_names))

if 0:
for name, module in to_compile:
log('to_compile %s', name)

for name, module in to_compile:
pass1.visit_mypy_file(module)

Expand Down Expand Up @@ -183,9 +202,6 @@ def main(argv):
local_vars=local_vars, fmt_ids=fmt_ids)
p4.visit_mypy_file(module)

for name, module in to_compile:
log('to_compile: %s', name)


if __name__ == '__main__':
try:
Expand Down

0 comments on commit 08c621b

Please sign in to comment.