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 / OPER.H < prev    next >
C/C++ Source or Header  |  1992-09-17  |  5KB  |  125 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. /* oper.h */
  21. /* Definitions for Ghostscript operators */
  22. #include "ostack.h"
  23. #include "opdef.h"
  24. #include "gsutil.h"
  25. #include "iutil.h"
  26.  
  27. /* Structure for initializing variables that hold name constants. */
  28. typedef struct {
  29.     const char _ds *vname;
  30.     ref _ds *pvref;
  31. } names_def;
  32. #define names_def_end {(const char _ds *)0, (ref _ds *)0}
  33. extern void init_names(P1(const names_def _ds *));
  34.  
  35. /* Operand stack manipulation */
  36. /* The most efficient code is different depending on the compiler.... */
  37. #ifdef __TURBOC__            /* stupid compilers */
  38. #define push(n)\
  39.   if ( (op += (n)) > ostop ) return (e_stackoverflow); else osp += (n)
  40. #else                    /* reasonable compiler */
  41. #define push(n)\
  42.   if ( (osp = op += (n)) > ostop ) return (osp -= (n), e_stackoverflow)
  43. #endif
  44. /*
  45.  * Note that the pop macro only decrements osp, not op.  For this reason,
  46.  *
  47.  *    >>>    pop should only be used just before returning,    <<<
  48.  *    >>>    or else op must be decremented explicitly.    <<<
  49.  */
  50. #define pop(n) (osp -= (n))
  51. /*
  52.  * Note that the interpreter does not check for operand stack underflow
  53.  * before calling the operator procedure.  There are "guard" entries
  54.  * with invalid types and attributes just below the bottom of the
  55.  * operand stack: if the operator returns with a typecheck error,
  56.  * the interpreter checks for underflow at that time.
  57.  * Operators that don't typecheck their arguments must check for
  58.  * operand stack underflow explicitly; operators that take a variable
  59.  * number of arguments must also check for stack underflow in those cases
  60.  * where they expect more than their minimum number of arguments.
  61.  * (This is because the interpreter can only recognize that a typecheck
  62.  * is really a stackunderflow when the stack has fewer than the
  63.  * operator's declared minimum number of entries.)
  64.  */
  65. #define os_max_nargs 6
  66. extern os_ptr osp_nargs[os_max_nargs];
  67. #define op_nargs_check(nargs) osp_nargs[(nargs) - 1]
  68. #define check_op(nargs)\
  69.   if ( op < op_nargs_check(nargs) ) return e_stackunderflow
  70.  
  71. /* Check type */
  72. #define check_type(rf,typ)\
  73.   if ( !r_has_type(&rf,typ) ) return e_typecheck
  74. /* Check for array */
  75. #define check_array_else(rf,err)\
  76.   if ( !r_has_type(&rf, t_array) ) return err
  77. #define check_array(rf) check_array_else(rf, e_typecheck)
  78. /* Check for procedure */
  79. #define check_proc(rf)\
  80.   switch ( r_type_xe(&rf) )\
  81.    { default:\
  82.     return(r_has_attrs(&rf, a_execute + a_executable) ? e_typecheck :\
  83.            e_invalidaccess);\
  84.      case type_xe_value(t_array, a_execute + a_executable):\
  85.      case type_xe_value(t_mixedarray, a_execute + a_executable):\
  86.      case type_xe_value(t_shortarray, a_execute + a_executable): ;\
  87.    }
  88.  
  89. /* Check for read, write, or execute access. */
  90. #define check_access(rf,acc1)\
  91.   if ( !r_has_attr(&rf,acc1) ) return e_invalidaccess
  92. #define check_read(rf) check_access(rf,a_read)
  93. #define check_type_access(rf,typ,acc1)\
  94.   if ( !r_has_type_attrs(&rf,typ,acc1) )\
  95.     return (!r_has_type(&rf,typ) ? e_typecheck : e_invalidaccess)
  96. #define check_read_type(rf,typ) check_type_access(rf,typ,a_read)
  97. #define check_write(rf) check_access(rf,a_write)
  98. #define check_write_type(rf,typ) check_type_access(rf,typ,a_write)
  99. #define check_execute(rf) check_access(rf,a_execute)
  100.  
  101. /* Macro for as yet unimplemented operators. */
  102. /* The if ( 1 ) is to prevent the compiler from complaining about */
  103. /* unreachable code. */
  104. #define NYI(msg) if ( 1 ) return e_undefined
  105.  
  106. /*
  107.  * If an operator has popped or pushed something on the control stack,
  108.  * it must return o_pop_estack or o_push_estack respectively,
  109.  * rather than 0, to indicate success.
  110.  * It is OK to return o_pop_estack if nothing has been popped,
  111.  * but it is not OK to return o_push_estack if nothing has been pushed.
  112.  *
  113.  * If an operator has suspended the current context and wants the
  114.  * interpreter to call the scheduler, it must return o_reschedule.
  115.  * It may also have pushed or popped elements on the control stack.
  116.  * (This is only used when the Display PostScript option is included.)
  117.  *
  118.  * These values must be positive, and far enough apart from zero and
  119.  * from each other not to tempt a compiler into implementing a 'switch'
  120.  * on them using indexing rather than testing.
  121.  */
  122. #define o_push_estack 3
  123. #define o_pop_estack 8
  124. #define o_reschedule 14
  125.