[pypy-svn] r47111 - in pypy/dist/pypy/translator/jvm: . src/pypy test
niko at codespeak.net
niko at codespeak.net
Wed Oct 3 06:31:50 CEST 2007
Author: niko
Date: Wed Oct 3 06:31:49 2007
New Revision: 47111
Added:
pypy/dist/pypy/translator/jvm/src/pypy/RecordStringString.java
Modified:
pypy/dist/pypy/translator/jvm/database.py
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
pypy/dist/pypy/translator/jvm/typesystem.py
Log:
fix a few of the builtin functions
Modified: pypy/dist/pypy/translator/jvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/database.py (original)
+++ pypy/dist/pypy/translator/jvm/database.py Wed Oct 3 06:31:49 2007
@@ -473,6 +473,11 @@
ootype.CustomDict: jvmtype.jPyPyCustomDict,
ootype.WeakReference: jvmtype.jPyPyWeakRef,
ll_os.STAT_RESULT: jvmtype.jPyPyStatResult,
+
+ # These are some configured records that are generated by Java
+ # code.
+ ootype.Record({"item0": ootype.String, "item1": ootype.String}):
+ jvmtype.jPyPyRecordStringString,
}
def lltype_to_cts(self, OOT):
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 Wed Oct 3 06:31:49 2007
@@ -269,7 +269,11 @@
return result;
}
- // Used in testing:
+ // Used in testing the JVM backend:
+ //
+ // A series of methods which serve a similar purpose to repr() in Python:
+ // they create strings that can be exec'd() to rebuild data structures.
+ // Also methods for writing to System.out.
public static void dump(String text) {
System.out.println(text);
@@ -343,6 +347,17 @@
public static String serializeObject(Object o) {
if (o == null)
return "None";
+ if (o instanceof ArrayList) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[");
+ for (Object obj : (ArrayList)o)
+ sb.append(serializeObject(obj)).append(",");
+ sb.append("]");
+ return sb.toString();
+ }
+ else if (o instanceof String) {
+ return escaped_string((String)o);
+ }
return o.toString();
}
@@ -800,8 +815,20 @@
public static double ll_time_time() {
return System.currentTimeMillis()/1000.0;
}
-
-
+
+ public static void ll_time_sleep(double seconds)
+ {
+ double startTime = ll_time_time();
+ double endTime = startTime + seconds;
+ do {
+ try {
+ Thread.sleep((int)((endTime-startTime)*1000));
+ return;
+ } catch (InterruptedException exc) {}
+ startTime = ll_time_time();
+ } while (startTime < endTime);
+ }
+
public static String ll_join(String a, String b)
{
return a + "/" + b; // XXX
Added: pypy/dist/pypy/translator/jvm/src/pypy/RecordStringString.java
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/jvm/src/pypy/RecordStringString.java Wed Oct 3 06:31:49 2007
@@ -0,0 +1,10 @@
+package pypy;
+
+public final class RecordStringString {
+ public String item0, item1;
+ public RecordStringString() {
+ }
+ public RecordStringString(String i0, String i1) {
+ item0 = i0; item1 = i1;
+ }
+}
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 Wed Oct 3 06:31:49 2007
@@ -4,6 +4,9 @@
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Arrays;
abstract class FileWrapper
{
@@ -323,10 +326,52 @@
else
return false;
}
+
+ public static String ll_os_getenv(String key)
+ {
+ return System.getenv(key);
+ }
+
+ public static void ll_os_putenv(String key, String value)
+ {
+ //System.setenv(key, value);
+ // it appears that there is no such method??!!
+ }
+
+ public static ArrayList ll_os_envkeys()
+ {
+ Map variables = System.getenv();
+ Set variableNames = variables.keySet();
+ return new ArrayList(variableNames);
+ }
public static ArrayList ll_os_envitems()
{
- return new ArrayList(); // XXX
+ Map variables = System.getenv();
+ Set variableNames = variables.keySet();
+ Iterator nameIterator = variableNames.iterator();
+ ArrayList result = new ArrayList();
+
+ for (int index = 0; index < variableNames.size(); index++)
+ {
+ String name = (String) nameIterator.next();
+ String value = (String) variables.get(name);
+ result.add(new RecordStringString(name, value));
+ }
+
+ return result;
+ }
+
+ public static ArrayList<String> ll_os_listdir(String path)
+ {
+ if (path == "")
+ throwOSError(PyPy.ENOENT, "No such file or directory: ''");
+
+ File f = new File(path);
+ if (!f.exists() || !f.isDirectory())
+ throwOSError(PyPy.ENOENT, "No such file or directory: '"+path+"'");
+
+ return new ArrayList(Arrays.asList(f.list()));
}
public static String ll_os_getcwd()
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 Wed Oct 3 06:31:49 2007
@@ -23,14 +23,8 @@
def test_os_dup(self):
py.test.skip("not implemented")
- def test_environ_items(self):
- py.test.skip('fixme!')
-
def test_environ(self):
- py.test.skip('fixme!')
-
- def test_os_listdir(self):
- py.test.skip('fixme!')
+ py.test.skip('fixme! how to set environment variables in Java?')
def test_os_read_binary_crlf(self):
py.test.skip('fixme!')
@@ -39,6 +33,5 @@
class TestJvmTime(JvmTest, BaseTestTime):
- def test_time_sleep(self):
- py.test.skip('fixme!')
+ pass
Modified: pypy/dist/pypy/translator/jvm/typesystem.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/typesystem.py (original)
+++ pypy/dist/pypy/translator/jvm/typesystem.py Wed Oct 3 06:31:49 2007
@@ -179,6 +179,7 @@
jPyPyStatResult = JvmClassType('pypy.StatResult')
jPyPyWeakRef = JvmClassType('pypy.PyPyWeakRef')
jll_os = JvmClassType('pypy.ll_os')
+jPyPyRecordStringString = JvmClassType('pypy.RecordStringString')
jArithmeticException = JvmClassType('java.lang.ArithmeticException', throwable=True)
More information about the Pypy-commit
mailing list