qse/ase/awk/val.h

184 lines
4.1 KiB
C
Raw Normal View History

2006-03-03 11:45:45 +00:00
/*
2006-10-22 11:34:53 +00:00
* $Id: val.h,v 1.47 2006-10-22 11:34:53 bacon Exp $
2006-03-03 11:45:45 +00:00
*/
2006-10-22 11:34:53 +00:00
#ifndef _SSE_AWK_VAL_H_
#define _SSE_AWK_VAL_H_
2006-03-03 11:45:45 +00:00
2006-10-22 11:34:53 +00:00
#ifndef _SSE_AWK_AWK_H_
#error Never include this file directly. Include <sse/awk/awk.h> instead
2006-03-03 11:45:45 +00:00
#endif
2006-03-04 15:54:37 +00:00
enum
{
2006-10-22 11:34:53 +00:00
/* the values between SSE_AWK_VAL_NIL and SSE_AWK_VAL_STR inclusive
2006-09-28 06:58:10 +00:00
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_NIL = 0,
SSE_AWK_VAL_INT = 1,
SSE_AWK_VAL_REAL = 2,
SSE_AWK_VAL_STR = 3,
SSE_AWK_VAL_REX = 4,
SSE_AWK_VAL_MAP = 5,
SSE_AWK_VAL_REF = 6
2006-08-20 15:49:48 +00:00
};
enum
{
/* keep these items in the same order as corresponding items
* in tree.h */
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_REF_NAMED,
SSE_AWK_VAL_REF_GLOBAL,
SSE_AWK_VAL_REF_LOCAL,
SSE_AWK_VAL_REF_ARG,
SSE_AWK_VAL_REF_NAMEDIDX,
SSE_AWK_VAL_REF_GLOBALIDX,
SSE_AWK_VAL_REF_LOCALIDX,
SSE_AWK_VAL_REF_ARGIDX,
SSE_AWK_VAL_REF_POS
2006-03-04 15:54:37 +00:00
};
2006-10-11 15:02:26 +00:00
enum
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VALTOSTR_CLEAR = (1 << 0),
SSE_AWK_VALTOSTR_PRINT = (1 << 1)
2006-10-11 15:02:26 +00:00
};
2006-10-22 11:34:53 +00:00
typedef struct sse_awk_val_nil_t sse_awk_val_nil_t;
typedef struct sse_awk_val_int_t sse_awk_val_int_t;
typedef struct sse_awk_val_real_t sse_awk_val_real_t;
typedef struct sse_awk_val_str_t sse_awk_val_str_t;
typedef struct sse_awk_val_rex_t sse_awk_val_rex_t;
typedef struct sse_awk_val_map_t sse_awk_val_map_t;
typedef struct sse_awk_val_ref_t sse_awk_val_ref_t;
2006-03-03 11:45:45 +00:00
2006-10-22 11:34:53 +00:00
#if SSE_SIZEOF_INT == 2
#define SSE_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-10-22 11:34:53 +00:00
#define SSE_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
2006-10-22 11:34:53 +00:00
struct sse_awk_val_t
2006-03-03 11:45:45 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
2006-03-03 11:45:45 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_NIL */
struct sse_awk_val_nil_t
2006-03-07 15:55:14 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
2006-03-07 15:55:14 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_INT */
struct sse_awk_val_int_t
2006-03-03 11:45:45 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
sse_long_t val;
sse_awk_nde_int_t* nde;
2006-03-03 11:45:45 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_REAL */
struct sse_awk_val_real_t
2006-03-03 11:45:45 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
sse_real_t val;
sse_awk_nde_real_t* nde;
2006-03-03 11:45:45 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_STR */
struct sse_awk_val_str_t
2006-03-03 11:45:45 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
sse_char_t* buf;
sse_size_t len;
2006-03-03 11:45:45 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_REX */
struct sse_awk_val_rex_t
2006-04-24 11:26:00 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
sse_char_t* buf;
sse_size_t len;
2006-07-26 15:00:01 +00:00
void* code;
2006-04-24 11:26:00 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_MAP */
struct sse_awk_val_map_t
2006-03-27 15:44:38 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_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-10-22 11:34:53 +00:00
sse_awk_map_t* map;
2006-03-27 15:44:38 +00:00
};
2006-10-22 11:34:53 +00:00
/* SSE_AWK_VAL_REF */
struct sse_awk_val_ref_t
2006-08-20 15:49:48 +00:00
{
2006-10-22 11:34:53 +00:00
SSE_AWK_VAL_HDR;
2006-08-20 15:49:48 +00:00
int id;
2006-10-22 11:34:53 +00:00
/* if id is SSE_AWK_VAL_REF_POS, adr holds an index of the
2006-10-01 14:48:48 +00:00
* positionalvariable. Otherwise, adr points to the value
* directly. */
2006-10-22 11:34:53 +00:00
sse_awk_val_t** adr;
2006-08-20 15:49:48 +00:00
};
2006-03-04 15:54:37 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-10-22 11:34:53 +00:00
extern sse_awk_val_t* sse_awk_val_nil;
extern sse_awk_val_t* sse_awk_val_zls;
extern sse_awk_val_t* sse_awk_val_zero;
extern sse_awk_val_t* sse_awk_val_one;
2006-03-07 15:55:14 +00:00
2006-10-22 11:34:53 +00:00
sse_awk_val_t* sse_awk_makeintval (sse_awk_run_t* run, sse_long_t v);
sse_awk_val_t* sse_awk_makerealval (sse_awk_run_t* run, sse_real_t v);
2006-08-31 15:22:40 +00:00
2006-10-22 11:34:53 +00:00
sse_awk_val_t* sse_awk_makestrval0 (sse_awk_run_t* run, const sse_char_t* str);
sse_awk_val_t* sse_awk_makestrval (
sse_awk_run_t* run, const sse_char_t* str, sse_size_t len);
sse_awk_val_t* sse_awk_makestrval2 (
sse_awk_run_t* run,
const sse_char_t* str1, sse_size_t len1,
const sse_char_t* str2, sse_size_t len2);
2006-08-31 15:22:40 +00:00
2006-10-22 11:34:53 +00:00
sse_awk_val_t* sse_awk_makerexval (
sse_awk_run_t* run, const sse_char_t* buf, sse_size_t len, void* code);
sse_awk_val_t* sse_awk_makemapval (sse_awk_run_t* run);
sse_awk_val_t* sse_awk_makerefval (
sse_awk_run_t* run, int id, sse_awk_val_t** adr);
2006-03-05 17:07:33 +00:00
2006-10-22 11:34:53 +00:00
sse_bool_t sse_awk_isbuiltinval (sse_awk_val_t* val);
2006-06-30 16:46:34 +00:00
2006-10-22 11:34:53 +00:00
void sse_awk_freeval (sse_awk_run_t* run, sse_awk_val_t* val, sse_bool_t cache);
void sse_awk_refupval (sse_awk_val_t* val);
void sse_awk_refdownval (sse_awk_run_t* run, sse_awk_val_t* val);
void sse_awk_refdownval_nofree (sse_awk_run_t* run, sse_awk_val_t* val);
2006-03-23 13:26:04 +00:00
2006-10-22 11:34:53 +00:00
sse_bool_t sse_awk_valtobool (
sse_awk_run_t* run, sse_awk_val_t* val);
2006-10-12 04:17:58 +00:00
2006-10-22 11:34:53 +00:00
sse_char_t* sse_awk_valtostr (
sse_awk_run_t* run, sse_awk_val_t* val,
int opt, sse_awk_str_t* buf, sse_size_t* len);
2006-10-12 04:17:58 +00:00
2006-10-22 11:34:53 +00:00
int sse_awk_valtonum (
sse_awk_run_t* run, sse_awk_val_t* v, sse_long_t* l, sse_real_t* r);
2006-06-21 11:45:26 +00:00
2006-10-22 11:34:53 +00:00
void sse_awk_printval (sse_awk_val_t* val);
2006-03-04 15:54:37 +00:00
#ifdef __cplusplus
}
#endif
2006-03-03 11:45:45 +00:00
#endif