View
@@ -11,15 +11,22 @@
from osh.meta import Id, Kind, ast, ID_SPEC
"""
import os
from asdl import asdl_ as asdl
from core import id_kind
# TODO: Remove this dependency!
from asdl import front_end
from asdl import py_meta
_BOOTSTRAP_LEVEL = int(os.getenv('BOOTSTRAP_LEVEL', '3'))
from core import id_kind
from core import util
# TODO: Get rid of this hack.
def _AssignTypes(src_module, dest_module):
"""For generated code."""
for name in dir(src_module):
if not name.startswith('__'):
v = getattr(src_module, name)
setattr(dest_module, name, v)
class Id(object):
@@ -78,21 +85,9 @@ def IdInstance(i):
# Instantiate osh/types.asdl
#
f = util.GetResourceLoader().open('osh/types.asdl')
_schema_ast, _type_lookup = front_end.LoadSchema(f, {}) # no app_types
types = _AsdlModule()
if 0:
py_meta.MakeTypes(_schema_ast, types, _type_lookup)
else:
# Exported for the generated code to use
TYPES_TYPE_LOOKUP = _type_lookup
# Get the types from elsewhere
from _devbuild.gen import types_asdl
py_meta.AssignTypes(types_asdl, types)
f.close()
from _devbuild.gen import types_asdl
_AssignTypes(types_asdl, types)
# Id -> bool_arg_type_e
@@ -105,7 +100,7 @@ def IdInstance(i):
#
# Instantiate the spec
# Add attributes to Id and Kind
#
ID_SPEC = id_kind.IdSpec(Id, Kind,
@@ -114,6 +109,8 @@ def IdInstance(i):
id_kind.AddKinds(ID_SPEC)
id_kind.AddBoolKinds(ID_SPEC, Id, types.bool_arg_type_e) # must come second
# NOTE: Dependency on the types module here. This is the root cause of the
# _BOOTSTRAP_LEVEL hack.
id_kind.SetupTestBuiltin(Id, Kind, ID_SPEC,
TEST_UNARY_LOOKUP, TEST_BINARY_LOOKUP,
TEST_OTHER_LOOKUP,
@@ -123,47 +120,23 @@ def IdInstance(i):
_kind_sizes = ID_SPEC.kind_sizes
APP_TYPES = {'id': asdl.UserType(Id)}
#
# Instantiate osh/osh.asdl
#
f = util.GetResourceLoader().open('osh/osh.asdl')
_schema_ast, _type_lookup = front_end.LoadSchema(f, APP_TYPES)
ast = _AsdlModule()
if 0:
py_meta.MakeTypes(_schema_ast, ast, _type_lookup)
else:
# Exported for the generated code to use
OSH_TYPE_LOOKUP = _type_lookup
# Get the types from elsewhere
if _BOOTSTRAP_LEVEL > 1:
ast = _AsdlModule()
from _devbuild.gen import osh_asdl
py_meta.AssignTypes(osh_asdl, ast)
f.close()
_AssignTypes(osh_asdl, ast)
#
# Instantiate core/runtime.asdl
#
f = util.GetResourceLoader().open('core/runtime.asdl')
_schema_ast, _type_lookup = front_end.LoadSchema(f, APP_TYPES)
runtime = _AsdlModule()
if 0:
py_meta.MakeTypes(_schema_ast, runtime, _type_lookup)
else:
# Exported for the generated code to use
RUNTIME_TYPE_LOOKUP = _type_lookup
# Get the types from elsewhere
if _BOOTSTRAP_LEVEL > 2:
runtime = _AsdlModule()
from _devbuild.gen import runtime_asdl
py_meta.AssignTypes(runtime_asdl, runtime)
f.close()
_AssignTypes(runtime_asdl, runtime)
#
# Redirect Tables associated with IDs
View
@@ -84,7 +84,8 @@ all() {
echo
echo 'ASDL'
wc -l asdl/{asdl_*,const,py_meta,encode,format}.py | sort --numeric
ls asdl/*.py | filter-py | grep -v -E 'arith_|tdop|_demo' |
xargs wc -l | sort --numeric
echo
echo 'CODE GENERATORS'