Skip to content
⌘ NSIS Forum Archive

!Stack.nsh

4 posts

Zinthose#

!Stack.nsh

I created a precompiler library to perform compiler time named stack operations. Well pseudo stack operations anyway. As a named stack is just a delimited !define with macros to Push, Pop, Exch, & Peek at the values.

PasteBin.com [!Stack.nsh]

I'm not quite sure how I'd use this yet, but it's still cool. (Any ideas?)

EXAMPLE:
     # Stack(TestStack): 5 4 2 1 0
    ${!Push} TestStack ${ValueTmp}  # Stack(TestStack): 3 5 4 2 1 0
     
    ${!Exch} TestStack 2            # Stack(TestStack): 4 5 3 2 1 0
    ${!Exch} TestStack 1            # Stack(TestStack): 5 4 3 2 1 0
    
    ${!Pop}  TestStack Value5       # Stack(TestStack): 4 3 2 1 0
    ${!Pop}  TestStack Value4       # Stack(TestStack): 3 2 1 0
    ${!Peek} TestStack Value3       # Stack(TestStack): 3 2 1 0
    ${!Pop}  TestStack Value3       # Stack(TestStack): 2 1 0
    ${!Pop}  TestStack Value2       # Stack(TestStack): 1 0
    ${!Pop}  TestStack Value1       # Stack(TestStack): 0
    ${!Pop}  TestStack Value0       # Stack(TestStack): EMPTY
   ;${!Pop}  TestStack ValueE       # Stack(TestStack): ERROR! Stack is Empty!
    !echo `5=${Value5}`
    !echo `4=${Value4}`
    !echo `3=${Value3}`
    !echo `2=${Value2}`
    !echo `1=${Value1}`
    !echo `0=${Value0}` 
Zinthose#
Here is the complete example...
    !define !Stack_AllowRedefine
    !include "!Stack.nsh"
    ${!Push} TestStack 0            # Stack(TestStack): 0 
    ${!Push} TestStack 1            # Stack(TestStack): 1 0
    ${!Push} TestStack 2            # Stack(TestStack): 2 1 0
    ${!Push} TestStack 3            # Stack(TestStack): 3 2 1 0
    ${!Push} TestStack 4            # Stack(TestStack): 4 3 2 1 0
    ${!Exch} TestStack 1            # Stack(TestStack): 3 4 2 1 0
    
    !define  ValueTmp 5
    ${!Exch} TestStack ValueTmp     # Stack(TestStack): 5 4 2 1 0
    ${!Push} TestStack ${ValueTmp}  # Stack(TestStack): 3 5 4 2 1 0
     
    ${!Exch} TestStack 2            # Stack(TestStack): 4 5 3 2 1 0
    ${!Exch} TestStack 1            # Stack(TestStack): 5 4 3 2 1 0
    
    ${!Pop}  TestStack Value5       # Stack(TestStack): 4 3 2 1 0
    ${!Pop}  TestStack Value4       # Stack(TestStack): 3 2 1 0
    ${!Peek} TestStack Value3       # Stack(TestStack): 3 2 1 0
    ${!Pop}  TestStack Value3       # Stack(TestStack): 2 1 0
    ${!Pop}  TestStack Value2       # Stack(TestStack): 1 0
    ${!Pop}  TestStack Value1       # Stack(TestStack): 0
    ${!Pop}  TestStack Value0       # Stack(TestStack): EMPTY
   ;${!Pop}  TestStack ValueE       # Stack(TestStack): ERROR! Stack is Empty!
    !echo `5=${Value5}`
    !echo `4=${Value4}`
    !echo `3=${Value3}`
    !echo `2=${Value2}`
    !echo `1=${Value1}`
    !echo `0=${Value0}`
    ;!echo `E=${ValueE}` 
I vaguely remember having the ability to edit previous posts but I can't find it now.. 😕