changed the moo_code_t structure a little

This commit is contained in:
hyunghwan.chung 2019-07-02 09:48:56 +00:00
parent 92093dd23f
commit a9045a56b2
2 changed files with 17 additions and 5 deletions

View File

@ -2489,18 +2489,27 @@ static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code)
return -1; return -1;
} }
if (cc->mth.code.len >= cc->mth.code_capa) if (cc->mth.code.len >= cc->mth.code.capa)
{ {
moo_oob_t* tmp; moo_oob_t* tmp;
moo_oow_t* tmp2;
moo_oow_t newcapa; moo_oow_t newcapa;
newcapa = MOO_ALIGN (cc->mth.code.len + 1, CODE_BUFFER_ALIGN); newcapa = MOO_ALIGN (cc->mth.code.len + 1, CODE_BUFFER_ALIGN);
tmp = moo_reallocmem (moo, cc->mth.code.ptr, newcapa * MOO_SIZEOF(*tmp)); tmp = (moo_oob_t*)moo_reallocmem(moo, cc->mth.code.ptr, newcapa * MOO_SIZEOF(*tmp));
if (!tmp) return -1; if (!tmp) return -1;
tmp2 = (moo_oow_t*)moo_reallocmem(moo, cc->mth.code.locptr, newcapa * MOO_SIZEOF(*tmp2));
if (!tmp)
{
moo_freemem (moo, tmp);
return -1;
}
cc->mth.code.capa = newcapa;
cc->mth.code.ptr = tmp; cc->mth.code.ptr = tmp;
cc->mth.code_capa = newcapa; cc->mth.code.locptr = tmp2;
} }
cc->mth.code.ptr[cc->mth.code.len++] = code; cc->mth.code.ptr[cc->mth.code.len++] = code;
@ -2549,7 +2558,6 @@ static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1
goto write_long; goto write_long;
} }
case BCODE_JUMP_FORWARD_0: case BCODE_JUMP_FORWARD_0:
case BCODE_JUMP_BACKWARD_0: case BCODE_JUMP_BACKWARD_0:
case BCODE_JUMPOP_BACKWARD_IF_FALSE_0: case BCODE_JUMPOP_BACKWARD_IF_FALSE_0:

View File

@ -359,6 +359,10 @@ struct moo_code_t
{ {
moo_uint8_t* ptr; moo_uint8_t* ptr;
moo_oow_t len; moo_oow_t len;
moo_oow_t capa;
/* array that hold the location of the byte code emitted */
moo_oow_t* locptr;
}; };
typedef struct moo_oow_pool_chunk_t moo_oow_pool_chunk_t; typedef struct moo_oow_pool_chunk_t moo_oow_pool_chunk_t;
@ -471,6 +475,7 @@ struct moo_pooldic_import_data_t
moo_oow_t oops_capa; moo_oow_t oops_capa;
}; };
/* data kept by compiler to complie a method */
typedef struct moo_method_data_t moo_method_data_t; typedef struct moo_method_data_t moo_method_data_t;
struct moo_method_data_t struct moo_method_data_t
{ {
@ -528,7 +533,6 @@ struct moo_method_data_t
/* byte code */ /* byte code */
moo_code_t code; moo_code_t code;
moo_oow_t code_capa;
}; };
typedef struct moo_cunit_class_t moo_cunit_class_t; typedef struct moo_cunit_class_t moo_cunit_class_t;