/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss or reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#include <nanu-nanu.h>

/** @addtogroup nanu */
/** @{ */

/**
*	Pushes a constant onto the stack
*
*	Creates a new number on the top of the stack. The value of the
*	new number will be that of the number represented by the
*	argument. The argument is a pointer to a structure. The first
*	element of the structure is the length of the constant, in 32-bit
*	words. It is followed by a number of unsigned ints that represent
*	the constant in little-endian order. The most significant word must
*	not be 0; if it is, then the function returns with a size error and
*	the stack is flushed. The only exception is if you want to push a
*	constant 0, which is allowed.<br>
*	This function actually does not create a copy of the item, it just
*	stores a reference to the external data. Therefore, the structure
*	describing the constant must not be modified as long as this constant
*	is on the stack. In addition, although the constant itself is not
*	pushed onto the stack, a reference is, therefore this routine can
*	still return an out of memory error.
*
*	@param	nanu			The natural number machine state descriptor
*	@param	cons			Pointer to the constant descriptor
*
*	@retval	BC_NANU_NANU	The operation succeeded
*	@retval	BC_NANU_SOVR	The stack was full
*	@retval	BC_NANU_SIZE	The size parameter is invalid
*	@retval	BC_NANU_OMEM	There's not enough memory in the pool to store
*							the number.
*
*	@par Stack image
*		...  ==> const ...
*/

int		BC_NanuCons( BC_NANU nanu, const BC_NANU_CONS *cons )
{
int		vref;

	if ( cons->size == 1 && ! cons->data[ 0 ] ) {

		vref = 0;
		return( BC_NanuPush( nanu, &vref, 1 ) );
	}

	if ( ! cons->size || ! cons->data[ cons->size - 1 ] )

		return( _bc_NanuError( nanu, BC_NANU_SIZE ) );

	if ( ( vref = _bc_NanuVarCon( nanu, cons ) ) < 0 )

		return( _bc_NanuError( nanu, vref ) );

	return( _bc_NanuError( nanu, _bc_NanuStkPut( nanu, vref ) ) );
}

/** @} */

