Author: Armin Rigo <ar...@tunes.org> Branch: kill-someobject Changeset: r57816:8b728bceee27 Date: 2012-10-07 16:29 +0200 http://bitbucket.org/pypy/pypy/changeset/8b728bceee27/
Log: Slow progress. Did not find a better way than listing by hand the exceptions in make_raise_noarg(). diff --git a/pypy/annotation/bookkeeper.py b/pypy/annotation/bookkeeper.py --- a/pypy/annotation/bookkeeper.py +++ b/pypy/annotation/bookkeeper.py @@ -444,7 +444,8 @@ elif isinstance(x, (ootype._object)): result = SomeOOObject() elif tp is type: - if x is type(None): # add cases here if needed + if (x is type(None) or # add cases here if needed + x.__module__ == 'pypy.rpython.lltypesystem.lltype'): result = SomeType() else: result = SomePBC([self.getdesc(x)]) diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py --- a/pypy/annotation/builtin.py +++ b/pypy/annotation/builtin.py @@ -189,7 +189,7 @@ for variable in variables: assert bk.annotator.binding(variable) == s_obj r.knowntypedata = {} - if not isinstance(s_type, SomeBuiltin): + if isinstance(s_type, SomePBC): add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ)) return r diff --git a/pypy/annotation/signature.py b/pypy/annotation/signature.py --- a/pypy/annotation/signature.py +++ b/pypy/annotation/signature.py @@ -80,14 +80,14 @@ return SomeUnicodeString() elif t is types.NoneType: return s_None - elif t is type: - return SomeType() elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy): entry = extregistry.lookup_type(t, bookkeeper.policy) return entry.compute_annotation_bk(bookkeeper) elif bookkeeper and t.__module__ != '__builtin__' and t not in bookkeeper.pbctypes: classdef = bookkeeper.getuniqueclassdef(t) return SomeInstance(classdef) + elif t is type: + return SomeType() else: raise AssertionError("annotationoftype(%r)" % (t,)) diff --git a/pypy/rpython/exceptiondata.py b/pypy/rpython/exceptiondata.py --- a/pypy/rpython/exceptiondata.py +++ b/pypy/rpython/exceptiondata.py @@ -51,6 +51,18 @@ classdef = bk.getuniqueclassdef(cls) rclass.getclassrepr(rtyper, classdef).setup() + def make_raise_noarg(self, rtyper): + def ll_raise_noarg(classname): + if classname == 'OverflowError': + raise OverflowError + if classname == 'ValueError': + raise ValueError + if classname == 'ZeroDivisionError': + raise ZeroDivisionError + raise NotImplementedError # we did not special-case this so far + helper_fn = rtyper.annotate_helper_fn(ll_raise_noarg, [annmodel.SomeString()]) + return helper_fn + def make_raise_OSError(self, rtyper): # ll_raise_OSError(errno) def ll_raise_OSError(errno): diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py --- a/pypy/rpython/llinterp.py +++ b/pypy/rpython/llinterp.py @@ -459,13 +459,11 @@ exdata = typer.getexceptiondata() if isinstance(exc, OSError): self.op_direct_call(exdata.fn_raise_OSError, exc.errno) - assert False, "op_direct_call above should have raised" else: - exc_class = exc.__class__ - evalue = self.op_direct_call(exdata.fn_pyexcclass2exc, - self.heap.pyobjectptr(exc_class)) - etype = self.op_direct_call(exdata.fn_type_of_exc_inst, evalue) - raise LLException(etype, evalue, *extraargs) + exc_class = exc.__class__.__name__ + llname = typer.type_system.rstr.string_repr.convert_const(exc_class) + self.op_direct_call(exdata.fn_raise_noarg, llname) + assert False, "op_direct_call above should have raised" def invoke_callable_with_pyexceptions(self, fptr, *args): obj = self.llinterpreter.typer.type_system.deref(fptr) diff --git a/pypy/rpython/lltypesystem/exceptiondata.py b/pypy/rpython/lltypesystem/exceptiondata.py --- a/pypy/rpython/lltypesystem/exceptiondata.py +++ b/pypy/rpython/lltypesystem/exceptiondata.py @@ -14,6 +14,7 @@ self.fn_exception_match = self.make_exception_matcher(rtyper) self.fn_type_of_exc_inst = self.make_type_of_exc_inst(rtyper) self.fn_raise_OSError = self.make_raise_OSError(rtyper) + self.fn_raise_noarg = self.make_raise_noarg(rtyper) def make_exception_matcher(self, rtyper): # ll_exception_matcher(real_exception_vtable, match_exception_vtable) diff --git a/pypy/rpython/ootypesystem/exceptiondata.py b/pypy/rpython/ootypesystem/exceptiondata.py --- a/pypy/rpython/ootypesystem/exceptiondata.py +++ b/pypy/rpython/ootypesystem/exceptiondata.py @@ -21,9 +21,9 @@ def make_helpers(self, rtyper): self.fn_exception_match = self.make_exception_matcher(rtyper) - self.fn_pyexcclass2exc = self.make_pyexcclass2exc(rtyper) self.fn_type_of_exc_inst = self.make_type_of_exc_inst(rtyper) self.fn_raise_OSError = self.make_raise_OSError(rtyper) + self.fn_raise_noarg = self.make_raise_noarg(rtyper) def make_exception_matcher(self, rtyper): # ll_exception_matcher(real_exception_class, match_exception_class) @@ -38,64 +38,5 @@ helper_fn = rtyper.annotate_helper_fn(rclass.ll_inst_type, [s_excinst]) return helper_fn - def make_pyexcclass2exc(self, rtyper): - # ll_pyexcclass2exc(python_exception_class) -> exception_instance - table = {} - Exception_def = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception) - for clsdef in rtyper.class_reprs: - if (clsdef and clsdef is not Exception_def - and clsdef.issubclass(Exception_def)): - if not hasattr(clsdef.classdesc, 'pyobj'): - continue - cls = clsdef.classdesc.pyobj - if cls in self.standardexceptions and cls not in FORCE_ATTRIBUTES_INTO_CLASSES: - is_standard = True - assert not clsdef.attrs, ( - "%r should not have grown attributes" % (cls,)) - else: - is_standard = (cls.__module__ == 'exceptions' - and not clsdef.attrs) - if is_standard: - example = self.get_standard_ll_exc_instance(rtyper, clsdef) - table[cls] = example - r_inst = rclass.getinstancerepr(rtyper, None) - r_inst.setup() - r_class = rclass.getclassrepr(rtyper, None) - r_class.setup() - default_excinst = ootype.new(self.lltype_of_exception_value) - - # build the table in order base classes first, subclasses last - sortedtable = [] - def add_class(cls): - if cls in table: - for base in cls.__bases__: - add_class(base) - sortedtable.append((cls, table[cls])) - del table[cls] - for cls in table.keys(): - add_class(cls) - assert table == {} - - initial_value_of_i = len(sortedtable) - 1 - def pyexcclass2exc(python_exception_class): - python_exception_class = python_exception_class._obj.value - i = initial_value_of_i - while i >= 0: - if issubclass(python_exception_class, sortedtable[i][0]): - return sortedtable[i][1] - i -= 1 - return default_excinst - - # This function will only be used by the llinterpreter which usually - # expects a low-level callable (_meth, _static_meth), so we just - # fake it here. - FakeCallableType = ootype.OOType() - FakeCallableType.ARGS = () - class fake_callable(object): - def __init__(self, fn): - self._TYPE = FakeCallableType - self._callable = fn - return fake_callable(pyexcclass2exc) - def cast_exception(self, TYPE, value): return ootype.ooupcast(TYPE, value) diff --git a/pypy/translator/tool/graphpage.py b/pypy/translator/tool/graphpage.py --- a/pypy/translator/tool/graphpage.py +++ b/pypy/translator/tool/graphpage.py @@ -106,22 +106,14 @@ name = 'no_graph' self.source = make_dot_graphs(name, gs, target=None) # make the dictionary of links -- one per annotated variable - self.binding_history = {} self.current_value = {} - self.caused_by = {} if self.annotator: for var, s_value in self.annotator.bindings.items(): info = '%s: %s' % (var.name, s_value) annotationcolor = getattr(s_value, 'annotationcolor', None) self.links[var.name] = info, annotationcolor self.current_value[var.name] = s_value - self.caused_by[var.name] = ( - self.annotator.binding_caused_by.get(var)) - for var, history in self.annotator.bindingshistory.items(): - cause_history = ( - self.annotator.binding_cause_history.get(var, [])) - self.binding_history[var.name] = zip(history, cause_history) - + #from pypy.jit.hintannotator.annotator import HintAnnotator #if isinstance(self.annotator, HintAnnotator): # return @@ -145,15 +137,6 @@ info = info, (160,160,160) self.links[var.name] = info - def followlink(self, varname): - # clicking on a variable name shows its binding history - cur_value = self.current_value[varname] - caused_by = self.caused_by[varname] - history = list(self.binding_history.get(varname, [])) - history.reverse() - return VariableHistoryGraphPage(self.translator, varname, cur_value, - caused_by, history, self.func_names) - class SingleGraphPage(FlowGraphPage): """ A GraphPage showing a single precomputed FlowGraph.""" _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit