Commit e7418647 authored by Armin Rigo's avatar Armin Rigo

merge heads

parents 624e65ad 13826225
......@@ -54,3 +54,6 @@ Fix performance regression on ufunc(<scalar>, <scalar>) in numpy.
.. branch: pytest-25
Update our copies of py.test and pylib to versions 2.5.2 and 1.4.20,
respectively.
.. branch: split-ast-classes
Classes in the ast module are now distinct from structures used by the compiler.
This diff is collapsed.
from pypy.interpreter.astcompiler import ast
class TestAstToObject:
def test_types(self, space):
assert space.is_true(space.issubtype(
ast.get(space).w_Module, ast.get(space).w_mod))
def test_num(self, space):
value = space.wrap(42)
node = ast.Num(value, lineno=1, col_offset=1)
w_node = node.to_object(space)
assert space.getattr(w_node, space.wrap("n")) is value
def test_expr(self, space):
value = space.wrap(42)
node = ast.Num(value, lineno=1, col_offset=1)
expr = ast.Expr(node, lineno=1, col_offset=1)
w_node = expr.to_object(space)
# node.value.n
assert space.getattr(space.getattr(w_node, space.wrap("value")),
space.wrap("n")) is value
def test_operation(self, space):
val1 = ast.Num(space.wrap(1), lineno=1, col_offset=1)
val2 = ast.Num(space.wrap(2), lineno=1, col_offset=1)
node = ast.BinOp(left=val1, right=val2, op=ast.Add,
lineno=1, col_offset=1)
w_node = node.to_object(space)
w_op = space.getattr(w_node, space.wrap("op"))
assert space.isinstance_w(w_op, ast.get(space).w_operator)
def test_from_object(self, space):
value = space.wrap(42)
w_node = space.call_function(ast.get(space).w_Num)
space.setattr(w_node, space.wrap('n'), value)
space.setattr(w_node, space.wrap('lineno'), space.wrap(1))
space.setattr(w_node, space.wrap('col_offset'), space.wrap(1))
node = ast.Num.from_object(space, w_node)
assert node.n is value
def test_fields(self, space):
w_fields = space.getattr(ast.get(space).w_FunctionDef,
space.wrap("_fields"))
assert space.eq_w(w_fields, space.wrap(
('name', 'args', 'body', 'decorator_list')))
w_fields = space.getattr(ast.get(space).w_arguments,
space.wrap("_fields"))
assert space.eq_w(w_fields, space.wrap(
('args', 'vararg', 'kwarg', 'defaults')))
def test_attributes(self, space):
w_attrs = space.getattr(ast.get(space).w_FunctionDef,
space.wrap("_attributes"))
assert space.eq_w(w_attrs, space.wrap(('lineno', 'col_offset')))
......@@ -302,16 +302,7 @@ class VisitorBase(object):
meth = self._dispatch(object)
if meth is None:
return
try:
meth(object, *args)
except Exception, err:
print "Error visiting", repr(object)
print err
traceback.print_exc()
# XXX hack
if hasattr(self, 'file'):
self.file.flush()
os._exit(1)
meth(object, *args)
def _dispatch(self, object):
assert isinstance(object, AST), repr(object)
......
......@@ -39,9 +39,8 @@ in addition to any features explicitly specified.
space.wrap("compile() arg 3 must be 'exec' "
"or 'eval' or 'single'"))
if space.isinstance_w(w_source, space.gettypeobject(ast.AST.typedef)):
ast_node = space.interp_w(ast.mod, w_source)
ast_node.sync_app_attrs(space)
if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)):
ast_node = ast.mod.from_object(space, w_source)
code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
return space.wrap(code)
......@@ -60,10 +59,11 @@ in addition to any features explicitly specified.
"compile() expected string without null bytes"))
if flags & consts.PyCF_ONLY_AST:
code = ec.compiler.compile_to_ast(source, filename, mode, flags)
node = ec.compiler.compile_to_ast(source, filename, mode, flags)
return node.to_object(space)
else:
code = ec.compiler.compile(source, filename, mode, flags)
return space.wrap(code)
return space.wrap(code)
def eval(space, w_code, w_globals=None, w_locals=None):
......
......@@ -15,7 +15,7 @@ class Module(MixedModule):
def _setup():
defs = Module.interpleveldefs
for name, cls in ast.__dict__.iteritems():
if isinstance(cls, type) and issubclass(cls, ast.AST):
defs[name.lstrip("_")] = cls.__module__ + "." + name
defs['AST'] = "pypy.interpreter.astcompiler.ast.get(space).w_AST"
for (name, base, fields, attributes) in ast.State.AST_TYPES:
defs[name] = "pypy.interpreter.astcompiler.ast.get(space).w_" + name
_setup()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment