[pypy-svn] r30759 - in pypy/dist/pypy/translator/cli: . src src/stub test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Jul 31 10:51:31 CEST 2006
Author: antocuni
Date: Mon Jul 31 10:51:12 2006
New Revision: 30759
Modified:
pypy/dist/pypy/translator/cli/gencli.py
pypy/dist/pypy/translator/cli/prebuiltgraphs.py
pypy/dist/pypy/translator/cli/src/ll_os.cs
pypy/dist/pypy/translator/cli/src/stub/main.il
pypy/dist/pypy/translator/cli/test/runtest.py
Log:
Some refactoring around prebuiltgraphs:
- get_prebuilt_graphs has been renamed to get_prebuilt_nodes,
because it could returns any kind of node, not only functions;
- now it is called directly inside gencli, instead of passing
pending_graphs as a parameter to its constructor;
- raiseExceptions is not longer needed, because all exceptions used
by IL code are already automatically generated;
- use exceptiondata.ll_raise_OSError instead of our own raiseOSError;
- prebuilt functions are now grouped into the pypy.runtime.Helpers
class instead of the global PrebuiltGraphs class, to avoid name
clashes.
Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py (original)
+++ pypy/dist/pypy/translator/cli/gencli.py Mon Jul 31 10:51:12 2006
@@ -13,7 +13,7 @@
from pypy.translator.cli.sdk import SDK
from pypy.translator.cli.rte import get_pypy_dll
from pypy.translator.cli.support import Tee
-
+from pypy.translator.cli.prebuiltgraphs import get_prebuilt_nodes
class GenCli(object):
def __init__(self, tmpdir, translator, entrypoint=None, type_system_class=CTS,
@@ -25,8 +25,8 @@
self.db = database_class(type_system_class = type_system_class, opcode_dict = opcode_dict,
function_class = function_class)
- for graph, functype in pending_graphs:
- self.db.pending_function(graph, functype)
+ for node in get_prebuilt_nodes(translator, self.db):
+ self.db.pending_node(node)
if entrypoint is None:
self.assembly_name = self.translator.graphs[0].name
Modified: pypy/dist/pypy/translator/cli/prebuiltgraphs.py
==============================================================================
--- pypy/dist/pypy/translator/cli/prebuiltgraphs.py (original)
+++ pypy/dist/pypy/translator/cli/prebuiltgraphs.py Mon Jul 31 10:51:12 2006
@@ -1,43 +1,13 @@
from pypy.translator.cli.function import Function
-class PrebuiltGraph(Function):
+class Helper(Function):
def render(self, ilasm):
- ilasm.begin_class('PrebuiltGraphs')
+ ilasm.begin_namespace('pypy.runtime')
+ ilasm.begin_class('Helpers')
Function.render(self, ilasm)
ilasm.end_class()
+ ilasm.end_namespace()
-## The following functions are used for construct prebuilt graphs.
-
-## We need prebuilt graphs for force rendering of some classes
-## (e.g. some kind of exception) or because they are used by pypylib
-## (see the comment in src/stub/main.il).
-def raiseExceptions(switch):
- if switch == 0:
- raise ValueError
- elif switch == 1:
- raise OverflowError
- else:
- raise ZeroDivisionError
-
-def raiseOSError(errno):
- raise OSError(errno, None)
-
-PREBUILT_GRAPHS = [(raiseExceptions, [int], PrebuiltGraph),
- (raiseOSError, [int], PrebuiltGraph),
- ]
-
-def get_prebuilt_graphs(translator):
- functions = {}
- for fn, annotation, functype in PREBUILT_GRAPHS:
- functions[fn] = functype
- translator.annotator.build_types(fn, annotation)
-
- res = []
- for graph in translator.graphs:
- try:
- functype = functions[graph.func]
- res.append((graph, functype))
- except (AttributeError, KeyError):
- pass
- return res
-
+def get_prebuilt_nodes(translator, db):
+ raise_OSError_graph = translator.rtyper.exceptiondata.fn_raise_OSError.graph
+ return [Helper(db, raise_OSError_graph, 'raise_OSError')]
Modified: pypy/dist/pypy/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/ll_os.cs (original)
+++ pypy/dist/pypy/translator/cli/src/ll_os.cs Mon Jul 31 10:51:12 2006
@@ -122,7 +122,7 @@
return res;
}
// path is not a file nor a dir, raise OSError
- PrebuiltGraphs.raiseOSError(2); // ENOENT
+ Helpers.raise_OSError(2); // ENOENT
return null; // never reached
}
Modified: pypy/dist/pypy/translator/cli/src/stub/main.il
==============================================================================
--- pypy/dist/pypy/translator/cli/src/stub/main.il (original)
+++ pypy/dist/pypy/translator/cli/src/stub/main.il Mon Jul 31 10:51:12 2006
@@ -23,13 +23,16 @@
}
-.class public PrebuiltGraphs
+.namespace pypy.runtime
{
- .method public static void raiseOSError(int32 errno_1) il managed
+ .class public Helpers
{
- ldstr "This is only a stub, it should not be called"
- newobj instance void class [mscorlib]System.ApplicationException::.ctor(string)
- throw
- ret
+ .method public static void raise_OSError(int32 errno_1) il managed
+ {
+ ldstr "This is only a stub, it should not be called"
+ newobj instance void class [mscorlib]System.ApplicationException::.ctor(string)
+ throw
+ ret
+ }
}
}
Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py (original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py Mon Jul 31 10:51:12 2006
@@ -18,7 +18,6 @@
from pypy.translator.cli.database import LowLevelDatabase
from pypy.translator.cli.sdk import SDK
from pypy.translator.cli.entrypoint import BaseEntryPoint
-from pypy.translator.cli.prebuiltgraphs import get_prebuilt_graphs
FLOAT_PRECISION = 8
@@ -134,7 +133,6 @@
ann = t.buildannotator()
ann.build_types(func, annotation)
- prebuilt_graphs = get_prebuilt_graphs(t)
t.buildrtyper(type_system="ootype").specialize()
main_graph = t.graphs[0]
@@ -146,8 +144,7 @@
else:
tmpdir = udir
- return GenCli(tmpdir, t, TestEntryPoint(main_graph, True),
- pending_graphs=prebuilt_graphs)
+ return GenCli(tmpdir, t, TestEntryPoint(main_graph, True))
class CliFunctionWrapper(object):
def __init__(self, exe_name):
More information about the Pypy-commit
mailing list