[pypy-svn] r49308 - in pypy/dist/pypy/translator/jvm: src/pypy test

niko at codespeak.net niko at codespeak.net
Mon Dec 3 10:33:11 CET 2007


Author: niko
Date: Mon Dec  3 10:33:10 2007
New Revision: 49308

Modified:
   pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
   pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
   pypy/dist/pypy/translator/jvm/test/test_builtin.py
Log:
implement unlink, mkdir, frexp, and add a test or two

Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java	Mon Dec  3 10:33:10 2007
@@ -978,11 +978,48 @@
         return x % y;
     }
 
-    /* TODO
-    public double ll_math_frexp(double x) {
-    }
-    */
+    public Object ll_math_frexp(double x) {
+        /*
+          Return the mantissa and exponent of x as the pair (m, e). m
+          is a float and e is an integer such that x == m * 2**e
+          exactly. If x is zero, returns (0.0, 0), otherwise 0.5 <=
+          abs(m) < 1. This is used to "pick apart" the internal
+          representation of a float in a portable way.
+        */
+
+        // NaN: Python returns (NaN, 0)
+        if (Double.isNaN(x))
+            return interlink.recordFloatSigned(x, 0);
+
+        // Infinity: Python throws exception
+        if (Double.isInfinite(x))
+            interlink.throwOverflowError();
 
+        // Extract the various parts of the format:
+        final long e=11, f=52; // number of bits in IEEE format
+        long bits = Double.doubleToLongBits(x);
+        long bits_mantissa = bits & ((1 << f) - 1);
+        int bits_exponent = (int)((bits >> f) & ((1 << e) - 1));
+        int bits_sign = (int)(bits >> (e+f));
+
+        // [+-]0
+        if (bits_exponent == 0 && bits_mantissa == 0)
+            return interlink.recordFloatSigned(x, 0);
+
+        // TODO: Non-looping impl
+        double mantissa = x;
+        int exponent = 0;
+        while (mantissa > 1) {
+            mantissa /= 2;
+            exponent += 1;
+        }
+        while (mantissa < 0.5) {
+            mantissa *= 2;
+            exponent -= 1;
+        }
+        return interlink.recordFloatSigned(mantissa, exponent); 
+    }
+          
     public double ll_math_ldexp(double v, int w) {
         return check(v * Math.pow(2.0, w));
     }
@@ -996,8 +1033,8 @@
         return Math.exp(x);
     }
 
-    public double ll_math_log(double x, double base) {
-        return Math.log10(x) / Math.log10(base);
+    public double ll_math_log(double x) {
+        return Math.log(x);
     }
 
     public double ll_math_log10(double v) {

Modified: pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java	Mon Dec  3 10:33:10 2007
@@ -357,6 +357,29 @@
         return text.length();
     }
 
+    public void ll_os_mkdir(String path, int mode) {
+        File f = new File(path);
+        if (f.exists())
+            throwOSError(PyPy.EEXIST, "File exists: '"+path+"'");
+        if (!f.mkdir())
+            throwOSError(PyPy.EPERM, "Operation not permitted: '"+path+"'");
+    }
+
+    public void ll_os_unlink(String path) {
+        if (STRACE) strace("ll_os_unlink: "+path);
+
+        File f = new File(path);
+
+        if (!f.exists())
+            throwOSError(PyPy.ENOENT, "No such file or directory: '"+path+"'");
+
+        if (f.isDirectory())
+            throwOSError(PyPy.EPERM, "Operation not permitted: '"+path+"'");
+
+        if (!f.delete())
+            throwOSError(PyPy.EPERM, "Operation not permitted: '"+path+"'");
+    }
+
     public boolean ll_os_isatty(int x)
     {
         // XXX: this is not the right behaviour, but it's needed

Modified: pypy/dist/pypy/translator/jvm/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/test_builtin.py	(original)
+++ pypy/dist/pypy/translator/jvm/test/test_builtin.py	Mon Dec  3 10:33:10 2007
@@ -14,12 +14,6 @@
         skip_win()
         BaseTestBuiltin.test_os_write_magic(self)
 
-    def test_builtin_math_frexp(self):
-        py.test.skip("metavm.py needs to be updated to handle this math op; graphless extrernal")
-        
-    def test_builtin_math_modf(self):
-        py.test.skip("metavm.py needs to be updated to handle this math op; graphless extrernal")
-
     def test_os_path_exists(self):
         py.test.skip("fails in annotation stage, unrelated to JVM I think")
         



More information about the Pypy-commit mailing list