1. exec
Executes an object immediately.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
(varies) |
Results depend on object executed |
1.3. Description
exec pushes the operand on the execution stack, executing it immediately.
The effect depends on the object’s type and literal/executable attribute:
-
Literal objects: Pushed back on operand stack
-
Executable arrays (procedures): Elements executed sequentially
-
Executable names: Looked up and executed
-
Operators: Executed
-
Files/strings: Interpreted as PostScript code
1.5. Examples
(3 2 add) cvx exec % Returns 5
/add cvx exec % Error: stackunderflow (no operands)
3 2 /add cvx exec % Returns 5
{ 1 2 add } exec % Returns 3
/add exec % Pushes /add (literal)
/add cvx exec % Executes add operator
1.6. Common Use Cases
1.7. Common Pitfalls
| Literal Objects Not Executed - Literal objects are just pushed back. |
123 exec % Returns 123 (literal integer)
/name exec % Returns /name (literal name)
{ code } cvlit exec % Returns { code } (literal array)
| Must Use cvx for Strings - Strings must be executable to interpret as code. |
(1 2 add) exec % Pushes string (literal)
(1 2 add) cvx exec % Evaluates: 3
| Security Risk - Executing arbitrary strings can be dangerous. |
userInput cvx exec % Dangerous if userInput malicious!
Check Executable Attribute - Use xcheck to verify before execution.
|
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
No operand on stack |
(various) |
Depends on what is executed |
1.9. Implementation Notes
-
Pushes object onto execution stack
-
Interpreter then processes it normally
-
No special overhead (same as normal execution)
-
Can execute any PostScript object
1.10. Execution Behavior by Type
| Object Type | Literal | Executable |
|---|---|---|
Integer/Real |
Pushed on stack |
Pushed on stack |
Boolean/Null |
Pushed on stack |
Pushed on stack |
String |
Pushed on stack |
Interpreted as code |
Name |
Pushed on stack |
Looked up and executed |
Array |
Pushed on stack |
Elements executed |
Operator |
Pushed on stack |
Executed |
Dictionary |
Pushed on stack |
Pushed on stack |