*** empty log message ***

This commit is contained in:
hyung-hwan 2005-09-17 17:50:45 +00:00
parent f0448b3e43
commit bfeb8dac69
2 changed files with 54 additions and 33 deletions

View File

@ -1,21 +1,21 @@
/*
* $Id: lsp.c,v 1.1 2005-09-17 17:42:21 bacon Exp $
* $Id: lsp.c,v 1.2 2005-09-17 17:50:45 bacon Exp $
*/
#include <xp/lsp/lisp.h>
#include <xp/bas/memory.h>
#include <xp/bas/assert.h>
xp_lisp_t* xp_lisp_open (xp_lisp_t* lsp, xp_size_t mem_ubound, xp_size_t mem_ubound_inc)
xp_lisp_t*xp_lsp_open xp_lsp_t* lsp, xp_size_t mem_ubound, xp_size_t mem_ubound_inc)
{
if (lsp == XP_NULL) {
lsp = (xp_lisp_t*)xp_malloc(sizeof(xp_lisp_t));
lsp = xp_lsp_t*)xp_malloc(sizeofxp_lsp_t));
if (lsp == XP_NULL) return lsp;
lsp->__malloced = xp_true;
}
else lsp->__malloced = xp_false;
lsp->token = xp_lisp_token_new (256);
lsp->token =xp_lsp_token_new (256);
if (lsp->token == XP_NULL) {
xp_free (lsp);
return XP_NULL;
@ -31,16 +31,16 @@ xp_lisp_t* xp_lisp_open (xp_lisp_t* lsp, xp_size_t mem_ubound, xp_size_t mem_ubo
lsp->creader_just_set = 0;
lsp->outstream = xp_stdout;
lsp->mem = xp_lisp_mem_new (mem_ubound, mem_ubound_inc);
lsp->mem =xp_lsp_mem_new (mem_ubound, mem_ubound_inc);
if (lsp->mem == XP_NULL) {
xp_lisp_token_free (lsp->token);
xp_lsp_token_free (lsp->token);
free (lsp);
return XP_NULL;
}
if (xp_lisp_add_prims (lsp->mem) == -1) {
xp_lisp_mem_free (lsp->mem);
xp_lisp_token_free (lsp->token);
if xp_lsp_add_prims (lsp->mem) == -1) {
xp_lsp_mem_free (lsp->mem);
xp_lsp_token_free (lsp->token);
free (lsp);
return XP_NULL;
}
@ -48,16 +48,16 @@ xp_lisp_t* xp_lisp_open (xp_lisp_t* lsp, xp_size_t mem_ubound, xp_size_t mem_ubo
return lsp;
}
void xp_lisp_free (xp_lisp_t* lsp)
voidxp_lsp_free xp_lsp_t* lsp)
{
xp_assert (lsp != XP_NULL);
xp_lisp_mem_free (lsp->mem);
xp_lisp_token_free (lsp->token);
xp_lsp_mem_free (lsp->mem);
xp_lsp_token_free (lsp->token);
if (lsp->__malloced) xp_free (lsp);
}
int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size)
intxp_lsp_error xp_lsp_t* lsp, xp_char_t* buf, xp_size_t size)
{
if (buf != XP_NULL || size == 0) return lsp->error;
@ -66,7 +66,7 @@ int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size)
switch (lsp->error) {
default:
xp_lisp_copy_string (buf, size, "unknown error");
xp_lsp_copy_string (buf, size, "unknown error");
}
*/

View File

@ -1,9 +1,16 @@
/*
* $Id: lsp.h,v 1.1 2005-09-17 17:42:21 bacon Exp $
* $Id: lsp.h,v 1.2 2005-09-17 17:50:45 bacon Exp $
*/
#ifndef _XP_LSP_LISP_H_
#define _XP_LSP_LISP_H_
#ifndef _XP_LSP_LSP_H_
#define _XP_LSP_LSP_H_
/*
* HEADER: xp_lsp_t
* A lisp-like embeddable language processor is provied for application
* development that requires scripting.
*
*/
#include <xp/lsp/types.h>
#include <xp/lsp/token.h>
@ -12,10 +19,10 @@
#include <xp/bas/stdio.h> // TODO: may have to remove dependency on stdio?
// NOTICE: the function of xp_lisp_creader_t must return -1 on error
// NOTICE: the function of xp_lsp_creader_t must return -1 on error
// and 0 on success. the first argument must be set to
// XP_LISP_END_CHAR at the end of input.
typedef int (*xp_lisp_creader_t) (xp_cint_t*, void*);
typedef int (*xp_lsp_creader_t) (xp_cint_t*, void*);
#define XP_LISP_ERR(lsp) ((lsp)->error)
#define XP_LISP_ERR_NONE 0
@ -36,7 +43,11 @@ typedef int (*xp_lisp_creader_t) (xp_cint_t*, void*);
#define XP_LISP_ERR_EMPTY_BODY 15
#define XP_LISP_ERR_BAD_VALUE 16
struct xp_lisp_t
/*
* STRUCT: xp_lsp_t
* Defines the lisp object
*/
struct xp_lsp_t
{
/* error number */
int error;
@ -44,10 +55,10 @@ struct xp_lisp_t
/* for read */
xp_cint_t curc;
xp_lisp_creader_t creader;
xp_lsp_creader_t creader;
void* creader_extra;
int creader_just_set;
xp_lisp_token_t* token;
xp_lsp_token_t* token;
/* for eval */
xp_size_t max_eval_depth; // TODO:....
@ -57,33 +68,43 @@ struct xp_lisp_t
XP_FILE* outstream;
/* memory manager */
xp_lisp_mem_t* mem;
xp_lsp_mem_t* mem;
xp_bool_t __malloced;
};
typedef struct xp_lisp_t xp_lisp_t;
typedef struct xp_lsp_t xp_lsp_t;
#ifdef __cplusplus
extern "C" {
#endif
/* lsp.c */
xp_lisp_t* xp_lisp_open (xp_lisp_t* lisp,
/*
* FUNCTION: xp_lsp_open
* Instantiate the lisp object
*/
xp_lsp_t* xp_lsp_open (xp_lsp_t* lisp,
xp_size_t mem_ubound, xp_size_t mem_ubound_inc);
void xp_lisp_close (xp_lisp_t* lsp);
/*
* FUNCTION: xp_lsp_close
* Destroys the lisp object
*
* PARAMETERS:
* lsp - the pointer to the lisp object
*/
void xp_lsp_close (xp_lsp_t* lsp);
int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size);
int xp_lsp_error (xp_lsp_t* lsp, xp_char_t* buf, xp_size_t size);
/* read.c */
// TODO: move xp_lisp_set_creader to lsp.c
void xp_lisp_set_creader (xp_lisp_t* lsp, xp_lisp_creader_t func, void* extra);
xp_lisp_obj_t* xp_lisp_read (xp_lisp_t* lsp);
// TODO: move xp_lsp_set_creader to lsp.c
void xp_lsp_set_creader (xp_lsp_t* lsp, xp_lsp_creader_t func, void* extra);
xp_lsp_obj_t* xp_lsp_read (xp_lsp_t* lsp);
/* eval.c */
xp_lisp_obj_t* xp_lisp_eval (xp_lisp_t* lsp, xp_lisp_obj_t* obj);
xp_lsp_obj_t* xp_lsp_eval (xp_lsp_t* lsp, xp_lsp_obj_t* obj);
/* print.c */
void xp_lisp_print (xp_lisp_t* lsp, xp_lisp_obj_t* obj);
void xp_lsp_print (xp_lsp_t* lsp, xp_lsp_obj_t* obj);
#ifdef __cplusplus
}