OpenMediaLib User and Development Guide

Stack Manipulations

This is a small deviation for the filter descriptions since it defines a collection of operations which you can carry out on the RPN stack.

These operations are inspired by the standard collection provided by Forth, but deviate somewhat since we aren't quite so constrained when operations occur – since we're creating filter graphs, we can break up the graph on a whim (see Decapitation as an example).

None of these are strictly necessary since they can all be carried out via push and pop operations with the exception of clone and decap since they need to walk through a filter graph (see walk operations below).

Swapping operations:

<input1> <input2> swap == <input2> <input1>
<input1> <input2> <input3> <input4> 2swap == <input3> <input4> <input1> <input2>

Rotations:

<input1> <input2> <input3> rot == <input2> <input3> <input1>

Dropping:

<input1> <input2> drop == <input1>
<input1> <input2> 2drop ==

Duplicating:

<input1> dup == <input1> <input1>

NB: This creates a second reference to the same input – it might not be what you want.

Cloning:

<input1> clone == <input1> <input1'>

NB: dup creates a reference, clone clones the entire input (hence, if you only want the same frame in both eventual uses, use dup – if you want to seek to different parts, use clone).

TODO: Check safety issues related to dup – it might be necessary to recreate the frame objects before updating...

Over:

<input1> <input2> over == <input1> <input2> <input1'>

NB: this invokes clone rather than dup.

Nip:

<input1> <input2> nip == <input2>

Tuck:

<input1> <intput2> tuck == <input1> <input2> <input1'>

Assignment:

<input> blah ! <something> blah == <something> <input>

Decapitation:

<input1> <input2> filter:composite decap == <input1> <input2>

NB: This is, of course, impossible in arithmetic terms (ie: 1 2 + decap is nonsensical – you can't go back from 3 to 1 2), but for our purposes, it is both possible and probably desirable.

Decapitation and Assignment:

<i1> <i2> filter:composite top decap! top == <i1> <i2> filter:composite

Note: this allows insertion of filters before existing filters or editing of complex graphs.

Debug:

<...> debug == <...>

This outputs a 'stack dump' – it shows all the contents of the current stack (equivalent to the Forth's .s word).

Render:

<...> render == <..>

Another debug operation - this 'draws' a graph of the top of stack input.

Clear:

<...> clear ==

Removes everything from the stack. This is a bit of a special case since all nodes are evaluated and returned to the pool.