qse/ase/lsp/lsp.h

208 lines
4.1 KiB
C
Raw Normal View History

2005-02-04 15:39:11 +00:00
/*
2006-10-22 13:10:46 +00:00
* $Id: lsp.h,v 1.21 2006-10-22 13:10:46 bacon Exp $
2005-02-04 15:39:11 +00:00
*/
2006-10-22 13:10:46 +00:00
#ifndef _SSE_LSP_LSP_H_
#define _SSE_LSP_LSP_H_
2005-09-17 17:50:45 +00:00
/*
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
2006-10-22 13:10:46 +00:00
#include <sse/lsp/types.h>
#include <sse/lsp/token.h>
#include <sse/lsp/obj.h>
#include <sse/lsp/mem.h>
2005-02-04 15:39:11 +00:00
2006-10-22 13:10:46 +00:00
#define SSE_LSP_ERR(lsp) ((lsp)->errnum)
2005-09-18 08:10:50 +00:00
enum
{
2006-10-22 13:10:46 +00:00
SSE_LSP_ERR_NONE = 0,
SSE_LSP_ERR_ABORT,
SSE_LSP_ERR_END,
SSE_LSP_ERR_MEMORY,
SSE_LSP_ERR_INPUT_NOT_ATTACHED,
SSE_LSP_ERR_INPUT,
SSE_LSP_ERR_OUTPUT_NOT_ATTACHED,
SSE_LSP_ERR_OUTPUT,
SSE_LSP_ERR_SYNTAX,
SSE_LSP_ERR_BAD_ARG,
SSE_LSP_ERR_WRONG_ARG,
SSE_LSP_ERR_TOO_FEW_ARGS,
SSE_LSP_ERR_TOO_MANY_ARGS,
SSE_LSP_ERR_UNDEF_FUNC,
SSE_LSP_ERR_BAD_FUNC,
SSE_LSP_ERR_DUP_FORMAL,
SSE_LSP_ERR_BAD_SYMBOL,
SSE_LSP_ERR_UNDEF_SYMBOL,
SSE_LSP_ERR_EMPTY_BODY,
SSE_LSP_ERR_BAD_VALUE,
SSE_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
/*
2006-10-22 13:10:46 +00:00
* TYPE: sse_lsp_t
2005-09-19 03:05:37 +00:00
* Defines a lisp processor type
2005-09-18 12:20:43 +00:00
*/
2006-10-22 13:10:46 +00:00
typedef struct sse_lsp_t sse_lsp_t;
2005-09-18 12:20:43 +00:00
2005-09-18 13:06:43 +00:00
/*
2006-10-22 13:10:46 +00:00
* TYPE: sse_lsp_io_t
2005-09-19 03:05:37 +00:00
* Defines an IO handler type
2005-09-18 13:06:43 +00:00
*/
2006-10-22 13:10:46 +00:00
typedef sse_ssize_t (*sse_lsp_io_t) (
int cmd, void* arg, sse_char_t* data, sse_size_t count);
2005-09-18 13:06:43 +00:00
2005-09-18 10:18:35 +00:00
enum
{
2006-10-22 13:10:46 +00:00
SSE_LSP_IO_OPEN,
SSE_LSP_IO_CLOSE,
SSE_LSP_IO_DATA
2005-09-18 10:18:35 +00:00
};
2005-09-19 03:05:37 +00:00
/*
2006-10-22 13:10:46 +00:00
* TYPEDEF: sse_lsp_prim_t
2005-09-19 03:05:37 +00:00
* Defines a primitive type
*/
2006-10-22 13:10:46 +00:00
typedef sse_lsp_obj_t* (*sse_lsp_prim_t) (sse_lsp_t* lsp, sse_lsp_obj_t* obj);
2005-09-19 03:05:37 +00:00
2006-10-22 13:10:46 +00:00
struct sse_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 */
2006-10-22 13:10:46 +00:00
sse_cint_t curc;
sse_lsp_token_t token;
2005-02-04 15:39:11 +00:00
2005-09-18 10:18:35 +00:00
/* io functions */
2006-10-22 13:10:46 +00:00
sse_lsp_io_t input_func;
sse_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 */
2006-10-22 13:10:46 +00:00
sse_size_t max_eval_depth;
sse_size_t cur_eval_depth;
2005-09-20 08:05:32 +00:00
2005-02-04 15:39:11 +00:00
/* memory manager */
2006-10-22 13:10:46 +00:00
sse_lsp_mem_t* mem;
sse_bool_t __dynamic;
2005-02-04 15:39:11 +00:00
};
#ifdef __cplusplus
extern "C" {
#endif
2005-09-17 17:50:45 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_open
2005-09-18 11:34:35 +00:00
* Instantiates a lisp processor
*
* PARAMETERS:
2006-10-22 13:10:46 +00:00
* lsp - pointer to lisp processor space or SSE_NULL
2005-09-18 11:34:35 +00:00
* mem_ubound - memory upper bound
* mem_ubound_inc - memory increment
2005-09-17 17:50:45 +00:00
*/
2006-10-22 13:10:46 +00:00
sse_lsp_t* sse_lsp_open (sse_lsp_t* lsp,
sse_size_t mem_ubound, sse_size_t mem_ubound_inc);
2005-09-18 10:18:35 +00:00
2005-09-17 17:50:45 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_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
*/
2006-10-22 13:10:46 +00:00
void sse_lsp_close (sse_lsp_t* lsp);
2005-09-17 17:42:21 +00:00
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_error
2005-09-18 10:18:35 +00:00
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_error (sse_lsp_t* lsp, sse_char_t* buf, sse_size_t size);
2005-02-04 15:39:11 +00:00
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_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
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_attach_input (sse_lsp_t* lsp, sse_lsp_io_t input, void* arg);
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_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
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_detach_input (sse_lsp_t* lsp);
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_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
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_attach_output (sse_lsp_t* lsp, sse_lsp_io_t output, void* arg);
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_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
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_detach_output (sse_lsp_t* lsp);
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_read
2005-09-18 14:05:16 +00:00
* Reads a lisp expression
2005-09-18 10:18:35 +00:00
*/
2006-10-22 13:10:46 +00:00
sse_lsp_obj_t* sse_lsp_read (sse_lsp_t* lsp);
2005-02-04 15:39:11 +00:00
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_eval
2005-09-18 14:05:16 +00:00
* Evaluates a lisp object
2005-09-18 10:18:35 +00:00
*/
2006-10-22 13:10:46 +00:00
sse_lsp_obj_t* sse_lsp_eval (sse_lsp_t* lsp, sse_lsp_obj_t* obj);
2005-02-04 15:39:11 +00:00
2005-09-18 10:18:35 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_print
2005-09-18 14:05:16 +00:00
* Prints a lisp object
2005-09-18 10:18:35 +00:00
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_print (sse_lsp_t* lsp, const sse_lsp_obj_t* obj);
2005-02-04 15:39:11 +00:00
2005-09-18 14:05:16 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_add_prim
2005-09-18 14:05:16 +00:00
* Adds a user-defined primitive
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_add_prim (sse_lsp_t* lsp, const sse_char_t* name, sse_lsp_prim_t prim);
2005-09-18 14:05:16 +00:00
/*
2006-10-22 13:10:46 +00:00
* FUNCTION: sse_lsp_remove_prim
2005-09-18 14:05:16 +00:00
* Removes a user-defined primitive
*/
2006-10-22 13:10:46 +00:00
int sse_lsp_remove_prim (sse_lsp_t* lsp, const sse_char_t* name);
2005-09-18 14:05:16 +00:00
2005-02-04 15:39:11 +00:00
#ifdef __cplusplus
}
#endif
#endif