/*! \file Macro.h
*	\brief User Scol machine Macro conversion API
* \remarks This file was named "macro.h" when it was in the external "scol SDK" system, moved to vm to keep up to date.
*/

#ifndef _SCOL_TYPE_CONVERSION_H_
#define _SCOL_TYPE_CONVERSION_H_

#include "scolPrerequisites.h"

/*! @defgroup group1 Macro conversion API
 *  User Scol machine Macro conversion API
 *  @{
 */

/*! \brief Convert scol machine value to int
*   \param int : scol machine value
*   \return int : system int value
*/
#define MTOI(val) ((val)>>1)

/** \brief Convert scol machine value to system handle
* \param int : scol machine value
* \return int : system handle
*/
#define MTOP(val) ((val)>>1)

/*! \brief Convert int to scol machine value
*   \param int : system int value
*   \return int : scol machine value
*/
#define ITOM(val) ((val)<<1)

/*! \brief Convert system handle to scol machine value
*   \param int : system int value
*   \return int : scol machine value
*/
#define PTOM(val) (((val)<<1)+1)

#ifndef SCOL_FLOAT_DEFINITION // TODO: really useful? Check if we can remove this.
/*! \brief Convert scol machine value to float
*   \param int : scol machine value
*   \return float : system float value
*/
_inline float MTOF(int val) {	return *(float*)&(val);	}

/*! \brief Convert float to scol machine value
*   \param float : system float value
*   \return int : scol machine value
*/
_inline int   FTOM(float val) {	return ((*(int*)&(val)) & 0xfffffffe);	}
#define SCOL_FLOAT_DEFINITION
#endif

/*! \brief Invert 2 stack positions in scol machine\n
*    need a int tmp_res local variable to work
* \param Mmachine : the scol machine structure pointer
*	\param int : first position in stack
* \param int : second position in stack
// TODO: rename tmp_res variable, declare it in there, and remove all the tmp_res variables declaration in scol plugins
*/
#define INVERT(m, a, b) {tmp_res=MMget(m, a); MMset(m, a, MMget(m, b)); MMset(m, b, tmp_res); }

/*!
*/
#define STR_SIZE(size) (2+((size)>>2))

/*!
*/
#define SIZE(t) ((sizeof(t)+3)>>2)

/*!
*/
#define CHECK(m) if ((tmp_res=m)) return tmp_res

/*!
*/
#define CHECK_ALLOC(adresse, taille, type) adresse=MMmalloc(m,taille,type);if (adresse==NIL) return MERRMEM;

#endif
