[pypy-svn] r25417 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Wed Apr 5 20:41:59 CEST 2006
Author: antocuni
Date: Wed Apr 5 20:41:46 2006
New Revision: 25417
Modified:
pypy/dist/pypy/translator/cli/class_.py
pypy/dist/pypy/translator/cli/cts.py
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/gencli.py
pypy/dist/pypy/translator/cli/ilgenerator.py
pypy/dist/pypy/translator/cli/test/compile.py
Log:
Added namespace support
Modified: pypy/dist/pypy/translator/cli/class_.py
==============================================================================
--- pypy/dist/pypy/translator/cli/class_.py (original)
+++ pypy/dist/pypy/translator/cli/class_.py Wed Apr 5 20:41:46 2006
@@ -5,14 +5,17 @@
class Class(Node):
def __init__(self, classdef):
self.classdef = classdef
+ self.namespace, self.name = cts.split_class_name(classdef._name)
def get_name(self):
- return self.classdef._name
+ return self.name
def render(self, ilasm):
self.ilasm = ilasm
- name = self.get_name().replace('__main__.', '') # TODO: handle modules
- ilasm.begin_class(name) # TODO: handle base class
+ if self.namespace:
+ ilasm.begin_namespace(self.namespace)
+
+ ilasm.begin_class(self.name) # TODO: handle base class
for f_name, (f_type, f_default) in self.classdef._fields.iteritems():
# TODO: handle default values
ilasm.field(f_name, cts.lltype_to_cts(f_type))
@@ -27,6 +30,9 @@
ilasm.end_class()
+ if self.namespace:
+ ilasm.end_namespace()
+
def _ctor(self):
self.ilasm.begin_function('.ctor', [], 'void', False, 'specialname', 'rtspecialname', 'instance')
self.ilasm.opcode('ldarg.0')
Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py (original)
+++ pypy/dist/pypy/translator/cli/cts.py Wed Apr 5 20:41:46 2006
@@ -92,6 +92,13 @@
return '%s %s(%s)' % (ret_type, func_name, arg_list)
+def split_class_name(class_name):
+ parts = class_name.rsplit('.', 1)
+ if len(parts) == 2:
+ return parts
+ else:
+ return None, parts[0]
+
_pyexception_to_cts = {
exceptions.Exception: '[mscorlib]System.Exception',
exceptions.OverflowError: '[mscorlib]System.OverflowException'
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Wed Apr 5 20:41:46 2006
@@ -229,7 +229,7 @@
return cts.graph_to_signature(graph, True, name)
def class_name(self, ooinstance):
- return ooinstance._name.replace('__main__.', '') # TODO: modules
+ return ooinstance._name
def emit(self, instr, *args):
self.ilasm.opcode(instr, *args)
@@ -249,6 +249,8 @@
def call_method(self, obj, name):
owner, meth = obj._lookup(name)
full_name = '%s::%s' % (self.class_name(obj), name)
+ # TODO: there are cases when we don't need callvirt but a
+ # plain call is sufficient
self.ilasm.call_method(self.method_signature(meth.graph, full_name))
def load(self, v):
Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py (original)
+++ pypy/dist/pypy/translator/cli/gencli.py Wed Apr 5 20:41:46 2006
@@ -61,7 +61,7 @@
# TODO: remove this test
if graph.name.startswith('ll_'):
continue
-
+
if '.' not in graph.name: # it's not a method
f = Function(graph)
f.render(self.ilasm)
Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py Wed Apr 5 20:41:46 2006
@@ -42,6 +42,13 @@
def close(self):
self.out.close()
+ def begin_namespace(self, name):
+ self.code.writeline('.namespace ' + name)
+ self.code.openblock()
+
+ def end_namespace(self):
+ self.code.closeblock()
+
def begin_class(self, name, base = None):
if base is None:
base = '[mscorlib]System.Object'
Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py (original)
+++ pypy/dist/pypy/translator/cli/test/compile.py Wed Apr 5 20:41:46 2006
@@ -1,5 +1,4 @@
#!/bin/env python
-
import sys
import py
from pypy.rpython.rarithmetic import r_int, r_uint, r_ulonglong, r_longlong, ovfcheck
More information about the Pypy-commit
mailing list