oper.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 1989, 1995, 1998, 1999 Aladdin Enterprises. 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: oper.h,v 1.2 2000/09/19 19:00:47 lpd Exp $ */
  16. /* Definitions for Ghostscript operators */
  17. #ifndef oper_INCLUDED
  18. # define oper_INCLUDED
  19. #include "errors.h"
  20. #include "ostack.h"
  21. #include "opdef.h"
  22. #include "opextern.h"
  23. #include "opcheck.h"
  24. #include "iutil.h"
  25. /*
  26. * Operator procedures take a single argument. This is currently a pointer
  27. * to the current context state, but might conceivably change in the future.
  28. * They return 0 for success, a negative code for an error, or a positive
  29. * code for some uncommon situations (see below).
  30. */
  31. /*
  32. * In order to combine typecheck and stackunderflow error checking
  33. * into a single test, we guard the bottom of the o-stack with
  34. * additional entries of type t__invalid. However, if a type check fails,
  35. * we must make an additional check to determine which error
  36. * should be reported. In order not to have to make this check in-line
  37. * in every type check in every operator, we define a procedure that takes
  38. * an o-stack pointer and returns e_stackunderflow if it points to
  39. * a guard entry, e_typecheck otherwise.
  40. *
  41. * Note that we only need to do this for typecheck, not for any other
  42. * kind of error such as invalidaccess, since any operator that can
  43. * generate the latter will do a check_type or a check_op first.
  44. * (See ostack.h for more information.)
  45. *
  46. * We define the operand type of check_type_failed as const ref * rather than
  47. * const_os_ptr simply because there are a number of routines that might
  48. * be used either with a stack operand or with a general operand, and
  49. * the check for t__invalid is harmless when applied to off-stack refs.
  50. */
  51. int check_type_failed(P1(const ref *));
  52. /*
  53. * Check the type of an object. Operators almost always use check_type,
  54. * which includes the stack underflow check described just above;
  55. * check_type_only is for checking subsidiary objects obtained from
  56. * places other than the stack.
  57. */
  58. #define return_op_typecheck(op)\
  59. return_error(check_type_failed(op))
  60. #define check_type(orf,typ)\
  61. if ( !r_has_type(&orf,typ) ) return_op_typecheck(&orf)
  62. #define check_stype(orf,styp)\
  63. if ( !r_has_stype(&orf,imemory,styp) ) return_op_typecheck(&orf)
  64. #define check_array(orf)\
  65. check_array_else(orf, return_op_typecheck(&orf))
  66. #define check_type_access(orf,typ,acc1)\
  67. if ( !r_has_type_attrs(&orf,typ,acc1) )\
  68. return_error((!r_has_type(&orf,typ) ? check_type_failed(&orf) :\
  69. e_invalidaccess))
  70. #define check_read_type(orf,typ)\
  71. check_type_access(orf,typ,a_read)
  72. #define check_write_type(orf,typ)\
  73. check_type_access(orf,typ,a_write)
  74. /* Macro for as yet unimplemented operators. */
  75. /* The if ( 1 ) is to prevent the compiler from complaining about */
  76. /* unreachable code. */
  77. #define NYI(msg) if ( 1 ) return_error(e_undefined)
  78. /*
  79. * If an operator has popped or pushed something on the control stack,
  80. * it must return o_pop_estack or o_push_estack respectively,
  81. * rather than 0, to indicate success.
  82. * It is OK to return o_pop_estack if nothing has been popped,
  83. * but it is not OK to return o_push_estack if nothing has been pushed.
  84. *
  85. * If an operator has suspended the current context and wants the
  86. * interpreter to call the scheduler, it must return o_reschedule.
  87. * It may also have pushed or popped elements on the control stack.
  88. * (This is only used when the Display PostScript option is included.)
  89. *
  90. * These values must be greater than 1, and far enough apart from zero and
  91. * from each other not to tempt a compiler into implementing a 'switch'
  92. * on them using indexing rather than testing.
  93. */
  94. #define o_push_estack 5
  95. #define o_pop_estack 14
  96. #define o_reschedule 22
  97. #endif /* oper_INCLUDED */