qse/ase/awk/val.h

175 lines
3.8 KiB
C
Raw Normal View History

2006-03-03 11:45:45 +00:00
/*
2006-10-01 14:48:48 +00:00
* $Id: val.h,v 1.44 2006-10-01 14:48:48 bacon Exp $
2006-03-03 11:45:45 +00:00
*/
#ifndef _XP_AWK_VAL_H_
#define _XP_AWK_VAL_H_
#ifndef _XP_AWK_AWK_H_
#error Never include this file directly. Include <xp/awk/awk.h> instead
#endif
2006-03-04 15:54:37 +00:00
enum
{
2006-09-28 06:58:10 +00:00
/* the values between XP_AWK_VAL_NIL and XP_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
2006-03-27 11:43:17 +00:00
XP_AWK_VAL_NIL = 0,
XP_AWK_VAL_INT = 1,
XP_AWK_VAL_REAL = 2,
2006-03-27 15:44:38 +00:00
XP_AWK_VAL_STR = 3,
2006-09-28 06:58:10 +00:00
2006-04-24 11:26:00 +00:00
XP_AWK_VAL_REX = 4,
2006-08-20 15:49:48 +00:00
XP_AWK_VAL_MAP = 5,
XP_AWK_VAL_REF = 6
};
enum
{
/* keep these items in the same order as corresponding items
* in tree.h */
XP_AWK_VAL_REF_NAMED,
XP_AWK_VAL_REF_GLOBAL,
XP_AWK_VAL_REF_LOCAL,
XP_AWK_VAL_REF_ARG,
XP_AWK_VAL_REF_NAMEDIDX,
XP_AWK_VAL_REF_GLOBALIDX,
XP_AWK_VAL_REF_LOCALIDX,
2006-09-30 17:03:11 +00:00
XP_AWK_VAL_REF_ARGIDX,
XP_AWK_VAL_REF_POS
2006-03-04 15:54:37 +00:00
};
2006-03-07 15:55:14 +00:00
typedef struct xp_awk_val_nil_t xp_awk_val_nil_t;
2006-03-03 11:45:45 +00:00
typedef struct xp_awk_val_int_t xp_awk_val_int_t;
typedef struct xp_awk_val_real_t xp_awk_val_real_t;
typedef struct xp_awk_val_str_t xp_awk_val_str_t;
2006-04-24 11:26:00 +00:00
typedef struct xp_awk_val_rex_t xp_awk_val_rex_t;
2006-03-27 15:44:38 +00:00
typedef struct xp_awk_val_map_t xp_awk_val_map_t;
2006-08-20 15:49:48 +00:00
typedef struct xp_awk_val_ref_t xp_awk_val_ref_t;
2006-03-03 11:45:45 +00:00
2006-04-30 18:05:07 +00:00
#if XP_SIZEOF_INT == 2
2006-03-03 11:45:45 +00:00
#define XP_AWK_VAL_HDR \
2006-04-17 16:12:02 +00:00
unsigned int type: 3; \
2006-04-30 18:05:07 +00:00
unsigned int ref: 13
#else
2006-04-17 16:12:02 +00:00
#define XP_AWK_VAL_HDR \
2006-04-30 18:05:07 +00:00
unsigned int type: 3; \
unsigned int ref: 29
#endif
2006-03-03 11:45:45 +00:00
struct xp_awk_val_t
{
XP_AWK_VAL_HDR;
};
2006-03-07 15:55:14 +00:00
/* XP_AWK_VAL_NIL */
struct xp_awk_val_nil_t
{
XP_AWK_VAL_HDR;
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_VAL_INT */
2006-03-03 11:45:45 +00:00
struct xp_awk_val_int_t
{
XP_AWK_VAL_HDR;
xp_long_t val;
2006-09-27 14:14:47 +00:00
xp_awk_nde_int_t* nde;
2006-03-03 11:45:45 +00:00
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_VAL_REAL */
2006-03-03 11:45:45 +00:00
struct xp_awk_val_real_t
{
XP_AWK_VAL_HDR;
xp_real_t val;
2006-09-27 14:14:47 +00:00
xp_awk_nde_real_t* nde;
2006-03-03 11:45:45 +00:00
};
2006-03-04 15:54:37 +00:00
/* XP_AWK_VAL_STR */
2006-03-03 11:45:45 +00:00
struct xp_awk_val_str_t
{
XP_AWK_VAL_HDR;
xp_char_t* buf;
xp_size_t len;
};
2006-04-24 11:26:00 +00:00
/* XP_AWK_VAL_REX */
struct xp_awk_val_rex_t
{
XP_AWK_VAL_HDR;
xp_char_t* buf;
xp_size_t len;
2006-07-26 15:00:01 +00:00
void* code;
2006-04-24 11:26:00 +00:00
};
2006-03-27 15:44:38 +00:00
/* XP_AWK_VAL_MAP */
struct xp_awk_val_map_t
{
XP_AWK_VAL_HDR;
2006-04-26 15:53:17 +00:00
2006-10-01 14:48:48 +00:00
/* TODO: make val_map to array if the indices used are all
* integers switch to map dynamically once the
* non-integral index is seen.
2006-04-26 15:53:17 +00:00
*/
2006-04-16 16:30:59 +00:00
xp_awk_map_t* map;
2006-03-27 15:44:38 +00:00
};
2006-08-20 15:49:48 +00:00
/* XP_AWK_VAL_REF */
struct xp_awk_val_ref_t
{
XP_AWK_VAL_HDR;
int id;
2006-10-01 14:48:48 +00:00
/* if id is XP_AWK_VAL_REF_POS, adr holds an index of the
* positionalvariable. Otherwise, adr points to the value
* directly. */
2006-08-20 15:49:48 +00:00
xp_awk_val_t** adr;
};
2006-03-04 15:54:37 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-03-07 15:55:14 +00:00
extern xp_awk_val_t* xp_awk_val_nil;
2006-07-10 04:51:38 +00:00
extern xp_awk_val_t* xp_awk_val_zls;
2006-07-12 07:25:15 +00:00
extern xp_awk_val_t* xp_awk_val_zero;
extern xp_awk_val_t* xp_awk_val_one;
2006-03-07 15:55:14 +00:00
2006-04-21 17:24:31 +00:00
xp_awk_val_t* xp_awk_makeintval (xp_awk_run_t* run, xp_long_t v);
xp_awk_val_t* xp_awk_makerealval (xp_awk_run_t* run, xp_real_t v);
2006-08-31 15:22:40 +00:00
xp_awk_val_t* xp_awk_makestrval0 (xp_awk_run_t* run, const xp_char_t* str);
xp_awk_val_t* xp_awk_makestrval (
xp_awk_run_t* run, const xp_char_t* str, xp_size_t len);
2006-04-06 16:25:37 +00:00
xp_awk_val_t* xp_awk_makestrval2 (
2006-08-31 15:22:40 +00:00
xp_awk_run_t* run,
2006-04-06 16:25:37 +00:00
const xp_char_t* str1, xp_size_t len1,
const xp_char_t* str2, xp_size_t len2);
2006-08-31 15:22:40 +00:00
2006-07-26 15:00:01 +00:00
xp_awk_val_t* xp_awk_makerexval (
2006-08-31 15:22:40 +00:00
xp_awk_run_t* run, const xp_char_t* buf, xp_size_t len, void* code);
2006-04-21 17:24:31 +00:00
xp_awk_val_t* xp_awk_makemapval (xp_awk_run_t* run);
2006-08-20 15:49:48 +00:00
xp_awk_val_t* xp_awk_makerefval (
xp_awk_run_t* run, int id, xp_awk_val_t** adr);
2006-03-05 17:07:33 +00:00
2006-03-26 16:36:30 +00:00
xp_bool_t xp_awk_isbuiltinval (xp_awk_val_t* val);
2006-06-30 16:46:34 +00:00
2006-04-21 17:24:31 +00:00
void xp_awk_freeval (xp_awk_run_t* run, xp_awk_val_t* val, xp_bool_t cache);
2006-03-23 13:26:04 +00:00
void xp_awk_refupval (xp_awk_val_t* val);
2006-04-21 17:24:31 +00:00
void xp_awk_refdownval (xp_awk_run_t* run, xp_awk_val_t* val);
void xp_awk_refdownval_nofree (xp_awk_run_t* run, xp_awk_val_t* val);
2006-03-23 13:26:04 +00:00
2006-06-21 11:45:26 +00:00
xp_bool_t xp_awk_valtobool (xp_awk_val_t* val);
2006-07-13 03:10:35 +00:00
xp_char_t* xp_awk_valtostr (
2006-08-31 15:41:11 +00:00
xp_awk_run_t* run, xp_awk_val_t* val,
2006-08-31 16:00:20 +00:00
xp_bool_t clear_buf, xp_awk_str_t* buf, xp_size_t* len);
2006-09-01 06:23:58 +00:00
int xp_awk_valtonum (
xp_awk_run_t* run, xp_awk_val_t* v, xp_long_t* l, xp_real_t* r);
2006-06-21 11:45:26 +00:00
2006-03-04 15:54:37 +00:00
void xp_awk_printval (xp_awk_val_t* val);
#ifdef __cplusplus
}
#endif
2006-03-03 11:45:45 +00:00
#endif