diff --git a/ase/lsp/array.c b/ase/lsp/array.c index 61b5d555..5b3d368e 100644 --- a/ase/lsp/array.c +++ b/ase/lsp/array.c @@ -1,5 +1,5 @@ /* - * $Id: array.c,v 1.8 2006-10-22 13:10:45 bacon Exp $ + * $Id: array.c,v 1.9 2006-10-23 10:57:59 bacon Exp $ */ #include @@ -11,10 +11,10 @@ sse_lsp_array_t* sse_lsp_array_new (sse_size_t capacity) sse_lsp_array_t* array; sse_assert (capacity > 0); - array = (sse_lsp_array_t*)malloc (sizeof(sse_lsp_array_t)); + array = (sse_lsp_array_t*) sse_malloc (sizeof(sse_lsp_array_t)); if (array == SSE_NULL) return SSE_NULL; - array->buffer = (void**)malloc (capacity + 1); + array->buffer = (void**) sse_malloc (capacity + 1); if (array->buffer == SSE_NULL) { free (array); return SSE_NULL; @@ -90,7 +90,7 @@ void** sse_lsp_array_yield (sse_lsp_array_t* array, sse_size_t capacity) { void** old_buffer, ** new_buffer; - new_buffer = (void**)malloc(capacity + 1); + new_buffer = (void**) sse_malloc (capacity + 1); if (new_buffer == SSE_NULL) return SSE_NULL; old_buffer = array->buffer; diff --git a/ase/lsp/err.c b/ase/lsp/err.c new file mode 100644 index 00000000..da4a4f17 --- /dev/null +++ b/ase/lsp/err.c @@ -0,0 +1,45 @@ +/* + * $Id: err.c,v 1.1 2006-10-23 10:54:15 bacon Exp $ + */ + +#include + +static const sse_char_t* __errstr[] = +{ + SSE_T("no error"), + SSE_T("abort"), + SSE_T("end"), + SSE_T("memory"), + SSE_T("input not attached"), + SSE_T("input"), + SSE_T("output not attached"), + SSE_T("output"), + SSE_T("syntax"), + SSE_T("bad arguments"), + SSE_T("wrong arguments"), + SSE_T("too few arguments"), + SSE_T("too many arguments"), + SSE_T("undefined function"), + SSE_T("bad function"), + SSE_T("duplicate formal"), + SSE_T("bad symbol"), + SSE_T("undefined symbol"), + SSE_T("empty body"), + SSE_T("bad value"), + SSE_T("divide by zero") +}; + +int sse_lsp_geterrnum (sse_lsp_t* lsp) +{ + return lsp->errnum; +} + +const sse_char_t* sse_lsp_geterrstr (int errnum) +{ + if (errnum >= 0 && errnum < sse_countof(__errstr)) + { + return __errstr[errnum]; + } + + return SSE_T("unknown error"); +} diff --git a/ase/lsp/error.c b/ase/lsp/error.c deleted file mode 100644 index aa26b2ec..00000000 --- a/ase/lsp/error.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * $Id: error.c,v 1.3 2006-10-22 13:10:45 bacon Exp $ - */ - -#include -#include - -static const sse_char_t* __errstr[] = -{ - SSE_TEXT("no error"), - SSE_TEXT("abort"), - SSE_TEXT("end"), - SSE_TEXT("memory"), - SSE_TEXT("input not attached"), - SSE_TEXT("input"), - SSE_TEXT("output not attached"), - SSE_TEXT("output"), - SSE_TEXT("syntax"), - SSE_TEXT("bad arguments"), - SSE_TEXT("wrong arguments"), - SSE_TEXT("too few arguments"), - SSE_TEXT("too many arguments"), - SSE_TEXT("undefined function"), - SSE_TEXT("bad function"), - SSE_TEXT("duplicate formal"), - SSE_TEXT("bad symbol"), - SSE_TEXT("undefined symbol"), - SSE_TEXT("empty body"), - SSE_TEXT("bad value"), - SSE_TEXT("divide by zero") -}; - -int sse_lsp_error (sse_lsp_t* lsp, sse_char_t* buf, sse_size_t size) -{ - if (buf == SSE_NULL || size == 0) return lsp->errnum; - sse_strxcpy (buf, size, __errstr[lsp->errnum]); - return lsp->errnum; -} - diff --git a/ase/lsp/lsp.dsp b/ase/lsp/lsp.dsp index d5fa5b8a..8daaa14b 100644 --- a/ase/lsp/lsp.dsp +++ b/ase/lsp/lsp.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "../.." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -65,8 +65,8 @@ LIB32=link.exe -lib # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" MTL=midl.exe -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../.." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -95,7 +95,7 @@ SOURCE=.\env.c # End Source File # Begin Source File -SOURCE=.\error.c +SOURCE=.\err.c # End Source File # Begin Source File diff --git a/ase/lsp/lsp.h b/ase/lsp/lsp.h index 1e403b3a..fdae79fa 100644 --- a/ase/lsp/lsp.h +++ b/ase/lsp/lsp.h @@ -1,5 +1,5 @@ /* - * $Id: lsp.h,v 1.21 2006-10-22 13:10:46 bacon Exp $ + * $Id: lsp.h,v 1.22 2006-10-23 10:54:15 bacon Exp $ */ #ifndef _SSE_LSP_LSP_H_ @@ -17,7 +17,6 @@ #include #include -#define SSE_LSP_ERR(lsp) ((lsp)->errnum) enum { SSE_LSP_ERR_NONE = 0, @@ -63,10 +62,6 @@ enum SSE_LSP_IO_DATA }; -/* - * TYPEDEF: sse_lsp_prim_t - * Defines a primitive type - */ typedef sse_lsp_obj_t* (*sse_lsp_prim_t) (sse_lsp_t* lsp, sse_lsp_obj_t* obj); struct sse_lsp_t @@ -98,108 +93,29 @@ struct sse_lsp_t extern "C" { #endif -/* - * FUNCTION: sse_lsp_open - * Instantiates a lisp processor - * - * PARAMETERS: - * lsp - pointer to lisp processor space or SSE_NULL - * mem_ubound - memory upper bound - * mem_ubound_inc - memory increment - */ -sse_lsp_t* sse_lsp_open (sse_lsp_t* lsp, - sse_size_t mem_ubound, sse_size_t mem_ubound_inc); +sse_lsp_t* sse_lsp_open ( + sse_lsp_t* lsp, sse_size_t mem_ubound, sse_size_t mem_ubound_inc); -/* - * FUNCTION: sse_lsp_close - * Destroys a lisp processor - * - * PARAMETERS: - * lsp - the pointer to the lisp object - */ void sse_lsp_close (sse_lsp_t* lsp); -/* - * FUNCTION: sse_lsp_error - */ -int sse_lsp_error (sse_lsp_t* lsp, sse_char_t* buf, sse_size_t size); +int sse_lsp_geterrnum (sse_lsp_t* awk); -/* - * FUNCTION: sse_lsp_attach_input - * 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 - */ int sse_lsp_attach_input (sse_lsp_t* lsp, sse_lsp_io_t input, void* arg); - -/* - * FUNCTION: sse_lsp_detach_input - * Detaches an input handler function - * - * RETURNS: - * 0 on success, -1 on failure - */ int sse_lsp_detach_input (sse_lsp_t* lsp); -/* - * FUNCTION: sse_lsp_attach_output - * 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 - */ int sse_lsp_attach_output (sse_lsp_t* lsp, sse_lsp_io_t output, void* arg); - -/* - * FUNCTION: sse_lsp_detach_output - * Detaches an output handler function - * - * RETURNS: - * 0 on success, -1 on failure - */ int sse_lsp_detach_output (sse_lsp_t* lsp); -/* - * FUNCTION: sse_lsp_read - * Reads a lisp expression - */ sse_lsp_obj_t* sse_lsp_read (sse_lsp_t* lsp); - -/* - * FUNCTION: sse_lsp_eval - * Evaluates a lisp object - */ sse_lsp_obj_t* sse_lsp_eval (sse_lsp_t* lsp, sse_lsp_obj_t* obj); - -/* - * FUNCTION: sse_lsp_print - * Prints a lisp object - */ int sse_lsp_print (sse_lsp_t* lsp, const sse_lsp_obj_t* obj); -/* - * FUNCTION: sse_lsp_add_prim - * Adds a user-defined primitive - */ int sse_lsp_add_prim (sse_lsp_t* lsp, const sse_char_t* name, sse_lsp_prim_t prim); - -/* - * FUNCTION: sse_lsp_remove_prim - * Removes a user-defined primitive - */ int sse_lsp_remove_prim (sse_lsp_t* lsp, const sse_char_t* name); + +const sse_char_t* sse_lsp_geterrstr (int errnum); + #ifdef __cplusplus } #endif diff --git a/ase/lsp/makefile.cl b/ase/lsp/makefile.cl index c1a13d73..63985b21 100644 --- a/ase/lsp/makefile.cl +++ b/ase/lsp/makefile.cl @@ -1,18 +1,18 @@ -SRCS = name.c token.c array.c mem.c env.c error.c \ +SRCS = name.c token.c array.c mem.c env.c err.c \ init.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 CC = cl -CFLAGS = /nologo /MT /GX /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. +LD = link +CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. -DSSE_CHAR_IS_WCHAR all: $(OBJS) - link -lib @<< + $(LD) -lib @<< /nologo /out:$(OUT) $(OBJS) << - clean: del $(OBJS) $(OUT) *.obj diff --git a/ase/lsp/mem.c b/ase/lsp/mem.c index 032ce863..a173e254 100644 --- a/ase/lsp/mem.c +++ b/ase/lsp/mem.c @@ -1,5 +1,5 @@ /* - * $Id: mem.c,v 1.8 2006-10-22 13:10:46 bacon Exp $ + * $Id: mem.c,v 1.9 2006-10-23 10:57:59 bacon Exp $ */ #include @@ -15,7 +15,7 @@ sse_lsp_mem_t* sse_lsp_mem_new (sse_size_t ubound, sse_size_t ubound_inc) sse_size_t i; // allocate memory - mem = (sse_lsp_mem_t*)sse_malloc (sse_sizeof(sse_lsp_mem_t)); + mem = (sse_lsp_mem_t*) sse_malloc (sse_sizeof(sse_lsp_mem_t)); if (mem == SSE_NULL) return SSE_NULL; // create a new root environment frame @@ -160,11 +160,11 @@ sse_lsp_obj_t* sse_lsp_alloc (sse_lsp_mem_t* mem, int type, sse_size_t size) if (mem->count >= mem->ubound) return SSE_NULL; } - obj = (sse_lsp_obj_t*)sse_malloc (size); + obj = (sse_lsp_obj_t*) sse_malloc (size); if (obj == SSE_NULL) { sse_lsp_garbage_collect (mem); - obj = (sse_lsp_obj_t*)sse_malloc (size); + obj = (sse_lsp_obj_t*) sse_malloc (size); if (obj == SSE_NULL) return SSE_NULL; }