changed arr to use gem instead of hawk

This commit is contained in:
hyung-hwan 2019-12-16 15:09:58 +00:00
parent 58d06e55b3
commit e21d307a8c
11 changed files with 124 additions and 129 deletions

View File

@ -28,7 +28,7 @@
#include "hawk-prv.h" #include "hawk-prv.h"
///////////////////////////////// /////////////////////////////////
HAWK_BEGIN_NAMESPACE(QSE) HAWK_BEGIN_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -1702,7 +1702,7 @@ int Hawk::dispatch_function (Run* run, const fnc_info_t* fi)
// call the default constructor on the space allocated above. // call the default constructor on the space allocated above.
// no exception handling is implemented here as i know // no exception handling is implemented here as i know
// that Value::Value() doesn't throw an exception // that Value::Value() doesn't throw an exception
new((QSE::Mmgr*)HAWK_NULL, (void*)&args[i]) Value (); new((HAWK::Mmgr*)HAWK_NULL, (void*)&args[i]) Value ();
} }
#endif #endif
} }
@ -2449,5 +2449,5 @@ void* Hawk::modsym (awk_t* awk, void* handle, const char_t* name)
return xtn->awk->modsym (handle, name); return xtn->awk->modsym (handle, name);
} }
///////////////////////////////// /////////////////////////////////
HAWK_END_NAMESPACE(QSE) HAWK_END_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////

View File

@ -44,7 +44,7 @@
/// AWK Interpreter /// AWK Interpreter
///////////////////////////////// /////////////////////////////////
HAWK_BEGIN_NAMESPACE(QSE) HAWK_BEGIN_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////
/// ///
@ -1424,7 +1424,7 @@ private:
}; };
///////////////////////////////// /////////////////////////////////
HAWK_END_NAMESPACE(QSE) HAWK_END_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////
#endif #endif

View File

@ -47,7 +47,7 @@
///////////////////////////////// /////////////////////////////////
HAWK_BEGIN_NAMESPACE(QSE) HAWK_BEGIN_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////
StdHawk::ioattr_t StdHawk::default_ioattr; StdHawk::ioattr_t StdHawk::default_ioattr;
@ -1371,6 +1371,6 @@ StdHawk::ssize_t StdHawk::SourceString::write (Data& io, const char_t* buf, size
} }
///////////////////////////////// /////////////////////////////////
HAWK_END_NAMESPACE(QSE) HAWK_END_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////

View File

@ -34,7 +34,7 @@
/// Standard AWK Interpreter /// Standard AWK Interpreter
///////////////////////////////// /////////////////////////////////
HAWK_BEGIN_NAMESPACE(QSE) HAWK_BEGIN_NAMESPACE(HAWK)
//////////////////////////////// ////////////////////////////////
/// ///
@ -219,7 +219,7 @@ private:
}; };
///////////////////////////////// /////////////////////////////////
HAWK_END_NAMESPACE(QSE) HAWK_END_NAMESPACE(HAWK)
///////////////////////////////// /////////////////////////////////
#endif #endif

View File

@ -70,13 +70,13 @@ static HAWK_INLINE slot_t* alloc_slot (hawk_arr_t* arr, void* dptr, hawk_oow_t d
if (arr->copier == HAWK_ARR_COPIER_SIMPLE) if (arr->copier == HAWK_ARR_COPIER_SIMPLE)
{ {
n = (slot_t*)hawk_allocmem(arr->hawk, HAWK_SIZEOF(slot_t)); n = (slot_t*)hawk_gem_allocmem(arr->gem, HAWK_SIZEOF(slot_t));
if (!n) return HAWK_NULL; if (!n) return HAWK_NULL;
DPTR(n) = dptr; DPTR(n) = dptr;
} }
else if (arr->copier == HAWK_ARR_COPIER_INLINE) else if (arr->copier == HAWK_ARR_COPIER_INLINE)
{ {
n = (slot_t*)hawk_allocmem(arr->hawk, HAWK_SIZEOF(slot_t) + TOB(arr,dlen)); n = (slot_t*)hawk_gem_allocmem(arr->gem, HAWK_SIZEOF(slot_t) + TOB(arr,dlen));
if (!n) return HAWK_NULL; if (!n) return HAWK_NULL;
HAWK_MEMCPY (n + 1, dptr, TOB(arr,dlen)); HAWK_MEMCPY (n + 1, dptr, TOB(arr,dlen));
@ -84,12 +84,12 @@ static HAWK_INLINE slot_t* alloc_slot (hawk_arr_t* arr, void* dptr, hawk_oow_t d
} }
else else
{ {
n = (slot_t*)hawk_allocmem(arr->hawk, HAWK_SIZEOF(slot_t)); n = (slot_t*)hawk_gem_allocmem(arr->gem, HAWK_SIZEOF(slot_t));
if (!n) return HAWK_NULL; if (!n) return HAWK_NULL;
DPTR(n) = arr->copier (arr, dptr, dlen); DPTR(n) = arr->copier(arr, dptr, dlen);
if (DPTR(n) == HAWK_NULL) if (DPTR(n) == HAWK_NULL)
{ {
hawk_freemem (arr->hawk, n); hawk_gem_freemem (arr->gem, n);
return HAWK_NULL; return HAWK_NULL;
} }
} }
@ -99,16 +99,16 @@ static HAWK_INLINE slot_t* alloc_slot (hawk_arr_t* arr, void* dptr, hawk_oow_t d
return n; return n;
} }
hawk_arr_t* hawk_arr_open (hawk_t* awk, hawk_oow_t xtnsize, hawk_oow_t capa) hawk_arr_t* hawk_arr_open (hawk_gem_t* gem, hawk_oow_t xtnsize, hawk_oow_t capa)
{ {
hawk_arr_t* arr; hawk_arr_t* arr;
arr = (hawk_arr_t*)hawk_allocmem(awk, HAWK_SIZEOF(hawk_arr_t) + xtnsize); arr = (hawk_arr_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_arr_t) + xtnsize);
if (arr == HAWK_NULL) return HAWK_NULL; if (arr == HAWK_NULL) return HAWK_NULL;
if (hawk_arr_init(arr, awk, capa) <= -1) if (hawk_arr_init(arr, gem, capa) <= -1)
{ {
hawk_freemem (awk, arr); hawk_gem_freemem (gem, arr);
return HAWK_NULL; return HAWK_NULL;
} }
@ -119,14 +119,14 @@ hawk_arr_t* hawk_arr_open (hawk_t* awk, hawk_oow_t xtnsize, hawk_oow_t capa)
void hawk_arr_close (hawk_arr_t* arr) void hawk_arr_close (hawk_arr_t* arr)
{ {
hawk_arr_fini (arr); hawk_arr_fini (arr);
hawk_freemem (arr->hawk, arr); hawk_gem_freemem (arr->gem, arr);
} }
int hawk_arr_init (hawk_arr_t* arr, hawk_t* awk, hawk_oow_t capa) int hawk_arr_init (hawk_arr_t* arr, hawk_gem_t* gem, hawk_oow_t capa)
{ {
HAWK_MEMSET (arr, 0, HAWK_SIZEOF(*arr)); HAWK_MEMSET (arr, 0, HAWK_SIZEOF(*arr));
arr->hawk = awk; arr->gem = gem;
arr->size = 0; arr->size = 0;
arr->capa = 0; arr->capa = 0;
arr->slot = HAWK_NULL; arr->slot = HAWK_NULL;
@ -145,7 +145,7 @@ void hawk_arr_fini (hawk_arr_t* arr)
if (arr->slot) if (arr->slot)
{ {
hawk_freemem (arr->hawk, arr->slot); hawk_gem_freemem (arr->gem, arr->slot);
arr->slot = HAWK_NULL; arr->slot = HAWK_NULL;
arr->capa = 0; arr->capa = 0;
} }
@ -160,7 +160,7 @@ void hawk_arr_setscale (hawk_arr_t* arr, int scale)
{ {
/* The scale should be larger than 0 and less than or equal to the /* The scale should be larger than 0 and less than or equal to the
* maximum value that the hawk_uint8_t type can hold */ * maximum value that the hawk_uint8_t type can hold */
HAWK_ASSERT (arr->hawk, scale > 0 && scale <= HAWK_TYPE_MAX(hawk_uint8_t)); /*HAWK_ASSERT (arr->gem, scale > 0 && scale <= HAWK_TYPE_MAX(hawk_uint8_t));*/
if (scale <= 0) scale = 1; if (scale <= 0) scale = 1;
if (scale > HAWK_TYPE_MAX(hawk_uint8_t)) scale = HAWK_TYPE_MAX(hawk_uint8_t); if (scale > HAWK_TYPE_MAX(hawk_uint8_t)) scale = HAWK_TYPE_MAX(hawk_uint8_t);
@ -240,12 +240,12 @@ hawk_arr_t* hawk_arr_setcapa (hawk_arr_t* arr, hawk_oow_t capa)
{ {
/* to trigger freeers on the items truncated */ /* to trigger freeers on the items truncated */
hawk_arr_delete (arr, capa, arr->size - capa); hawk_arr_delete (arr, capa, arr->size - capa);
HAWK_ASSERT (arr->hawk, arr->size <= capa); /*HAWK_ASSERT (arr->gem, arr->size <= capa);*/
} }
if (capa > 0) if (capa > 0)
{ {
tmp = (slot_t**)hawk_reallocmem(arr->hawk, arr->slot, HAWK_SIZEOF(*arr->slot) * capa); tmp = (slot_t**)hawk_gem_reallocmem(arr->gem, arr->slot, HAWK_SIZEOF(*arr->slot) * capa);
if (!tmp) return HAWK_NULL; if (!tmp) return HAWK_NULL;
} }
else else
@ -253,7 +253,7 @@ hawk_arr_t* hawk_arr_setcapa (hawk_arr_t* arr, hawk_oow_t capa)
if (arr->slot) if (arr->slot)
{ {
hawk_arr_clear (arr); hawk_arr_clear (arr);
hawk_freemem (arr->hawk, arr->slot); hawk_gem_freemem (arr->gem, arr->slot);
} }
tmp = HAWK_NULL; tmp = HAWK_NULL;
@ -272,12 +272,10 @@ hawk_oow_t hawk_arr_search (hawk_arr_t* arr, hawk_oow_t pos, const void* dptr, h
for (i = pos; i < arr->size; i++) for (i = pos; i < arr->size; i++)
{ {
if (arr->slot[i] == HAWK_NULL) continue; if (arr->slot[i] == HAWK_NULL) continue;
if (arr->comper(arr, DPTR(arr->slot[i]), DLEN(arr->slot[i]), dptr, dlen) == 0) return i;
if (arr->comper (arr,
DPTR(arr->slot[i]), DLEN(arr->slot[i]),
dptr, dlen) == 0) return i;
} }
hawk_gem_seterrnum (arr->gem, HAWK_NULL, HAWK_ENOENT);
return HAWK_ARR_NIL; return HAWK_ARR_NIL;
} }
@ -292,20 +290,18 @@ hawk_oow_t hawk_arr_rsearch (hawk_arr_t* arr, hawk_oow_t pos, const void* dptr,
for (i = pos + 1; i-- > 0; ) for (i = pos + 1; i-- > 0; )
{ {
if (arr->slot[i] == HAWK_NULL) continue; if (arr->slot[i] == HAWK_NULL) continue;
if (arr->comper (arr, DPTR(arr->slot[i]), DLEN(arr->slot[i]), dptr, dlen) == 0) return i;
if (arr->comper (arr,
DPTR(arr->slot[i]), DLEN(arr->slot[i]),
dptr, dlen) == 0) return i;
} }
} }
hawk_gem_seterrnum (arr->gem, HAWK_NULL, HAWK_ENOENT);
return HAWK_ARR_NIL; return HAWK_ARR_NIL;
} }
hawk_oow_t hawk_arr_upsert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oow_t dlen) hawk_oow_t hawk_arr_upsert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oow_t dlen)
{ {
if (pos < arr->size) return hawk_arr_update (arr, pos, dptr, dlen); if (pos < arr->size) return hawk_arr_update (arr, pos, dptr, dlen);
return hawk_arr_insert (arr, pos, dptr, dlen); return hawk_arr_insert(arr, pos, dptr, dlen);
} }
hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oow_t dlen) hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oow_t dlen)
@ -329,44 +325,46 @@ hawk_oow_t hawk_arr_insert (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo
if (arr->sizer) if (arr->sizer)
{ {
capa = arr->sizer (arr, mincapa); capa = arr->sizer(arr, mincapa);
} }
else else
{ {
if (arr->capa <= 0) if (arr->capa <= 0)
{ {
HAWK_ASSERT (arr->hawk, arr->size <= 0); /*HAWK_ASSERT (arr->gem, arr->size <= 0);*/
capa = (pos < 16)? 16: (pos + 1); capa = HAWK_ALIGN_POW2(pos + 1, 64);
} }
else else
{ {
hawk_oow_t bound = (pos >= arr->size)? pos: arr->size; hawk_oow_t bound = (pos >= arr->size)? pos: arr->size;
capa = HAWK_ALIGN_POW2(bound + 1, 64);
do { capa = arr->capa * 2; } while (capa <= bound); do { capa = arr->capa * 2; } while (capa <= bound);
} }
} }
do do
{ {
if (hawk_arr_setcapa(arr,capa) != HAWK_NULL) break; if (hawk_arr_setcapa(arr, capa) != HAWK_NULL) break;
if (capa <= mincapa) if (capa <= mincapa)
{ {
if (arr->freeer) arr->freeer (arr, DPTR(slot), DLEN(slot)); if (arr->freeer) arr->freeer (arr, DPTR(slot), DLEN(slot));
hawk_freemem (arr->hawk, slot); hawk_gem_freemem (arr->gem, slot);
return HAWK_ARR_NIL; return HAWK_ARR_NIL;
} }
capa--; /* let it retry after lowering the capacity */ capa--; /* let it retry after lowering the capacity */
} }
while (1); while (1);
}
if (pos >= arr->capa || arr->size >= arr->capa) if (pos >= arr->capa || arr->size >= arr->capa) /* can happen if the sizer() callback isn't good enough */
{ {
/* the buffer is not still enough after resizing */ /* the buffer is not still enough after resizing */
if (arr->freeer) arr->freeer (arr, DPTR(slot), DLEN(slot)); if (arr->freeer) arr->freeer (arr, DPTR(slot), DLEN(slot));
hawk_freemem (arr->hawk, slot); hawk_gem_freemem (arr->gem, slot);
return HAWK_ARR_NIL; hawk_gem_seterrnum (arr->gem, HAWK_NULL, HAWK_EBUFFULL);
return HAWK_ARR_NIL;
}
} }
/* fill in the gap with HAWK_NULL */ /* fill in the gap with HAWK_NULL */
@ -388,13 +386,17 @@ hawk_oow_t hawk_arr_update (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo
{ {
slot_t* c; slot_t* c;
if (pos >= arr->size) return HAWK_ARR_NIL; if (pos >= arr->size)
{
hawk_gem_seterrnum (arr->gem, HAWK_NULL, HAWK_EINVAL);
return HAWK_ARR_NIL;
}
c = arr->slot[pos]; c = arr->slot[pos];
if (c == HAWK_NULL) if (c == HAWK_NULL)
{ {
/* no previous data */ /* no previous data */
arr->slot[pos] = alloc_slot (arr, dptr, dlen); arr->slot[pos] = alloc_slot(arr, dptr, dlen);
if (arr->slot[pos] == HAWK_NULL) return HAWK_ARR_NIL; if (arr->slot[pos] == HAWK_NULL) return HAWK_ARR_NIL;
} }
else else
@ -407,11 +409,11 @@ hawk_oow_t hawk_arr_update (hawk_arr_t* arr, hawk_oow_t pos, void* dptr, hawk_oo
else else
{ {
/* updated to different data */ /* updated to different data */
slot_t* slot = alloc_slot (arr, dptr, dlen); slot_t* slot = alloc_slot(arr, dptr, dlen);
if (slot == HAWK_NULL) return HAWK_ARR_NIL; if (slot == HAWK_NULL) return HAWK_ARR_NIL;
if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c)); if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c));
hawk_freemem (arr->hawk, c); hawk_gem_freemem (arr->gem, c);
arr->slot[pos] = slot; arr->slot[pos] = slot;
} }
@ -436,8 +438,7 @@ hawk_oow_t hawk_arr_delete (hawk_arr_t* arr, hawk_oow_t index, hawk_oow_t count)
if (c != HAWK_NULL) if (c != HAWK_NULL)
{ {
if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c)); if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c));
hawk_freemem (arr->hawk, c); hawk_gem_freemem (arr->gem, c);
arr->slot[i] = HAWK_NULL; arr->slot[i] = HAWK_NULL;
} }
} }
@ -468,8 +469,7 @@ hawk_oow_t hawk_arr_uplete (hawk_arr_t* arr, hawk_oow_t index, hawk_oow_t count)
if (c != HAWK_NULL) if (c != HAWK_NULL)
{ {
if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c)); if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c));
hawk_freemem (arr->hawk, c); hawk_gem_freemem (arr->gem, c);
arr->slot[i] = HAWK_NULL; arr->slot[i] = HAWK_NULL;
} }
} }
@ -486,9 +486,8 @@ void hawk_arr_clear (hawk_arr_t* arr)
slot_t* c = arr->slot[i]; slot_t* c = arr->slot[i];
if (c != HAWK_NULL) if (c != HAWK_NULL)
{ {
if (arr->freeer) if (arr->freeer) arr->freeer (arr, DPTR(c), DLEN(c));
arr->freeer (arr, DPTR(c), DLEN(c)); hawk_gem_freemem (arr->gem, c);
hawk_freemem (arr->hawk, c);
arr->slot[i] = HAWK_NULL; arr->slot[i] = HAWK_NULL;
} }
} }
@ -568,7 +567,7 @@ hawk_oow_t hawk_arr_pushstack (hawk_arr_t* arr, void* dptr, hawk_oow_t dlen)
void hawk_arr_popstack (hawk_arr_t* arr) void hawk_arr_popstack (hawk_arr_t* arr)
{ {
HAWK_ASSERT (arr->hawk, arr->size > 0); /*HAWK_ASSERT (arr->gem, arr->size > 0);*/
hawk_arr_delete (arr, arr->size - 1, 1); hawk_arr_delete (arr, arr->size - 1, 1);
} }
@ -679,10 +678,10 @@ hawk_oow_t hawk_arr_pushheap (hawk_arr_t* arr, void* dptr, hawk_oow_t dlen)
/* add a value at the back of the array */ /* add a value at the back of the array */
index = arr->size; index = arr->size;
if (hawk_arr_insert (arr, index, dptr, dlen) == HAWK_ARR_NIL) return HAWK_ARR_NIL; if (hawk_arr_insert(arr, index, dptr, dlen) == HAWK_ARR_NIL) return HAWK_ARR_NIL;
HEAP_UPDATE_POS (arr, index); HEAP_UPDATE_POS (arr, index);
HAWK_ASSERT (arr->hawk, arr->size == index + 1); /*HAWK_ASSERT (arr->gem, arr->size == index + 1);*/
/* move the item upto the top if it's greater than the parent items */ /* move the item upto the top if it's greater than the parent items */
sift_up (arr, index); sift_up (arr, index);
@ -691,7 +690,7 @@ hawk_oow_t hawk_arr_pushheap (hawk_arr_t* arr, void* dptr, hawk_oow_t dlen)
void hawk_arr_popheap (hawk_arr_t* arr) void hawk_arr_popheap (hawk_arr_t* arr)
{ {
HAWK_ASSERT (arr->hawk, arr->size > 0); /*HAWK_ASSERT (arr->gem, arr->size > 0);*/
hawk_arr_deleteheap (arr, 0); hawk_arr_deleteheap (arr, 0);
} }
@ -699,8 +698,8 @@ void hawk_arr_deleteheap (hawk_arr_t* arr, hawk_oow_t index)
{ {
slot_t* tmp; slot_t* tmp;
HAWK_ASSERT (arr->hawk, arr->size > 0); /*HAWK_ASSERT (arr->gem, arr->size > 0);
HAWK_ASSERT (arr->hawk, index < arr->size); HAWK_ASSERT (arr->gem, index < arr->size);*/
/* remember the item to destroy */ /* remember the item to destroy */
tmp = arr->slot[index]; tmp = arr->slot[index];
@ -725,7 +724,7 @@ void hawk_arr_deleteheap (hawk_arr_t* arr, hawk_oow_t index)
/* destroy the actual item */ /* destroy the actual item */
if (arr->freeer) arr->freeer (arr, DPTR(tmp), DLEN(tmp)); if (arr->freeer) arr->freeer (arr, DPTR(tmp), DLEN(tmp));
hawk_freemem (arr->hawk, tmp); hawk_gem_freemem (arr->gem, tmp);
/* empty the last slot */ /* empty the last slot */
arr->slot[arr->size] = HAWK_NULL; arr->slot[arr->size] = HAWK_NULL;
@ -737,7 +736,7 @@ hawk_oow_t hawk_arr_updateheap (hawk_arr_t* arr, hawk_oow_t index, void* dptr, h
int n; int n;
tmp = arr->slot[index]; tmp = arr->slot[index];
HAWK_ASSERT (arr->hawk, tmp != HAWK_NULL); /*HAWK_ASSERT (arr->gem, tmp != HAWK_NULL);*/
n = arr->comper(arr, dptr, dlen, DPTR(tmp), DLEN(tmp)); n = arr->comper(arr, dptr, dlen, DPTR(tmp), DLEN(tmp));
if (n) if (n)

View File

@ -70,14 +70,12 @@ hawk_oow_t hawk_becs_ncatuchars (hawk_becs_t* str, const hawk_uch_t* s, hawk_oow
hawk_oow_t bcslen, ucslen; hawk_oow_t bcslen, ucslen;
ucslen = len; ucslen = len;
//if (qse_wcsntombsnwithcmgr(s, &ucslen, QSE_NULL, &bcslen, cmgr) <= -1) return (hawk_oow_t)-1;
if (hawk_conv_uchars_to_bchars_with_cmgr(s, &ucslen, HAWK_NULL, &bcslen, cmgr) <= -1) return (hawk_oow_t)-1; if (hawk_conv_uchars_to_bchars_with_cmgr(s, &ucslen, HAWK_NULL, &bcslen, cmgr) <= -1) return (hawk_oow_t)-1;
if (hawk_becs_resize_for_ncat(str, bcslen) <= 0) return -1; if (hawk_becs_resize_for_ncat(str, bcslen) <= 0) return -1;
ucslen = len; ucslen = len;
bcslen = str->capa - str->val.len; bcslen = str->capa - str->val.len;
//qse_wcsntombsnwithcmgr(s, &ucslen, &str->val.ptr[str->val.len], &bcslen, cmgr);
hawk_conv_uchars_to_bchars_with_cmgr (s, &ucslen, &str->val.ptr[str->val.len], &bcslen, cmgr); hawk_conv_uchars_to_bchars_with_cmgr (s, &ucslen, &str->val.ptr[str->val.len], &bcslen, cmgr);
str->val.len += bcslen; str->val.len += bcslen;
str->val.ptr[str->val.len] = '\0'; str->val.ptr[str->val.len] = '\0';
@ -90,14 +88,12 @@ hawk_oow_t hawk_uecs_ncatbchars (hawk_uecs_t* str, const hawk_bch_t* s, hawk_oow
hawk_oow_t bcslen, ucslen; hawk_oow_t bcslen, ucslen;
bcslen = len; bcslen = len;
//if (qse_mbsntowcsnallwithcmgr(s, &bcslen, QSE_NULL, &ucslen, cmgr) <= -1) return (hawk_oow_t)-1;
if (hawk_conv_bchars_to_uchars_with_cmgr(s, &bcslen, HAWK_NULL, &ucslen, cmgr, all) <= -1) return (hawk_oow_t)-1; if (hawk_conv_bchars_to_uchars_with_cmgr(s, &bcslen, HAWK_NULL, &ucslen, cmgr, all) <= -1) return (hawk_oow_t)-1;
if (hawk_uecs_resize_for_ncat(str, ucslen) <= 0) return -1; if (hawk_uecs_resize_for_ncat(str, ucslen) <= 0) return -1;
bcslen = len; bcslen = len;
ucslen = str->capa - str->val.len; ucslen = str->capa - str->val.len;
//qse_mbsntowcsnallwithcmgr(s, &bcslen, &str->val.ptr[str->val.len], &ucslen, cmgr);
hawk_conv_bchars_to_uchars_with_cmgr (s, &bcslen, &str->val.ptr[str->val.len], &ucslen, cmgr, all); hawk_conv_bchars_to_uchars_with_cmgr (s, &bcslen, &str->val.ptr[str->val.len], &ucslen, cmgr, all);
str->val.len += ucslen; str->val.len += ucslen;
str->val.ptr[str->val.len] = '\0'; str->val.ptr[str->val.len] = '\0';

View File

@ -92,7 +92,7 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("variable '${0}' redefined"), HAWK_T("variable '${0}' redefined"),
HAWK_T("duplicate parameter name '${0}'"), HAWK_T("duplicate parameter name '${0}'"),
HAWK_T("duplicate global variable '${0}'"), HAWK_T("duplicate global variable '${0}'"),
HAWK_T("duplicate local variable '${0}'"), HAWK_T("duplicate local variable"),
HAWK_T("'${0}' not a valid parameter name"), HAWK_T("'${0}' not a valid parameter name"),
HAWK_T("'${0}' not a valid variable name"), HAWK_T("'${0}' not a valid variable name"),
HAWK_T("variable name missing"), HAWK_T("variable name missing"),

View File

@ -141,7 +141,7 @@ typedef hawk_arr_walk_t (*hawk_arr_walker_t) (
*/ */
struct hawk_arr_t struct hawk_arr_t
{ {
hawk_t* hawk; hawk_gem_t* gem;
hawk_arr_copier_t copier; /* data copier */ hawk_arr_copier_t copier; /* data copier */
hawk_arr_freeer_t freeer; /* data freeer */ hawk_arr_freeer_t freeer; /* data freeer */
hawk_arr_comper_t comper; /* data comparator */ hawk_arr_comper_t comper; /* data comparator */
@ -171,7 +171,7 @@ extern "C" {
* The hawk_arr_open() function creates a linear dynamic array. * The hawk_arr_open() function creates a linear dynamic array.
*/ */
HAWK_EXPORT hawk_arr_t* hawk_arr_open ( HAWK_EXPORT hawk_arr_t* hawk_arr_open (
hawk_t* awk, /**< memory manager */ hawk_gem_t* gem,
hawk_oow_t ext, /**< extension size in bytes */ hawk_oow_t ext, /**< extension size in bytes */
hawk_oow_t capa /**< initial array capacity */ hawk_oow_t capa /**< initial array capacity */
); );
@ -188,7 +188,7 @@ HAWK_EXPORT void hawk_arr_close (
*/ */
HAWK_EXPORT int hawk_arr_init ( HAWK_EXPORT int hawk_arr_init (
hawk_arr_t* arr, hawk_arr_t* arr,
hawk_t* awk, hawk_gem_t* gem,
hawk_oow_t capa hawk_oow_t capa
); );

View File

@ -201,9 +201,9 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
awk->parse.funs = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1); awk->parse.funs = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
awk->parse.named = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1); awk->parse.named = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
awk->parse.gbls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 128); awk->parse.gbls = hawk_arr_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 128);
awk->parse.lcls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 64); awk->parse.lcls = hawk_arr_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 64);
awk->parse.params = hawk_arr_open(awk, HAWK_SIZEOF(awk), 32); awk->parse.params = hawk_arr_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 32);
awk->fnc.sys = HAWK_NULL; awk->fnc.sys = HAWK_NULL;
awk->fnc.user = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1); awk->fnc.user = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1);

View File

@ -1327,7 +1327,7 @@ static hawk_nde_t* parse_function (hawk_t* awk)
if (hawk_arr_insert(awk->parse.params, HAWK_ARR_SIZE(awk->parse.params), pa, pal) == HAWK_ARR_NIL) if (hawk_arr_insert(awk->parse.params, HAWK_ARR_SIZE(awk->parse.params), pa, pal) == HAWK_ARR_NIL)
{ {
SETERR_LOC (awk, HAWK_ENOMEM, &awk->tok.loc); ADJERR_LOC (awk, &awk->tok.loc);
goto oops; goto oops;
} }
@ -1977,7 +1977,7 @@ int hawk_addgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
#define HAWK_NUM_STATIC_GBLS \ #define HAWK_NUM_STATIC_GBLS \
(HAWK_MAX_GBL_ID-HAWK_MIN_GBL_ID+1) (HAWK_MAX_GBL_ID-HAWK_MIN_GBL_ID+1)
int hawk_delgblwithbcstr (hawk_t* awk, const hawk_bch_t* name) int hawk_delgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name)
{ {
hawk_oow_t n; hawk_oow_t n;
hawk_bcs_t ncs; hawk_bcs_t ncs;
@ -1986,31 +1986,31 @@ int hawk_delgblwithbcstr (hawk_t* awk, const hawk_bch_t* name)
ncs.ptr = (hawk_bch_t*)name; ncs.ptr = (hawk_bch_t*)name;
ncs.len = hawk_count_bcstr(name); ncs.len = hawk_count_bcstr(name);
if (awk->tree.ngbls > awk->tree.ngbls_base) if (hawk->tree.ngbls > hawk->tree.ngbls_base)
{ {
/* this function is not allow after hawk_parse is called */ /* this function is not allow after hawk_parse is called */
hawk_seterrnum (awk, HAWK_EPERM, HAWK_NULL); hawk_seterrnum (hawk, HAWK_EPERM, HAWK_NULL);
return -1; return -1;
} }
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &ncs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT "no such global variable - %.*hs", ncs.len, ncs.ptr);
return -1; return -1;
} }
#else #else
wcs.ptr = hawk_dupbtoucstr(awk, ncs.ptr, &wcs.len, 0); wcs.ptr = hawk_dupbtoucstr(hawk, ncs.ptr, &wcs.len, 0);
if (!wcs.ptr) return -1; if (!wcs.ptr) return -1;
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &wcs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", wcs.len, wcs.ptr);
hawk_freemem (awk, wcs.ptr); hawk_freemem (hawk, wcs.ptr);
return -1; return -1;
} }
hawk_freemem (awk, wcs.ptr); hawk_freemem (hawk, wcs.ptr);
#endif #endif
/* invalidate the name if deletion is requested. /* invalidate the name if deletion is requested.
@ -2019,16 +2019,16 @@ int hawk_delgblwithbcstr (hawk_t* awk, const hawk_bch_t* name)
* again, the entry will be appended again. * again, the entry will be appended again.
* never call this funciton unless it is really required. */ * never call this funciton unless it is really required. */
/* /*
awk->parse.gbls.buf[n].name.ptr[0] = HAWK_T('\0'); hawk->parse.gbls.buf[n].name.ptr[0] = HAWK_T('\0');
awk->parse.gbls.buf[n].name.len = 0; hawk->parse.gbls.buf[n].name.len = 0;
*/ */
n = hawk_arr_uplete(awk->parse.gbls, n, 1); n = hawk_arr_uplete(hawk->parse.gbls, n, 1);
HAWK_ASSERT (awk, n == 1); HAWK_ASSERT (hawk, n == 1);
return 0; return 0;
} }
int hawk_delgblwithucstr (hawk_t* awk, const hawk_uch_t* name) int hawk_delgblwithucstr (hawk_t* hawk, const hawk_uch_t* name)
{ {
hawk_oow_t n; hawk_oow_t n;
hawk_ucs_t ncs; hawk_ucs_t ncs;
@ -2037,29 +2037,29 @@ int hawk_delgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
ncs.ptr = (hawk_uch_t*)name; ncs.ptr = (hawk_uch_t*)name;
ncs.len = hawk_count_ucstr(name); ncs.len = hawk_count_ucstr(name);
if (awk->tree.ngbls > awk->tree.ngbls_base) if (hawk->tree.ngbls > hawk->tree.ngbls_base)
{ {
/* this function is not allow after hawk_parse is called */ /* this function is not allow after hawk_parse is called */
hawk_seterrnum (awk, HAWK_EPERM, HAWK_NULL); hawk_seterrnum (hawk, HAWK_EPERM, HAWK_NULL);
return -1; return -1;
} }
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
mbs.ptr = hawk_duputobcstr(awk, ncs.ptr, &mbs.len); mbs.ptr = hawk_duputobcstr(hawk, ncs.ptr, &mbs.len);
if (!mbs.ptr) return -1; if (!mbs.ptr) return -1;
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &mbs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", mbs.len, mbs.ptr);
hawk_freemem (awk, mbs.ptr); hawk_freemem (hawk, mbs.ptr);
return -1; return -1;
} }
hawk_freemem (awk, mbs.ptr); hawk_freemem (hawk, mbs.ptr);
#else #else
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &ncs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", ncs.len, ncs.ptr);
return -1; return -1;
} }
#endif #endif
@ -2070,16 +2070,16 @@ int hawk_delgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
* again, the entry will be appended again. * again, the entry will be appended again.
* never call this funciton unless it is really required. */ * never call this funciton unless it is really required. */
/* /*
awk->parse.gbls.buf[n].name.ptr[0] = HAWK_T('\0'); hawk->parse.gbls.buf[n].name.ptr[0] = HAWK_T('\0');
awk->parse.gbls.buf[n].name.len = 0; hawk->parse.gbls.buf[n].name.len = 0;
*/ */
n = hawk_arr_uplete(awk->parse.gbls, n, 1); n = hawk_arr_uplete(hawk->parse.gbls, n, 1);
HAWK_ASSERT (awk, n == 1); HAWK_ASSERT (awk, n == 1);
return 0; return 0;
} }
int hawk_findgblwithbcstr (hawk_t* awk, const hawk_bch_t* name) int hawk_findgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name)
{ {
hawk_oow_t n; hawk_oow_t n;
hawk_bcs_t ncs; hawk_bcs_t ncs;
@ -2089,29 +2089,29 @@ int hawk_findgblwithbcstr (hawk_t* awk, const hawk_bch_t* name)
ncs.len = hawk_count_bcstr(name); ncs.len = hawk_count_bcstr(name);
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &ncs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", ncs.len, ncs.ptr);
return -1; return -1;
} }
#else #else
wcs.ptr = hawk_dupbtoucstr(awk, ncs.ptr, &wcs.len, 0); wcs.ptr = hawk_dupbtoucstr(hawk, ncs.ptr, &wcs.len, 0);
if (!wcs.ptr) return -1; if (!wcs.ptr) return -1;
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &wcs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", wcs.len, wcs.ptr);
hawk_freemem (awk, wcs.ptr); hawk_freemem (hawk, wcs.ptr);
return -1; return -1;
} }
hawk_freemem (awk, wcs.ptr); hawk_freemem (hawk, wcs.ptr);
#endif #endif
return (int)n; return (int)n;
} }
int hawk_findgblwithucstr (hawk_t* awk, const hawk_uch_t* name) int hawk_findgblwithucstr (hawk_t* hawk, const hawk_uch_t* name)
{ {
hawk_oow_t n; hawk_oow_t n;
hawk_ucs_t ncs; hawk_ucs_t ncs;
@ -2121,21 +2121,21 @@ int hawk_findgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
ncs.len = hawk_count_ucstr(name); ncs.len = hawk_count_ucstr(name);
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
mbs.ptr = hawk_duputobcstr(awk, ncs.ptr, &mbs.len); mbs.ptr = hawk_duputobcstr(hawk, ncs.ptr, &mbs.len);
if (!mbs.ptr) return -1; if (!mbs.ptr) return -1;
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &mbs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", mbs.len, mbs.ptr);
hawk_freemem (awk, mbs.ptr); hawk_freemem (hawk, mbs.ptr);
return -1; return -1;
} }
hawk_freemem (awk, mbs.ptr); hawk_freemem (hawk, mbs.ptr);
#else #else
n = hawk_arr_search(awk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len);
if (n == HAWK_ARR_NIL) if (n == HAWK_ARR_NIL)
{ {
hawk_seterrnum (awk, HAWK_ENOENT, &ncs); hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", ncs.len, ncs.ptr);
return -1; return -1;
} }
#endif #endif
@ -2257,32 +2257,32 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
n = hawk_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len); n = hawk_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len);
if (n != HAWK_ARR_NIL) if (n != HAWK_ARR_NIL)
{ {
SETERR_ARG_LOC (awk, HAWK_EDUPLCL, lcl.ptr, lcl.len, &awk->tok.loc); hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, "duplicate local variable - %.*js", lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
/* check if it conflicts with global variable names */ /* check if it conflicts with global variable names */
n = find_global (awk, &lcl); n = find_global(awk, &lcl);
if (n != HAWK_ARR_NIL) if (n != HAWK_ARR_NIL)
{ {
if (n < awk->tree.ngbls_base) if (n < awk->tree.ngbls_base)
{ {
/* it is a conflict only if it is one of a /* it is a conflict only if it is one of a
* static global variable */ * static global variable */
SETERR_ARG_LOC (awk, HAWK_EDUPLCL, lcl.ptr, lcl.len, &awk->tok.loc); hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, "duplicate local variable - %.*js", lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
} }
if (HAWK_ARR_SIZE(awk->parse.lcls) >= HAWK_MAX_LCLS) if (HAWK_ARR_SIZE(awk->parse.lcls) >= HAWK_MAX_LCLS)
{ {
SETERR_LOC (awk, HAWK_ELCLTM, &awk->tok.loc); hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_ELCLTM, "too many local variables defined - %.*js", lcl.len, lcl.ptr);
return HAWK_NULL; return HAWK_NULL;
} }
if (hawk_arr_insert (awk->parse.lcls, HAWK_ARR_SIZE(awk->parse.lcls), lcl.ptr, lcl.len) == HAWK_ARR_NIL) if (hawk_arr_insert(awk->parse.lcls, HAWK_ARR_SIZE(awk->parse.lcls), lcl.ptr, lcl.len) == HAWK_ARR_NIL)
{ {
SETERR_LOC (awk, HAWK_ENOMEM, &awk->tok.loc); ADJERR_LOC (awk, &awk->tok.loc);
return HAWK_NULL; return HAWK_NULL;
} }

View File

@ -25,7 +25,7 @@
*/ */
/* /*
* This is the TRE memory allocator modified for QSE. * This is the TRE memory allocator modified for Hawk.
* See the original license notice below. * See the original license notice below.
*/ */