Skip to content

Commit

Permalink
Fold the core/runtime.py loader into osh/meta.py.
Browse files Browse the repository at this point in the history
This makes ASDL loading more consistent.
  • Loading branch information
Andy Chu committed Feb 7, 2018
1 parent 42fa8d7 commit 723b8ba
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 64 deletions.
6 changes: 3 additions & 3 deletions asdl/gen_python.py
Expand Up @@ -110,7 +110,7 @@ def EmitFooter(self):
def main(argv):

schema_path = argv[1]
type_lookup_module = argv[2]
type_lookup_import = argv[2]
with open(schema_path) as input_f:
module = asdl.parse(input_f)

Expand All @@ -119,9 +119,9 @@ def main(argv):
f.write("""\
from asdl import const # For const.NO_INTEGER
from asdl import py_meta
from %s import TYPE_LOOKUP
%s
""" % type_lookup_module)
""" % type_lookup_import)

v = GenClassesVisitor(f)
v.VisitModule(module)
Expand Down
6 changes: 4 additions & 2 deletions build/dev.sh
Expand Up @@ -33,13 +33,15 @@ gen-help() {

gen-osh-asdl() {
local out=_devbuild/gen/osh_asdl.py
PYTHONPATH=. asdl/gen_python.py osh/osh.asdl 'osh.meta' > $out
local import='from osh.meta import OSH_TYPE_LOOKUP as TYPE_LOOKUP'
PYTHONPATH=. asdl/gen_python.py osh/osh.asdl "$import" > $out
echo "Wrote $out"
}

gen-runtime-asdl() {
local out=_devbuild/gen/runtime_asdl.py
PYTHONPATH=. asdl/gen_python.py core/runtime.asdl 'core.runtime' > $out
local import='from osh.meta import RUNTIME_TYPE_LOOKUP as TYPE_LOOKUP'
PYTHONPATH=. asdl/gen_python.py core/runtime.asdl "$import" > $out
echo "Wrote $out"
}

Expand Down
2 changes: 1 addition & 1 deletion core/builtin.py
Expand Up @@ -31,7 +31,7 @@

from core import args
from core import lexer
from core import runtime
from osh.meta import runtime
from core import util
from core import state
from core import word_compile
Expand Down
2 changes: 1 addition & 1 deletion core/cmd_exec.py
Expand Up @@ -35,7 +35,7 @@
from core import util
from core import builtin
from core import process
from core import runtime
from osh.meta import runtime
from core import state
from core import word_compile

Expand Down
2 changes: 1 addition & 1 deletion core/completion.py
Expand Up @@ -38,7 +38,7 @@
from osh.meta import ast
from osh import parse_lib
from core import alloc
from core import runtime
from osh.meta import runtime
from core import state
from core import ui
from core import util
Expand Down
2 changes: 1 addition & 1 deletion core/expr_eval.py
Expand Up @@ -20,7 +20,7 @@
from osh.meta import BOOL_OPS, Id
from core.id_kind import OperandType
from core import util
from core import runtime
from osh.meta import runtime

from osh.meta import ast

Expand Down
2 changes: 1 addition & 1 deletion core/legacy.py
Expand Up @@ -37,7 +37,7 @@
}
"""

from core import runtime
from osh.meta import runtime
from core import util

value_e = runtime.value_e
Expand Down
2 changes: 1 addition & 1 deletion core/process.py
Expand Up @@ -16,7 +16,7 @@
import os
import sys

from core import runtime
from osh.meta import runtime
from core import util
from osh.meta import Id

Expand Down
2 changes: 1 addition & 1 deletion core/process_test.py
Expand Up @@ -11,7 +11,7 @@
from osh.meta import ast

from core import process # module under test
from core import runtime
from osh.meta import runtime
from core import util
from core.cmd_exec_test import InitExecutor # helper

Expand Down
43 changes: 0 additions & 43 deletions core/runtime.py

This file was deleted.

2 changes: 1 addition & 1 deletion core/state.py
Expand Up @@ -15,7 +15,7 @@

from core import args
from core import legacy
from core import runtime
from osh.meta import runtime
from core import util
from osh.meta import Id

Expand Down
2 changes: 1 addition & 1 deletion core/state_test.py
Expand Up @@ -5,7 +5,7 @@

import unittest

from core import runtime
from osh.meta import runtime
from core import state # module under test
from core import util
from core import test_lib
Expand Down
2 changes: 1 addition & 1 deletion core/test_builtin.py
Expand Up @@ -8,7 +8,7 @@

from core import id_kind
from core import expr_eval
from core import runtime
from osh.meta import runtime
from core import util

from osh import bool_parse
Expand Down
2 changes: 1 addition & 1 deletion core/word_compile.py
Expand Up @@ -7,7 +7,7 @@
"""

from osh.meta import Id
from core import runtime
from osh.meta import runtime

var_flags_e = runtime.var_flags_e

Expand Down
2 changes: 1 addition & 1 deletion core/word_eval.py
Expand Up @@ -10,7 +10,7 @@
from core import libstr
from core import glob_
from osh.meta import Id, Kind, LookupKind
from core import runtime
from osh.meta import runtime
from core import state
from core import word_compile
from core import util
Expand Down
27 changes: 24 additions & 3 deletions osh/meta.py
Expand Up @@ -102,27 +102,48 @@ def IdInstance(i):
_kind_sizes = ID_SPEC.kind_sizes


APP_TYPES = {'id': asdl.UserType(Id)}

#
# Instantiate the AST
#

f = util.GetResourceLoader().open('osh/osh.asdl')
app_types = {'id': asdl.UserType(Id)}
_asdl_module, _type_lookup = asdl.LoadSchema(f, app_types)
_asdl_module, _type_lookup = asdl.LoadSchema(f, APP_TYPES)

ast = _AsdlModule()
if 0:
py_meta.MakeTypes(_asdl_module, ast, _type_lookup)
else:
# Exported for the generated code to use
TYPE_LOOKUP = _type_lookup
OSH_TYPE_LOOKUP = _type_lookup

# Get the types from elsewhere
from _devbuild.gen import osh_asdl
py_meta.AssignTypes(osh_asdl, ast)

f.close()

#
# Instantiate runtime
#

f = util.GetResourceLoader().open('core/runtime.asdl')
_asdl_module, _type_lookup = asdl.LoadSchema(f, APP_TYPES)

runtime = _AsdlModule()
if 0:
py_meta.MakeTypes(module, runtime, _type_lookup)
else:
# Exported for the generated code to use
RUNTIME_TYPE_LOOKUP = _type_lookup

# Get the types from elsewhere
from _devbuild.gen import runtime_asdl
py_meta.AssignTypes(runtime_asdl, runtime)

f.close()


#
# Redirect Tables associated with IDs
Expand Down
3 changes: 2 additions & 1 deletion scripts/refactor.sh
Expand Up @@ -55,7 +55,8 @@ replace() {

replace2() {
#sed -r -i "s/^from core.id_kind import/from osh.meta import/g" */*.py
sed -r -i "s/^from osh import ast_ as ast/from osh.meta import ast/g" */*.py
#sed -r -i "s/^from osh import ast_ as ast/from osh.meta import ast/g" */*.py
sed -r -i "s/^from core import runtime/from osh.meta import runtime/g" */*.py
}

trailing-ws() {
Expand Down

0 comments on commit 723b8ba

Please sign in to comment.