386BSD 0.1 development
[unix-history] / usr / othersrc / public / ghostscript-2.4.1 / ghost.h
CommitLineData
0d0d6b2b
WJ
1/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
2 Distributed by Free Software Foundation, Inc.
3
4This file is part of Ghostscript.
5
6Ghostscript is distributed in the hope that it will be useful, but
7WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8to anyone for the consequences of using it or for whether it serves any
9particular purpose or works at all, unless he says so in writing. Refer
10to the Ghostscript General Public License for full details.
11
12Everyone is granted permission to copy, modify and redistribute
13Ghostscript, but only under the conditions described in the Ghostscript
14General Public License. A copy of this license is supposed to have been
15given to you along with Ghostscript so you can know your rights and
16responsibilities. It should be in a file named COPYING. Among other
17things, the copyright notice and this notice must be preserved on all
18copies. */
19
20/* ghost.h */
21/* Common definitions for Ghostscript */
22#include "gx.h"
23
24/* The typedef for object references */
25typedef struct ref_s ref;
26
27/*
28 * Object types. This should be an enum, but there is no way
29 * to declare an enum a subrange of byte rather than int....
30 * The types marked with + use the read/write/execute attributes;
31 * the rest only use the executable attribute.
32 */
33typedef enum {
34 t_array, /* + value.refs, uses size */
35 t_boolean, /* value.index */
36 t_condition, /* value.pcond */
37 t_dictionary, /* + value.pdict */
38 t_file, /* + value.pfile */
39 t_fontID, /* value.pfont */
40 t_gstate, /* value.pgstate */
41 t_integer, /* value.intval */
42 t_lock, /* value.plock */
43 t_mark, /* (no value) */
44 t_name, /* value.pname */
45 t_null, /* (no value) */
46 t_operator, /* value.opproc, uses size */
47 t_real, /* value.realval */
48 t_save, /* value.psave */
49 t_string, /* + value.bytes, uses size */
50/* The following are the two implementations of packed arrays. */
51 t_mixedarray, /* + value.packed, uses size */
52 t_shortarray, /* + value.packed, uses size */
53/*
54 * The following are extensions to the PostScript type set.
55 * When adding new types, be sure to edit the table in gs_init.ps
56 * (==only operator), the printing routine in idebug.c, the dispatch
57 * in interp.c, obj_eq in iutil.c, restore_check_stack in zvmem.c,
58 * and also type_name_strings and type_print_strings below.
59 */
60 t_color, /* value.pcolor */
61 t_device, /* value.pdevice */
62 t_oparray, /* (no value), uses size */
63 t_next_index /*** first available index ***/
64} ref_type;
65/*
66 * The interpreter uses types starting at t_next_index for representing
67 * a few high-frequency operators.
68 * Since there are no operations specifically on operators,
69 * there is no need for any operators to check specifically for these
70 * types. The r_btype macro takes care of the conversion when required.
71 */
72/*
73 * Define the types that use the size field.
74 */
75#define case_types_with_size\
76 case t_array: case t_operator: case t_string:\
77 case t_mixedarray: case t_shortarray: case t_oparray
78/*
79 * Define the type names for debugging printout.
80 * All names must be the same length, so that columns will line up.
81 */
82#define type_print_strings\
83 "arry","bool","cond","dict","file","font","gstt","int ","lock","mark",\
84 "name","null","oper","real","save","str ","mpry","spry","colr","devc",\
85 "opry"
86/*
87 * Define the type names for the type operator.
88 */
89#define type_name_strings\
90 "arraytype","booleantype","conditiontype","dicttype","filetype",\
91 "fonttype","gstatetype","integertype","locktype","marktype",\
92 "nametype","nulltype","operatortype","realtype","savetype",\
93 "stringtype","packedarraytype","packedarraytype","colortype","devicetype",\
94 "operatortype"
95
96/*
97 * The encoding of attributes is constrained by two factors:
98 *
99 * - The packed array format requires the high-order bits of the
100 * type/attributes field to be 0. (see packed.h)
101 *
102 * - The interpreter wants the type, executable bit, and execute
103 * permission to be adjacent, and in that order from high to low.
104 *
105 * The layout given below is the one that leads to the most efficient
106 * dispatching in the interpreter.
107 */
108
109/* Location attributes */
110/* Note that these are associated with the *location*, not with the */
111/* ref that is *stored* in that location. */
112#define l_mark 1 /* mark for garbage collector */
113 /* (not used yet) */
114#define l_new 2 /* stored into since last save */
115#define l_space 4 /* local vs. global space */
116 /* (not used yet) */
117#define a_write 8
118#define a_read 0x10
119#define a_execute 0x20
120#define a_executable 0x40
121#define a_all (a_write+a_read+a_execute)
122#define r_type_shift 7
123#define r_type_bits 6
124
125/* Define the attribute names for debugging printout. */
126#define attr_print_string "mnswrxe......???"
127
128/* Abstract types */
129typedef struct dict_s dict;
130typedef struct name_s name;
131/* We define a dummy type for op_proc_p so that */
132/* we don't have to include oper.h. */
133typedef int (*dummy_op_proc_p)();
134#define real_opproc(pref) (*(op_proc_p *)&(pref)->value)
135
136/* Object reference */
137/*
138 * Note that because of the way packed arrays are represented,
139 * the type_attrs member must be the first one in the ref structure.
140 */
141struct stream_s;
142struct gs_font_s;
143struct gs_color_s;
144struct gs_condition_s;
145struct gs_lock_s;
146struct gx_device_s;
147struct gstate_obj_s;
148struct vm_save_s;
149struct tas_s {
150 ushort type_attrs;
151 ushort rsize;
152};
153struct ref_s {
154
155 struct tas_s tas;
156
157#define r_size(rp) ((rp)->tas.rsize)
158#define r_inc_size(rp,inc) ((rp)->tas.rsize += (inc))
159#define r_set_size(rp,siz) ((rp)->tas.rsize = (siz))
160/* type_attrs is a single element for fast dispatching in the interpreter */
161#define r_type(rp) ((rp)->tas.type_attrs >> r_type_shift)
162#define r_has_type(rp,typ) r_has_type_attrs(rp,typ,0) /* see below */
163#define r_set_type(rp,typ) ((rp)->tas.type_attrs = (typ) << r_type_shift)
164#define r_btype(rp)\
165 ((rp)->tas.type_attrs >= (t_next_index << r_type_shift) ?\
166 t_operator : r_type(rp))
167#define type_xe(tas) ((tas) >> (r_type_shift - 2))
168#define r_type_xe(rp) type_xe((rp)->tas.type_attrs)
169#define type_xe_value(t,xe) type_xe(((t) << r_type_shift) + (xe))
170#define r_type_attrs(rp) ((rp)->tas.type_attrs) /* reading only */
171#define r_has_attrs(rp,mask) !(~r_type_attrs(rp) & (mask))
172#define r_has_attr(rp,mask1) /* optimize 1-bit case */\
173 (r_type_attrs(rp) & (mask1))
174#define r_has_type_attrs(rp,typ,mask)\
175 (((rp)->tas.type_attrs & ((((1 << r_type_bits) - 1) << r_type_shift)\
176 + (mask))) ==\
177 (((typ) << r_type_shift) + (mask)))
178#define r_set_attrs(rp,mask) ((rp)->tas.type_attrs |= (mask))
179#define r_clear_attrs(rp,mask) ((rp)->tas.type_attrs &= ~(mask))
180#define r_set_type_attrs(rp,typ,mask)\
181 ((rp)->tas.type_attrs = ((typ) << r_type_shift) + (mask))
182
183 union v { /* name the union to keep gdb happy */
184 long intval;
185 ushort index; /* for enumerated things */
186 float realval;
187 byte *bytes;
188 struct ref_s *refs;
189 name *pname;
190 dict *pdict;
191 ushort *packed;
192 dummy_op_proc_p opproc;
193 struct stream_s *pfile;
194 struct gs_font_s *pfont;
195 struct gs_color_s *pcolor;
196 struct gs_condition_s *pcond;
197 struct gs_lock_s *plock;
198 struct gx_device_s *pdevice;
199 struct gstate_obj_s *pgstate;
200 struct vm_save_s *psave;
201 } value;
202};