qse/ase/lsp/lsp.h

153 lines
2.7 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2005-09-18 12:20:43 +00:00
* $Id: lsp.h,v 1.9 2005-09-18 12:20:43 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-17 17:50:45 +00:00
* A lisp-like embeddable language processor is provied 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,
XP_LSP_ERR_MEM,
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,
XP_LSP_ERR_BAD_VALUE
};
2005-02-04 15:39:11 +00:00
2005-09-18 12:20:43 +00:00
/*
* TYPEDEF: xp_lsp_t
* Defines a lisp processor
*/
typedef struct xp_lsp_t xp_lsp_t;
typedef int (*xp_lsp_io_t) (xp_lsp_t* lsp, int cmd, void* arg);
2005-09-18 10:18:35 +00:00
enum
{
XP_LSP_IO_OPEN,
XP_LSP_IO_CLOSE,
XP_LSP_IO_CHAR,
XP_LSP_IO_STR
};
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
/* for eval */
xp_size_t max_eval_depth; // TODO:....
xp_size_t eval_depth;
2005-09-18 10:18:35 +00:00
/* io functions */
xp_lsp_io_t input_func;
xp_lsp_io_t output_func;
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
*/
xp_lsp_t* xp_lsp_open (xp_lsp_t* lisp,
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
*/
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
*/
int xp_lsp_attach_input (xp_lsp_t* lsp, xp_lsp_io_t input);
/*
* FUNCTION: xp_lsp_detach_input
*/
int xp_lsp_detach_input (xp_lsp_t* lsp);
/*
* FUNCTION: xp_lsp_attach_output
*/
int xp_lsp_attach_output (xp_lsp_t* lsp, xp_lsp_io_t output);
/*
* FUNCTION: xp_lsp_detach_output
*/
int xp_lsp_detach_output (xp_lsp_t* lsp);
/*
* FUNCTION: xp_lsp_read
*/
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-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
*/
int xp_lsp_print (xp_lsp_t* lsp, const xp_lsp_obj_t* obj);
2005-02-04 15:39:11 +00:00
#ifdef __cplusplus
}
#endif
#endif