xref: /plan9/sys/src/cmd/gs/src/idsdata.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: idsdata.h,v 1.4 2002/02/21 22:24:53 giles Exp $ */
18 /* Generic dictionary stack structure definition */
19 
20 #ifndef idsdata_INCLUDED
21 #  define idsdata_INCLUDED
22 
23 #include "isdata.h"
24 
25 /* Define the dictionary stack structure. */
26 #ifndef dict_stack_DEFINED
27 #  define dict_stack_DEFINED
28 typedef struct dict_stack_s dict_stack_t;
29 #endif
30 struct dict_stack_s {
31 
32     ref_stack_t stack;		/* the actual stack of dictionaries */
33 
34 /*
35  * Switching between Level 1 and Level 2 involves inserting and removing
36  * globaldict on the dictionary stack.  Instead of truly inserting and
37  * removing entries, we replace globaldict by a copy of systemdict in
38  * Level 1 mode.  min_dstack_size, the minimum number of entries, does not
39  * change depending on language level; the countdictstack and dictstack
40  * operators must take this into account.
41  */
42     uint min_size;		/* size of stack after clearing */
43 
44     int userdict_index;		/* index of userdict on stack */
45 
46 /*
47  * Cache a value for fast checking of def operations.
48  * If the top entry on the dictionary stack is a writable dictionary,
49  * dsspace is the space of the dictionary; if it is a non-writable
50  * dictionary, dsspace = -1.  Then def is legal precisely if
51  * r_space(pvalue) <= dsspace.  Note that in order for this trick to work,
52  * the result of r_space must be a signed integer; some compilers treat
53  * enums as unsigned, probably in violation of the ANSI standard.
54  */
55     int def_space;
56 
57 /*
58  * Cache values for fast name lookup.  If the top entry on the dictionary
59  * stack is a readable dictionary with packed keys, dtop_keys, dtop_npairs,
60  * and dtop_values are keys.value.packed, npairs, and values.value.refs
61  * for that dictionary; otherwise, these variables point to a dummy
62  * empty dictionary.
63  */
64     const ref_packed *top_keys;
65     uint top_npairs;
66     ref *top_values;
67 
68 /*
69  * Cache a copy of the bottom entry on the stack, which is never deleted.
70  */
71     ref system_dict;
72 
73 };
74 
75 /*
76  * The top-entry pointers are recomputed after garbage collection, so we
77  * don't declare them as pointers.
78  */
79 #define public_st_dict_stack()	/* in interp.c */\
80   gs_public_st_suffix_add0(st_dict_stack, dict_stack_t, "dict_stack_t",\
81     dict_stack_enum_ptrs, dict_stack_reloc_ptrs, st_ref_stack)
82 #define st_dict_stack_num_ptrs st_ref_stack_num_ptrs
83 
84 #endif /* idsdata_INCLUDED */
85