UNPKG

@thi.ng/pointfree

Version:

Pointfree functional composition / Forth style stack execution engine

259 lines 6.02 kB
import type { Stack, StackContext } from "./api.js"; /** * Returns top of stack value (always unsafe, no underflow checking). * * @param stack - */ export declare const tos: (stack: Stack) => any; /** * Utility word w/ no stack nor side effect. */ export declare const nop: (ctx: StackContext) => StackContext; /** * Pushes current d-stack size on d-stack. * * Stack effect: `( -- n )` * * @param ctx - */ export declare const dsp: (ctx: StackContext) => StackContext; /** * Uses TOS as index to look up a deeper d-stack value, then places it * as new TOS. Throws error if stack depth is < `x`. * * Stack effect: `( ... x -- ... stack[x] )` * * @param ctx - */ export declare const pick: (ctx: StackContext) => StackContext; /** * Removes TOS from d-stack. * * Stack effect: `( x -- )` * * @param ctx - */ export declare const drop: (ctx: StackContext) => StackContext; /** * Removes top 2 vals from d-stack. * * Stack effect: `( x y -- )` * * @param ctx - */ export declare const drop2: (ctx: StackContext) => StackContext; /** * If TOS is truthy then drop it: * * Stack effect: `( x -- )` * * Else, no effect: * * Stack effect: `( x -- x )` */ export declare const dropif: (ctx: StackContext) => StackContext; /** * Higher order word. Pushes given args verbatim on d-stack. * * Stack effect: `( -- ...args )` * * @param args - */ export declare const defPush: (...args: any[]) => (ctx: StackContext) => StackContext; /** * Duplicates TOS on d-stack. * * Stack effect: `( x -- x x )` * * @param ctx - */ export declare const dup: (ctx: StackContext) => StackContext; /** * Duplicates top 2 vals on d-stack. * * Stack effect: `( x y -- x y x y )` * * @param ctx - */ export declare const dup2: (ctx: StackContext) => StackContext; /** * Duplicates top 3 vals on d-stack. * * Stack effect: `( x y -- x y x y )` * * @param ctx - */ export declare const dup3: (ctx: StackContext) => StackContext; /** * If TOS is truthy then push copy of it on d-stack: * * Stack effect: `( x -- x x )` * * Else, no effect: * * Stack effect: `( x -- x )` * * @param ctx - */ export declare const dupif: (ctx: StackContext) => StackContext; /** * Swaps the two topmost d-stack items. * * Stack effect: `( x y -- y x )` * * @param ctx - */ export declare const swap: (ctx: StackContext) => StackContext; /** * Swaps the two topmost d-stack pairs. * * Stack effect: `( a b c d -- c d a b )` * * @param ctx - */ export declare const swap2: (ctx: StackContext) => StackContext; /** * Removes second topmost item from d-stack. * * Stack effect: `( x y -- y )` * * @param ctx - */ export declare const nip: (ctx: StackContext) => StackContext; /** * Inserts copy of TOS @ TOS-2 in d-stack. * * Stack effect: `( x y -- y x y )` * * @param ctx - */ export declare const tuck: (ctx: StackContext) => StackContext; /** * Rotates three topmost d-stack items downwards/to the left. * * Stack effect: `( x y z -- y z x )` * * @param ctx - */ export declare const rot: (ctx: StackContext) => StackContext; /** * Rotates three topmost d-stack items upwards/to the right. * * Stack effect: `( x y z -- z x y )` * * @param ctx - */ export declare const invrot: (ctx: StackContext) => StackContext; /** * Pushes copy of TOS-1 as new TOS on d-stack. * * Stack effect: `( x y -- x y x )` * * @param ctx - */ export declare const over: (ctx: StackContext) => StackContext; /** * Stack effect: `( x -- x+1 )` * * @param ctx - */ export declare const inc: (ctx: StackContext) => StackContext; /** * Stack effect: `( x -- x-1 )` * * @param ctx - */ export declare const dec: (ctx: StackContext) => StackContext; /** * Pushes current r-stack size on d-stack. * * Stack effect: `( -- n )` * * @param ctx - */ export declare const rsp: (ctx: StackContext) => StackContext; /** * Duplicates TOS on r-stack. * * Stack effect: `( x -- x x )` * * @param ctx - */ export declare const rdup: (ctx: StackContext) => StackContext; /** * Duplicates top 2 vals on r-stack. * * Stack effect: `( x y -- x y x y )` * * @param ctx - */ export declare const rdup2: (ctx: StackContext) => StackContext; /** * Duplicates top 3 vals on r-stack. * * Stack effect: `( x y -- x y x y )` * * @param ctx - */ export declare const rdup3: (ctx: StackContext) => StackContext; /** * Removes TOS from r-stack. * * Stack effect: `( x -- )` * * @param ctx - */ export declare const rdrop: (ctx: StackContext) => StackContext; /** * Removes top 2 vals from r-stack. * * Stack effect: `( x y -- )` * * @param ctx - */ export declare const rdrop2: (ctx: StackContext) => StackContext; export declare const movdr: (ctx: StackContext) => StackContext; export declare const movrd: (ctx: StackContext) => StackContext; export declare const cpdr: (ctx: StackContext) => StackContext; export declare const cprd: (ctx: StackContext) => StackContext; export declare const movdr2: (ctx: StackContext) => StackContext; export declare const movrd2: (ctx: StackContext) => StackContext; export declare const cpdr2: (ctx: StackContext) => StackContext; export declare const cprd2: (ctx: StackContext) => StackContext; /** * Swaps the two topmost r-stack items. * * Stack effect: `( x y -- y x )` * * @param ctx - */ export declare const rswap: (ctx: StackContext) => StackContext; /** * Swaps the two topmost d-stack pairs. * * Stack effect: `( a b c d -- c d a b )` * * @param ctx - */ export declare const rswap2: (ctx: StackContext) => StackContext; /** * Pushes copy of TOS-1 as new TOS on r-stack. * * Stack effect: `( x y -- x y x )` * * @param ctx - */ export declare const rover: (ctx: StackContext) => StackContext; /** * Like {@link inc}, but applies to r-stack TOS. * * @param ctx - */ export declare const rinc: (ctx: StackContext) => StackContext; /** * Like {@link dec}, but applies to r-stack TOS. * * @param ctx - */ export declare const rdec: (ctx: StackContext) => StackContext; //# sourceMappingURL=stack.d.ts.map