[pypy-svn] r36669 - in pypy/dist/pypy/rpython/ootypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Jan 13 16:31:46 CET 2007
Author: fijal
Date: Sat Jan 13 16:31:45 2007
New Revision: 36669
Modified:
pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
pypy/dist/pypy/rpython/ootypesystem/extdesc.py
pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
Log:
(antonio, fijal) Create new interface for bltregistry, which kills several hacks
broken JS tests, will fix it probably today
Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py Sat Jan 13 16:31:45 2007
@@ -10,18 +10,16 @@
from types import MethodType
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.ootypesystem.extdesc import MethodDesc, ArgDesc
+from pypy.annotation.signature import annotation
class CallableEntry(ExtRegistryEntry):
_type_ = MethodDesc
def compute_annotation(self):
- # because we have no good annotation
- # let's cheat a little bit for a while...
bookkeeper = getbookkeeper()
- # hack, hack, hack, hack, hack, hack, hack, hack, hack, hack, hack,
- values = ["v%d"%i for i in xrange(len(self.instance.args))]
- lb = eval("lambda %s: None" % ",".join(values))
- return annmodel.SomePBC([bookkeeper.getdesc(lb)])
+ args_s = [annotation(i._type) for i in self.instance.args]
+ s_result = annotation(self.instance.result._type)
+ return annmodel.SomeGenericCallable(args=args_s, result=s_result)
class BasicMetaExternal(type):
def _is_compatible(type2):
@@ -47,6 +45,7 @@
_methods = {}
def described(retval=None, args={}):
+ xxx # we'll fix that later
def decorator(func):
code = func.func_code
if not func.func_defaults:
@@ -57,7 +56,7 @@
assert(code.co_argcount < len(defs) + len(args), "Not enough information for describing method")
for arg in xrange(1, code.co_argcount - len(defs)):
- assert code.co_varnames[arg] in args, "Don't have example for arg %s" % code.co_varnames[arg]
+ assert code.co_varnames[arg] in args, "Don't have type for arg %s" % code.co_varnames[arg]
arg_pass = []
start_pos = code.co_argcount - len(defs)
@@ -84,10 +83,10 @@
self.value = value
def __call__(self, *args):
- for i in args:
- if isinstance(i, annmodel.SomePBC):
- bookkeeper = getbookkeeper()
- bookkeeper.pbc_call(i, bookkeeper.build_args("simple_call", (self.s_retval,)))
+ #for i in args:
+ # if isinstance(i, annmodel.SomePBC):
+ # bookkeeper = getbookkeeper()
+ # bookkeeper.pbc_call(i, bookkeeper.build_args("simple_call", (self.s_retval,)))
return self.s_retval
class ExternalType(ootype.OOType):
@@ -104,7 +103,7 @@
def update_fields(self, _fields):
for i, val in _fields.iteritems():
- self._fields[i] = getbookkeeper().annotation_from_example(val)
+ self._fields[i] = annotation(val)
def _is_compatible(type2):
return type(type2) is ExternalType
@@ -115,9 +114,10 @@
_signs = {}
self._fields = {}
for i, val in _methods.iteritems():
- retval = getbookkeeper().annotation_from_example(val.retval.example)
- values = [arg.example for arg in val.args]
- s_args = [getbookkeeper().annotation_from_example(j) for j in values]
+ #s_retval =
+ retval = annotation(val.retval._type)
+ values = [arg._type for arg in val.args]
+ s_args = [annotation(j) for j in values]
_signs[i] = MethodDesc(tuple(s_args), retval)
next = annmodel.SomeBuiltin(Analyzer(i, val, retval, s_args), s_self = annmodel.SomeExternalBuiltin(self), methodname = i)
next.const = True
@@ -166,15 +166,12 @@
def compute_annotation(self):
return annmodel.SomeExternalBuiltin(self.bookkeeper.getexternaldesc\
(self.instance.__class__))
- #return annmodel.SomeExternalBuiltin(ExternalType.get(self.instance.__class__))
def get_field_annotation(self, ext_obj, attr):
return ext_obj.get_field(attr)
def get_arg_annotation(self, ext_obj, attr):
- field = ext_obj._class_._fields[attr]
- assert isinstance(field, MethodDesc)
- return [getbookkeeper().annotation_from_example(arg.example) for arg in field.args]
+ return ext_obj._class_._fields[attr].args_s
def set_field_annotation(self, ext_obj, attr, s_val):
ext_obj.set_field(attr, s_val)
@@ -189,6 +186,3 @@
value = hop.r_result.lowleveltype
return hop.genop('new', [Constant(value, concretetype=ootype.Void)], \
resulttype = value)
-
-#def rebuild_basic_external():
-# ExternalType.class_dict = {}
Modified: pypy/dist/pypy/rpython/ootypesystem/extdesc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/extdesc.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/extdesc.py Sat Jan 13 16:31:45 2007
@@ -6,12 +6,12 @@
""" Description of argument, given as name + example value
(used to deduce type)
"""
- def __init__(self, name, ex_value):
+ def __init__(self, name, _type):
self.name = name
- self.example = ex_value
+ self._type = _type
def __repr__(self):
- return "<ArgDesc %s: %s>" % (self.name, self.example)
+ return "<ArgDesc %s: %s>" % (self.name, self._type)
class MethodDesc(object):
""" Description of method to be external,
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py Sat Jan 13 16:31:45 2007
@@ -2,6 +2,7 @@
""" Builtin annotation test
"""
+import py
from pypy.annotation import model as annmodel
from pypy.objspace.flow import FlowObjSpace
from pypy.annotation.annrpython import RPythonAnnotator
@@ -9,6 +10,7 @@
from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType, MethodDesc
from pypy.rpython.ootypesystem.ootype import Signed, _static_meth, StaticMethod, Void
from pypy.rpython.test.test_llinterp import interpret
+from pypy.annotation.signature import annotation
class C(BasicExternal):
pass
@@ -24,7 +26,7 @@
class A(BasicExternal):
_fields = {
- 'b' : 3,
+ 'b' : int,
}
def test_bltn_attrs():
@@ -51,11 +53,11 @@
class B(BasicExternal):
_fields = {
- 'a' : 32,
+ 'a' : int,
}
_methods = {
- 'm' : MethodDesc([1],2),
+ 'm' : MethodDesc([int], int),
}
def test_bltn_method():
@@ -79,14 +81,14 @@
class CB(BasicExternal):
_fields = {
- 'm': MethodDesc([], 3), # XXX maybe
+ 'm': annmodel.SomeGenericCallable(
+ args=[], result=annmodel.SomeInteger()),
}
def some_int():
return 3
def test_flowin():
- import py; py.test.skip("Indirect call is missing")
def set_callback():
a = CB()
a.m = some_int
@@ -98,7 +100,10 @@
class CC(BasicExternal):
_methods = {
- 'some_method' : MethodDesc(['some_callback', MethodDesc([('some_int', 3)], 3.0)], 3)
+ 'some_method' : MethodDesc(
+ [annmodel.SomeGenericCallable(args=[
+ annmodel.SomeInteger()], result=annmodel.SomeFloat())],
+ int)
}
def test_callback_flowin():
@@ -115,7 +120,9 @@
class CD(BasicExternal):
_fields = {
- 'callback_field' : MethodDesc([('some_int', 3)], 3.0)
+ 'callback_field' :
+ annmodel.SomeGenericCallable([annmodel.SomeInteger()],
+ annmodel.SomeFloat())
}
def test_callback_field():
@@ -129,4 +136,4 @@
a = RPythonAnnotator()
s = a.build_types(callback_field, [])
- assert isinstance(s, annmodel.SomePBC)
+ assert isinstance(s, annmodel.SomeGenericCallable)
More information about the Pypy-commit
mailing list