[pypy-commit] pypy rtyper-stuff: Create LowLevelType._contains_value()
rlamy
noreply at buildbot.pypy.org
Sat Oct 4 00:44:39 CEST 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: rtyper-stuff
Changeset: r73763:098a8b6598ba
Date: 2014-05-14 19:22 +0100
http://bitbucket.org/pypy/pypy/changeset/098a8b6598ba/
Log: Create LowLevelType._contains_value()
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -191,6 +191,11 @@
def _is_varsize(self):
return False
+ def _contains_value(self, value):
+ if self is Void:
+ return True
+ return isCompatibleType(typeOf(value), self)
+
NFOUND = object()
class ContainerType(LowLevelType):
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -2,8 +2,7 @@
from rpython.flowspace.model import Constant
from rpython.rtyper.error import TyperError, MissingRTypeOperation
from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.lltypesystem.lltype import (Void, Bool, typeOf,
- LowLevelType, isCompatibleType)
+from rpython.rtyper.lltypesystem.lltype import Void, Bool, LowLevelType
from rpython.tool.pairtype import pairtype, extendabletype, pair
@@ -120,14 +119,9 @@
def convert_const(self, value):
"Convert the given constant value to the low-level repr of 'self'."
- if self.lowleveltype is not Void:
- try:
- realtype = typeOf(value)
- except (AssertionError, AttributeError, TypeError):
- realtype = '???'
- if realtype != self.lowleveltype:
- raise TyperError("convert_const(self = %r, value = %r)" % (
- self, value))
+ if not self.lowleveltype._contains_value(value):
+ raise TyperError("convert_const(self = %r, value = %r)" % (
+ self, value))
return value
def get_ll_eq_function(self):
@@ -356,18 +350,9 @@
lltype = reqtype
else:
raise TypeError(repr(reqtype))
- # Void Constants can hold any value;
- # non-Void Constants must hold a correctly ll-typed value
- if lltype is not Void:
- try:
- realtype = typeOf(value)
- except (AssertionError, AttributeError):
- realtype = '???'
- if not isCompatibleType(realtype, lltype):
- raise TyperError("inputconst(reqtype = %s, value = %s):\n"
- "expected a %r,\n"
- " got a %r" % (reqtype, value,
- lltype, realtype))
+ if not lltype._contains_value(value):
+ raise TyperError("inputconst(): expected a %r, got %r" %
+ (lltype, value))
c = Constant(value)
c.concretetype = lltype
return c
More information about the pypy-commit
mailing list