Alex Gaynor avatar Alex Gaynor committed 3489b70

(fijal, alex): added getshape()

Comments (0)

Files changed (2)


     def getlength(self):
         return len(self.shape)
+    def getshape(self):
+        return self.shape
     def getint(self, idx):
         assert self.shape[idx] == INT
         v =[idx]
     def method_getlength(self):
         return annmodel.SomeInteger()
+    def method_getshape(self):
+        return annmodel.SomeString(can_be_None=False)
     def method_getint(self, s_idx):
         return annmodel.SomeInteger()
         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)


 import py
 from pypy.rlib import rerased_raw
+from pypy.rpython.annlowlevel import hlstr
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
     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):
             return storage.getlength()
         res = self.interpret(f, [])
-        assert res == 3
+        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"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.