Lay the groundwork for on-demand dictionary expansion.
This commit is contained in:
parent
56f09cbe0e
commit
64e1aa5faa
@ -29,6 +29,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ficl.h"
|
#include "ficl.h"
|
||||||
|
|
||||||
|
/* Dictionary on-demand resizing control variables */
|
||||||
|
unsigned int dictThreshold;
|
||||||
|
unsigned int dictIncrease;
|
||||||
|
|
||||||
|
|
||||||
static char *dictCopyName(FICL_DICT *pDict, STRINGINFO si);
|
static char *dictCopyName(FICL_DICT *pDict, STRINGINFO si);
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@ -347,12 +352,14 @@ FICL_DICT *dictCreateHashed(unsigned nCells, unsigned nHash)
|
|||||||
FICL_DICT *pDict;
|
FICL_DICT *pDict;
|
||||||
size_t nAlloc;
|
size_t nAlloc;
|
||||||
|
|
||||||
nAlloc = sizeof (FICL_DICT) + nCells * sizeof (CELL)
|
nAlloc = sizeof (FICL_HASH) + nCells * sizeof (CELL)
|
||||||
+ sizeof (FICL_HASH) + (nHash - 1) * sizeof (FICL_WORD *);
|
+ (nHash - 1) * sizeof (FICL_WORD *);
|
||||||
|
|
||||||
pDict = ficlMalloc(nAlloc);
|
pDict = ficlMalloc(sizeof (FICL_DICT));
|
||||||
assert(pDict);
|
assert(pDict);
|
||||||
memset(pDict, 0, sizeof (FICL_DICT));
|
memset(pDict, 0, sizeof (FICL_DICT));
|
||||||
|
pDict->dict = ficlMalloc(nAlloc);
|
||||||
|
assert(pDict->dict);
|
||||||
pDict->size = nCells;
|
pDict->size = nCells;
|
||||||
dictEmpty(pDict, nHash);
|
dictEmpty(pDict, nHash);
|
||||||
return pDict;
|
return pDict;
|
||||||
@ -701,4 +708,19 @@ void hashReset(FICL_HASH *pHash)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
d i c t C h e c k T h r e s h o l d
|
||||||
|
** Verify if an increase in the dictionary size is warranted, and do it if
|
||||||
|
** so.
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
void dictCheckThreshold(FICL_DICT* dp)
|
||||||
|
{
|
||||||
|
if( dictCellsAvail(dp) < dictThreshold ) {
|
||||||
|
dp->dict = ficlMalloc( dictIncrease * sizeof (CELL) );
|
||||||
|
assert(dp->dict);
|
||||||
|
dp->here = dp->dict;
|
||||||
|
dp->size = dictIncrease;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ typedef struct ficl_dict
|
|||||||
FICL_HASH *pSearch[FICL_DEFAULT_VOCS];
|
FICL_HASH *pSearch[FICL_DEFAULT_VOCS];
|
||||||
int nLists;
|
int nLists;
|
||||||
unsigned size; /* Number of cells in dict (total)*/
|
unsigned size; /* Number of cells in dict (total)*/
|
||||||
CELL dict[1]; /* Base of dictionary memory */
|
CELL *dict; /* Base of dictionary memory */
|
||||||
} FICL_DICT;
|
} FICL_DICT;
|
||||||
|
|
||||||
void *alignPtr(void *ptr);
|
void *alignPtr(void *ptr);
|
||||||
@ -828,6 +828,12 @@ void ficlCompileSoftCore(FICL_VM *pVM);
|
|||||||
void constantParen(FICL_VM *pVM);
|
void constantParen(FICL_VM *pVM);
|
||||||
void twoConstParen(FICL_VM *pVM);
|
void twoConstParen(FICL_VM *pVM);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Dictionary on-demand resizing
|
||||||
|
*/
|
||||||
|
extern unsigned int dictThreshold;
|
||||||
|
extern unsigned int dictIncrease;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** So we can more easily debug...
|
** So we can more easily debug...
|
||||||
*/
|
*/
|
||||||
|
@ -72,7 +72,6 @@ static FICL_WORD *pUnLinkParen = NULL;
|
|||||||
static int nLocals = 0;
|
static int nLocals = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** C O N T R O L S T R U C T U R E B U I L D E R S
|
** C O N T R O L S T R U C T U R E B U I L D E R S
|
||||||
**
|
**
|
||||||
@ -431,6 +430,8 @@ static void colon(FICL_VM *pVM)
|
|||||||
FICL_DICT *dp = ficlGetDict();
|
FICL_DICT *dp = ficlGetDict();
|
||||||
STRINGINFO si = vmGetWord(pVM);
|
STRINGINFO si = vmGetWord(pVM);
|
||||||
|
|
||||||
|
dictCheckThreshold(dp);
|
||||||
|
|
||||||
pVM->state = COMPILE;
|
pVM->state = COMPILE;
|
||||||
markControlTag(pVM, colonTag);
|
markControlTag(pVM, colonTag);
|
||||||
dictAppendWord2(dp, si, colonParen, FW_DEFAULT | FW_SMUDGE);
|
dictAppendWord2(dp, si, colonParen, FW_DEFAULT | FW_SMUDGE);
|
||||||
@ -4472,6 +4473,18 @@ static void dnegate(FICL_VM *pVM)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************* Increase dictionary size on-demand ******************/
|
||||||
|
|
||||||
|
static void ficlDictThreshold(FICL_VM *pVM)
|
||||||
|
{
|
||||||
|
stackPushPtr(pVM->pStack, &dictThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ficlDictIncrease(FICL_VM *pVM)
|
||||||
|
{
|
||||||
|
stackPushPtr(pVM->pStack, &dictIncrease);
|
||||||
|
}
|
||||||
|
|
||||||
/************************* freebsd added trace ***************************/
|
/************************* freebsd added trace ***************************/
|
||||||
|
|
||||||
#ifdef FICL_TRACE
|
#ifdef FICL_TRACE
|
||||||
@ -4658,6 +4671,8 @@ void ficlCompileCore(FICL_DICT *dp)
|
|||||||
dictAppendWord(dp, "ms", ms, FW_DEFAULT);
|
dictAppendWord(dp, "ms", ms, FW_DEFAULT);
|
||||||
dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT);
|
dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT);
|
||||||
dictAppendWord(dp, "heap?", freeHeap, FW_DEFAULT);
|
dictAppendWord(dp, "heap?", freeHeap, FW_DEFAULT);
|
||||||
|
dictAppendWord(dp, "dictthreshold", ficlDictThreshold, FW_DEFAULT);
|
||||||
|
dictAppendWord(dp, "dictincrease", ficlDictIncrease, FW_DEFAULT);
|
||||||
#ifdef FICL_TRACE
|
#ifdef FICL_TRACE
|
||||||
dictAppendWord(dp, "trace!", ficlTrace, FW_DEFAULT);
|
dictAppendWord(dp, "trace!", ficlTrace, FW_DEFAULT);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user