[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Jitter: new stack primitive: tuck [

From: Luca Saiu
Subject: Re: Jitter: new stack primitive: tuck [
Date: Thu, 28 Nov 2019 17:32:31 +0100
User-agent: Gnus (Gnus v5.13), GNU Emacs 27.0.50, x86_64-pc-linux-gnu

On 2019-11-25 at 04:50 +0100, Luca Saiu wrote:

> And now another, which you might also like since you juggle a lot with
> stacks.

Speaking of which, you often need to delete elements from a stack below
the top in a way more general than nip.

The instruction is too generic and parametric to completely fit the
style of Forth, but I still find it useful and consistent with Jitter's
idea of stacks.

It is well explained in the comment below.  Patch introducing it in Poke

José, would you like to keep the two arguments in a VM instruction, or
shall I make the instruction version less general?  What you really
need, and what I called "slide" in the notes I sent you a copy of, was
slide 1 2.  But other values of element_no and depth are also useful.

/* Expand to a statement performing a stack change to delete a given number of
   non-top elements at the given depth.
   * The element_no argument is the number of elements to delete.  It must be
   * the depth argument is the depth of the deepest element to delete.  It must
     be strictly positive.
   For good performance both arguments should be known at compile time.
   It is forbidden for this operation to change the top element: the metaphor of
   "sliding" is a landslide where some below-ground strata collapse, which cause
   a displacement of the surface layer down (potentially along with other 
   without changing the surface.
   After the operation is executed the stack will be element_no elements 
   Undefined behavior on:
   * underflow;
   * top element write;
   * any over-the-top element access.
   For example
     slide 1 1
   is equivalent to nip, and has the stack effect
     ( a b -- b )
   .  Then
     slide 2 2
   is equivalent to nip nip, and has the stack effect
     ( a b c -- c )
     slide 1 2
   has the stack effect
     ( b c d -- c d )
   This is a generalization of nip, fast when the arguments are known at compile
   time but potentially dangerous to use because of the possibility of accessing
   the top element or even elements above the top by mistake, which may lead to
   subtly incorrect results. */

Luca Saiu
* My personal web site:  http://ageinghacker.net
* GNU epsilon:           http://www.gnu.org/software/epsilon
* Jitter:                http://ageinghacker.net/projects/jitter

I support everyone's freedom of mocking any opinion or belief, no
matter how deeply held, with open disrespect and the same unrelented
enthusiasm of a toddler who has just learned the word "poo".

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]