blob: 56973cd4f24db4e703df61359ad2fdaffd1931be [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009******************************************************************/
10
Guido van Rossum884afd61995-07-18 14:21:06 +000011/* Definitions for bytecode */
Guido van Rossum3f5da241990-12-20 15:06:42 +000012
Fred Drakeea9cb5a2000-07-09 00:20:36 +000013#ifndef Py_COMPILE_H
14#define Py_COMPILE_H
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Guido van Rossum884afd61995-07-18 14:21:06 +000019/* Bytecode object */
Guido van Rossum3f5da241990-12-20 15:06:42 +000020typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000021 PyObject_HEAD
22 int co_argcount; /* #arguments, except *args */
23 int co_nlocals; /* #local variables */
24 int co_stacksize; /* #entries needed for evaluation stack */
25 int co_flags; /* CO_..., see below */
26 PyObject *co_code; /* instruction opcodes */
27 PyObject *co_consts; /* list (constants used) */
28 PyObject *co_names; /* list of strings (names used) */
29 PyObject *co_varnames; /* tuple of strings (local variable names) */
30 /* The rest doesn't count for hash/cmp */
31 PyObject *co_filename; /* string (where it was loaded from) */
32 PyObject *co_name; /* string (name, for reference) */
33 int co_firstlineno; /* first source line number */
34 PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */
Guido van Rossumcaa63801995-01-12 11:45:45 +000035} PyCodeObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000036
Guido van Rossum884afd61995-07-18 14:21:06 +000037/* Masks for co_flags above */
38#define CO_OPTIMIZED 0x0001
39#define CO_NEWLOCALS 0x0002
40#define CO_VARARGS 0x0004
41#define CO_VARKEYWORDS 0x0008
42
Guido van Rossum051ab121995-02-27 10:17:52 +000043extern DL_IMPORT(PyTypeObject) PyCode_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000044
Guido van Rossumcaa63801995-01-12 11:45:45 +000045#define PyCode_Check(op) ((op)->ob_type == &PyCode_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +000046
Guido van Rossum3f6e4081997-01-17 20:59:26 +000047#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
Guido van Rossum3f5da241990-12-20 15:06:42 +000048
49/* Public interface */
Guido van Rossume543a941991-04-03 19:00:55 +000050struct _node; /* Declare the existence of this type */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000051DL_IMPORT(PyCodeObject *) PyNode_Compile(struct _node *, char *);
52DL_IMPORT(PyCodeObject *) PyCode_New(
Guido van Rossum3f6e4081997-01-17 20:59:26 +000053 int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
Fred Drakeea9cb5a2000-07-09 00:20:36 +000054 PyObject *, PyObject *, int, PyObject *); /* same as struct above */
55DL_IMPORT(int) PyCode_Addr2Line(PyCodeObject *, int);
Guido van Rossuma3309961993-07-28 09:05:47 +000056
Guido van Rossumd076c731998-10-07 19:42:25 +000057/* for internal use only */
58#define _PyCode_GETCODEPTR(co, pp) \
59 ((*(co)->co_code->ob_type->tp_as_buffer->bf_getreadbuffer) \
60 ((co)->co_code, 0, (void **)(pp)))
61
Guido van Rossuma3309961993-07-28 09:05:47 +000062#ifdef __cplusplus
63}
64#endif
65#endif /* !Py_COMPILE_H */