File: pycodegen.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 (68 lines) | stat: -rw-r--r-- 1,565 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
60
61
62
63
64
65
66
67
68
 /***************************************************************/
/*** Generic support code for Python-specific code generation  ***/
 /***************************************************************/

#ifndef _PYCODEGEN_H
#define _PYCODEGEN_H

#include "vcompiler.h"
#include <ipyencoding.h>


/* emit Py_INCREF(v) */
PSY_INLINE bool psyco_incref_v(PsycoObject* po, vinfo_t* v)
{
  if (!compute_vinfo(v, po)) return false;
  psyco_incref_nv(po, v);
  return true;
}

/* emit Py_DECREF(v) */
PSY_INLINE void psyco_decref_v(PsycoObject* po, vinfo_t* v)
{
  switch (gettime(v->source)) {
    
  case RunTime:
    psyco_decref_rt(po, v);
    break;

  case CompileTime:
    psyco_decref_c(po, (PyObject*) CompileTime_Get(v->source)->value);
    break;
  }
}


/* can eat a reference if we had one in the first place, and
   if no one else will require it (i.e. there is only one reference
   left to 'vi') */
PSY_INLINE bool eat_reference(vinfo_t* vi)
{
  if (has_rtref(vi->source) && vi->refcount == 1)
    {
      vi->source = remove_rtref(vi->source);
      return true;
    }
  else
    return false;
}

/* force a reference to be consumed */
PSY_INLINE void consume_reference(PsycoObject* po, vinfo_t* vi)
{
	if (!eat_reference(vi))
		psyco_incref_v(po, vi);
}

/* make sure we have a reference on 'vi' */
PSY_INLINE void need_reference(PsycoObject* po, vinfo_t* vi)
{
  if ((vi->source & (TimeMask | RunTime_NoRef)) == (RunTime | RunTime_NoRef))
    {
      vi->source = add_rtref(vi->source);
      psyco_incref_rt(po, vi);
    }
}


#endif /* _PYCODEGEN_H */