blob: 22bdfa9c11eb6219188774d0a580d7ec5ea3a3d5 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
2Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum3f5da241990-12-20 15:06:42 +000025/* Frame object interface */
26
27typedef struct {
28 int b_type; /* what kind of block this is */
29 int b_handler; /* where to jump to find handler */
30 int b_level; /* value stack level to pop to */
31} block;
32
33typedef struct _frame {
34 OB_HEAD
35 struct _frame *f_back; /* previous frame, or NULL */
36 codeobject *f_code; /* code segment */
37 object *f_globals; /* global symbol table (dictobject) */
38 object *f_locals; /* local symbol table (dictobject) */
39 object **f_valuestack; /* malloc'ed array */
40 block *f_blockstack; /* malloc'ed array */
41 int f_nvalues; /* size of f_valuestack */
42 int f_nblocks; /* size of f_blockstack */
43 int f_iblock; /* index in f_blockstack */
44} frameobject;
45
46
47/* Standard object interface */
48
49extern typeobject Frametype;
50
51#define is_frameobject(op) ((op)->ob_type == &Frametype)
52
53frameobject * newframeobject PROTO(
54 (frameobject *, codeobject *, object *, object *, int, int));
55
56
57/* The rest of the interface is specific for frame objects */
58
59/* List access macros */
60
61#ifdef NDEBUG
62#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
63#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
64#else
65#define GETITEM(v, i) getlistitem((v), (i))
66#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
67#endif
68
69#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
70
71/* Code access macros */
72
73#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
74#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000075#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000076
77
78/* Block management functions */
79
80void setup_block PROTO((frameobject *, int, int, int));
81block *pop_block PROTO((frameobject *));