[pypy-svn] r36574 - in pypy/dist/pypy/translator/jvm: . src/pypy
niko at codespeak.net
niko at codespeak.net
Fri Jan 12 14:54:12 CET 2007
Author: niko
Date: Fri Jan 12 14:54:05 2007
New Revision: 36574
Modified:
pypy/dist/pypy/translator/jvm/builtin.py
pypy/dist/pypy/translator/jvm/database.py
pypy/dist/pypy/translator/jvm/generator.py
pypy/dist/pypy/translator/jvm/opcodes.py
pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
Log:
(antocuni, niko) fix it enough to run pystone translated
Modified: pypy/dist/pypy/translator/jvm/builtin.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/builtin.py (original)
+++ pypy/dist/pypy/translator/jvm/builtin.py Fri Jan 12 14:54:05 2007
@@ -41,8 +41,6 @@
# Look for a shortcut method in our table of remappings:
try:
key = (self.OOTYPE.__class__, methodnm)
- print "key=%r" % (key,)
- print "hash=%r" % (built_in_methods,)
return built_in_methods[key]
except KeyError: pass
Modified: pypy/dist/pypy/translator/jvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/database.py (original)
+++ pypy/dist/pypy/translator/jvm/database.py Fri Jan 12 14:54:05 2007
@@ -76,7 +76,14 @@
#
# Creates nodes that represents classes, functions, simple constants.
- def _types_for_graph(self, graph):
+ def types_for_graph(self, graph):
+ """
+ Given a graph, returns a tuple like so:
+ ( (java argument types...), java return type )
+ For example, if the graph took two strings and returned a bool,
+ then the return would be:
+ ( (jString, jString), jBool )
+ """
argtypes = [arg.concretetype for arg in graph.getargs()
if arg.concretetype is not ootype.Void]
jargtypes = tuple([self.lltype_to_cts(argty) for argty in argtypes])
@@ -90,7 +97,7 @@
Creates a node.Function object for a particular graph. Adds
the method to 'classobj', which should be a node.Class object.
"""
- jargtypes, jrettype = self._types_for_graph(graph)
+ jargtypes, jrettype = self.types_for_graph(graph)
funcobj = node.Function(
self, classobj, funcnm, jargtypes, jrettype, graph, is_static)
return funcobj
@@ -231,7 +238,7 @@
def record_delegate_impl(self, graph):
""" TYPE is a StaticMethod """
- jargtypes, jrettype = self._types_for_graph(graph)
+ jargtypes, jrettype = self.types_for_graph(graph)
key = (jargtypes, jrettype)
assert key in self._delegates
pfunc = self.pending_function(graph)
Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py (original)
+++ pypy/dist/pypy/translator/jvm/generator.py Fri Jan 12 14:54:05 2007
@@ -911,7 +911,9 @@
self.prepare_generic_result(RETTYPE)
def call_primitive(self, graph):
- raise NotImplementedError
+ argtypes, rettype = self.db.types_for_graph(graph)
+ mthd = Method.s(jPyPy, graph.func.func_name, argtypes, rettype)
+ self.emit(mthd)
def call_oostring(self, OOTYPE):
cts_type = self.db.lltype_to_cts(OOTYPE)
@@ -1006,7 +1008,8 @@
elif value == 1.0:
self.emit(DCONST_1)
else:
- self.emit(LDC2, value)
+ # Big hack to avoid exponential notation:
+ self.emit(LDC2, "%22.22f" % value)
# __________________________________________________________________
# Methods invoked directly by strings in jvm/opcode.py
@@ -1092,7 +1095,7 @@
def _dbl_compare_op(self, cmpopcode):
# XXX --- NaN behavior?
- self._invoke(DCMPG)
+ self.emit(DCMPG)
self._compare_op(cmpopcode)
dbl_equals = lambda self: self._dbl_compare_op(IFEQ)
@@ -1103,7 +1106,7 @@
dbl_greater_equals = lambda self: self._dbl_compare_op(IFGE)
def _long_compare_op(self, cmpopcode):
- self._invoke(LCMP)
+ self.emit(LCMP)
self._compare_op(cmpopcode)
long_equals = lambda self: self._long_compare_op(IFEQ)
@@ -1194,6 +1197,9 @@
assert isinstance(lbl, Label)
self.curclass.out(' %s:\n' % lbl.jasmin_syntax())
+ # We count labels as instructions because ASM does:
+ self.curfunc.instr_counter += 1
+
def _instr(self, opcode, *args):
jvmstr, args = opcode.specialize(args)
def jasmin_syntax(arg):
Modified: pypy/dist/pypy/translator/jvm/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/opcodes.py (original)
+++ pypy/dist/pypy/translator/jvm/opcodes.py Fri Jan 12 14:54:05 2007
@@ -33,7 +33,7 @@
'oodowncast': [DownCast, StoreResult],
'oois': 'ref_is_eq',
'oononnull': 'is_not_null',
- 'instanceof': CastTo,
+ 'instanceof': [CastTo, StoreResult],
'subclassof': [PushAllArgs, jvmgen.SWAP, jvmgen.CLASSISASSIGNABLEFROM, StoreResult],
'ooidentityhash': [PushAllArgs, jvmgen.OBJHASHCODE, StoreResult],
'oohash': [PushAllArgs, jvmgen.OBJHASHCODE, StoreResult],
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 Fri Jan 12 14:54:05 2007
@@ -425,7 +425,9 @@
public static ArrayList array_to_list(Object[] array)
{
- return new ArrayList(java.util.Arrays.asList(array));
+ ArrayList list = new ArrayList(java.util.Arrays.asList(array));
+ list.add(0, "dummy_executable_name");
+ return list;
}
// ----------------------------------------------------------------------
@@ -476,6 +478,24 @@
}
// ----------------------------------------------------------------------
+ // Primitive built-in functions
+
+ public static double ll_time_clock() {
+ return System.currentTimeMillis()/1000;
+ }
+
+ public static int ll_os_write(int fd, String text) {
+ // TODO: file descriptors, etc
+ if (fd == 1)
+ System.out.print(text);
+ else if (fd == 2)
+ System.err.print(text);
+ else
+ throw new RuntimeException("Invalid FD");
+ return text.length();
+ }
+
+ // ----------------------------------------------------------------------
// Exceptions
//
// If we don't use true Java exceptions, then this
@@ -523,6 +543,7 @@
}
public static void _ll_resize_le(ArrayList self, int length) {
+ System.err.println("ll_resize_le: self.size()="+self.size()+" length="+length);
while (self.size() > length) {
self.remove(self.size()-1);
}
@@ -532,8 +553,8 @@
if (length > self.size())
_ll_resize_ge(self, length);
else if (length < self.size())
- _ll_resize_le(self, length);
- }
+ _ll_resize_le(self, length);
+ }
// ----------------------------------------------------------------------
// Self Test
More information about the Pypy-commit
mailing list