[pypy-svn] r12489 - in pypy/dist: Pyrex pypy/tool pypy/translator pypy/translator/llvm pypy/translator/pyrex pypy/translator/pyrex/Pyrex pypy/translator/pyrex/test pypy/translator/test pypy/translator/tool
arigo at codespeak.net
arigo at codespeak.net
Wed May 18 22:10:56 CEST 2005
Author: arigo
Date: Wed May 18 22:10:55 2005
New Revision: 12489
Added:
pypy/dist/pypy/translator/pyrex/
pypy/dist/pypy/translator/pyrex/Pyrex/
- copied from r12466, pypy/dist/Pyrex/
pypy/dist/pypy/translator/pyrex/__init__.py (contents, props changed)
pypy/dist/pypy/translator/pyrex/autopath.py
- copied unchanged from r12466, pypy/dist/pypy/translator/autopath.py
pypy/dist/pypy/translator/pyrex/genpyrex.py
- copied unchanged from r12466, pypy/dist/pypy/translator/genpyrex.py
pypy/dist/pypy/translator/pyrex/pyrexc
- copied, changed from r12466, pypy/dist/pypy/tool/pyrexc
pypy/dist/pypy/translator/pyrex/test/
pypy/dist/pypy/translator/pyrex/test/__init__.py (contents, props changed)
pypy/dist/pypy/translator/pyrex/test/autopath.py
- copied unchanged from r12466, pypy/dist/pypy/translator/autopath.py
pypy/dist/pypy/translator/pyrex/test/test_pyrextrans.py
- copied, changed from r12466, pypy/dist/pypy/translator/test/test_pyrextrans.py
pypy/dist/pypy/translator/pyrex/test/test_sourcegen.py
- copied, changed from r12466, pypy/dist/pypy/translator/test/test_sourcegen.py
Removed:
pypy/dist/Pyrex/
pypy/dist/pypy/tool/pyrexc
pypy/dist/pypy/translator/genpyrex.py
pypy/dist/pypy/translator/test/run_snippet.py
pypy/dist/pypy/translator/test/test_pyrextrans.py
pypy/dist/pypy/translator/test/test_sourcegen.py
pypy/dist/pypy/translator/tool/traceann.py
Modified:
pypy/dist/pypy/translator/llvm/build_llvm_module.py
pypy/dist/pypy/translator/pyrex/Pyrex/conftest.py
pypy/dist/pypy/translator/tool/buildpyxmodule.py
pypy/dist/pypy/translator/translator.py
Log:
issue49 testing
Moved the top-level Pyrex directory into a new, well-hidden
pypy/translator/pyrex/, which also receives genpyrex.py and its tests
as well as the command-line utility pypy/tool/pyrexc.
Removed a couple of strange old test files.
The Translator.compile() method is renamed to pyrexcompile(), which apparently
wasn't directly tested at all.
Deleted: /pypy/dist/pypy/tool/pyrexc
==============================================================================
--- /pypy/dist/pypy/tool/pyrexc Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,9 +0,0 @@
-#!/usr/bin/env python
-
-#
-# Pyrex -- Main Program, Unix
-#
-
-import autopath
-from Pyrex.Compiler.Main import main
-main(command_line = 1)
Deleted: /pypy/dist/pypy/translator/genpyrex.py
==============================================================================
--- /pypy/dist/pypy/translator/genpyrex.py Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,472 +0,0 @@
-"""
-generate Pyrex files from the flowmodel.
-
-"""
-from pypy.interpreter.baseobjspace import ObjSpace
-from pypy.interpreter.argument import Arguments
-from pypy.objspace.flow.model import Variable, Constant
-from pypy.objspace.flow.model import mkentrymap, last_exception
-from pypy.translator.annrpython import RPythonAnnotator
-from pypy.annotation.model import SomePBC
-from pypy.annotation.classdef import isclassdef
-from pypy.tool.uid import uid
-import inspect
-
-class Op:
- def __init__(self, operation, gen, block):
- self._str = gen._str
- self.gen = gen
- self.argnames = [self._str(arg, block) for arg in operation.args]
- self.resultname = self._str(operation.result, block)
- self.op = operation
- #op.opname
-
- def __call__(self):
- operator = self.gen.ops.get(self.op.opname, self.op.opname)
- args = self.argnames
- if not (operator[0] >= "a" and operator[0] <= "z"):
- if len(args) == 1:
- return "%s = %s %s" % (self.resultname, operator) + args
- elif len(args) == 2:
- #Inplace operators
- inp=['+=','-=','*=','/=','%=','&=','|=','^=','//=',
- '<<=','>>=','**=']
- if operator in inp:
- return "%s = %s; %s %s %s" % (self.resultname, args[0],
- self.resultname, operator, args[1])
- else:
- return "%s = %s %s %s" % (self.resultname, args[0], operator, args[1])
- elif len(args) == 3 and operator == "**": #special case, have to handle it manually
- return "%s = pow(%s, %s, %s)" % (self.resultname,) + args
- else:
- raise NotImplementedError, "I don't know to handle the operator %s (arity %s)" \
- % (operator, len(args))
- else:
- method = getattr(self, "op_%s" % operator, self.generic_op)
- return method()
-
- def ispythonident(self, s):
- if s[0] not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_":
- return False
- for c in s[1:]:
- if (c not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
- "0123456789"):
- return False
- return True
-
-
- def generic_op(self):
- """Generic handler for all operators, which I don't handle explicitly"""
-
- return "%s = %s(%s)" % (self.resultname, self.op.opname, ", ".join(self.argnames))
-
- def op_next(self):
- args = self.argnames
- return "%s = %s.next()" % (self.resultname, args[0])
-
- def op_contains(self):
- args = self.argnames
- return "%s = %s in %s" % (self.resultname, args[1], args[0])
-
- def op_getitem(self):
- direct = "%s = %s[%s]" % ((self.resultname,) + tuple(self.argnames))
- w_sequence, w_index = self.op.args
- tp = self.gen.get_type(w_index)
- if tp is int:
- return direct
- else:
- # the index could be a slice
- indexname = self.argnames[1]
- lines = []
- if tp is slice: # XXX do this better
- lines.append('if 1:')
- else:
- lines.append('from types import SliceType')
- lines.append('if isinstance(%s, SliceType):' % indexname)
- lines.append(' assert %s.step is None' % indexname)
- lines.append(' %s = %s[%s.start:%s.stop]' % (self.resultname,
- self.argnames[0],
- indexname,
- indexname))
- lines.append('else:')
- lines.append(' ' + direct)
- return "\n".join(lines)
-
- def op_newtuple(self):
- if self.argnames:
- return "%s = (%s,)" % (self.resultname, ", ".join(self.argnames))
- else:
- return "%s = ()" % self.resultname
-
- def op_newlist(self):
- if self.argnames:
- return "%s = [%s,]" % (self.resultname, ", ".join(self.argnames))
- else:
- return "%s = []" % self.resultname
-
- def op_newdict(self):
- pairs = []
- for i in range(0, len(self.argnames), 2):
- pairs.append("%s: %s, " % (self.argnames[i], self.argnames[i+1]))
- return "%s = {%s}" % (self.resultname, "".join(pairs))
-
- def op_newslice(self):
- a = self.argnames
- return "%s = slice(%s, %s, %s)" % (self.resultname, a[0], a[1], a[2])
-
- def op_call_args(self):
- a = self.argnames
- shape = self.op.args[1].value
- args = Arguments.fromshape(None, shape, a[2:])
- lst = args.arguments_w[:]
- for key, value in args.kwds_w.items():
- lst.append("%s=%s" % (key, value))
- if args.w_stararg is not None:
- lst.append("*%s" % args.w_stararg)
- if args.w_starstararg is not None:
- lst.append("**%s" % args.w_starstararg)
- return "%s = %s(%s)" % (self.resultname, a[0], ", ".join(lst))
-
- def op_simple_call(self):
- a = self.argnames
- return "%s = %s(%s)" % (self.resultname, a[0], ", ".join(a[1:]))
-
- def op_setitem(self):
- a = self.argnames
- return "%s[%s] = %s" % (a[0], a[1], a[2])
-
- def op_getattr(self):
- args = self.argnames
- attr = self.op.args[1]
- if isinstance(attr, Constant) and self.ispythonident(attr.value):
- return "%s = %s.%s" % (self.resultname, args[0], attr.value)
- else:
- return "%s = getattr(%s)" % (self.resultname, ", ".join(args))
-
- def op_setattr(self):
- args = self.argnames
- attr = self.op.args[1]
- if isinstance(attr, Constant) and self.ispythonident(attr.value):
- return "%s.%s = %s" % (args[0], attr.value, args[2])
- else:
- return "setattr(%s, %s, %s)" % args
-
- def op_not(self):
- return "%s = not %s" % (self.resultname, self.argnames[0])
-
- def op_is_true(self):
- return "%s = not not %s" % (self.resultname, self.argnames[0])
-
-class GenPyrex:
- def __init__(self, functiongraph):
- self.functiongraph = functiongraph
- ops = {}
- oparity = {}
- for (opname, opsymbol, arity, _) in ObjSpace.MethodTable:
- ops[opname] = opsymbol
- oparity[opname] = arity
- self.ops = ops
- self.oparity = oparity
- self.annotator = None
- self.namecache = {}
-
- def annotate(self, input_arg_types):
- a = RPythonAnnotator()
- a.build_types(self.functiongraph, input_arg_types)
- self.setannotator(a)
-
- def setannotator(self, annotator):
- self.annotator = annotator
-
- def emitcode(self, public=True):
- self.blockids = {}
- #self.variablelocations = {}
- self.lines = []
- self.indent = 0
- self.gen_graph(public)
- return "\n".join(self.lines)
-
- def putline(self, line):
- for l in line.split('\n'):
- self.lines.append(" " * self.indent + l)
-
- def gen_graph(self, public=True):
- fun = self.functiongraph
- self.entrymap = mkentrymap(fun)
- currentlines = self.lines
- self.lines = []
- self.indent += 1
- self.gen_block(fun.startblock)
- self.indent -= 1
- # emit the header after the body
- functionbodylines = self.lines
- self.lines = currentlines
- inputargnames = [ " ".join(self._paramvardecl(var)) for var in fun.getargs() ]
- params = ", ".join(inputargnames)
- returntype = self.get_type(fun.getreturnvar())
- returntypename = self._gettypename(returntype)
- try:
- function_object = self.by_the_way_the_function_was # XXX!
- except AttributeError:
- def function_object(): pass # XXX!!!
- if public:
- # make the function visible from the outside
- # under its original name
- args = ', '.join([var.name for var in fun.getargs()])
- self.putline("def %s(%s):" % (fun.name, args))
- self.indent += 1
- self.putline("return %s(%s)" % (
- self.getfunctionname(function_object), args))
- self.indent -= 1
- # go ahead with the mandled header and body of the function
- self.putline("cdef %s %s(%s):" % (
- returntypename,
- self.getfunctionname(function_object),
- params))
- self.indent += 1
- #self.putline("# %r" % self.annotations)
- decllines = []
- missing_decl = []
- funargs = fun.getargs()
- for block in self.blockids:
- for var in block.getvariables():
- if var not in funargs:
- decl = self._vardecl(var)
- if decl:
- decllines.append(decl)
- else:
- missing_decl.append(self.get_varname(var))
- if missing_decl:
- missing_decl.sort()
- decllines.append('# untyped variables: ' + ' '.join(missing_decl))
- decllines.sort()
- for decl in decllines:
- self.putline(decl)
- self.indent -= 1
- self.lines.extend(functionbodylines)
-
- def get_type(self, var):
- if isinstance(var, Constant):
- return type(var.value)
- elif self.annotator:
- return self.annotator.gettype(var)
- else:
- return None
-
- def get_varname(self, var):
- vartype = self.get_type(var)
- if vartype in (int, bool):
- prefix = "i_"
- elif self.annotator and vartype in self.annotator.getuserclasses():
- prefix = "p_"
- else:
- prefix = ""
- return prefix + var.name
-
- def _paramvardecl(self, var):
- vartype = self.get_type(var)
- ctype=self._gettypename(vartype)
- return (ctype, self.get_varname(var))
-
- def _gettypename(self, vartype):
- if vartype in (int, bool):
- ctype = "int"
- elif (self.annotator and vartype in self.annotator.getuserclasses()
- and vartype.__module__ != '__builtin__'):
- ctype = self.getclassname(vartype)
- else:
- ctype = "object"
- return ctype
-
- def _vardecl(self, var):
- vartype, varname = self._paramvardecl(var)
- if vartype != "object":
- return "cdef %s %s" % (vartype, varname)
- else:
- return ""
-
- def getclassname(self,cls):
- assert inspect.isclass(cls)
- name = cls.__name__
- if issubclass(cls,Exception):
- return name
- return '%s__%x' % (name, uid(cls))#self._hackname(cls)
-
- def getfunctionname(self,func):
- # NB. the purpose of the cache is not performance, but to ensure that
- # two methods that compare equal get the same name.
- if inspect.ismethod(func) and func.im_self is None:
- func = func.im_func # consider unbound methods as plain functions
- try:
- return self.namecache[func]
- except KeyError:
- assert inspect.isfunction(func) or inspect.ismethod(func)
- name = '%s__%x' % (func.__name__, uid(func))#self._hackname(func)
- self.namecache[func] = name
- return name
-
- def getvarname(self,var):
- assert inspect.isclass(var)
- return self._hackname(var)
-
- def _str(self, obj, block):
- if isinstance(obj, Variable):
- #self.variablelocations[obj] = block
- return self.get_varname(obj)
- elif isinstance(obj, Constant):
- import types
- if isinstance(obj.value,(types.ClassType,type)):
- fff=self.getclassname(obj.value)
- elif isinstance(obj.value,(types.FunctionType,
- types.MethodType,
- type)):
- fff=self.getfunctionname(obj.value)
- elif isinstance(obj.value, types.BuiltinFunctionType):
- fff=str(obj.value.__name__)
- else:
- #fff=self._hackname(obj.value)
- fff=repr(obj.value)
- if isinstance(obj.value,( int,long)):
- fff = repr(int(obj.value))
- return fff
- else:
- raise TypeError("Unknown class: %s" % obj.__class__)
-
- def gen_block(self, block):
- if self.blockids.has_key(block):
- self.putline('cinline "goto Label%s;"' % self.blockids[block])
- return
-
- blockids = self.blockids
- blockids.setdefault(block, len(blockids))
-
- #the label is only written if there are multiple refs to the block
- if len(self.entrymap[block]) > 1:
- self.putline('cinline "Label%s:"' % blockids[block])
-
- if block.exitswitch == Constant(last_exception):
- catch_exc = len(block.operations)-1
- else:
- catch_exc = None
-
- for i, op in zip(range(len(block.operations)), block.operations):
- if i == catch_exc:
- self.putline("try:")
- self.indent += 1
- opg = Op(op, self, block)
- self.putline(opg())
- if i == catch_exc:
- # generate all exception handlers
- self.indent -= 1
- exits = block.exits
- for exit in exits[1:]:
- self.putline("except %s, last_exc_value:" %
- exit.exitcase.__name__)
- self.indent += 1
- self.putline("last_exception = last_exc_value.__class__")
- self.gen_link(block, exit)
- self.indent -= 1
- self.putline("else:") # no-exception case
- self.indent += 1
- assert exits[0].exitcase is None
- self.gen_link(block, exits[0])
- self.indent -= 1
- break
-
- else:
- exits = block.exits
- if len(exits) == 1:
- self.gen_link(block, exits[0])
- elif len(exits) > 1:
- varname = self._str(block.exitswitch, block)
- for i in range(len(exits)):
- exit = exits[-i-1] # reverse order
- cond = self._str(Constant(exit.exitcase), block)
- if i == 0:
- self.putline("if %s == %s:" % (varname, cond))
- elif i < len(exits) - 1:
- self.putline("elif %s == %s:" % (varname, cond))
- else:
- self.putline("else: # %s == %s" % (varname, cond))
- self.indent += 1
- self.gen_link(block, exit)
- self.indent -= 1
- elif len(block.inputargs) == 2: # exc_cls, exc_value
- exc_cls = self._str(block.inputargs[0], block)
- exc_value = self._str(block.inputargs[1], block)
- self.putline("raise %s, %s" % (exc_cls, exc_value))
- else:
- self.putline("return %s" % self._str(block.inputargs[0], block))
-
- def gen_link(self, prevblock, link):
- _str = self._str
- block = link.target
- sourceargs = link.args
- targetargs = block.inputargs
- assert len(sourceargs) == len(targetargs)
- # get rid of identity-assignments and assignments of undefined_value
- sargs, targs = [], []
- for s,t in zip(sourceargs, targetargs):
- if s != t: # and s != Constant(undefined_value):
- sargs.append(s)
- targs.append(t)
- if sargs:
- sargs = [_str(arg, prevblock) for arg in sargs]
- targs = [_str(arg, block) for arg in targs]
- self.putline("%s = %s" % (", ".join(targs), ", ".join(sargs)))
-
- self.gen_block(block)
-
- def globaldeclarations(self,):
- """Generate the global class declaration for a group of functions."""
- if self.annotator:
- self.lines = []
- self.indent = 0
- delay_methods={}
- for cls in self.annotator.getuserclassdefinitions():
- if cls.basedef:
- bdef="(%s)" % (self.getclassname(cls.basedef.cls))
- else:
- bdef=""
- self.putline("cdef class %s%s:" % (self.getclassname(cls.cls),bdef))
- self.indent += 1
- empty = True
- for attr, attrdef in cls.attrs.items():
- s_value = attrdef.s_value
- if isinstance(s_value, SomePBC):
- for py_fun,fun_class in s_value.prebuiltinstances.items():
- assert isclassdef(fun_class), ("don't support "
- "prebuilt constants like %r" % py_fun)
- delay_methods.setdefault(fun_class,[]).append(py_fun)
- else:
- vartype=self._gettypename(s_value.knowntype)
- self.putline("cdef public %s %s" % (vartype, attr))
- empty = False
- list_methods=delay_methods.get(cls,[])
- for py_fun in list_methods:
- # XXX!
- try:
- fun = self.annotator.translator.flowgraphs[py_fun]
- except KeyError:
- continue # method present in class but never called
- hackedargs = ', '.join([var.name for var in fun.getargs()])
- self.putline("def %s(%s):" % (py_fun.__name__, hackedargs))
- self.indent += 1
- # XXX special case hack: cannot use 'return' in __init__
- if py_fun.__name__ == "__init__":
- statement = ""
- else:
- statement = "return "
- self.putline("%s%s(%s)" % (statement,
- self.getfunctionname(py_fun),
- hackedargs))
- self.indent -= 1
- empty = False
- if empty:
- self.putline("pass")
- self.indent -= 1
- self.putline("")
- return '\n'.join(self.lines)
- else:
- return ''
-
Modified: pypy/dist/pypy/translator/llvm/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/build_llvm_module.py (original)
+++ pypy/dist/pypy/translator/llvm/build_llvm_module.py Wed May 18 22:10:55 2005
@@ -10,7 +10,7 @@
from py import path
from pypy.tool.udir import udir
-from pypy.translator.genpyrex import GenPyrex
+from pypy.translator.pyrex.genpyrex import GenPyrex
from pypy.translator.tool.buildpyxmodule import make_c_from_pyxfile
from pypy.translator.tool import stdoutcapture
Modified: pypy/dist/pypy/translator/pyrex/Pyrex/conftest.py
==============================================================================
--- pypy/dist/Pyrex/conftest.py (original)
+++ pypy/dist/pypy/translator/pyrex/Pyrex/conftest.py Wed May 18 22:10:55 2005
@@ -1,6 +1,4 @@
import py
class Directory(py.test.collect.Directory):
- def __iter__(self):
- return self
- def next(self):
- raise StopIteration
+ def run(self):
+ return []
Added: pypy/dist/pypy/translator/pyrex/__init__.py
==============================================================================
Copied: pypy/dist/pypy/translator/pyrex/pyrexc (from r12466, pypy/dist/pypy/tool/pyrexc)
==============================================================================
--- pypy/dist/pypy/tool/pyrexc (original)
+++ pypy/dist/pypy/translator/pyrex/pyrexc Wed May 18 22:10:55 2005
@@ -4,6 +4,5 @@
# Pyrex -- Main Program, Unix
#
-import autopath
from Pyrex.Compiler.Main import main
main(command_line = 1)
Added: pypy/dist/pypy/translator/pyrex/test/__init__.py
==============================================================================
Copied: pypy/dist/pypy/translator/pyrex/test/test_pyrextrans.py (from r12466, pypy/dist/pypy/translator/test/test_pyrextrans.py)
==============================================================================
--- pypy/dist/pypy/translator/test/test_pyrextrans.py (original)
+++ pypy/dist/pypy/translator/pyrex/test/test_pyrextrans.py Wed May 18 22:10:55 2005
@@ -1,7 +1,7 @@
import autopath
import py
from pypy.tool.udir import udir
-from pypy.translator.genpyrex import GenPyrex
+from pypy.translator.pyrex.genpyrex import GenPyrex
from pypy.objspace.flow.model import *
from pypy.translator.tool.buildpyxmodule import build_cfunc
from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
Copied: pypy/dist/pypy/translator/pyrex/test/test_sourcegen.py (from r12466, pypy/dist/pypy/translator/test/test_sourcegen.py)
==============================================================================
--- pypy/dist/pypy/translator/test/test_sourcegen.py (original)
+++ pypy/dist/pypy/translator/pyrex/test/test_sourcegen.py Wed May 18 22:10:55 2005
@@ -3,7 +3,7 @@
import py
from pypy.tool.udir import udir
-from pypy.translator.genpyrex import GenPyrex
+from pypy.translator.pyrex.genpyrex import GenPyrex
from pypy.objspace.flow.model import *
from pypy.translator.tool.buildpyxmodule import make_module_from_pyxstring
Deleted: /pypy/dist/pypy/translator/test/run_snippet.py
==============================================================================
--- /pypy/dist/pypy/translator/test/run_snippet.py Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,106 +0,0 @@
-"""
-
- Use all functions in snippet to test translation to pyrex
-
-"""
-import autopath
-import traceback
-import sys
-from pypy.translator.translator import Translator
-
-from pypy.translator.test import snippet
-
-class Result:
- def __init__(self, func, argtypes):
- self.func = func
- self.argtypes = argtypes
- self.r_flow = self.r_annotate = self.r_compile = None
- for name in 'flow', 'annotate', 'compile':
- method = getattr(self, name)
- resname = 'r_' + name
- try:
- method()
- except (KeyboardInterrupt, SystemExit):
- raise
- except:
- self.excinfo = sys.exc_info()
- setattr(self, resname, False)
- else:
- setattr(self, resname, True)
-
- def flow(self):
- self.translator = Translator(func)
- self.translator.simplify()
-
- def annotate(self):
- self.translator.annotate(self.argtypes)
-
- def compile(self):
- compiled_function = self.translator.compile()
- return compiled_function
-
-def collect_functions(module, specnamelist):
- l = []
- for funcname, value in vars(module).items():
- if not hasattr(value, 'func_code'):
- continue
- for specname in specnamelist:
- if funcname.startswith(specname):
- l.append(value)
- break
- if not specnamelist:
- l.append(value)
- return l
-
-
-def combine(lists):
- if not lists:
- yield []
- else:
- head = lists[0]
- if not isinstance(head, tuple):
- head = (head,)
- tail = lists[1:]
- for item in head:
- for com in combine(tail):
- yield [item] + com
-
-def get_arg_types(func):
- # func_defaults e.g.: ([int, float], [str, int], int)
- if func.func_defaults:
- for argtypeslist in combine(func.func_defaults):
- yield argtypeslist
- else:
- yield []
-
-# format string for result-lines
-format_str = "%-30s %10s %10s %10s"
-
-def repr_result(res):
- name = res.func.func_name
- argtypes = res.argtypes
- funccall = "%s(%s)" % (name, ", ".join([x.__name__ for x in argtypes]))
- flow = res.r_flow and 'ok' or 'fail'
- ann = res.r_annotate and 'ok' or 'fail'
- comp = res.r_compile and 'ok' or 'fail'
- return format_str %(funccall, flow, ann, comp)
-
-if __name__=='__main__':
- specnamelist = sys.argv[1:]
- funcs = collect_functions(snippet, specnamelist)
- results = []
- print format_str %("functioncall", "flowed", "annotated", "compiled")
- for func in funcs:
- for argtypeslist in get_arg_types(func):
- #print "trying %s %s" %(func, argtypeslist)
- result = Result(func, argtypeslist)
- results.append(result)
- print repr_result(result)
- if specnamelist and getattr(result, 'excinfo', None):
- traceback.print_exception(*result.excinfo)
- raise SystemExit, 1
-
- #for res in results:
- # print repr_result(res)
-
-
Deleted: /pypy/dist/pypy/translator/test/test_pyrextrans.py
==============================================================================
--- /pypy/dist/pypy/translator/test/test_pyrextrans.py Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,155 +0,0 @@
-import autopath
-import py
-from pypy.tool.udir import udir
-from pypy.translator.genpyrex import GenPyrex
-from pypy.objspace.flow.model import *
-from pypy.translator.tool.buildpyxmodule import build_cfunc
-from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
-from pypy.translator.translator import Translator
-
-from pypy import conftest
-#from pypy.conftest import option
-
-from pypy.translator.test import snippet
-
-# XXX this tries to make compiling faster for full-scale testing
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
-
-
-class TestNoTypePyrexGenTestCase:
- objspacename = 'flow'
-
- def build_cfunc(self, func):
- try: func = func.im_func
- except AttributeError: pass
-
- dot = conftest.option.verbose > 0 and 1 or 0
- options = {
- 'simplify' : 1,
- 'dot' : dot,
- }
- return skip_missing_compiler(build_cfunc, func, **options)
-
- def test_simple_func(self):
- cfunc = self.build_cfunc(snippet.simple_func)
- assert cfunc(1) == 2
-
- def test_while_func(self):
- while_func = self.build_cfunc(snippet.while_func)
- assert while_func(10) == 55
-
- def test_nested_whiles(self):
- nested_whiles = self.build_cfunc(snippet.nested_whiles)
- assert nested_whiles(111, 114) == (
- '...!...!...!...!...!')
-
- def test_my_contains(self):
- my_contains = self.build_cfunc(snippet.my_contains)
- assert my_contains([1, 2, 3], 1)
-
- def test_poor_man_range(self):
- poor_man_range = self.build_cfunc(snippet.poor_man_range)
- assert poor_man_range(10) == range(10)
-
- def poor_man_rev_range(self):
- poor_man_rev_range = self.build_cfunc(snippet.poor_man_rev_range)
- assert poor_man_rev_range(10) == range(9,-1,-1)
-
- def test_simple_id(self):
- #we just want to see, if renaming of parameter works correctly
- #if the first branch is the end branch
- simple_id = self.build_cfunc(snippet.simple_id)
- assert simple_id(9) == 9
-
- def test_branch_id(self):
- branch_id = self.build_cfunc(snippet.branch_id)
- assert branch_id(1, 2, 3) == 2
- assert branch_id(0, 2, 3) == 3
-
- def test_int_id(self):
- int_id = self.build_cfunc(snippet.int_id)
- assert int_id(3) == 3
-
- def dont_test_attrs(self):
- attrs = self.build_cfunc(snippet.attrs)
- assert attrs() == 9
-
- def test_builtinusage(self):
- fun = self.build_cfunc(snippet.builtinusage)
- assert fun() == 4
-
- def test_sieve(self):
- sieve = self.build_cfunc(snippet.sieve_of_eratosthenes)
- assert sieve() == 1028
-
- def test_slice(self):
- half = self.build_cfunc(snippet.half_of_n)
- assert half(10) == 5
-
- def test_poly_branch(self):
- poly_branch = self.build_cfunc(snippet.poly_branch)
- assert poly_branch(10) == [1,2,3]*2
- assert poly_branch(0) == ['a','b','c']*2
-
- def test_and(self):
- sand = self.build_cfunc(snippet.s_and)
- assert sand(5, 6) == "yes"
- assert sand(5, 0) == "no"
- assert sand(0, 6) == "no"
- assert sand(0, 0) == "no"
-
-# -- the following test doesn't really work right now --
-## def test_call_very_complex(self):
-## call_very_complex = self.build_cfunc(snippet.call_very_complex,
-## snippet.default_args)
-## assert call_very_complex(5, (3,), {}) == -12
-## assert call_very_complex(5, (), {'y': 3}) == -12
-## py.test.raises("call_very_complex(5, (3,), {'y': 4})")
-
-
-class TestTypedTestCase:
-
- def getcompiled(self, func):
- t = Translator(func, simplifying=True)
- # builds starting-types from func_defs
- argstypelist = []
- if func.func_defaults:
- for spec in func.func_defaults:
- if isinstance(spec, tuple):
- spec = spec[0] # use the first type only for the tests
- argstypelist.append(spec)
- t.annotate(argstypelist)
- return skip_missing_compiler(t.compile)
-
- def test_set_attr(self):
- set_attr = self.getcompiled(snippet.set_attr)
- assert set_attr() == 2
-
- def test_inheritance2(self):
- inheritance2 = self.getcompiled(snippet.inheritance2)
- assert inheritance2() == ((-12, -12), (3, "world"))
-
- def test_factorial2(self):
- factorial2 = self.getcompiled(snippet.factorial2)
- assert factorial2(5) == 120
-
- def test_factorial(self):
- factorial = self.getcompiled(snippet.factorial)
- assert factorial(5) == 120
-
- def test_simple_method(self):
- simple_method = self.getcompiled(snippet.simple_method)
- assert simple_method(55) == 55
-
- def test_sieve_of_eratosthenes(self):
- sieve_of_eratosthenes = self.getcompiled(snippet.sieve_of_eratosthenes)
- assert sieve_of_eratosthenes() == 1028
-
- def test_nested_whiles(self):
- nested_whiles = self.getcompiled(snippet.nested_whiles)
- assert nested_whiles(5,3) == '!!!!!'
-
- def test_call_five(self):
- call_five = self.getcompiled(snippet.call_five)
- assert call_five() == [5]
Deleted: /pypy/dist/pypy/translator/test/test_sourcegen.py
==============================================================================
--- /pypy/dist/pypy/translator/test/test_sourcegen.py Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,98 +0,0 @@
-
-import autopath
-import py
-from pypy.tool.udir import udir
-
-from pypy.translator.genpyrex import GenPyrex
-from pypy.objspace.flow.model import *
-
-from pypy.translator.tool.buildpyxmodule import make_module_from_pyxstring
-#from pypy.translator.test.make_dot import make_ps
-
-# XXX this tries to make compiling faster for full-scale testing
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
-
-
-class TestSourceGenTestCase:
- def test_simple_func(self):
- """
- one test source:
- def f(x):
- return x+1
- """
- x = Variable("x")
- result = Variable("result")
- op = SpaceOperation("add", [x, Constant(1)], result)
- block = Block([x])
- fun = FunctionGraph("f", block)
- block.operations.append(op)
- block.closeblock(Link([result], fun.returnblock))
- result = GenPyrex(fun).emitcode()
- mod = py.test.skip_on_error(
- make_module_from_pyxstring, 'test_source1', udir, result)
- assert mod.f(1) == 2
-
- def test_if(self):
- """
- one test source:
- def f(i, j):
- if i < 0:
- i = j
- return i
- """
- i = Variable("i")
- j = Variable("j")
-
- conditionres = Variable("conditionres")
- conditionop = SpaceOperation("lt", [i, Constant(0)], conditionres)
- startblock = Block([i, j])
-
- fun = FunctionGraph("f", startblock)
- startblock.operations.append(conditionop)
- startblock.exitswitch = conditionres
- startblock.closeblock(Link([i], fun.returnblock, False),
- Link([j], fun.returnblock, True))
-
- result = GenPyrex(fun).emitcode()
- mod = py.test.skip_on_error(
- make_module_from_pyxstring, 'test_source2', udir, result)
- assert mod.f(-1, 42) == 42
- assert mod.f(3, 5) == 3
-
- def test_while_sum(self):
- """
- one test source:
- def f(i):
- sum = 0
- while i > 0:
- sum = sum + i
- i = i - 1
- return sum
- """
- i = Variable("i")
- sum = Variable("sum")
-
- conditionres = Variable("conditionres")
- conditionop = SpaceOperation("gt", [i, Constant(0)], conditionres)
- decop = SpaceOperation("add", [i, Constant(-1)], i)
- addop = SpaceOperation("add", [i, sum], sum)
- startblock = Block([i])
- headerblock = Block([i, sum])
- whileblock = Block([i, sum])
-
- fun = FunctionGraph("f", startblock)
- startblock.closeblock(Link([i, Constant(0)], headerblock))
- headerblock.operations.append(conditionop)
- headerblock.exitswitch = conditionres
- headerblock.closeblock(Link([sum], fun.returnblock, False),
- Link([i, sum], whileblock, True))
- whileblock.operations.append(addop)
- whileblock.operations.append(decop)
- whileblock.closeblock(Link([i, sum], headerblock))
-
- result = GenPyrex(fun).emitcode()
- mod = py.test.skip_on_error(
- make_module_from_pyxstring, 'test_source4', udir, result)
- assert mod.f(3) == 6
- assert mod.f(-3) == 0
Modified: pypy/dist/pypy/translator/tool/buildpyxmodule.py
==============================================================================
--- pypy/dist/pypy/translator/tool/buildpyxmodule.py (original)
+++ pypy/dist/pypy/translator/tool/buildpyxmodule.py Wed May 18 22:10:55 2005
@@ -1,7 +1,6 @@
import autopath
import py
-from pypy.translator.genpyrex import GenPyrex
import os, sys, inspect, re
from pypy.translator.tool import stdoutcapture
@@ -122,6 +121,10 @@
return testmodule
def make_c_from_pyxfile(pyxfile):
+ from pypy.translator.pyrex import genpyrex
+ pyrexdir = os.path.dirname(genpyrex.__file__)
+ if pyrexdir not in sys.path:
+ sys.path.append(pyrexdir)
from Pyrex.Compiler.Main import CompilationOptions, Context, PyrexError
try:
options = CompilationOptions(show_version = 0,
@@ -180,6 +183,7 @@
name += '_s'
# get the pyrex generator
+ from pypy.translator.pyrex.genpyrex import GenPyrex
genpyrex = GenPyrex(funcgraph)
# generate pyrex (without type inference)
Deleted: /pypy/dist/pypy/translator/tool/traceann.py
==============================================================================
--- /pypy/dist/pypy/translator/tool/traceann.py Wed May 18 22:10:55 2005
+++ (empty file)
@@ -1,55 +0,0 @@
-"""
-
-- annotate and translate snippet producing tracing of calls
-to AnnotationSet and RPythonAnnotator
-- print bindings and final annotation set
-and pyrex
-
-- display flow graph
-
-call it like:
-
-traceann <snippet-name> <types...> >result.txt 2>trace.txt
-
-"""
-
-import sys
-
-import autopath
-
-from pypy.translator.translator import *
-from pypy.translator.test import snippet as test
-
-#from pypy.translator.tool import tracer
-#tracer.trace(AnnotationSet)
-#tracer.trace(RPythonAnnotator)
-
-try:
- snippet_name = sys.argv[1]
-except IndexError:
- snippet_name = "call_five"
-
-argtypes = []
-
-for argtype in sys.argv[2:]:
- argtypes.append(eval(argtype))
-
-t = Translator(getattr(test,snippet_name))
-t.simplify()
-a = t.annotate(argtypes)
-lines = []
-for key, value in a.bindings.items():
- lines.append('%r: %r' % (key, value))
-#for cl, attrdict in a.classes.items():
-# lines.append('%s: %r' % (cl.__name__,attrdict))
-lines.sort()
-for line in lines:
- print line
-print '-'*50
-print a.heap
-sys.stdout.flush()
-
-print '-'*50
-print t.pyrex()
-
-t.gv()
Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py (original)
+++ pypy/dist/pypy/translator/translator.py Wed May 18 22:10:55 2005
@@ -10,7 +10,7 @@
from pypy.annotation.model import *
from pypy.translator.annrpython import RPythonAnnotator
from pypy.translator.simplify import simplify_graph
-from pypy.translator.genpyrex import GenPyrex
+from pypy.translator.pyrex.genpyrex import GenPyrex
from pypy.translator.gencl import GenCL
from pypy.translator.genc.genc import GenC
from pypy.translator.gensupp import uniquemodulename
@@ -216,7 +216,7 @@
g.setannotator(ann)
return g.globaldeclarations()
- def compile(self):
+ def pyrexcompile(self):
"""Returns compiled function, compiled using Pyrex.
"""
from pypy.tool.udir import udir
More information about the Pypy-commit
mailing list