This commit is contained in:
hyung-hwan 2008-07-10 07:20:08 +00:00
parent b18be770ce
commit 75d4e90399
10 changed files with 204 additions and 233 deletions

View File

@ -3,7 +3,6 @@
*/
#include <ase/awk/awk.h>
#include <ase/awk/val.h>
#include <ase/utl/helper.h>
#include <ase/utl/stdio.h>

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 233 2008-06-29 13:41:11Z baconevi $
* $Id: awk.h 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -18,6 +18,7 @@
#include <ase/types.h>
#include <ase/macros.h>
#include <ase/cmn/map.h>
#include <ase/cmn/str.h>
typedef struct ase_awk_t ase_awk_t;
typedef struct ase_awk_run_t ase_awk_run_t;
@ -454,21 +455,163 @@ enum ase_awk_global_id_t
ASE_AWK_MAX_GLOBAL_ID = ASE_AWK_GLOBAL_SUBSEP
};
enum ase_awk_val_type_t
{
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
ASE_AWK_VAL_NIL = 0,
ASE_AWK_VAL_INT = 1,
ASE_AWK_VAL_REAL = 2,
ASE_AWK_VAL_STR = 3,
ASE_AWK_VAL_REX = 4,
ASE_AWK_VAL_MAP = 5,
ASE_AWK_VAL_REF = 6
};
enum ase_awk_val_ref_id_t
{
/* keep these items in the same order as corresponding items
* in tree.h */
ASE_AWK_VAL_REF_NAMED,
ASE_AWK_VAL_REF_GLOBAL,
ASE_AWK_VAL_REF_LOCAL,
ASE_AWK_VAL_REF_ARG,
ASE_AWK_VAL_REF_NAMEDIDX,
ASE_AWK_VAL_REF_GLOBALIDX,
ASE_AWK_VAL_REF_LOCALIDX,
ASE_AWK_VAL_REF_ARGIDX,
ASE_AWK_VAL_REF_POS
};
enum ase_awk_valtostr_opt_t
{
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
ASE_AWK_VALTOSTR_FIXED = (1 << 1),/* this overrides CLEAR */
ASE_AWK_VALTOSTR_PRINT = (1 << 2)
};
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
/* this is not a value. it is just a value holder */
typedef struct ase_awk_val_chunk_t ase_awk_val_chunk_t;
#if ASE_SIZEOF_INT == 2
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 13
#else
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 29
#endif
#define ASE_AWK_VAL_TYPE(x) ((x)->type)
struct ase_awk_val_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_NIL */
struct ase_awk_val_nil_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_INT */
struct ase_awk_val_int_t
{
ASE_AWK_VAL_HDR;
ase_long_t val;
void* nde;
};
/* ASE_AWK_VAL_REAL */
struct ase_awk_val_real_t
{
ASE_AWK_VAL_HDR;
ase_real_t val;
void* nde;
};
/* ASE_AWK_VAL_STR */
struct ase_awk_val_str_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_VAL_REX */
struct ase_awk_val_rex_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_VAL_MAP */
struct ase_awk_val_map_t
{
ASE_AWK_VAL_HDR;
/* TODO: make val_map to array if the indices used are all
* integers switch to map dynamically once the
* non-integral index is seen.
*/
ase_map_t* map;
};
/* ASE_AWK_VAL_REF */
struct ase_awk_val_ref_t
{
ASE_AWK_VAL_HDR;
int id;
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
* positional variable. Otherwise, adr points to the value
* directly. */
ase_awk_val_t** adr;
};
#ifdef __cplusplus
extern "C" {
#endif
extern ase_awk_val_t* ase_awk_val_nil;
extern ase_awk_val_t* ase_awk_val_zls;
extern ase_awk_val_t* ase_awk_val_negone;
extern ase_awk_val_t* ase_awk_val_zero;
extern ase_awk_val_t* ase_awk_val_one;
/**
* @brief opens an awk interpreter
*/
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns);
/**
* @brief opens an awk interpreter
*/
int ase_awk_close (ase_awk_t* awk);
/**
* @brief clears an awk interpreter
*/
int ase_awk_clear (ase_awk_t* awk);
/**
* @function ase_awk_setassocdata
* @brief associats the user-specified data with an interpreter
*/
void ase_awk_setassocdata (ase_awk_t* awk, void* data);
/**
* @function ase_awk_getassocdata
* @brief returns the user-specified data associated with an interpreter
*/
void* ase_awk_getassocdata (ase_awk_t* awk);
@ -677,6 +820,51 @@ ase_size_t ase_awk_longtostr (
ase_long_t value, int radix, const ase_char_t* prefix,
ase_char_t* buf, ase_size_t size);
/* value manipulation functions */
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
ase_awk_val_t* ase_awk_makestrval0 (
ase_awk_run_t* run, const ase_char_t* str);
ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval_nodup (
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval2 (
ase_awk_run_t* run,
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2);
ase_awk_val_t* ase_awk_makerexval (
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
ase_awk_val_t* ase_awk_makerefval (
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
ase_bool_t ase_awk_isstaticval (ase_awk_val_t* val);
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_freevalchunk (ase_awk_run_t* run, ase_awk_val_chunk_t* chunk);
ase_bool_t ase_awk_valtobool (
ase_awk_run_t* run, ase_awk_val_t* val);
ase_char_t* ase_awk_valtostr (
ase_awk_run_t* run, ase_awk_val_t* val,
int opt, ase_str_t* buf, ase_size_t* len);
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,4 @@
pkginclude_HEADERS = awk.h val.h Awk.hpp StdAwk.hpp
pkginclude_HEADERS = awk.h Awk.hpp StdAwk.hpp
pkgincludedir= $(includedir)/ase/awk
CLEANFILES = *dist

View File

@ -1,213 +0,0 @@
/*
* $Id: val.h 194 2008-06-06 13:00:39Z baconevi $
*
* {License}
*/
#ifndef _ASE_AWK_VAL_H_
#define _ASE_AWK_VAL_H_
#ifndef _ASE_AWK_AWK_H_
#error Include <ase/awk/awk.h> first
#endif
#include <ase/cmn/str.h>
enum ase_awk_val_type_t
{
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
ASE_AWK_VAL_NIL = 0,
ASE_AWK_VAL_INT = 1,
ASE_AWK_VAL_REAL = 2,
ASE_AWK_VAL_STR = 3,
ASE_AWK_VAL_REX = 4,
ASE_AWK_VAL_MAP = 5,
ASE_AWK_VAL_REF = 6
};
enum ase_awk_val_ref_id_t
{
/* keep these items in the same order as corresponding items
* in tree.h */
ASE_AWK_VAL_REF_NAMED,
ASE_AWK_VAL_REF_GLOBAL,
ASE_AWK_VAL_REF_LOCAL,
ASE_AWK_VAL_REF_ARG,
ASE_AWK_VAL_REF_NAMEDIDX,
ASE_AWK_VAL_REF_GLOBALIDX,
ASE_AWK_VAL_REF_LOCALIDX,
ASE_AWK_VAL_REF_ARGIDX,
ASE_AWK_VAL_REF_POS
};
enum ase_awk_valtostr_opt_t
{
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
ASE_AWK_VALTOSTR_FIXED = (1 << 1),/* this overrides CLEAR */
ASE_AWK_VALTOSTR_PRINT = (1 << 2)
};
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
/* this is not a value. it is just a value holder */
typedef struct ase_awk_val_chunk_t ase_awk_val_chunk_t;
#if ASE_SIZEOF_INT == 2
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 13
#else
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 29
#endif
#ifndef ASE_AWK_NDE_INT_DEFINED
#define ASE_AWK_NDE_INT_DEFINED
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
#endif
#ifndef ASE_AWK_NDE_REAL_DEFINED
#define ASE_AWK_NDE_REAL_DEFINED
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
#endif
#define ASE_AWK_VAL_TYPE(x) ((x)->type)
struct ase_awk_val_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_NIL */
struct ase_awk_val_nil_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_INT */
struct ase_awk_val_int_t
{
ASE_AWK_VAL_HDR;
ase_long_t val;
ase_awk_nde_int_t* nde;
};
/* ASE_AWK_VAL_REAL */
struct ase_awk_val_real_t
{
ASE_AWK_VAL_HDR;
ase_real_t val;
ase_awk_nde_real_t* nde;
};
/* ASE_AWK_VAL_STR */
struct ase_awk_val_str_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_VAL_REX */
struct ase_awk_val_rex_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_VAL_MAP */
struct ase_awk_val_map_t
{
ASE_AWK_VAL_HDR;
/* TODO: make val_map to array if the indices used are all
* integers switch to map dynamically once the
* non-integral index is seen.
*/
ase_map_t* map;
};
/* ASE_AWK_VAL_REF */
struct ase_awk_val_ref_t
{
ASE_AWK_VAL_HDR;
int id;
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
* positional variable. Otherwise, adr points to the value
* directly. */
ase_awk_val_t** adr;
};
#ifdef __cplusplus
extern "C" {
#endif
extern ase_awk_val_t* ase_awk_val_nil;
extern ase_awk_val_t* ase_awk_val_zls;
extern ase_awk_val_t* ase_awk_val_negone;
extern ase_awk_val_t* ase_awk_val_zero;
extern ase_awk_val_t* ase_awk_val_one;
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
ase_awk_val_t* ase_awk_makestrval0 (
ase_awk_run_t* run, const ase_char_t* str);
ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval_nodup (
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval2 (
ase_awk_run_t* run,
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2);
ase_awk_val_t* ase_awk_makerexval (
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
ase_awk_val_t* ase_awk_makerefval (
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
ase_bool_t ase_awk_isstaticval (ase_awk_val_t* val);
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_freevalchunk (ase_awk_run_t* run, ase_awk_val_chunk_t* chunk);
ase_bool_t ase_awk_valtobool (
ase_awk_run_t* run, ase_awk_val_t* val);
ase_char_t* ase_awk_valtostr (
ase_awk_run_t* run, ase_awk_val_t* val,
int opt, ase_str_t* buf, ase_size_t* len);
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,12 +1,11 @@
/*
* $Id: Awk.cpp 232 2008-06-28 09:38:00Z baconevi $
* $Id: Awk.cpp 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
#include <ase/awk/Awk.hpp>
#include <ase/awk/val.h>
#include <ase/cmn/str.h>
#include <ase/cmn/mem.h>

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h 232 2008-06-28 09:38:00Z baconevi $
* $Id: awk_i.h 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -16,7 +16,6 @@ typedef struct ase_awk_chain_t ase_awk_chain_t;
typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/awk.h>
#include <ase/awk/val.h>
#include "tree.h"
#include "func.h"
#include "tab.h"

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c 232 2008-06-28 09:38:00Z baconevi $
* $Id: jni.c 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -15,7 +15,6 @@
#include <time.h>
#include <ase/awk/jni.h>
#include <ase/awk/awk.h>
#include <ase/awk/val.h>
#include <ase/cmn/mem.h>
#include <ase/utl/stdio.h>

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c 197 2008-06-09 06:24:10Z baconevi $
* $Id: run.c 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -4172,7 +4172,7 @@ static int __cmp_val (
static cmp_val_t func[] =
{
/* this table must be synchronized with
* the ASE_AWK_VAL_XXX values in val.h */
* the ASE_AWK_VAL_XXX values in awk.h */
__cmp_nil_nil, __cmp_nil_int, __cmp_nil_real, __cmp_nil_str,
__cmp_int_nil, __cmp_int_int, __cmp_int_real, __cmp_int_str,
__cmp_real_nil, __cmp_real_int, __cmp_real_real, __cmp_real_str,
@ -5936,7 +5936,7 @@ static ase_awk_val_t* eval_int (ase_awk_run_t* run, ase_awk_nde_t* nde)
run->errlin = nde->line;
return ASE_NULL;
}
((ase_awk_val_int_t*)val)->nde = (ase_awk_nde_int_t*)nde;
((ase_awk_val_int_t*)val)->nde = nde;
return val;
}
@ -5951,7 +5951,7 @@ static ase_awk_val_t* eval_real (ase_awk_run_t* run, ase_awk_nde_t* nde)
run->errlin = nde->line;
return ASE_NULL;
}
((ase_awk_val_real_t*)val)->nde = (ase_awk_nde_real_t*)nde;
((ase_awk_val_real_t*)val)->nde = nde;
return val;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: tree.h 115 2008-03-03 11:13:15Z baconevi $
* $Id: tree.h 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -53,7 +53,7 @@ enum ase_awk_nde_type_t
/* keep this order for the following items otherwise, you may have
* to change eval_incpre and eval_incpst in run.c as well as
* ASE_AWK_VAL_REF_XXX in val.h */
* ASE_AWK_VAL_REF_XXX in awk.h */
ASE_AWK_NDE_NAMED,
ASE_AWK_NDE_GLOBAL,
ASE_AWK_NDE_LOCAL,

View File

@ -1,5 +1,5 @@
/*
* $Id: val.c 197 2008-06-09 06:24:10Z baconevi $
* $Id: val.c 237 2008-07-09 13:20:08Z baconevi $
*
* {License}
*/
@ -580,7 +580,7 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
{
ASE_ASSERTX (
!"should never happen - invalid value type",
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h");
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in awk.h");
}
}
@ -660,7 +660,7 @@ ase_bool_t ase_awk_valtobool (ase_awk_run_t* run, ase_awk_val_t* val)
ASE_ASSERTX (
!"should never happen - invalid value type",
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h");
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in awk.h");
return ASE_FALSE;
}