fixed a bug of not resetting the heap limit after gc.
added some pointer arithmetic macros.
This commit is contained in:
parent
0b97fee2c4
commit
10661777a1
@ -60,7 +60,7 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t old_bucket)
|
||||
return new_bucket;
|
||||
}
|
||||
|
||||
stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t value)
|
||||
static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t value)
|
||||
{
|
||||
stix_oow_t index, tally;
|
||||
stix_oop_association_t ass;
|
||||
@ -81,18 +81,12 @@ stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t value)
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association);
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,ass->key) == stix->_symbol);
|
||||
|
||||
if (STIX_OBJ_GET_SIZE(key) == STIX_OBJ_GET_SIZE(ass->key))
|
||||
if (STIX_OBJ_GET_SIZE(key) == STIX_OBJ_GET_SIZE(ass->key) &&
|
||||
stix_equalchars (key->slot, ((stix_oop_char_t)ass->key)->slot, STIX_OBJ_GET_SIZE(key)))
|
||||
{
|
||||
stix_oow_t i;
|
||||
|
||||
for (i = 0; i < STIX_OBJ_GET_SIZE(key); i++)
|
||||
{
|
||||
if (key->slot[i] != ((stix_oop_char_t)ass->key)->slot[i]) goto not_equal;
|
||||
}
|
||||
return (stix_oop_t)ass;
|
||||
}
|
||||
|
||||
not_equal:
|
||||
index = (index + 1) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include "stix-prv.h"
|
||||
|
||||
static void cleanup_symbols_for_gc (stix_t* stix, stix_oop_t _nil)
|
||||
static void compact_symbol_table (stix_t* stix, stix_oop_t _nil)
|
||||
{
|
||||
stix_oop_char_t symbol;
|
||||
stix_oow_t tally, index, i, x, y, z;
|
||||
@ -107,12 +107,11 @@ static stix_oop_t move_one (stix_t* stix, stix_oop_t oop)
|
||||
}
|
||||
else
|
||||
{
|
||||
stix_oow_t nbytes, nbytes_aligned;
|
||||
stix_oow_t nbytes_aligned;
|
||||
stix_oop_t tmp;
|
||||
|
||||
/* calculate the payload size in bytes */
|
||||
nbytes = (oop->_size + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop);
|
||||
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
|
||||
nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t));
|
||||
|
||||
/* allocate space in the new heap */
|
||||
tmp = stix_allocheapmem (stix, stix->newheap, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
|
||||
@ -144,15 +143,15 @@ static stix_oop_t move_one (stix_t* stix, stix_oop_t oop)
|
||||
|
||||
static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr)
|
||||
{
|
||||
while (ptr < stix->newheap->ptr)
|
||||
/*while (ptr < stix->newheap->ptr)*/
|
||||
while (STIX_LTPTR(stix_uint8_t, ptr, stix->newheap->ptr))
|
||||
{
|
||||
stix_oow_t i;
|
||||
stix_oow_t nbytes, nbytes_aligned;
|
||||
stix_oow_t nbytes_aligned;
|
||||
stix_oop_t oop;
|
||||
|
||||
oop = (stix_oop_t)ptr;
|
||||
nbytes = (STIX_OBJ_GET_SIZE(oop) + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop);
|
||||
nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t));
|
||||
nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t));
|
||||
|
||||
STIX_OBJ_SET_CLASS (oop, move_one(stix, STIX_OBJ_GET_CLASS(oop)));
|
||||
if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP)
|
||||
@ -167,8 +166,8 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr)
|
||||
}
|
||||
}
|
||||
|
||||
/*wprintf (L"ptr in gc => %p size => %d, aligned size => %d\n", ptr, (int)nbytes, (int)nbytes_aligned);*/
|
||||
ptr = ptr + STIX_SIZEOF(stix_obj_t) + nbytes_aligned;
|
||||
/*ptr = ptr + STIX_SIZEOF(stix_obj_t) + nbytes_aligned;*/
|
||||
ptr = STIX_INCPTR (stix_uint8_t, ptr, STIX_SIZEOF(stix_obj_t) + nbytes_aligned);
|
||||
}
|
||||
|
||||
/* return the pointer to the beginning of the free space in the heap */
|
||||
@ -188,6 +187,8 @@ void stix_gc (stix_t* stix)
|
||||
stix_oop_t old_nil;
|
||||
stix_oow_t i;
|
||||
|
||||
printf ("STARTING GC curheap base %p ptr %p newheap base %p ptr %p\n",
|
||||
stix->curheap->base, stix->curheap->ptr, stix->newheap->base, stix->newheap->ptr);
|
||||
/* TODO: allocate common objects like _nil and the root dictionary
|
||||
* in the permanant heap. minimize moving around */
|
||||
old_nil = stix->_nil;
|
||||
@ -226,7 +227,7 @@ void stix_gc (stix_t* stix)
|
||||
* if the symbol has not moved to the new heap, the symbol
|
||||
* is not referenced by any other objects than the symbol
|
||||
* table itself */
|
||||
cleanup_symbols_for_gc (stix, old_nil);
|
||||
compact_symbol_table (stix, old_nil);
|
||||
|
||||
/* move the symbol table itself */
|
||||
stix->symtab = (stix_oop_set_t)move_one (stix, (stix_oop_t)stix->symtab);
|
||||
@ -236,6 +237,11 @@ void stix_gc (stix_t* stix)
|
||||
* the symbol table. */
|
||||
ptr = scan_new_heap (stix, ptr);
|
||||
|
||||
/* the contents of the current heap is not needed any more.
|
||||
* reset the upper bound to the base. don't forget to align the heap
|
||||
* pointer to the OOP size. See stix_makeheap() also */
|
||||
stix->curheap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)stix->curheap->base), STIX_SIZEOF(stix_oop_t));
|
||||
|
||||
/* swap the current heap and old heap */
|
||||
tmp = stix->curheap;
|
||||
stix->curheap = stix->newheap;
|
||||
|
@ -42,9 +42,11 @@ stix_heap_t* stix_makeheap (stix_t* stix, stix_size_t size)
|
||||
heap->base = (stix_uint8_t*)(heap + 1);
|
||||
/* adjust the initial allocation pointer to a multiple of the oop size */
|
||||
heap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)heap->base), STIX_SIZEOF(stix_oop_t));
|
||||
heap->limit = heap->base + size;
|
||||
heap->limit = STIX_INCPTR(stix_uint8_t, heap->base, size); /*heap->base + size;*/
|
||||
|
||||
STIX_ASSERT (heap->ptr >= heap->base);
|
||||
STIX_ASSERT (STIX_GTPTR(stix_uint8_t, heap->limit, heap->base)); /* heap->limit >= heap->base */
|
||||
STIX_ASSERT (STIX_SUBPTR(stix_uint8_t, heap->limit, heap->base) == size);
|
||||
|
||||
/* if size is too small, heap->ptr may go past heap->limit even at
|
||||
* this moment depending on the alignment of heap->base. subsequent
|
||||
@ -64,7 +66,9 @@ void* stix_allocheapmem (stix_t* stix, stix_heap_t* heap, stix_size_t size)
|
||||
stix_uint8_t* ptr;
|
||||
|
||||
/* check the heap size limit */
|
||||
if (heap->ptr >= heap->limit || heap->limit - heap->ptr < size)
|
||||
/*if (heap->ptr >= heap->limit || heap->limit - heap->ptr < size)*/
|
||||
if (STIX_GEPTR(stix_uint8_t, heap->ptr, heap->limit) ||
|
||||
STIX_SUBPTR(stix_uint8_t, heap->limit, heap->ptr) < size)
|
||||
{
|
||||
stix->errnum = STIX_ENOMEM;
|
||||
return STIX_NULL;
|
||||
@ -72,7 +76,7 @@ void* stix_allocheapmem (stix_t* stix, stix_heap_t* heap, stix_size_t size)
|
||||
|
||||
/* allocation is as simple as moving the heap pointer */
|
||||
ptr = heap->ptr;
|
||||
heap->ptr += size;
|
||||
heap->ptr = STIX_INCPTR (stix_uint8_t, heap->ptr, size); /*heap->ptr += size;*/
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
@ -180,7 +180,12 @@ static int ignite_2 (stix_t* stix)
|
||||
if (!stix->symtab) return -1;
|
||||
|
||||
stix->symtab->tally = STIX_OOP_FROM_SMINT(0);
|
||||
arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.default_symtab_size);
|
||||
/* It's important to assign the result of stix_instantiate() to a temporary
|
||||
* variable first and then assign it to stix->symtab->bucket.
|
||||
* The pointer 'stix->symtab; can change in stix_instantiate() and the
|
||||
* target address of assignment may get set before stix_instantiate()
|
||||
* is called. */
|
||||
arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size);
|
||||
if (!arr) return -1;
|
||||
stix->symtab->bucket = arr;
|
||||
|
||||
@ -189,7 +194,7 @@ static int ignite_2 (stix_t* stix)
|
||||
if (!stix->sysdic) return -1;
|
||||
|
||||
stix->sysdic->tally = STIX_OOP_FROM_SMINT(0);
|
||||
arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.default_sysdic_size);
|
||||
arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_sysdic_size);
|
||||
if (!arr) return -1;
|
||||
stix->sysdic->bucket = arr;
|
||||
|
||||
|
@ -1,3 +1,29 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2015 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stix-prv.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -69,7 +95,7 @@ int main (int argc, char* argv[])
|
||||
(unsigned long int)STIX_CLASS_SPEC_INDEXED_TYPE(x));
|
||||
}
|
||||
|
||||
stix = stix_open (&sys_mmgr, 0, 1000000lu, STIX_NULL);
|
||||
stix = stix_open (&sys_mmgr, 0, 512000lu, STIX_NULL);
|
||||
if (!stix)
|
||||
{
|
||||
printf ("cannot open stix\n");
|
||||
@ -78,8 +104,8 @@ int main (int argc, char* argv[])
|
||||
|
||||
{
|
||||
stix_oow_t symtab_size = 5000;
|
||||
stix_setoption (stix, STIX_DEFAULT_SYMTAB_SIZE, &symtab_size);
|
||||
stix_setoption (stix, STIX_DEFAULT_SYSDIC_SIZE, &symtab_size);
|
||||
stix_setoption (stix, STIX_DFL_SYMTAB_SIZE, &symtab_size);
|
||||
stix_setoption (stix, STIX_DFL_SYSDIC_SIZE, &symtab_size);
|
||||
}
|
||||
|
||||
if (stix_ignite(stix) <= -1)
|
||||
@ -89,6 +115,7 @@ int main (int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
stix_char_t x[] = { 'S', 't', 'r', 'i', 'n', 'g', '\0' };
|
||||
stix_char_t y[] = { 'S', 'y', 'm', 'b', 'o', 'l', '\0' };
|
||||
@ -98,18 +125,17 @@ a = stix_makesymbol (stix, x, 6);
|
||||
b = stix_makesymbol (stix, y, 6);
|
||||
|
||||
printf ("%p %p\n", a, b);
|
||||
}
|
||||
|
||||
|
||||
dump_symbol_table (stix);
|
||||
|
||||
|
||||
stix_gc (stix);
|
||||
a = stix_findsymbol (stix, x, 6);
|
||||
printf ("%p\n", a);
|
||||
dump_symbol_table (stix);
|
||||
|
||||
}
|
||||
stix_close (stix);
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
printf ("Press the enter key...\n");
|
||||
getchar ();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ void* stix_allocbytes (stix_t* stix, stix_size_t size)
|
||||
stix_uint8_t* ptr;
|
||||
|
||||
#if defined(STIX_DEBUG_GC_1)
|
||||
stix_gc (stix);
|
||||
stix_gc (stix);
|
||||
#endif
|
||||
|
||||
ptr = stix_allocheapmem (stix, stix->curheap, size);
|
||||
@ -65,8 +65,8 @@ stix_oop_t stix_allocoopobj (stix_t* stix, stix_oow_t size)
|
||||
if (!hdr) return STIX_NULL;
|
||||
|
||||
hdr->_flags = STIX_OBJ_MAKE_FLAGS(STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 0, 0);
|
||||
hdr->_size = size;
|
||||
hdr->_class = stix->_nil;
|
||||
STIX_OBJ_SET_SIZE (hdr, size);
|
||||
STIX_OBJ_SET_CLASS (hdr, stix->_nil);
|
||||
|
||||
while (size > 0) hdr->slot[--size] = stix->_nil;
|
||||
|
||||
@ -85,7 +85,7 @@ static stix_oop_t alloc_numeric_array (stix_t* stix, const void* ptr, stix_oow_t
|
||||
* it's useful to store a string with a terminating null */
|
||||
nbytes = extra? xbytes + len: xbytes;
|
||||
nbytes_aligned = STIX_ALIGN(nbytes, STIX_SIZEOF(stix_oop_t));
|
||||
/* TODO: check overflow in size calculation*/
|
||||
/* TODO: check overflow in size calculation*/
|
||||
|
||||
/* making the number of bytes to allocate a multiple of
|
||||
* STIX_SIZEOF(stix_oop_t) will guarantee the starting address
|
||||
@ -96,7 +96,8 @@ static stix_oop_t alloc_numeric_array (stix_t* stix, const void* ptr, stix_oow_t
|
||||
|
||||
hdr->_flags = STIX_OBJ_MAKE_FLAGS(type, unit, extra, 0, 0);
|
||||
hdr->_size = len;
|
||||
hdr->_class = stix->_nil;
|
||||
STIX_OBJ_SET_SIZE (hdr, len);
|
||||
STIX_OBJ_SET_CLASS (hdr, stix->_nil);
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
@ -135,11 +136,12 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
||||
stix_oow_t spec;
|
||||
stix_oow_t named_instvar;
|
||||
stix_obj_type_t indexed_type;
|
||||
stix_oow_t tmp_count = 0;
|
||||
|
||||
STIX_ASSERT (stix->_nil != STIX_NULL);
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_POINTER(_class));
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class);
|
||||
STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class);
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_SMINT(((stix_oop_class_t)_class)->spec));
|
||||
spec = STIX_OOP_TO_SMINT(((stix_oop_class_t)_class)->spec);
|
||||
@ -174,7 +176,7 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
||||
if (named_instvar > STIX_MAX_NAMED_INSTVARS) goto einval;
|
||||
}
|
||||
|
||||
stix_pushtmp (stix, &_class);
|
||||
stix_pushtmp (stix, &_class); tmp_count++;
|
||||
|
||||
switch (indexed_type)
|
||||
{
|
||||
@ -182,9 +184,8 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
||||
/* both the fixed part(named instance variables) and
|
||||
* the variable part(indexed instance variables) are allowed. */
|
||||
oop = stix_allocoopobj(stix, named_instvar + vlen);
|
||||
if (!oop) return STIX_NULL;
|
||||
|
||||
if (vptr && vlen > 0)
|
||||
if (oop && vptr && vlen > 0)
|
||||
{
|
||||
stix_oop_oop_t hdr = (stix_oop_oop_t)oop;
|
||||
STIX_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * STIX_SIZEOF(stix_oop_t));
|
||||
@ -193,30 +194,26 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
|
||||
|
||||
case STIX_OBJ_TYPE_CHAR:
|
||||
oop = stix_alloccharobj(stix, vptr, vlen);
|
||||
if (!oop) return STIX_NULL;
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_UINT8:
|
||||
oop = stix_allocuint8obj(stix, vptr, vlen);
|
||||
if (!oop) return STIX_NULL;
|
||||
break;
|
||||
|
||||
case STIX_OBJ_TYPE_UINT16:
|
||||
oop = stix_allocuint16obj(stix, vptr, vlen);
|
||||
if (!oop) return STIX_NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
stix->errnum = STIX_EINTERN;
|
||||
return STIX_NULL;
|
||||
oop = STIX_NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
STIX_OBJ_SET_CLASS (oop, _class);
|
||||
stix_poptmp (stix);
|
||||
|
||||
if (oop) STIX_OBJ_SET_CLASS (oop, _class);
|
||||
stix_poptmps (stix, tmp_count);
|
||||
return oop;
|
||||
|
||||
|
||||
einval:
|
||||
stix->errnum = STIX_EINVAL;
|
||||
return STIX_NULL;
|
||||
|
@ -171,7 +171,13 @@ stix_oow_t stix_hashbytes (
|
||||
|
||||
stix_oow_t stix_hashchars (
|
||||
const stix_char_t* ptr,
|
||||
stix_size_t len
|
||||
stix_oow_t len
|
||||
);
|
||||
|
||||
int stix_equalchars (
|
||||
const stix_char_t* str1,
|
||||
const stix_char_t* str2,
|
||||
stix_oow_t len
|
||||
);
|
||||
|
||||
/* ========================================================================= */
|
||||
|
@ -92,11 +92,11 @@ int stix_setoption (stix_t* stix, stix_option_t id, const void* value)
|
||||
stix->option.trait = *(const int*)value;
|
||||
return 0;
|
||||
|
||||
case STIX_DEFAULT_SYMTAB_SIZE:
|
||||
stix->option.default_symtab_size = *(stix_oow_t*)value;
|
||||
case STIX_DFL_SYMTAB_SIZE:
|
||||
stix->option.dfl_symtab_size = *(stix_oow_t*)value;
|
||||
|
||||
case STIX_DEFAULT_SYSDIC_SIZE:
|
||||
stix->option.default_sysdic_size = *(stix_oow_t*)value;
|
||||
case STIX_DFL_SYSDIC_SIZE:
|
||||
stix->option.dfl_sysdic_size = *(stix_oow_t*)value;
|
||||
}
|
||||
|
||||
stix->errnum = STIX_EINVAL;
|
||||
@ -111,11 +111,11 @@ int stix_getoption (stix_t* stix, stix_option_t id, void* value)
|
||||
*(int*)value = stix->option.trait;
|
||||
return 0;
|
||||
|
||||
case STIX_DEFAULT_SYMTAB_SIZE:
|
||||
*(stix_oow_t*)value = stix->option.default_symtab_size;
|
||||
case STIX_DFL_SYMTAB_SIZE:
|
||||
*(stix_oow_t*)value = stix->option.dfl_symtab_size;
|
||||
|
||||
case STIX_DEFAULT_SYSDIC_SIZE:
|
||||
*(stix_oow_t*)value = stix->option.default_sysdic_size;
|
||||
case STIX_DFL_SYSDIC_SIZE:
|
||||
*(stix_oow_t*)value = stix->option.dfl_sysdic_size;
|
||||
};
|
||||
|
||||
stix->errnum = STIX_EINVAL;
|
||||
@ -134,9 +134,20 @@ stix_oow_t stix_hashbytes (const stix_uint8_t* ptr, stix_oow_t len)
|
||||
return h;
|
||||
}
|
||||
|
||||
stix_oow_t stix_hashchars (const stix_char_t* ptr, stix_size_t len)
|
||||
stix_oow_t stix_hashchars (const stix_char_t* ptr, stix_oow_t len)
|
||||
{
|
||||
return stix_hashbytes ((const stix_uint8_t *)ptr, len * STIX_SIZEOF(*ptr));
|
||||
}
|
||||
|
||||
int stix_equalchars (const stix_char_t* str1, const stix_char_t* str2, stix_oow_t len)
|
||||
{
|
||||
stix_oow_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (str1[i] != str2[i]) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,26 @@
|
||||
#ifndef _STIX_H_
|
||||
#define _STIX_H_
|
||||
|
||||
#if defined(__MSDOS__)
|
||||
# define STIX_INCPTR(type,base,inc) (((type __huge*)base) + (inc))
|
||||
# define STIX_DECPTR(type,base,inc) (((type __huge*)base) - (inc))
|
||||
# define STIX_GTPTR(type,ptr1,ptr2) (((type __huge*)ptr1) > ((type __huge*)ptr2))
|
||||
# define STIX_GEPTR(type,ptr1,ptr2) (((type __huge*)ptr1) >= ((type __huge*)ptr2))
|
||||
# define STIX_LTPTR(type,ptr1,ptr2) (((type __huge*)ptr1) < ((type __huge*)ptr2))
|
||||
# define STIX_LEPTR(type,ptr1,ptr2) (((type __huge*)ptr1) <= ((type __huge*)ptr2))
|
||||
# define STIX_EQPTR(type,ptr1,ptr2) (((type __huge*)ptr1) == ((type __huge*)ptr2))
|
||||
# define STIX_SUBPTR(type,ptr1,ptr2) (((type __huge*)ptr1) - ((type __huge*)ptr2))
|
||||
#else
|
||||
# define STIX_INCPTR(type,base,inc) (((type*)base) + (inc))
|
||||
# define STIX_DECPTR(type,base,inc) (((type*)base) - (inc))
|
||||
# define STIX_GTPTR(type,ptr1,ptr2) (((type*)ptr1) > ((type*)ptr2))
|
||||
# define STIX_GEPTR(type,ptr1,ptr2) (((type*)ptr1) >= ((type*)ptr2))
|
||||
# define STIX_LTPTR(type,ptr1,ptr2) (((type*)ptr1) < ((type*)ptr2))
|
||||
# define STIX_LEPTR(type,ptr1,ptr2) (((type*)ptr1) <= ((type*)ptr2))
|
||||
# define STIX_EQPTR(type,ptr1,ptr2) (((type*)ptr1) == ((type*)ptr2))
|
||||
# define STIX_SUBPTR(type,ptr1,ptr2) (((type*)ptr1) - ((type*)ptr2))
|
||||
#endif
|
||||
|
||||
/* ========================================================================== */
|
||||
/* TODO: define these types and macros using autoconf */
|
||||
typedef unsigned char stix_uint8_t;
|
||||
@ -189,8 +209,8 @@ typedef enum stix_errnum_t stix_errnum_t;
|
||||
enum stix_option_t
|
||||
{
|
||||
STIX_TRAIT,
|
||||
STIX_DEFAULT_SYMTAB_SIZE,
|
||||
STIX_DEFAULT_SYSDIC_SIZE
|
||||
STIX_DFL_SYMTAB_SIZE,
|
||||
STIX_DFL_SYSDIC_SIZE
|
||||
};
|
||||
typedef enum stix_option_t stix_option_t;
|
||||
|
||||
@ -495,8 +515,12 @@ typedef enum stix_obj_type_t stix_obj_type_t;
|
||||
|
||||
#define STIX_OBJ_GET_SIZE(oop) ((oop)->_size)
|
||||
#define STIX_OBJ_GET_CLASS(oop) ((oop)->_class)
|
||||
|
||||
#define STIX_OBJ_SET_SIZE(oop,v) ((oop)->_size = (v))
|
||||
#define STIX_OBJ_SET_CLASS(oop,c) ((oop)->_class = (c))
|
||||
|
||||
#define STIX_OBJ_BYTESOF(oop) ((STIX_OBJ_GET_SIZE(oop) + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop))
|
||||
|
||||
/* this macro doesn't check the range of the actual value.
|
||||
* make sure that the value of each bit fields given fall within the number
|
||||
* of defined bits */
|
||||
@ -655,18 +679,22 @@ enum stix_class_desc_t
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The STIX_CLASSOF() macro return the class of an object including a numeric
|
||||
* object encoded into a pointer.
|
||||
*/
|
||||
#define STIX_CLASSOF(stix,oop) ( \
|
||||
STIX_OOP_IS_SMINT(oop)? (stix)->_small_integer: \
|
||||
STIX_OOP_IS_CHAR(oop)? (stix)->_character: (oop)->_class \
|
||||
STIX_OOP_IS_CHAR(oop)? (stix)->_character: STIX_OBJ_GET_CLASS(oop) \
|
||||
)
|
||||
|
||||
/*
|
||||
/**
|
||||
* The STIX_BYTESOF() macro returns the size of the payload of
|
||||
* an object in bytes. If the pointer given encodes a numeric value,
|
||||
* it returns the size of #stix_oow_t in bytes.
|
||||
*/
|
||||
#define STIX_BYTESOF(stix,oop) \
|
||||
(STIX_OOP_IS_NUMERIC(oop)? \
|
||||
(STIX_SIZEOF(stix_oow_t)): \
|
||||
(STIX_SIZEOF(stix_obj_t) + STIX_ALIGN(((oop)->size + (oop)->extra) * (oop)->unit), STIX_SIZEOF(stix_oop_t)) \
|
||||
)
|
||||
*/
|
||||
(STIX_OOP_IS_NUMERIC(oop)? STIX_SIZEOF(stix_oow_t): STIX_OBJ_BYTESOF(oop))
|
||||
|
||||
typedef struct stix_heap_t stix_heap_t;
|
||||
|
||||
@ -687,8 +715,8 @@ struct stix_t
|
||||
struct
|
||||
{
|
||||
int trait;
|
||||
stix_oow_t default_symtab_size;
|
||||
stix_oow_t default_sysdic_size;
|
||||
stix_oow_t dfl_symtab_size;
|
||||
stix_oow_t dfl_sysdic_size;
|
||||
} option;
|
||||
|
||||
/* ========================= */
|
||||
|
@ -79,18 +79,12 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_char_t* ptr, sti
|
||||
symbol = (stix_oop_char_t)stix->symtab->bucket->slot[index];
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,symbol) == (stix_oop_t)stix->_symbol);
|
||||
|
||||
if (len == STIX_OBJ_GET_SIZE(symbol))
|
||||
if (len == STIX_OBJ_GET_SIZE(symbol) &&
|
||||
stix_equalchars (ptr, symbol->slot, len))
|
||||
{
|
||||
stix_oow_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (ptr[i] != symbol->slot[i]) goto not_equal;
|
||||
}
|
||||
return (stix_oop_t)symbol;
|
||||
}
|
||||
|
||||
not_equal:
|
||||
index = (index + 1) % STIX_OBJ_GET_SIZE(stix->symtab->bucket);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user