如何在 PostScript 的过程中处理 "get"

How to handle "get" on a procedure in PostScript

我正在编写一个 postscript 解释器,但不知道应该如何处理以下代码。具体来说,我不知道如何处理在过程(代码块的最后一行)上使用 getget 对程序有效吗?如果是这样,嵌套过程是否被视为一个元素?如果是这样,是否意味着 { pop 0 } 应该添加到堆栈中?

userdict /internaldict 
{
  count 0 eq 
  { /internaldict errordict /invalidaccess get exec }
  if

  dup type /integertype ne 
  { /internaldict errordict /invalidaccess get exec }
  if 

  dup 1183615869 eq 
  { pop 0 }
  { /internaldict errordict /invalidaccess get exec }
  ifelse 
}
dup 14 get 1 25 dict put

感谢您提供的任何说明!

嗯,从根本上说,请阅读第 3 版 PostScript 语言参考手册的第 3.3.6 节,其中(像往常一样)非常清楚地解释了这一点。

A packed array is a more compact representation of an ordinary array, intended primarily for use as a procedure. A packed array object is distinct from an ordinary array object (it has type packedarray instead of array), but in most respects it behaves the same as an ordinary array.

正如文中所说,压缩数组与常规数组几乎没有区别,因此 get 压缩数组的功能与普通数组完全相同。

所以举个具体的例子:

%% procedure to convert PostScript units to inches
%% usage: units inch inches

/inch {
 72 div
} bind def

现在如果我这样做:

/inch load 0 get ==

结果是72,而

/inch load 1 get ==

结果

--div--

对于您发布的代码,'get' 将检索打包数组的第 14 个元素(从 0 开始)。在您的情况下将是:

{pop 0}

适用于数组的所有常用规则,因此数组中的数组是父元素的单个元素。

因为第0个元素是count,第一个元素是0,第二个是eq,第三个是另一个packedarray { /internaldict errordict /invalidaccess get exec }等等

所以是的,您应该在操作数堆栈上以 {pop 0} 结尾。

您知道可以使用 Ghostscript 自己调查此类问题吗?如果出于某种原因您不相信 Ghostscript 是符合标准的 PostScript 解释器,您可以随时使用 PLRM 检查它的行为。