- deleted unnecessary callback functions - on_loop_enter() & on_loop_exit()
- modified qse_awk_rtx_loop() and Awk::loop() to return the return value - deprecated the callback totally from the Awk class: may readd it in the future. - added POC code to pass arguments by reference for intrinsic functions. POC ok. more works needed for full support. not enabled.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 236 2009-07-16 08:27:53Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -255,7 +255,9 @@ protected:
|
||||
void retrieveError (Run* run);
|
||||
/*@}*/
|
||||
|
||||
protected:
|
||||
class NoSource;
|
||||
|
||||
public:
|
||||
/**
|
||||
* The Source class is an abstract class to encapsulate
|
||||
@ -677,6 +679,7 @@ public:
|
||||
static const char_t* EMPTY_STRING;
|
||||
};
|
||||
|
||||
public:
|
||||
/**
|
||||
* Defines an identifier of predefined global variables.
|
||||
* Awk::setGlobal and Awk::getGlobal can take one of these enumerators.
|
||||
@ -802,24 +805,26 @@ public:
|
||||
* @return a Run object on success, #QSE_NULL on failure
|
||||
*/
|
||||
Awk::Run* parse (
|
||||
Source& in, /**< script to parse */
|
||||
Source& out /**< deparsing target */
|
||||
Source& in, ///< script to parse
|
||||
Source& out ///< deparsing target
|
||||
);
|
||||
|
||||
/**
|
||||
* Executes the BEGIN block, pattern-action blocks, and the END block.
|
||||
* @return 0 on succes, -1 on failure
|
||||
*/
|
||||
int loop ();
|
||||
int loop (
|
||||
Value* ret ///< return value holder
|
||||
);
|
||||
|
||||
/**
|
||||
* Calls a function
|
||||
*/
|
||||
int call (
|
||||
const char_t* name,
|
||||
Value* ret,
|
||||
const Value* args,
|
||||
size_t nargs
|
||||
const char_t* name, ///< function name
|
||||
Value* ret, ///< return value holder
|
||||
const Value* args, ///< argument array
|
||||
size_t nargs ///< number of arguments
|
||||
);
|
||||
|
||||
/**
|
||||
@ -982,16 +987,6 @@ public:
|
||||
int deleteFunction (const char_t* name);
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Enables the run-time callback
|
||||
*/
|
||||
void enableRunCallback ();
|
||||
|
||||
/**
|
||||
* Disables the run-time callback
|
||||
*/
|
||||
void disableRunCallback ();
|
||||
|
||||
/**
|
||||
* @name Word Substitution
|
||||
*/
|
||||
@ -1058,11 +1053,6 @@ protected:
|
||||
virtual int nextConsole (Console& io) = 0;
|
||||
/*@}*/
|
||||
|
||||
// run-time callbacks
|
||||
virtual bool onLoopEnter (Run& run);
|
||||
virtual void onLoopExit (Run& run, const Value& ret);
|
||||
virtual void onStatement (Run& run, size_t line);
|
||||
|
||||
// primitive handlers
|
||||
virtual real_t pow (real_t x, real_t y) = 0;
|
||||
virtual int vsprintf (char_t* buf, size_t size,
|
||||
@ -1086,10 +1076,6 @@ protected:
|
||||
|
||||
static int functionHandler (rtx_t* rtx, const cstr_t* name);
|
||||
|
||||
static int onLoopEnter (rtx_t* run, void* data);
|
||||
static void onLoopExit (rtx_t* run, val_t* ret, void* data);
|
||||
static void onStatement (rtx_t* run, size_t line, void* data);
|
||||
|
||||
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,
|
||||
const char_t* fmt, ...);
|
||||
@ -1108,8 +1094,6 @@ protected:
|
||||
Source* sourceReader;
|
||||
Source* sourceWriter;
|
||||
|
||||
bool runCallback;
|
||||
|
||||
struct xstrs_t
|
||||
{
|
||||
xstrs_t (): ptr (QSE_NULL), len (0), capa (0) {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 235 2009-07-15 10:43:31Z hyunghwan.chung $
|
||||
* $Id: awk.h 236 2009-07-16 08:27:53Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -58,7 +58,9 @@
|
||||
* awk = qse_awk_open (mmgr, 0, prm); // create an interpreter
|
||||
* qse_awk_parse (awk, &sio); // parse a script
|
||||
* rtx = qse_awk_rtx_open (awk, 0, &rio, args); // create a runtime context
|
||||
* qse_awk_rtx_loop (rtx); // run a standard AWK loop
|
||||
* retv = qse_awk_rtx_loop (rtx); // run a standard AWK loop
|
||||
* if (retv != QSE_NULL)
|
||||
* qse_awk_rtx_refdownval (rtx, retv); // free return value
|
||||
* qse_awk_rtx_close (rtx); // destroy the runtime context
|
||||
* qse_awk_close (awk); // destroy the interpreter
|
||||
* @endcode
|
||||
@ -466,20 +468,6 @@ typedef struct qse_awk_rio_t qse_awk_rio_t;
|
||||
*/
|
||||
struct qse_awk_rcb_t
|
||||
{
|
||||
/**
|
||||
* called by qse_awk_rtx_loop() before entering pattern-action loop.
|
||||
* A @b BEGIN block is executed after this callback.
|
||||
*/
|
||||
int (*on_loop_enter) (
|
||||
qse_awk_rtx_t* rtx, void* udd);
|
||||
|
||||
/**
|
||||
* called by qse_awk_rtx_loop() when exiting pattern-action loop.
|
||||
* An @b END block is executed before this callback.
|
||||
*/
|
||||
void (*on_loop_exit) (
|
||||
qse_awk_rtx_t* rtx, qse_awk_val_t* ret, void* udd);
|
||||
|
||||
/**
|
||||
* called by qse_awk_rtx_loop() and qse_awk_rtx_call() for
|
||||
* each statement executed.
|
||||
@ -1304,22 +1292,25 @@ void qse_awk_rtx_close (
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_loop() function executes the BEGIN block, pattern-action
|
||||
* blocks and the END blocks in an AWk program. Multiple invocations of the
|
||||
* function for the lifetime of a runtime context is not desirable.
|
||||
* blocks and the END blocks in an AWk program. It returns the global return
|
||||
* value of which the reference count must be decremented when not necessary.
|
||||
* Multiple invocations of the function for the lifetime of a runtime context
|
||||
* is not desirable.
|
||||
*
|
||||
* The example shows typical usage of the function.
|
||||
* @code
|
||||
* The example shows typical usage of the function.
|
||||
* rtx = qse_awk_rtx_open (awk, 0, rio, QSE_NULL);
|
||||
* if (rtx != QSE_NULL)
|
||||
* {
|
||||
* qse_awk_rtx_loop (rtx);
|
||||
* qse_awk_rtx_close (rtx);
|
||||
* }
|
||||
* rtx = qse_awk_rtx_open (awk, 0, rio, QSE_NULL);
|
||||
* if (rtx != QSE_NULL)
|
||||
* {
|
||||
* retv = qse_awk_rtx_loop (rtx);
|
||||
* if (retv != QSE_NULL) qse_awk_rtx_refdownval (rtx, retv);
|
||||
* qse_awk_rtx_close (rtx);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @return 0 on success, -1 on failure.
|
||||
* @return return value on success, QSE_NULL on failure.
|
||||
*/
|
||||
int qse_awk_rtx_loop (
|
||||
qse_awk_val_t* qse_awk_rtx_loop (
|
||||
qse_awk_rtx_t* rtx /**< runtime context */
|
||||
);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: rex.h 203 2009-06-17 12:43:50Z hyunghwan.chung $
|
||||
* $Id: rex.h 236 2009-07-16 08:27:53Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -54,6 +54,7 @@
|
||||
*
|
||||
* @todo
|
||||
* - support \\n to refer to the nth matching substring
|
||||
* - change to adopt Thomson's NFA (http://swtch.com/~rsc/regexp/regexp1.html)
|
||||
*/
|
||||
|
||||
#define QSE_REX_NA(code) (*(qse_size_t*)(code))
|
||||
|
Reference in New Issue
Block a user