*** empty log message ***

This commit is contained in:
hyung-hwan 2005-06-12 16:22:47 +00:00
parent 2433bcb17b
commit 34578ca3ba
8 changed files with 242 additions and 124 deletions

View File

@ -1,5 +1,5 @@
SRCS = stx.c memory.c object.c symbol.c class.c \
hash.c misc.c context.c token.c parser.c bootstrp.c
hash.c misc.c context.c name.c token.c parser.c bootstrp.c
OBJS = $(SRCS:.c=.o)
OUT = libxpstx.a

View File

@ -1,7 +1,7 @@
SRCS = stx.c memory.c object.c symbol.c class.c \
hash.c misc.c context.c token.c parser.c bootstrp.c
hash.c misc.c context.c name.c token.c parser.c bootstrp.c
OBJS = stx.obj memory.obj object.obj symbol.obj class.obj \
hash.obj misc.obj context.obj token.obj parser.obj bootstrp.obj
hash.obj misc.obj context.obj name.obj token.obj parser.obj bootstrp.obj
OUT = xpstx.lib
CC = lcc

151
ase/stx/name.c Normal file
View File

@ -0,0 +1,151 @@
/*
* $Id: name.c,v 1.1 2005-06-12 16:22:03 bacon Exp $
*/
#include <xp/stx/name.h>
#include <xp/stx/misc.h>
xp_stx_name_t* xp_stx_name_open (
xp_stx_name_t* name, xp_word_t capacity)
{
if (capacity == 0)
capacity = xp_countof(name->static_buffer) - 1;
if (name == XP_NULL) {
name = (xp_stx_name_t*)
xp_malloc (xp_sizeof(xp_stx_name_t));
if (name == XP_NULL) return XP_NULL;
name->__malloced = xp_true;
}
else name->__malloced = xp_false;
if (capacity < xp_countof(name->static_buffer)) {
name->buffer = name->static_buffer;
}
else {
name->buffer = (xp_char_t*)
xp_malloc ((capacity + 1) * xp_sizeof(xp_char_t));
if (name->buffer == XP_NULL) {
if (name->__malloced) xp_free (name);
return XP_NULL;
}
}
/*
name->ivalue = 0;
name->fvalue = .0;
*/
name->size = 0;
name->capacity = capacity;
name->buffer[0] = XP_CHAR('\0');
return name;
}
void xp_stx_name_close (xp_stx_name_t* name)
{
if (name->capacity >= xp_countof(name->static_buffer)) {
xp_assert (name->buffer != name->static_buffer);
xp_free (name->buffer);
}
if (name->__malloced) xp_free (name);
}
int xp_stx_name_addc (xp_stx_name_t* name, xp_cint_t c)
{
if (name->size >= name->capacity) {
/* double the capacity. */
xp_size_t new_capacity = name->capacity * 2;
if (new_capacity >= xp_countof(name->static_buffer)) {
xp_char_t* space;
if (name->capacity < xp_countof(name->static_buffer)) {
space = (xp_char_t*)xp_malloc (
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
/* don't need to copy up to the terminating null */
xp_memcpy (space, name->buffer,
name->capacity * xp_sizeof(xp_char_t));
}
else {
space = (xp_char_t*)xp_realloc (name->buffer,
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
}
name->buffer = space;
}
name->capacity = new_capacity;
}
name->buffer[name->size++] = c;
name->buffer[name->size] = XP_CHAR('\0');
return 0;
}
int xp_stx_name_adds (xp_stx_name_t* name, const xp_char_t* s)
{
while (*s != XP_CHAR('\0')) {
if (xp_stx_name_addc(name, *s) == -1) return -1;
s++;
}
return 0;
}
void xp_stx_name_clear (xp_stx_name_t* name)
{
name->size = 0;
name->buffer[0] = XP_CHAR('\0');
}
xp_char_t* xp_stx_name_yield (xp_stx_name_t* name, xp_word_t capacity)
{
xp_char_t* old_buffer, * new_buffer;
if (capacity == 0)
capacity = xp_countof(name->static_buffer) - 1;
if (name->capacity < xp_countof(name->static_buffer)) {
old_buffer = (xp_char_t*)
xp_malloc((name->capacity + 1) * xp_sizeof(xp_char_t));
if (old_buffer == XP_NULL) return XP_NULL;
xp_memcpy (old_buffer, name->buffer,
(name->capacity + 1) * xp_sizeof(xp_char_t));
}
else old_buffer = name->buffer;
if (capacity < xp_countof(name->static_buffer)) {
new_buffer = name->static_buffer;
}
else {
new_buffer = (xp_char_t*)
xp_malloc((capacity + 1) * xp_sizeof(xp_char_t));
if (new_buffer == XP_NULL) return XP_NULL;
}
name->buffer = new_buffer;
name->size = 0;
name->capacity = capacity;
name->buffer[0] = XP_CHAR('\0');
return old_buffer;
}
int xp_stx_name_compare (xp_stx_name_t* name, const xp_char_t* str)
{
xp_char_t* p = name->buffer;
xp_word_t index = 0;
while (index < name->size) {
if (*p > *str) return 1;
if (*p < *str) return -1;
index++; p++; str++;
}
return (*str == XP_CHAR('\0'))? 0: -1;
}

39
ase/stx/name.h Normal file
View File

@ -0,0 +1,39 @@
/*
* $Id: name.h,v 1.1 2005-06-12 16:22:03 bacon Exp $
*/
#ifndef _XP_STX_NAME_H_
#define _XP_STX_NAME_H_
#include <xp/stx/stx.h>
struct xp_stx_name_t
{
xp_word_t capacity;
xp_word_t size;
xp_char_t* buffer;
xp_char_t static_buffer[128];
xp_bool_t __malloced;
};
typedef struct xp_stx_name_t xp_stx_name_t;
#ifdef __cplusplus
extern "C" {
#endif
xp_stx_name_t* xp_stx_name_open (
xp_stx_name_t* name, xp_word_t capacity);
void xp_stx_name_close (xp_stx_name_t* name);
int xp_stx_name_addc (xp_stx_name_t* name, xp_cint_t c);
int xp_stx_name_adds (xp_stx_name_t* name, const xp_char_t* s);
void xp_stx_name_clear (xp_stx_name_t* name);
xp_char_t* xp_stx_name_yield (xp_stx_name_t* name, xp_word_t capacity);
int xp_stx_name_compare (xp_stx_name_t* name, const xp_char_t* str);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,9 +1,8 @@
/*
* $Id: parser.c,v 1.29 2005-06-12 16:07:23 bacon Exp $
* $Id: parser.c,v 1.30 2005-06-12 16:22:03 bacon Exp $
*/
#include <xp/stx/parser.h>
#include <xp/stx/token.h>
#include <xp/stx/misc.h>
static int __parse_method (
@ -43,7 +42,13 @@ xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser, xp_stx_t* stx)
}
else parser->__malloced = xp_false;
if (xp_stx_name_open (&parser->method_name, 0) == XP_NULL) {
if (parser->__malloced) xp_free (parser);
return XP_NULL;
}
if (xp_stx_token_open (&parser->token, 0) == XP_NULL) {
xp_stx_name_close (&parser->method_name);
if (parser->__malloced) xp_free (parser);
return XP_NULL;
}
@ -67,6 +72,7 @@ void xp_stx_parser_close (xp_stx_parser_t* parser)
xp_free (parser->argument[--parser->argument_count]);
}
xp_stx_name_close (&parser->method_name);
xp_stx_token_close (&parser->token);
if (parser->__malloced) xp_free (parser);
}
@ -184,7 +190,7 @@ static int __parse_unary_pattern (xp_stx_parser_t* parser)
{
/* TODO: check if the method name exists */
if (xp_stx_name_adds(
&parser->method_name, parser->token.buffer) == -1) {
&parser->method_name, parser->token.name.buffer) == -1) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1;
}
@ -197,7 +203,7 @@ static int __parse_binary_pattern (xp_stx_parser_t* parser)
{
/* TODO: check if the method name exists */
if (xp_stx_name_adds(
&parser->method_name, parser->token.buffer) == -1) {
&parser->method_name, parser->token.name.buffer) == -1) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1;
}
@ -230,7 +236,7 @@ static int __parse_keyword_pattern (xp_stx_parser_t* parser)
{
do {
if (xp_stx_name_adds(
&parser->method_name, parser->token.buffer) == -1) {
&parser->method_name, parser->token.name.buffer) == -1) {
parser->error_code = XP_STX_PARSER_ERROR_MEMORY;
return -1;
}
@ -261,6 +267,7 @@ static int __parse_keyword_pattern (xp_stx_parser_t* parser)
/* TODO: check if the method name exists */
/* if it exists, collapse arguments */
xp_printf (XP_TEXT("METHOD NAME ==> [%s]\n"), parser->method_name.buffer);
return 0;
}
@ -269,8 +276,8 @@ static inline xp_bool_t __is_vbar_token (const xp_stx_token_t* token)
{
return
token->type == XP_STX_TOKEN_BINARY &&
token->size == 1 &&
token->buffer[0] == XP_CHAR('|');
token->name.size == 1 &&
token->name.buffer[0] == XP_CHAR('|');
}
static int __parse_temporaries (xp_stx_parser_t* parser)
@ -279,7 +286,7 @@ static int __parse_temporaries (xp_stx_parser_t* parser)
GET_TOKEN (parser);
while (parser->token.type == XP_STX_TOKEN_IDENT) {
xp_printf (XP_TEXT("temporary: %s\n"), parser->token.buffer);
xp_printf (XP_TEXT("temporary: %s\n"), parser->token.name.buffer);
GET_TOKEN (parser);
}
if (!__is_vbar_token(&parser->token)) {
@ -344,14 +351,14 @@ static int __parse_expression (xp_stx_parser_t* parser)
*/
if (parser->token.type == XP_STX_TOKEN_IDENT) {
xp_printf (XP_TEXT("identifier......[%s]\n"), parser->token.buffer);
xp_printf (XP_TEXT("identifier......[%s]\n"), parser->token.name.buffer);
GET_TOKEN (parser);
}
else if (parser->token.type == XP_STX_TOKEN_CHARLIT ||
parser->token.type == XP_STX_TOKEN_STRLIT ||
parser->token.type == XP_STX_TOKEN_NUMLIT) {
/* more literals - array symbol #xxx #(1 2 3) */
xp_printf (XP_TEXT("literal......[%s]\n"), parser->token.buffer);
xp_printf (XP_TEXT("literal......[%s]\n"), parser->token.name.buffer);
GET_TOKEN (parser);
}
else if (parser->token.type == XP_STX_TOKEN_LBRACKET) {
@ -469,7 +476,7 @@ static int __get_token (xp_stx_parser_t* parser)
return -1;
}
xp_printf (XP_TEXT("TOKEN: [%s]\n"), parser->token.buffer);
xp_printf (XP_TEXT("TOKEN: [%s]\n"), parser->token.name.buffer);
return 0;
}
@ -490,6 +497,7 @@ static int __get_ident (xp_stx_parser_t* parser)
} while (xp_isalnum(c));
if (c == XP_CHAR(':')) {
ADD_TOKEN_CHAR(parser, c);
parser->token.type = XP_STX_TOKEN_KEYWORD;
GET_CHAR (parser);
}

View File

@ -1,11 +1,12 @@
/*
* $Id: parser.h,v 1.18 2005-06-12 15:46:02 bacon Exp $
* $Id: parser.h,v 1.19 2005-06-12 16:22:03 bacon Exp $
*/
#ifndef _XP_STX_PARSER_H_
#define _XP_STX_PARSER_H_
#include <xp/stx/stx.h>
#include <xp/stx/name.h>
#include <xp/stx/token.h>
enum
@ -47,6 +48,7 @@ struct xp_stx_parser_t
xp_stx_t* stx;
int error_code;
xp_stx_name_t method_name;
xp_char_t* argument[32];
xp_size_t argument_count;

View File

@ -1,5 +1,5 @@
/*
* $Id: token.c,v 1.8 2005-06-12 16:07:23 bacon Exp $
* $Id: token.c,v 1.9 2005-06-12 16:22:03 bacon Exp $
*/
#include <xp/stx/token.h>
@ -8,9 +8,6 @@
xp_stx_token_t* xp_stx_token_open (
xp_stx_token_t* token, xp_word_t capacity)
{
if (capacity == 0)
capacity = xp_countof(token->static_buffer) - 1;
if (token == XP_NULL) {
token = (xp_stx_token_t*)
xp_malloc (xp_sizeof(xp_stx_token_t));
@ -19,137 +16,62 @@ xp_stx_token_t* xp_stx_token_open (
}
else token->__malloced = xp_false;
if (capacity < xp_countof(token->static_buffer)) {
token->buffer = token->static_buffer;
}
else {
token->buffer = (xp_char_t*)
xp_malloc ((capacity + 1) * xp_sizeof(xp_char_t));
if (token->buffer == XP_NULL) {
if (token->__malloced) xp_free (token);
return XP_NULL;
}
if (xp_stx_name_open(&token->name, capacity) == XP_NULL) {
if (token->__malloced) xp_free (token);
return XP_NULL;
}
/*
token->ivalue = 0;
token->fvalue = .0;
*/
token->size = 0;
token->capacity = capacity;
token->buffer[0] = XP_CHAR('\0');
token->type = XP_STX_TOKEN_END;
return token;
}
void xp_stx_token_close (xp_stx_token_t* token)
{
if (token->capacity >= xp_countof(token->static_buffer)) {
xp_assert (token->buffer != token->static_buffer);
xp_free (token->buffer);
}
xp_stx_name_close (&token->name);
if (token->__malloced) xp_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_size_t new_capacity = token->capacity * 2;
if (new_capacity >= xp_countof(token->static_buffer)) {
xp_char_t* space;
if (token->capacity < xp_countof(token->static_buffer)) {
space = (xp_char_t*)xp_malloc (
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
/* don't need to copy up to the terminating null */
xp_memcpy (space, token->buffer,
token->capacity * xp_sizeof(xp_char_t));
}
else {
space = (xp_char_t*)xp_realloc (token->buffer,
(new_capacity + 1) * xp_sizeof(xp_char_t));
if (space == XP_NULL) return -1;
}
token->buffer = space;
}
token->capacity = new_capacity;
}
token->buffer[token->size++] = c;
token->buffer[token->size] = XP_CHAR('\0');
return 0;
return xp_stx_name_addc (&token->name, c);
}
int xp_stx_token_adds (xp_stx_token_t* token, const xp_char_t* s)
{
while (*s != XP_CHAR('\0')) {
if (xp_stx_token_addc(token, *s) == -1) return -1;
}
return 0;
return xp_stx_name_adds (&token->name, s);
}
void xp_stx_token_clear (xp_stx_token_t* token)
{
/*
token->ivalue = 0;
token->fvalue = .0;
token->ivalue = 0;
token->fvalue = .0;
*/
token->size = 0;
token->buffer[0] = XP_CHAR('\0');
token->type = XP_STX_TOKEN_END;
xp_stx_name_clear (&token->name);
}
xp_char_t* xp_stx_token_yield (xp_stx_token_t* token, xp_word_t capacity)
{
xp_char_t* old_buffer, * new_buffer;
xp_char_t* p;
if (capacity == 0)
capacity = xp_countof(token->static_buffer) - 1;
if (token->capacity < xp_countof(token->static_buffer)) {
old_buffer = (xp_char_t*)
xp_malloc((token->capacity + 1) * xp_sizeof(xp_char_t));
if (old_buffer == XP_NULL) return XP_NULL;
xp_memcpy (old_buffer, token->buffer,
(token->capacity + 1) * xp_sizeof(xp_char_t));
}
else old_buffer = token->buffer;
p = xp_stx_name_yield (&token->name, capacity);
if (p == XP_NULL) return XP_NULL;
if (capacity < xp_countof(token->static_buffer)) {
new_buffer = token->static_buffer;
}
else {
new_buffer = (xp_char_t*)
xp_malloc((capacity + 1) * xp_sizeof(xp_char_t));
if (new_buffer == XP_NULL) return XP_NULL;
}
token->buffer = new_buffer;
token->size = 0;
token->capacity = capacity;
token->buffer[0] = XP_CHAR('\0');
return old_buffer;
/*
token->ivalue = 0;
token->fvalue = .0;
*/
token->type = XP_STX_TOKEN_END;
return p;
}
int xp_stx_token_compare (xp_stx_token_t* token, const xp_char_t* str)
int xp_stx_token_compare_name (xp_stx_token_t* token, const xp_char_t* str)
{
xp_char_t* p = token->buffer;
xp_word_t index = 0;
while (index < token->size) {
if (*p > *str) return 1;
if (*p < *str) return -1;
index++; p++; str++;
}
return (*str == XP_CHAR('\0'))? 0: -1;
return xp_stx_name_compare (&token->name, str);
}

View File

@ -1,11 +1,12 @@
/*
* $Id: token.h,v 1.14 2005-06-12 16:07:23 bacon Exp $
* $Id: token.h,v 1.15 2005-06-12 16:22:03 bacon Exp $
*/
#ifndef _XP_STX_TOKEN_H_
#define _XP_STX_TOKEN_H_
#include <xp/stx/stx.h>
#include <xp/stx/name.h>
enum
{
@ -35,12 +36,7 @@ struct xp_stx_token_t
xp_stx_int_t ivalue;
xp_stx_real_t fvalue;
*/
xp_word_t capacity;
xp_word_t size;
xp_char_t* buffer;
xp_char_t static_buffer[128];
xp_stx_name_t name;
xp_bool_t __malloced;
};
@ -58,7 +54,7 @@ int xp_stx_token_addc (xp_stx_token_t* token, xp_cint_t c);
int xp_stx_token_adds (xp_stx_token_t* token, const xp_char_t* s);
void xp_stx_token_clear (xp_stx_token_t* token);
xp_char_t* xp_stx_token_yield (xp_stx_token_t* token, xp_word_t capacity);
int xp_stx_token_compare (xp_stx_token_t* token, const xp_char_t* str);
int xp_stx_token_compare_name (xp_stx_token_t* token, const xp_char_t* str);
#ifdef __cplusplus
}