Permalink
Please sign in to comment.
Browse files
Progress toward migrating away from asdl/py_meta.py.
Not quite done yet. Equality and pretty printing of still need to be handled by asdl/gen_python.py. - Profile running abuild -h. These will eventually be osh runtime benchmarks. - Fix osh/lex_test.py
- Loading branch information...
Showing
with
96 additions
and 25 deletions.
- +43 −0 asdl/asdl_base.py
- +11 −23 asdl/gen_python.py
- +10 −1 benchmarks/pytrace.sh
- +31 −0 core/test_lib.py
- +1 −1 osh/lex_test.py
| @@ -0,0 +1,43 @@ | ||
| #!/usr/bin/python | ||
| """ | ||
| asdl_base.py | ||
| Base classes for generated code. | ||
| """ | ||
| import io | ||
| from core import util | ||
| # Copied from py_meta | ||
| class Obj(object): | ||
| # NOTE: We're using CAPS for these static fields, since they are constant at | ||
| # runtime after metaprogramming. | ||
| DESCRIPTOR = None # Used for type checking | ||
| class SimpleObj(Obj): | ||
| def __init__(self, enum_id, name): | ||
| self.enum_id = enum_id | ||
| self.name = name | ||
| def __repr__(self): | ||
| return '<%s %s %s>' % (self.__class__.__name__, self.name, self.enum_id) | ||
| class CompoundObj(Obj): | ||
| FIELDS = [] # ordered list of field names, overriden | ||
| DESCRIPTOR_LOOKUP = {} # field name: (asdl.Sum | asdl.Product | ...) | ||
| """ | ||
| def __repr__(self): | ||
| # Breaking circular dependency, gah. | ||
| from asdl import format as fmt | ||
| ast_f = fmt.TextOutput(util.Buffer()) # No color by default. | ||
| ast_f = fmt.AnsiOutput(io.StringIO()) | ||
| tree = fmt.MakeTree(self) | ||
| fmt.PrintTree(tree, ast_f) | ||
| s, _ = ast_f.GetRaw() | ||
| return s | ||
| """ |
0 comments on commit
8ba80cb