cleaned up code

This commit is contained in:
2009-02-17 02:11:31 +00:00
parent 66b21c8eab
commit 26b4ecd16e
19 changed files with 492 additions and 470 deletions

View File

@ -68,7 +68,7 @@ public:
/** Represents an runtime I/O data */
typedef qse_awk_riod_t riod_t;
enum ccls_type_t
enum ccls_id_t
{
CCLS_UPPER = QSE_CCLS_UPPER,
CCLS_LOWER = QSE_CCLS_LOWER,
@ -743,10 +743,9 @@ public:
void free (void* ptr);
protected:
Awk* awk;
Awk* awk;
rtx_t* run;
bool callbackFailed;
void* data;
void* data;
};
/** Constructor */
@ -1045,8 +1044,6 @@ protected:
/*@}*/
// run-time callbacks
virtual bool onRunStart (Run& run);
virtual void onRunEnd (Run& run);
virtual bool onRunEnter (Run& run);
virtual void onRunExit (Run& run, const Argument& ret);
virtual void onRunStatement (Run& run, size_t line);
@ -1056,8 +1053,8 @@ protected:
virtual void* reallocMem (void* ptr, size_t n) = 0;
virtual void freeMem (void* ptr) = 0;
virtual bool_t isType (cint_t c, ccls_type_t type) = 0;
virtual cint_t transCase (cint_t c, ccls_type_t type) = 0;
virtual bool_t isType (cint_t c, ccls_id_t type) = 0;
virtual cint_t transCase (cint_t c, ccls_id_t type) = 0;
virtual real_t pow (real_t x, real_t y) = 0;
virtual int vsprintf (char_t* buf, size_t size,
@ -1065,23 +1062,24 @@ protected:
// static glue members for various handlers
static ssize_t sourceReader (
awk_t* awk, int cmd, char_t* data, size_t count);
awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
static ssize_t sourceWriter (
awk_t* awk, int cmd, char_t* data, size_t count);
awk_t* awk, qse_awk_sio_cmd_t cmd, char_t* data, size_t count);
static ssize_t pipeHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static ssize_t fileHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static ssize_t consoleHandler (
rtx_t* rtx, int cmd, riod_t* riod, char_t* data, size_t count);
rtx_t* rtx, qse_awk_rio_cmd_t cmd, riod_t* riod,
char_t* data, size_t count);
static int functionHandler (
rtx_t* rtx, const char_t* name, size_t len);
static void freeFunctionMapValue (map_t* map, void* dptr, size_t dlen);
static int onRunStart (rtx_t* run, void* data);
static void onRunEnd (rtx_t* run, int errnum, void* data);
static int onRunEnter (rtx_t* run, void* data);
static void onRunExit (rtx_t* run, val_t* ret, void* data);
static void onRunStatement (rtx_t* run, size_t line, void* data);
@ -1090,8 +1088,8 @@ protected:
static void* reallocMem (void* data, void* ptr, size_t n);
static void freeMem (void* data, void* ptr);
static bool_t isType (void* data, cint_t c, qse_ccls_type_t type);
static cint_t transCase (void* data, cint_t c, qse_ccls_type_t type);
static bool_t isType (awk_t* awk, cint_t c, qse_ccls_id_t type);
static cint_t transCase (awk_t* awk, cint_t c, qse_ccls_id_t type);
static real_t pow (awk_t* data, real_t x, real_t y);
static int sprintf (awk_t* data, char_t* buf, size_t size,
@ -1115,8 +1113,6 @@ private:
Awk& operator= (const Awk&);
mmgr_t mmgr;
ccls_t ccls;
qse_awk_prm_t prm;
};
/////////////////////////////////

View File

@ -84,8 +84,8 @@ protected:
void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr);
bool_t isType (cint_t c, ccls_type_t type);
cint_t transCase (cint_t c, ccls_type_t type);
bool_t isType (cint_t c, ccls_id_t type);
cint_t transCase (cint_t c, ccls_id_t type);
real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size,

View File

@ -58,7 +58,6 @@ typedef struct qse_awk_rio_t qse_awk_rio_t;
typedef struct qse_awk_riod_t qse_awk_riod_t;
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
typedef struct qse_awk_rexfns_t qse_awk_rexfns_t;
typedef qse_real_t (*qse_awk_pow_t) (
qse_awk_t* awk,
@ -74,36 +73,70 @@ typedef int (*qse_awk_sprintf_t) (
...
);
typedef qse_bool_t (*qse_awk_isccls_t) (
qse_awk_t* awk,
qse_cint_t c,
qse_ccls_id_t type
);
typedef qse_cint_t (*qse_awk_toccls_t) (
qse_awk_t* awk,
qse_cint_t c,
qse_ccls_id_t type
);
enum qse_awk_sio_cmd_t
{
QSE_AWK_SIO_OPEN = 0,
QSE_AWK_SIO_CLOSE = 1,
QSE_AWK_SIO_READ = 2,
QSE_AWK_SIO_WRITE = 3
};
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
/****t* AWK/qse_awk_siof_t
* NAME
* qse_awk_siof_t - define a source IO function
* SYNOPSIS
*/
typedef qse_ssize_t (*qse_awk_siof_t) (
qse_awk_t* awk,
int cmd,
qse_char_t* data,
qse_size_t count
qse_awk_t* awk,
qse_awk_sio_cmd_t cmd,
qse_char_t* data,
qse_size_t count
);
/*****/
enum qse_awk_rio_cmd_t
{
QSE_AWK_RIO_OPEN = 0,
QSE_AWK_RIO_CLOSE = 1,
QSE_AWK_RIO_READ = 2,
QSE_AWK_RIO_WRITE = 3,
QSE_AWK_RIO_FLUSH = 4,
QSE_AWK_RIO_NEXT = 5
};
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
/****f* AWK/qse_awk_riof_t
* NAME
* qse_awk_riof_t - define a runtime IO function
* SYNOPSIS
*/
typedef qse_ssize_t (*qse_awk_riof_t) (
qse_awk_rtx_t* rtx,
int cmd,
qse_awk_riod_t* riod,
qse_char_t* data,
qse_size_t count
qse_awk_rtx_t* rtx,
qse_awk_rio_cmd_t cmd,
qse_awk_riod_t* riod,
qse_char_t* data,
qse_size_t count
);
/******/
/****f* AWK/qse_awk_riod_t
* NAME
* qse_awk_riod_f - define a data passed to a rio function
* qse_awk_riod_f - define the data passed to a rio function
* SYNOPSIS
*/
struct qse_awk_riod_t
@ -135,40 +168,13 @@ struct qse_awk_riod_t
struct qse_awk_prm_t
{
qse_awk_pow_t pow; /* required */
qse_awk_sprintf_t sprintf; /* required */
};
qse_awk_pow_t pow;
qse_awk_sprintf_t sprintf;
qse_awk_isccls_t isccls;
qse_awk_toccls_t toccls;
struct qse_awk_sio_t
{
qse_awk_siof_t in;
qse_awk_siof_t out;
};
struct qse_awk_rio_t
{
qse_awk_riof_t pipe;
qse_awk_riof_t file;
qse_awk_riof_t console;
};
struct qse_awk_rcb_t
{
int (*on_enter) (
qse_awk_rtx_t* rtx, void* data);
void (*on_statement) (
qse_awk_rtx_t* rtx, qse_size_t line, void* data);
void (*on_exit) (
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data);
void* data;
};
struct qse_awk_rexfns_t
{
/* TODO: implement functions to get/set rexfns */
#if 0
/* TODO: accept regular expression handling functions */
void* (*build) (
qse_awk_t* awk,
const qse_char_t* ptn,
@ -196,17 +202,34 @@ struct qse_awk_rexfns_t
qse_awk_t* awk,
void* code
);
#endif
};
/* io function commands */
enum qse_awk_iocmd_t
struct qse_awk_sio_t
{
QSE_AWK_IO_OPEN = 0,
QSE_AWK_IO_CLOSE = 1,
QSE_AWK_IO_READ = 2,
QSE_AWK_IO_WRITE = 3,
QSE_AWK_IO_FLUSH = 4,
QSE_AWK_IO_NEXT = 5
qse_awk_siof_t in;
qse_awk_siof_t out;
};
struct qse_awk_rio_t
{
qse_awk_riof_t pipe;
qse_awk_riof_t file;
qse_awk_riof_t console;
};
struct qse_awk_rcb_t
{
int (*on_enter) (
qse_awk_rtx_t* rtx, void* data);
void (*on_statement) (
qse_awk_rtx_t* rtx, qse_size_t line, void* data);
void (*on_exit) (
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* data);
void* data;
};
/* various options */
@ -649,19 +672,35 @@ extern qse_awk_val_t* qse_awk_val_one;
* NAME
* qse_awk_open - create an awk object
* DESCRIPTION
* The qse_awk_open() function creates a new qse_awk_t instance.
* The qse_awk_open() function creates a new qse_awk_t object.
* The instance created can be passed to other qse_awk_xxx() functions and
* is valid until it is successfully destroyed using the qse_qse_close()
* function.
* function. The function save the memory manager pointer while it copies
* the contents of the primitive function structures. Therefore, you should
* keep the memory manager valid during the whole life cycle of an qse_awk_t
* object.
*
* qse_awk_t* dummy()
* {
* qse_mmgr_t mmgr;
* qse_awk_prm_t prm;
* return qse_awk_open (
* &mmgr, // NOT OK because the contents of mmgr is
* // invalidated when dummy() returns.
* 0,
* &prm // OK
* );
* }
*
* RETURN
* The qse_awk_open() function returns the pointer to a qse_awk_t instance
* The qse_awk_open() function returns the pointer to a qse_awk_t object
* on success and QSE_NULL on failure.
* SYNOPSIS
*/
qse_awk_t* qse_awk_open (
qse_mmgr_t* mmgr /* a memory manager */,
qse_size_t xtn /* the size of extension in bytes */,
qse_ccls_t* ccls
qse_mmgr_t* mmgr /* a memory manager */,
qse_size_t xtn /* the size of extension in bytes */,
qse_awk_prm_t* prm /* primitive functoins */
);
/******/
@ -723,27 +762,6 @@ void* qse_awk_getxtn (
);
/******/
/****f* AWK/qse_awk_getccls
* NAME
* qse_awk_getccls - get a character classifier
* SYNOPSIS
*/
qse_ccls_t* qse_awk_getccls (
qse_awk_t* awk
);
/******/
/****f* AWK/qse_awk_setccls
* NAME
* qse_awk_setccls - set the character classfier
* SYNOPSIS
*/
void qse_awk_setccls (
qse_awk_t* awk,
qse_ccls_t* ccls
);
/******/
/****f* AWK/qse_awk_getprm
* NAME
* qse_awk_getprm - get primitive functions
@ -754,14 +772,13 @@ qse_awk_prm_t* qse_awk_getprm (
);
/******/
/****f* AWK/qse_awk_setprm
/****f* AWK/qse_awk_getccls
* NAME
* qse_awk_setprm - set primitive functions
* qse_awk_getcclas - get the character classifier
* SYNOPSIS
*/
void qse_awk_setprm (
qse_awk_t* awk,
qse_awk_prm_t* prm
qse_ccls_t* qse_awk_getccls (
qse_awk_t* ccls
);
/******/
@ -1450,7 +1467,7 @@ qse_awk_val_t* qse_awk_rtx_makerefval (
qse_awk_val_t** adr
);
qse_bool_t qse_awk_isstaticval (
qse_bool_t qse_awk_rtx_isstaticval (
qse_awk_rtx_t* rtx,
qse_awk_val_t* val
);

View File

@ -53,16 +53,14 @@ extern qse_ccls_t* qse_ccls;
qse_bool_t qse_ccls_is (
qse_cint_t c,
qse_ccls_type_t type
qse_ccls_id_t type
);
qse_cint_t qse_ccls_to (
qse_cint_t c,
qse_ccls_type_t type
qse_ccls_id_t type
);
qse_size_t qse_mblen (
const qse_mchar_t* mb,
qse_size_t mblen

View File

@ -172,6 +172,26 @@ qse_mmgr_t* qse_##name##_getmmgr (qse_##name##_t* name); \
void* qse_##name##_getxtn (qse_##name##_t* name);
/******/
/****d* Base/QSE_MMGR
* NAME
* QSE_MMGR - get the memory manager field
* SYNOPSIS
*/
#define QSE_MMGR(obj) (obj->mmgr)
/******/
/****d* Base/QSE_XTN
* NAME
* QSE_XTN - get a pointer to extension space
* DESCRIPTION
* The QSE_XTN() macro is a convenience macro to retrieve the pointer to
* extension space located at the end of an object. The type of the object
* should be known in advance for it to work properly.
* SYNOPSIS
*/
#define QSE_XTN(obj) ((void*)(obj + 1))
/******/
/****d* Base/QSE_IMPLEMENT_COMMON_FUNCTIONS
* NAME
* QSE_IMPLEMENT_COMMON_FUNCTIONS - implement common functions
@ -180,16 +200,17 @@ void* qse_##name##_getxtn (qse_##name##_t* name);
#define QSE_IMPLEMENT_COMMON_FUNCTIONS(name) \
void qse_##name##_setmmgr (qse_##name##_t* name, qse_mmgr_t* mmgr) \
{ \
name->mmgr = mmgr; \
QSE_MMGR(name) = mmgr; \
} \
qse_mmgr_t* qse_##name##_getmmgr (qse_##name##_t* name) \
{ \
return name->mmgr; \
return QSE_MMGR(name); \
} \
void* qse_##name##_getxtn (qse_##name##_t* name) \
{ \
return (void*)(name + 1); \
return QSE_XTN(name); \
}
/******/
#endif

View File

@ -413,12 +413,12 @@ struct qse_mmgr_t
};
/******/
/****t* Base/qse_ccls_type_t
/****t* Base/qse_ccls_id_t
* NAME
* qse_ccls_type_t - define character class types
* qse_ccls_id_t - define character class types
* SYNOPSIS
*/
enum qse_ccls_type_t
enum qse_ccls_id_t
{
QSE_CCLS_UPPER,
QSE_CCLS_LOWER,
@ -434,7 +434,12 @@ enum qse_ccls_type_t
};
/******/
typedef enum qse_ccls_type_t qse_ccls_type_t;
typedef enum qse_ccls_id_t qse_ccls_id_t;
typedef qse_bool_t (*qse_ccls_is_t) (
void* data, qse_cint_t c, qse_ccls_id_t type);
typedef qse_cint_t (*qse_ccls_to_t) (
void* data, qse_cint_t c, qse_ccls_id_t type);
/****t* Base/qse_ccls_t
* NAME
@ -443,9 +448,9 @@ typedef enum qse_ccls_type_t qse_ccls_type_t;
*/
struct qse_ccls_t
{
qse_bool_t (*is) (void* data, qse_cint_t c, qse_ccls_type_t type);
qse_cint_t (*to) (void* data, qse_cint_t c, qse_ccls_type_t type);
void* data;
qse_ccls_is_t is;
qse_ccls_to_t to;
void* data;
};
/******/