From ffe1527b0b82f7e6564991be0fa4750c92061310 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 7 Feb 2005 15:10:41 +0000 Subject: [PATCH] *** empty log message *** --- ase/lsp/lisp.c | 4 ++-- ase/lsp/lisp.h | 8 ++++---- ase/lsp/memory.c | 39 ++++++++++++++++++++------------------- ase/lsp/memory.h | 18 +++++++++--------- ase/lsp/object.h | 14 +++++++------- ase/lsp/token.c | 20 ++++++++++---------- ase/lsp/token.h | 10 +++++----- ase/lsp/types.h | 3 +-- ase/test/lsp/lisp.c | 5 +++++ 9 files changed, 63 insertions(+), 58 deletions(-) diff --git a/ase/lsp/lisp.c b/ase/lsp/lisp.c index 1766a14b..00d3e5c2 100644 --- a/ase/lsp/lisp.c +++ b/ase/lsp/lisp.c @@ -1,5 +1,5 @@ /* - * $Id: lisp.c,v 1.6 2005-02-05 05:43:55 bacon Exp $ + * $Id: lisp.c,v 1.7 2005-02-07 15:10:41 bacon Exp $ */ #include @@ -55,7 +55,7 @@ void xp_lisp_free (xp_lisp_t* lsp) free (lsp); } -int xp_lisp_error (xp_lisp_t* lsp, xp_lisp_char* buf, xp_size_t size) +int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size) { if (buf != XP_NULL || size == 0) return lsp->error; diff --git a/ase/lsp/lisp.h b/ase/lsp/lisp.h index 0a794132..c7cc1ce4 100644 --- a/ase/lsp/lisp.h +++ b/ase/lsp/lisp.h @@ -1,5 +1,5 @@ /* - * $Id: lisp.h,v 1.2 2005-02-04 16:00:37 bacon Exp $ + * $Id: lisp.h,v 1.3 2005-02-07 15:10:41 bacon Exp $ */ #ifndef _XP_LISP_LISP_H_ @@ -15,7 +15,7 @@ // NOTICE: the function of xp_lisp_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_lisp_cint*, void*); +typedef int (*xp_lisp_creader_t) (xp_cint_t*, void*); #define XP_LISP_ERR(lsp) ((lsp)->error) #define XP_LISP_ERR_NONE 0 @@ -43,7 +43,7 @@ struct xp_lisp_t int opt_undef_symbol; /* for read */ - xp_lisp_cint curc; + xp_cint_t curc; xp_lisp_creader_t creader; void* creader_extra; int creader_just_set; @@ -69,7 +69,7 @@ extern "C" { /* 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); -int xp_lisp_error (xp_lisp_t* lsp, xp_lisp_char* buf, xp_size_t size); +int xp_lisp_error (xp_lisp_t* lsp, xp_char_t* buf, xp_size_t size); /* read.c */ // TODO: move xp_lisp_set_creader to lsp.c diff --git a/ase/lsp/memory.c b/ase/lsp/memory.c index 75399997..b8572ace 100644 --- a/ase/lsp/memory.c +++ b/ase/lsp/memory.c @@ -1,5 +1,5 @@ /* - * $Id: memory.c,v 1.7 2005-02-05 06:28:13 bacon Exp $ + * $Id: memory.c,v 1.8 2005-02-07 15:10:41 bacon Exp $ */ #include @@ -55,9 +55,9 @@ xp_lisp_mem_t* xp_lisp_mem_new (xp_size_t ubound, xp_size_t ubound_inc) // initialize common object pointers mem->nil = xp_lisp_make_nil (mem); mem->t = xp_lisp_make_true (mem); - mem->quote = xp_lisp_make_symbol (mem,XP_TEXT("quote"), 5); - mem->lambda = xp_lisp_make_symbol (mem,XP_TEXT("lambda"), 6); - mem->macro = xp_lisp_make_symbol (mem,XP_TEXT("macro"), 5); + mem->quote = xp_lisp_make_symbol (mem, XP_TEXT("quote"), 5); + mem->lambda = xp_lisp_make_symbol (mem, XP_TEXT("lambda"), 6); + mem->macro = xp_lisp_make_symbol (mem, XP_TEXT("macro"), 5); if (mem->nil == XP_NULL || mem->t == XP_NULL || @@ -92,7 +92,7 @@ void xp_lisp_mem_free (xp_lisp_mem_t* mem) } static int xp_lisp_add_prim ( - xp_lisp_mem_t* mem, const xp_lisp_char* name, xp_size_t len, xp_lisp_pimpl_t prim) + xp_lisp_mem_t* mem, const xp_char_t* name, xp_size_t len, xp_lisp_pimpl_t prim) { xp_lisp_obj_t* n, * p; @@ -407,7 +407,8 @@ xp_lisp_obj_t* xp_lisp_make_float (xp_lisp_mem_t* mem, xp_lisp_float value) return obj; } -xp_lisp_obj_t* xp_lisp_make_symbol (xp_lisp_mem_t* mem, const xp_lisp_char* str, xp_size_t len) +xp_lisp_obj_t* xp_lisp_make_symbol ( + xp_lisp_mem_t* mem, const xp_char_t* str, xp_size_t len) { xp_lisp_obj_t* obj; @@ -421,7 +422,7 @@ xp_lisp_obj_t* xp_lisp_make_symbol (xp_lisp_mem_t* mem, const xp_lisp_char* str, // no such symbol found. create a new one obj = xp_lisp_allocate (mem, XP_LISP_OBJ_SYMBOL, - sizeof(xp_lisp_obj_symbol_t) + (len + 1) * sizeof(xp_lisp_char)); + sizeof(xp_lisp_obj_symbol_t) + (len + 1) * sizeof(xp_char_t)); if (obj == XP_NULL) return XP_NULL; // fill in the symbol buffer @@ -430,13 +431,13 @@ xp_lisp_obj_t* xp_lisp_make_symbol (xp_lisp_mem_t* mem, const xp_lisp_char* str, return obj; } -xp_lisp_obj_t* xp_lisp_make_string (xp_lisp_mem_t* mem, const xp_lisp_char* str, xp_size_t len) +xp_lisp_obj_t* xp_lisp_make_string (xp_lisp_mem_t* mem, const xp_char_t* str, xp_size_t len) { xp_lisp_obj_t* obj; // allocate memory for the string obj = xp_lisp_allocate (mem, XP_LISP_OBJ_STRING, - sizeof(xp_lisp_obj_string_t) + (len + 1) * sizeof(xp_lisp_char)); + sizeof(xp_lisp_obj_string_t) + (len + 1) * sizeof(xp_char_t)); if (obj == XP_NULL) return XP_NULL; // fill in the string buffer @@ -559,9 +560,9 @@ int xp_lisp_probe_args (xp_lisp_mem_t* mem, xp_lisp_obj_t* obj, xp_size_t* len) return 0; } -int xp_lisp_comp_symbol (xp_lisp_obj_t* obj, const xp_lisp_char* str) +int xp_lisp_comp_symbol (xp_lisp_obj_t* obj, const xp_char_t* str) { - xp_lisp_char* p; + xp_char_t* p; xp_size_t index, length; xp_assert (XP_LISP_TYPE(obj) == XP_LISP_OBJ_SYMBOL); @@ -579,9 +580,9 @@ int xp_lisp_comp_symbol (xp_lisp_obj_t* obj, const xp_lisp_char* str) return (*str == XP_CHAR('\0'))? 0: -1; } -int xp_lisp_comp_symbol2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t len) +int xp_lisp_comp_symbol2 (xp_lisp_obj_t* obj, const xp_char_t* str, xp_size_t len) { - xp_lisp_char* p; + xp_char_t* p; xp_size_t index, length; xp_assert (XP_LISP_TYPE(obj) == XP_LISP_OBJ_SYMBOL); @@ -600,9 +601,9 @@ int xp_lisp_comp_symbol2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t (length > len)? 1: 0; } -int xp_lisp_comp_string (xp_lisp_obj_t* obj, const xp_lisp_char* str) +int xp_lisp_comp_string (xp_lisp_obj_t* obj, const xp_char_t* str) { - xp_lisp_char* p; + xp_char_t* p; xp_size_t index, length; xp_assert (XP_LISP_TYPE(obj) == XP_LISP_OBJ_STRING); @@ -620,9 +621,9 @@ int xp_lisp_comp_string (xp_lisp_obj_t* obj, const xp_lisp_char* str) return (*str == XP_CHAR('\0'))? 0: -1; } -int xp_lisp_comp_string2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t len) +int xp_lisp_comp_string2 (xp_lisp_obj_t* obj, const xp_char_t* str, xp_size_t len) { - xp_lisp_char* p; + xp_char_t* p; xp_size_t index, length; xp_assert (XP_LISP_TYPE(obj) == XP_LISP_OBJ_STRING); @@ -641,14 +642,14 @@ int xp_lisp_comp_string2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t (length > len)? 1: 0; } -void xp_lisp_copy_string (xp_lisp_char* dst, const xp_lisp_char* str) +void xp_lisp_copy_string (xp_char_t* dst, const xp_char_t* str) { // the buffer pointed by dst should be big enough to hold str while (*str != XP_CHAR('\0')) *dst++ = *str++; *dst = XP_CHAR('\0'); } -void xp_lisp_copy_string2 (xp_lisp_char* dst, const xp_lisp_char* str, xp_size_t len) +void xp_lisp_copy_string2 (xp_char_t* dst, const xp_char_t* str, xp_size_t len) { // the buffer pointed by dst should be big enough to hold str while (len > 0) { diff --git a/ase/lsp/memory.h b/ase/lsp/memory.h index 7193f3da..9e6f6fc7 100644 --- a/ase/lsp/memory.h +++ b/ase/lsp/memory.h @@ -1,5 +1,5 @@ /* - * $Id: memory.h,v 1.2 2005-02-04 16:00:37 bacon Exp $ + * $Id: memory.h,v 1.3 2005-02-07 15:10:41 bacon Exp $ */ #ifndef _XP_LISP_MEM_H_ @@ -70,8 +70,8 @@ xp_lisp_obj_t* xp_lisp_make_nil (xp_lisp_mem_t* mem); xp_lisp_obj_t* xp_lisp_make_true (xp_lisp_mem_t* mem); xp_lisp_obj_t* xp_lisp_make_int (xp_lisp_mem_t* mem, xp_lisp_int value); xp_lisp_obj_t* xp_lisp_make_float (xp_lisp_mem_t* mem, xp_lisp_float value); -xp_lisp_obj_t* xp_lisp_make_symbol (xp_lisp_mem_t* mem, const xp_lisp_char* str, xp_size_t len); -xp_lisp_obj_t* xp_lisp_make_string (xp_lisp_mem_t* mem, const xp_lisp_char* str, xp_size_t len); +xp_lisp_obj_t* xp_lisp_make_symbol (xp_lisp_mem_t* mem, const xp_char_t* str, xp_size_t len); +xp_lisp_obj_t* xp_lisp_make_string (xp_lisp_mem_t* mem, const xp_char_t* str, xp_size_t len); xp_lisp_obj_t* xp_lisp_make_cons (xp_lisp_mem_t* mem, xp_lisp_obj_t* car, xp_lisp_obj_t* cdr); xp_lisp_obj_t* xp_lisp_make_func (xp_lisp_mem_t* mem, xp_lisp_obj_t* formal, xp_lisp_obj_t* body); xp_lisp_obj_t* xp_lisp_make_macro (xp_lisp_mem_t* mem, xp_lisp_obj_t* formal, xp_lisp_obj_t* body); @@ -86,12 +86,12 @@ xp_size_t xp_lisp_cons_len (xp_lisp_mem_t* mem, xp_lisp_obj_t* obj); int xp_lisp_probe_args (xp_lisp_mem_t* mem, xp_lisp_obj_t* obj, xp_size_t* len); // symbol and string operations -int xp_lisp_comp_symbol (xp_lisp_obj_t* obj, const xp_lisp_char* str); -int xp_lisp_comp_symbol2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t len); -int xp_lisp_comp_string (xp_lisp_obj_t* obj, const xp_lisp_char* str); -int xp_lisp_comp_string2 (xp_lisp_obj_t* obj, const xp_lisp_char* str, xp_size_t len); -void xp_lisp_copy_string (xp_lisp_char* dst, const xp_lisp_char* str); -void xp_lisp_copy_string2 (xp_lisp_char* dst, const xp_lisp_char* str, xp_size_t len); +int xp_lisp_comp_symbol (xp_lisp_obj_t* obj, const xp_char_t* str); +int xp_lisp_comp_symbol2 (xp_lisp_obj_t* obj, const xp_char_t* str, xp_size_t len); +int xp_lisp_comp_string (xp_lisp_obj_t* obj, const xp_char_t* str); +int xp_lisp_comp_string2 (xp_lisp_obj_t* obj, const xp_char_t* str, xp_size_t len); +void xp_lisp_copy_string (xp_char_t* dst, const xp_char_t* str); +void xp_lisp_copy_string2 (xp_char_t* dst, const xp_char_t* str, xp_size_t len); #ifdef __cplusplus } diff --git a/ase/lsp/object.h b/ase/lsp/object.h index 2dbf8140..5185091f 100644 --- a/ase/lsp/object.h +++ b/ase/lsp/object.h @@ -1,5 +1,5 @@ /* - * $Id: object.h,v 1.2 2005-02-04 16:00:37 bacon Exp $ + * $Id: object.h,v 1.3 2005-02-07 15:10:41 bacon Exp $ */ #ifndef _XP_LISP_OBJECT_H_ @@ -63,7 +63,7 @@ struct xp_lisp_obj_symbol_t XP_LISP_OBJ_HEADER; #ifdef __BORLANDC__ #else - xp_lisp_char buffer[0]; + xp_char_t buffer[0]; #endif }; @@ -72,7 +72,7 @@ struct xp_lisp_obj_string_t XP_LISP_OBJ_HEADER; #ifdef __BORLANDC__ #else - xp_lisp_char buffer[0]; + xp_char_t buffer[0]; #endif }; @@ -127,18 +127,18 @@ typedef struct xp_lisp_obj_prim_t xp_lisp_obj_prim_t; #define XP_LISP_FVALUE(x) (((xp_lisp_obj_float_t*)x)->value) #ifdef __BORLANDC__ -#define XP_LISP_SYMVALUE(x) ((xp_lisp_char*)(((xp_lisp_obj_symbol_t*)x) + 1)) +#define XP_LISP_SYMVALUE(x) ((xp_char_t*)(((xp_lisp_obj_symbol_t*)x) + 1)) #else #define XP_LISP_SYMVALUE(x) (((xp_lisp_obj_symbol_t*)x)->buffer) #endif -#define XP_LISP_SYMLEN(x) ((((xp_lisp_obj_symbol_t*)x)->size - sizeof(xp_lisp_obj_t)) / sizeof(xp_lisp_char) - 1) +#define XP_LISP_SYMLEN(x) ((((xp_lisp_obj_symbol_t*)x)->size - sizeof(xp_lisp_obj_t)) / sizeof(xp_char_t) - 1) #ifdef __BORLANDC__ -#define XP_LISP_STRVALUE(x) ((xp_lisp_char*)(((xp_lisp_obj_string_t*)x) + 1)) +#define XP_LISP_STRVALUE(x) ((xp_char_t*)(((xp_lisp_obj_string_t*)x) + 1)) #else #define XP_LISP_STRVALUE(x) (((xp_lisp_obj_string_t*)x)->buffer) #endif -#define XP_LISP_STRLEN(x) ((((xp_lisp_obj_string_t*)x)->size - sizeof(xp_lisp_obj_t)) / sizeof(xp_lisp_char) - 1) +#define XP_LISP_STRLEN(x) ((((xp_lisp_obj_string_t*)x)->size - sizeof(xp_lisp_obj_t)) / sizeof(xp_char_t) - 1) #define XP_LISP_CAR(x) (((xp_lisp_obj_cons_t*)x)->car) #define XP_LISP_CDR(x) (((xp_lisp_obj_cons_t*)x)->cdr) diff --git a/ase/lsp/token.c b/ase/lsp/token.c index 25cfd86b..725ade99 100644 --- a/ase/lsp/token.c +++ b/ase/lsp/token.c @@ -1,5 +1,5 @@ /* - * $Id: token.c,v 1.6 2005-02-05 05:43:55 bacon Exp $ + * $Id: token.c,v 1.7 2005-02-07 15:10:41 bacon Exp $ */ #include @@ -15,7 +15,7 @@ xp_lisp_token_t* xp_lisp_token_new (xp_size_t capacity) token = (xp_lisp_token_t*)xp_malloc (sizeof(xp_lisp_token_t)); if (token == XP_NULL) return XP_NULL; - token->buffer = (xp_lisp_char*)xp_malloc ((capacity + 1) * sizeof(xp_lisp_char)); + token->buffer = (xp_char_t*)xp_malloc ((capacity + 1) * sizeof(xp_char_t)); if (token->buffer == XP_NULL) { xp_free (token); return XP_NULL; @@ -37,12 +37,12 @@ void xp_lisp_token_free (xp_lisp_token_t* token) xp_free (token); } -int xp_lisp_token_addc (xp_lisp_token_t* token, xp_lisp_cint c) +int xp_lisp_token_addc (xp_lisp_token_t* token, xp_cint_t c) { if (token->size >= token->capacity) { // double the capacity. - xp_lisp_char* new_buffer = (xp_lisp_char*)realloc ( - token->buffer, (token->capacity * 2 + 1) * sizeof(xp_lisp_char)); + xp_char_t* new_buffer = (xp_char_t*)realloc ( + token->buffer, (token->capacity * 2 + 1) * sizeof(xp_char_t)); if (new_buffer == XP_NULL) return -1; token->buffer = new_buffer; token->capacity = token->capacity * 2; @@ -62,11 +62,11 @@ void xp_lisp_token_clear (xp_lisp_token_t* token) token->buffer[0] = XP_CHAR('\0'); } -xp_lisp_char* xp_lisp_token_transfer (xp_lisp_token_t* token, xp_size_t capacity) +xp_char_t* xp_lisp_token_transfer (xp_lisp_token_t* token, xp_size_t capacity) { - xp_lisp_char* old_buffer, * new_buffer; + xp_char_t* old_buffer, * new_buffer; - new_buffer = (xp_lisp_char*)xp_malloc((capacity + 1) * sizeof(xp_lisp_char)); + new_buffer = (xp_char_t*)xp_malloc((capacity + 1) * sizeof(xp_char_t)); if (new_buffer == XP_NULL) return XP_NULL; old_buffer = token->buffer; @@ -78,9 +78,9 @@ xp_lisp_char* xp_lisp_token_transfer (xp_lisp_token_t* token, xp_size_t capacity return old_buffer; } -int xp_lisp_token_compare (xp_lisp_token_t* token, const xp_lisp_char* str) +int xp_lisp_token_compare (xp_lisp_token_t* token, const xp_char_t* str) { - xp_lisp_char* p = token->buffer; + xp_char_t* p = token->buffer; xp_size_t index = 0; while (index < token->size) { diff --git a/ase/lsp/token.h b/ase/lsp/token.h index f6f0e029..7755fb96 100644 --- a/ase/lsp/token.h +++ b/ase/lsp/token.h @@ -1,5 +1,5 @@ /* - * $Id: token.h,v 1.3 2005-02-04 16:03:25 bacon Exp $ + * $Id: token.h,v 1.4 2005-02-07 15:10:41 bacon Exp $ */ #ifndef _XP_LISP_TOKEN_H_ @@ -16,7 +16,7 @@ struct xp_lisp_token_t xp_size_t capacity; xp_size_t size; - xp_lisp_char* buffer; + xp_char_t* buffer; }; typedef struct xp_lisp_token_t xp_lisp_token_t; @@ -27,10 +27,10 @@ extern "C" { xp_lisp_token_t* xp_lisp_token_new (xp_size_t capacity); void xp_lisp_token_free (xp_lisp_token_t* token); -int xp_lisp_token_addc (xp_lisp_token_t* token, xp_lisp_cint c); +int xp_lisp_token_addc (xp_lisp_token_t* token, xp_cint_t c); void xp_lisp_token_clear (xp_lisp_token_t* token); -xp_lisp_char* xp_lisp_token_transfer (xp_lisp_token_t* token, xp_size_t capacity); -int xp_lisp_token_compare (xp_lisp_token_t* token, const xp_lisp_char* str); +xp_char_t* xp_lisp_token_transfer (xp_lisp_token_t* token, xp_size_t capacity); +int xp_lisp_token_compare (xp_lisp_token_t* token, const xp_char_t* str); #ifdef __cplusplus } diff --git a/ase/lsp/types.h b/ase/lsp/types.h index adef958e..4a4b1091 100644 --- a/ase/lsp/types.h +++ b/ase/lsp/types.h @@ -1,5 +1,5 @@ /* - * $Id: types.h,v 1.3 2005-02-04 16:23:34 bacon Exp $ + * $Id: types.h,v 1.4 2005-02-07 15:10:41 bacon Exp $ */ #ifndef _XP_LISP_TYPES_H_ @@ -8,7 +8,6 @@ #include #include -typedef xp_char_t xp_lisp_char; typedef xp_cint_t xp_lisp_cint; typedef xp_long_t xp_lisp_int; typedef xp_real_t xp_lisp_float; diff --git a/ase/test/lsp/lisp.c b/ase/test/lsp/lisp.c index c382d319..d4998dbc 100644 --- a/ase/test/lsp/lisp.c +++ b/ase/test/lsp/lisp.c @@ -33,6 +33,8 @@ int to_int (const xp_char_t* str) return r; } +#include + int xp_main (int argc, xp_char_t* argv[]) { xp_lisp_t* lisp; @@ -41,6 +43,9 @@ int xp_main (int argc, xp_char_t* argv[]) #ifdef LINUX mtrace (); #endif + +setlocale (LC_ALL, ""); + if (argc != 3) { xp_fprintf (xp_stderr, XP_TEXT("usage: %s mem_ubound mem_ubound_inc\n"), argv[0]); return -1;