[pypy-commit] pypy erase-raw-mem: (fijal, alex): added getshape()
alex_gaynor
noreply at buildbot.pypy.org
Tue Mar 13 07:59:53 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: erase-raw-mem
Changeset: r53423:3489b70178b4
Date: 2012-03-12 23:59 -0700
http://bitbucket.org/pypy/pypy/changeset/3489b70178b4/
Log: (fijal, alex): added getshape()
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
@@ -25,6 +25,9 @@
def getlength(self):
return len(self.shape)
+ def getshape(self):
+ return self.shape
+
def getint(self, idx):
assert self.shape[idx] == INT
v = self.storage[idx]
@@ -78,6 +81,9 @@
def method_getlength(self):
return annmodel.SomeInteger()
+ def method_getshape(self):
+ return annmodel.SomeString(can_be_None=False)
+
def method_getint(self, s_idx):
self._check_idx(s_idx)
return annmodel.SomeInteger()
@@ -176,6 +182,12 @@
hop.exception_cannot_occur()
return hop.gendirectcall(self.ll_getlength, v_arr)
+ def rtype_method_getshape(self, hop):
+ [v_arr] = hop.inputargs(self)
+ hop.exception_cannot_occur()
+ c_name = hop.inputconst(lltype.Void, "shape")
+ return hop.genop("getfield", [v_arr, c_name], resulttype=string_repr)
+
def rtype_method_getint(self, hop):
v_addr = self._read_index(hop)
return hop.genop("force_cast", [v_addr], resulttype=lltype.Signed)
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
@@ -1,6 +1,7 @@
import py
from pypy.rlib import rerased_raw
+from pypy.rpython.annlowlevel import hlstr
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
@@ -29,10 +30,14 @@
assert storage.getinstance(0, A).value == 4
-def test_direct_length():
+def test_direct_getlength():
storage = rerased_raw.UntypedStorage("ooi")
assert storage.getlength() == 3
+def test_direct_getshape():
+ storage = rerased_raw.UntypedStorage("ooi")
+ assert storage.getshape() == "ooi"
+
class TestRerasedRawLLType(LLRtypeMixin, BaseRtypingTest):
def test_int(self):
@@ -103,4 +108,12 @@
return storage.getlength()
res = self.interpret(f, [])
- assert res == 3
\ No newline at end of file
+ assert res == 3
+
+ def test_getshape(self):
+ def f():
+ storage = rerased_raw.UntypedStorage("ooi")
+ return storage.getshape()
+
+ llres = self.interpret(f, [])
+ assert hlstr(llres) == "ooi"
\ No newline at end of file
More information about the pypy-commit
mailing list