fixed wrong computation of buffer capacity for moo->inttostr.xbuf and moo->inttostr.t
updated some sample code fixed a few flaws in ffi.c
This commit is contained in:
@ -4153,7 +4153,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
|
||||
reqcapa = MOO_OOW_BITS + 1;
|
||||
if (moo->inttostr.xbuf.capa < reqcapa)
|
||||
{
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa);
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa * MOO_SIZEOF(*xbuf));
|
||||
if (!xbuf) return MOO_NULL;
|
||||
moo->inttostr.xbuf.capa = reqcapa;
|
||||
moo->inttostr.xbuf.ptr = xbuf;
|
||||
@ -4182,10 +4182,10 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
|
||||
xlen = as * ((MOO_LIW_BITS + exp) / exp) + 1;
|
||||
xpos = xlen;
|
||||
|
||||
reqcapa = MOO_SIZEOF(*xbuf) * xlen;
|
||||
reqcapa = xlen;
|
||||
if (moo->inttostr.xbuf.capa < reqcapa)
|
||||
{
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa);
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa * MOO_SIZEOF(*xbuf));
|
||||
if (!xbuf) return MOO_NULL;
|
||||
moo->inttostr.xbuf.capa = reqcapa;
|
||||
moo->inttostr.xbuf.ptr = xbuf;
|
||||
@ -4232,10 +4232,10 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
|
||||
|
||||
/* TODO: find an optimial buffer size */
|
||||
/* TODO: find an optimial buffer size */
|
||||
reqcapa = MOO_SIZEOF(*xbuf) * (as * MOO_LIW_BITS + 1);
|
||||
reqcapa = as * MOO_LIW_BITS + 1;
|
||||
if (moo->inttostr.xbuf.capa < reqcapa)
|
||||
{
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa);
|
||||
xbuf = (moo_ooch_t*)moo_reallocmem(moo, moo->inttostr.xbuf.ptr, reqcapa * MOO_SIZEOF(*xbuf));
|
||||
if (!xbuf) return MOO_NULL;
|
||||
moo->inttostr.xbuf.capa = reqcapa;
|
||||
moo->inttostr.xbuf.ptr = xbuf;
|
||||
@ -4245,10 +4245,10 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
|
||||
xbuf = moo->inttostr.xbuf.ptr;
|
||||
}
|
||||
|
||||
reqcapa = MOO_SIZEOF(*t) * as * 3;
|
||||
reqcapa = as * 3;
|
||||
if (moo->inttostr.t.capa < reqcapa)
|
||||
{
|
||||
t = (moo_liw_t*)moo_reallocmem(moo, moo->inttostr.t.ptr, reqcapa);
|
||||
t = (moo_liw_t*)moo_reallocmem(moo, moo->inttostr.t.ptr, reqcapa * MOO_SIZEOF(*t));
|
||||
if (!t) return MOO_NULL;
|
||||
moo->inttostr.t.capa = reqcapa;
|
||||
moo->inttostr.t.ptr = t;
|
||||
@ -4258,7 +4258,6 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix)
|
||||
t = moo->inttostr.t.ptr;
|
||||
}
|
||||
|
||||
|
||||
#if (MOO_LIW_BITS == MOO_OOW_BITS)
|
||||
b[0] = moo->bigint[radix].multiplier; /* block divisor */
|
||||
bs = 1;
|
||||
|
@ -7407,7 +7407,7 @@ static int make_defined_class (moo_t* moo)
|
||||
|
||||
for (i = 0; i < initv_count; i++)
|
||||
{
|
||||
MOO_STORE_OOP (moo, &cc->self_oop->cvar[i], initv->slot[i]);
|
||||
MOO_STORE_OOP (moo, &cc->self_oop->cvar[i], MOO_OBJ_GET_OOP_VAL(initv, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4852,7 +4852,7 @@ static int __execute (moo_t* moo)
|
||||
if ((bcode >> 4) & 1)
|
||||
{
|
||||
/* push - bit 4 on */
|
||||
LOG_INST1 (moo, "push_tempvar %zu", b1);
|
||||
LOG_INST2 (moo, "push_tempvar %zu => %O", b1, ctx->stack[bx]);
|
||||
MOO_STACK_PUSH (moo, ctx->stack[bx]);
|
||||
}
|
||||
else
|
||||
|
@ -207,9 +207,9 @@ int main (int argc, char* argv[])
|
||||
{
|
||||
moo_oow_t tab_size;
|
||||
|
||||
tab_size = 5000;
|
||||
tab_size = 10;
|
||||
moo_setoption (moo, MOO_SYMTAB_SIZE, &tab_size);
|
||||
tab_size = 5000;
|
||||
tab_size = 10;
|
||||
moo_setoption (moo, MOO_SYSDIC_SIZE, &tab_size);
|
||||
tab_size = 600;
|
||||
moo_setoption (moo, MOO_PROCSTK_SIZE, &tab_size);
|
||||
|
@ -54,7 +54,7 @@
|
||||
/*#define MOO_DEBUG_LEXER 1*/
|
||||
#define MOO_DEBUG_COMPILER 1
|
||||
#define MOO_DEBUG_VM_PROCESSOR 1
|
||||
/*#define MOO_DEBUG_VM_EXEC*/
|
||||
/*#define MOO_DEBUG_VM_EXEC 1*/
|
||||
#define MOO_PROFILE_VM 1
|
||||
#endif
|
||||
|
||||
@ -382,8 +382,6 @@ struct moo_loop_t
|
||||
moo_loop_t* next;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct moo_oopbuf_t moo_oopbuf_t;
|
||||
struct moo_oopbuf_t
|
||||
{
|
||||
|
@ -67,15 +67,17 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc)
|
||||
|
||||
while (oldsz > 0)
|
||||
{
|
||||
symbol = (moo_oop_char_t)oldbuc->slot[--oldsz];
|
||||
oldsz = oldsz - 1;
|
||||
symbol = (moo_oop_char_t)MOO_OBJ_GET_OOP_VAL(oldbuc, oldsz);
|
||||
|
||||
if ((moo_oop_t)symbol != moo->_nil)
|
||||
{
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol);
|
||||
/*MOO_ASSERT (moo, sym->size > 0);*/
|
||||
|
||||
index = moo_hashoochars(MOO_OBJ_GET_CHAR_SLOT(symbol), MOO_OBJ_GET_SIZE(symbol)) % newsz;
|
||||
while (newbuc->slot[index] != moo->_nil) index = (index + 1) % newsz;
|
||||
MOO_STORE_OOP (moo, &newbuc->slot[index], (moo_oop_t)symbol);
|
||||
while (MOO_OBJ_GET_OOP_VAL(newbuc, index) != moo->_nil) index = (index + 1) % newsz;
|
||||
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(newbuc, index), (moo_oop_t)symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,9 +94,8 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
|
||||
index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket);
|
||||
|
||||
/* find a matching symbol in the open-addressed symbol table */
|
||||
while (moo->symtab->bucket->slot[index] != moo->_nil)
|
||||
while ((moo_oop_t)(symbol = MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index)) != moo->_nil)
|
||||
{
|
||||
symbol = (moo_oop_char_t)moo->symtab->bucket->slot[index];
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol);
|
||||
|
||||
if (len == MOO_OBJ_GET_SIZE(symbol) &&
|
||||
@ -147,7 +148,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
|
||||
/* recalculate the index for the expanded bucket */
|
||||
index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket);
|
||||
|
||||
while (moo->symtab->bucket->slot[index] != moo->_nil)
|
||||
while (MOO_OBJ_GET_OOP_VAL(moo->symtab->bucket, index) != moo->_nil)
|
||||
index = (index + 1) % MOO_OBJ_GET_SIZE(moo->symtab->bucket);
|
||||
}
|
||||
|
||||
@ -157,7 +158,7 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
|
||||
{
|
||||
MOO_ASSERT (moo, tally < MOO_SMOOI_MAX);
|
||||
moo->symtab->tally = MOO_SMOOI_TO_OOP(tally + 1);
|
||||
MOO_STORE_OOP (moo, &moo->symtab->bucket->slot[index], (moo_oop_t)symbol);
|
||||
MOO_STORE_OOP (moo, MOO_OBJ_GET_OOP_PTR(moo->symtab->bucket, index), (moo_oop_t)symbol);
|
||||
}
|
||||
|
||||
return (moo_oop_t)symbol;
|
||||
|
Reference in New Issue
Block a user