[pypy-svn] r18324 - in pypy/dist/pypy/translator/c: . src

tismer at codespeak.net tismer at codespeak.net
Mon Oct 10 10:24:53 CEST 2005


Author: tismer
Date: Mon Oct 10 10:24:49 2005
New Revision: 18324

Modified:
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/src/debuginfo.h
   pypy/dist/pypy/translator/c/src/exception.h
   pypy/dist/pypy/translator/c/src/int.h
   pypy/dist/pypy/translator/c/src/ll_os.h
   pypy/dist/pypy/translator/c/src/thread_nt.h
Log:
some so-far working source splitting.
This is just a start to have small source files
at all (makes debugging with Windows possible).

Next thing to do is figuring out source info
and grouping pieces together.

(p.s.: Armin fixed a bug in my include file patches)

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Mon Oct 10 10:24:49 2005
@@ -124,7 +124,9 @@
 
 # ____________________________________________________________
 
-SPLIT_CRITERIA = 2000
+SPLIT_CRITERIA = 170
+
+MARKER = '/*/*/' # provide an easy way to split after generating
 
 class SourceGenerator:
     one_source_file = True
@@ -137,10 +139,22 @@
         self.namespace = NameManager()
 
     def set_strategy(self, path):
-        self.all_nodes = list(self.database.globalcontainers())
-        if len(self.all_nodes) >= SPLIT_CRITERIA:
-            pass # self.one_source_file = False
-        # disabled. still a problem: compiles but infinite recursion etc.
+        all_nodes = list(self.database.globalcontainers())
+        # split off non-function nodes
+        # win32 has a problem: compiles but infinite recursion etc.
+        # trytocicumvent this by placing all non-func nodes into one file.
+        funcnodes = []
+        othernodes = []
+        for node in all_nodes:
+            if node.nodekind == 'func':
+                funcnodes.append(node)
+            else:
+                othernodes.append(node)
+        #if len(funcnodes) >= SPLIT_CRITERIA:
+        # always now
+        self.one_source_file = False
+        self.funcnodes = funcnodes
+        self.othernodes = othernodes
         self.path = path
 
     def uniquecname(self, name):
@@ -156,11 +170,14 @@
     def getextrafiles(self):
         return self.extrafiles
 
-    def splitglobalcontainers(self):
+    def getothernodes(self):
+        return self.othernodes[:]
+
+    def splitfuncnodes(self):
         # silly first split, just by node count
         # XXX filter constant stuff off and put it elsewhere
-        nodes = self.all_nodes[:]
-        nchunks = len(nodes) // SPLIT_CRITERIA
+        nodes = self.funcnodes[:]
+        nchunks = len(nodes) // SPLIT_CRITERIA or 1
         chunksize = (len(nodes) + nchunks - 1) // nchunks
         while nodes:
             yield self.uniquecname('implement.c'), nodes[:chunksize]
@@ -225,13 +242,43 @@
         print >> fc, '#include "structdef.h"'
         print >> fc, '#include "forwarddecl.h"'
         print >> fc
+        print >> fc, '#include "src/g_include.h"'
+        print >> fc
+        print >> fc, MARKER
+
+        def render_nonempty(seq):
+            lines = list(seq)
+            if lines:
+                print >> fc, '\n'.join(lines)
+                print >> fc, MARKER
+                return len(lines) + 1
+            return 0
+
         for node in structdeflist:
-            for line in node.definition(phase=2):
-                print >> fc, line
+            render_nonempty(node.definition(phase=2))
+        print >> fc, '/***********************************************************/'
+        fc.close()
+
+        name = self.uniquecname('nonfuncnodes.c')
+        print >> f, '/* %s */' % name
+        fc = self.makefile(name)
+        print >> fc, '/***********************************************************/'
+        print >> fc, '/***  Non-function Implementations                       ***/'
+        print >> fc
+        print >> fc, '#define PYPY_NOT_MAIN_FILE'
+        print >> fc, '#include "common_header.h"'
+        print >> fc, '#include "structdef.h"'
+        print >> fc, '#include "forwarddecl.h"'
+        print >> fc
+        print >> fc, '#include "src/g_include.h"'
         print >> fc
+        print >> fc, MARKER
+        for node in self.getothernodes():
+            render_nonempty(node.implementation())
         print >> fc, '/***********************************************************/'
         fc.close()
-        for name, nodes in self.splitglobalcontainers():
+
+        for name, nodes in self.splitfuncnodes():
             print >> f, '/* %s */' % name
             fc = self.makefile(name)
             print >> fc, '/***********************************************************/'
@@ -247,10 +294,10 @@
             print >> fc
             print >> fc, '#include "src/g_include.h"'
             print >> fc
+            print >> fc, MARKER
+            linecount = 12 + len(self.preimpl)
             for node in nodes:
-                for line in node.implementation():
-                    print >> fc, line
-            print >> fc
+                linecount += render_nonempty(node.implementation())
             print >> fc, '/***********************************************************/'
             fc.close()
         print >> f

Modified: pypy/dist/pypy/translator/c/src/debuginfo.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/debuginfo.h	(original)
+++ pypy/dist/pypy/translator/c/src/debuginfo.h	Mon Oct 10 10:24:49 2005
@@ -13,16 +13,16 @@
 
 /* prototypes */
 
-static PyObject *debuginfo_offset(PyObject *self, PyObject *args);
-static PyObject *debuginfo_global(PyObject *self, PyObject *args);
-static PyObject *debuginfo_peek(PyObject *self, PyObject *args);
+PyObject *debuginfo_offset(PyObject *self, PyObject *args);
+PyObject *debuginfo_global(PyObject *self, PyObject *args);
+PyObject *debuginfo_peek(PyObject *self, PyObject *args);
 
 
 /* implementations */
 
 #ifndef PYPY_NOT_MAIN_FILE
 
-static PyObject *debuginfo_offset(PyObject *self, PyObject *args)
+PyObject *debuginfo_offset(PyObject *self, PyObject *args)
 {
 	int index;
 	if (!PyArg_ParseTuple(args, "i", &index))
@@ -30,7 +30,7 @@
 	return PyInt_FromLong(debuginfo_offsets[index]);
 }
 
-static PyObject *debuginfo_global(PyObject *self, PyObject *args)
+PyObject *debuginfo_global(PyObject *self, PyObject *args)
 {
 	int index;
 	if (!PyArg_ParseTuple(args, "i", &index))
@@ -38,7 +38,7 @@
 	return PyLong_FromVoidPtr(debuginfo_globals[index]);
 }
 
-static PyObject *debuginfo_peek(PyObject *self, PyObject *args)
+PyObject *debuginfo_peek(PyObject *self, PyObject *args)
 {
 	PyObject *o;
 	int size;

Modified: pypy/dist/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/exception.h	(original)
+++ pypy/dist/pypy/translator/c/src/exception.h	Mon Oct 10 10:24:49 2005
@@ -2,16 +2,21 @@
 /************************************************************/
  /***  C header subsection: exceptions                     ***/
 
-#ifndef PYPY_STANDALONE
-   static PyObject *RPythonError;
+#if !defined(PYPY_STANDALONE) && !defined(PYPY_NOT_MAIN_FILE)
+   PyObject *RPythonError;
 #endif 
 
 /******************************************************************/
 #ifdef HAVE_RTYPER               /* RPython version of exceptions */
 /******************************************************************/
 
-static RPYTHON_EXCEPTION_VTABLE	rpython_exc_type = NULL;
-static RPYTHON_EXCEPTION	rpython_exc_value = NULL;
+#ifdef PYPY_NOT_MAIN_FILE
+extern RPYTHON_EXCEPTION_VTABLE	rpython_exc_type;
+extern RPYTHON_EXCEPTION	rpython_exc_value;
+#else
+RPYTHON_EXCEPTION_VTABLE	rpython_exc_type = NULL;
+RPYTHON_EXCEPTION		rpython_exc_value = NULL;
+#endif
 
 #define RPyExceptionOccurred()	(rpython_exc_type != NULL)
 

Modified: pypy/dist/pypy/translator/c/src/int.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/int.h	(original)
+++ pypy/dist/pypy/translator/c/src/int.h	Mon Oct 10 10:24:49 2005
@@ -66,7 +66,7 @@
 #define OP_INT_MUL_OVF(x,y,r,err) \
 	{ \
 		PY_LONG_LONG lr = (PY_LONG_LONG)(x) * (PY_LONG_LONG)(y); \
-		r = lr; \
+		r = (long)lr; \
 		if ((PY_LONG_LONG)r == lr); \
 		else FAIL_OVF(err, "integer multiplication"); \
 	}

Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h	Mon Oct 10 10:24:49 2005
@@ -38,6 +38,11 @@
 
 /* prototypes */
 
+int LL_os_open(RPyString *filename, int flag, int mode);
+long LL_read_into(int fd, RPyString *buffer);
+long LL_os_write(int fd, RPyString *buffer);
+void LL_os_close(int fd);
+int LL_os_dup(int fd);
 RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st);
 RPySTAT_RESULT* LL_os_stat(RPyString * fname);
 RPySTAT_RESULT* LL_os_fstat(long fd);

Modified: pypy/dist/pypy/translator/c/src/thread_nt.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/thread_nt.h	(original)
+++ pypy/dist/pypy/translator/c/src/thread_nt.h	Mon Oct 10 10:24:49 2005
@@ -18,6 +18,7 @@
    identify the thread in the system
  */
 #define RPyThreadGetIdent GetCurrentThreadId
+#define RPyOpaque_INITEXPR_ThreadLock  { 0, 0, NULL }
 
 typedef struct {
 	void (*func)(void*);
@@ -91,8 +92,6 @@
 
 /************************************************************/
 
-#define RPyOpaque_INITEXPR_ThreadLock  { 0, 0, NULL }
-
 
 typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ;
 



More information about the Pypy-commit mailing list