[pypy-svn] r20394 - in pypy/branch/somepbc-refactoring/pypy/rpython: l3interp/test ootypesystem/test test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Nov 29 16:15:07 CET 2005
Author: pedronis
Date: Tue Nov 29 16:15:04 2005
New Revision: 20394
Modified:
pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_convert.py
pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_l3interp.py
pypy/branch/somepbc-refactoring/pypy/rpython/ootypesystem/test/test_oortype.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_normalizecalls.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_objectmodel.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rbool.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rint.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rlist.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtuple.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtyper.py
Log:
remove usage of Translator from rpython/
the translating tests in l3interp/test/test_l3interp work again, but the last one fails with a translated code
RuntimeError !!
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_convert.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_convert.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_convert.py Tue Nov 29 16:15:04 2005
@@ -1,12 +1,12 @@
from pypy.rpython.l3interp import convertgraph, l3interp
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
def test_convert_add():
def f(x):
return x + 4
- t = Translator(f)
- t.annotate([int])
- t.specialize()
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
globals = convertgraph.convert(t.graphs[0])
interp = l3interp.LLInterpreter(globals)
graph = globals.graphs[0]
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_l3interp.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_l3interp.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/l3interp/test/test_l3interp.py Tue Nov 29 16:15:04 2005
@@ -1,16 +1,24 @@
from pypy.rpython.l3interp import l3interp
from pypy.rpython.l3interp import model
from pypy.translator.c.test.test_genc import compile
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
from pypy.annotation import policy
def translate(func, inputargs):
- t = Translator(func)
+ t = TranslationContext()
pol = policy.AnnotatorPolicy()
pol.allow_someobjects = False
- t.annotate(inputargs, policy=pol)
- t.specialize()
- return t.ccompile()
+ t.buildannotator(policy=pol).build_types(func, inputargs)
+ t.buildrtyper().specialize()
+
+ from pypy.translator.tool.cbuild import skip_missing_compiler
+ from pypy.translator.c import genc
+ builder = genc.CExtModuleBuilder(t, func)
+ builder.generate_source()
+ skip_missing_compiler(builder.compile)
+ builder.import_module()
+ return builder.get_entry_point()
+
#----------------------------------------------------------------------
def eval_seven():
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/ootypesystem/test/test_oortype.py Tue Nov 29 16:15:04 2005
@@ -2,15 +2,15 @@
from pypy.rpython.ootypesystem.ootype import *
from pypy.annotation import model as annmodel
from pypy.objspace.flow import FlowObjSpace
-from pypy.translator.translator import Translator, graphof
+from pypy.translator.translator import TranslationContext, graphof
from pypy.rpython.test.test_llinterp import interpret
def gengraph(f, args=[], viewBefore=False, viewAfter=False):
- t = Translator(f)
- t.annotate(args)
+ t = TranslationContext()
+ t.buildannotator().build_types(f, args)
if viewBefore:
t.view()
- t.specialize(type_system="ootype")
+ t.buildrtyper(type_system="ootype").specialize()
if viewAfter:
t.view()
return graphof(t, f)
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_exception.py Tue Nov 29 16:15:04 2005
@@ -1,6 +1,5 @@
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.rtyper import RPythonTyper
from pypy.rpython.test.test_llinterp import interpret
@@ -10,6 +9,14 @@
class MyStrangeException: # no (Exception) here
pass
+def rtype(fn, argtypes=[]):
+ t = TranslationContext()
+ t.buildannotator().build_types(fn, argtypes)
+ typer = t.buildrtyper()
+ typer.specialize()
+ #t.view()
+ t.checkgraphs()
+ return t
def test_simple():
def g():
@@ -20,24 +27,18 @@
except MyException:
pass
- t = Translator(dummyfn)
- a = t.annotate([])
- a.simplify()
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- t.checkgraphs()
+ rtype(dummyfn)
+
def test_exception_data():
def f(n):
raise OverflowError()
- t = Translator(f)
- a = t.annotate([int])
- t.specialize()
+ t = rtype(f, [int])
+
excdata = t.rtyper.getexceptiondata()
- getcdef = a.bookkeeper.getuniqueclassdef
+ getcdef = t.annotator.bookkeeper.getuniqueclassdef
#t.view()
ovferr_inst = excdata.fn_pyexcclass2exc(pyobjectptr(OverflowError))
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_llinterp.py Tue Nov 29 16:15:04 2005
@@ -3,7 +3,7 @@
from pypy.rpython.lltypesystem.lltype import typeOf, pyobjectptr, Ptr, PyObject
from pypy.rpython.rtyper import RPythonTyper
from pypy.rpython.llinterp import LLInterpreter, LLException,log
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
from pypy.rpython.rlist import *
from pypy.rpython.rint import signed_repr
from pypy.rpython import rstr
@@ -45,14 +45,14 @@
def gengraph(func, argtypes=[], viewbefore=False, policy=None,
type_system="lltype"):
- t = Translator(func)
-
- timelog("annotating", t.annotate, argtypes, policy=policy)
+ t = TranslationContext()
+ a = t.buildannotator(policy=policy)
+ timelog("annotating", a.build_types, func, argtypes)
if viewbefore:
- t.annotator.simplify()
+ a.simplify()
t.view()
global typer # we need it for find_exception
- typer = RPythonTyper(t.annotator, type_system=type_system)
+ typer = t.buildrtyper(type_system=type_system)
timelog("rtyper-specializing", typer.specialize)
#t.view()
timelog("checking graphs", t.checkgraphs)
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_normalizecalls.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_normalizecalls.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_normalizecalls.py Tue Nov 29 16:15:04 2005
@@ -1,14 +1,13 @@
from pypy.annotation import model as annmodel
-from pypy.translator.translator import Translator, graphof
-from pypy.rpython.rtyper import RPythonTyper
+from pypy.translator.translator import TranslationContext, graphof
from pypy.rpython.test.test_llinterp import interpret
from pypy.rpython.lltypesystem import lltype
def rtype(fn, argtypes=[]):
- t = Translator(fn)
- t.annotate(argtypes)
- typer = RPythonTyper(t.annotator)
+ t = TranslationContext()
+ t.buildannotator().build_types(fn, argtypes)
+ typer = t.buildrtyper()
typer.specialize()
#t.view()
t.checkgraphs()
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_objectmodel.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_objectmodel.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_objectmodel.py Tue Nov 29 16:15:04 2005
@@ -1,5 +1,5 @@
from pypy.rpython.objectmodel import *
-from pypy.translator.translator import Translator, graphof
+from pypy.translator.translator import TranslationContext, graphof
from pypy.rpython.test.test_llinterp import interpret
def test_we_are_translated():
@@ -94,8 +94,9 @@
return play_with_r_dict(d)
def test_annotate_r_dict():
- t = Translator(test_r_dict)
- a = t.annotate([])
+ t = TranslationContext()
+ a = t.buildannotator()
+ a.build_types(test_r_dict, [])
#t.view()
graph = graphof(t, strange_key_eq)
assert a.binding(graph.getargs()[0]).knowntype == str
@@ -104,8 +105,9 @@
assert a.binding(graph.getargs()[0]).knowntype == str
def test_annotate_r_dict_bm():
- t = Translator(test_r_dict_bm)
- a = t.annotate([])
+ t = TranslationContext()
+ a = t.buildannotator()
+ a.build_types(test_r_dict_bm, [])
#t.view()
strange_key_eq = Strange.key_eq.im_func
strange_key_hash = Strange.key_hash.im_func
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rbool.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rbool.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rbool.py Tue Nov 29 16:15:04 2005
@@ -1,6 +1,5 @@
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
from pypy.rpython.lltypesystem.lltype import pyobjectptr
-from pypy.rpython.rtyper import RPythonTyper
from pypy.annotation import model as annmodel
from pypy.rpython.test import snippet
from pypy.rpython.test.test_llinterp import interpret
@@ -9,13 +8,10 @@
class TestSnippet(object):
def _test(self, func, types):
- t = Translator(func)
- t.annotate(types)
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- t.checkgraphs()
- #if func == snippet.bool_cast1:
- # t.view()
+ t = TranslationContext()
+ t.buildannotator().build_types(func, types)
+ t.buildrtyper().specialize()
+ t.checkgraphs()
def test_not1(self):
self._test(snippet.not1, [bool])
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py Tue Nov 29 16:15:04 2005
@@ -1,21 +1,16 @@
-from pypy.translator.translator import Translator
-from pypy.rpython.rtyper import RPythonTyper
-from pypy.annotation import model as annmodel
+from pypy.translator.translator import TranslationContext
from pypy.rpython.test import snippet
from pypy.rpython.test.test_llinterp import interpret
class TestSnippet(object):
-
- def _test(self, func, types):
- t = Translator(func)
- t.annotate(types)
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- t.checkgraphs()
- #if func == snippet.float_cast1:
- # t.view()
+ def _test(self, func, types):
+ t = TranslationContext()
+ t.buildannotator().build_types(func, types)
+ t.buildrtyper().specialize()
+ t.checkgraphs()
+
def test_not1(self):
self._test(snippet.not1, [float])
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rint.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rint.py Tue Nov 29 16:15:04 2005
@@ -1,6 +1,5 @@
import sys
-from pypy.translator.translator import Translator
-from pypy.rpython.rtyper import RPythonTyper
+from pypy.translator.translator import TranslationContext
from pypy.annotation import model as annmodel
from pypy.rpython.test import snippet
from pypy.rpython.test.test_llinterp import interpret
@@ -8,16 +7,13 @@
class TestSnippet(object):
-
+
def _test(self, func, types):
- t = Translator(func)
- t.annotate(types)
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- t.checkgraphs()
- #if func == snippet.int_cast1:
- # t.view()
-
+ t = TranslationContext()
+ t.buildannotator().build_types(func, types)
+ t.buildrtyper().specialize()
+ t.checkgraphs()
+
def test_not1(self):
self._test(snippet.not1, [int])
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rlist.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rlist.py Tue Nov 29 16:15:04 2005
@@ -158,16 +158,6 @@
# ____________________________________________________________
-def rtype(fn, argtypes=[]):
- t = Translator(fn)
- t.annotate(argtypes)
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- t.checkgraphs()
- return t
-
-
def test_simple():
def dummyfn():
l = [10, 20, 30]
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtuple.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtuple.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtuple.py Tue Nov 29 16:15:04 2005
@@ -1,6 +1,5 @@
from pypy.translator.translator import Translator
from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.rtyper import RPythonTyper
from pypy.rpython.rtuple import *
from pypy.rpython.rint import signed_repr
from pypy.rpython.rbool import bool_repr
@@ -16,40 +15,26 @@
# ____________________________________________________________
-def rtype(fn, argtypes=[]):
- t = Translator(fn)
- t.annotate(argtypes)
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- t.checkgraphs()
- return t
-
-
def test_simple():
def dummyfn(x):
l = (10,x,30)
return l[2]
- rtype(dummyfn, [int])
+ res = interpret(dummyfn,[4])
+ assert res == 30
def test_len():
def dummyfn(x):
l = (5,x)
return len(l)
- rtype(dummyfn, [int])
-
-##def test_iterate():
-## def dummyfn():
-## total = 0
-## for x in (1,3,5,7,9):
-## total += x
-## return total
-## rtype(dummyfn)
+ res = interpret(dummyfn, [4])
+ assert res == 2
def test_return_tuple():
def dummyfn(x, y):
return (x<y, x>y)
- rtype(dummyfn, [int, int])
+ res = interpret(dummyfn, [4,5])
+ assert res.item0 == True
+ assert res.item1 == False
def test_tuple_concatenation():
def f(n):
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtyper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtyper.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rtyper.py Tue Nov 29 16:15:04 2005
@@ -1,6 +1,6 @@
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Constant
-from pypy.translator.translator import Translator, graphof
+from pypy.translator.translator import TranslationContext, graphof
from pypy.translator import annrpython
from pypy.rpython.lltypesystem.lltype import *
from pypy.rpython.test.test_llinterp import interpret
@@ -8,6 +8,7 @@
from pypy.rpython import rmodel
import py
+
def setup_module(mod):
mod.logstate = py.log._getstate()
py.log.setconsumer("rtyper", py.log.STDOUT)
@@ -74,10 +75,9 @@
def test_retval():
def f(x):
return x
- t = Translator(f)
- t.annotate([int])
- typer = RPythonTyper(t.annotator)
- typer.specialize()
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
#t.view()
t.checkgraphs()
graph = graphof(t, f)
@@ -87,10 +87,9 @@
def test_retval_None():
def f(x):
pass
- t = Translator(f)
- t.annotate([int])
- typer = RPythonTyper(t.annotator)
- typer.specialize()
+ t = TranslationContext()
+ t.buildannotator().build_types(f, [int])
+ t.buildrtyper().specialize()
#t.view()
t.checkgraphs()
graph = graphof(t, f)
More information about the Pypy-commit
mailing list