[pypy-commit] pypy py3.3: merge py3k
pjenvey
noreply at buildbot.pypy.org
Tue Aug 26 23:22:41 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3.3
Changeset: r73077:664cef61a119
Date: 2014-08-26 14:22 -0700
http://bitbucket.org/pypy/pypy/changeset/664cef61a119/
Log: merge py3k
diff too long, truncating to 2000 out of 11591 lines
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -354,6 +354,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-Detailled license information is contained in the NOTICE file in the
+Detailed license information is contained in the NOTICE file in the
directory.
diff --git a/lib_pypy/pyrepl/reader.py b/lib_pypy/pyrepl/reader.py
--- a/lib_pypy/pyrepl/reader.py
+++ b/lib_pypy/pyrepl/reader.py
@@ -101,7 +101,7 @@
st = {}
for c in map(unichr, range(256)):
st[c] = SYNTAX_SYMBOL
- for c in [a for a in map(unichr, range(256)) if a.isalpha()]:
+ for c in [a for a in map(unichr, range(256)) if a.isalnum()]:
st[c] = SYNTAX_WORD
st[unicode('\n')] = st[unicode(' ')] = SYNTAX_WHITESPACE
return st
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -54,3 +54,6 @@
.. 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.
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -37,7 +37,7 @@
using a 32 bit Python and vice versa. By default pypy is built using the
Multi-threaded DLL (/MD) runtime environment.
-**Note:** PyPy is currently not supported for 64 bit Windows, and translation
+**Note:** PyPy is currently not supported for 64 bit Python, and translation
will fail in this case.
Python and a C compiler are all you need to build pypy, but it will miss some
@@ -136,7 +136,7 @@
cd zlib-1.2.3
nmake -f win32\Makefile.msc
- copy zlib1.lib <somewhere in LIB>
+ copy zlib.lib <somewhere in LIB>
copy zlib.h zconf.h <somewhere in INCLUDE>
The bz2 compression library
@@ -165,27 +165,29 @@
directory. Version 2.1.0 is known to pass tests. Then open the project
file ``expat.dsw`` with Visual
Studio; follow the instruction for converting the project files,
-switch to the "Release" configuration, reconfigure the runtime for
-Multi-threaded DLL (/MD) and build the solution (the ``expat`` project
-is actually enough for pypy).
+switch to the "Release" configuration, use the ``expat_static`` project,
+reconfigure the runtime for Multi-threaded DLL (/MD) and build.
-Then, copy the file ``win32\bin\release\libexpat.dll`` somewhere in
-your PATH, ``win32\bin\release\libexpat.lib`` somewhere in LIB, and
-both ``lib\expat.h`` and ``lib\expat_external.h`` somewhere in INCLUDE.
+Then, copy the file ``win32\bin\release\libexpat.lib`` somewhere in
+somewhere in LIB, and both ``lib\expat.h`` and ``lib\expat_external.h``
+somewhere in INCLUDE.
The OpenSSL library
~~~~~~~~~~~~~~~~~~~
OpenSSL needs a Perl interpreter to configure its makefile. You may
-use the one distributed by ActiveState, or the one from cygwin. In
-both case the perl interpreter must be found on the PATH.
+use the one distributed by ActiveState, or the one from cygwin.::
- svn export http://svn.python.org/projects/external/openssl-0.9.8y
- cd openssl-0.9.8y
- perl Configure VC-WIN32
+ svn export http://svn.python.org/projects/external/openssl-1.0.1i
+ cd openssl-1.0.1i
+ perl Configure VC-WIN32 no-idea no-mdc2
ms\do_ms.bat
nmake -f ms\nt.mak install
+Then, copy the files ``out32\*.lib`` somewhere in
+somewhere in LIB, and the entire ``include\openssl`` directory as-is somewhere
+in INCLUDE.
+
TkInter module support
~~~~~~~~~~~~~~~~~~~~~~
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -1,5 +1,4 @@
# Generated by tools/asdl_py.py
-from rpython.rlib.unroll import unrolling_iterable
from rpython.tool.pairtype import extendabletype
from rpython.tool.sourcetools import func_with_new_name
@@ -21,11 +20,15 @@
'AST string must be of type str or unicode'))
return w_obj
-
-class AST(W_Root):
-
- w_dict = None
-
+def get_field(space, w_node, name, optional):
+ w_obj = w_node.getdictvalue(space, name)
+ if w_obj is None and not optional:
+ raise oefmt(space.w_TypeError,
+ "required field \"%s\" missing from %T", name, w_node)
+ return w_obj
+
+
+class AST(object):
__metaclass__ = extendabletype
def walkabout(self, visitor):
@@ -34,8 +37,23 @@
def mutate_over(self, visitor):
raise AssertionError("mutate_over() implementation not provided")
- def sync_app_attrs(self, space):
- raise NotImplementedError
+
+class NodeVisitorNotImplemented(Exception):
+ pass
+
+
+class _FieldsWrapper(W_Root):
+ "Hack around the fact we can't store tuples on a TypeDef."
+
+ def __init__(self, fields):
+ self.fields = fields
+
+ def __spacebind__(self, space):
+ return space.newtuple([space.wrap(field) for field in self.fields])
+
+
+class W_AST(W_Root):
+ w_dict = None
def getdict(self, space):
if self.w_dict is None:
@@ -47,7 +65,7 @@
if w_dict is None:
w_dict = space.newdict()
w_type = space.type(self)
- w_fields = w_type.getdictvalue(space, "_fields")
+ w_fields = space.getattr(w_type, space.wrap("_fields"))
for w_name in space.fixedview(w_fields):
try:
space.setitem(w_dict, w_name,
@@ -71,79 +89,94 @@
space.setattr(self, w_name,
space.getitem(w_state, w_name))
- def missing_field(self, space, required, host):
- "Find which required field is missing."
- state = self.initialization_state
- for i in range(len(required)):
- if (state >> i) & 1:
- continue # field is present
- missing = required[i]
- if missing is None:
- continue # field is optional
- w_obj = self.getdictvalue(space, missing)
- if w_obj is None:
- raise oefmt(space.w_TypeError,
- "required field \"%s\" missing from %s",
- missing, host)
- else:
- raise oefmt(space.w_TypeError,
- "incorrect type for field \"%s\" in %s",
- missing, host)
- raise AssertionError("should not reach here")
-
-
-class NodeVisitorNotImplemented(Exception):
- pass
-
-
-class _FieldsWrapper(W_Root):
- "Hack around the fact we can't store tuples on a TypeDef."
-
- def __init__(self, fields):
- self.fields = fields
-
- def __spacebind__(self, space):
- return space.newtuple([space.wrap(field) for field in self.fields])
-
-
-def get_AST_new(node_class):
- def generic_AST_new(space, w_type, __args__):
- node = space.allocate_instance(node_class, w_type)
- node.initialization_state = 0
- return space.wrap(node)
- return func_with_new_name(generic_AST_new, "new_%s" % node_class.__name__)
-
-def AST_init(space, w_self, __args__):
+def W_AST_new(space, w_type, __args__):
+ node = space.allocate_instance(W_AST, w_type)
+ return space.wrap(node)
+
+def W_AST_init(space, w_self, __args__):
args_w, kwargs_w = __args__.unpack()
- if args_w and len(args_w) != 0:
- w_err = space.wrap("_ast.AST constructor takes 0 positional arguments")
- raise OperationError(space.w_TypeError, w_err)
+ fields_w = space.fixedview(space.getattr(space.type(w_self),
+ space.wrap("_fields")))
+ num_fields = len(fields_w) if fields_w else 0
+ if args_w and len(args_w) != num_fields:
+ if num_fields == 0:
+ raise oefmt(space.w_TypeError,
+ "%T constructor takes 0 positional arguments", w_self)
+ elif num_fields == 1:
+ raise oefmt(space.w_TypeError,
+ "%T constructor takes either 0 or %d positional argument", w_self, num_fields)
+ else:
+ raise oefmt(space.w_TypeError,
+ "%T constructor takes either 0 or %d positional arguments", w_self, num_fields)
+ if args_w:
+ for i, w_field in enumerate(fields_w):
+ space.setattr(w_self, w_field, args_w[i])
for field, w_value in kwargs_w.iteritems():
space.setattr(w_self, space.wrap(field), w_value)
-AST.typedef = typedef.TypeDef("_ast.AST",
+
+W_AST.typedef = typedef.TypeDef("_ast.AST",
_fields=_FieldsWrapper([]),
_attributes=_FieldsWrapper([]),
- __reduce__=interp2app(AST.reduce_w),
- __setstate__=interp2app(AST.setstate_w),
+ __reduce__=interp2app(W_AST.reduce_w),
+ __setstate__=interp2app(W_AST.setstate_w),
__dict__ = typedef.GetSetProperty(typedef.descr_get_dict,
- typedef.descr_set_dict, cls=AST),
- __new__=interp2app(get_AST_new(AST)),
- __init__=interp2app(AST_init),
+ typedef.descr_set_dict, cls=W_AST),
+ __new__=interp2app(W_AST_new),
+ __init__=interp2app(W_AST_init),
)
-
-
+class State:
+ AST_TYPES = []
+
+ @classmethod
+ def ast_type(cls, name, base, fields, attributes=None):
+ cls.AST_TYPES.append((name, base, fields, attributes))
+
+ def __init__(self, space):
+ self.w_AST = space.gettypeobject(W_AST.typedef)
+ for (name, base, fields, attributes) in self.AST_TYPES:
+ self.make_new_type(space, name, base, fields, attributes)
+
+ def make_new_type(self, space, name, base, fields, attributes):
+ w_base = getattr(self, 'w_%s' % base)
+ w_dict = space.newdict()
+ space.setitem_str(w_dict, '__module__', space.wrap('_ast'))
+ if fields is not None:
+ space.setitem_str(w_dict, "_fields",
+ space.newtuple([space.wrap(f) for f in fields]))
+ if attributes is not None:
+ space.setitem_str(w_dict, "_attributes",
+ space.newtuple([space.wrap(a) for a in attributes]))
+ w_type = space.call_function(
+ space.w_type,
+ space.wrap(name), space.newtuple([w_base]), w_dict)
+ setattr(self, 'w_%s' % name, w_type)
+
+def get(space):
+ return space.fromcache(State)
class mod(AST):
- pass
+ @staticmethod
+ def from_object(space, w_node):
+ if space.is_w(w_node, space.w_None):
+ return None
+ if space.isinstance_w(w_node, get(space).w_Module):
+ return Module.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Interactive):
+ return Interactive.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Expression):
+ return Expression.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Suite):
+ return Suite.from_object(space, w_node)
+ raise oefmt(space.w_TypeError,
+ "Expected mod node, got %T", w_node)
+State.ast_type('mod', 'AST', None, [])
class Module(mod):
def __init__(self, body):
self.body = body
- self.w_body = None
- self.initialization_state = 1
def walkabout(self, visitor):
visitor.visit_Module(self)
@@ -153,29 +186,30 @@
visitor._mutate_sequence(self.body)
return visitor.visit_Module(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 1:
- self.missing_field(space, ['body'], 'Module')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Module)
+ if self.body is None:
+ body_w = []
else:
- pass
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ return Module(_body)
+
+State.ast_type('Module', 'mod', ['body'])
class Interactive(mod):
def __init__(self, body):
self.body = body
- self.w_body = None
- self.initialization_state = 1
def walkabout(self, visitor):
visitor.visit_Interactive(self)
@@ -185,28 +219,30 @@
visitor._mutate_sequence(self.body)
return visitor.visit_Interactive(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 1:
- self.missing_field(space, ['body'], 'Interactive')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Interactive)
+ if self.body is None:
+ body_w = []
else:
- pass
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ return Interactive(_body)
+
+State.ast_type('Interactive', 'mod', ['body'])
class Expression(mod):
def __init__(self, body):
self.body = body
- self.initialization_state = 1
def walkabout(self, visitor):
visitor.visit_Expression(self)
@@ -215,20 +251,25 @@
self.body = self.body.mutate_over(visitor)
return visitor.visit_Expression(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 1:
- self.missing_field(space, ['body'], 'Expression')
- else:
- pass
- self.body.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Expression)
+ w_body = self.body.to_object(space) # expr
+ space.setattr(w_node, space.wrap('body'), w_body)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ _body = expr.from_object(space, w_body)
+ return Expression(_body)
+
+State.ast_type('Expression', 'mod', ['body'])
class Suite(mod):
def __init__(self, body):
self.body = body
- self.w_body = None
- self.initialization_state = 1
def walkabout(self, visitor):
visitor.visit_Suite(self)
@@ -238,21 +279,24 @@
visitor._mutate_sequence(self.body)
return visitor.visit_Suite(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 1:
- self.missing_field(space, ['body'], 'Suite')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Suite)
+ if self.body is None:
+ body_w = []
else:
- pass
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ return Suite(_body)
+
+State.ast_type('Suite', 'mod', ['body'])
class stmt(AST):
@@ -261,18 +305,67 @@
self.lineno = lineno
self.col_offset = col_offset
+ @staticmethod
+ def from_object(space, w_node):
+ if space.is_w(w_node, space.w_None):
+ return None
+ if space.isinstance_w(w_node, get(space).w_FunctionDef):
+ return FunctionDef.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_ClassDef):
+ return ClassDef.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Return):
+ return Return.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Delete):
+ return Delete.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Assign):
+ return Assign.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_AugAssign):
+ return AugAssign.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_For):
+ return For.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_While):
+ return While.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_If):
+ return If.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_With):
+ return With.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Raise):
+ return Raise.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_TryExcept):
+ return TryExcept.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_TryFinally):
+ return TryFinally.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Assert):
+ return Assert.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Import):
+ return Import.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_ImportFrom):
+ return ImportFrom.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Global):
+ return Global.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Nonlocal):
+ return Nonlocal.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Expr):
+ return Expr.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Pass):
+ return Pass.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Break):
+ return Break.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Continue):
+ return Continue.from_object(space, w_node)
+ raise oefmt(space.w_TypeError,
+ "Expected stmt node, got %T", w_node)
+State.ast_type('stmt', 'AST', None, ['lineno', 'col_offset'])
+
class FunctionDef(stmt):
def __init__(self, name, args, body, decorator_list, returns, lineno, col_offset):
self.name = name
self.args = args
self.body = body
- self.w_body = None
self.decorator_list = decorator_list
- self.w_decorator_list = None
self.returns = returns
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 127
def walkabout(self, visitor):
visitor.visit_FunctionDef(self)
@@ -287,35 +380,53 @@
self.returns = self.returns.mutate_over(visitor)
return visitor.visit_FunctionDef(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~64) ^ 63:
- self.missing_field(space, ['lineno', 'col_offset', 'name', 'args', 'body', 'decorator_list', None], 'FunctionDef')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_FunctionDef)
+ w_name = space.wrap(self.name.decode('utf-8')) # identifier
+ space.setattr(w_node, space.wrap('name'), w_name)
+ w_args = self.args.to_object(space) # arguments
+ space.setattr(w_node, space.wrap('args'), w_args)
+ if self.body is None:
+ body_w = []
else:
- if not self.initialization_state & 64:
- self.returns = None
- self.args.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_decorator_list
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.decorator_list = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.decorator_list = None
- if self.decorator_list is not None:
- for node in self.decorator_list:
- node.sync_app_attrs(space)
- if self.returns:
- self.returns.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.decorator_list is None:
+ decorator_list_w = []
+ else:
+ decorator_list_w = [node.to_object(space) for node in self.decorator_list] # expr
+ w_decorator_list = space.newlist(decorator_list_w)
+ space.setattr(w_node, space.wrap('decorator_list'), w_decorator_list)
+ w_returns = self.returns.to_object(space) if self.returns is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('returns'), w_returns)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_name = get_field(space, w_node, 'name', False)
+ w_args = get_field(space, w_node, 'args', False)
+ w_body = get_field(space, w_node, 'body', False)
+ w_decorator_list = get_field(space, w_node, 'decorator_list', False)
+ w_returns = get_field(space, w_node, 'returns', True)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _name = space.identifier_w(w_name)
+ _args = arguments.from_object(space, w_args)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ decorator_list_w = space.unpackiterable(w_decorator_list)
+ _decorator_list = [expr.from_object(space, w_item) for w_item in decorator_list_w]
+ _returns = expr.from_object(space, w_returns) if w_returns is not None else None
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return FunctionDef(_name, _args, _body, _decorator_list, _returns, _lineno, _col_offset)
+
+State.ast_type('FunctionDef', 'stmt', ['name', 'args', 'body', 'decorator_list', 'returns'])
class ClassDef(stmt):
@@ -323,17 +434,12 @@
def __init__(self, name, bases, keywords, starargs, kwargs, body, decorator_list, lineno, col_offset):
self.name = name
self.bases = bases
- self.w_bases = None
self.keywords = keywords
- self.w_keywords = None
self.starargs = starargs
self.kwargs = kwargs
self.body = body
- self.w_body = None
self.decorator_list = decorator_list
- self.w_decorator_list = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 511
def walkabout(self, visitor):
visitor.visit_ClassDef(self)
@@ -353,58 +459,71 @@
visitor._mutate_sequence(self.decorator_list)
return visitor.visit_ClassDef(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~96) ^ 415:
- self.missing_field(space, ['lineno', 'col_offset', 'name', 'bases', 'keywords', None, None, 'body', 'decorator_list'], 'ClassDef')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_ClassDef)
+ w_name = space.wrap(self.name.decode('utf-8')) # identifier
+ space.setattr(w_node, space.wrap('name'), w_name)
+ if self.bases is None:
+ bases_w = []
else:
- if not self.initialization_state & 32:
- self.starargs = None
- if not self.initialization_state & 64:
- self.kwargs = None
- w_list = self.w_bases
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.bases = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.bases = None
- if self.bases is not None:
- for node in self.bases:
- node.sync_app_attrs(space)
- w_list = self.w_keywords
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.keywords = [space.interp_w(keyword, w_obj) for w_obj in list_w]
- else:
- self.keywords = None
- if self.keywords is not None:
- for node in self.keywords:
- node.sync_app_attrs(space)
- if self.starargs:
- self.starargs.sync_app_attrs(space)
- if self.kwargs:
- self.kwargs.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_decorator_list
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.decorator_list = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.decorator_list = None
- if self.decorator_list is not None:
- for node in self.decorator_list:
- node.sync_app_attrs(space)
+ bases_w = [node.to_object(space) for node in self.bases] # expr
+ w_bases = space.newlist(bases_w)
+ space.setattr(w_node, space.wrap('bases'), w_bases)
+ if self.keywords is None:
+ keywords_w = []
+ else:
+ keywords_w = [node.to_object(space) for node in self.keywords] # keyword
+ w_keywords = space.newlist(keywords_w)
+ space.setattr(w_node, space.wrap('keywords'), w_keywords)
+ w_starargs = self.starargs.to_object(space) if self.starargs is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('starargs'), w_starargs)
+ w_kwargs = self.kwargs.to_object(space) if self.kwargs is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('kwargs'), w_kwargs)
+ if self.body is None:
+ body_w = []
+ else:
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.decorator_list is None:
+ decorator_list_w = []
+ else:
+ decorator_list_w = [node.to_object(space) for node in self.decorator_list] # expr
+ w_decorator_list = space.newlist(decorator_list_w)
+ space.setattr(w_node, space.wrap('decorator_list'), w_decorator_list)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_name = get_field(space, w_node, 'name', False)
+ w_bases = get_field(space, w_node, 'bases', False)
+ w_keywords = get_field(space, w_node, 'keywords', False)
+ w_starargs = get_field(space, w_node, 'starargs', True)
+ w_kwargs = get_field(space, w_node, 'kwargs', True)
+ w_body = get_field(space, w_node, 'body', False)
+ w_decorator_list = get_field(space, w_node, 'decorator_list', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _name = space.identifier_w(w_name)
+ bases_w = space.unpackiterable(w_bases)
+ _bases = [expr.from_object(space, w_item) for w_item in bases_w]
+ keywords_w = space.unpackiterable(w_keywords)
+ _keywords = [keyword.from_object(space, w_item) for w_item in keywords_w]
+ _starargs = expr.from_object(space, w_starargs) if w_starargs is not None else None
+ _kwargs = expr.from_object(space, w_kwargs) if w_kwargs is not None else None
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ decorator_list_w = space.unpackiterable(w_decorator_list)
+ _decorator_list = [expr.from_object(space, w_item) for w_item in decorator_list_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return ClassDef(_name, _bases, _keywords, _starargs, _kwargs, _body, _decorator_list, _lineno, _col_offset)
+
+State.ast_type('ClassDef', 'stmt', ['name', 'bases', 'keywords', 'starargs', 'kwargs', 'body', 'decorator_list'])
class Return(stmt):
@@ -412,7 +531,6 @@
def __init__(self, value, lineno, col_offset):
self.value = value
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Return(self)
@@ -422,23 +540,34 @@
self.value = self.value.mutate_over(visitor)
return visitor.visit_Return(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~4) ^ 3:
- self.missing_field(space, ['lineno', 'col_offset', None], 'Return')
- else:
- if not self.initialization_state & 4:
- self.value = None
- if self.value:
- self.value.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Return)
+ w_value = self.value.to_object(space) if self.value is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('value'), w_value)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_value = get_field(space, w_node, 'value', True)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _value = expr.from_object(space, w_value) if w_value is not None else None
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Return(_value, _lineno, _col_offset)
+
+State.ast_type('Return', 'stmt', ['value'])
class Delete(stmt):
def __init__(self, targets, lineno, col_offset):
self.targets = targets
- self.w_targets = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Delete(self)
@@ -448,31 +577,40 @@
visitor._mutate_sequence(self.targets)
return visitor.visit_Delete(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'targets'], 'Delete')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Delete)
+ if self.targets is None:
+ targets_w = []
else:
- pass
- w_list = self.w_targets
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.targets = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.targets = None
- if self.targets is not None:
- for node in self.targets:
- node.sync_app_attrs(space)
+ targets_w = [node.to_object(space) for node in self.targets] # expr
+ w_targets = space.newlist(targets_w)
+ space.setattr(w_node, space.wrap('targets'), w_targets)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_targets = get_field(space, w_node, 'targets', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ targets_w = space.unpackiterable(w_targets)
+ _targets = [expr.from_object(space, w_item) for w_item in targets_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Delete(_targets, _lineno, _col_offset)
+
+State.ast_type('Delete', 'stmt', ['targets'])
class Assign(stmt):
def __init__(self, targets, value, lineno, col_offset):
self.targets = targets
- self.w_targets = None
self.value = value
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 15
def walkabout(self, visitor):
visitor.visit_Assign(self)
@@ -483,22 +621,36 @@
self.value = self.value.mutate_over(visitor)
return visitor.visit_Assign(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 15:
- self.missing_field(space, ['lineno', 'col_offset', 'targets', 'value'], 'Assign')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Assign)
+ if self.targets is None:
+ targets_w = []
else:
- pass
- w_list = self.w_targets
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.targets = [space.interp_w(expr, w_obj) for w_obj in list_w]
- else:
- self.targets = None
- if self.targets is not None:
- for node in self.targets:
- node.sync_app_attrs(space)
- self.value.sync_app_attrs(space)
+ targets_w = [node.to_object(space) for node in self.targets] # expr
+ w_targets = space.newlist(targets_w)
+ space.setattr(w_node, space.wrap('targets'), w_targets)
+ w_value = self.value.to_object(space) # expr
+ space.setattr(w_node, space.wrap('value'), w_value)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_targets = get_field(space, w_node, 'targets', False)
+ w_value = get_field(space, w_node, 'value', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ targets_w = space.unpackiterable(w_targets)
+ _targets = [expr.from_object(space, w_item) for w_item in targets_w]
+ _value = expr.from_object(space, w_value)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Assign(_targets, _value, _lineno, _col_offset)
+
+State.ast_type('Assign', 'stmt', ['targets', 'value'])
class AugAssign(stmt):
@@ -508,7 +660,6 @@
self.op = op
self.value = value
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 31
def walkabout(self, visitor):
visitor.visit_AugAssign(self)
@@ -518,13 +669,35 @@
self.value = self.value.mutate_over(visitor)
return visitor.visit_AugAssign(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 31:
- self.missing_field(space, ['lineno', 'col_offset', 'target', 'op', 'value'], 'AugAssign')
- else:
- pass
- self.target.sync_app_attrs(space)
- self.value.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_AugAssign)
+ w_target = self.target.to_object(space) # expr
+ space.setattr(w_node, space.wrap('target'), w_target)
+ w_op = operator_to_class[self.op - 1]().to_object(space) # operator
+ space.setattr(w_node, space.wrap('op'), w_op)
+ w_value = self.value.to_object(space) # expr
+ space.setattr(w_node, space.wrap('value'), w_value)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_target = get_field(space, w_node, 'target', False)
+ w_op = get_field(space, w_node, 'op', False)
+ w_value = get_field(space, w_node, 'value', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _target = expr.from_object(space, w_target)
+ _op = operator.from_object(space, w_op)
+ _value = expr.from_object(space, w_value)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return AugAssign(_target, _op, _value, _lineno, _col_offset)
+
+State.ast_type('AugAssign', 'stmt', ['target', 'op', 'value'])
class For(stmt):
@@ -533,11 +706,8 @@
self.target = target
self.iter = iter
self.body = body
- self.w_body = None
self.orelse = orelse
- self.w_orelse = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 63
def walkabout(self, visitor):
visitor.visit_For(self)
@@ -551,33 +721,49 @@
visitor._mutate_sequence(self.orelse)
return visitor.visit_For(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 63:
- self.missing_field(space, ['lineno', 'col_offset', 'target', 'iter', 'body', 'orelse'], 'For')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_For)
+ w_target = self.target.to_object(space) # expr
+ space.setattr(w_node, space.wrap('target'), w_target)
+ w_iter = self.iter.to_object(space) # expr
+ space.setattr(w_node, space.wrap('iter'), w_iter)
+ if self.body is None:
+ body_w = []
else:
- pass
- self.target.sync_app_attrs(space)
- self.iter.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_orelse
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.orelse = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.orelse = None
- if self.orelse is not None:
- for node in self.orelse:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.orelse is None:
+ orelse_w = []
+ else:
+ orelse_w = [node.to_object(space) for node in self.orelse] # stmt
+ w_orelse = space.newlist(orelse_w)
+ space.setattr(w_node, space.wrap('orelse'), w_orelse)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_target = get_field(space, w_node, 'target', False)
+ w_iter = get_field(space, w_node, 'iter', False)
+ w_body = get_field(space, w_node, 'body', False)
+ w_orelse = get_field(space, w_node, 'orelse', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _target = expr.from_object(space, w_target)
+ _iter = expr.from_object(space, w_iter)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ orelse_w = space.unpackiterable(w_orelse)
+ _orelse = [stmt.from_object(space, w_item) for w_item in orelse_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return For(_target, _iter, _body, _orelse, _lineno, _col_offset)
+
+State.ast_type('For', 'stmt', ['target', 'iter', 'body', 'orelse'])
class While(stmt):
@@ -585,11 +771,8 @@
def __init__(self, test, body, orelse, lineno, col_offset):
self.test = test
self.body = body
- self.w_body = None
self.orelse = orelse
- self.w_orelse = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 31
def walkabout(self, visitor):
visitor.visit_While(self)
@@ -602,32 +785,45 @@
visitor._mutate_sequence(self.orelse)
return visitor.visit_While(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 31:
- self.missing_field(space, ['lineno', 'col_offset', 'test', 'body', 'orelse'], 'While')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_While)
+ w_test = self.test.to_object(space) # expr
+ space.setattr(w_node, space.wrap('test'), w_test)
+ if self.body is None:
+ body_w = []
else:
- pass
- self.test.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_orelse
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.orelse = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.orelse = None
- if self.orelse is not None:
- for node in self.orelse:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.orelse is None:
+ orelse_w = []
+ else:
+ orelse_w = [node.to_object(space) for node in self.orelse] # stmt
+ w_orelse = space.newlist(orelse_w)
+ space.setattr(w_node, space.wrap('orelse'), w_orelse)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_test = get_field(space, w_node, 'test', False)
+ w_body = get_field(space, w_node, 'body', False)
+ w_orelse = get_field(space, w_node, 'orelse', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _test = expr.from_object(space, w_test)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ orelse_w = space.unpackiterable(w_orelse)
+ _orelse = [stmt.from_object(space, w_item) for w_item in orelse_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return While(_test, _body, _orelse, _lineno, _col_offset)
+
+State.ast_type('While', 'stmt', ['test', 'body', 'orelse'])
class If(stmt):
@@ -635,11 +831,8 @@
def __init__(self, test, body, orelse, lineno, col_offset):
self.test = test
self.body = body
- self.w_body = None
self.orelse = orelse
- self.w_orelse = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 31
def walkabout(self, visitor):
visitor.visit_If(self)
@@ -652,43 +845,53 @@
visitor._mutate_sequence(self.orelse)
return visitor.visit_If(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 31:
- self.missing_field(space, ['lineno', 'col_offset', 'test', 'body', 'orelse'], 'If')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_If)
+ w_test = self.test.to_object(space) # expr
+ space.setattr(w_node, space.wrap('test'), w_test)
+ if self.body is None:
+ body_w = []
else:
- pass
- self.test.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_orelse
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.orelse = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.orelse = None
- if self.orelse is not None:
- for node in self.orelse:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.orelse is None:
+ orelse_w = []
+ else:
+ orelse_w = [node.to_object(space) for node in self.orelse] # stmt
+ w_orelse = space.newlist(orelse_w)
+ space.setattr(w_node, space.wrap('orelse'), w_orelse)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_test = get_field(space, w_node, 'test', False)
+ w_body = get_field(space, w_node, 'body', False)
+ w_orelse = get_field(space, w_node, 'orelse', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _test = expr.from_object(space, w_test)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ orelse_w = space.unpackiterable(w_orelse)
+ _orelse = [stmt.from_object(space, w_item) for w_item in orelse_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return If(_test, _body, _orelse, _lineno, _col_offset)
+
+State.ast_type('If', 'stmt', ['test', 'body', 'orelse'])
class With(stmt):
def __init__(self, items, body, lineno, col_offset):
self.items = items
- self.w_items = None
self.body = body
- self.w_body = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 15
def walkabout(self, visitor):
visitor.visit_With(self)
@@ -700,31 +903,41 @@
visitor._mutate_sequence(self.body)
return visitor.visit_With(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 15:
- self.missing_field(space, ['lineno', 'col_offset', 'items', 'body'], 'With')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_With)
+ if self.items is None:
+ items_w = []
else:
- pass
- w_list = self.w_items
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.items = [space.interp_w(withitem, w_obj) for w_obj in list_w]
- else:
- self.items = None
- if self.items is not None:
- for node in self.items:
- node.sync_app_attrs(space)
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
+ items_w = [node.to_object(space) for node in self.items] # withitem
+ w_items = space.newlist(items_w)
+ space.setattr(w_node, space.wrap('items'), w_items)
+ if self.body is None:
+ body_w = []
+ else:
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_items = get_field(space, w_node, 'items', False)
+ w_body = get_field(space, w_node, 'body', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ items_w = space.unpackiterable(w_items)
+ _items = [withitem.from_object(space, w_item) for w_item in items_w]
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return With(_items, _body, _lineno, _col_offset)
+
+State.ast_type('With', 'stmt', ['items', 'body'])
class Raise(stmt):
@@ -733,7 +946,6 @@
self.exc = exc
self.cause = cause
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 15
def walkabout(self, visitor):
visitor.visit_Raise(self)
@@ -745,31 +957,40 @@
self.cause = self.cause.mutate_over(visitor)
return visitor.visit_Raise(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~12) ^ 3:
- self.missing_field(space, ['lineno', 'col_offset', None, None], 'Raise')
- else:
- if not self.initialization_state & 4:
- self.exc = None
- if not self.initialization_state & 8:
- self.cause = None
- if self.exc:
- self.exc.sync_app_attrs(space)
- if self.cause:
- self.cause.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Raise)
+ w_exc = self.exc.to_object(space) if self.exc is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('exc'), w_exc)
+ w_cause = self.cause.to_object(space) if self.cause is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('cause'), w_cause)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_exc = get_field(space, w_node, 'exc', True)
+ w_cause = get_field(space, w_node, 'cause', True)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _exc = expr.from_object(space, w_exc) if w_exc is not None else None
+ _cause = expr.from_object(space, w_cause) if w_cause is not None else None
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Raise(_exc, _cause, _lineno, _col_offset)
+
+State.ast_type('Raise', 'stmt', ['exc', 'cause'])
class TryExcept(stmt):
def __init__(self, body, handlers, orelse, lineno, col_offset):
self.body = body
- self.w_body = None
self.handlers = handlers
- self.w_handlers = None
self.orelse = orelse
- self.w_orelse = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 31
def walkabout(self, visitor):
visitor.visit_TryExcept(self)
@@ -783,52 +1004,58 @@
visitor._mutate_sequence(self.orelse)
return visitor.visit_TryExcept(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 31:
- self.missing_field(space, ['lineno', 'col_offset', 'body', 'handlers', 'orelse'], 'TryExcept')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_TryExcept)
+ if self.body is None:
+ body_w = []
else:
- pass
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_handlers
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.handlers = [space.interp_w(excepthandler, w_obj) for w_obj in list_w]
- else:
- self.handlers = None
- if self.handlers is not None:
- for node in self.handlers:
- node.sync_app_attrs(space)
- w_list = self.w_orelse
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.orelse = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.orelse = None
- if self.orelse is not None:
- for node in self.orelse:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.handlers is None:
+ handlers_w = []
+ else:
+ handlers_w = [node.to_object(space) for node in self.handlers] # excepthandler
+ w_handlers = space.newlist(handlers_w)
+ space.setattr(w_node, space.wrap('handlers'), w_handlers)
+ if self.orelse is None:
+ orelse_w = []
+ else:
+ orelse_w = [node.to_object(space) for node in self.orelse] # stmt
+ w_orelse = space.newlist(orelse_w)
+ space.setattr(w_node, space.wrap('orelse'), w_orelse)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ w_handlers = get_field(space, w_node, 'handlers', False)
+ w_orelse = get_field(space, w_node, 'orelse', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ handlers_w = space.unpackiterable(w_handlers)
+ _handlers = [excepthandler.from_object(space, w_item) for w_item in handlers_w]
+ orelse_w = space.unpackiterable(w_orelse)
+ _orelse = [stmt.from_object(space, w_item) for w_item in orelse_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return TryExcept(_body, _handlers, _orelse, _lineno, _col_offset)
+
+State.ast_type('TryExcept', 'stmt', ['body', 'handlers', 'orelse'])
class TryFinally(stmt):
def __init__(self, body, finalbody, lineno, col_offset):
self.body = body
- self.w_body = None
self.finalbody = finalbody
- self.w_finalbody = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 15
def walkabout(self, visitor):
visitor.visit_TryFinally(self)
@@ -840,31 +1067,41 @@
visitor._mutate_sequence(self.finalbody)
return visitor.visit_TryFinally(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 15:
- self.missing_field(space, ['lineno', 'col_offset', 'body', 'finalbody'], 'TryFinally')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_TryFinally)
+ if self.body is None:
+ body_w = []
else:
- pass
- w_list = self.w_body
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.body = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.body = None
- if self.body is not None:
- for node in self.body:
- node.sync_app_attrs(space)
- w_list = self.w_finalbody
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.finalbody = [space.interp_w(stmt, w_obj) for w_obj in list_w]
- else:
- self.finalbody = None
- if self.finalbody is not None:
- for node in self.finalbody:
- node.sync_app_attrs(space)
+ body_w = [node.to_object(space) for node in self.body] # stmt
+ w_body = space.newlist(body_w)
+ space.setattr(w_node, space.wrap('body'), w_body)
+ if self.finalbody is None:
+ finalbody_w = []
+ else:
+ finalbody_w = [node.to_object(space) for node in self.finalbody] # stmt
+ w_finalbody = space.newlist(finalbody_w)
+ space.setattr(w_node, space.wrap('finalbody'), w_finalbody)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_body = get_field(space, w_node, 'body', False)
+ w_finalbody = get_field(space, w_node, 'finalbody', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ body_w = space.unpackiterable(w_body)
+ _body = [stmt.from_object(space, w_item) for w_item in body_w]
+ finalbody_w = space.unpackiterable(w_finalbody)
+ _finalbody = [stmt.from_object(space, w_item) for w_item in finalbody_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return TryFinally(_body, _finalbody, _lineno, _col_offset)
+
+State.ast_type('TryFinally', 'stmt', ['body', 'finalbody'])
class Assert(stmt):
@@ -873,7 +1110,6 @@
self.test = test
self.msg = msg
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 15
def walkabout(self, visitor):
visitor.visit_Assert(self)
@@ -884,24 +1120,38 @@
self.msg = self.msg.mutate_over(visitor)
return visitor.visit_Assert(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~8) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'test', None], 'Assert')
- else:
- if not self.initialization_state & 8:
- self.msg = None
- self.test.sync_app_attrs(space)
- if self.msg:
- self.msg.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Assert)
+ w_test = self.test.to_object(space) # expr
+ space.setattr(w_node, space.wrap('test'), w_test)
+ w_msg = self.msg.to_object(space) if self.msg is not None else space.w_None # expr
+ space.setattr(w_node, space.wrap('msg'), w_msg)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_test = get_field(space, w_node, 'test', False)
+ w_msg = get_field(space, w_node, 'msg', True)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _test = expr.from_object(space, w_test)
+ _msg = expr.from_object(space, w_msg) if w_msg is not None else None
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Assert(_test, _msg, _lineno, _col_offset)
+
+State.ast_type('Assert', 'stmt', ['test', 'msg'])
class Import(stmt):
def __init__(self, names, lineno, col_offset):
self.names = names
- self.w_names = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Import(self)
@@ -911,21 +1161,32 @@
visitor._mutate_sequence(self.names)
return visitor.visit_Import(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'names'], 'Import')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Import)
+ if self.names is None:
+ names_w = []
else:
- pass
- w_list = self.w_names
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.names = [space.interp_w(alias, w_obj) for w_obj in list_w]
- else:
- self.names = None
- if self.names is not None:
- for node in self.names:
- node.sync_app_attrs(space)
+ names_w = [node.to_object(space) for node in self.names] # alias
+ w_names = space.newlist(names_w)
+ space.setattr(w_node, space.wrap('names'), w_names)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_names = get_field(space, w_node, 'names', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ names_w = space.unpackiterable(w_names)
+ _names = [alias.from_object(space, w_item) for w_item in names_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Import(_names, _lineno, _col_offset)
+
+State.ast_type('Import', 'stmt', ['names'])
class ImportFrom(stmt):
@@ -933,10 +1194,8 @@
def __init__(self, module, names, level, lineno, col_offset):
self.module = module
self.names = names
- self.w_names = None
self.level = level
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 31
def walkabout(self, visitor):
visitor.visit_ImportFrom(self)
@@ -946,33 +1205,47 @@
visitor._mutate_sequence(self.names)
return visitor.visit_ImportFrom(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~20) ^ 11:
- self.missing_field(space, ['lineno', 'col_offset', None, 'names', None], 'ImportFrom')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_ImportFrom)
+ w_module = space.wrap(self.module.decode('utf-8')) if self.module is not None else space.w_None # identifier
+ space.setattr(w_node, space.wrap('module'), w_module)
+ if self.names is None:
+ names_w = []
else:
- if not self.initialization_state & 4:
- self.module = None
- if not self.initialization_state & 16:
- self.level = 0
- w_list = self.w_names
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.names = [space.interp_w(alias, w_obj) for w_obj in list_w]
- else:
- self.names = None
- if self.names is not None:
- for node in self.names:
- node.sync_app_attrs(space)
+ names_w = [node.to_object(space) for node in self.names] # alias
+ w_names = space.newlist(names_w)
+ space.setattr(w_node, space.wrap('names'), w_names)
+ w_level = space.wrap(self.level) # int
+ space.setattr(w_node, space.wrap('level'), w_level)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_module = get_field(space, w_node, 'module', True)
+ w_names = get_field(space, w_node, 'names', False)
+ w_level = get_field(space, w_node, 'level', True)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _module = space.str_or_None_w(w_module)
+ names_w = space.unpackiterable(w_names)
+ _names = [alias.from_object(space, w_item) for w_item in names_w]
+ _level = space.int_w(w_level)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return ImportFrom(_module, _names, _level, _lineno, _col_offset)
+
+State.ast_type('ImportFrom', 'stmt', ['module', 'names', 'level'])
class Global(stmt):
def __init__(self, names, lineno, col_offset):
self.names = names
- self.w_names = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Global(self)
@@ -980,27 +1253,39 @@
def mutate_over(self, visitor):
return visitor.visit_Global(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'names'], 'Global')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Global)
+ if self.names is None:
+ names_w = []
else:
- pass
- w_list = self.w_names
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.names = [space.identifier_w(w_obj) for w_obj in list_w]
- else:
- self.names = None
+ names_w = [space.wrap(node.decode('utf-8')) for node in self.names] # identifier
+ w_names = space.newlist(names_w)
+ space.setattr(w_node, space.wrap('names'), w_names)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_names = get_field(space, w_node, 'names', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ names_w = space.unpackiterable(w_names)
+ _names = [space.identifier_w(w_item) for w_item in names_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Global(_names, _lineno, _col_offset)
+
+State.ast_type('Global', 'stmt', ['names'])
class Nonlocal(stmt):
def __init__(self, names, lineno, col_offset):
self.names = names
- self.w_names = None
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Nonlocal(self)
@@ -1008,18 +1293,32 @@
def mutate_over(self, visitor):
return visitor.visit_Nonlocal(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'names'], 'Nonlocal')
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Nonlocal)
+ if self.names is None:
+ names_w = []
else:
- pass
- w_list = self.w_names
- if w_list is not None:
- list_w = space.listview(w_list)
- if list_w:
- self.names = [space.identifier_w(w_obj) for w_obj in list_w]
- else:
- self.names = None
+ names_w = [space.wrap(node.decode('utf-8')) for node in self.names] # identifier
+ w_names = space.newlist(names_w)
+ space.setattr(w_node, space.wrap('names'), w_names)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_names = get_field(space, w_node, 'names', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ names_w = space.unpackiterable(w_names)
+ _names = [space.identifier_w(w_item) for w_item in names_w]
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Nonlocal(_names, _lineno, _col_offset)
+
+State.ast_type('Nonlocal', 'stmt', ['names'])
class Expr(stmt):
@@ -1027,7 +1326,6 @@
def __init__(self, value, lineno, col_offset):
self.value = value
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 7
def walkabout(self, visitor):
visitor.visit_Expr(self)
@@ -1036,19 +1334,33 @@
self.value = self.value.mutate_over(visitor)
return visitor.visit_Expr(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 7:
- self.missing_field(space, ['lineno', 'col_offset', 'value'], 'Expr')
- else:
- pass
- self.value.sync_app_attrs(space)
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Expr)
+ w_value = self.value.to_object(space) # expr
+ space.setattr(w_node, space.wrap('value'), w_value)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_value = get_field(space, w_node, 'value', False)
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _value = expr.from_object(space, w_value)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Expr(_value, _lineno, _col_offset)
+
+State.ast_type('Expr', 'stmt', ['value'])
class Pass(stmt):
def __init__(self, lineno, col_offset):
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 3
def walkabout(self, visitor):
visitor.visit_Pass(self)
@@ -1056,18 +1368,29 @@
def mutate_over(self, visitor):
return visitor.visit_Pass(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 3:
- self.missing_field(space, ['lineno', 'col_offset'], 'Pass')
- else:
- pass
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Pass)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Pass(_lineno, _col_offset)
+
+State.ast_type('Pass', 'stmt', [])
class Break(stmt):
def __init__(self, lineno, col_offset):
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 3
def walkabout(self, visitor):
visitor.visit_Break(self)
@@ -1075,18 +1398,29 @@
def mutate_over(self, visitor):
return visitor.visit_Break(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 3:
- self.missing_field(space, ['lineno', 'col_offset'], 'Break')
- else:
- pass
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Break)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Break(_lineno, _col_offset)
+
+State.ast_type('Break', 'stmt', [])
class Continue(stmt):
def __init__(self, lineno, col_offset):
stmt.__init__(self, lineno, col_offset)
- self.initialization_state = 3
def walkabout(self, visitor):
visitor.visit_Continue(self)
@@ -1094,11 +1428,23 @@
def mutate_over(self, visitor):
return visitor.visit_Continue(self)
- def sync_app_attrs(self, space):
- if (self.initialization_state & ~0) ^ 3:
- self.missing_field(space, ['lineno', 'col_offset'], 'Continue')
- else:
- pass
+ def to_object(self, space):
+ w_node = space.call_function(get(space).w_Continue)
+ w_lineno = space.wrap(self.lineno) # int
+ space.setattr(w_node, space.wrap('lineno'), w_lineno)
+ w_col_offset = space.wrap(self.col_offset) # int
+ space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+ return w_node
+
+ @staticmethod
+ def from_object(space, w_node):
+ w_lineno = get_field(space, w_node, 'lineno', False)
+ w_col_offset = get_field(space, w_node, 'col_offset', False)
+ _lineno = space.int_w(w_lineno)
+ _col_offset = space.int_w(w_col_offset)
+ return Continue(_lineno, _col_offset)
+
+State.ast_type('Continue', 'stmt', [])
class expr(AST):
@@ -1107,14 +1453,72 @@
self.lineno = lineno
self.col_offset = col_offset
+ @staticmethod
+ def from_object(space, w_node):
+ if space.is_w(w_node, space.w_None):
+ return None
+ if space.isinstance_w(w_node, get(space).w_BoolOp):
+ return BoolOp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_BinOp):
+ return BinOp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_UnaryOp):
+ return UnaryOp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Lambda):
+ return Lambda.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_IfExp):
+ return IfExp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Dict):
+ return Dict.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_Set):
+ return Set.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_ListComp):
+ return ListComp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_SetComp):
+ return SetComp.from_object(space, w_node)
+ if space.isinstance_w(w_node, get(space).w_DictComp):
More information about the pypy-commit
mailing list