Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The |
| 3 | Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 25 | /* Frame object interface */ |
| 26 | |
| 27 | typedef 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 | |
| 33 | typedef 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 | |
| 49 | extern typeobject Frametype; |
| 50 | |
| 51 | #define is_frameobject(op) ((op)->ob_type == &Frametype) |
| 52 | |
| 53 | frameobject * 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 Rossum | d594c91 | 1991-04-03 19:03:22 +0000 | [diff] [blame] | 75 | #define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i))) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | /* Block management functions */ |
| 79 | |
| 80 | void setup_block PROTO((frameobject *, int, int, int)); |
| 81 | block *pop_block PROTO((frameobject *)); |