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: zsysvm.c 9043 2008-08-28 22:48:19Z giles $ */
15 /* System VM and VM-specific operators */
16 #include "ghost.h"
17 #include "oper.h"
18 #include "ialloc.h"
19 #include "ivmspace.h"
20 #include "store.h"		/* for make_bool */
21 
22 /*
23  * These operators allow creation of objects in a specific VM --
24  * local, global, or system.  System VM, which is not a standard PostScript
25  * facility, is not subject to save and restore; objects in system VM
26  * may only refer to simple objects or to other (composite) objects
27  * in system VM.
28  */
29 
30 /* Execute an operator with a specific VM selected as current VM. */
31 static int
specific_vm_op(i_ctx_t * i_ctx_p,op_proc_t opproc,uint space)32 specific_vm_op(i_ctx_t *i_ctx_p, op_proc_t opproc, uint space)
33 {
34     uint save_space = icurrent_space;
35     int code;
36 
37     ialloc_set_space(idmemory, space);
38     code = opproc(i_ctx_p);
39     ialloc_set_space(idmemory, save_space);
40     return code;
41 }
42 
43 /* <int> .globalvmarray <array> */
44 static int
zglobalvmarray(i_ctx_t * i_ctx_p)45 zglobalvmarray(i_ctx_t *i_ctx_p)
46 {
47     return specific_vm_op(i_ctx_p, zarray, avm_global);
48 }
49 
50 /* <int> .globalvmdict <dict> */
51 static int
zglobalvmdict(i_ctx_t * i_ctx_p)52 zglobalvmdict(i_ctx_t *i_ctx_p)
53 {
54     return specific_vm_op(i_ctx_p, zdict, avm_global);
55 }
56 
57 /* <obj_0> ... <obj_n-1> <n> .globalvmpackedarray <packedarray> */
58 static int
zglobalvmpackedarray(i_ctx_t * i_ctx_p)59 zglobalvmpackedarray(i_ctx_t *i_ctx_p)
60 {
61     return specific_vm_op(i_ctx_p, zpackedarray, avm_global);
62 }
63 
64 /* <int> .globalvmstring <string> */
65 static int
zglobalvmstring(i_ctx_t * i_ctx_p)66 zglobalvmstring(i_ctx_t *i_ctx_p)
67 {
68     return specific_vm_op(i_ctx_p, zstring, avm_global);
69 }
70 
71 /* <int> .localvmarray <array> */
72 static int
zlocalvmarray(i_ctx_t * i_ctx_p)73 zlocalvmarray(i_ctx_t *i_ctx_p)
74 {
75     return specific_vm_op(i_ctx_p, zarray, avm_local);
76 }
77 
78 /* <int> .localvmdict <dict> */
79 static int
zlocalvmdict(i_ctx_t * i_ctx_p)80 zlocalvmdict(i_ctx_t *i_ctx_p)
81 {
82     return specific_vm_op(i_ctx_p, zdict, avm_local);
83 }
84 
85 /* <obj_0> ... <obj_n-1> <n> .localvmpackedarray <packedarray> */
86 static int
zlocalvmpackedarray(i_ctx_t * i_ctx_p)87 zlocalvmpackedarray(i_ctx_t *i_ctx_p)
88 {
89     return specific_vm_op(i_ctx_p, zpackedarray, avm_local);
90 }
91 
92 /* <int> .localvmstring <string> */
93 static int
zlocalvmstring(i_ctx_t * i_ctx_p)94 zlocalvmstring(i_ctx_t *i_ctx_p)
95 {
96     return specific_vm_op(i_ctx_p, zstring, avm_local);
97 }
98 
99 /* <int> .systemvmarray <array> */
100 static int
zsystemvmarray(i_ctx_t * i_ctx_p)101 zsystemvmarray(i_ctx_t *i_ctx_p)
102 {
103     return specific_vm_op(i_ctx_p, zarray, avm_system);
104 }
105 
106 /* <int> .systemvmdict <dict> */
107 static int
zsystemvmdict(i_ctx_t * i_ctx_p)108 zsystemvmdict(i_ctx_t *i_ctx_p)
109 {
110     return specific_vm_op(i_ctx_p, zdict, avm_system);
111 }
112 
113 /* <obj_0> ... <obj_n-1> <n> .systemvmpackedarray <packedarray> */
114 static int
zsystemvmpackedarray(i_ctx_t * i_ctx_p)115 zsystemvmpackedarray(i_ctx_t *i_ctx_p)
116 {
117     return specific_vm_op(i_ctx_p, zpackedarray, avm_system);
118 }
119 
120 /* <int> .systemvmstring <string> */
121 static int
zsystemvmstring(i_ctx_t * i_ctx_p)122 zsystemvmstring(i_ctx_t *i_ctx_p)
123 {
124     return specific_vm_op(i_ctx_p, zstring, avm_system);
125 }
126 
127 /* <name_string> <access_string> .systemvmfile <file> */
128 static int
zsystemvmfile(i_ctx_t * i_ctx_p)129 zsystemvmfile(i_ctx_t *i_ctx_p)
130 {
131     return specific_vm_op(i_ctx_p, zfile, avm_system);
132 }
133 
134 /* <string> .systemvmlibfile <file> true */
135 /* <string> .systemvmlibfile <string> false */
136 static int
zsystemvmlibfile(i_ctx_t * i_ctx_p)137 zsystemvmlibfile(i_ctx_t *i_ctx_p)
138 {
139     return specific_vm_op(i_ctx_p, zlibfile, avm_system);
140 }
141 
142 /* <source> <EODcount> <EODstring> .systemvmSFD <file> */
143 /* <source> <dict> <EODcount> <EODstring> .systemvmSFD <file> */
144 /* <source> <dict> .systemvmSFD <file> *//* (LL3 only) */
145 static int
zsystemvmSFD(i_ctx_t * i_ctx_p)146 zsystemvmSFD(i_ctx_t *i_ctx_p)
147 {
148     return specific_vm_op(i_ctx_p, zSFD, avm_system);
149 }
150 
151 /* <any> .systemvmcheck <bool> */
152 static int
zsystemvmcheck(i_ctx_t * i_ctx_p)153 zsystemvmcheck(i_ctx_t *i_ctx_p)
154 {
155     os_ptr op = osp;
156 
157     make_bool(op, (r_space(op) == avm_system ? true : false));
158     return 0;
159 }
160 
161 /* ------ Initialization procedure ------ */
162 
163 const op_def zsysvm_op_defs[] =
164 {
165     {"1.globalvmarray", zglobalvmarray},
166     {"1.globalvmdict", zglobalvmdict},
167     {"1.globalvmpackedarray", zglobalvmpackedarray},
168     {"1.globalvmstring", zglobalvmstring},
169     {"1.localvmarray", zlocalvmarray},
170     {"1.localvmdict", zlocalvmdict},
171     {"1.localvmpackedarray", zlocalvmpackedarray},
172     {"1.localvmstring", zlocalvmstring},
173     {"1.systemvmarray", zsystemvmarray},
174     {"1.systemvmcheck", zsystemvmcheck},
175     {"1.systemvmdict", zsystemvmdict},
176     {"1.systemvmpackedarray", zsystemvmpackedarray},
177     {"1.systemvmstring", zsystemvmstring},
178     {"1.systemvmfile", zsystemvmfile},
179     {"1.systemvmlibfile", zsystemvmlibfile},
180     {"2.systemvmSFD", zsystemvmSFD},
181     op_def_end(0)
182 };
183