File: psyfunc.h

package info (click to toggle)
psyco-doc 1.6-1
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 1,832 kB
  • ctags: 3,236
  • sloc: ansic: 23,895; python: 5,646; perl: 1,309; makefile: 153
file content (59 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 /***************************************************************/
/***          Psyco Function objects (a.k.a. proxies)          ***/
 /***************************************************************/

#ifndef _PSYFUNC_H
#define _PSYFUNC_H


#include "psyco.h"
#include <compile.h>        /* for PyCodeObject */


/* Encode a call to the given Python function, compiling it as needed. */
EXTERNFN vinfo_t* psyco_call_pyfunc(PsycoObject* po, PyCodeObject* co,
                                    vinfo_t* vglobals, vinfo_t* vdefaults,
                                    vinfo_t* arg_tuple, int recursion);

/* for pycompiler.c */
EXTERNFN vinfo_t* psyco_save_inline_po(PsycoObject* po);
EXTERNFN PsycoObject* psyco_restore_inline_po(PsycoObject* po,vinfo_array_t** a);


/* Psyco proxies for Python functions. Calling a proxy has the same effect
   as calling the function it has been built from, except that the function
   is compiled first. As proxies are real Python objects, calling them is
   the only way to go from Python's base level to Psyco's meta-level.
   Note that (unlike in previous versions of Psyco) proxies should not be
   seen by user Python code. Use _psyco.proxycode() to build a proxy and
   emcompass it in a code object. */
typedef struct {
  PyObject_HEAD
  PyCodeObject* psy_code;  /*                                     */
  PyObject* psy_globals;   /*  same as in Python function object  */
  PyObject* psy_defaults;  /*                                     */
  int psy_recursion;    /* # levels to automatically compile called functions */
  PyObject* psy_fastcall;       /* cache mapping arg count to code bufs */
} PsycoFunctionObject;

EXTERNVAR PyTypeObject PsycoFunction_Type;

#define PsycoFunction_Check(op)	PyObject_TypeCheck(op, &PsycoFunction_Type)


#if 0  /* unneeded */
EXTERNFN PyObject* psyco_PsycoFunction_New(PyFunctionObject* func, int rec);
#endif
EXTERNFN PsycoFunctionObject* psyco_PsycoFunction_NewEx(PyCodeObject* code,
                                                PyObject* globals,
                                                PyObject* defaults, /* or NULL */
                                                int rec);
EXTERNFN PyObject* psyco_proxycode(PyFunctionObject* func, int rec);

PSY_INLINE bool is_proxycode(PyCodeObject* code) {
  return PyTuple_Size(code->co_consts) > 1 &&
    PsycoFunction_Check(PyTuple_GET_ITEM(code->co_consts, 1));
}


#endif /* _PSYFUNC_H */