home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / IREF.H < prev    next >
C/C++ Source or Header  |  1992-08-08  |  7KB  |  201 lines

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