Class: PostScript::Runtime
- Inherits:
-
Object
- Object
- PostScript::Runtime
- Includes:
- Operators
- Defined in:
- lib/postscript/runtime.rb
Overview
The Runtime is responsible for evaluating procedures (as arrays output from Parser, or as strings to be parsed) and maintaining the stack.
It responds to all of the supported operators.
Instance Method Summary (collapse)
-
- (Array) eval(function)
Evaluates the provided PostScript function and returns the stack.
-
- (Object) eval_procedure(procedure)
private
Evaluates the result of a parsed PostScript procedure.
-
- (Object) push(*elements)
Pushes the provided operator onto the stack.
-
- (Array) stack
The current stack.
Methods included from Operators::Conditional
Methods included from Operators::Boolean
#and, #eq, #ge, #gt, #le, #lt, #ne, #not, #or, #xor
Methods included from Operators::Arithmetic
#abs, #add, #atan, #bitshift, #ceiling, #cos, #cvi, #cvr, #div, #exp, #floor, #ln, #log, #mod, #mul, #neg, #round, #sin, #sqrt, #sub, #truncate
Methods included from Operators::Stack
#copy, #dup, #exch, #index, #pop, #roll
Instance Method Details
- (Array) eval(function)
Evaluates the provided PostScript function and returns the stack.
48 49 50 51 |
# File 'lib/postscript/runtime.rb', line 48 def eval(function) eval_procedure Parser.parse(function) stack end |
- (Object) eval_procedure(procedure)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates the result of a parsed PostScript procedure.
56 57 58 59 60 61 62 63 64 |
# File 'lib/postscript/runtime.rb', line 56 def eval_procedure(procedure) procedure.each do |operator| if operator.is_a? Symbol send operator else push operator end end end |
- (Object) push(*elements)
Pushes the provided operator onto the stack. This is most useful for setting up the initial state before evaluating a PostScript function.
75 76 77 |
# File 'lib/postscript/runtime.rb', line 75 def push(*elements) stack.push *elements end |
- (Array) stack
The current stack
80 81 82 |
# File 'lib/postscript/runtime.rb', line 80 def stack @stack ||= [] end |