[pypy-commit] pypy less-stringly-ops: Move guessbool() call out of space.is_true()
rlamy
noreply at buildbot.pypy.org
Mon Aug 19 23:15:18 CEST 2013
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: less-stringly-ops
Changeset: r66241:ce7a9656676d
Date: 2013-05-05 04:15 +0100
http://bitbucket.org/pypy/pypy/changeset/ce7a9656676d/
Log: Move guessbool() call out of space.is_true()
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -129,7 +129,7 @@
def append(self, operation):
raise NotImplementedError
- def guessbool(self, frame, w_condition, **kwds):
+ def guessbool(self, frame, w_condition):
raise AssertionError("cannot guessbool(%s)" % (w_condition,))
@@ -211,7 +211,7 @@
[str(s) for s in self.listtoreplay[self.index:]]))
self.index += 1
- def guessbool(self, frame, w_condition, **kwds):
+ def guessbool(self, frame, w_condition):
assert self.index == len(self.listtoreplay)
frame.recorder = self.nextreplayer
return self.booloutcome
@@ -432,8 +432,10 @@
self.last_exception = FSException(data[-2], data[-1])
self.blockstack = state.blocklist[:]
- def guessbool(self, w_condition, **kwds):
- return self.recorder.guessbool(self, w_condition, **kwds)
+ def guessbool(self, w_condition):
+ if isinstance(w_condition, Constant):
+ return w_condition.value
+ return self.recorder.guessbool(self, w_condition)
def do_operation(self, name, *args_w):
spaceop = SpaceOperation(name, args_w, Variable())
@@ -738,34 +740,34 @@
def JUMP_IF_FALSE(self, target):
# Python <= 2.6 only
w_cond = self.peekvalue()
- if not self.space.is_true(w_cond):
+ if not self.guessbool(self.space.is_true(w_cond)):
return target
def JUMP_IF_TRUE(self, target):
# Python <= 2.6 only
w_cond = self.peekvalue()
- if self.space.is_true(w_cond):
+ if self.guessbool(self.space.is_true(w_cond)):
return target
def POP_JUMP_IF_FALSE(self, target):
w_value = self.popvalue()
- if not self.space.is_true(w_value):
+ if not self.guessbool(self.space.is_true(w_value)):
return target
def POP_JUMP_IF_TRUE(self, target):
w_value = self.popvalue()
- if self.space.is_true(w_value):
+ if self.guessbool(self.space.is_true(w_value)):
return target
def JUMP_IF_FALSE_OR_POP(self, target):
w_value = self.peekvalue()
- if not self.space.is_true(w_value):
+ if not self.guessbool(self.space.is_true(w_value)):
return target
self.popvalue()
def JUMP_IF_TRUE_OR_POP(self, target):
w_value = self.peekvalue()
- if self.space.is_true(w_value):
+ if self.guessbool(self.space.is_true(w_value)):
return target
self.popvalue()
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -90,7 +90,7 @@
return build_flow(func, self)
def is_w(self, w_one, w_two):
- return self.is_true(self.is_(w_one, w_two))
+ return self.frame.guessbool(self.is_true(self.is_(w_one, w_two)))
is_ = None # real version added by add_operations()
id = None # real version added by add_operations()
@@ -133,7 +133,7 @@
return FSException(w_type, w_value)
def exception_issubclass_w(self, w_cls1, w_cls2):
- return self.is_true(self.issubtype(w_cls1, w_cls2))
+ return self.frame.guessbool(self.is_true(self.issubtype(w_cls1, w_cls2)))
def exception_match(self, w_exc_type, w_check_class):
"""Checks if the given exception type matches 'w_check_class'."""
@@ -200,7 +200,7 @@
else:
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, const(expected_length))
- if not self.is_true(w_correct):
+ if not self.frame.guessbool(self.is_true(w_correct)):
e = self.exc_from_raise(self.w_ValueError, self.w_None)
raise e
return [self.frame.do_operation('getitem', w_iterable, const(i))
@@ -208,13 +208,13 @@
# ____________________________________________________________
def not_(self, w_obj):
- return const(not self.is_true(w_obj))
+ return const(not self.frame.guessbool(self.is_true(w_obj)))
def is_true(self, w_obj):
if w_obj.foldable():
- return bool(w_obj.value)
+ return const(bool(w_obj.value))
w_truthvalue = self.frame.do_operation('bool', w_obj)
- return self.frame.guessbool(w_truthvalue)
+ return w_truthvalue
def iter(self, w_iterable):
if isinstance(w_iterable, Constant):
@@ -264,7 +264,7 @@
return self.frame.do_op(op.getattr(w_obj, w_name))
def isinstance_w(self, w_obj, w_type):
- return self.is_true(self.isinstance(w_obj, w_type))
+ return self.frame.guessbool(self.is_true(self.isinstance(w_obj, w_type)))
def import_name(self, name, glob=None, loc=None, frm=None, level=-1):
try:
More information about the pypy-commit
mailing list