*** empty log message ***

This commit is contained in:
hyung-hwan 2006-10-23 14:42:38 +00:00
parent 4d0847c229
commit 67625392a5
4 changed files with 131 additions and 85 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: err.c,v 1.1 2006-10-23 10:54:15 bacon Exp $
* $Id: err.c,v 1.2 2006-10-23 14:42:38 bacon Exp $
*/
#include <sse/lsp/lsp.h>
@ -7,9 +7,9 @@
static const sse_char_t* __errstr[] =
{
SSE_T("no error"),
SSE_T("out of memory"),
SSE_T("abort"),
SSE_T("end"),
SSE_T("memory"),
SSE_T("input not attached"),
SSE_T("input"),
SSE_T("output not attached"),

View File

@ -1,30 +1,72 @@
/*
* $Id: init.c,v 1.12 2006-10-22 13:10:46 bacon Exp $
* $Id: lsp.c,v 1.5 2006-10-23 14:42:38 bacon Exp $
*/
#include <sse/lsp/lsp.h>
#include <sse/lsp/prim.h>
#include <sse/bas/memory.h>
#include <sse/bas/assert.h>
#if defined(__BORLANDC__)
#pragma hdrstop
#define Library
#endif
#include <sse/lsp/lsp_i.h>
static int __add_builtin_prims (sse_lsp_t* lsp);
sse_lsp_t* sse_lsp_open (sse_lsp_t* lsp,
sse_lsp_t* sse_lsp_open (
const sse_lsp_syscas_t* syscas,
sse_size_t mem_ubound, sse_size_t mem_ubound_inc)
{
if (lsp == SSE_NULL) {
lsp = (sse_lsp_t*)sse_malloc(sse_sizeof(sse_lsp_t));
if (lsp == SSE_NULL) return lsp;
lsp->__dynamic = sse_true;
}
else lsp->__dynamic = sse_false;
sse_lsp_t* lsp;
if (sse_lsp_token_open(&lsp->token, 0) == SSE_NULL) {
if (lsp->__dynamic) sse_free (lsp);
if (syscas == SSE_NULL) return SSE_NULL;
if (syscas->malloc == SSE_NULL ||
syscas->free == SSE_NULL) return SSE_NULL;
if (syscas->is_upper == SSE_NULL ||
syscas->is_lower == SSE_NULL ||
syscas->is_alpha == SSE_NULL ||
syscas->is_digit == SSE_NULL ||
syscas->is_xdigit == SSE_NULL ||
syscas->is_alnum == SSE_NULL ||
syscas->is_space == SSE_NULL ||
syscas->is_print == SSE_NULL ||
syscas->is_graph == SSE_NULL ||
syscas->is_cntrl == SSE_NULL ||
syscas->is_punct == SSE_NULL ||
syscas->to_upper == SSE_NULL ||
syscas->to_lower == SSE_NULL) return SSE_NULL;
if (syscas->sprintf == SSE_NULL ||
syscas->dprintf == SSE_NULL ||
syscas->abort == SSE_NULL) return SSE_NULL;
#if defined(_WIN32) && defined(_DEBUG)
lsp = (sse_lsp_t*) malloc (sse_sizeof(sse_lsp_t));
#else
lsp = (sse_lsp_t*) syscas->malloc (
sse_sizeof(sse_lsp_t), syscas->custom_data);
#endif
if (lsp == SSE_NULL) return SSE_NULL;
/* it uses the built-in sse_lsp_memset because lsp is not
* fully initialized yet */
sse_lsp_memset (lsp, 0, sse_sizeof(sse_lsp_t));
if (syscas->memcpy == SSE_NULL)
{
sse_lsp_memcpy (&lsp->syscas, syscas, sse_sizeof(lsp->syscas));
lsp->syscas.memcpy = sse_lsp_memcpy;
}
else syscas->memcpy (&lsp->syscas, syscas, sse_sizeof(lsp->syscas));
if (syscas->memset == SSE_NULL) lsp->syscas.memset = sse_lsp_memset;
if (sse_lsp_token_open(&lsp->token, 0) == SSE_NULL)
{
if (lsp->__dynamic) SSE_LSP_FREE (lsp, lsp);
return SSE_NULL;
}
lsp->errnum = SSE_LSP_ERR_NONE;
lsp->errnum = SSE_LSP_ENOERR;
lsp->opt_undef_symbol = 1;
//lsp->opt_undef_symbol = 0;
@ -37,14 +79,14 @@ sse_lsp_t* sse_lsp_open (sse_lsp_t* lsp,
lsp->mem = sse_lsp_mem_new (mem_ubound, mem_ubound_inc);
if (lsp->mem == SSE_NULL) {
sse_lsp_token_close (&lsp->token);
if (lsp->__dynamic) sse_free (lsp);
if (lsp->__dynamic) SSE_LSP_FREE (lsp, lsp);
return SSE_NULL;
}
if (__add_builtin_prims(lsp) == -1) {
sse_lsp_mem_free (lsp->mem);
sse_lsp_token_close (&lsp->token);
if (lsp->__dynamic) sse_free (lsp);
if (lsp->__dynamic) SSE_LSP_FREE (lsp, lsp);
return SSE_NULL;
}
@ -56,17 +98,16 @@ sse_lsp_t* sse_lsp_open (sse_lsp_t* lsp,
void sse_lsp_close (sse_lsp_t* lsp)
{
sse_assert (lsp != SSE_NULL);
sse_lsp_mem_free (lsp->mem);
sse_lsp_token_close (&lsp->token);
if (lsp->__dynamic) sse_free (lsp);
if (lsp->__dynamic) SSE_LSP_FREE (lsp, lsp);
}
int sse_lsp_attach_input (sse_lsp_t* lsp, sse_lsp_io_t input, void* arg)
{
if (sse_lsp_detach_input(lsp) == -1) return -1;
sse_assert (lsp->input_func == SSE_NULL);
sse_lsp_assert (lsp, lsp->input_func == SSE_NULL);
if (input(SSE_LSP_IO_OPEN, arg, SSE_NULL, 0) == -1) {
/* TODO: set error number */
@ -98,7 +139,7 @@ int sse_lsp_attach_output (sse_lsp_t* lsp, sse_lsp_io_t output, void* arg)
{
if (sse_lsp_detach_output(lsp) == -1) return -1;
sse_assert (lsp->output_func == SSE_NULL);
sse_lsp_assert (lsp, lsp->output_func == SSE_NULL);
if (output(SSE_LSP_IO_OPEN, arg, SSE_NULL, 0) == -1) {
/* TODO: set error number */

View File

@ -1,28 +1,76 @@
/*
* $Id: lsp.h,v 1.22 2006-10-23 10:54:15 bacon Exp $
* $Id: lsp.h,v 1.23 2006-10-23 14:42:38 bacon Exp $
*/
#ifndef _SSE_LSP_LSP_H_
#define _SSE_LSP_LSP_H_
/*
* HEADER: Lisp
* A lisp-like embeddable language processor is provided for application
* development that requires simple scripting.
*
*/
#include <sse/types.h>
#include <sse/macros.h>
#include <sse/lsp/types.h>
#include <sse/lsp/token.h>
#include <sse/lsp/obj.h>
#include <sse/lsp/mem.h>
typedef struct sse_lsp_t sse_lsp_t;
typedef struct sse_lsp_obj_t sse_lsp_obj_t;
typedef struct sse_lsp_syscas_t sse_lsp_syscas_t;
typedef sse_ssize_t (*sse_lsp_io_t) (
int cmd, void* arg, sse_char_t* data, sse_size_t count);
struct sse_lsp_syscas_t
{
/* memory */
void* (*malloc) (sse_size_t n, void* custom_data);
void* (*realloc) (void* ptr, sse_size_t n, void* custom_data);
void (*free) (void* ptr, void* custom_data);
/* character class */
sse_bool_t (*is_upper) (sse_cint_t c);
sse_bool_t (*is_lower) (sse_cint_t c);
sse_bool_t (*is_alpha) (sse_cint_t c);
sse_bool_t (*is_digit) (sse_cint_t c);
sse_bool_t (*is_xdigit) (sse_cint_t c);
sse_bool_t (*is_alnum) (sse_cint_t c);
sse_bool_t (*is_space) (sse_cint_t c);
sse_bool_t (*is_print) (sse_cint_t c);
sse_bool_t (*is_graph) (sse_cint_t c);
sse_bool_t (*is_cntrl) (sse_cint_t c);
sse_bool_t (*is_punct) (sse_cint_t c);
sse_cint_t (*to_upper) (sse_cint_t c);
sse_cint_t (*to_lower) (sse_cint_t c);
/* utilities */
void* (*memcpy) (void* dst, const void* src, sse_size_t n);
void* (*memset) (void* dst, int val, sse_size_t n);
int (*sprintf) (sse_char_t* buf, sse_size_t size, sse_char_t* fmt, ...);
int (*dprintf) (sse_char_t* fmt, ...);
void (*abort) (void);
void* custom_data;
};
/* io function commands */
enum
{
SSE_LSP_ERR_NONE = 0,
SSE_LSP_IO_OPEN = 0,
SSE_LSP_IO_CLOSE = 1,
SSE_LSP_IO_READ = 2,
SSE_LSP_IO_WRITE = 3
};
/* option code */
enum
{
SSE_LSP_UNDEFSYMBOL = (1 << 0)
};
/* error code */
enum
{
SSE_LSP_ENOERR,
SSE_LSP_ENOMEM,
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,
@ -39,66 +87,23 @@ enum
SSE_LSP_ERR_UNDEF_SYMBOL,
SSE_LSP_ERR_EMPTY_BODY,
SSE_LSP_ERR_BAD_VALUE,
SSE_LSP_ERR_DIVIDE_BY_ZERO
};
/*
* TYPE: sse_lsp_t
* Defines a lisp processor type
*/
typedef struct sse_lsp_t sse_lsp_t;
/*
* TYPE: sse_lsp_io_t
* Defines an IO handler type
*/
typedef sse_ssize_t (*sse_lsp_io_t) (
int cmd, void* arg, sse_char_t* data, sse_size_t count);
enum
{
SSE_LSP_IO_OPEN,
SSE_LSP_IO_CLOSE,
SSE_LSP_IO_DATA
SSE_LSP_EDIVBYZERO
};
typedef sse_lsp_obj_t* (*sse_lsp_prim_t) (sse_lsp_t* lsp, sse_lsp_obj_t* obj);
struct sse_lsp_t
{
/* error number */
int errnum;
int opt_undef_symbol;
/* for read */
sse_cint_t curc;
sse_lsp_token_t token;
/* io functions */
sse_lsp_io_t input_func;
sse_lsp_io_t output_func;
void* input_arg;
void* output_arg;
/* security options */
sse_size_t max_eval_depth;
sse_size_t cur_eval_depth;
/* memory manager */
sse_lsp_mem_t* mem;
sse_bool_t __dynamic;
};
#ifdef __cplusplus
extern "C" {
#endif
sse_lsp_t* sse_lsp_open (
sse_lsp_t* lsp, sse_size_t mem_ubound, sse_size_t mem_ubound_inc);
const sse_lsp_syscas_t* syscas,
sse_size_t mem_ubound, sse_size_t mem_ubound_inc);
void sse_lsp_close (sse_lsp_t* lsp);
int sse_lsp_geterrnum (sse_lsp_t* awk);
int sse_lsp_geterrnum (sse_lsp_t* lsp);
int sse_lsp_attach_input (sse_lsp_t* lsp, sse_lsp_io_t input, void* arg);
int sse_lsp_detach_input (sse_lsp_t* lsp);

View File

@ -1,5 +1,5 @@
SRCS = name.c token.c array.c mem.c env.c err.c \
init.c read.c eval.c print.c \
SRCS = lsp.c name.c token.c array.c mem.c env.c err.c \
read.c eval.c print.c \
prim.c prim_prog.c prim_let.c prim_compar.c prim_math.c
OBJS = $(SRCS:.c=.obj)
OUT = xplsp.lib