*** empty log message ***

This commit is contained in:
hyung-hwan 2006-10-23 14:44:43 +00:00
parent 67625392a5
commit 0d5283e988
13 changed files with 881 additions and 96 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.84 2006-10-22 14:00:05 bacon Exp $
* $Id: awk.c,v 1.85 2006-10-23 14:44:42 bacon Exp $
*/
#if defined(__BORLANDC__)
@ -11,7 +11,7 @@
static void __free_afn (void* awk, void* afn);
sse_awk_t* sse_awk_open (sse_awk_syscas_t* syscas)
sse_awk_t* sse_awk_open (const sse_awk_syscas_t* syscas)
{
sse_awk_t* awk;

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.131 2006-10-22 12:39:29 bacon Exp $
* $Id: awk.h,v 1.132 2006-10-23 14:44:42 bacon Exp $
*/
#ifndef _SSE_AWK_AWK_H_
@ -136,7 +136,7 @@ enum
};
/* various options */
enum sse_awk_option_t
enum
{
/* allow undeclared variables */
SSE_AWK_IMPLICIT = (1 << 0),
@ -198,7 +198,7 @@ enum sse_awk_option_t
};
/* error code */
enum ant_awk_errnum_t
enum
{
SSE_AWK_ENOERR, /* no error */
SSE_AWK_ENOMEM, /* out of memory */
@ -320,7 +320,7 @@ enum
extern "C" {
#endif
sse_awk_t* sse_awk_open (sse_awk_syscas_t* syscas);
sse_awk_t* sse_awk_open (const sse_awk_syscas_t* syscas);
int sse_awk_close (sse_awk_t* awk);
int sse_awk_clear (sse_awk_t* awk);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk_i.h,v 1.70 2006-10-22 12:39:29 bacon Exp $
* $Id: awk_i.h,v 1.71 2006-10-23 14:44:42 bacon Exp $
*/
#ifndef _SSE_AWK_AWKI_H_
@ -25,7 +25,7 @@ typedef struct sse_awk_tree_t sse_awk_tree_t;
#define sse_awk_assert(awk,expr) ((void)0)
#else
#define sse_awk_assert(awk,expr) (void)((expr) || \
(sse_awk_abort(awk, SSE_TEXT(#expr), SSE_TEXT(__FILE__), __LINE__), 0))
(sse_awk_abort(awk, SSE_T(#expr), SSE_T(__FILE__), __LINE__), 0))
#endif
#ifdef _MSC_VER

View File

@ -10,7 +10,7 @@ JAVA_INC = \
CC = cl
LD = link
CFLAGS = /nologo /O2 /MT /W3 /GR- /Za /D_WIN32_WINNT=0x0400 -I../.. -DXP_CHAR_IS_WCHAR $(JAVA_INC)
CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. -DSSE_CHAR_IS_WCHAR $(JAVA_INC)
all: lib

View File

@ -1,5 +1,5 @@
/*
* $Id: misc.h,v 1.5 2006-10-22 12:39:29 bacon Exp $
* $Id: misc.h,v 1.6 2006-10-23 14:44:43 bacon Exp $
*/
#ifndef _SSE_AWK_MISC_H_
@ -13,7 +13,7 @@
extern "C" {
#endif
void* sse_awk_memcpy (void* dst, const void* src, sse_size_t n);
void* sse_awk_memcpy (void* dst, const void* src, sse_size_t n);
void* sse_awk_memset (void* dst, int val, sse_size_t n);
sse_char_t* sse_awk_strtok (

View File

@ -1,5 +1,5 @@
/*
* $Id: lsp.c,v 1.5 2006-10-23 14:42:38 bacon Exp $
* $Id: lsp.c,v 1.6 2006-10-23 14:44:43 bacon Exp $
*/
#if defined(__BORLANDC__)
@ -170,39 +170,39 @@ static int __add_builtin_prims (sse_lsp_t* lsp)
#define ADD_PRIM(mem,name,prim) \
if (sse_lsp_add_prim(mem,name,prim) == -1) return -1;
ADD_PRIM (lsp, SSE_TEXT("abort"), sse_lsp_prim_abort);
ADD_PRIM (lsp, SSE_TEXT("eval"), sse_lsp_prim_eval);
ADD_PRIM (lsp, SSE_TEXT("prog1"), sse_lsp_prim_prog1);
ADD_PRIM (lsp, SSE_TEXT("progn"), sse_lsp_prim_progn);
ADD_PRIM (lsp, SSE_TEXT("gc"), sse_lsp_prim_gc);
ADD_PRIM (lsp, SSE_T("abort"), sse_lsp_prim_abort);
ADD_PRIM (lsp, SSE_T("eval"), sse_lsp_prim_eval);
ADD_PRIM (lsp, SSE_T("prog1"), sse_lsp_prim_prog1);
ADD_PRIM (lsp, SSE_T("progn"), sse_lsp_prim_progn);
ADD_PRIM (lsp, SSE_T("gc"), sse_lsp_prim_gc);
ADD_PRIM (lsp, SSE_TEXT("cond"), sse_lsp_prim_cond);
ADD_PRIM (lsp, SSE_TEXT("if"), sse_lsp_prim_if);
ADD_PRIM (lsp, SSE_TEXT("while"), sse_lsp_prim_while);
ADD_PRIM (lsp, SSE_T("cond"), sse_lsp_prim_cond);
ADD_PRIM (lsp, SSE_T("if"), sse_lsp_prim_if);
ADD_PRIM (lsp, SSE_T("while"), sse_lsp_prim_while);
ADD_PRIM (lsp, SSE_TEXT("car"), sse_lsp_prim_car);
ADD_PRIM (lsp, SSE_TEXT("cdr"), sse_lsp_prim_cdr);
ADD_PRIM (lsp, SSE_TEXT("cons"), sse_lsp_prim_cons);
ADD_PRIM (lsp, SSE_TEXT("set"), sse_lsp_prim_set);
ADD_PRIM (lsp, SSE_TEXT("setq"), sse_lsp_prim_setq);
ADD_PRIM (lsp, SSE_TEXT("quote"), sse_lsp_prim_quote);
ADD_PRIM (lsp, SSE_TEXT("defun"), sse_lsp_prim_defun);
ADD_PRIM (lsp, SSE_TEXT("demac"), sse_lsp_prim_demac);
ADD_PRIM (lsp, SSE_TEXT("let"), sse_lsp_prim_let);
ADD_PRIM (lsp, SSE_TEXT("let*"), sse_lsp_prim_letx);
ADD_PRIM (lsp, SSE_T("car"), sse_lsp_prim_car);
ADD_PRIM (lsp, SSE_T("cdr"), sse_lsp_prim_cdr);
ADD_PRIM (lsp, SSE_T("cons"), sse_lsp_prim_cons);
ADD_PRIM (lsp, SSE_T("set"), sse_lsp_prim_set);
ADD_PRIM (lsp, SSE_T("setq"), sse_lsp_prim_setq);
ADD_PRIM (lsp, SSE_T("quote"), sse_lsp_prim_quote);
ADD_PRIM (lsp, SSE_T("defun"), sse_lsp_prim_defun);
ADD_PRIM (lsp, SSE_T("demac"), sse_lsp_prim_demac);
ADD_PRIM (lsp, SSE_T("let"), sse_lsp_prim_let);
ADD_PRIM (lsp, SSE_T("let*"), sse_lsp_prim_letx);
ADD_PRIM (lsp, SSE_TEXT("="), sse_lsp_prim_eq);
ADD_PRIM (lsp, SSE_TEXT("/="), sse_lsp_prim_ne);
ADD_PRIM (lsp, SSE_TEXT(">"), sse_lsp_prim_gt);
ADD_PRIM (lsp, SSE_TEXT("<"), sse_lsp_prim_lt);
ADD_PRIM (lsp, SSE_TEXT(">="), sse_lsp_prim_ge);
ADD_PRIM (lsp, SSE_TEXT("<="), sse_lsp_prim_le);
ADD_PRIM (lsp, SSE_T("="), sse_lsp_prim_eq);
ADD_PRIM (lsp, SSE_T("/="), sse_lsp_prim_ne);
ADD_PRIM (lsp, SSE_T(">"), sse_lsp_prim_gt);
ADD_PRIM (lsp, SSE_T("<"), sse_lsp_prim_lt);
ADD_PRIM (lsp, SSE_T(">="), sse_lsp_prim_ge);
ADD_PRIM (lsp, SSE_T("<="), sse_lsp_prim_le);
ADD_PRIM (lsp, SSE_TEXT("+"), sse_lsp_prim_plus);
ADD_PRIM (lsp, SSE_TEXT("-"), sse_lsp_prim_minus);
ADD_PRIM (lsp, SSE_TEXT("*"), sse_lsp_prim_multiply);
ADD_PRIM (lsp, SSE_TEXT("/"), sse_lsp_prim_divide);
ADD_PRIM (lsp, SSE_TEXT("%"), sse_lsp_prim_modulus);
ADD_PRIM (lsp, SSE_T("+"), sse_lsp_prim_plus);
ADD_PRIM (lsp, SSE_T("-"), sse_lsp_prim_minus);
ADD_PRIM (lsp, SSE_T("*"), sse_lsp_prim_multiply);
ADD_PRIM (lsp, SSE_T("/"), sse_lsp_prim_divide);
ADD_PRIM (lsp, SSE_T("%"), sse_lsp_prim_modulus);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: mem.c,v 1.9 2006-10-23 10:57:59 bacon Exp $
* $Id: mem.c,v 1.10 2006-10-23 14:44:43 bacon Exp $
*/
#include <sse/lsp/mem.h>
@ -56,9 +56,9 @@ sse_lsp_mem_t* sse_lsp_mem_new (sse_size_t ubound, sse_size_t ubound_inc)
// initialize common object pointers
mem->nil = sse_lsp_make_nil (mem);
mem->t = sse_lsp_make_true (mem);
mem->quote = sse_lsp_make_symbol (mem, SSE_TEXT("quote"));
mem->lambda = sse_lsp_make_symbol (mem, SSE_TEXT("lambda"));
mem->macro = sse_lsp_make_symbol (mem, SSE_TEXT("macro"));
mem->quote = sse_lsp_make_symbol (mem, SSE_T("quote"));
mem->lambda = sse_lsp_make_symbol (mem, SSE_T("lambda"));
mem->macro = sse_lsp_make_symbol (mem, SSE_T("macro"));
if (mem->nil == SSE_NULL ||
mem->t == SSE_NULL ||
@ -119,32 +119,32 @@ int sse_lsp_add_builtin_prims (sse_lsp_mem_t* mem)
#define ADD_PRIM(mem,name,len,prim) \
if (__add_prim(mem,name,len,prim) == -1) return -1;
ADD_PRIM (mem, SSE_TEXT("abort"), 5, sse_lsp_prim_abort);
ADD_PRIM (mem, SSE_TEXT("eval"), 4, sse_lsp_prim_eval);
ADD_PRIM (mem, SSE_TEXT("prog1"), 5, sse_lsp_prim_prog1);
ADD_PRIM (mem, SSE_TEXT("progn"), 5, sse_lsp_prim_progn);
ADD_PRIM (mem, SSE_TEXT("gc"), 2, sse_lsp_prim_gc);
ADD_PRIM (mem, SSE_T("abort"), 5, sse_lsp_prim_abort);
ADD_PRIM (mem, SSE_T("eval"), 4, sse_lsp_prim_eval);
ADD_PRIM (mem, SSE_T("prog1"), 5, sse_lsp_prim_prog1);
ADD_PRIM (mem, SSE_T("progn"), 5, sse_lsp_prim_progn);
ADD_PRIM (mem, SSE_T("gc"), 2, sse_lsp_prim_gc);
ADD_PRIM (mem, SSE_TEXT("cond"), 4, sse_lsp_prim_cond);
ADD_PRIM (mem, SSE_TEXT("if"), 2, sse_lsp_prim_if);
ADD_PRIM (mem, SSE_TEXT("while"), 5, sse_lsp_prim_while);
ADD_PRIM (mem, SSE_T("cond"), 4, sse_lsp_prim_cond);
ADD_PRIM (mem, SSE_T("if"), 2, sse_lsp_prim_if);
ADD_PRIM (mem, SSE_T("while"), 5, sse_lsp_prim_while);
ADD_PRIM (mem, SSE_TEXT("car"), 3, sse_lsp_prim_car);
ADD_PRIM (mem, SSE_TEXT("cdr"), 3, sse_lsp_prim_cdr);
ADD_PRIM (mem, SSE_TEXT("cons"), 4, sse_lsp_prim_cons);
ADD_PRIM (mem, SSE_TEXT("set"), 3, sse_lsp_prim_set);
ADD_PRIM (mem, SSE_TEXT("setq"), 4, sse_lsp_prim_setq);
ADD_PRIM (mem, SSE_TEXT("quote"), 5, sse_lsp_prim_quote);
ADD_PRIM (mem, SSE_TEXT("defun"), 5, sse_lsp_prim_defun);
ADD_PRIM (mem, SSE_TEXT("demac"), 5, sse_lsp_prim_demac);
ADD_PRIM (mem, SSE_TEXT("let"), 3, sse_lsp_prim_let);
ADD_PRIM (mem, SSE_TEXT("let*"), 4, sse_lsp_prim_letx);
ADD_PRIM (mem, SSE_T("car"), 3, sse_lsp_prim_car);
ADD_PRIM (mem, SSE_T("cdr"), 3, sse_lsp_prim_cdr);
ADD_PRIM (mem, SSE_T("cons"), 4, sse_lsp_prim_cons);
ADD_PRIM (mem, SSE_T("set"), 3, sse_lsp_prim_set);
ADD_PRIM (mem, SSE_T("setq"), 4, sse_lsp_prim_setq);
ADD_PRIM (mem, SSE_T("quote"), 5, sse_lsp_prim_quote);
ADD_PRIM (mem, SSE_T("defun"), 5, sse_lsp_prim_defun);
ADD_PRIM (mem, SSE_T("demac"), 5, sse_lsp_prim_demac);
ADD_PRIM (mem, SSE_T("let"), 3, sse_lsp_prim_let);
ADD_PRIM (mem, SSE_T("let*"), 4, sse_lsp_prim_letx);
ADD_PRIM (mem, SSE_TEXT(">"), 1, sse_lsp_prim_gt);
ADD_PRIM (mem, SSE_TEXT("<"), 1, sse_lsp_prim_lt);
ADD_PRIM (mem, SSE_T(">"), 1, sse_lsp_prim_gt);
ADD_PRIM (mem, SSE_T("<"), 1, sse_lsp_prim_lt);
ADD_PRIM (mem, SSE_TEXT("+"), 1, sse_lsp_prim_plus);
ADD_PRIM (mem, SSE_TEXT("-"), 1, sse_lsp_prim_minus);
ADD_PRIM (mem, SSE_T("+"), 1, sse_lsp_prim_plus);
ADD_PRIM (mem, SSE_T("-"), 1, sse_lsp_prim_minus);
return 0;
}
@ -179,7 +179,7 @@ sse_lsp_obj_t* sse_lsp_alloc (sse_lsp_mem_t* mem, int type, sse_size_t size)
mem->count++;
#if 0
sse_dprint1 (SSE_TEXT("mem->count: %u\n"), mem->count);
sse_dprint1 (SSE_T("mem->count: %u\n"), mem->count);
#endif
return obj;
@ -200,7 +200,7 @@ void sse_lsp_dispose (sse_lsp_mem_t* mem, sse_lsp_obj_t* prev, sse_lsp_obj_t* ob
mem->count--;
#if 0
sse_dprint1 (SSE_TEXT("mem->count: %u\n"), mem->count);
sse_dprint1 (SSE_T("mem->count: %u\n"), mem->count);
#endif
sse_free (obj);
@ -290,7 +290,7 @@ static void sse_lsp_mark (sse_lsp_mem_t* mem)
sse_size_t i;
#if 0
sse_dprint0 (SSE_TEXT("marking environment frames\n"));
sse_dprint0 (SSE_T("marking environment frames\n"));
#endif
// mark objects in the environment frames
frame = mem->frame;
@ -311,7 +311,7 @@ static void sse_lsp_mark (sse_lsp_mem_t* mem)
}
#if 0
sse_dprint0 (SSE_TEXT("marking interim frames\n"));
sse_dprint0 (SSE_T("marking interim frames\n"));
#endif
// mark objects in the interim frames
@ -334,12 +334,12 @@ static void sse_lsp_mark (sse_lsp_mem_t* mem)
}
/*
sse_dprint0 (SSE_TEXT("marking the locked object\n"));
sse_dprint0 (SSE_T("marking the locked object\n"));
if (mem->locked != SSE_NULL) sse_lsp_mark_obj (mem->locked);
*/
#if 0
sse_dprint0 (SSE_TEXT("marking termporary objects\n"));
sse_dprint0 (SSE_T("marking termporary objects\n"));
#endif
array = mem->temp_array;
for (i = 0; i < array->size; i++) {
@ -347,7 +347,7 @@ static void sse_lsp_mark (sse_lsp_mem_t* mem)
}
#if 0
sse_dprint0 (SSE_TEXT("marking builtin objects\n"));
sse_dprint0 (SSE_T("marking builtin objects\n"));
#endif
// mark common objects
if (mem->t != SSE_NULL) sse_lsp_mark_obj (mem->t);
@ -370,7 +370,7 @@ static void sse_lsp_sweep (sse_lsp_mem_t* mem)
//obj = mem->used[--i];
#if 0
sse_dprint1 (SSE_TEXT("sweeping objects of type: %u\n"), i);
sse_dprint1 (SSE_T("sweeping objects of type: %u\n"), i);
#endif
while (obj != SSE_NULL) {
@ -638,7 +638,7 @@ int sse_lsp_comp_symbol (sse_lsp_obj_t* obj, const sse_char_t* str)
index++; p++; str++;
}
return (*str == SSE_CHAR('\0'))? 0: -1;
return (*str == SSE_T('\0'))? 0: -1;
}
int sse_lsp_comp_symbol2 (sse_lsp_obj_t* obj, const sse_char_t* str, sse_size_t len)
@ -679,7 +679,7 @@ int sse_lsp_comp_string (sse_lsp_obj_t* obj, const sse_char_t* str)
index++; p++; str++;
}
return (*str == SSE_CHAR('\0'))? 0: -1;
return (*str == SSE_T('\0'))? 0: -1;
}
int sse_lsp_comp_string2 (sse_lsp_obj_t* obj, const sse_char_t* str, sse_size_t len)
@ -706,8 +706,8 @@ int sse_lsp_comp_string2 (sse_lsp_obj_t* obj, const sse_char_t* str, sse_size_t
void sse_lsp_copy_string (sse_char_t* dst, const sse_char_t* str)
{
// the buffer pointed by dst should be big enough to hold str
while (*str != SSE_CHAR('\0')) *dst++ = *str++;
*dst = SSE_CHAR('\0');
while (*str != SSE_T('\0')) *dst++ = *str++;
*dst = SSE_T('\0');
}
void sse_lsp_copy_string2 (sse_char_t* dst, const sse_char_t* str, sse_size_t len)
@ -717,6 +717,6 @@ void sse_lsp_copy_string2 (sse_char_t* dst, const sse_char_t* str, sse_size_t le
*dst++ = *str++;
len--;
}
*dst = SSE_CHAR('\0');
*dst = SSE_T('\0');
}

View File

@ -1,5 +1,5 @@
/*
* $Id: mem.h,v 1.7 2006-10-22 13:10:46 bacon Exp $
* $Id: mem.h,v 1.8 2006-10-23 14:42:38 bacon Exp $
*/
#ifndef _SSE_LSP_MEM_H_
@ -52,18 +52,18 @@ extern "C" {
#endif
sse_lsp_mem_t* sse_lsp_mem_new (sse_size_t ubound, sse_size_t ubound_inc);
void sse_lsp_mem_free (sse_lsp_mem_t* mem);
void sse_lsp_mem_free (sse_lsp_mem_t* mem);
int sse_lsp_add_builtin_prims (sse_lsp_mem_t* mem);
sse_lsp_obj_t* sse_lsp_alloc (sse_lsp_mem_t* mem, int type, sse_size_t size);
void sse_lsp_dispose (sse_lsp_mem_t* mem, sse_lsp_obj_t* prev, sse_lsp_obj_t* obj);
void sse_lsp_dispose_all (sse_lsp_mem_t* mem);
void sse_lsp_garbage_collect (sse_lsp_mem_t* mem);
void sse_lsp_dispose (sse_lsp_mem_t* mem, sse_lsp_obj_t* prev, sse_lsp_obj_t* obj);
void sse_lsp_dispose_all (sse_lsp_mem_t* mem);
void sse_lsp_garbage_collect (sse_lsp_mem_t* mem);
void sse_lsp_lock (sse_lsp_obj_t* obj);
void sse_lsp_unlock (sse_lsp_obj_t* obj);
void sse_lsp_unlock_all (sse_lsp_obj_t* obj);
void sse_lsp_lock (sse_lsp_obj_t* obj);
void sse_lsp_unlock (sse_lsp_obj_t* obj);
void sse_lsp_unlock_all (sse_lsp_obj_t* obj);
// object creation of standard types
sse_lsp_obj_t* sse_lsp_make_nil (sse_lsp_mem_t* mem);

761
ase/lsp/misc.c Normal file
View File

@ -0,0 +1,761 @@
/*
* $Id: misc.c,v 1.1 2006-10-23 14:42:38 bacon Exp $
*/
#include <sse/lsp/lsp_i.h>
void* sse_lsp_memcpy (void* dst, const void* src, sse_size_t n)
{
void* p = dst;
void* e = (sse_byte_t*)dst + n;
while (dst < e)
{
*(sse_byte_t*)dst = *(sse_byte_t*)src;
dst = (sse_byte_t*)dst + 1;
src = (sse_byte_t*)src + 1;
}
return p;
}
void* sse_lsp_memset (void* dst, int val, sse_size_t n)
{
void* p = dst;
void* e = (sse_byte_t*)p + n;
while (p < e)
{
*(sse_byte_t*)p = (sse_byte_t)val;
p = (sse_byte_t*)p + 1;
}
return dst;
}
sse_long_t sse_lsp_strxtolong (
sse_lsp_t* lsp, const sse_char_t* str, sse_size_t len,
int base, const sse_char_t** endptr)
{
sse_long_t n = 0;
const sse_char_t* p;
const sse_char_t* end;
sse_size_t rem;
int digit, negative = 0;
sse_lsp_assert (lsp, base < 37);
p = str;
end = str + len;
/* strip off leading spaces */
/*while (SSE_LSP_ISSPACE(lsp,*p)) p++;*/
/* check for a sign */
/*while (*p != SSE_T('\0')) */
while (p < end)
{
if (*p == SSE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == SSE_T('+')) p++;
else break;
}
/* check for a binary/octal/hexadecimal notation */
rem = end - p;
if (base == 0)
{
if (rem >= 1 && *p == SSE_T('0'))
{
p++;
if (rem == 1) base = 8;
else if (*p == SSE_T('x') || *p == SSE_T('X'))
{
p++; base = 16;
}
else if (*p == SSE_T('b') || *p == SSE_T('B'))
{
p++; base = 2;
}
else base = 8;
}
else base = 10;
}
else if (rem >= 2 && base == 16)
{
if (*p == SSE_T('0') &&
(*(p+1) == SSE_T('x') || *(p+1) == SSE_T('X'))) p += 2;
}
else if (rem >= 2 && base == 2)
{
if (*p == SSE_T('0') &&
(*(p+1) == SSE_T('b') || *(p+1) == SSE_T('B'))) p += 2;
}
/* process the digits */
/*while (*p != SSE_T('\0'))*/
while (p < end)
{
if (*p >= SSE_T('0') && *p <= SSE_T('9'))
digit = *p - SSE_T('0');
else if (*p >= SSE_T('A') && *p <= SSE_T('Z'))
digit = *p - SSE_T('A') + 10;
else if (*p >= SSE_T('a') && *p <= SSE_T('z'))
digit = *p - SSE_T('a') + 10;
else break;
if (digit >= base) break;
n = n * base + digit;
p++;
}
if (endptr != SSE_NULL) *endptr = p;
return (negative)? -n: n;
}
/*
* sse_lsp_strtoreal is almost a replica of strtod.
*
* strtod.c --
*
* Source code for the "strtod" library procedure.
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#define MAX_EXPONENT 511
sse_real_t sse_lsp_strtoreal (sse_lsp_t* lsp, const sse_char_t* str)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static sse_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
sse_real_t fraction, dbl_exp, * d;
const sse_char_t* p;
sse_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const sse_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
/* strip off leading blanks */
/*while (SSE_LSP_ISSPACE(lsp,*p)) p++;*/
/* check for a sign */
while (*p != SSE_T('\0'))
{
if (*p == SSE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == SSE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
for (mant_size = 0; ; mant_size++)
{
c = *p;
if (!SSE_LSP_ISDIGIT (lsp, c))
{
if ((c != SSE_T('.')) || (dec_pt >= 0)) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18)
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == SSE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - SSE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p;
p++;
if (c == SSE_T('.'))
{
c = *p;
p++;
}
frac2 = 10*frac2 + (c - SSE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if ((*p == SSE_T('E')) || (*p == SSE_T('e')))
{
p++;
if (*p == SSE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == SSE_T('+')) p++;
exp_negative = 0;
}
if (!SSE_LSP_ISDIGIT (lsp, *p))
{
/* p = pexp; */
/* goto done; */
goto no_exp;
}
while (SSE_LSP_ISDIGIT (lsp, *p))
{
exp = exp * 10 + (*p - SSE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
return (negative)? -fraction: fraction;
}
sse_real_t sse_lsp_strxtoreal (
sse_lsp_t* lsp, const sse_char_t* str, sse_size_t len,
const sse_char_t** endptr)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static sse_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
sse_real_t fraction, dbl_exp, * d;
const sse_char_t* p, * end;
sse_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const sse_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
end = str + len;
/* Strip off leading blanks and check for a sign */
/*while (SSE_LSP_ISSPACE(lsp,*p)) p++;*/
/*while (*p != SSE_T('\0')) */
while (p < end)
{
if (*p == SSE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == SSE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
/*for (mant_size = 0; ; mant_size++) */
for (mant_size = 0; p < end; mant_size++)
{
c = *p;
if (!SSE_LSP_ISDIGIT (lsp, c))
{
if (c != SSE_T('.') || dec_pt >= 0) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18) /* TODO: is 18 correct for sse_real_t??? */
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == SSE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - SSE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p++;
if (c == SSE_T('.'))
{
c = *p;
p++;
}
frac2 = 10 * frac2 + (c - SSE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if (p < end && (*p == SSE_T('E') || *p == SSE_T('e')))
{
p++;
if (p < end)
{
if (*p == SSE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == SSE_T('+')) p++;
exp_negative = 0;
}
}
else exp_negative = 0;
if (!(p < end && SSE_LSP_ISDIGIT (lsp, *p)))
{
/*p = pexp;*/
/*goto done;*/
goto no_exp;
}
while (p < end && SSE_LSP_ISDIGIT (lsp, *p))
{
exp = exp * 10 + (*p - SSE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
if (endptr != SSE_NULL) *endptr = p;
return (negative)? -fraction: fraction;
}
sse_size_t sse_lsp_longtostr (
sse_long_t value, int radix, const sse_char_t* prefix,
sse_char_t* buf, sse_size_t size)
{
sse_long_t t, rem;
sse_size_t len, ret, i;
sse_size_t prefix_len;
prefix_len = (prefix != SSE_NULL)? sse_lsp_strlen(prefix): 0;
t = value;
if (t == 0)
{
/* zero */
if (buf == SSE_NULL) return prefix_len + 1;
if (size < prefix_len+1)
{
/* buffer too small */
return (sse_size_t)-1;
}
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
buf[prefix_len] = SSE_T('0');
if (size > prefix_len+1) buf[prefix_len+1] = SSE_T('\0');
return 1;
}
/* non-zero values */
len = prefix_len;
if (t < 0) { t = -t; len++; }
while (t > 0) { len++; t /= radix; }
if (buf == SSE_NULL)
{
/* if buf is not given, return the number of bytes required */
return len;
}
if (size < len) return (sse_size_t)-1; /* buffer too small */
if (size > len) buf[len] = SSE_T('\0');
ret = len;
t = value;
if (t < 0) t = -t;
while (t > 0)
{
rem = t % radix;
if (rem >= 10)
buf[--len] = (sse_char_t)rem + SSE_T('a') - 10;
else
buf[--len] = (sse_char_t)rem + SSE_T('0');
t /= radix;
}
if (value < 0)
{
for (i = 1; i <= prefix_len; i++)
{
buf[i] = prefix[i-1];
len--;
}
buf[--len] = SSE_T('-');
}
else
{
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
}
return ret;
}
sse_char_t* sse_lsp_strdup (sse_lsp_t* lsp, const sse_char_t* str)
{
sse_char_t* tmp;
tmp = (sse_char_t*) SSE_LSP_MALLOC (
lsp, (sse_lsp_strlen(str) + 1) * sse_sizeof(sse_char_t));
if (tmp == SSE_NULL) return SSE_NULL;
sse_lsp_strcpy (tmp, str);
return tmp;
}
sse_char_t* sse_lsp_strxdup (sse_lsp_t* lsp, const sse_char_t* str, sse_size_t len)
{
sse_char_t* tmp;
tmp = (sse_char_t*) SSE_LSP_MALLOC (
lsp, (len + 1) * sse_sizeof(sse_char_t));
if (tmp == SSE_NULL) return SSE_NULL;
sse_lsp_strncpy (tmp, str, len);
return tmp;
}
sse_char_t* sse_lsp_strxdup2 (
sse_lsp_t* lsp,
const sse_char_t* str1, sse_size_t len1,
const sse_char_t* str2, sse_size_t len2)
{
sse_char_t* tmp;
tmp = (sse_char_t*) SSE_LSP_MALLOC (
lsp, (len1 + len2 + 1) * sse_sizeof(sse_char_t));
if (tmp == SSE_NULL) return SSE_NULL;
sse_lsp_strncpy (tmp, str1, len1);
sse_lsp_strncpy (tmp + len1, str2, len2);
return tmp;
}
sse_size_t sse_lsp_strlen (const sse_char_t* str)
{
const sse_char_t* p = str;
while (*p != SSE_T('\0')) p++;
return p - str;
}
sse_size_t sse_lsp_strcpy (sse_char_t* buf, const sse_char_t* str)
{
sse_char_t* org = buf;
while ((*buf++ = *str++) != SSE_T('\0'));
return buf - org - 1;
}
sse_size_t sse_lsp_strncpy (sse_char_t* buf, const sse_char_t* str, sse_size_t len)
{
const sse_char_t* end = str + len;
while (str < end) *buf++ = *str++;
*buf = SSE_T('\0');
return len;
}
int sse_lsp_strcmp (const sse_char_t* s1, const sse_char_t* s2)
{
while (*s1 == *s2)
{
if (*s1 == SSE_C('\0')) return 0;
s1++, s2++;
}
return (*s1 > *s2)? 1: -1;
}
int sse_lsp_strxncmp (
const sse_char_t* s1, sse_size_t len1,
const sse_char_t* s2, sse_size_t len2)
{
sse_char_t c1, c2;
const sse_char_t* end1 = s1 + len1;
const sse_char_t* end2 = s2 + len2;
while (s1 < end1)
{
c1 = *s1;
if (s2 < end2)
{
c2 = *s2;
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
s1++; s2++;
}
return (s2 < end2)? -1: 0;
}
int sse_lsp_strxncasecmp (
sse_lsp_t* lsp,
const sse_char_t* s1, sse_size_t len1,
const sse_char_t* s2, sse_size_t len2)
{
sse_char_t c1, c2;
const sse_char_t* end1 = s1 + len1;
const sse_char_t* end2 = s2 + len2;
while (s1 < end1)
{
c1 = SSE_LSP_TOUPPER (lsp, *s1);
if (s2 < end2)
{
c2 = SSE_LSP_TOUPPER (lsp, *s2);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
s1++; s2++;
}
return (s2 < end2)? -1: 0;
}
sse_char_t* sse_lsp_strxnstr (
const sse_char_t* str, sse_size_t strsz,
const sse_char_t* sub, sse_size_t subsz)
{
const sse_char_t* end, * subp;
if (subsz == 0) return (sse_char_t*)str;
if (strsz < subsz) return SSE_NULL;
end = str + strsz - subsz;
subp = sub + subsz;
while (str <= end) {
const sse_char_t* x = str;
const sse_char_t* y = sub;
while (sse_true) {
if (y >= subp) return (sse_char_t*)str;
if (*x != *y) break;
x++; y++;
}
str++;
}
return SSE_NULL;
}
int sse_lsp_abort (sse_lsp_t* lsp,
const sse_char_t* expr, const sse_char_t* file, int line)
{
lsp->syscas.dprintf (
SSE_T("ASSERTION FAILURE AT FILE %s, LINE %d\n%s\n"),
file, line, expr);
lsp->syscas.abort ();
return 0;
}

27
ase/lsp/misc.h Normal file
View File

@ -0,0 +1,27 @@
/*
* $Id: misc.h,v 1.1 2006-10-23 14:42:38 bacon Exp $
*/
#ifndef _SSE_LSP_MISC_H_
#define _SSE_LSP_MISC_H_
#ifndef _SSE_LSP_LSP_H_
#error Never include this file directly. Include <sse/lsp/lsp.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
void* sse_lsp_memcpy (void* dst, const void* src, sse_size_t n);
void* sse_lsp_memset (void* dst, int val, sse_size_t n);
int sse_lsp_abort (sse_lsp_t* lsp,
const sse_char_t* expr, const sse_char_t* file, int line);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,10 +1,8 @@
/*
* $Id: name.c,v 1.4 2006-10-22 13:10:46 bacon Exp $
* $Id: name.c,v 1.5 2006-10-23 14:42:38 bacon Exp $
*/
#include <sse/lsp/name.h>
#include <sse/bas/memory.h>
#include <sse/bas/assert.h>
sse_lsp_name_t* sse_lsp_name_open (
sse_lsp_name_t* name, sse_word_t capacity)

View File

@ -1,5 +1,5 @@
/*
* $Id: obj.h,v 1.5 2006-10-22 13:10:46 bacon Exp $
* $Id: obj.h,v 1.6 2006-10-23 14:42:38 bacon Exp $
*/
#ifndef _SSE_LSP_OBJ_H_
@ -76,7 +76,7 @@ struct sse_lsp_obj_real_t
struct sse_lsp_obj_symbol_t
{
sse_lsp_objhdr_t hdr;
#ifdef __BORLANDC__
#if defined(__BORLANDC__) || defined(_MSC_VER)
#else
sse_char_t buffer[0];
#endif
@ -85,7 +85,7 @@ struct sse_lsp_obj_symbol_t
struct sse_lsp_obj_string_t
{
sse_lsp_objhdr_t hdr;
#ifdef __BORLANDC__
#if defined(__BORLANDC__) || defined(_MSC_VER)
#else
sse_char_t buffer[0];
#endif

View File

@ -1,11 +1,10 @@
/*
* $Id: prim.h,v 1.6 2006-10-22 13:10:46 bacon Exp $
* $Id: prim.h,v 1.7 2006-10-23 14:42:38 bacon Exp $
*/
#ifndef _SSE_LSP_PRIM_H_
#define _SSE_LSP_PRIM_H_
#include <sse/lsp/types.h>
#include <sse/lsp/lsp.h>
#ifdef __cplusplus