enhanced the compiler a bit

This commit is contained in:
hyung-hwan 2021-01-27 16:01:36 +00:00
parent d36c12e21a
commit 4a7e5dc44e
2 changed files with 22 additions and 14 deletions

View File

@ -2246,13 +2246,14 @@ static int compile_array_list (hcl_t* hcl)
cf->u.array_list.index = oldidx + 1; cf->u.array_list.index = oldidx + 1;
} }
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_ARRAY, HCL_SMOOI_TO_OOP(oldidx)); PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_ARRAY, car);
cf = GET_SUBCFRAME(hcl);
cf->u.array_list.index = oldidx;
} }
return 0; return 0;
} }
static int compile_bytearray_list (hcl_t* hcl) static int compile_bytearray_list (hcl_t* hcl)
{ {
hcl_cframe2_t* cf; hcl_cframe2_t* cf;
@ -2291,7 +2292,9 @@ static int compile_bytearray_list (hcl_t* hcl)
cf->u.bytearray_list.index = oldidx + 1; cf->u.bytearray_list.index = oldidx + 1;
} }
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_BYTEARRAY, HCL_SMOOI_TO_OOP(oldidx)); PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_BYTEARRAY, car);
cf = GET_SUBCFRAME(hcl);
cf->u.bytearray_list.index = oldidx;
} }
return 0; return 0;
@ -2340,7 +2343,7 @@ static int compile_dic_list (hcl_t* hcl)
PUSH_SUBCFRAME (hcl, COP_COMPILE_DIC_LIST, cddr); PUSH_SUBCFRAME (hcl, COP_COMPILE_DIC_LIST, cddr);
} }
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_DIC, HCL_SMOOI_TO_OOP(0)); PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_DIC, cdr);
PUSH_SUBCFRAME(hcl, COP_COMPILE_OBJECT, cadr); PUSH_SUBCFRAME(hcl, COP_COMPILE_OBJECT, cadr);
} }
@ -2363,16 +2366,16 @@ static int compile_qlist (hcl_t* hcl)
} }
else else
{ {
hcl_cnode_t* car, * cdr;
if (!HCL_CNODE_IS_CONS(oprnd)) if (!HCL_CNODE_IS_CONS(oprnd))
{ {
/* the last element after . */ /* the last element after . */
SWITCH_TOP_CFRAME (hcl, COP_COMPILE_OBJECT, oprnd); SWITCH_TOP_CFRAME (hcl, COP_COMPILE_OBJECT, oprnd);
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS_CDR, oprnd); /* TODO: can i pass the location of the closing )? */ PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS_CDR, oprnd);
} }
else else
{ {
hcl_cnode_t* car, * cdr;
car = HCL_CNODE_CONS_CAR(oprnd); car = HCL_CNODE_CONS_CAR(oprnd);
cdr = HCL_CNODE_CONS_CDR(oprnd); cdr = HCL_CNODE_CONS_CDR(oprnd);
@ -2380,12 +2383,12 @@ static int compile_qlist (hcl_t* hcl)
if (cdr) if (cdr)
{ {
PUSH_SUBCFRAME (hcl, COP_COMPILE_QLIST, cdr); /* 3 */ PUSH_SUBCFRAME (hcl, COP_COMPILE_QLIST, cdr); /* 3 */
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS, oprnd); /* 2 */ PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS, car); /* 2 */
} }
else else
{ {
/* the last element */ /* the last element */
PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS_END, oprnd); /* 2 */ PUSH_SUBCFRAME (hcl, COP_EMIT_POP_INTO_CONS_END, car); /* 2 */
} }
} }
} }
@ -2909,9 +2912,9 @@ static HCL_INLINE int emit_pop_into_array (hcl_t* hcl)
cf = GET_TOP_CFRAME(hcl); cf = GET_TOP_CFRAME(hcl);
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_ARRAY); HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_ARRAY);
HCL_ASSERT (hcl, HCL_OOP_IS_SMOOI(cf->operand)); HCL_ASSERT (hcl, cf->operand != HCL_NULL);
n = emit_single_param_instruction(hcl, HCL_CODE_POP_INTO_ARRAY, HCL_OOP_TO_SMOOI(cf->operand)); n = emit_single_param_instruction(hcl, HCL_CODE_POP_INTO_ARRAY, cf->u.array_list.index);
POP_CFRAME (hcl); POP_CFRAME (hcl);
return n; return n;
@ -2924,9 +2927,9 @@ static HCL_INLINE int emit_pop_into_bytearray (hcl_t* hcl)
cf = GET_TOP_CFRAME(hcl); cf = GET_TOP_CFRAME(hcl);
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_BYTEARRAY); HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_BYTEARRAY);
HCL_ASSERT (hcl, HCL_OOP_IS_SMOOI(cf->operand)); HCL_ASSERT (hcl, cf->operand != HCL_NULL);
n = emit_single_param_instruction(hcl, HCL_CODE_POP_INTO_BYTEARRAY, HCL_OOP_TO_SMOOI(cf->operand)); n = emit_single_param_instruction(hcl, HCL_CODE_POP_INTO_BYTEARRAY, cf->u.bytearray_list.index);
POP_CFRAME (hcl); POP_CFRAME (hcl);
return n; return n;
@ -2939,8 +2942,9 @@ static HCL_INLINE int emit_pop_into_dic (hcl_t* hcl)
cf = GET_TOP_CFRAME(hcl); cf = GET_TOP_CFRAME(hcl);
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_DIC); HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_INTO_DIC);
HCL_ASSERT (hcl, cf->operand != HCL_NULL);
n = emit_byte_instruction(hcl, HCL_CODE_POP_INTO_DIC, HCL_NULL); n = emit_byte_instruction(hcl, HCL_CODE_POP_INTO_DIC, HCL_CNODE_GET_LOC(cf->operand));
POP_CFRAME (hcl); POP_CFRAME (hcl);
return n; return n;

View File

@ -337,16 +337,19 @@ struct hcl_cframe2_t
hcl_ioloc_t start_loc; hcl_ioloc_t start_loc;
} post_if; } post_if;
/* COP_COMPILE_ARRAY_LIST, COP_POP_INTO_ARRAY */
struct struct
{ {
hcl_ooi_t index; hcl_ooi_t index;
} array_list; } array_list;
/* COP_COMPILE_BYTEARRAY_LIST, COP_POP_INTO_BYTEARRAY */
struct struct
{ {
hcl_ooi_t index; hcl_ooi_t index;
} bytearray_list; } bytearray_list;
/* COP_EMIT_LAMBDA */
struct struct
{ {
hcl_oow_t jump_inst_pos; hcl_oow_t jump_inst_pos;
@ -354,6 +357,7 @@ struct hcl_cframe2_t
hcl_ooi_t lfsize_pos; hcl_ooi_t lfsize_pos;
} lambda; } lambda;
/* COP_EMIT_RETURN */
struct struct
{ {
int from_home; int from_home;