oper.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 1989, 1995, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: oper.h,v 1.6 2003/09/03 03:22:59 giles Exp $ */
  14. /* Definitions for Ghostscript operators */
  15. #ifndef oper_INCLUDED
  16. # define oper_INCLUDED
  17. #include "ierrors.h"
  18. #include "ostack.h"
  19. #include "opdef.h"
  20. #include "opextern.h"
  21. #include "opcheck.h"
  22. #include "iutil.h"
  23. /*
  24. * Operator procedures take a single argument. This is currently a pointer
  25. * to the current context state, but might conceivably change in the future.
  26. * They return 0 for success, a negative code for an error, or a positive
  27. * code for some uncommon situations (see below).
  28. */
  29. /*
  30. * In order to combine typecheck and stackunderflow error checking
  31. * into a single test, we guard the bottom of the o-stack with
  32. * additional entries of type t__invalid. However, if a type check fails,
  33. * we must make an additional check to determine which error
  34. * should be reported. In order not to have to make this check in-line
  35. * in every type check in every operator, we define a procedure that takes
  36. * an o-stack pointer and returns e_stackunderflow if it points to
  37. * a guard entry, e_typecheck otherwise.
  38. *
  39. * Note that we only need to do this for typecheck, not for any other
  40. * kind of error such as invalidaccess, since any operator that can
  41. * generate the latter will do a check_type or a check_op first.
  42. * (See ostack.h for more information.)
  43. *
  44. * We define the operand type of check_type_failed as const ref * rather than
  45. * const_os_ptr simply because there are a number of routines that might
  46. * be used either with a stack operand or with a general operand, and
  47. * the check for t__invalid is harmless when applied to off-stack refs.
  48. */
  49. int check_type_failed(const ref *);
  50. /*
  51. * Check the type of an object. Operators almost always use check_type,
  52. * which includes the stack underflow check described just above;
  53. * check_type_only is for checking subsidiary objects obtained from
  54. * places other than the stack.
  55. */
  56. #define return_op_typecheck(op)\
  57. return_error(check_type_failed(op))
  58. #define check_type(orf,typ)\
  59. if ( !r_has_type(&orf,typ) ) return_op_typecheck(&orf)
  60. #define check_stype(orf,styp)\
  61. if ( !r_has_stype(&orf,imemory,styp) ) return_op_typecheck(&orf)
  62. #define check_array(orf)\
  63. check_array_else(orf, return_op_typecheck(&orf))
  64. #define check_type_access(orf,typ,acc1)\
  65. if ( !r_has_type_attrs(&orf,typ,acc1) )\
  66. return_error((!r_has_type(&orf,typ) ? check_type_failed(&orf) :\
  67. e_invalidaccess))
  68. #define check_read_type(orf,typ)\
  69. check_type_access(orf,typ,a_read)
  70. #define check_write_type(orf,typ)\
  71. check_type_access(orf,typ,a_write)
  72. /* Macro for as yet unimplemented operators. */
  73. /* The if ( 1 ) is to prevent the compiler from complaining about */
  74. /* unreachable code. */
  75. #define NYI(msg) if ( 1 ) return_error(e_undefined)
  76. /*
  77. * If an operator has popped or pushed something on the control stack,
  78. * it must return o_pop_estack or o_push_estack respectively,
  79. * rather than 0, to indicate success.
  80. * It is OK to return o_pop_estack if nothing has been popped,
  81. * but it is not OK to return o_push_estack if nothing has been pushed.
  82. *
  83. * If an operator has suspended the current context and wants the
  84. * interpreter to call the scheduler, it must return o_reschedule.
  85. * It may also have pushed or popped elements on the control stack.
  86. * (This is only used when the Display PostScript option is included.)
  87. *
  88. * These values must be greater than 1, and far enough apart from zero and
  89. * from each other not to tempt a compiler into implementing a 'switch'
  90. * on them using indexing rather than testing.
  91. */
  92. #define o_push_estack 5
  93. #define o_pop_estack 14
  94. #define o_reschedule 22
  95. #endif /* oper_INCLUDED */