fixing bugs introduced for block temporaries sheme
This commit is contained in:
parent
bd3730fd12
commit
c37b695a76
26
lib/comp.c
26
lib/comp.c
@ -389,6 +389,7 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
|
||||
case HCL_CODE_PUSH_NEGINTLIT:
|
||||
case HCL_CODE_PUSH_CHARLIT:
|
||||
|
||||
|
||||
case HCL_CODE_MAKE_DIC: /* TODO: don't these need write_long2? */
|
||||
case HCL_CODE_MAKE_ARRAY:
|
||||
case HCL_CODE_MAKE_BYTEARRAY:
|
||||
@ -396,6 +397,17 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
|
||||
case HCL_CODE_POP_INTO_BYTEARRAY:
|
||||
bc = cmd;
|
||||
goto write_long;
|
||||
|
||||
/* MAKE_FUNCTION is a quad-parameter instruction.
|
||||
* The caller must emit two more parameters after the call to this function.
|
||||
* however the instruction format is the same up to the second
|
||||
* parameters between MAKE_FUNCTION and MAKE_BLOCK.
|
||||
*/
|
||||
case HCL_CODE_MAKE_FUNCTION:
|
||||
case HCL_CODE_MAKE_BLOCK:
|
||||
/* write_long2 produces two parameters */
|
||||
bc = cmd;
|
||||
goto write_long2;
|
||||
}
|
||||
|
||||
hcl_seterrnum (hcl, HCL_EINVAL);
|
||||
@ -432,11 +444,11 @@ write_long2:
|
||||
emit_byte_instruction(hcl, (param_1 >> 24) & 0xFF, HCL_NULL) <= -1 ||
|
||||
emit_byte_instruction(hcl, (param_1 >> 16) & 0xFF, HCL_NULL) <= -1 ||
|
||||
emit_byte_instruction(hcl, (param_1 >> 8) & 0xFF, HCL_NULL) <= -1 ||
|
||||
emit_byte_instruction(hcl, param_1 & 0xFF, HCL_NULL) <= -1) return -1;
|
||||
emit_byte_instruction(hcl, (param_1 >> 0) & 0xFF, HCL_NULL) <= -1) return -1;
|
||||
#else
|
||||
if (emit_byte_instruction(hcl, bc, srcloc) <= -1 ||
|
||||
emit_byte_instruction(hcl, (param_1 >> 8) & 0xFF, HCL_NULL) <= -1 ||
|
||||
emit_byte_instruction(hcl, param_1 & 0xFF, HCL_NULL) <= -1) return -1;
|
||||
emit_byte_instruction(hcl, (param_1 >> 0) & 0xFF, HCL_NULL) <= -1) return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -467,16 +479,6 @@ static int emit_double_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
|
||||
bc = cmd | 0x80;
|
||||
goto write_long;
|
||||
}
|
||||
|
||||
/* MAKE_FUNCTION is a quad-parameter instruction.
|
||||
* The caller must emit two more parameters after the call to this function.
|
||||
* however the instruction format is the same up to the second
|
||||
* parameters between MAKE_FUNCTION and MAKE_BLOCK.
|
||||
*/
|
||||
case HCL_CODE_MAKE_FUNCTION:
|
||||
case HCL_CODE_MAKE_BLOCK:
|
||||
bc = cmd;
|
||||
goto write_long;
|
||||
}
|
||||
|
||||
hcl_seterrnum (hcl, HCL_EINVAL);
|
||||
|
40
lib/decode.c
40
lib/decode.c
@ -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;
|
||||
|
44
lib/exec.c
44
lib/exec.c
@ -121,6 +121,8 @@ static hcl_ooch_t oocstr_dash[] = { '-', '\0' };
|
||||
# define LOG_INST_2(hcl,fmt,a1,a2) HCL_LOG3(hcl, LOG_MASK_INST, "%010zd " fmt "\n", fetched_instruction_pointer, a1, a2)
|
||||
# define LOG_INST_3(hcl,fmt,a1,a2,a3) HCL_LOG4(hcl, LOG_MASK_INST, "%010zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3)
|
||||
# define LOG_INST_4(hcl,fmt,a1,a2,a3,a4) HCL_LOG5(hcl, LOG_MASK_INST, "%010zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3, a4)
|
||||
# define LOG_INST_5(hcl,fmt,a1,a2,a3,a4,a5) HCL_LOG6(hcl, LOG_MASK_INST, "%010zd " 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, LOG_MASK_INST, "%010zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3, a4, a5, a6)
|
||||
|
||||
#else
|
||||
# define LOG_INST_0(hcl,fmt)
|
||||
@ -128,6 +130,8 @@ static hcl_ooch_t oocstr_dash[] = { '-', '\0' };
|
||||
# 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)
|
||||
#endif
|
||||
|
||||
static int delete_sem_from_sem_io_tuple (hcl_t* hcl, hcl_oop_semaphore_t sem, int force);
|
||||
@ -2935,11 +2939,7 @@ static int execute (hcl_t* hcl)
|
||||
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:
|
||||
@ -3711,17 +3711,25 @@ static int execute (hcl_t* hcl)
|
||||
case HCL_CODE_MAKE_FUNCTION:
|
||||
{
|
||||
hcl_oop_function_t func;
|
||||
hcl_oow_t b3;
|
||||
hcl_oow_t b3, b4;
|
||||
hcl_oow_t joff;
|
||||
|
||||
/* b1 - block temporaries mask
|
||||
* b2 - literal frame base
|
||||
* b3 - literal frame size */
|
||||
* b2 - block temporaries mask
|
||||
* b3 - literal frame base
|
||||
* b4 - literal frame size */
|
||||
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);
|
||||
|
||||
@ -3736,13 +3744,13 @@ static int execute (hcl_t* hcl)
|
||||
|
||||
/* copy the byte codes from the active context to the new context */
|
||||
#if (HCL_CODE_LONG_PARAM_SIZE == 2)
|
||||
func = make_function(hcl, b3, &hcl->active_code[hcl->ip + 3], joff, HCL_NULL);
|
||||
func = make_function(hcl, b4, &hcl->active_code[hcl->ip + 3], joff, HCL_NULL);
|
||||
#else
|
||||
func = make_function(hcl, b3, &hcl->active_code[hcl->ip + 2], joff, HCL_NULL);
|
||||
func = make_function(hcl, b4, &hcl->active_code[hcl->ip + 2], joff, HCL_NULL);
|
||||
#endif
|
||||
if (HCL_UNLIKELY(!func)) goto oops;
|
||||
|
||||
fill_function_data (hcl, func, b1, hcl->active_context, &hcl->active_function->literal_frame[b2], b3);
|
||||
fill_function_data (hcl, func, b1, hcl->active_context, &hcl->active_function->literal_frame[b3], b4);
|
||||
|
||||
/* push the new function to the stack of the active context */
|
||||
HCL_STACK_PUSH (hcl, (hcl_oop_t)func);
|
||||
@ -3753,10 +3761,16 @@ static int execute (hcl_t* hcl)
|
||||
{
|
||||
hcl_oop_block_t blkobj;
|
||||
|
||||
/* b1 - block temporaries mask */
|
||||
/* b1 - block temporaries mask
|
||||
* b2 - block temporaries mask */
|
||||
FETCH_PARAM_CODE_TO (hcl, b1);
|
||||
|
||||
LOG_INST_1 (hcl, "make_block %zu", b1);
|
||||
FETCH_PARAM_CODE_TO (hcl, b2);
|
||||
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
|
||||
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);
|
||||
|
||||
|
@ -894,6 +894,7 @@ typedef enum hcl_log_mask_t hcl_log_mask_t;
|
||||
#define HCL_LOG4(hcl,mask,fmt,a1,a2,a3,a4) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4); } while(0)
|
||||
#define HCL_LOG5(hcl,mask,fmt,a1,a2,a3,a4,a5) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5); } while(0)
|
||||
#define HCL_LOG6(hcl,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0)
|
||||
#define HCL_LOG7(hcl,mask,fmt,a1,a2,a3,a4,a5,a6,a7) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5, a6, a7); } while(0)
|
||||
|
||||
#if defined(HCL_BUILD_RELEASE)
|
||||
/* [NOTE]
|
||||
|
Loading…
Reference in New Issue
Block a user