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