interp.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. /* Copyright (C) 1989, 2000, 2001 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: interp.c,v 1.20 2004/09/03 20:23:10 ray Exp $ */
  14. /* Ghostscript language interpreter */
  15. #include "memory_.h"
  16. #include "string_.h"
  17. #include "ghost.h"
  18. #include "gsstruct.h" /* for iastruct.h */
  19. #include "stream.h"
  20. #include "ierrors.h"
  21. #include "estack.h"
  22. #include "ialloc.h"
  23. #include "iastruct.h"
  24. #include "icontext.h"
  25. #include "icremap.h"
  26. #include "idebug.h"
  27. #include "igstate.h" /* for handling e_RemapColor */
  28. #include "inamedef.h"
  29. #include "iname.h" /* for the_name_table */
  30. #include "interp.h"
  31. #include "ipacked.h"
  32. #include "ostack.h" /* must precede iscan.h */
  33. #include "strimpl.h" /* for sfilter.h */
  34. #include "sfilter.h" /* for iscan.h */
  35. #include "iscan.h"
  36. #include "iddict.h"
  37. #include "isave.h"
  38. #include "istack.h"
  39. #include "itoken.h"
  40. #include "iutil.h" /* for array_get */
  41. #include "ivmspace.h"
  42. #include "dstack.h"
  43. #include "files.h" /* for file_check_read */
  44. #include "oper.h"
  45. #include "store.h"
  46. #include "gpcheck.h"
  47. /*
  48. * We may or may not optimize the handling of the special fast operators
  49. * in packed arrays. If we do this, they run much faster when packed, but
  50. * slightly slower when not packed.
  51. */
  52. #define PACKED_SPECIAL_OPS 1
  53. /*
  54. * Pseudo-operators (procedures of type t_oparray) record
  55. * the operand and dictionary stack pointers, and restore them if an error
  56. * occurs during the execution of the procedure and if the procedure hasn't
  57. * (net) decreased the depth of the stack. While this obviously doesn't
  58. * do all the work of restoring the state if a pseudo-operator gets an
  59. * error, it's a big help. The only downside is that pseudo-operators run
  60. * a little slower.
  61. */
  62. /* GC descriptors for stacks */
  63. extern_st(st_ref_stack);
  64. public_st_dict_stack();
  65. public_st_exec_stack();
  66. public_st_op_stack();
  67. /*
  68. * The procedure to call if an operator requests rescheduling.
  69. * This causes an error unless the context machinery has been installed.
  70. */
  71. private int
  72. no_reschedule(i_ctx_t **pi_ctx_p)
  73. {
  74. return_error(e_invalidcontext);
  75. }
  76. int (*gs_interp_reschedule_proc)(i_ctx_t **) = no_reschedule;
  77. /*
  78. * The procedure to call for time-slicing.
  79. * This is a no-op unless the context machinery has been installed.
  80. */
  81. int (*gs_interp_time_slice_proc)(i_ctx_t **) = 0;
  82. /*
  83. * The number of interpreter "ticks" between calls on the time_slice_proc.
  84. * Currently, the clock ticks before each operator, and at each
  85. * procedure return.
  86. */
  87. int gs_interp_time_slice_ticks = 0x7fff;
  88. /*
  89. * Apply an operator. When debugging, we route all operator calls
  90. * through a procedure.
  91. */
  92. #ifdef DEBUG
  93. private int
  94. call_operator(op_proc_t op_proc, i_ctx_t *i_ctx_p)
  95. {
  96. int code = op_proc(i_ctx_p);
  97. return code;
  98. }
  99. #else
  100. # define call_operator(proc, p) ((*(proc))(p))
  101. #endif
  102. /* Define debugging statistics. */
  103. #ifdef DEBUG
  104. struct stats_interp_s {
  105. long top;
  106. long lit, lit_array, exec_array, exec_operator, exec_name;
  107. long x_add, x_def, x_dup, x_exch, x_if, x_ifelse,
  108. x_index, x_pop, x_roll, x_sub;
  109. long find_name, name_lit, name_proc, name_oparray, name_operator;
  110. long p_full, p_exec_operator, p_exec_oparray, p_exec_non_x_operator,
  111. p_integer, p_lit_name, p_exec_name;
  112. long p_find_name, p_name_lit, p_name_proc;
  113. } stats_interp;
  114. # define INCR(v) (++(stats_interp.v))
  115. #else
  116. # define INCR(v) DO_NOTHING
  117. #endif
  118. /* Forward references */
  119. private int estack_underflow(i_ctx_t *);
  120. private int interp(i_ctx_t **, const ref *, ref *);
  121. private int interp_exit(i_ctx_t *);
  122. private void set_gc_signal(i_ctx_t *, int *, int);
  123. private int copy_stack(i_ctx_t *, const ref_stack_t *, ref *);
  124. private int oparray_pop(i_ctx_t *);
  125. private int oparray_cleanup(i_ctx_t *);
  126. private int zsetstackprotect(i_ctx_t *);
  127. private int zcurrentstackprotect(i_ctx_t *);
  128. /* Stack sizes */
  129. /* The maximum stack sizes may all be set in the makefile. */
  130. /*
  131. * Define the initial maximum size of the operand stack (MaxOpStack
  132. * user parameter).
  133. */
  134. #ifndef MAX_OSTACK
  135. # define MAX_OSTACK 800
  136. #endif
  137. /*
  138. * The minimum block size for extending the operand stack is the larger of:
  139. * - the maximum number of parameters to an operator
  140. * (currently setcolorscreen, with 12 parameters);
  141. * - the maximum number of values pushed by an operator
  142. * (currently setcolortransfer, which calls zcolor_remap_one 4 times
  143. * and therefore pushes 16 values).
  144. */
  145. #define MIN_BLOCK_OSTACK 16
  146. const int gs_interp_max_op_num_args = MIN_BLOCK_OSTACK; /* for iinit.c */
  147. /*
  148. * Define the initial maximum size of the execution stack (MaxExecStack
  149. * user parameter).
  150. */
  151. #ifndef MAX_ESTACK
  152. # define MAX_ESTACK 5000
  153. #endif
  154. /*
  155. * The minimum block size for extending the execution stack is the largest
  156. * size of a contiguous block surrounding an e-stack mark. (At least,
  157. * that's what the minimum value would be if we supported multi-block
  158. * estacks, which we currently don't.) Currently, the largest such block is
  159. * the one created for text processing, which is 8 (snumpush) slots.
  160. */
  161. #define MIN_BLOCK_ESTACK 8
  162. /*
  163. * If we get an e-stack overflow, we need to cut it back far enough to
  164. * have some headroom for executing the error procedure.
  165. */
  166. #define ES_HEADROOM 20
  167. /*
  168. * Define the initial maximum size of the dictionary stack (MaxDictStack
  169. * user parameter). Again, this is also currently the block size for
  170. * extending the d-stack.
  171. */
  172. #ifndef MAX_DSTACK
  173. # define MAX_DSTACK 20
  174. #endif
  175. /*
  176. * The minimum block size for extending the dictionary stack is the number
  177. * of permanent entries on the dictionary stack, currently 3.
  178. */
  179. #define MIN_BLOCK_DSTACK 3
  180. /* See estack.h for a description of the execution stack. */
  181. /* The logic for managing icount and iref below assumes that */
  182. /* there are no control operators which pop and then push */
  183. /* information on the execution stack. */
  184. /* Stacks */
  185. extern_st(st_ref_stack);
  186. #define OS_GUARD_UNDER 10
  187. #define OS_GUARD_OVER 10
  188. #define OS_REFS_SIZE(body_size)\
  189. (stack_block_refs + OS_GUARD_UNDER + (body_size) + OS_GUARD_OVER)
  190. #define ES_GUARD_UNDER 1
  191. #define ES_GUARD_OVER 10
  192. #define ES_REFS_SIZE(body_size)\
  193. (stack_block_refs + ES_GUARD_UNDER + (body_size) + ES_GUARD_OVER)
  194. #define DS_REFS_SIZE(body_size)\
  195. (stack_block_refs + (body_size))
  196. /* Extended types. The interpreter may replace the type of operators */
  197. /* in procedures with these, to speed up the interpretation loop. */
  198. /****** NOTE: If you add or change entries in this list, */
  199. /****** you must change the three dispatches in the interpreter loop. */
  200. /* The operator procedures are declared in opextern.h. */
  201. #define tx_op t_next_index
  202. typedef enum {
  203. tx_op_add = tx_op,
  204. tx_op_def,
  205. tx_op_dup,
  206. tx_op_exch,
  207. tx_op_if,
  208. tx_op_ifelse,
  209. tx_op_index,
  210. tx_op_pop,
  211. tx_op_roll,
  212. tx_op_sub,
  213. tx_next_op
  214. } special_op_types;
  215. #define num_special_ops ((int)tx_next_op - tx_op)
  216. const int gs_interp_num_special_ops = num_special_ops; /* for iinit.c */
  217. const int tx_next_index = tx_next_op;
  218. /*
  219. * Define the interpreter operators, which include the extended-type
  220. * operators defined in the list above. NOTE: if the size of this table
  221. * ever exceeds 15 real entries, it will have to be split.
  222. */
  223. const op_def interp_op_defs[] = {
  224. /*
  225. * The very first entry, which corresponds to operator index 0,
  226. * must not contain an actual operator.
  227. */
  228. op_def_begin_dict("systemdict"),
  229. /*
  230. * The next entries must be the extended-type operators, in the
  231. * correct order.
  232. */
  233. {"2add", zadd},
  234. {"2def", zdef},
  235. {"1dup", zdup},
  236. {"2exch", zexch},
  237. {"2if", zif},
  238. {"3ifelse", zifelse},
  239. {"1index", zindex},
  240. {"1pop", zpop},
  241. {"2roll", zroll},
  242. {"2sub", zsub},
  243. /*
  244. * The remaining entries are internal operators.
  245. */
  246. {"0.currentstackprotect", zcurrentstackprotect},
  247. {"1.setstackprotect", zsetstackprotect},
  248. {"0%interp_exit", interp_exit},
  249. {"0%oparray_pop", oparray_pop},
  250. op_def_end(0)
  251. };
  252. #define make_null_proc(pref)\
  253. make_empty_const_array(pref, a_executable + a_readonly)
  254. /* Initialize the interpreter. */
  255. int
  256. gs_interp_init(i_ctx_t **pi_ctx_p, const ref *psystem_dict,
  257. gs_dual_memory_t *dmem)
  258. {
  259. /* Create and initialize a context state. */
  260. gs_context_state_t *pcst = 0;
  261. int code = context_state_alloc(&pcst, psystem_dict, dmem);
  262. if (code >= 0)
  263. code = context_state_load(pcst);
  264. if (code < 0)
  265. lprintf1("Fatal error %d in gs_interp_init!", code);
  266. *pi_ctx_p = pcst;
  267. return code;
  268. }
  269. /*
  270. * Create initial stacks for the interpreter.
  271. * We export this for creating new contexts.
  272. */
  273. int
  274. gs_interp_alloc_stacks(gs_ref_memory_t *mem, gs_context_state_t * pcst)
  275. {
  276. gs_ref_memory_t *smem =
  277. (gs_ref_memory_t *)gs_memory_stable((gs_memory_t *)mem);
  278. ref stk;
  279. #define REFS_SIZE_OSTACK OS_REFS_SIZE(MAX_OSTACK)
  280. #define REFS_SIZE_ESTACK ES_REFS_SIZE(MAX_ESTACK)
  281. #define REFS_SIZE_DSTACK DS_REFS_SIZE(MAX_DSTACK)
  282. gs_alloc_ref_array(smem, &stk, 0,
  283. REFS_SIZE_OSTACK + REFS_SIZE_ESTACK +
  284. REFS_SIZE_DSTACK, "gs_interp_alloc_stacks");
  285. {
  286. ref_stack_t *pos = &pcst->op_stack.stack;
  287. r_set_size(&stk, REFS_SIZE_OSTACK);
  288. ref_stack_init(pos, &stk, OS_GUARD_UNDER, OS_GUARD_OVER, NULL,
  289. smem, NULL);
  290. ref_stack_set_error_codes(pos, e_stackunderflow, e_stackoverflow);
  291. ref_stack_set_max_count(pos, MAX_OSTACK);
  292. stk.value.refs += REFS_SIZE_OSTACK;
  293. }
  294. {
  295. ref_stack_t *pes = &pcst->exec_stack.stack;
  296. ref euop;
  297. r_set_size(&stk, REFS_SIZE_ESTACK);
  298. make_oper(&euop, 0, estack_underflow);
  299. ref_stack_init(pes, &stk, ES_GUARD_UNDER, ES_GUARD_OVER, &euop,
  300. smem, NULL);
  301. ref_stack_set_error_codes(pes, e_ExecStackUnderflow,
  302. e_execstackoverflow);
  303. /**************** E-STACK EXPANSION IS NYI. ****************/
  304. ref_stack_allow_expansion(pes, false);
  305. ref_stack_set_max_count(pes, MAX_ESTACK);
  306. stk.value.refs += REFS_SIZE_ESTACK;
  307. }
  308. {
  309. ref_stack_t *pds = &pcst->dict_stack.stack;
  310. r_set_size(&stk, REFS_SIZE_DSTACK);
  311. ref_stack_init(pds, &stk, 0, 0, NULL, smem, NULL);
  312. ref_stack_set_error_codes(pds, e_dictstackunderflow,
  313. e_dictstackoverflow);
  314. ref_stack_set_max_count(pds, MAX_DSTACK);
  315. }
  316. #undef REFS_SIZE_OSTACK
  317. #undef REFS_SIZE_ESTACK
  318. #undef REFS_SIZE_DSTACK
  319. return 0;
  320. }
  321. /*
  322. * Free the stacks when destroying a context. This is the inverse of
  323. * create_stacks.
  324. */
  325. void
  326. gs_interp_free_stacks(gs_ref_memory_t * smem, gs_context_state_t * pcst)
  327. {
  328. /* Free the stacks in inverse order of allocation. */
  329. ref_stack_release(&pcst->dict_stack.stack);
  330. ref_stack_release(&pcst->exec_stack.stack);
  331. ref_stack_release(&pcst->op_stack.stack);
  332. }
  333. void
  334. gs_interp_reset(i_ctx_t *i_ctx_p)
  335. { /* Reset the stacks. */
  336. ref_stack_clear(&o_stack);
  337. ref_stack_clear(&e_stack);
  338. esp++;
  339. make_oper(esp, 0, interp_exit);
  340. ref_stack_pop_to(&d_stack, min_dstack_size);
  341. dict_set_top();
  342. }
  343. /* Report an e-stack block underflow. The bottom guard slots of */
  344. /* e-stack blocks contain a pointer to this procedure. */
  345. private int
  346. estack_underflow(i_ctx_t *i_ctx_p)
  347. {
  348. return e_ExecStackUnderflow;
  349. }
  350. /*
  351. * Create an operator during initialization.
  352. * If operator is hard-coded into the interpreter,
  353. * assign it a special type and index.
  354. */
  355. void
  356. gs_interp_make_oper(ref * opref, op_proc_t proc, int idx)
  357. {
  358. int i;
  359. for (i = num_special_ops; i > 0 && proc != interp_op_defs[i].proc; --i)
  360. DO_NOTHING;
  361. if (i > 0)
  362. make_tasv(opref, tx_op + (i - 1), a_executable, i, opproc, proc);
  363. else
  364. make_tasv(opref, t_operator, a_executable, idx, opproc, proc);
  365. }
  366. /*
  367. * Call the garbage collector, updating the context pointer properly.
  368. */
  369. int
  370. interp_reclaim(i_ctx_t **pi_ctx_p, int space)
  371. {
  372. i_ctx_t *i_ctx_p = *pi_ctx_p;
  373. gs_gc_root_t ctx_root;
  374. int code;
  375. gs_register_struct_root(imemory_system, &ctx_root,
  376. (void **)pi_ctx_p, "interp_reclaim(pi_ctx_p)");
  377. code = (*idmemory->reclaim)(idmemory, space);
  378. i_ctx_p = *pi_ctx_p; /* may have moved */
  379. gs_unregister_root(imemory_system, &ctx_root, "interp_reclaim(pi_ctx_p)");
  380. return code;
  381. }
  382. /*
  383. * Invoke the interpreter. If execution completes normally, return 0.
  384. * If an error occurs, the action depends on user_errors as follows:
  385. * user_errors < 0: always return an error code.
  386. * user_errors >= 0: let the PostScript machinery handle all errors.
  387. * (This will eventually result in a fatal error if no 'stopped'
  388. * is active.)
  389. * In case of a quit or a fatal error, also store the exit code.
  390. * Set *perror_object to null or the error object.
  391. */
  392. private int gs_call_interp(i_ctx_t **, ref *, int, int *, ref *);
  393. int
  394. gs_interpret(i_ctx_t **pi_ctx_p, ref * pref, int user_errors, int *pexit_code,
  395. ref * perror_object)
  396. {
  397. i_ctx_t *i_ctx_p = *pi_ctx_p;
  398. gs_gc_root_t error_root;
  399. int code;
  400. gs_register_ref_root(imemory_system, &error_root,
  401. (void **)&perror_object, "gs_interpret");
  402. code = gs_call_interp(pi_ctx_p, pref, user_errors, pexit_code,
  403. perror_object);
  404. i_ctx_p = *pi_ctx_p;
  405. gs_unregister_root(imemory_system, &error_root, "gs_interpret");
  406. /* Avoid a dangling reference to a stack-allocated GC signal. */
  407. set_gc_signal(i_ctx_p, NULL, 0);
  408. return code;
  409. }
  410. private int
  411. gs_call_interp(i_ctx_t **pi_ctx_p, ref * pref, int user_errors,
  412. int *pexit_code, ref * perror_object)
  413. {
  414. ref *epref = pref;
  415. ref doref;
  416. ref *perrordict;
  417. ref error_name;
  418. int code, ccode;
  419. ref saref;
  420. int gc_signal = 0;
  421. i_ctx_t *i_ctx_p = *pi_ctx_p;
  422. *pexit_code = 0;
  423. ialloc_reset_requested(idmemory);
  424. again:
  425. /* Avoid a dangling error object that might get traced by a future GC. */
  426. make_null(perror_object);
  427. o_stack.requested = e_stack.requested = d_stack.requested = 0;
  428. while (gc_signal) { /* Some routine below triggered a GC. */
  429. gs_gc_root_t epref_root;
  430. gc_signal = 0;
  431. /* Make sure that doref will get relocated properly if */
  432. /* a garbage collection happens with epref == &doref. */
  433. gs_register_ref_root(imemory_system, &epref_root,
  434. (void **)&epref, "gs_call_interp(epref)");
  435. code = interp_reclaim(pi_ctx_p, -1);
  436. i_ctx_p = *pi_ctx_p;
  437. gs_unregister_root(imemory_system, &epref_root,
  438. "gs_call_interp(epref)");
  439. if (code < 0)
  440. return code;
  441. }
  442. code = interp(pi_ctx_p, epref, perror_object);
  443. i_ctx_p = *pi_ctx_p;
  444. /* Prevent a dangling reference to the GC signal in ticks_left */
  445. /* in the frame of interp, but be prepared to do a GC if */
  446. /* an allocation in this routine asks for it. */
  447. set_gc_signal(i_ctx_p, &gc_signal, 1);
  448. if (esp < esbot) /* popped guard entry */
  449. esp = esbot;
  450. switch (code) {
  451. case e_Fatal:
  452. *pexit_code = 255;
  453. return code;
  454. case e_Quit:
  455. *perror_object = osp[-1];
  456. *pexit_code = code = osp->value.intval;
  457. osp -= 2;
  458. return
  459. (code == 0 ? e_Quit :
  460. code < 0 && code > -100 ? code : e_Fatal);
  461. case e_InterpreterExit:
  462. return 0;
  463. case e_ExecStackUnderflow:
  464. /****** WRONG -- must keep mark blocks intact ******/
  465. ref_stack_pop_block(&e_stack);
  466. doref = *perror_object;
  467. epref = &doref;
  468. goto again;
  469. case e_VMreclaim:
  470. /* Do the GC and continue. */
  471. code = interp_reclaim(pi_ctx_p,
  472. (osp->value.intval == 2 ?
  473. avm_global : avm_local));
  474. i_ctx_p = *pi_ctx_p;
  475. /****** What if code < 0? ******/
  476. make_oper(&doref, 0, zpop);
  477. epref = &doref;
  478. goto again;
  479. case e_NeedInput:
  480. case e_NeedStdin:
  481. case e_NeedStdout:
  482. case e_NeedStderr:
  483. return code;
  484. }
  485. /* Adjust osp in case of operand stack underflow */
  486. if (osp < osbot - 1)
  487. osp = osbot - 1;
  488. /* We have to handle stack over/underflow specially, because */
  489. /* we might be able to recover by adding or removing a block. */
  490. switch (code) {
  491. case e_dictstackoverflow:
  492. if (ref_stack_extend(&d_stack, d_stack.requested) >= 0) {
  493. dict_set_top();
  494. doref = *perror_object;
  495. epref = &doref;
  496. goto again;
  497. }
  498. if (osp >= ostop) {
  499. if ((ccode = ref_stack_extend(&o_stack, 1)) < 0)
  500. return ccode;
  501. }
  502. ccode = copy_stack(i_ctx_p, &d_stack, &saref);
  503. if (ccode < 0)
  504. return ccode;
  505. ref_stack_pop_to(&d_stack, min_dstack_size);
  506. dict_set_top();
  507. *++osp = saref;
  508. break;
  509. case e_dictstackunderflow:
  510. if (ref_stack_pop_block(&d_stack) >= 0) {
  511. dict_set_top();
  512. doref = *perror_object;
  513. epref = &doref;
  514. goto again;
  515. }
  516. break;
  517. case e_execstackoverflow:
  518. /* We don't have to handle this specially: */
  519. /* The only places that could generate it */
  520. /* use check_estack, which does a ref_stack_extend, */
  521. /* so if we get this error, it's a real one. */
  522. if (osp >= ostop) {
  523. if ((ccode = ref_stack_extend(&o_stack, 1)) < 0)
  524. return ccode;
  525. }
  526. ccode = copy_stack(i_ctx_p, &e_stack, &saref);
  527. if (ccode < 0)
  528. return ccode;
  529. {
  530. uint count = ref_stack_count(&e_stack);
  531. uint limit = ref_stack_max_count(&e_stack) - ES_HEADROOM;
  532. if (count > limit) {
  533. /*
  534. * If there is an e-stack mark within MIN_BLOCK_ESTACK of
  535. * the new top, cut the stack back to remove the mark.
  536. */
  537. int skip = count - limit;
  538. int i;
  539. for (i = skip; i < skip + MIN_BLOCK_ESTACK; ++i) {
  540. const ref *ep = ref_stack_index(&e_stack, i);
  541. if (r_has_type_attrs(ep, t_null, a_executable)) {
  542. skip = i + 1;
  543. break;
  544. }
  545. }
  546. pop_estack(i_ctx_p, skip);
  547. }
  548. }
  549. *++osp = saref;
  550. break;
  551. case e_stackoverflow:
  552. if (ref_stack_extend(&o_stack, o_stack.requested) >= 0) { /* We can't just re-execute the object, because */
  553. /* it might be a procedure being pushed as a */
  554. /* literal. We check for this case specially. */
  555. doref = *perror_object;
  556. if (r_is_proc(&doref)) {
  557. *++osp = doref;
  558. make_null_proc(&doref);
  559. }
  560. epref = &doref;
  561. goto again;
  562. }
  563. ccode = copy_stack(i_ctx_p, &o_stack, &saref);
  564. if (ccode < 0)
  565. return ccode;
  566. ref_stack_clear(&o_stack);
  567. *++osp = saref;
  568. break;
  569. case e_stackunderflow:
  570. if (ref_stack_pop_block(&o_stack) >= 0) {
  571. doref = *perror_object;
  572. epref = &doref;
  573. goto again;
  574. }
  575. break;
  576. }
  577. if (user_errors < 0)
  578. return code;
  579. if (gs_errorname(i_ctx_p, code, &error_name) < 0)
  580. return code; /* out-of-range error code! */
  581. if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 ||
  582. dict_find(perrordict, &error_name, &epref) <= 0
  583. )
  584. return code; /* error name not in errordict??? */
  585. doref = *epref;
  586. epref = &doref;
  587. /* Push the error object on the operand stack if appropriate. */
  588. if (!ERROR_IS_INTERRUPT(code))
  589. *++osp = *perror_object;
  590. goto again;
  591. }
  592. private int
  593. interp_exit(i_ctx_t *i_ctx_p)
  594. {
  595. return e_InterpreterExit;
  596. }
  597. /* Set the GC signal for all VMs. */
  598. private void
  599. set_gc_signal(i_ctx_t *i_ctx_p, int *psignal, int value)
  600. {
  601. gs_memory_gc_status_t stat;
  602. int i;
  603. for (i = 0; i < countof(idmemory->spaces_indexed); i++) {
  604. gs_ref_memory_t *mem = idmemory->spaces_indexed[i];
  605. gs_ref_memory_t *mem_stable;
  606. if (mem == 0)
  607. continue;
  608. for (;; mem = mem_stable) {
  609. mem_stable = (gs_ref_memory_t *)
  610. gs_memory_stable((gs_memory_t *)mem);
  611. gs_memory_gc_status(mem, &stat);
  612. stat.psignal = psignal;
  613. stat.signal_value = value;
  614. gs_memory_set_gc_status(mem, &stat);
  615. if (mem_stable == mem)
  616. break;
  617. }
  618. }
  619. }
  620. /* Copy the contents of an overflowed stack into a (local) array. */
  621. private int
  622. copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, ref * arr)
  623. {
  624. uint size = ref_stack_count(pstack);
  625. uint save_space = ialloc_space(idmemory);
  626. int code;
  627. ialloc_set_space(idmemory, avm_local);
  628. code = ialloc_ref_array(arr, a_all, size, "copy_stack");
  629. if (code >= 0)
  630. code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory,
  631. "copy_stack");
  632. ialloc_set_space(idmemory, save_space);
  633. return code;
  634. }
  635. /* Get the name corresponding to an error number. */
  636. int
  637. gs_errorname(i_ctx_t *i_ctx_p, int code, ref * perror_name)
  638. {
  639. ref *perrordict, *pErrorNames;
  640. if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 ||
  641. dict_find_string(systemdict, "ErrorNames", &pErrorNames) <= 0
  642. )
  643. return_error(e_undefined); /* errordict or ErrorNames not found?! */
  644. return array_get(imemory, pErrorNames, (long)(-code - 1), perror_name);
  645. }
  646. /* Store an error string in $error.errorinfo. */
  647. /* This routine is here because of the proximity to the error handler. */
  648. int
  649. gs_errorinfo_put_string(i_ctx_t *i_ctx_p, const char *str)
  650. {
  651. ref rstr;
  652. ref *pderror;
  653. int code = string_to_ref(str, &rstr, iimemory, "gs_errorinfo_put_string");
  654. if (code < 0)
  655. return code;
  656. if (dict_find_string(systemdict, "$error", &pderror) <= 0 ||
  657. !r_has_type(pderror, t_dictionary) ||
  658. idict_put_string(pderror, "errorinfo", &rstr) < 0
  659. )
  660. return_error(e_Fatal);
  661. return 0;
  662. }
  663. /* Main interpreter. */
  664. /* If execution terminates normally, return e_InterpreterExit. */
  665. /* If an error occurs, leave the current object in *perror_object */
  666. /* and return a (negative) error code. */
  667. private int
  668. interp(i_ctx_t **pi_ctx_p /* context for execution, updated if resched */,
  669. const ref * pref /* object to interpret */,
  670. ref * perror_object)
  671. {
  672. i_ctx_t *i_ctx_p = *pi_ctx_p;
  673. /*
  674. * Note that iref may actually be either a ref * or a ref_packed *.
  675. * Certain DEC compilers assume that a ref * is ref-aligned even if it
  676. * is cast to a short *, and generate code on this assumption, leading
  677. * to "unaligned access" errors. For this reason, we declare
  678. * iref_packed, and use a macro to cast it to the more aligned type
  679. * where necessary (which is almost everywhere it is used). This may
  680. * lead to compiler warnings about "cast increases alignment
  681. * requirements", but this is less harmful than expensive traps at run
  682. * time.
  683. */
  684. register const ref_packed *iref_packed = (const ref_packed *)pref;
  685. /*
  686. * To make matters worse, some versions of gcc/egcs have a bug that
  687. * leads them to assume that if iref_packed is EVER cast to a ref *,
  688. * it is ALWAYS ref-aligned. We detect this in stdpre.h and provide
  689. * the following workaround:
  690. */
  691. #ifdef ALIGNMENT_ALIASING_BUG
  692. const ref *iref_temp;
  693. # define IREF (iref_temp = (const ref *)iref_packed, iref_temp)
  694. #else
  695. # define IREF ((const ref *)iref_packed)
  696. #endif
  697. #define SET_IREF(rp) (iref_packed = (const ref_packed *)(rp))
  698. register int icount = 0; /* # of consecutive tokens at iref */
  699. register os_ptr iosp = osp; /* private copy of osp */
  700. register es_ptr iesp = esp; /* private copy of esp */
  701. int code;
  702. ref token; /* token read from file or string, */
  703. /* must be declared in this scope */
  704. register const ref *pvalue;
  705. os_ptr whichp;
  706. /*
  707. * We have to make the error information into a struct;
  708. * otherwise, the Watcom compiler will assign it to registers
  709. * strictly on the basis of textual frequency.
  710. * We also have to use ref_assign_inline everywhere, and
  711. * avoid direct assignments of refs, so that esi and edi
  712. * will remain available on Intel processors.
  713. */
  714. struct interp_error_s {
  715. int code;
  716. int line;
  717. const ref *obj;
  718. ref full;
  719. } ierror;
  720. /*
  721. * Get a pointer to the name table so that we can use the
  722. * inline version of name_index_ref.
  723. */
  724. const name_table *const int_nt = imemory->gs_lib_ctx->gs_name_table;
  725. #define set_error(ecode)\
  726. { ierror.code = ecode; ierror.line = __LINE__; }
  727. #define return_with_error(ecode, objp)\
  728. { set_error(ecode); ierror.obj = objp; goto rwe; }
  729. #define return_with_error_iref(ecode)\
  730. { set_error(ecode); goto rwei; }
  731. #define return_with_code_iref()\
  732. { ierror.line = __LINE__; goto rweci; }
  733. #define return_with_error_code_op(nargs)\
  734. return_with_code_iref()
  735. #define return_with_stackoverflow(objp)\
  736. { o_stack.requested = 1; return_with_error(e_stackoverflow, objp); }
  737. #define return_with_stackoverflow_iref()\
  738. { o_stack.requested = 1; return_with_error_iref(e_stackoverflow); }
  739. int ticks_left = gs_interp_time_slice_ticks;
  740. /*
  741. * If we exceed the VMThreshold, set ticks_left to -100
  742. * to alert the interpreter that we need to garbage collect.
  743. */
  744. set_gc_signal(i_ctx_p, &ticks_left, -100);
  745. esfile_clear_cache();
  746. /*
  747. * From here on, if icount > 0, iref and icount correspond
  748. * to the top entry on the execution stack: icount is the count
  749. * of sequential entries remaining AFTER the current one.
  750. */
  751. #define IREF_NEXT(ip)\
  752. ((const ref_packed *)((const ref *)(ip) + 1))
  753. #define IREF_NEXT_EITHER(ip)\
  754. ( r_is_packed(ip) ? (ip) + 1 : IREF_NEXT(ip) )
  755. #define store_state(ep)\
  756. ( icount > 0 ? (ep->value.const_refs = IREF + 1, r_set_size(ep, icount)) : 0 )
  757. #define store_state_short(ep)\
  758. ( icount > 0 ? (ep->value.packed = iref_packed + 1, r_set_size(ep, icount)) : 0 )
  759. #define store_state_either(ep)\
  760. ( icount > 0 ? (ep->value.packed = IREF_NEXT_EITHER(iref_packed), r_set_size(ep, icount)) : 0 )
  761. #define next()\
  762. if ( --icount > 0 ) { iref_packed = IREF_NEXT(iref_packed); goto top; } else goto out
  763. #define next_short()\
  764. if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\
  765. ++iref_packed; goto top
  766. #define next_either()\
  767. if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\
  768. iref_packed = IREF_NEXT_EITHER(iref_packed); goto top
  769. #if !PACKED_SPECIAL_OPS
  770. # undef next_either
  771. # define next_either() next()
  772. # undef store_state_either
  773. # define store_state_either(ep) store_state(ep)
  774. #endif
  775. /* We want to recognize executable arrays here, */
  776. /* so we push the argument on the estack and enter */
  777. /* the loop at the bottom. */
  778. if (iesp >= estop)
  779. return_with_error(e_execstackoverflow, pref);
  780. ++iesp;
  781. ref_assign_inline(iesp, pref);
  782. goto bot;
  783. top:
  784. /*
  785. * This is the top of the interpreter loop.
  786. * iref points to the ref being interpreted.
  787. * Note that this might be an element of a packed array,
  788. * not a real ref: we carefully arranged the first 16 bits of
  789. * a ref and of a packed array element so they could be distinguished
  790. * from each other. (See ghost.h and packed.h for more detail.)
  791. */
  792. INCR(top);
  793. #ifdef DEBUG
  794. /* Do a little validation on the top o-stack entry. */
  795. if (iosp >= osbot &&
  796. (r_type(iosp) == t__invalid || r_type(iosp) >= tx_next_op)
  797. ) {
  798. lprintf("Invalid value on o-stack!\n");
  799. return_with_error_iref(e_Fatal);
  800. }
  801. if (gs_debug['I'] ||
  802. (gs_debug['i'] &&
  803. (r_is_packed(iref_packed) ?
  804. r_packed_is_name(iref_packed) :
  805. r_has_type(IREF, t_name)))
  806. ) {
  807. os_ptr save_osp = osp; /* avoid side-effects */
  808. es_ptr save_esp = esp;
  809. osp = iosp;
  810. esp = iesp;
  811. dlprintf5("d%u,e%u<%u>0x%lx(%d): ",
  812. ref_stack_count(&d_stack), ref_stack_count(&e_stack),
  813. ref_stack_count(&o_stack), (ulong)IREF, icount);
  814. debug_print_ref(imemory, IREF);
  815. if (iosp >= osbot) {
  816. dputs(" // ");
  817. debug_print_ref(imemory, iosp);
  818. }
  819. dputc('\n');
  820. osp = save_osp;
  821. esp = save_esp;
  822. fflush(dstderr);
  823. }
  824. #endif
  825. /* Objects that have attributes (arrays, dictionaries, files, and strings) */
  826. /* use lit and exec; other objects use plain and plain_exec. */
  827. #define lit(t) type_xe_value(t, a_execute)
  828. #define exec(t) type_xe_value(t, a_execute + a_executable)
  829. #define nox(t) type_xe_value(t, 0)
  830. #define nox_exec(t) type_xe_value(t, a_executable)
  831. #define plain(t) type_xe_value(t, 0)
  832. #define plain_exec(t) type_xe_value(t, a_executable)
  833. /*
  834. * We have to populate enough cases of the switch statement to force
  835. * some compilers to use a dispatch rather than a testing loop.
  836. * What a nuisance!
  837. */
  838. switch (r_type_xe(iref_packed)) {
  839. /* Access errors. */
  840. #define cases_invalid()\
  841. case plain(t__invalid): case plain_exec(t__invalid)
  842. cases_invalid():
  843. return_with_error_iref(e_Fatal);
  844. #define cases_nox()\
  845. case nox_exec(t_array): case nox_exec(t_dictionary):\
  846. case nox_exec(t_file): case nox_exec(t_string):\
  847. case nox_exec(t_mixedarray): case nox_exec(t_shortarray)
  848. cases_nox():
  849. return_with_error_iref(e_invalidaccess);
  850. /*
  851. * Literal objects. We have to enumerate all the types.
  852. * In fact, we have to include some extra plain_exec entries
  853. * just to populate the switch. We break them up into groups
  854. * to avoid overflowing some preprocessors.
  855. */
  856. #define cases_lit_1()\
  857. case lit(t_array): case nox(t_array):\
  858. case plain(t_boolean): case plain_exec(t_boolean):\
  859. case lit(t_dictionary): case nox(t_dictionary)
  860. #define cases_lit_2()\
  861. case lit(t_file): case nox(t_file):\
  862. case plain(t_fontID): case plain_exec(t_fontID):\
  863. case plain(t_integer): case plain_exec(t_integer):\
  864. case plain(t_mark): case plain_exec(t_mark)
  865. #define cases_lit_3()\
  866. case plain(t_name):\
  867. case plain(t_null):\
  868. case plain(t_oparray):\
  869. case plain(t_operator)
  870. #define cases_lit_4()\
  871. case plain(t_real): case plain_exec(t_real):\
  872. case plain(t_save): case plain_exec(t_save):\
  873. case lit(t_string): case nox(t_string)
  874. #define cases_lit_5()\
  875. case lit(t_mixedarray): case nox(t_mixedarray):\
  876. case lit(t_shortarray): case nox(t_shortarray):\
  877. case plain(t_device): case plain_exec(t_device):\
  878. case plain(t_struct): case plain_exec(t_struct):\
  879. case plain(t_astruct): case plain_exec(t_astruct)
  880. /* Executable arrays are treated as literals in direct execution. */
  881. #define cases_lit_array()\
  882. case exec(t_array): case exec(t_mixedarray): case exec(t_shortarray)
  883. cases_lit_1():
  884. cases_lit_2():
  885. cases_lit_3():
  886. cases_lit_4():
  887. cases_lit_5():
  888. INCR(lit);
  889. break;
  890. cases_lit_array():
  891. INCR(lit_array);
  892. break;
  893. /* Special operators. */
  894. case plain_exec(tx_op_add):
  895. x_add: INCR(x_add);
  896. if ((code = zop_add(iosp)) < 0)
  897. return_with_error_code_op(2);
  898. iosp--;
  899. next_either();
  900. case plain_exec(tx_op_def):
  901. x_def: INCR(x_def);
  902. osp = iosp; /* sync o_stack */
  903. if ((code = zop_def(i_ctx_p)) < 0)
  904. return_with_error_code_op(2);
  905. iosp -= 2;
  906. next_either();
  907. case plain_exec(tx_op_dup):
  908. x_dup: INCR(x_dup);
  909. if (iosp < osbot)
  910. return_with_error_iref(e_stackunderflow);
  911. if (iosp >= ostop)
  912. return_with_stackoverflow_iref();
  913. iosp++;
  914. ref_assign_inline(iosp, iosp - 1);
  915. next_either();
  916. case plain_exec(tx_op_exch):
  917. x_exch: INCR(x_exch);
  918. if (iosp <= osbot)
  919. return_with_error_iref(e_stackunderflow);
  920. ref_assign_inline(&token, iosp);
  921. ref_assign_inline(iosp, iosp - 1);
  922. ref_assign_inline(iosp - 1, &token);
  923. next_either();
  924. case plain_exec(tx_op_if):
  925. x_if: INCR(x_if);
  926. if (!r_has_type(iosp - 1, t_boolean))
  927. return_with_error_iref((iosp <= osbot ?
  928. e_stackunderflow : e_typecheck));
  929. if (!r_is_proc(iosp))
  930. return_with_error_iref(check_proc_failed(iosp));
  931. if (!iosp[-1].value.boolval) {
  932. iosp -= 2;
  933. next_either();
  934. }
  935. if (iesp >= estop)
  936. return_with_error_iref(e_execstackoverflow);
  937. store_state_either(iesp);
  938. whichp = iosp;
  939. iosp -= 2;
  940. goto ifup;
  941. case plain_exec(tx_op_ifelse):
  942. x_ifelse: INCR(x_ifelse);
  943. if (!r_has_type(iosp - 2, t_boolean))
  944. return_with_error_iref((iosp < osbot + 2 ?
  945. e_stackunderflow : e_typecheck));
  946. if (!r_is_proc(iosp - 1))
  947. return_with_error_iref(check_proc_failed(iosp - 1));
  948. if (!r_is_proc(iosp))
  949. return_with_error_iref(check_proc_failed(iosp));
  950. if (iesp >= estop)
  951. return_with_error_iref(e_execstackoverflow);
  952. store_state_either(iesp);
  953. whichp = (iosp[-2].value.boolval ? iosp - 1 : iosp);
  954. iosp -= 3;
  955. /* Open code "up" for the array case(s) */
  956. ifup:if ((icount = r_size(whichp) - 1) <= 0) {
  957. if (icount < 0)
  958. goto up; /* 0-element proc */
  959. SET_IREF(whichp->value.refs); /* 1-element proc */
  960. if (--ticks_left > 0)
  961. goto top;
  962. }
  963. ++iesp;
  964. /* Do a ref_assign, but also set iref. */
  965. iesp->tas = whichp->tas;
  966. SET_IREF(iesp->value.refs = whichp->value.refs);
  967. if (--ticks_left > 0)
  968. goto top;
  969. goto slice;
  970. case plain_exec(tx_op_index):
  971. x_index: INCR(x_index);
  972. osp = iosp; /* zindex references o_stack */
  973. if ((code = zindex(i_ctx_p)) < 0)
  974. return_with_error_code_op(1);
  975. next_either();
  976. case plain_exec(tx_op_pop):
  977. x_pop: INCR(x_pop);
  978. if (iosp < osbot)
  979. return_with_error_iref(e_stackunderflow);
  980. iosp--;
  981. next_either();
  982. case plain_exec(tx_op_roll):
  983. x_roll: INCR(x_roll);
  984. osp = iosp; /* zroll references o_stack */
  985. if ((code = zroll(i_ctx_p)) < 0)
  986. return_with_error_code_op(2);
  987. iosp -= 2;
  988. next_either();
  989. case plain_exec(tx_op_sub):
  990. x_sub: INCR(x_sub);
  991. if ((code = zop_sub(iosp)) < 0)
  992. return_with_error_code_op(2);
  993. iosp--;
  994. next_either();
  995. /* Executable types. */
  996. case plain_exec(t_null):
  997. goto bot;
  998. case plain_exec(t_oparray):
  999. /* Replace with the definition and go again. */
  1000. INCR(exec_array);
  1001. pvalue = IREF->value.const_refs;
  1002. opst: /* Prepare to call a t_oparray procedure in *pvalue. */
  1003. store_state(iesp);
  1004. oppr: /* Record the stack depths in case of failure. */
  1005. if (iesp >= estop - 3)
  1006. return_with_error_iref(e_execstackoverflow);
  1007. iesp += 4;
  1008. osp = iosp; /* ref_stack_count_inline needs this */
  1009. make_mark_estack(iesp - 3, es_other, oparray_cleanup);
  1010. make_int(iesp - 2, ref_stack_count_inline(&o_stack));
  1011. make_int(iesp - 1, ref_stack_count_inline(&d_stack));
  1012. make_op_estack(iesp, oparray_pop);
  1013. goto pr;
  1014. prst: /* Prepare to call the procedure (array) in *pvalue. */
  1015. store_state(iesp);
  1016. pr: /* Call the array in *pvalue. State has been stored. */
  1017. if ((icount = r_size(pvalue) - 1) <= 0) {
  1018. if (icount < 0)
  1019. goto up; /* 0-element proc */
  1020. SET_IREF(pvalue->value.refs); /* 1-element proc */
  1021. if (--ticks_left > 0)
  1022. goto top;
  1023. }
  1024. if (iesp >= estop)
  1025. return_with_error_iref(e_execstackoverflow);
  1026. ++iesp;
  1027. /* Do a ref_assign, but also set iref. */
  1028. iesp->tas = pvalue->tas;
  1029. SET_IREF(iesp->value.refs = pvalue->value.refs);
  1030. if (--ticks_left > 0)
  1031. goto top;
  1032. goto slice;
  1033. case plain_exec(t_operator):
  1034. INCR(exec_operator);
  1035. if (--ticks_left <= 0) { /* The following doesn't work, */
  1036. /* and I can't figure out why. */
  1037. /****** goto sst; ******/
  1038. }
  1039. esp = iesp; /* save for operator */
  1040. osp = iosp; /* ditto */
  1041. /* Operator routines take osp as an argument. */
  1042. /* This is just a convenience, since they adjust */
  1043. /* osp themselves to reflect the results. */
  1044. /* Operators that (net) push information on the */
  1045. /* operand stack must check for overflow: */
  1046. /* this normally happens automatically through */
  1047. /* the push macro (in oper.h). */
  1048. /* Operators that do not typecheck their operands, */
  1049. /* or take a variable number of arguments, */
  1050. /* must check explicitly for stack underflow. */
  1051. /* (See oper.h for more detail.) */
  1052. /* Note that each case must set iosp = osp: */
  1053. /* this is so we can switch on code without having to */
  1054. /* store it and reload it (for dumb compilers). */
  1055. switch (code = call_operator(real_opproc(IREF), i_ctx_p)) {
  1056. case 0: /* normal case */
  1057. case 1: /* alternative success case */
  1058. iosp = osp;
  1059. next();
  1060. case o_push_estack: /* store the state and go to up */
  1061. store_state(iesp);
  1062. opush:iosp = osp;
  1063. iesp = esp;
  1064. if (--ticks_left > 0)
  1065. goto up;
  1066. goto slice;
  1067. case o_pop_estack: /* just go to up */
  1068. opop:iosp = osp;
  1069. if (esp == iesp)
  1070. goto bot;
  1071. iesp = esp;
  1072. goto up;
  1073. case o_reschedule:
  1074. store_state(iesp);
  1075. goto res;
  1076. case e_RemapColor:
  1077. oe_remap: store_state(iesp);
  1078. remap: if (iesp + 2 >= estop) {
  1079. esp = iesp;
  1080. code = ref_stack_extend(&e_stack, 2);
  1081. if (code < 0)
  1082. return_with_error_iref(code);
  1083. iesp = esp;
  1084. }
  1085. packed_get(imemory, iref_packed, iesp + 1);
  1086. make_oper(iesp + 2, 0,
  1087. r_ptr(&istate->remap_color_info,
  1088. int_remap_color_info_t)->proc);
  1089. iesp += 2;
  1090. goto up;
  1091. }
  1092. iosp = osp;
  1093. iesp = esp;
  1094. return_with_code_iref();
  1095. case plain_exec(t_name):
  1096. INCR(exec_name);
  1097. pvalue = IREF->value.pname->pvalue;
  1098. if (!pv_valid(pvalue)) {
  1099. uint nidx = names_index(int_nt, IREF);
  1100. uint htemp;
  1101. INCR(find_name);
  1102. if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0)
  1103. return_with_error_iref(e_undefined);
  1104. }
  1105. /* Dispatch on the type of the value. */
  1106. /* Again, we have to over-populate the switch. */
  1107. switch (r_type_xe(pvalue)) {
  1108. cases_invalid():
  1109. return_with_error_iref(e_Fatal);
  1110. cases_nox(): /* access errors */
  1111. return_with_error_iref(e_invalidaccess);
  1112. cases_lit_1():
  1113. cases_lit_2():
  1114. cases_lit_3():
  1115. cases_lit_4():
  1116. cases_lit_5():
  1117. INCR(name_lit);
  1118. /* Just push the value */
  1119. if (iosp >= ostop)
  1120. return_with_stackoverflow(pvalue);
  1121. ++iosp;
  1122. ref_assign_inline(iosp, pvalue);
  1123. next();
  1124. case exec(t_array):
  1125. case exec(t_mixedarray):
  1126. case exec(t_shortarray):
  1127. INCR(name_proc);
  1128. /* This is an executable procedure, execute it. */
  1129. goto prst;
  1130. case plain_exec(tx_op_add):
  1131. goto x_add;
  1132. case plain_exec(tx_op_def):
  1133. goto x_def;
  1134. case plain_exec(tx_op_dup):
  1135. goto x_dup;
  1136. case plain_exec(tx_op_exch):
  1137. goto x_exch;
  1138. case plain_exec(tx_op_if):
  1139. goto x_if;
  1140. case plain_exec(tx_op_ifelse):
  1141. goto x_ifelse;
  1142. case plain_exec(tx_op_index):
  1143. goto x_index;
  1144. case plain_exec(tx_op_pop):
  1145. goto x_pop;
  1146. case plain_exec(tx_op_roll):
  1147. goto x_roll;
  1148. case plain_exec(tx_op_sub):
  1149. goto x_sub;
  1150. case plain_exec(t_null):
  1151. goto bot;
  1152. case plain_exec(t_oparray):
  1153. INCR(name_oparray);
  1154. pvalue = (const ref *)pvalue->value.const_refs;
  1155. goto opst;
  1156. case plain_exec(t_operator):
  1157. INCR(name_operator);
  1158. { /* Shortcut for operators. */
  1159. /* See above for the logic. */
  1160. if (--ticks_left <= 0) { /* The following doesn't work, */
  1161. /* and I can't figure out why. */
  1162. /****** goto sst; ******/
  1163. }
  1164. esp = iesp;
  1165. osp = iosp;
  1166. switch (code = call_operator(real_opproc(pvalue),
  1167. i_ctx_p)
  1168. ) {
  1169. case 0: /* normal case */
  1170. case 1: /* alternative success case */
  1171. iosp = osp;
  1172. next();
  1173. case o_push_estack:
  1174. store_state(iesp);
  1175. goto opush;
  1176. case o_pop_estack:
  1177. goto opop;
  1178. case o_reschedule:
  1179. store_state(iesp);
  1180. goto res;
  1181. case e_RemapColor:
  1182. goto oe_remap;
  1183. }
  1184. iosp = osp;
  1185. iesp = esp;
  1186. return_with_error(code, pvalue);
  1187. }
  1188. case plain_exec(t_name):
  1189. case exec(t_file):
  1190. case exec(t_string):
  1191. default:
  1192. /* Not a procedure, reinterpret it. */
  1193. store_state(iesp);
  1194. icount = 0;
  1195. SET_IREF(pvalue);
  1196. goto top;
  1197. }
  1198. case exec(t_file):
  1199. { /* Executable file. Read the next token and interpret it. */
  1200. stream *s;
  1201. scanner_state sstate;
  1202. check_read_known_file(s, IREF, return_with_error_iref);
  1203. rt:
  1204. if (iosp >= ostop) /* check early */
  1205. return_with_stackoverflow_iref();
  1206. osp = iosp; /* scan_token uses ostack */
  1207. scanner_state_init_options(&sstate, i_ctx_p->scanner_options);
  1208. again:
  1209. code = scan_token(i_ctx_p, s, &token, &sstate);
  1210. iosp = osp; /* ditto */
  1211. switch (code) {
  1212. case 0: /* read a token */
  1213. /* It's worth checking for literals, which make up */
  1214. /* the majority of input tokens, before storing the */
  1215. /* state on the e-stack. Note that because of //, */
  1216. /* the token may have *any* type and attributes. */
  1217. /* Note also that executable arrays aren't executed */
  1218. /* at the top level -- they're treated as literals. */
  1219. if (!r_has_attr(&token, a_executable) ||
  1220. r_is_array(&token)
  1221. ) { /* If scan_token used the o-stack, */
  1222. /* we know we can do a push now; if not, */
  1223. /* the pre-check is still valid. */
  1224. iosp++;
  1225. ref_assign_inline(iosp, &token);
  1226. goto rt;
  1227. }
  1228. store_state(iesp);
  1229. /* Push the file on the e-stack */
  1230. if (iesp >= estop)
  1231. return_with_error_iref(e_execstackoverflow);
  1232. esfile_set_cache(++iesp);
  1233. ref_assign_inline(iesp, IREF);
  1234. SET_IREF(&token);
  1235. icount = 0;
  1236. goto top;
  1237. case e_undefined: /* //name undefined */
  1238. return_with_error(code, &token);
  1239. case scan_EOF: /* end of file */
  1240. esfile_clear_cache();
  1241. goto bot;
  1242. case scan_BOS:
  1243. /* Binary object sequences */
  1244. /* ARE executed at the top level. */
  1245. store_state(iesp);
  1246. /* Push the file on the e-stack */
  1247. if (iesp >= estop)
  1248. return_with_error_iref(e_execstackoverflow);
  1249. esfile_set_cache(++iesp);
  1250. ref_assign_inline(iesp, IREF);
  1251. pvalue = &token;
  1252. goto pr;
  1253. case scan_Refill:
  1254. store_state(iesp);
  1255. /* iref may point into the exec stack; */
  1256. /* save its referent now. */
  1257. ref_assign_inline(&token, IREF);
  1258. /* Push the file on the e-stack */
  1259. if (iesp >= estop)
  1260. return_with_error_iref(e_execstackoverflow);
  1261. ++iesp;
  1262. ref_assign_inline(iesp, &token);
  1263. esp = iesp;
  1264. osp = iosp;
  1265. code = scan_handle_refill(i_ctx_p, &token, &sstate,
  1266. true, true,
  1267. ztokenexec_continue);
  1268. scan_cont:
  1269. iosp = osp;
  1270. iesp = esp;
  1271. switch (code) {
  1272. case 0:
  1273. iesp--; /* don't push the file */
  1274. goto again; /* stacks are unchanged */
  1275. case o_push_estack:
  1276. esfile_clear_cache();
  1277. if (--ticks_left > 0)
  1278. goto up;
  1279. goto slice;
  1280. }
  1281. /* must be an error */
  1282. iesp--; /* don't push the file */
  1283. return_with_code_iref();
  1284. case scan_Comment:
  1285. case scan_DSC_Comment: {
  1286. /* See scan_Refill above for comments. */
  1287. ref file_token;
  1288. store_state(iesp);
  1289. ref_assign_inline(&file_token, IREF);
  1290. if (iesp >= estop)
  1291. return_with_error_iref(e_execstackoverflow);
  1292. ++iesp;
  1293. ref_assign_inline(iesp, &file_token);
  1294. esp = iesp;
  1295. osp = iosp;
  1296. code = ztoken_handle_comment(i_ctx_p, &file_token,
  1297. &sstate, &token,
  1298. code, true, true,
  1299. ztokenexec_continue);
  1300. }
  1301. goto scan_cont;
  1302. default: /* error */
  1303. return_with_code_iref();
  1304. }
  1305. }
  1306. case exec(t_string):
  1307. { /* Executable string. Read a token and interpret it. */
  1308. stream ss;
  1309. scanner_state sstate;
  1310. scanner_state_init_options(&sstate, SCAN_FROM_STRING);
  1311. s_init(&ss, NULL);
  1312. sread_string(&ss, IREF->value.bytes, r_size(IREF));
  1313. osp = iosp; /* scan_token uses ostack */
  1314. code = scan_token(i_ctx_p, &ss, &token, &sstate);
  1315. iosp = osp; /* ditto */
  1316. switch (code) {
  1317. case 0: /* read a token */
  1318. case scan_BOS: /* binary object sequence */
  1319. store_state(iesp);
  1320. /* If the updated string isn't empty, push it back */
  1321. /* on the e-stack. */
  1322. {
  1323. uint size = sbufavailable(&ss);
  1324. if (size) {
  1325. if (iesp >= estop)
  1326. return_with_error_iref(e_execstackoverflow);
  1327. ++iesp;
  1328. iesp->tas.type_attrs = IREF->tas.type_attrs;
  1329. iesp->value.const_bytes = sbufptr(&ss);
  1330. r_set_size(iesp, size);
  1331. }
  1332. }
  1333. if (code == 0) {
  1334. SET_IREF(&token);
  1335. icount = 0;
  1336. goto top;
  1337. }
  1338. /* Handle BOS specially */
  1339. pvalue = &token;
  1340. goto pr;
  1341. case scan_EOF: /* end of string */
  1342. goto bot;
  1343. case scan_Refill: /* error */
  1344. code = gs_note_error(e_syntaxerror);
  1345. default: /* error */
  1346. return_with_code_iref();
  1347. }
  1348. }
  1349. /* Handle packed arrays here by re-dispatching. */
  1350. /* This also picks up some anomalous cases of non-packed arrays. */
  1351. default:
  1352. {
  1353. uint index;
  1354. switch (*iref_packed >> r_packed_type_shift) {
  1355. case pt_full_ref:
  1356. case pt_full_ref + 1:
  1357. INCR(p_full);
  1358. if (iosp >= ostop)
  1359. return_with_stackoverflow_iref();
  1360. /* We know this can't be an executable object */
  1361. /* requiring special handling, so we just push it. */
  1362. ++iosp;
  1363. /* We know that refs are properly aligned: */
  1364. /* see packed.h for details. */
  1365. ref_assign_inline(iosp, IREF);
  1366. next();
  1367. case pt_executable_operator:
  1368. index = *iref_packed & packed_value_mask;
  1369. if (--ticks_left <= 0) { /* The following doesn't work, */
  1370. /* and I can't figure out why. */
  1371. /****** goto sst_short; ******/
  1372. }
  1373. if (!op_index_is_operator(index)) {
  1374. INCR(p_exec_oparray);
  1375. store_state_short(iesp);
  1376. /* Call the operator procedure. */
  1377. index -= op_def_count;
  1378. pvalue = (const ref *)
  1379. (index < r_size(&op_array_table_global.table) ?
  1380. op_array_table_global.table.value.const_refs +
  1381. index :
  1382. op_array_table_local.table.value.const_refs +
  1383. (index - r_size(&op_array_table_global.table)));
  1384. goto oppr;
  1385. }
  1386. INCR(p_exec_operator);
  1387. /* See the main plain_exec(t_operator) case */
  1388. /* for details of what happens here. */
  1389. #if PACKED_SPECIAL_OPS
  1390. /*
  1391. * We arranged in iinit.c that the special ops
  1392. * have operator indices starting at 1.
  1393. *
  1394. * The (int) cast in the next line is required
  1395. * because some compilers don't allow arithmetic
  1396. * involving two different enumerated types.
  1397. */
  1398. # define case_xop(xop) case xop - (int)tx_op + 1
  1399. switch (index) {
  1400. case_xop(tx_op_add):goto x_add;
  1401. case_xop(tx_op_def):goto x_def;
  1402. case_xop(tx_op_dup):goto x_dup;
  1403. case_xop(tx_op_exch):goto x_exch;
  1404. case_xop(tx_op_if):goto x_if;
  1405. case_xop(tx_op_ifelse):goto x_ifelse;
  1406. case_xop(tx_op_index):goto x_index;
  1407. case_xop(tx_op_pop):goto x_pop;
  1408. case_xop(tx_op_roll):goto x_roll;
  1409. case_xop(tx_op_sub):goto x_sub;
  1410. case 0: /* for dumb compilers */
  1411. default:
  1412. ;
  1413. }
  1414. # undef case_xop
  1415. #endif
  1416. INCR(p_exec_non_x_operator);
  1417. esp = iesp;
  1418. osp = iosp;
  1419. switch (code = call_operator(op_index_proc(index), i_ctx_p)) {
  1420. case 0:
  1421. case 1:
  1422. iosp = osp;
  1423. next_short();
  1424. case o_push_estack:
  1425. store_state_short(iesp);
  1426. goto opush;
  1427. case o_pop_estack:
  1428. iosp = osp;
  1429. if (esp == iesp) {
  1430. next_short();
  1431. }
  1432. iesp = esp;
  1433. goto up;
  1434. case o_reschedule:
  1435. store_state_short(iesp);
  1436. goto res;
  1437. case e_RemapColor:
  1438. store_state_short(iesp);
  1439. goto remap;
  1440. }
  1441. iosp = osp;
  1442. iesp = esp;
  1443. return_with_code_iref();
  1444. case pt_integer:
  1445. INCR(p_integer);
  1446. if (iosp >= ostop)
  1447. return_with_stackoverflow_iref();
  1448. ++iosp;
  1449. make_int(iosp,
  1450. ((int)*iref_packed & packed_int_mask) +
  1451. packed_min_intval);
  1452. next_short();
  1453. case pt_literal_name:
  1454. INCR(p_lit_name);
  1455. {
  1456. uint nidx = *iref_packed & packed_value_mask;
  1457. if (iosp >= ostop)
  1458. return_with_stackoverflow_iref();
  1459. ++iosp;
  1460. name_index_ref_inline(int_nt, nidx, iosp);
  1461. next_short();
  1462. }
  1463. case pt_executable_name:
  1464. INCR(p_exec_name);
  1465. {
  1466. uint nidx = *iref_packed & packed_value_mask;
  1467. pvalue = name_index_ptr_inline(int_nt, nidx)->pvalue;
  1468. if (!pv_valid(pvalue)) {
  1469. uint htemp;
  1470. INCR(p_find_name);
  1471. if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0) {
  1472. names_index_ref(int_nt, nidx, &token);
  1473. return_with_error(e_undefined, &token);
  1474. }
  1475. }
  1476. if (r_has_masked_attrs(pvalue, a_execute, a_execute + a_executable)) { /* Literal, push it. */
  1477. INCR(p_name_lit);
  1478. if (iosp >= ostop)
  1479. return_with_stackoverflow_iref();
  1480. ++iosp;
  1481. ref_assign_inline(iosp, pvalue);
  1482. next_short();
  1483. }
  1484. if (r_is_proc(pvalue)) { /* This is an executable procedure, */
  1485. /* execute it. */
  1486. INCR(p_name_proc);
  1487. store_state_short(iesp);
  1488. goto pr;
  1489. }
  1490. /* Not a literal or procedure, reinterpret it. */
  1491. store_state_short(iesp);
  1492. icount = 0;
  1493. SET_IREF(pvalue);
  1494. goto top;
  1495. }
  1496. /* default can't happen here */
  1497. }
  1498. }
  1499. }
  1500. /* Literal type, just push it. */
  1501. if (iosp >= ostop)
  1502. return_with_stackoverflow_iref();
  1503. ++iosp;
  1504. ref_assign_inline(iosp, IREF);
  1505. bot:next();
  1506. out: /* At most 1 more token in the current procedure. */
  1507. /* (We already decremented icount.) */
  1508. if (!icount) {
  1509. /* Pop the execution stack for tail recursion. */
  1510. iesp--;
  1511. iref_packed = IREF_NEXT(iref_packed);
  1512. goto top;
  1513. }
  1514. up:if (--ticks_left < 0)
  1515. goto slice;
  1516. /* See if there is anything left on the execution stack. */
  1517. if (!r_is_proc(iesp)) {
  1518. SET_IREF(iesp--);
  1519. icount = 0;
  1520. goto top;
  1521. }
  1522. SET_IREF(iesp->value.refs); /* next element of array */
  1523. icount = r_size(iesp) - 1;
  1524. if (icount <= 0) { /* <= 1 more elements */
  1525. iesp--; /* pop, or tail recursion */
  1526. if (icount < 0)
  1527. goto up;
  1528. }
  1529. goto top;
  1530. res:
  1531. /* Some operator has asked for context rescheduling. */
  1532. /* We've done a store_state. */
  1533. *pi_ctx_p = i_ctx_p;
  1534. code = (*gs_interp_reschedule_proc)(pi_ctx_p);
  1535. i_ctx_p = *pi_ctx_p;
  1536. sched: /* We've just called a scheduling procedure. */
  1537. /* The interpreter state is in memory; iref is not current. */
  1538. if (code < 0) {
  1539. set_error(code);
  1540. /*
  1541. * We need a real object to return as the error object.
  1542. * (It only has to last long enough to store in
  1543. * *perror_object.)
  1544. */
  1545. make_null_proc(&ierror.full);
  1546. SET_IREF(ierror.obj = &ierror.full);
  1547. goto error_exit;
  1548. }
  1549. /* Reload state information from memory. */
  1550. iosp = osp;
  1551. iesp = esp;
  1552. goto up;
  1553. #if 0 /****** ****** ***** */
  1554. sst: /* Time-slice, but push the current object first. */
  1555. store_state(iesp);
  1556. if (iesp >= estop)
  1557. return_with_error_iref(e_execstackoverflow);
  1558. iesp++;
  1559. ref_assign_inline(iesp, iref);
  1560. #endif /****** ****** ***** */
  1561. slice: /* It's time to time-slice or garbage collect. */
  1562. /* iref is not live, so we don't need to do a store_state. */
  1563. osp = iosp;
  1564. esp = iesp;
  1565. /* If ticks_left <= -100, we need to GC now. */
  1566. if (ticks_left <= -100) { /* We need to garbage collect now. */
  1567. *pi_ctx_p = i_ctx_p;
  1568. code = interp_reclaim(pi_ctx_p, -1);
  1569. i_ctx_p = *pi_ctx_p;
  1570. } else if (gs_interp_time_slice_proc) {
  1571. *pi_ctx_p = i_ctx_p;
  1572. code = (*gs_interp_time_slice_proc)(pi_ctx_p);
  1573. i_ctx_p = *pi_ctx_p;
  1574. } else
  1575. code = 0;
  1576. ticks_left = gs_interp_time_slice_ticks;
  1577. set_code_on_interrupt(imemory, &code);
  1578. goto sched;
  1579. /* Error exits. */
  1580. rweci:
  1581. ierror.code = code;
  1582. rwei:
  1583. ierror.obj = IREF;
  1584. rwe:
  1585. if (!r_is_packed(iref_packed))
  1586. store_state(iesp);
  1587. else {
  1588. /*
  1589. * We need a real object to return as the error object.
  1590. * (It only has to last long enough to store in *perror_object.)
  1591. */
  1592. packed_get(imemory, (const ref_packed *)ierror.obj, &ierror.full);
  1593. store_state_short(iesp);
  1594. if (IREF == ierror.obj)
  1595. SET_IREF(&ierror.full);
  1596. ierror.obj = &ierror.full;
  1597. }
  1598. error_exit:
  1599. if (ERROR_IS_INTERRUPT(ierror.code)) { /* We must push the current object being interpreted */
  1600. /* back on the e-stack so it will be re-executed. */
  1601. /* Currently, this is always an executable operator, */
  1602. /* but it might be something else someday if we check */
  1603. /* for interrupts in the interpreter loop itself. */
  1604. if (iesp >= estop)
  1605. code = e_execstackoverflow;
  1606. else {
  1607. iesp++;
  1608. ref_assign_inline(iesp, IREF);
  1609. }
  1610. }
  1611. esp = iesp;
  1612. osp = iosp;
  1613. ref_assign_inline(perror_object, ierror.obj);
  1614. return gs_log_error(ierror.code, __FILE__, ierror.line);
  1615. }
  1616. /* Pop the bookkeeping information for a normal exit from a t_oparray. */
  1617. private int
  1618. oparray_pop(i_ctx_t *i_ctx_p)
  1619. {
  1620. esp -= 3;
  1621. return o_pop_estack;
  1622. }
  1623. /* Restore the stack pointers after an error inside a t_oparray procedure. */
  1624. /* This procedure is called only from pop_estack. */
  1625. private int
  1626. oparray_cleanup(i_ctx_t *i_ctx_p)
  1627. { /* esp points just below the cleanup procedure. */
  1628. es_ptr ep = esp;
  1629. uint ocount_old = (uint) ep[2].value.intval;
  1630. uint dcount_old = (uint) ep[3].value.intval;
  1631. uint ocount = ref_stack_count(&o_stack);
  1632. uint dcount = ref_stack_count(&d_stack);
  1633. if (ocount > ocount_old)
  1634. ref_stack_pop(&o_stack, ocount - ocount_old);
  1635. if (dcount > dcount_old) {
  1636. ref_stack_pop(&d_stack, dcount - dcount_old);
  1637. dict_set_top();
  1638. }
  1639. return 0;
  1640. }
  1641. /* Don't restore the stack pointers. */
  1642. private int
  1643. oparray_no_cleanup(i_ctx_t *i_ctx_p)
  1644. {
  1645. return 0;
  1646. }
  1647. /* Find the innermost oparray. */
  1648. private ref *
  1649. oparray_find(i_ctx_t *i_ctx_p)
  1650. {
  1651. long i;
  1652. ref *ep;
  1653. for (i = 0; (ep = ref_stack_index(&e_stack, i)) != 0; ++i) {
  1654. if (r_is_estack_mark(ep) &&
  1655. (ep->value.opproc == oparray_cleanup ||
  1656. ep->value.opproc == oparray_no_cleanup)
  1657. )
  1658. return ep;
  1659. }
  1660. return 0;
  1661. }
  1662. /* <bool> .setstackprotect - */
  1663. /* Set whether to protect the stack for the innermost oparray. */
  1664. private int
  1665. zsetstackprotect(i_ctx_t *i_ctx_p)
  1666. {
  1667. os_ptr op = osp;
  1668. ref *ep = oparray_find(i_ctx_p);
  1669. check_type(*op, t_boolean);
  1670. if (ep == 0)
  1671. return_error(e_rangecheck);
  1672. ep->value.opproc =
  1673. (op->value.boolval ? oparray_cleanup : oparray_no_cleanup);
  1674. pop(1);
  1675. return 0;
  1676. }
  1677. /* - .currentstackprotect <bool> */
  1678. /* Return the stack protection status. */
  1679. private int
  1680. zcurrentstackprotect(i_ctx_t *i_ctx_p)
  1681. {
  1682. os_ptr op = osp;
  1683. ref *ep = oparray_find(i_ctx_p);
  1684. if (ep == 0)
  1685. return_error(e_rangecheck);
  1686. push(1);
  1687. make_bool(op, ep->value.opproc == oparray_cleanup);
  1688. return 0;
  1689. }