fixing bugs introduced for block temporaries sheme

This commit is contained in:
2021-05-05 17:37:26 +00:00
parent bd3730fd12
commit c37b695a76
4 changed files with 73 additions and 38 deletions

View File

@ -36,12 +36,16 @@
# define LOG_INST_2(hcl,fmt,a1,a2)
# define LOG_INST_3(hcl,fmt,a1,a2,a3)
# define LOG_INST_4(hcl,fmt,a1,a2,a3,a4)
# define LOG_INST_5(hcl,fmt,a1,a2,a3,a4,a5)
# define LOG_INST_6(hcl,fmt,a1,a2,a3,a4,a5,a6)
#else
# define LOG_INST_0(hcl,fmt) HCL_LOG1(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer)
# define LOG_INST_1(hcl,fmt,a1) HCL_LOG2(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1)
# define LOG_INST_2(hcl,fmt,a1,a2) HCL_LOG3(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2)
# define LOG_INST_3(hcl,fmt,a1,a2,a3) HCL_LOG4(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3)
# define LOG_INST_4(hcl,fmt,a1,a2,a3,a4) HCL_LOG5(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3, a4)
# define LOG_INST_5(hcl,fmt,a1,a2,a3,a4,a5) HCL_LOG6(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3, a4, a5)
# define LOG_INST_6(hcl,fmt,a1,a2,a3,a4,a5,a6) HCL_LOG7(hcl, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3, a4, a5, a6)
#endif
#define FETCH_BYTE_CODE(hcl) (cdptr[ip++])
@ -61,7 +65,7 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
{
hcl_oob_t bcode, * cdptr;
hcl_ooi_t ip = start, fetched_instruction_pointer;
hcl_oow_t b1, b2, b3;
hcl_oow_t b1, b2;
/* the instruction at the offset 'end' is not decoded.
* decoding offset range is from start to end - 1. */
@ -195,11 +199,7 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
case HCL_CODE_PUSH_LITERAL_X2:
FETCH_PARAM_CODE_TO (hcl, b1);
FETCH_PARAM_CODE_TO (hcl, b2);
#if (HCL_CODE_LONG_PARAM_SIZE == 2)
b1 = (b1 << 16) | b2;
#else
b1 = (b1 << 8) | b2;
#endif
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
goto push_literal;
case HCL_CODE_PUSH_LITERAL_X:
@ -606,23 +606,41 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
break;
case HCL_CODE_MAKE_FUNCTION:
{
hcl_oow_t b3, b4;
/* b1 - block temporaries mask
* b2 - base literal frame start
* b3 - base literal frame end */
* b2 - block temporaries mask
* b3 - base literal frame start
* b4 - base literal frame end */
FETCH_PARAM_CODE_TO (hcl, b1);
FETCH_PARAM_CODE_TO (hcl, b2);
FETCH_PARAM_CODE_TO (hcl, b3);
FETCH_PARAM_CODE_TO (hcl, b4);
LOG_INST_3 (hcl, "make_function %zu %zu %zu", b1, b2, b3);
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
LOG_INST_6 (hcl, "make_function %zu %zu %zu %zu %zu %zu",
GET_BLKTMPR_MASK_VA(b1),
GET_BLKTMPR_MASK_NARGS(b1),
GET_BLKTMPR_MASK_NRVARS(b1),
GET_BLKTMPR_MASK_NLVARS(b1),
b3, b4);
HCL_ASSERT (hcl, b1 >= 0);
break;
}
case HCL_CODE_MAKE_BLOCK:
/* b1 - block temporaries mask */
/* b1 - block temporaries mask
* b2 - block temporaries mask */
FETCH_PARAM_CODE_TO (hcl, b1);
FETCH_PARAM_CODE_TO (hcl, b2);
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
LOG_INST_1 (hcl, "make_block %zu", b1);
LOG_INST_4 (hcl, "make_block %zu %zu %zu %zu",
GET_BLKTMPR_MASK_VA(b1),
GET_BLKTMPR_MASK_NARGS(b1),
GET_BLKTMPR_MASK_NRVARS(b1),
GET_BLKTMPR_MASK_NLVARS(b1));
HCL_ASSERT (hcl, b1 >= 0);
break;