writing code exchange functions
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
17
lib/decode.c
17
lib/decode.c
@ -49,7 +49,7 @@
|
||||
#endif
|
||||
|
||||
/* TODO: check if ip shoots beyond the maximum length in fetching code and parameters */
|
||||
int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
|
||||
int hcl_decode (hcl_t* hcl, const hcl_code_t* code, hcl_oow_t start, hcl_oow_t end)
|
||||
{
|
||||
hcl_oob_t bcode, * cdptr;
|
||||
hcl_ooi_t ip = start, fetched_instruction_pointer;
|
||||
@ -58,18 +58,19 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
|
||||
/* the instruction at the offset 'end' is not decoded.
|
||||
* decoding offset range is from start to end - 1. */
|
||||
|
||||
|
||||
HCL_ASSERT (hcl, start >= 0 && end >= 0);
|
||||
HCL_ASSERT (hcl, hcl->code.bc.len < HCL_SMOOI_MAX); /* asserted by the compiler */
|
||||
HCL_ASSERT (hcl, end <= hcl->code.bc.len); /* not harmful though this fails */
|
||||
if (start >= hcl->code.bc.len)
|
||||
HCL_ASSERT (hcl, code->bc.len < HCL_SMOOI_MAX); /* asserted by the compiler */
|
||||
HCL_ASSERT (hcl, end <= code->bc.len); /* not harmful though this fails */
|
||||
if (start >= code->bc.len)
|
||||
{
|
||||
hcl_seterrnum (hcl, HCL_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
if (end > hcl->code.bc.len) end = hcl->code.bc.len;
|
||||
if (end > code->bc.len) end = code->bc.len;
|
||||
|
||||
ip = start;
|
||||
cdptr = hcl->code.bc.ptr;
|
||||
cdptr = code->bc.ptr;
|
||||
|
||||
/* TODO: check if ip increases beyond bcode when fetching parameters too */
|
||||
while (ip < end)
|
||||
@ -742,9 +743,9 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
|
||||
|
||||
/* TODO: this needs changes... */
|
||||
/* print literal frame contents */
|
||||
for (ip = 0; ip < hcl->code.lit.len; ip++)
|
||||
for (ip = 0; ip < code->lit.len; ip++)
|
||||
{
|
||||
HCL_LOG2(hcl, DECODE_LOG_MASK, "@%-9zd %O\n", ip, ((hcl_oop_oop_t)hcl->code.lit.arr)->slot[ip]);
|
||||
HCL_LOG2(hcl, DECODE_LOG_MASK, "@%-9zd %O\n", ip, ((hcl_oop_oop_t)code->lit.arr)->slot[ip]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user