Author: Ronan Lamy <[email protected]>
Branch: kill-flowobjspace
Changeset: r60522:d45f1bd16894
Date: 2013-01-26 20:40 +0000
http://bitbucket.org/pypy/pypy/changeset/d45f1bd16894/
Log: Move do_operation* from FlowObjSpace to FSFrame
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -9,11 +9,12 @@
from rpython.tool.stdlib_opcode import host_bytecode_spec
from rpython.flowspace.argument import ArgumentsForTranslation
from rpython.flowspace.model import (Constant, Variable, Block, Link,
- UnwrapException, c_last_exception)
+ UnwrapException, c_last_exception, SpaceOperation)
from rpython.flowspace.framestate import (FrameState, recursively_unflatten,
recursively_flatten)
from rpython.flowspace.specialcase import (rpython_print_item,
rpython_print_newline)
+from rpython.flowspace.operation import implicit_exceptions
class FlowingError(Exception):
""" Signals invalid RPython in the function being analysed"""
@@ -471,6 +472,17 @@
def guessbool(self, w_condition, **kwds):
return self.recorder.guessbool(self, w_condition, **kwds)
+ def do_operation(self, name, *args_w):
+ spaceop = SpaceOperation(name, args_w, Variable())
+ spaceop.offset = self.last_instr
+ self.record(spaceop)
+ return spaceop.result
+
+ def do_operation_with_implicit_exceptions(self, name, *args_w):
+ w_result = self.do_operation(name, *args_w)
+ self.handle_implicit_exceptions(implicit_exceptions.get(name))
+ return w_result
+
def handle_implicit_exceptions(self, exceptions):
"""
Catch possible exceptions implicitly.
@@ -740,7 +752,7 @@
def YIELD_VALUE(self, _, next_instr):
assert self.pycode.is_generator
w_result = self.popvalue()
- self.space.do_operation('yield', w_result)
+ self.do_operation('yield', w_result)
# XXX yield expressions not supported. This will blow up if the value
# isn't popped straightaway.
self.pushvalue(None)
@@ -751,7 +763,7 @@
def PRINT_ITEM(self, oparg, next_instr):
w_item = self.popvalue()
- w_s = self.space.do_operation('str', w_item)
+ w_s = self.do_operation('str', w_item)
self.space.appcall(rpython_print_item, w_s)
def PRINT_NEWLINE(self, oparg, next_instr):
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -9,7 +9,7 @@
from rpython.flowspace.argument import ArgumentsForTranslation
from rpython.flowspace.model import (Constant, Variable, WrapException,
- UnwrapException, checkgraph, SpaceOperation)
+ UnwrapException, checkgraph)
from rpython.flowspace.bytecode import HostCode
from rpython.flowspace import operation
from rpython.flowspace.flowcontext import (FlowSpaceFrame, fixeggblocks,
@@ -91,21 +91,21 @@
id = None # real version added by add_operations()
def newdict(self, module="ignored"):
- return self.do_operation('newdict')
+ return self.frame.do_operation('newdict')
def newtuple(self, args_w):
try:
content = [self.unwrap(w_arg) for w_arg in args_w]
except UnwrapException:
- return self.do_operation('newtuple', *args_w)
+ return self.frame.do_operation('newtuple', *args_w)
else:
return Constant(tuple(content))
def newlist(self, args_w, sizehint=None):
- return self.do_operation('newlist', *args_w)
+ return self.frame.do_operation('newlist', *args_w)
def newslice(self, w_start, w_stop, w_step):
- return self.do_operation('newslice', w_start, w_stop, w_step)
+ return self.frame.do_operation('newslice', w_start, w_stop, w_step)
def newbool(self, b):
if b:
@@ -299,22 +299,10 @@
if not self.is_true(w_correct):
e = self.exc_from_raise(self.w_ValueError, self.w_None)
raise e
- return [self.do_operation('getitem', w_iterable, self.wrap(i))
+ return [self.frame.do_operation('getitem', w_iterable,
self.wrap(i))
for i in range(expected_length)]
# ____________________________________________________________
- def do_operation(self, name, *args_w):
- spaceop = SpaceOperation(name, args_w, Variable())
- spaceop.offset = self.frame.last_instr
- self.frame.record(spaceop)
- return spaceop.result
-
- def do_operation_with_implicit_exceptions(self, name, *args_w):
- w_result = self.do_operation(name, *args_w)
- self.frame.handle_implicit_exceptions(
- operation.implicit_exceptions.get(name))
- return w_result
-
def not_(self, w_obj):
return self.wrap(not self.is_true(w_obj))
@@ -325,7 +313,7 @@
pass
else:
return bool(obj)
- w_truthvalue = self.do_operation('is_true', w_obj)
+ w_truthvalue = self.frame.do_operation('is_true', w_obj)
return self.frame.guessbool(w_truthvalue)
def iter(self, w_iterable):
@@ -336,7 +324,7 @@
else:
if isinstance(iterable, unrolling_iterable):
return self.wrap(iterable.get_unroller())
- w_iter = self.do_operation("iter", w_iterable)
+ w_iter = self.frame.do_operation("iter", w_iterable)
return w_iter
def next(self, w_iter):
@@ -354,7 +342,7 @@
else:
frame.replace_in_stack(it, next_unroller)
return self.wrap(v)
- w_item = self.do_operation("next", w_iter)
+ w_item = frame.do_operation("next", w_iter)
frame.handle_implicit_exceptions([StopIteration, RuntimeError])
return w_item
@@ -363,8 +351,8 @@
if w_obj is self.frame.w_globals:
raise FlowingError(self.frame,
"Attempting to modify global variable %r." % (w_key))
- return self.do_operation_with_implicit_exceptions('setitem', w_obj,
- w_key, w_val)
+ return self.frame.do_operation_with_implicit_exceptions('setitem',
+ w_obj, w_key, w_val)
def setitem_str(self, w_obj, key, w_value):
return self.setitem(w_obj, self.wrap(key), w_value)
@@ -375,7 +363,7 @@
if w_obj in self.not_really_const:
const_w = self.not_really_const[w_obj]
if w_name not in const_w:
- return self.do_operation_with_implicit_exceptions('getattr',
+ return
self.frame.do_operation_with_implicit_exceptions('getattr',
w_obj, w_name)
try:
obj = self.unwrap_for_computation(w_obj)
@@ -394,7 +382,7 @@
return self.wrap(result)
except WrapException:
pass
- return self.do_operation_with_implicit_exceptions('getattr',
+ return self.frame.do_operation_with_implicit_exceptions('getattr',
w_obj, w_name)
def isinstance_w(self, w_obj, w_type):
@@ -414,7 +402,7 @@
if w_module in self.not_really_const:
const_w = self.not_really_const[w_obj]
if w_name not in const_w:
- return self.do_operation_with_implicit_exceptions('getattr',
+ return
self.frame.do_operation_with_implicit_exceptions('getattr',
w_obj, w_name)
try:
return self.wrap(getattr(w_module.value, w_name.value))
@@ -433,7 +421,7 @@
def appcall(self, func, *args_w):
"""Call an app-level RPython function directly"""
w_func = self.wrap(func)
- return self.do_operation('simple_call', w_func, *args_w)
+ return self.frame.do_operation('simple_call', w_func, *args_w)
def call_args(self, w_callable, args):
try:
@@ -454,11 +442,11 @@
# NOTE: annrpython needs to know about the following two operations!
if not kwds_w:
# simple case
- w_res = self.do_operation('simple_call', w_callable, *args_w)
+ w_res = self.frame.do_operation('simple_call', w_callable, *args_w)
else:
# general case
shape, args_w = args.flatten()
- w_res = self.do_operation('call_args', w_callable, Constant(shape),
+ w_res = self.frame.do_operation('call_args', w_callable,
Constant(shape),
*args_w)
# maybe the call has generated an exception (any one)
@@ -562,7 +550,7 @@
# type cannot sanely appear in flow graph,
# store operation with variable result instead
pass
- w_result = self.do_operation_with_implicit_exceptions(name, *args_w)
+ w_result = self.frame.do_operation_with_implicit_exceptions(name,
*args_w)
return w_result
setattr(FlowObjSpace, name, generic_operator)
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -18,7 +18,7 @@
if opname == 'pow' and len(args_w) == 2:
args_w = args_w + [Constant(None)]
elif opname == 'getattr' and len(args_w) == 3:
- return space.do_operation('simple_call', Constant(getattr),
*args_w)
+ return space.frame.do_operation('simple_call', Constant(getattr),
*args_w)
else:
raise Exception, "should call %r with exactly %d arguments" % (
fn, Arity[opname])
@@ -60,7 +60,7 @@
[w_value] = args_w
if isinstance(w_value, Constant):
return Constant(r_uint(w_value.value))
- return space.do_operation('simple_call', space.wrap(r_uint), w_value)
+ return space.frame.do_operation('simple_call', space.wrap(r_uint), w_value)
def sc_we_are_translated(space, we_are_translated, args):
return Constant(True)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit