Author: Ronan Lamy <ronan.l...@gmail.com> Branch: less-stringly-ops Changeset: r66232:d8b2304b850b Date: 2013-08-09 04:48 +0100 http://bitbucket.org/pypy/pypy/changeset/d8b2304b850b/
Log: kill FlowObjSpace.unwrap(), .int_w(), .str_w() diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -662,8 +662,8 @@ def IMPORT_NAME(self, nameindex, next_instr): space = self.space modulename = self.getname_u(nameindex) - glob = space.unwrap(self.w_globals) - fromlist = space.unwrap(self.popvalue()) + glob = self.w_globals.value + fromlist = self.popvalue().value level = self.popvalue().value w_obj = space.import_name(modulename, glob, None, fromlist, level) self.pushvalue(w_obj) @@ -941,7 +941,7 @@ for _ in range(n_keywords): w_value = self.popvalue() w_key = self.popvalue() - key = self.space.str_w(w_key) + key = w_key.value keywords[key] = w_value arguments = self.popvalues(n_arguments) args = CallSpec(arguments, keywords, w_star, w_starstar) diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py --- a/rpython/flowspace/objspace.py +++ b/rpython/flowspace/objspace.py @@ -20,7 +20,6 @@ from rpython.flowspace.specialcase import SPECIAL_CASES from rpython.rlib.unroll import unrolling_iterable, _unroller from rpython.rlib import rstackovf -from rpython.rlib.rarithmetic import is_valid_int # the following gives us easy access to declare more for applications: @@ -68,7 +67,6 @@ (the bytecode of) some function. """ w_None = Constant(None) - builtin = Constant(__builtin__) sys = Constant(sys) w_False = Constant(False) w_True = Constant(True) @@ -120,13 +118,12 @@ return self.w_False def newfunction(self, w_code, w_globals, defaults_w): - try: - code = self.unwrap(w_code) - globals = self.unwrap(w_globals) - defaults = tuple([self.unwrap(value) for value in defaults_w]) - except UnwrapException: + if not all(isinstance(value, Constant) for value in defaults_w): raise FlowingError(self.frame, "Dynamically created function must" " have constant default values.") + code = w_code.value + globals = w_globals.value + defaults = tuple([default.value for default in defaults_w]) fn = types.FunctionType(code, globals, code.co_name, defaults) return Constant(fn) @@ -135,39 +132,14 @@ w_type = const(type(exc)) return FSException(w_type, w_value) - def int_w(self, w_obj): - if isinstance(w_obj, Constant): - val = w_obj.value - if not is_valid_int(val): - raise TypeError("expected integer: " + repr(w_obj)) - return val - return self.unwrap(w_obj) - - def str_w(self, w_obj): - if isinstance(w_obj, Constant): - val = w_obj.value - if type(val) is not str: - raise TypeError("expected string: " + repr(w_obj)) - return val - return self.unwrap(w_obj) - - def unwrap(self, w_obj): - if isinstance(w_obj, Variable): - raise UnwrapException - elif isinstance(w_obj, Constant): - return w_obj.value - else: - raise TypeError("not wrapped: " + repr(w_obj)) - def exception_issubclass_w(self, w_cls1, w_cls2): return 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'.""" - try: - check_class = self.unwrap(w_check_class) - except UnwrapException: + if not isinstance(w_check_class, Constant): raise FlowingError(self.frame, "Non-constant except guard.") + check_class = w_check_class.value if check_class in (NotImplementedError, AssertionError): raise FlowingError(self.frame, "Catching %s is not valid in RPython" % check_class.__name__) @@ -221,7 +193,7 @@ def unpack_sequence(self, w_iterable, expected_length): if isinstance(w_iterable, Constant): - l = list(self.unwrap(w_iterable)) + l = list(w_iterable.value) if len(l) != expected_length: raise ValueError return [const(x) for x in l] @@ -373,11 +345,11 @@ def find_global(self, w_globals, varname): try: - value = self.unwrap(w_globals)[varname] + value = w_globals.value[varname] except KeyError: # not in the globals, now look in the built-ins try: - value = getattr(self.unwrap(self.builtin), varname) + value = getattr(__builtin__, varname) except AttributeError: message = "global name '%s' is not defined" % varname raise FlowingError(self.frame, const(message)) diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py --- a/rpython/flowspace/specialcase.py +++ b/rpython/flowspace/specialcase.py @@ -1,3 +1,5 @@ +from rpython.flowspace.model import Constant + SPECIAL_CASES = {} def register_flow_sc(func): @@ -14,7 +16,8 @@ @register_flow_sc(__import__) def sc_import(space, args_w): assert len(args_w) > 0 and len(args_w) <= 5, 'import needs 1 to 5 arguments' - args = [space.unwrap(arg) for arg in args_w] + assert all(isinstance(arg, Constant) for arg in args_w) + args = [arg.value for arg in args_w] return space.import_name(*args) @register_flow_sc(locals) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit