/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/



/*
// File: macros.h
// Temporary macros (mostly used by debugger agent)
// from F.J. Alberti
*/


#ifndef _MACROS_H_
#define _MACROS_H_

#define SAFEdelete(p)      { if (p) { free (p); (p) = NULL; } }


#define _SEPTRBIT            0x00000001


/* SE conversions*/
#define SEW2I(w)             ((w)>>1)
#define SEW2P(w)             ((w)>>1)
#define SEI2W(n)             ((n)<<1)
#define SEP2W(p)             ((p)<<1 | _SEPTRBIT)

#define MTOI( mot )			 ((mot)>>1)
#define MTOP( mot )		     ((mot)>>1)
#define ITOM( mot )			 ((mot)<<1)
#define PTOM( mot )			 (((mot)<<1)+1)
/*#ifndef SCOL_FLOAT_DEFINITION
typedef float          float32;
#define SCOL_FLOAT_DEFINITION
#endif*/

/*Invert two positions in the stack*/
#define INVERT(m, a, b)       {tmp_res=MMget(m,a);MMset(m,a,MMget(m,b));MMset(m,b,tmp_res);}

/*Stack management*/
#define SEDROP(m, n)         ((m)->pp += (n))

/* String management*/
#define SEPUSHSTR(m, s)      (Mpushstrbloc((m), (s)))

#define CHECK(m)			if ((tmp_res=m)) return tmp_res

/* $Iri : length of the int (234 -> 3)*/
#define SIZEINT(x)  floor (log10 (x)) + 1
/* $ Iri : float support */
#define FSET(val, f)  {                 \
  float g = (f);                      \
  (val) = (*(int*)&g) & 0xfffffffe;     \
}
#define FGET(val)     (*(float*)&(val))

/* $ Iri : double support */
/*#define DSET(val, d)  {                 \
  float g = (d);                      \
  (val) = (*(int*)&g) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE;     \
}
#define DGET(val)     (*(double*)&(val))*/
#endif
