1991-02-19 13:39:46 +01:00
|
|
|
|
1990-10-14 13:07:46 +01:00
|
|
|
/* Function object interface */
|
|
|
|
|
2000-07-09 02:20:36 +02:00
|
|
|
#ifndef Py_FUNCOBJECT_H
|
|
|
|
#define Py_FUNCOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1993-05-19 16:50:45 +02:00
|
|
|
typedef struct {
|
2000-07-09 02:20:36 +02:00
|
|
|
PyObject_HEAD
|
|
|
|
PyObject *func_code;
|
|
|
|
PyObject *func_globals;
|
|
|
|
PyObject *func_defaults;
|
PEP 227 implementation
The majority of the changes are in the compiler. The mainloop changes
primarily to implement the new opcodes and to pass a function's
closure to eval_code2(). Frames and functions got new slots to hold
the closure.
Include/compile.h
Add co_freevars and co_cellvars slots to code objects.
Update PyCode_New() to take freevars and cellvars as arguments
Include/funcobject.h
Add func_closure slot to function objects.
Add GetClosure()/SetClosure() functions (and corresponding
macros) for getting at the closure.
Include/frameobject.h
PyFrame_New() now takes a closure.
Include/opcode.h
Add four new opcodes: MAKE_CLOSURE, LOAD_CLOSURE, LOAD_DEREF,
STORE_DEREF.
Remove comment about old requirement for opcodes to fit in 7
bits.
compile.c
Implement changes to code objects for co_freevars and co_cellvars.
Modify symbol table to use st_cur_name (string object for the name
of the current scope) and st_cur_children (list of nested blocks).
Also define st_nested, which might more properly be called
st_cur_nested. Add several DEF_XXX flags to track def-use
information for free variables.
New or modified functions of note:
com_make_closure(struct compiling *, PyCodeObject *)
Emit LOAD_CLOSURE opcodes as needed to pass cells for free
variables into nested scope.
com_addop_varname(struct compiling *, int, char *)
Emits opcodes for LOAD_DEREF and STORE_DEREF.
get_ref_type(struct compiling *, char *name)
Return NAME_CLOSURE if ref type is FREE or CELL
symtable_load_symbols(struct compiling *)
Decides what variables are cell or free based on def-use info.
Can now raise SyntaxError if nested scopes are mixed with
exec or from blah import *.
make_scope_info(PyObject *, PyObject *, int, int)
Helper functions for symtable scope stack.
symtable_update_free_vars(struct symtable *)
After a code block has been analyzed, it must check each of
its children for free variables that are not defined in the
block. If a variable is free in a child and not defined in
the parent, then it is defined by block the enclosing the
current one or it is a global. This does the right logic.
symtable_add_use() is now a macro for symtable_add_def()
symtable_assign(struct symtable *, node *)
Use goto instead of for (;;)
Fixed bug in symtable where name of keyword argument in function
call was treated as assignment in the scope of the call site. Ex:
def f():
g(a=2) # a was considered a local of f
ceval.c
eval_code2() now take one more argument, a closure.
Implement LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF, MAKE_CLOSURE>
Also: When name error occurs for global variable, report that the
name was global in the error mesage.
Objects/frameobject.c
Initialize f_closure to be a tuple containing space for cellvars
and freevars. f_closure is NULL if neither are present.
Objects/funcobject.c
Add support for func_closure.
Python/import.c
Change the magic number.
Python/marshal.c
Track changes to code objects.
2001-01-25 21:06:59 +01:00
|
|
|
PyObject *func_closure;
|
2000-07-09 02:20:36 +02:00
|
|
|
PyObject *func_doc;
|
|
|
|
PyObject *func_name;
|
2001-01-15 21:40:19 +01:00
|
|
|
PyObject *func_dict;
|
2001-03-23 05:17:58 +01:00
|
|
|
PyObject *func_weakreflist;
|
2003-01-31 19:33:18 +01:00
|
|
|
PyObject *func_module;
|
1995-01-12 12:45:45 +01:00
|
|
|
} PyFunctionObject;
|
1993-05-19 16:50:45 +02:00
|
|
|
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_DATA(PyTypeObject) PyFunction_Type;
|
1990-10-14 13:07:46 +01:00
|
|
|
|
1995-01-12 12:45:45 +01:00
|
|
|
#define PyFunction_Check(op) ((op)->ob_type == &PyFunction_Type)
|
1990-10-14 13:07:46 +01:00
|
|
|
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
|
2003-01-31 19:33:18 +01:00
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
|
1993-07-28 11:05:47 +02:00
|
|
|
|
1998-07-10 17:47:08 +02:00
|
|
|
/* Macros for direct access to these values. Type checks are *not*
|
|
|
|
done, so use with care. */
|
|
|
|
#define PyFunction_GET_CODE(func) \
|
|
|
|
(((PyFunctionObject *)func) -> func_code)
|
|
|
|
#define PyFunction_GET_GLOBALS(func) \
|
|
|
|
(((PyFunctionObject *)func) -> func_globals)
|
2003-01-31 19:33:18 +01:00
|
|
|
#define PyFunction_GET_MODULE(func) \
|
|
|
|
(((PyFunctionObject *)func) -> func_module)
|
1998-07-10 17:47:08 +02:00
|
|
|
#define PyFunction_GET_DEFAULTS(func) \
|
|
|
|
(((PyFunctionObject *)func) -> func_defaults)
|
PEP 227 implementation
The majority of the changes are in the compiler. The mainloop changes
primarily to implement the new opcodes and to pass a function's
closure to eval_code2(). Frames and functions got new slots to hold
the closure.
Include/compile.h
Add co_freevars and co_cellvars slots to code objects.
Update PyCode_New() to take freevars and cellvars as arguments
Include/funcobject.h
Add func_closure slot to function objects.
Add GetClosure()/SetClosure() functions (and corresponding
macros) for getting at the closure.
Include/frameobject.h
PyFrame_New() now takes a closure.
Include/opcode.h
Add four new opcodes: MAKE_CLOSURE, LOAD_CLOSURE, LOAD_DEREF,
STORE_DEREF.
Remove comment about old requirement for opcodes to fit in 7
bits.
compile.c
Implement changes to code objects for co_freevars and co_cellvars.
Modify symbol table to use st_cur_name (string object for the name
of the current scope) and st_cur_children (list of nested blocks).
Also define st_nested, which might more properly be called
st_cur_nested. Add several DEF_XXX flags to track def-use
information for free variables.
New or modified functions of note:
com_make_closure(struct compiling *, PyCodeObject *)
Emit LOAD_CLOSURE opcodes as needed to pass cells for free
variables into nested scope.
com_addop_varname(struct compiling *, int, char *)
Emits opcodes for LOAD_DEREF and STORE_DEREF.
get_ref_type(struct compiling *, char *name)
Return NAME_CLOSURE if ref type is FREE or CELL
symtable_load_symbols(struct compiling *)
Decides what variables are cell or free based on def-use info.
Can now raise SyntaxError if nested scopes are mixed with
exec or from blah import *.
make_scope_info(PyObject *, PyObject *, int, int)
Helper functions for symtable scope stack.
symtable_update_free_vars(struct symtable *)
After a code block has been analyzed, it must check each of
its children for free variables that are not defined in the
block. If a variable is free in a child and not defined in
the parent, then it is defined by block the enclosing the
current one or it is a global. This does the right logic.
symtable_add_use() is now a macro for symtable_add_def()
symtable_assign(struct symtable *, node *)
Use goto instead of for (;;)
Fixed bug in symtable where name of keyword argument in function
call was treated as assignment in the scope of the call site. Ex:
def f():
g(a=2) # a was considered a local of f
ceval.c
eval_code2() now take one more argument, a closure.
Implement LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF, MAKE_CLOSURE>
Also: When name error occurs for global variable, report that the
name was global in the error mesage.
Objects/frameobject.c
Initialize f_closure to be a tuple containing space for cellvars
and freevars. f_closure is NULL if neither are present.
Objects/funcobject.c
Add support for func_closure.
Python/import.c
Change the magic number.
Python/marshal.c
Track changes to code objects.
2001-01-25 21:06:59 +01:00
|
|
|
#define PyFunction_GET_CLOSURE(func) \
|
|
|
|
(((PyFunctionObject *)func) -> func_closure)
|
1998-07-10 17:47:08 +02:00
|
|
|
|
2001-08-02 06:15:00 +02:00
|
|
|
/* The classmethod and staticmethod types lives here, too */
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
|
|
|
|
PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
|
2001-08-02 06:15:00 +02:00
|
|
|
|
2002-08-12 09:21:58 +02:00
|
|
|
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
|
2001-08-02 06:15:00 +02:00
|
|
|
|
1993-07-28 11:05:47 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_FUNCOBJECT_H */
|