2005-02-04 15:39:11 +00:00
|
|
|
/*
|
2005-10-19 15:44:29 +00:00
|
|
|
* $Id: lsp.h,v 1.19 2005-10-19 15:44:29 bacon Exp $
|
2005-02-04 15:39:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-17 17:50:45 +00:00
|
|
|
#ifndef _XP_LSP_LSP_H_
|
|
|
|
#define _XP_LSP_LSP_H_
|
|
|
|
|
|
|
|
/*
|
2005-09-18 10:23:19 +00:00
|
|
|
* HEADER: Lisp
|
2005-09-19 14:57:09 +00:00
|
|
|
* A lisp-like embeddable language processor is provided for application
|
2005-09-18 11:34:35 +00:00
|
|
|
* development that requires simple scripting.
|
2005-09-17 17:50:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-05-28 13:34:26 +00:00
|
|
|
#include <xp/lsp/types.h>
|
|
|
|
#include <xp/lsp/token.h>
|
2005-09-18 11:54:23 +00:00
|
|
|
#include <xp/lsp/obj.h>
|
2005-09-18 11:34:35 +00:00
|
|
|
#include <xp/lsp/mem.h>
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
#define XP_LSP_ERR(lsp) ((lsp)->errnum)
|
2005-09-18 08:10:50 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
XP_LSP_ERR_NONE = 0,
|
|
|
|
XP_LSP_ERR_ABORT,
|
|
|
|
XP_LSP_ERR_END,
|
2005-09-23 13:27:54 +00:00
|
|
|
XP_LSP_ERR_MEMORY,
|
2005-09-18 10:18:35 +00:00
|
|
|
XP_LSP_ERR_INPUT_NOT_ATTACHED,
|
|
|
|
XP_LSP_ERR_INPUT,
|
|
|
|
XP_LSP_ERR_OUTPUT_NOT_ATTACHED,
|
|
|
|
XP_LSP_ERR_OUTPUT,
|
2005-09-18 08:10:50 +00:00
|
|
|
XP_LSP_ERR_SYNTAX,
|
|
|
|
XP_LSP_ERR_BAD_ARG,
|
|
|
|
XP_LSP_ERR_WRONG_ARG,
|
|
|
|
XP_LSP_ERR_TOO_FEW_ARGS,
|
|
|
|
XP_LSP_ERR_TOO_MANY_ARGS,
|
|
|
|
XP_LSP_ERR_UNDEF_FUNC,
|
|
|
|
XP_LSP_ERR_BAD_FUNC,
|
|
|
|
XP_LSP_ERR_DUP_FORMAL,
|
|
|
|
XP_LSP_ERR_BAD_SYMBOL,
|
|
|
|
XP_LSP_ERR_UNDEF_SYMBOL,
|
|
|
|
XP_LSP_ERR_EMPTY_BODY,
|
2005-09-21 12:04:05 +00:00
|
|
|
XP_LSP_ERR_BAD_VALUE,
|
|
|
|
XP_LSP_ERR_DIVIDE_BY_ZERO
|
2005-09-18 08:10:50 +00:00
|
|
|
};
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 12:20:43 +00:00
|
|
|
/*
|
2005-10-19 15:44:29 +00:00
|
|
|
* TYPE: xp_lsp_t
|
2005-09-19 03:05:37 +00:00
|
|
|
* Defines a lisp processor type
|
2005-09-18 12:20:43 +00:00
|
|
|
*/
|
|
|
|
typedef struct xp_lsp_t xp_lsp_t;
|
|
|
|
|
2005-09-18 13:06:43 +00:00
|
|
|
/*
|
2005-10-19 15:44:29 +00:00
|
|
|
* TYPE: xp_lsp_io_t
|
2005-09-19 03:05:37 +00:00
|
|
|
* Defines an IO handler type
|
2005-09-18 13:06:43 +00:00
|
|
|
*/
|
|
|
|
typedef xp_ssize_t (*xp_lsp_io_t) (
|
|
|
|
int cmd, void* arg, xp_char_t* data, xp_size_t count);
|
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
XP_LSP_IO_OPEN,
|
|
|
|
XP_LSP_IO_CLOSE,
|
2005-09-18 13:06:43 +00:00
|
|
|
XP_LSP_IO_DATA
|
2005-09-18 10:18:35 +00:00
|
|
|
};
|
|
|
|
|
2005-09-19 03:05:37 +00:00
|
|
|
/*
|
|
|
|
* TYPEDEF: xp_lsp_prim_t
|
|
|
|
* Defines a primitive type
|
|
|
|
*/
|
|
|
|
typedef xp_lsp_obj_t* (*xp_lsp_prim_t) (xp_lsp_t* lsp, xp_lsp_obj_t* obj);
|
|
|
|
|
2005-09-17 17:50:45 +00:00
|
|
|
struct xp_lsp_t
|
2005-02-04 15:39:11 +00:00
|
|
|
{
|
|
|
|
/* error number */
|
2005-09-18 10:18:35 +00:00
|
|
|
int errnum;
|
2005-02-04 15:39:11 +00:00
|
|
|
int opt_undef_symbol;
|
|
|
|
|
|
|
|
/* for read */
|
2005-02-07 15:10:41 +00:00
|
|
|
xp_cint_t curc;
|
2005-09-18 10:18:35 +00:00
|
|
|
xp_lsp_token_t token;
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
/* io functions */
|
|
|
|
xp_lsp_io_t input_func;
|
|
|
|
xp_lsp_io_t output_func;
|
2005-09-18 13:06:43 +00:00
|
|
|
void* input_arg;
|
|
|
|
void* output_arg;
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-20 08:05:32 +00:00
|
|
|
/* security options */
|
|
|
|
xp_size_t max_eval_depth;
|
|
|
|
xp_size_t cur_eval_depth;
|
|
|
|
|
2005-02-04 15:39:11 +00:00
|
|
|
/* memory manager */
|
2005-09-17 17:50:45 +00:00
|
|
|
xp_lsp_mem_t* mem;
|
2005-09-17 17:42:21 +00:00
|
|
|
xp_bool_t __malloced;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-17 17:50:45 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_open
|
2005-09-18 11:34:35 +00:00
|
|
|
* Instantiates a lisp processor
|
|
|
|
*
|
|
|
|
* PARAMETERS:
|
|
|
|
* lsp - pointer to lisp processor space or XP_NULL
|
|
|
|
* mem_ubound - memory upper bound
|
|
|
|
* mem_ubound_inc - memory increment
|
2005-09-17 17:50:45 +00:00
|
|
|
*/
|
2005-09-20 14:38:39 +00:00
|
|
|
xp_lsp_t* xp_lsp_open (xp_lsp_t* lsp,
|
2005-09-17 17:42:21 +00:00
|
|
|
xp_size_t mem_ubound, xp_size_t mem_ubound_inc);
|
2005-09-18 10:18:35 +00:00
|
|
|
|
2005-09-17 17:50:45 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_close
|
2005-09-18 11:34:35 +00:00
|
|
|
* Destroys a lisp processor
|
2005-09-17 17:50:45 +00:00
|
|
|
*
|
|
|
|
* PARAMETERS:
|
|
|
|
* lsp - the pointer to the lisp object
|
|
|
|
*/
|
2005-09-20 14:38:39 +00:00
|
|
|
void xp_lsp_close (xp_lsp_t* lsp);
|
2005-09-17 17:42:21 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_error
|
|
|
|
*/
|
2005-09-17 17:50:45 +00:00
|
|
|
int xp_lsp_error (xp_lsp_t* lsp, xp_char_t* buf, xp_size_t size);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_attach_input
|
2005-09-18 14:05:16 +00:00
|
|
|
* Attaches an input handler function
|
|
|
|
*
|
|
|
|
* PARAMETERS:
|
|
|
|
* lsp - the lisp processor
|
|
|
|
* input - input handler function
|
|
|
|
* arg - user data to be passed to the input handler
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -1 on failure
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
2005-09-18 13:06:43 +00:00
|
|
|
int xp_lsp_attach_input (xp_lsp_t* lsp, xp_lsp_io_t input, void* arg);
|
2005-09-18 10:18:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_detach_input
|
2005-09-18 14:05:16 +00:00
|
|
|
* Detaches an input handler function
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -1 on failure
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
|
|
|
int xp_lsp_detach_input (xp_lsp_t* lsp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_attach_output
|
2005-09-18 14:05:16 +00:00
|
|
|
* Attaches an output handler function
|
|
|
|
*
|
|
|
|
* PARAMETERS:
|
|
|
|
* lsp - the lisp processor
|
|
|
|
* output - output handler function
|
|
|
|
* arg - user data to be passed to the output handler
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -1 on failure
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
2005-09-18 13:06:43 +00:00
|
|
|
int xp_lsp_attach_output (xp_lsp_t* lsp, xp_lsp_io_t output, void* arg);
|
2005-09-18 10:18:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_detach_output
|
2005-09-18 14:05:16 +00:00
|
|
|
* Detaches an output handler function
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -1 on failure
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
|
|
|
int xp_lsp_detach_output (xp_lsp_t* lsp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_read
|
2005-09-18 14:05:16 +00:00
|
|
|
* Reads a lisp expression
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
2005-09-17 17:50:45 +00:00
|
|
|
xp_lsp_obj_t* xp_lsp_read (xp_lsp_t* lsp);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_eval
|
2005-09-18 14:05:16 +00:00
|
|
|
* Evaluates a lisp object
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
2005-09-17 17:50:45 +00:00
|
|
|
xp_lsp_obj_t* xp_lsp_eval (xp_lsp_t* lsp, xp_lsp_obj_t* obj);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 10:18:35 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_print
|
2005-09-18 14:05:16 +00:00
|
|
|
* Prints a lisp object
|
2005-09-18 10:18:35 +00:00
|
|
|
*/
|
|
|
|
int xp_lsp_print (xp_lsp_t* lsp, const xp_lsp_obj_t* obj);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-09-18 14:05:16 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_add_prim
|
|
|
|
* Adds a user-defined primitive
|
|
|
|
*/
|
|
|
|
int xp_lsp_add_prim (xp_lsp_t* lsp, const xp_char_t* name, xp_lsp_prim_t prim);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: xp_lsp_remove_prim
|
|
|
|
* Removes a user-defined primitive
|
|
|
|
*/
|
2005-09-19 03:05:37 +00:00
|
|
|
int xp_lsp_remove_prim (xp_lsp_t* lsp, const xp_char_t* name);
|
2005-09-18 14:05:16 +00:00
|
|
|
|
2005-02-04 15:39:11 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|