diff options
author | Thomas Wouters <thomas@python.org> | 2006-03-03 18:16:20 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2006-03-03 18:16:20 (GMT) |
commit | fa0cf4f3ae1c4eac0a6d45af89fcbcecc62f910c (patch) | |
tree | a3081b1644348af2f32b643964a02c895c99111b /Lib/compiler/ast.py | |
parent | 7e2ac2533eb7279ccff193f8cffe94abd1dfa83f (diff) | |
download | cpython-fa0cf4f3ae1c4eac0a6d45af89fcbcecc62f910c.zip cpython-fa0cf4f3ae1c4eac0a6d45af89fcbcecc62f910c.tar.gz cpython-fa0cf4f3ae1c4eac0a6d45af89fcbcecc62f910c.tar.bz2 |
Add support for absolute/relative imports and if/else expressions:
- regenerate ast.py
- add future flags for absolute-import and with-statement so they
(hopefully) properly get set in code-object flags
- try out if/else expressions in actual code for the hell of it.
Seems to generate the same kind of bytecode as the normal compiler.
Diffstat (limited to 'Lib/compiler/ast.py')
-rw-r--r-- | Lib/compiler/ast.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py index 6e3e182..7d1c18f 100644 --- a/Lib/compiler/ast.py +++ b/Lib/compiler/ast.py @@ -524,19 +524,20 @@ class For(Node): return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_)) class From(Node): - def __init__(self, modname, names, lineno=None): + def __init__(self, modname, names, level, lineno=None): self.modname = modname self.names = names + self.level = level self.lineno = lineno def getChildren(self): - return self.modname, self.names + return self.modname, self.names, self.level def getChildNodes(self): return () def __repr__(self): - return "From(%s, %s)" % (repr(self.modname), repr(self.names)) + return "From(%s, %s, %s)" % (repr(self.modname), repr(self.names), repr(self.level)) class Function(Node): def __init__(self, decorators, name, argnames, defaults, flags, doc, code, lineno=None): @@ -553,7 +554,7 @@ class Function(Node): self.varargs = 1 if flags & CO_VARKEYWORDS: self.kwargs = 1 - + def getChildren(self): @@ -584,7 +585,7 @@ class GenExpr(Node): self.lineno = lineno self.argnames = ['[outmost-iterable]'] self.varargs = self.kwargs = None - + def getChildren(self): @@ -708,6 +709,22 @@ class If(Node): def __repr__(self): return "If(%s, %s)" % (repr(self.tests), repr(self.else_)) +class IfExp(Node): + def __init__(self, test, then, else_, lineno=None): + self.test = test + self.then = then + self.else_ = else_ + self.lineno = lineno + + def getChildren(self): + return self.test, self.then, self.else_ + + def getChildNodes(self): + return self.test, self.then, self.else_ + + def __repr__(self): + return "IfExp(%s, %s, %s)" % (repr(self.test), repr(self.then), repr(self.else_)) + class Import(Node): def __init__(self, names, lineno=None): self.names = names @@ -763,7 +780,7 @@ class Lambda(Node): self.varargs = 1 if flags & CO_VARKEYWORDS: self.kwargs = 1 - + def getChildren(self): |