opdef.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (C) 1991, 1995, 1998, 1999 artofcode LLC. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: opdef.h,v 1.3 2001/08/28 03:28:08 giles Exp $ */
  16. /* Operator definition interface for Ghostscript */
  17. #ifndef opdef_INCLUDED
  18. # define opdef_INCLUDED
  19. /*
  20. * Define the structure for initializing the operator table. Each operator
  21. * file zxxx.c declares an array of these as follows:
  22. const op_def * const zxxx_op_defs[] = {
  23. {"1name", zname},
  24. ...
  25. op_def_end(iproc)
  26. };
  27. * where iproc is an initialization procedure for the file or 0, and, for
  28. * each operator defined, the initial digit of the name string indicates
  29. * the number of arguments and zname is the address of the associated C
  30. * function to invoke.
  31. *
  32. * The array definition always appears at the END of the file, to avoid
  33. * the need for forward declarations for all the operator procedures.
  34. *
  35. * Operators may be stored in dictionaries other than systemdict.
  36. * We support this with op_def entries of a special form:
  37. op_def_begin_dict("dictname"),
  38. */
  39. typedef struct {
  40. const char *oname;
  41. op_proc_t proc;
  42. } op_def;
  43. #define op_def_begin_dict(dname) {dname, 0}
  44. #define op_def_begin_filter() op_def_begin_dict("filterdict")
  45. #define op_def_begin_level2() op_def_begin_dict("level2dict")
  46. #define op_def_begin_ll3() op_def_begin_dict("ll3dict")
  47. #define op_def_is_begin_dict(def) ((def)->proc == 0)
  48. #define op_def_end(iproc) {0, iproc}
  49. /*
  50. * NOTE: for implementation reasons, a single table of operator definitions
  51. * is limited to 16 entries, including op_def_begin_xxx entries. If a file
  52. * defines more operators than this, it must split them into multiple
  53. * tables and have multiple -oper entries in the makefile. Currently,
  54. * only 4 out of 85 operator files require this.
  55. */
  56. #define OP_DEFS_LOG2_MAX_SIZE 4
  57. #define OP_DEFS_MAX_SIZE (1 << OP_DEFS_LOG2_MAX_SIZE)
  58. /*
  59. * Define the table of pointers to all operator definition tables.
  60. */
  61. extern const op_def *const op_defs_all[];
  62. /*
  63. * Internal operators whose names begin with %, such as continuation
  64. * operators, do not appear in systemdict. Ghostscript assumes
  65. * that these operators cannot appear anywhere (in executable form)
  66. * except on the e-stack; to maintain this invariant, the execstack
  67. * operator converts them to literal form, and cvx refuses to convert
  68. * them back. As a result of this invariant, they do not need to
  69. * push themselves back on the e-stack when executed, since the only
  70. * place they could have come from was the e-stack.
  71. */
  72. #define op_def_is_internal(def) ((def)->oname[1] == '%')
  73. /*
  74. * All operators are catalogued in a table; this is necessary because
  75. * they must have a short packed representation for the sake of 'bind'.
  76. * The `size' of an operator is normally its index in this table;
  77. * however, internal operators have a `size' of 0, and their true index
  78. * must be found by searching the table for their procedure address.
  79. */
  80. ushort op_find_index(P1(const ref *));
  81. #define op_index(opref)\
  82. (r_size(opref) == 0 ? op_find_index(opref) : r_size(opref))
  83. /*
  84. * There are actually two kinds of operators: the real ones (t_operator),
  85. * and ones defined by procedures (t_oparray). The catalog for t_operators
  86. * is (indirectly) op_defs_all, and their index is in the range
  87. * [1..op_def_count-1].
  88. */
  89. #define op_index_is_operator(index) ((index) < op_def_count)
  90. extern const uint op_def_count;
  91. #define op_index_def(index)\
  92. (&op_defs_all[(index) >> OP_DEFS_LOG2_MAX_SIZE]\
  93. [(index) & (OP_DEFS_MAX_SIZE - 1)])
  94. #define op_num_args(opref) (op_index_def(op_index(opref))->oname[0] - '0')
  95. #define op_index_proc(index) (op_index_def(index)->proc)
  96. /*
  97. * There are two catalogs for t_oparrays, one global and one local.
  98. * Operator indices for the global table are in the range
  99. * [op_def_count..op_def_count+op_array_global.count-1]
  100. * Operator indices for the local table are in the range
  101. * [op_def_count+r_size(&op_array_global.table)..
  102. * op_def_count+r_size(&op_array_global.table)+op_array_local.count-1]
  103. */
  104. typedef struct op_array_table_s {
  105. ref table; /* t_array */
  106. ushort *nx_table; /* name indices */
  107. uint count; /* # of occupied entries */
  108. uint base_index; /* operator index of first entry */
  109. uint attrs; /* ref attrs of ops in this table */
  110. ref *root_p; /* self-pointer for GC root */
  111. } op_array_table;
  112. extern op_array_table
  113. op_array_table_global, op_array_table_local;
  114. #define op_index_op_array_table(index)\
  115. ((index) < op_array_table_local.base_index ?\
  116. &op_array_table_global : &op_array_table_local)
  117. /*
  118. * Convert an operator index to an operator or oparray ref.
  119. * This is only used for debugging and for 'get' from packed arrays,
  120. * so it doesn't have to be very fast.
  121. */
  122. void op_index_ref(P2(uint, ref *));
  123. #endif /* opdef_INCLUDED */