Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3263

Passing data on the exec stack

Newsgroups comp.lang.postscript
Date 2018-05-26 21:24 -0700
Message-ID <5df88191-52f3-491c-bfb2-ec9f5df6acc4@googlegroups.com> (permalink)
Subject Passing data on the exec stack
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


I've been working on a program that has to put its data
structures in global memory. So the way I decided to do
it is to wrap all the functions that serve as entry points
with code that set global allocation mode first and then 
restores the previous mode afterwards. 

So the first draft is to add

  currentglobal true setglobal

at the front and

  setglobal

at the end. But of course that leaves the boolean on
the stack. So we could do roll and/or exch to get it
out of the way and pull it back again later. But I 
wanted to to make this wrapping more transparent than
that.

To get the value off of the stack, I take a subarray
of the procedure body itself and save it there.
In pseudocode it looks like this

  { ARRAY 0 currentglobal put true setglobal ...
      FILL-IN setglobal }

Where the ARRAY token represents the sub-array.

    {FILL-IN}


A simpler application of the same idea has arisen 
before in these threads. If you have a function 
that takes a user-defined proc argument and you
want to execute it without your local dictionary
in the way, then you can do something like this.

/func { % proc
   1 dict begin {proc}{exch def}forall
   % ... local dict available
   [ /proc load /exec cvx currentdict /begin cvx ] cvx
   end exec
   % ... local dict available
   end
} def

Or

/func { % proc
   1 dict begin {proc}{exch def}forall
   /mydict currentdict def
   %
   ({//proc exec //mydict begin}) cvx exec
   end exec
   %
   end
} def

In both of these examples, we call 'end' before executing
the little procedure body which has the dictionary embedded
in it. Thus, passing the dict "on the exec stack".

Back to comp.lang.postscript | Previous | Next | Find similar | Unroll thread


Thread

Passing data on the exec stack luser droog <luser.droog@gmail.com> - 2018-05-26 21:24 -0700

csiph-web