[pypy-commit] pypy py3.5-async-translate: translation issues batch 2
plan_rich
pypy.commits at gmail.com
Fri Aug 5 16:13:58 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-async-translate
Changeset: r86045:5a7b8af95db6
Date: 2016-08-05 22:13 +0200
http://bitbucket.org/pypy/pypy/changeset/5a7b8af95db6/
Log: translation issues batch 2
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -581,12 +581,13 @@
# position, then raise a GeneratorExit. Otherwise, there is
# no point.
# If coroutine was never awaited on issue a RuntimeWarning.
- if self.pycode is not None:
- if self.frame is not None:
- if self.frame.fget_f_lasti(self.frame).int_w(self.space) == -1:
- raise oefmt(space.w_RuntimeWarning,
- "coroutine '%s' was never awaited",
- self.pycode.co_name)
+ if self.pycode is not None and \
+ self.frame is not None and \
+ self.frame.last_instr == -1:
+ # XXX PyErr_Occured in condition?
+ raise oefmt(self.space.w_RuntimeWarning,
+ "coroutine '%s' was never awaited",
+ self.pycode.co_name)
if self.frame is not None:
block = self.frame.lastblock
while block is not None:
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -6,7 +6,7 @@
from rpython.rlib import jit, rstackovf, rstring
from rpython.rlib.debug import check_nonneg
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, always_inline
from rpython.rlib.rarithmetic import r_uint, intmask
from rpython.tool.sourcetools import func_with_new_name
@@ -18,6 +18,7 @@
from pypy.interpreter.nestedscope import Cell
from pypy.interpreter.pycode import PyCode, BytecodeCorruption
from pypy.tool.stdlib_opcode import bytecode_spec
+from pypy.objspace.std.dictmultiobject import W_DictMultiObject
CANNOT_CATCH_MSG = ("catching classes that don't inherit from BaseException "
"is not allowed in 3.x")
@@ -45,6 +46,27 @@
return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
+def get_func_desc(func):
+ if self.space.type(func) is function.Function:
+ return "()"
+ elif self.space.type(func) is function.Method:
+ return "()"
+ else:
+ return " object";
+
+ at always_inline
+def list_unpack_helper(frame, itemcount):
+ space = frame.space
+ w_sum = space.newlist([], sizehint=itemcount)
+ for i in range(itemcount, 0, -1):
+ w_item = frame.peekvalue(i-1)
+ #items = frame.space.fixedview(w_item)
+ w_sum.extend(w_item)
+ while itemcount != 0:
+ frame.popvalue()
+ itemcount -= 1
+ return w_sum
+
opcodedesc = bytecode_spec.opcodedesc
HAVE_ARGUMENT = bytecode_spec.HAVE_ARGUMENT
@@ -1351,74 +1373,73 @@
self.space.call_method(w_set, 'add', w_item)
self.pushvalue(w_set)
- def unpack_helper(self, itemcount, next_instr):
- w_sum = []
+ def BUILD_SET_UNPACK(self, itemcount, next_instr):
+ space = self.space
+ w_sum = space.newset()
for i in range(itemcount, 0, -1):
w_item = self.peekvalue(i-1)
- items = self.space.fixedview(w_item)
- w_sum.extend(items)
+ # cannot use w_sum.update, w_item might not be a set
+ iterator = w_item.itervalues()
+ while True:
+ w_value = iterator.next_value()
+ if w_value is None:
+ break
+ w_sum.add(w_value)
while itemcount != 0:
self.popvalue()
itemcount -= 1
- return w_sum
-
- def BUILD_SET_UNPACK(self, itemcount, next_instr):
- w_sum = self.unpack_helper(itemcount, next_instr)
- self.pushvalue(self.space.newset(w_sum))
+ self.pushvalue(w_sum)
def BUILD_TUPLE_UNPACK(self, itemcount, next_instr):
- w_sum = self.unpack_helper(itemcount, next_instr)
- self.pushvalue(self.space.newtuple(w_sum))
-
+ space = self.space
+ w_sum_list = list_unpack_helper(self, itemcount)
+ self.pushvalue(space.newtuple(w_sum_list))
+
def BUILD_LIST_UNPACK(self, itemcount, next_instr):
- w_sum = self.unpack_helper(itemcount, next_instr)
- self.pushvalue(self.space.newlist(w_sum))
-
- def getFuncDesc(func):
- if self.space.type(aaa).name.decode('utf-8') == 'method':
- return "()"
- elif self.space.type(aaa).name.decode('utf-8') == 'function':
- return "()"
- else:
- return " object";
-
+ w_sum = list_unpack_helper(self, itemcount)
+ self.pushvalue(w_sum)
+
def BUILD_MAP_UNPACK_WITH_CALL(self, itemcount, next_instr):
+ space = self.space
num_maps = itemcount & 0xff
function_location = (itemcount>>8) & 0xff
- w_dict = self.space.newdict()
- dict_class = w_dict.__class__
+ w_dict = space.newdict()
for i in range(num_maps, 0, -1):
w_item = self.peekvalue(i-1)
- if not issubclass(w_item.__class__, dict_class):
- raise oefmt(self.space.w_TypeError,
+ if space.lookup(w_item, '__getitem__') is None:
+ raise oefmt(space.w_TypeError,
"'%T' object is not a mapping", w_item)
- num_items = w_item.length()
- keys = w_item.w_keys()
- for j in range(num_items):
- if self.space.type(keys.getitem(j)).name.decode('utf-8') == 'method':
+ iterator = w_item.iterkeys()
+ while True:
+ w_key = iterator.next_key()
+ if w_key is None:
+ break
+ if not isinstance(w_key, space.UnicodeObjectCls):
err_fun = self.peekvalue(num_maps + function_location-1)
- raise oefmt(self.space.w_TypeError,
- "%N%s keywords must be strings", err_fun, getFuncDesc(err_fun))
- if self.space.is_true(self.space.contains(w_dict,keys.getitem(j))):
+ raise oefmt(space.w_TypeError,
+ "%N%s keywords must be strings", err_fun,
+ get_func_desc(err_fun))
+ if space.is_true(space.contains(w_dict,w_key)):
err_fun = self.peekvalue(num_maps + function_location-1)
- err_arg = self.space.unicode_w(keys.getitem(j))
- raise oefmt(self.space.w_TypeError,
- "%N%s got multiple values for keyword argument %s", err_fun, getFuncDesc(err_fun), err_arg)
- self.space.call_method(w_dict, 'update', w_item)
+ err_arg = w_key
+ raise oefmt(space.w_TypeError,
+ "%N%s got multiple values for keyword argument %s",
+ err_fun, get_func_desc(err_fun), err_arg)
+ space.call_method(w_dict, 'update', w_item)
while num_maps != 0:
self.popvalue()
num_maps -= 1
self.pushvalue(w_dict)
-
+
def BUILD_MAP_UNPACK(self, itemcount, next_instr):
- w_dict = self.space.newdict()
- dict_class = w_dict.__class__
+ space = self.space
+ w_dict = space.newdict()
for i in range(itemcount, 0, -1):
w_item = self.peekvalue(i-1)
- if not issubclass(w_item.__class__, dict_class):
+ if space.lookup(w_item, '__getitem__') is None:
raise oefmt(self.space.w_TypeError,
"'%T' object is not a mapping", w_item)
- self.space.call_method(w_dict, 'update', w_item)
+ space.call_method(w_dict, 'update', w_item)
while itemcount != 0:
self.popvalue()
itemcount -= 1
diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -198,7 +198,6 @@
def get_native_fmtchar(self, fmt):
from rpython.rtyper.lltypesystem import rffi
- from sys import getsizeof
size = -1
if fmt[0] == '@':
f = fmt[1]
@@ -215,7 +214,7 @@
elif f == 'q' or f == 'Q':
size = rffi.sizeof(rffi.LONGLONG)
elif f == 'n' or f == 'N':
- size = getsizeof(rffi.r_ssize_t)
+ size = rffi.sizeof(rffi.SIZE_T)
elif f == 'f':
size = rffi.sizeof(rffi.FLOAT)
elif f == 'd':
@@ -225,13 +224,13 @@
elif f == 'P':
size = rffi.sizeof(rffi.VOIDP)
return size
-
- def descr_cast(self, space, w_args, w_kwds):
+
+ def descr_cast(self, space, w_format, w_shape=None):
# XXX fixme. does not do anything near cpython (see memoryobjet.c memory_cast)
- #self._check_released(space)
- #newitemsize = self.get_native_fmtchar(w_args._val(w_args))
- return W_MemoryView(self.buf, self.format, self.itemsize)
- return mv
+ self._check_released(space)
+ fmt = space.str_w(w_format)
+ newitemsize = self.get_native_fmtchar(fmt)
+ return W_MemoryView(self.buf, fmt, newitemsize)
W_MemoryView.typedef = TypeDef(
More information about the pypy-commit
mailing list