[pypy-commit] pypy erase-raw-mem: (fijal, alex): added getlength
alex_gaynor
noreply at buildbot.pypy.org
Tue Mar 13 07:51:14 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: erase-raw-mem
Changeset: r53422:adeea4f9ee88
Date: 2012-03-12 23:50 -0700
http://bitbucket.org/pypy/pypy/changeset/adeea4f9ee88/
Log: (fijal, alex): added getlength
diff --git a/pypy/rlib/rerased_raw.py b/pypy/rlib/rerased_raw.py
--- a/pypy/rlib/rerased_raw.py
+++ b/pypy/rlib/rerased_raw.py
@@ -22,6 +22,9 @@
self.storage = [None] * len(shape)
self.shape = shape
+ def getlength(self):
+ return len(self.shape)
+
def getint(self, idx):
assert self.shape[idx] == INT
v = self.storage[idx]
@@ -72,6 +75,9 @@
def rtyper_makerepr(self, rtyper):
return UntypedStorageRepr()
+ def method_getlength(self):
+ return annmodel.SomeInteger()
+
def method_getint(self, s_idx):
self._check_idx(s_idx)
return annmodel.SomeInteger()
@@ -165,6 +171,11 @@
hop.exception_cannot_occur()
return hop.gendirectcall(self.ll_new, v_shape)
+ def rtype_method_getlength(self, hop):
+ [v_arr] = hop.inputargs(self)
+ hop.exception_cannot_occur()
+ return hop.gendirectcall(self.ll_getlength, v_arr)
+
def rtype_method_getint(self, hop):
v_addr = self._read_index(hop)
return hop.genop("force_cast", [v_addr], resulttype=lltype.Signed)
@@ -201,4 +212,8 @@
def ll_new(cls, shape):
obj = lltype.malloc(cls.lowleveltype.TO, len(shape.chars))
obj.shape = shape
- return obj
\ No newline at end of file
+ return obj
+
+ @classmethod
+ def ll_getlength(cls, arr):
+ return len(arr.shape.chars)
diff --git a/pypy/rlib/test/test_rerased_raw.py b/pypy/rlib/test/test_rerased_raw.py
--- a/pypy/rlib/test/test_rerased_raw.py
+++ b/pypy/rlib/test/test_rerased_raw.py
@@ -29,6 +29,10 @@
assert storage.getinstance(0, A).value == 4
+def test_direct_length():
+ storage = rerased_raw.UntypedStorage("ooi")
+ assert storage.getlength() == 3
+
class TestRerasedRawLLType(LLRtypeMixin, BaseRtypingTest):
def test_int(self):
@@ -92,3 +96,11 @@
res = self.interpret(f, [True, 15])
assert res == 15
+
+ def test_getlength(self):
+ def f():
+ storage = rerased_raw.UntypedStorage("ooi")
+ return storage.getlength()
+
+ res = self.interpret(f, [])
+ assert res == 3
\ No newline at end of file
More information about the pypy-commit
mailing list