Groups | Search | Server Info | Login | Register


Groups > comp.lang.postscript > #4013

Stack Management In GXScript

From Lawrence D'Oliveiro <ldo@nz.invalid>
Newsgroups comp.lang.postscript
Subject Stack Management In GXScript
Date 2024-12-30 04:49 +0000
Organization A noiseless patient Spider
Message-ID <vkt8p3$1fes1$1@dont-email.me> (permalink)

Show all headers | View raw


Programming in stack-based languages is notoriously error-prone: it is way 
too easy to lose track of where an operand on the stack came from, and 
leave too many or too few operands for an operation.

GXScript <https://bitbucket.org/ldo17/gxscript> defines operators “</” 
(which I call “stackbegin”) and “/>” (which I call “stackend”). They are 
used as follows:

    «n» </

where «n» is a non-negative integer, pops «n» operands off the top of the 
current operand stack (obviously it must contain at least that many), and 
puts these on a new operand stack, which becomes the current stack, while 
the previous stack becomes (temporarily) inaccessible, but saved on a 
stack of stacks, as it were.

Correspondingly,

    «n» />

verifies that the current operand stack contains exactly «n» items; it 
pops these off, discards the current operand stack, restores the previous 
one, and pushes those values on.

The stack of stacks allows these </ ... /> sequences to be nested to any 
desired depth.

The “;” operator is quite simple: it asserts that the current operand 
stack is currently empty, raising an error if not.

Simple, even trivial, example:

    /try
      {
        2 </
        add
        1 />
      }
    ddef

    2 3 try = ;

prints

    5

Back to comp.lang.postscript | Previous | NextNext in thread | Find similar


Thread

Stack Management In GXScript Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-12-30 04:49 +0000
  Re: Stack Management In GXScript Buzz McCool <buzz_mccool@yahoo.com> - 2025-01-03 08:53 -0800
    Re: Stack Management In GXScript Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-01-03 21:23 +0000
      Re: Stack Management In GXScript Buzz McCool <buzz_mccool@yahoo.com> - 2025-01-06 08:03 -0800
        Re: Stack Management In GXScript Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-01-06 20:15 +0000

csiph-web