home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / printing / ghostscrip / source / _gs / h / oper < prev    next >
Encoding:
Text File  |  1991-10-27  |  3.6 KB  |  95 lines

  1. /* Copyright (C) 1989, 1990, 1991 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 "iutil.h"
  25.  
  26. /* Structure for initializing variables that hold name constants. */
  27. typedef struct {
  28.     char _ds *vname;
  29.     ref _ds *pvref;
  30. } names_def;
  31. #define names_def_end {(char _ds *)0, (ref _ds *)0}
  32. extern void init_names(P1(names_def _ds *));
  33.  
  34. /* Operand stack manipulation */
  35. /* The most efficient code is different on MS-DOS vs. Unix.... */
  36. #ifdef __MSDOS__            /* stupid compiler */
  37. #define push(n)\
  38.   if ( (op += (n)) > ostop ) return (e_stackoverflow); else osp += (n)
  39. #else                    /* reasonable compiler */
  40. #define push(n)\
  41.   if ( (osp = op += (n)) > ostop ) return (osp -= (n), e_stackoverflow)
  42. #endif
  43. /*
  44.  * Note that the pop macro only decrements osp, not op.  For this reason,
  45.  *
  46.  *    >>>    pop should only be used just before returning,    <<<
  47.  *    >>>    or else op must be decremented explicitly.    <<<
  48.  */
  49. #define pop(n) (osp -= (n))
  50. /*
  51.  * Note that the interpreter does not check for operand stack underflow
  52.  * before calling the operator procedure.  There are "guard" entries
  53.  * with invalid types and attributes just below the bottom of the
  54.  * operand stack: if the operator returns with a typecheck error,
  55.  * the interpreter checks for underflow at that time.
  56.  * Operators that don't typecheck their arguments must check for
  57.  * operand stack underflow explicitly.
  58.  */
  59. #define os_max_nargs 6
  60. extern os_ptr osp_nargs[os_max_nargs];
  61. #define check_op(nargs)\
  62.   if ( op < osp_nargs[(nargs) - 1] ) return e_stackunderflow
  63.  
  64. /* Check type */
  65. #define check_type(rf,typ)\
  66.   if ( !r_has_type(&rf,typ) ) return e_typecheck
  67. /* Check for array */
  68. #define check_array_else(rf,err)\
  69.   if ( !r_has_type(&rf, t_array) ) return err
  70. #define check_array(rf) check_array_else(rf, e_typecheck)
  71. /* Check for procedure */
  72. #define check_proc(rf)\
  73.   switch ( r_type(&rf) )\
  74.    { default: return e_typecheck;\
  75.      case t_array: case t_mixedarray: case t_shortarray: ; }\
  76.   check_access(rf, (a_execute+a_executable))
  77.  
  78. /* Check for read, write, or execute access */
  79. #define check_access(rf,acc)\
  80.   if ( !r_has_attrs(&rf,acc) ) return e_invalidaccess
  81. #define check_read(rf) check_access(rf,a_read)
  82. #define check_read_type(rf,typ) check_type(rf,typ); check_read(rf)
  83. #define check_write(rf) check_access(rf,a_write)
  84. #define check_write_type(rf,typ) check_type(rf,typ); check_write(rf)
  85. #define check_execute(rf) check_access(rf,a_execute)
  86.  
  87. /* Macro for as yet unimplemented operators. */
  88. /* The if ( 1 ) is to prevent the compiler from complaining about */
  89. /* unreachable code. */
  90. #define NYI(msg) if ( 1 ) return e_undefined
  91.  
  92. /* If an operator may have popped or pushed something on the control stack, */
  93. /* it must return o_check_estack rather than 0 to indicate success. */
  94. #define o_check_estack 1
  95.