touched up various size related definitions and code
This commit is contained in:
		@ -257,7 +257,7 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o
 | 
				
			|||||||
	stix_oow_t w;
 | 
						stix_oow_t w;
 | 
				
			||||||
	stix_oop_t z;
 | 
						stix_oop_t z;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	STIX_ASSERT (extra <= STIX_TYPE_MAX(stix_oow_t) - 1); 
 | 
						STIX_ASSERT (extra <= STIX_OBJ_SIZE_MAX - 1); 
 | 
				
			||||||
	STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t));
 | 
						STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t));
 | 
				
			||||||
	if (i >= 0)
 | 
						if (i >= 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -280,7 +280,7 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o
 | 
				
			|||||||
	stix_oow_t w;
 | 
						stix_oow_t w;
 | 
				
			||||||
	stix_oop_t z;
 | 
						stix_oop_t z;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	STIX_ASSERT (extra <= STIX_TYPE_MAX(stix_oow_t) - 2); 
 | 
						STIX_ASSERT (extra <= STIX_OBJ_SIZE_MAX - 2); 
 | 
				
			||||||
	if (i >= 0)
 | 
						if (i >= 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		w = i;
 | 
							w = i;
 | 
				
			||||||
@ -337,7 +337,7 @@ static STIX_INLINE stix_oop_t expand_bigint (stix_t* stix, stix_oop_t oop, stix_
 | 
				
			|||||||
	STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
 | 
						STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
 | 
				
			||||||
	count = STIX_OBJ_GET_SIZE(oop);
 | 
						count = STIX_OBJ_GET_SIZE(oop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (inc > STIX_TYPE_MAX(stix_oow_t) - count)
 | 
						if (inc > STIX_OBJ_SIZE_MAX - count)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		stix->errnum = STIX_ENOMEM; /* TODO: is it a soft failure or a hard failure? is this error code proper? */
 | 
							stix->errnum = STIX_ENOMEM; /* TODO: is it a soft failure or a hard failure? is this error code proper? */
 | 
				
			||||||
		return STIX_NULL;
 | 
							return STIX_NULL;
 | 
				
			||||||
@ -855,7 +855,7 @@ static stix_oop_t add_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t
 | 
				
			|||||||
	bs = STIX_OBJ_GET_SIZE(y);
 | 
						bs = STIX_OBJ_GET_SIZE(y);
 | 
				
			||||||
	zs = (as >= bs? as: bs);
 | 
						zs = (as >= bs? as: bs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (zs >= STIX_TYPE_MAX(stix_oow_t))
 | 
						if (zs >= STIX_OBJ_SIZE_MAX)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		stix->errnum = STIX_ENOMEM; /* TOOD: is it a soft failure or hard failure? */
 | 
							stix->errnum = STIX_ENOMEM; /* TOOD: is it a soft failure or hard failure? */
 | 
				
			||||||
		return STIX_NULL;
 | 
							return STIX_NULL;
 | 
				
			||||||
@ -916,7 +916,7 @@ static stix_oop_t multiply_unsigned_integers (stix_t* stix, stix_oop_t x, stix_o
 | 
				
			|||||||
	xz = STIX_OBJ_GET_SIZE(x);
 | 
						xz = STIX_OBJ_GET_SIZE(x);
 | 
				
			||||||
	yz = STIX_OBJ_GET_SIZE(y);
 | 
						yz = STIX_OBJ_GET_SIZE(y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (yz > STIX_TYPE_MAX(stix_oow_t) - xz)
 | 
						if (yz > STIX_OBJ_SIZE_MAX - xz)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		stix->errnum = STIX_ENOMEM; /* TOOD: is it a soft failure or hard failure? */
 | 
							stix->errnum = STIX_ENOMEM; /* TOOD: is it a soft failure or hard failure? */
 | 
				
			||||||
		return STIX_NULL;
 | 
							return STIX_NULL;
 | 
				
			||||||
 | 
				
			|||||||
@ -33,15 +33,39 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc)
 | 
				
			|||||||
	stix_oop_association_t ass;
 | 
						stix_oop_association_t ass;
 | 
				
			||||||
	stix_oop_char_t key;
 | 
						stix_oop_char_t key;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* TODO: derive a better growth size */
 | 
						oldsz = STIX_OBJ_GET_SIZE(oldbuc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* TODO: better growth policy? */
 | 
				
			||||||
 | 
						if (oldsz < 5000) newsz = oldsz + oldsz;
 | 
				
			||||||
 | 
						else if (oldsz < 50000) newsz = oldsz + (oldsz / 2);
 | 
				
			||||||
 | 
						else if (oldsz < 100000) newsz = oldsz + (oldsz / 4);
 | 
				
			||||||
 | 
						else if (oldsz < 200000) newsz = oldsz + (oldsz / 8);
 | 
				
			||||||
 | 
						else if (oldsz < 400000) newsz = oldsz + (oldsz / 16);
 | 
				
			||||||
 | 
						else if (oldsz < 800000) newsz = oldsz + (oldsz / 32);
 | 
				
			||||||
 | 
						else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64);
 | 
				
			||||||
 | 
						else 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							stix_oow_t inc, inc_max;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inc = oldsz / 128;
 | 
				
			||||||
 | 
							inc_max = STIX_OBJ_SIZE_MAX - oldsz;
 | 
				
			||||||
 | 
							if (inc > inc_max) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (inc_max > 0) inc = inc_max;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									stix->errnum = STIX_ENOMEM;
 | 
				
			||||||
 | 
									return STIX_NULL;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							newsz = oldsz + inc;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	stix_pushtmp (stix, (stix_oop_t*)&oldbuc);
 | 
						stix_pushtmp (stix, (stix_oop_t*)&oldbuc);
 | 
				
			||||||
	newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(oldbuc) * 2); 
 | 
						newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, newsz); 
 | 
				
			||||||
	stix_poptmp (stix);
 | 
						stix_poptmp (stix);
 | 
				
			||||||
	if (!newbuc) return STIX_NULL;
 | 
						if (!newbuc) return STIX_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oldsz = STIX_OBJ_GET_SIZE(oldbuc);
 | 
					 | 
				
			||||||
	newsz = STIX_OBJ_GET_SIZE(newbuc);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	while (oldsz > 0)
 | 
						while (oldsz > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		ass = (stix_oop_association_t)oldbuc->slot[--oldsz];
 | 
							ass = (stix_oop_association_t)oldbuc->slot[--oldsz];
 | 
				
			||||||
 | 
				
			|||||||
@ -384,7 +384,7 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
	stix_vmprim_t vmprim;
 | 
						stix_vmprim_t vmprim;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	printf ("Stix 1.0.0 - max named %lu max indexed %lu max class %lu max classinst %lu oowmax %lu, ooimax %ld ooimin %ld smintmax %ld smintmax %ld\n", 
 | 
						printf ("Stix 1.0.0 - max named %lu max indexed %lu max class %lu max classinst %lu oowmax %lu, ooimax %ld ooimin %ld smooimax %ld smooimax %ld\n", 
 | 
				
			||||||
		(unsigned long int)STIX_MAX_NAMED_INSTVARS, 
 | 
							(unsigned long int)STIX_MAX_NAMED_INSTVARS, 
 | 
				
			||||||
		(unsigned long int)STIX_MAX_INDEXED_INSTVARS(STIX_MAX_NAMED_INSTVARS),
 | 
							(unsigned long int)STIX_MAX_INDEXED_INSTVARS(STIX_MAX_NAMED_INSTVARS),
 | 
				
			||||||
		(unsigned long int)STIX_MAX_CLASSVARS,
 | 
							(unsigned long int)STIX_MAX_CLASSVARS,
 | 
				
			||||||
 | 
				
			|||||||
@ -199,11 +199,14 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				goto einval;
 | 
									goto einval;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								STIX_ASSERT (named_instvar + vlen <= STIX_OBJ_SIZE_MAX);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			/* a non-pointer indexed class can't have named instance variables */
 | 
								/* a non-pointer indexed class can't have named instance variables */
 | 
				
			||||||
			if (named_instvar > 0) goto einval;
 | 
								if (named_instvar > 0) goto einval;
 | 
				
			||||||
 | 
								if (vlen > STIX_OBJ_SIZE_MAX) goto einval;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
@ -211,9 +214,10 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr,
 | 
				
			|||||||
		/* named instance variables only. treat it as if it is an
 | 
							/* named instance variables only. treat it as if it is an
 | 
				
			||||||
		 * indexable class with no variable data */
 | 
							 * indexable class with no variable data */
 | 
				
			||||||
		indexed_type = STIX_OBJ_TYPE_OOP;
 | 
							indexed_type = STIX_OBJ_TYPE_OOP;
 | 
				
			||||||
		vlen = 0;
 | 
							vlen = 0; /* vlen is not used */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (named_instvar > STIX_MAX_NAMED_INSTVARS) goto einval;
 | 
							if (named_instvar > STIX_MAX_NAMED_INSTVARS) goto einval;
 | 
				
			||||||
 | 
							STIX_ASSERT (named_instvar <= STIX_OBJ_SIZE_MAX);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	stix_pushtmp (stix, &_class); tmp_count++;
 | 
						stix_pushtmp (stix, &_class); tmp_count++;
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,6 @@
 | 
				
			|||||||
/*#define STIX_DEBUG_EXEC*/
 | 
					/*#define STIX_DEBUG_EXEC*/
 | 
				
			||||||
#define STIX_PROFILE_EXEC
 | 
					#define STIX_PROFILE_EXEC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <stdio.h> /* TODO: delete these header inclusion lines */
 | 
					#include <stdio.h> /* TODO: delete these header inclusion lines */
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
@ -118,8 +117,9 @@
 | 
				
			|||||||
 * |number of named instance variables|indexed-type|indexability|oop-tag|
 | 
					 * |number of named instance variables|indexed-type|indexability|oop-tag|
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * the number of named instance variables is stored in high 23 bits.
 | 
					 * the number of named instance variables is stored in high 23 bits.
 | 
				
			||||||
 * the indexed type takes up bit 3 to bit 8. And the indexability is
 | 
					 * the indexed type takes up bit 3 to bit 8 (assuming STIX_OBJ_TYPE_BITS is 6. 
 | 
				
			||||||
 * stored in bit 2. 
 | 
					 * STIX_OBJ_TYPE_XXX enumerators are used to represent actual values).
 | 
				
			||||||
 | 
					 * and the indexability is stored in bit 2.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * The maximum number of named(fixed) instance variables for a class is:
 | 
					 * The maximum number of named(fixed) instance variables for a class is:
 | 
				
			||||||
 *     2 ^ ((BITS-IN-OOW - STIX_OOP_TAG_BITS) - STIX_OBJ_TYPE_BITS - 1) - 1
 | 
					 *     2 ^ ((BITS-IN-OOW - STIX_OOP_TAG_BITS) - STIX_OBJ_TYPE_BITS - 1) - 1
 | 
				
			||||||
@ -163,11 +163,15 @@
 | 
				
			|||||||
 * This limit is set so because the number must be encoded into the spec field
 | 
					 * This limit is set so because the number must be encoded into the spec field
 | 
				
			||||||
 * of the class with limited number of bits assigned to the number of
 | 
					 * of the class with limited number of bits assigned to the number of
 | 
				
			||||||
 * named instance variables. the trailing -1 in the calculation of number of
 | 
					 * named instance variables. the trailing -1 in the calculation of number of
 | 
				
			||||||
 * bits is to consider the signness of a small-integer which is a typical
 | 
					 * bits is to consider the sign bit of a small-integer which is a typical
 | 
				
			||||||
 * type of the spec field in the class object.
 | 
					 * type of the spec field in the class object.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
#define STIX_MAX_NAMED_INSTVARS \
 | 
					#define STIX_MAX_NAMED_INSTVARS \
 | 
				
			||||||
	STIX_BITS_MAX(stix_oow_t, STIX_OOW_BITS - STIX_OOP_TAG_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1) - 1)
 | 
						STIX_BITS_MAX(stix_oow_t, STIX_OOW_BITS - STIX_OOP_TAG_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1) - 1)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#define STIX_MAX_NAMED_INSTVARS \
 | 
				
			||||||
 | 
						STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Given the number of named instance variables, what is the maximum number 
 | 
					/* Given the number of named instance variables, what is the maximum number 
 | 
				
			||||||
 * of indexed instance variables? The number of indexed instance variables
 | 
					 * of indexed instance variables? The number of indexed instance variables
 | 
				
			||||||
@ -176,21 +180,32 @@
 | 
				
			|||||||
 * named instance variables. So it's the maximum value of obj->_size minus
 | 
					 * named instance variables. So it's the maximum value of obj->_size minus
 | 
				
			||||||
 * the number of named instance variables.
 | 
					 * the number of named instance variables.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define STIX_MAX_INDEXED_INSTVARS(named_instvar) ((~(stix_oow_t)0) - named_instvar)
 | 
					#define STIX_MAX_INDEXED_INSTVARS(named_instvar) (STIX_OBJ_SIZE_MAX - named_instvar)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
#define STIX_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \
 | 
					#define STIX_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \
 | 
				
			||||||
	(((stix_oow_t)class_var) << ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)) | ((stix_oow_t)classinst_var)
 | 
						(((stix_oow_t)class_var) << ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)) | ((stix_oow_t)classinst_var)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#define STIX_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \
 | 
				
			||||||
 | 
						(((stix_oow_t)class_var) << (STIX_SMOOI_BITS / 2)) | ((stix_oow_t)classinst_var)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
 | 
					#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
 | 
				
			||||||
#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
 | 
					#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> (STIX_SMOOI_BITS / 2))
 | 
				
			||||||
 | 
					#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_SMOOI_BITS / 2)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * yet another -1 in the calculation of the bit numbers for signed nature of
 | 
					 * yet another -1 in the calculation of the bit numbers for signed nature of
 | 
				
			||||||
 * a small-integer
 | 
					 * a small-integer
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
#define STIX_MAX_CLASSVARS      STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
 | 
					#define STIX_MAX_CLASSVARS      STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
 | 
				
			||||||
#define STIX_MAX_CLASSINSTVARS  STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
 | 
					#define STIX_MAX_CLASSINSTVARS  STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#define STIX_MAX_CLASSVARS      STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS / 2)
 | 
				
			||||||
 | 
					#define STIX_MAX_CLASSINSTVARS  STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS / 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(STIX_INCLUDE_COMPILER)
 | 
					#if defined(STIX_INCLUDE_COMPILER)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -163,10 +163,14 @@ typedef struct stix_obj_word_t*     stix_oop_word_t;
 | 
				
			|||||||
#define STIX_CHAR_TO_OOP(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_CHAR))
 | 
					#define STIX_CHAR_TO_OOP(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_CHAR))
 | 
				
			||||||
#define STIX_OOP_TO_CHAR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS)
 | 
					#define STIX_OOP_TO_CHAR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define STIX_SMINT_BITS (STIX_SIZEOF(stix_ooi_t) * 8 - STIX_OOP_TAG_BITS)
 | 
					/* SMOOI takes up 62 bit on a 64-bit architecture and 30 bits 
 | 
				
			||||||
 | 
					 * on a 32-bit architecture. The absolute value takes up 61 bits and 29 bits
 | 
				
			||||||
 | 
					 * respectively for the 1 sign bit. */
 | 
				
			||||||
 | 
					#define STIX_SMOOI_BITS (STIX_OOI_BITS - STIX_OOP_TAG_BITS)
 | 
				
			||||||
 | 
					#define STIX_SMOOI_ABS_BITS (STIX_SMOOI_BITS - 1)
 | 
				
			||||||
#define STIX_SMOOI_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1)))
 | 
					#define STIX_SMOOI_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1)))
 | 
				
			||||||
/* Sacrificing 1 bit pattern for a negative SMOOI makes implementation
 | 
					/* Sacrificing 1 bit pattern for a negative SMOOI makes 
 | 
				
			||||||
 * a lot eaisier in many parts */
 | 
					 * implementation a lot eaisier in many respect. */
 | 
				
			||||||
/*#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX - 1)*/
 | 
					/*#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX - 1)*/
 | 
				
			||||||
#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX)
 | 
					#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX)
 | 
				
			||||||
#define STIX_IN_SMOOI_RANGE(ooi)  ((ooi) >= STIX_SMOOI_MIN && (ooi) <= STIX_SMOOI_MAX)
 | 
					#define STIX_IN_SMOOI_RANGE(ooi)  ((ooi) >= STIX_SMOOI_MIN && (ooi) <= STIX_SMOOI_MAX)
 | 
				
			||||||
@ -188,7 +192,6 @@ enum stix_obj_type_t
 | 
				
			|||||||
	STIX_OBJ_TYPE_HALFWORD,
 | 
						STIX_OBJ_TYPE_HALFWORD,
 | 
				
			||||||
	STIX_OBJ_TYPE_WORD,
 | 
						STIX_OBJ_TYPE_WORD,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
	STIX_OBJ_TYPE_UINT8,
 | 
						STIX_OBJ_TYPE_UINT8,
 | 
				
			||||||
	STIX_OBJ_TYPE_UINT16,
 | 
						STIX_OBJ_TYPE_UINT16,
 | 
				
			||||||
@ -293,6 +296,9 @@ typedef enum stix_obj_type_t stix_obj_type_t;
 | 
				
			|||||||
	(((stix_oow_t)(r)) << 0) \
 | 
						(((stix_oow_t)(r)) << 0) \
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define STIX_OBJ_SIZE_MAX ((stix_oow_t)STIX_SMOOI_MAX)
 | 
				
			||||||
 | 
					/*#define STIX_OBJ_SIZE_MAX ((stix_oow_t)STIX_TYPE_MAX(stix_oow_t))*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define STIX_OBJ_HEADER \
 | 
					#define STIX_OBJ_HEADER \
 | 
				
			||||||
	stix_oow_t _flags; \
 | 
						stix_oow_t _flags; \
 | 
				
			||||||
	stix_oow_t _size; \
 | 
						stix_oow_t _size; \
 | 
				
			||||||
 | 
				
			|||||||
@ -32,15 +32,39 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc)
 | 
				
			|||||||
	stix_oow_t oldsz, newsz, index;
 | 
						stix_oow_t oldsz, newsz, index;
 | 
				
			||||||
	stix_oop_char_t symbol;
 | 
						stix_oop_char_t symbol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* TODO: derive a better growth size */
 | 
						oldsz = STIX_OBJ_GET_SIZE(oldbuc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* TODO: better growth policy? */
 | 
				
			||||||
 | 
						if (oldsz < 5000) newsz = oldsz + oldsz;
 | 
				
			||||||
 | 
						else if (oldsz < 50000) newsz = oldsz + (oldsz / 2);
 | 
				
			||||||
 | 
						else if (oldsz < 100000) newsz = oldsz + (oldsz / 4);
 | 
				
			||||||
 | 
						else if (oldsz < 200000) newsz = oldsz + (oldsz / 8);
 | 
				
			||||||
 | 
						else if (oldsz < 400000) newsz = oldsz + (oldsz / 16);
 | 
				
			||||||
 | 
						else if (oldsz < 800000) newsz = oldsz + (oldsz / 32);
 | 
				
			||||||
 | 
						else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64);
 | 
				
			||||||
 | 
						else 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							stix_oow_t inc, inc_max;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inc = oldsz / 128;
 | 
				
			||||||
 | 
							inc_max = STIX_OBJ_SIZE_MAX - oldsz;
 | 
				
			||||||
 | 
							if (inc > inc_max) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (inc_max > 0) inc = inc_max;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									stix->errnum = STIX_ENOMEM;
 | 
				
			||||||
 | 
									return STIX_NULL;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							newsz = oldsz + inc;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	stix_pushtmp (stix, (stix_oop_t*)&oldbuc);
 | 
						stix_pushtmp (stix, (stix_oop_t*)&oldbuc);
 | 
				
			||||||
	newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(oldbuc) * 2); 
 | 
						newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, newsz); 
 | 
				
			||||||
	stix_poptmp (stix);
 | 
						stix_poptmp (stix);
 | 
				
			||||||
	if (!newbuc) return STIX_NULL;
 | 
						if (!newbuc) return STIX_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oldsz = STIX_OBJ_GET_SIZE(oldbuc);
 | 
					 | 
				
			||||||
	newsz = STIX_OBJ_GET_SIZE(newbuc);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	while (oldsz > 0)
 | 
						while (oldsz > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		symbol = (stix_oop_char_t)oldbuc->slot[--oldsz];
 | 
							symbol = (stix_oop_char_t)oldbuc->slot[--oldsz];
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user