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