2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2007-05-02 01:07:00 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2014-11-19 14:42:24 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-05-02 01:07:00 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-01 03:59:46 +00:00
|
|
|
#ifndef _QSE_LIB_AWK_VAL_H_
|
|
|
|
#define _QSE_LIB_AWK_VAL_H_
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2009-02-27 04:56:12 +00:00
|
|
|
#define QSE_AWK_VAL_CHUNK_SIZE 100
|
|
|
|
|
|
|
|
typedef struct qse_awk_val_chunk_t qse_awk_val_chunk_t;
|
|
|
|
typedef struct qse_awk_val_ichunk_t qse_awk_val_ichunk_t;
|
|
|
|
typedef struct qse_awk_val_rchunk_t qse_awk_val_rchunk_t;
|
|
|
|
|
|
|
|
struct qse_awk_val_chunk_t
|
|
|
|
{
|
|
|
|
qse_awk_val_chunk_t* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct qse_awk_val_ichunk_t
|
|
|
|
{
|
|
|
|
qse_awk_val_chunk_t* next;
|
|
|
|
/* make sure that it has the same fields as
|
|
|
|
qse_awk_val_chunk_t up to this point */
|
|
|
|
|
|
|
|
qse_awk_val_int_t slot[QSE_AWK_VAL_CHUNK_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct qse_awk_val_rchunk_t
|
|
|
|
{
|
|
|
|
qse_awk_val_chunk_t* next;
|
|
|
|
/* make sure that it has the same fields as
|
|
|
|
qse_awk_val_chunk_t up to this point */
|
|
|
|
|
2011-11-22 05:03:31 +00:00
|
|
|
qse_awk_val_flt_t slot[QSE_AWK_VAL_CHUNK_SIZE];
|
2009-02-27 04:56:12 +00:00
|
|
|
};
|
|
|
|
|
2014-10-23 09:18:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if shared objects link a static library, statically defined objects
|
|
|
|
* in the static library will be instatiated in the multiple shared objects.
|
|
|
|
*
|
|
|
|
* so equality check with a value pointer doesn't work
|
|
|
|
* if the code crosses the library boundaries. instead, i decided to
|
|
|
|
* add a field to indicate if a value is static.
|
|
|
|
*
|
|
|
|
|
2019-06-18 07:03:50 +00:00
|
|
|
#define IS_STATICVAL(val) ((val) == QSE_NULL || (val) == qse_awk_val_nil || (val) == qse_awk_val_zls || (val) == qse_awk_val_zlm)
|
2014-10-23 09:18:49 +00:00
|
|
|
*/
|
|
|
|
#define IS_STATICVAL(val) ((val)->stat)
|
|
|
|
|
|
|
|
|
2014-10-23 16:09:05 +00:00
|
|
|
/* qse_awk_val_t pointer encoding assumes the pointer is an even number.
|
2018-11-15 06:27:42 +00:00
|
|
|
* i shift an integer within a certain range and set bit 0 to 1 to
|
|
|
|
* encode it in a pointer. (vtr = value pointer).
|
|
|
|
*
|
2014-10-23 16:09:05 +00:00
|
|
|
* is this a safe assumption? do i have to use memalign or write my own
|
|
|
|
* aligned malloc()? */
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_VTR_NUM_TYPE_BITS 1
|
|
|
|
#define QSE_AWK_VTR_MASK_TYPE_BITS 1
|
2014-10-23 09:18:49 +00:00
|
|
|
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_VTR_TYPE_BITS_POINTER 0
|
|
|
|
#define QSE_AWK_VTR_TYPE_BITS_QUICKINT 1
|
|
|
|
#define QSE_AWK_VTR_SIGN_BIT ((qse_uintptr_t)1 << (QSE_SIZEOF_UINTPTR_T * 8 - 1))
|
2014-10-23 09:18:49 +00:00
|
|
|
|
|
|
|
/* shrink the bit range by 1 more bit to ease signbit handling.
|
|
|
|
* i want abs(max) == abs(min).
|
|
|
|
* i don't want abs(max) + 1 == abs(min). e.g min: -32768, max: 32767
|
|
|
|
*/
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_QUICKINT_MAX ((qse_awk_int_t)((~(qse_uintptr_t)0) >> (QSE_AWK_VTR_NUM_TYPE_BITS + 1)))
|
|
|
|
#define QSE_AWK_QUICKINT_MIN (-QSE_AWK_QUICKINT_MAX)
|
|
|
|
#define QSE_AWK_IN_QUICKINT_RANGE(i) ((i) >= QSE_AWK_QUICKINT_MIN && (i) <= QSE_AWK_QUICKINT_MAX)
|
|
|
|
|
|
|
|
#define QSE_AWK_VTR_TYPE_BITS(p) (((qse_uintptr_t)(p)) & QSE_AWK_VTR_MASK_TYPE_BITS)
|
|
|
|
#define QSE_AWK_VTR_IS_POINTER(p) (QSE_AWK_VTR_TYPE_BITS(p) == QSE_AWK_VTR_TYPE_BITS_POINTER)
|
|
|
|
#define QSE_AWK_VTR_IS_QUICKINT(p) (QSE_AWK_VTR_TYPE_BITS(p) == QSE_AWK_VTR_TYPE_BITS_QUICKINT)
|
2014-10-23 09:18:49 +00:00
|
|
|
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_QUICKINT_TO_VTR_POSITIVE(i) \
|
|
|
|
(((qse_uintptr_t)(i) << QSE_AWK_VTR_NUM_TYPE_BITS) | QSE_AWK_VTR_TYPE_BITS_QUICKINT)
|
2014-10-23 09:18:49 +00:00
|
|
|
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_QUICKINT_TO_VTR_NEGATIVE(i) \
|
|
|
|
((((qse_uintptr_t)-(i)) << QSE_AWK_VTR_NUM_TYPE_BITS) | QSE_AWK_VTR_TYPE_BITS_QUICKINT | QSE_AWK_VTR_SIGN_BIT)
|
|
|
|
|
|
|
|
#define QSE_AWK_QUICKINT_TO_VTR(i) \
|
|
|
|
((qse_awk_val_t*)(((i) < 0)? QSE_AWK_QUICKINT_TO_VTR_NEGATIVE(i): QSE_AWK_QUICKINT_TO_VTR_POSITIVE(i)))
|
|
|
|
|
|
|
|
#define QSE_AWK_VTR_ZERO ((qse_awk_val_t*)QSE_AWK_QUICKINT_TO_VTR_POSITIVE(0))
|
|
|
|
#define QSE_AWK_VTR_ONE ((qse_awk_val_t*)QSE_AWK_QUICKINT_TO_VTR_POSITIVE(1))
|
|
|
|
#define QSE_AWK_VTR_NEGONE ((qse_awk_val_t*)QSE_AWK_QUICKINT_TO_VTR_NEGATIVE(-1))
|
2014-10-23 09:18:49 +00:00
|
|
|
|
|
|
|
/* sizeof(qse_intptr_t) may not be the same as sizeof(qse_awk_int_t).
|
|
|
|
* so step-by-step type conversions are needed.
|
|
|
|
* e.g) pointer to uintptr_t, uintptr_t to intptr_t, intptr_t to awk_int_t */
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_VTR_TO_QUICKINT_POSITIVE(p) \
|
|
|
|
((qse_intptr_t)((qse_uintptr_t)(p) >> QSE_AWK_VTR_NUM_TYPE_BITS))
|
|
|
|
#define QSE_AWK_VTR_TO_QUICKINT_NEGATIVE(p) \
|
|
|
|
(-(qse_intptr_t)(((qse_uintptr_t)(p) & ~QSE_AWK_VTR_SIGN_BIT) >> QSE_AWK_VTR_NUM_TYPE_BITS))
|
|
|
|
#define QSE_AWK_VTR_TO_QUICKINT(p) \
|
|
|
|
(((qse_uintptr_t)(p) & QSE_AWK_VTR_SIGN_BIT)? QSE_AWK_VTR_TO_QUICKINT_NEGATIVE(p): QSE_AWK_VTR_TO_QUICKINT_POSITIVE(p))
|
|
|
|
|
2014-10-23 09:18:49 +00:00
|
|
|
|
2018-11-15 06:27:42 +00:00
|
|
|
#define QSE_AWK_RTX_GETVALTYPE(rtx,p) (QSE_AWK_VTR_IS_QUICKINT(p)? QSE_AWK_VAL_INT: (p)->v_type)
|
|
|
|
#define QSE_AWK_RTX_GETINTFROMVAL(rtx,p) ((QSE_AWK_VTR_IS_QUICKINT(p)? (qse_awk_int_t)QSE_AWK_VTR_TO_QUICKINT(p): ((qse_awk_val_int_t*)(p))->i_val))
|
|
|
|
|
|
|
|
|
|
|
|
#define QSE_AWK_VAL_ZERO QSE_AWK_VTR_ZERO
|
|
|
|
#define QSE_AWK_VAL_ONE QSE_AWK_VTR_ONE
|
|
|
|
#define QSE_AWK_VAL_NEGONE QSE_AWK_VTR_NEGONE
|
2014-10-23 09:18:49 +00:00
|
|
|
|
2014-11-14 02:44:20 +00:00
|
|
|
#if defined(__cplusplus)
|
2007-05-02 01:07:00 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-11-29 14:03:59 +00:00
|
|
|
/* represents a nil value */
|
|
|
|
extern qse_awk_val_t* qse_awk_val_nil;
|
|
|
|
|
|
|
|
/* represents an empty string */
|
|
|
|
extern qse_awk_val_t* qse_awk_val_zls;
|
|
|
|
|
|
|
|
|
2009-02-23 08:10:34 +00:00
|
|
|
void qse_awk_rtx_freeval (
|
|
|
|
qse_awk_rtx_t* rtx,
|
|
|
|
qse_awk_val_t* val,
|
2012-10-22 09:36:15 +00:00
|
|
|
int cache
|
2009-02-23 08:10:34 +00:00
|
|
|
);
|
|
|
|
|
2009-02-01 03:59:46 +00:00
|
|
|
void qse_awk_rtx_freevalchunk (
|
|
|
|
qse_awk_rtx_t* rtx,
|
|
|
|
qse_awk_val_chunk_t* chunk
|
|
|
|
);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2014-11-14 02:44:20 +00:00
|
|
|
#if defined(__cplusplus)
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|