blob: dd36468ec166ea8bea3a7a3d9136a5c40394fc29 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum5113f5f1992-04-05 14:20:22 +00002Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Guido van Rossumf70e43a1991-02-19 12:39:46 +00003Netherlands.
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 */
Guido van Rossum088bc2a1992-01-14 18:32:11 +000044 int f_lasti; /* Last instruction if called */
45 int f_lineno; /* Current line number */
Guido van Rossum3f5da241990-12-20 15:06:42 +000046} frameobject;
47
48
49/* Standard object interface */
50
51extern typeobject Frametype;
52
53#define is_frameobject(op) ((op)->ob_type == &Frametype)
54
55frameobject * newframeobject PROTO(
56 (frameobject *, codeobject *, object *, object *, int, int));
57
58
59/* The rest of the interface is specific for frame objects */
60
61/* List access macros */
62
63#ifdef NDEBUG
64#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
65#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
66#else
67#define GETITEM(v, i) getlistitem((v), (i))
68#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
69#endif
70
71#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
72
73/* Code access macros */
74
75#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
76#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000077#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000078
79
80/* Block management functions */
81
82void setup_block PROTO((frameobject *, int, int, int));
83block *pop_block PROTO((frameobject *));
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000084
85/* Extend the value stack */
86
87object **extend_stack PROTO((frameobject *, int, int));