function newStack(name, bottom, limit, pointer) {
    function check(offset) {
      if (offset < 0 && pointer - offset > m[bottom]) throw Error(name + " underflow");
      else if (offset > 0 && pointer - offset < m[limit]) throw Error(name + " overflow");
    }

    return {
      check: check,
      push:  function(val) { check(1); m[--pointer] = val },
      pop:   function() { check(-1); return m[pointer++]; },
      popN:  function(val) { check(-val); return m.slice(pointer, pointer += val).reverse(); },
      pick:  function(index) { check(-index-1); return m[pointer + index] },
      roll:  function(index) {
        check(-index-1);
        var v = m[pointer + index];
        for(var i = pointer + index; i > pointer; i--) m[i] = m[i-1];
        m[pointer] = v;
      },
      pointer: function(addr) { return arguments.length ? (pointer = addr) : pointer }
    }
  }
/** Creates a new stack in the memory */
Creates a new stack in the memory
Creates a new stack in the memory
function newStack(name, bottom, limit, pointer) {
    function check(offset) {
      if (offset < 0 && pointer - offset > m[bottom]) throw Error(name + " underflow");
      else if (offset > 0 && pointer - offset < m[limit]) throw Error(name + " overflow");
    }
    return {
      check: check,
      push:  function(val) { check(1); m[--pointer] = val },
      pop:   function() { check(-1); return m[pointer++]; },
      popN:  function(val) { check(-val); return m.slice(pointer, pointer += val).reverse(); },
      pick:  function(index) { check(-index-1); return m[pointer + index] },
      roll:  function(index) {
        check(-index-1);
        var v = m[pointer + index];
        for(var i = pointer + index; i > pointer; i--) m[i] = m[i-1];
        m[pointer] = v;
      },
      pointer: function(addr) { return arguments.length ? (pointer = addr) : pointer }
    }
  }
function newStack ( name , bottom , limit , pointer ) { function check ( offset ) { if ( offset < 0 && pointer - offset > m [ bottom ] ) throw Error ( name + " underflow" ) ; else if ( offset > 0 && pointer - offset < m [ limit ] ) throw Error ( name + " overflow" ) ; } return { check : check , push : function ( val ) { check ( 1 ) ; m [ -- pointer ] = val } , pop : function ( ) { check ( - 1 ) ; return m [ pointer ++ ] ; } , popN : function ( val ) { check ( - val ) ; return m . slice ( pointer , pointer += val ) . reverse ( ) ; } , pick : function ( index ) { check ( - index - 1 ) ; return m [ pointer + index ] } , roll : function ( index ) { check ( - index - 1 ) ; var v = m [ pointer + index ] ; for ( var i = pointer + index ; i > pointer ; i -- ) m [ i ] = m [ i - 1 ] ; m [ pointer ] = v ; } , pointer : function ( addr ) { return arguments . length ? ( pointer = addr ) : pointer } } }
Creates a new stack in the memory
Creates a new stack in the memory