2005-02-04 15:39:11 +00:00
|
|
|
/*
|
2005-05-28 13:34:26 +00:00
|
|
|
* $Id: lisp.h,v 1.5 2005-05-28 13:34:26 bacon Exp $
|
2005-02-04 15:39:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-05-28 13:34:26 +00:00
|
|
|
#ifndef _XP_LSP_LISP_H_
|
|
|
|
#define _XP_LSP_LISP_H_
|
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>
|
|
|
|
#include <xp/lsp/object.h>
|
|
|
|
#include <xp/lsp/memory.h>
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-04-24 07:48:16 +00:00
|
|
|
#include <xp/bas/stdio.h> // TODO: may have to remove dependency on stdio?
|
2005-02-04 16:00:37 +00:00
|
|
|
|
2005-02-04 15:39:11 +00:00
|
|
|
// NOTICE: the function of xp_lisp_creader_t must return -1 on error
|
|
|
|
// and 0 on success. the first argument must be set to
|
2005-02-04 16:00:37 +00:00
|
|
|
// XP_LISP_END_CHAR at the end of input.
|
2005-02-07 15:10:41 +00:00
|
|
|
typedef int (*xp_lisp_creader_t) (xp_cint_t*, void*);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
2005-02-04 16:00:37 +00:00
|
|
|
#define XP_LISP_ERR(lsp) ((lsp)->error)
|
|
|
|
#define XP_LISP_ERR_NONE 0
|
|
|
|
#define XP_LISP_ERR_ABORT 1
|
|
|
|
#define XP_LISP_ERR_END 2
|
|
|
|
#define XP_LISP_ERR_MEM 3
|
|
|
|
#define XP_LISP_ERR_READ 4
|
|
|
|
#define XP_LISP_ERR_SYNTAX 5
|
|
|
|
#define XP_LISP_ERR_BAD_ARG 6
|
|
|
|
#define XP_LISP_ERR_WRONG_ARG 7
|
|
|
|
#define XP_LISP_ERR_TOO_FEW_ARGS 8
|
|
|
|
#define XP_LISP_ERR_TOO_MANY_ARGS 9
|
|
|
|
#define XP_LISP_ERR_UNDEF_FUNC 10
|
|
|
|
#define XP_LISP_ERR_BAD_FUNC 11
|
|
|
|
#define XP_LISP_ERR_DUP_FORMAL 12
|
|
|
|
#define XP_LISP_ERR_BAD_SYMBOL 13
|
|
|
|
#define XP_LISP_ERR_UNDEF_SYMBOL 14
|
|
|
|
#define XP_LISP_ERR_EMPTY_BODY 15
|
|
|
|
#define XP_LISP_ERR_BAD_VALUE 16
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
struct xp_lisp_t
|
|
|
|
{
|
|
|
|
/* error number */
|
|
|
|
int error;
|
|
|
|
int opt_undef_symbol;
|
|
|
|
|
|
|
|
/* for read */
|
2005-02-07 15:10:41 +00:00
|
|
|
xp_cint_t curc;
|
2005-02-04 16:00:37 +00:00
|
|
|
xp_lisp_creader_t creader;
|
|
|
|
void* creader_extra;
|
|
|
|
int creader_just_set;
|
2005-02-04 15:39:11 +00:00
|
|
|
xp_lisp_token_t* token;
|
|
|
|
|
|
|
|
/* for eval */
|
|
|
|
xp_size_t max_eval_depth; // TODO:....
|
|
|
|
xp_size_t eval_depth;
|
|
|
|
|
|
|
|
/* for print */
|
2005-02-04 16:00:37 +00:00
|
|
|
XP_FILE* outstream;
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
/* memory manager */
|
2005-02-04 16:00:37 +00:00
|
|
|
xp_lisp_mem_t* mem;
|
2005-02-04 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct xp_lisp_t xp_lisp_t;
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* lsp.c */
|
|
|
|
xp_lisp_t* xp_lisp_new (xp_size_t mem_ubound, xp_size_t mem_ubound_inc);
|
|
|
|
void xp_lisp_free (xp_lisp_t* lsp);
|
2005-02-07 15:10:41 +00:00
|
|
|
int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size);
|
2005-02-04 15:39:11 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* eval.c */
|
|
|
|
xp_lisp_obj_t* xp_lisp_eval (xp_lisp_t* lsp, xp_lisp_obj_t* obj);
|
|
|
|
|
|
|
|
/* print.c */
|
|
|
|
void xp_lisp_print (xp_lisp_t* lsp, xp_lisp_obj_t* obj);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|