From 450c413990b92437e63cb2b95fdcbf92f0749e63 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 22 May 2005 10:32:37 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/kernel.st | 24 ++++++++++++ ase/stx/token.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ ase/stx/token.h | 45 +++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 ase/stx/kernel.st create mode 100644 ase/stx/token.c create mode 100644 ase/stx/token.h diff --git a/ase/stx/kernel.st b/ase/stx/kernel.st new file mode 100644 index 00000000..c50ff22d --- /dev/null +++ b/ase/stx/kernel.st @@ -0,0 +1,24 @@ +nil subclass: #Object + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: ''. + +Object subclass: #Behavior + instanceVariableNames: 'name instanceSpec methods superclass variables classVariables poolDictionaries category' + classVariableNames: '' + poolDictionaries: ''. + +Behavior subclass: #Class + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: ''. + +Behavior subclass: #Metaclass + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: ''. + +Object subclass: #Block + instanceVariableNames: 'context argCount argLoc bytePointer' + classVariableNames: '' + poolDictionaries; ''. diff --git a/ase/stx/token.c b/ase/stx/token.c new file mode 100644 index 00000000..436e8c57 --- /dev/null +++ b/ase/stx/token.c @@ -0,0 +1,99 @@ +/* + * $Id: token.c,v 1.1 2005-05-22 10:32:37 bacon Exp $ + */ + +#include +#include + +xp_stx_token_t* xp_stx_token_new ( + xp_stx_token_t* token, xp_stx_word_t capacity) +{ + xp_stx_assert (capacity > 0); + + if (token == XP_NULL) { + token = (xp_stx_token_t*) + xp_stx_malloc (sizeof(xp_stx_token_t)); + if (token == XP_NULL) return XP_NULL; + token->__malloced = xp_true; + } + else token->__malloced = xp_false; + + token->buffer = (xp_char_t*) + xp_stx_malloc ((capacity + 1) * sizeof(xp_char_t)); + if (token->buffer == XP_NULL) { + if (token->__malloced) xp_stx_free (token); + return XP_NULL; + } + + /* + token->ivalue = 0; + token->fvalue = .0; + */ + + token->size = 0; + token->capacity = capacity; + token->buffer[0] = XP_STX_CHAR('\0'); + + return token; +} + +void xp_stx_token_close (xp_stx_token_t* token) +{ + xp_stx_free (token->buffer); + if (token->__malloced) xp_stx_free (token); +} + +int xp_stx_token_addc (xp_stx_token_t* token, xp_cint_t c) +{ + if (token->size >= token->capacity) { + // double the capacity. + 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; + } + + token->buffer[token->size++] = c; + token->buffer[token->size] = XP_STX_CHAR('\0'); + return 0; +} + +void xp_stx_token_clear (xp_stx_token_t* token) +{ + token->ivalue = 0; + token->fvalue = .0; + + token->size = 0; + token->buffer[0] = XP_STX_CHAR('\0'); +} + +xp_char_t* xp_stx_token_transfer (xp_stx_token_t* token, xp_size_t capacity) +{ + xp_char_t* old_buffer, * new_buffer; + + 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; + token->buffer = new_buffer; + token->size = 0; + token->capacity = capacity; + token->buffer[0] = XP_STX_CHAR('\0'); + + return old_buffer; +} + +int xp_stx_token_compare (xp_stx_token_t* token, const xp_char_t* str) +{ + xp_char_t* p = token->buffer; + xp_size_t index = 0; + + while (index < token->size) { + if (*p > *str) return 1; + if (*p < *str) return -1; + index++; p++; str++; + } + + return (*str == XP_STX_CHAR('\0'))? 0: -1; +} diff --git a/ase/stx/token.h b/ase/stx/token.h new file mode 100644 index 00000000..03e472f1 --- /dev/null +++ b/ase/stx/token.h @@ -0,0 +1,45 @@ +/* + * $Id: token.h,v 1.1 2005-05-22 10:32:37 bacon Exp $ + */ + +#ifndef _XP_STX_TOKEN_H_ +#define _XP_STX_TOKEN_H_ + +#include + +struct xp_stx_token_t +{ + int type; + + /* + xp_stx_int_t ivalue; + xp_stx_real_t fvalue; + */ + + xp_size_t capacity; + xp_size_t size; + xp_char_t* buffer; + + xp_bool_t __malloced; +}; + +typedef struct xp_stx_token_t xp_stx_token_t; + +#ifdef __cplusplus +extern "C" { +#endif + +xp_stx_token_t* xp_stx_token_open ( + xp_stx_token_t* token, xp_stx_word_t capacity); +void xp_stx_token_close (xp_stx_token_t* token); + +int xp_stx_token_addc (xp_stx_token_t* token, xp_cint_t c); +void xp_stx_token_clear (xp_stx_token_t* token); +xp_char_t* xp_stx_token_transfer (xp_stx_token_t* token, xp_size_t capacity); +int xp_stx_token_compare (xp_stx_token_t* token, const xp_char_t* str); + +#ifdef __cplusplus +} +#endif + +#endif