adding class_cmstore and class_imstore. deleting class_mstore

This commit is contained in:
hyung-hwan 2022-02-12 15:05:31 +00:00
parent 36aba57e4b
commit cdc499763e
4 changed files with 85 additions and 14 deletions

View File

@ -552,7 +552,8 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
case HCL_CODE_STORE_INTO_CLSVAR_M_X: case HCL_CODE_STORE_INTO_CLSVAR_M_X:
case HCL_CODE_POP_INTO_CLSVAR_M_X: case HCL_CODE_POP_INTO_CLSVAR_M_X:
case HCL_CODE_CLASS_MSTORE: case HCL_CODE_CLASS_CMSTORE:
case HCL_CODE_CLASS_IMSTORE:
case HCL_CODE_TRY_ENTER: case HCL_CODE_TRY_ENTER:
case HCL_CODE_TRY_ENTER2: case HCL_CODE_TRY_ENTER2:
case HCL_CODE_PUSH_INTLIT: case HCL_CODE_PUSH_INTLIT:
@ -1279,7 +1280,8 @@ enum
COP_EMIT_POP_STACKTOP, COP_EMIT_POP_STACKTOP,
COP_EMIT_RETURN, COP_EMIT_RETURN,
COP_EMIT_SET, COP_EMIT_SET,
COP_EMIT_CLASS_MSTORE, COP_EMIT_CLASS_CMSTORE,
COP_EMIT_CLASS_IMSTORE,
COP_EMIT_THROW, COP_EMIT_THROW,
COP_POST_IF_COND, COP_POST_IF_COND,
@ -4803,7 +4805,16 @@ static HCL_INLINE int post_lambda (hcl_t* hcl)
if (x == 0) if (x == 0)
{ {
/* arrange to save to the method slot */ /* arrange to save to the method slot */
SWITCH_TOP_CFRAME (hcl, COP_EMIT_CLASS_MSTORE, defun_name); if (xxxx)
{
/* class method */
SWITCH_TOP_CFRAME (hcl, COP_EMIT_CLASS_CMSTORE, defun_name);
}
else
{
/* instance method */
SWITCH_TOP_CFRAME (hcl, COP_EMIT_CLASS_IMSTORE, defun_name);
}
cf = GET_TOP_CFRAME(hcl); cf = GET_TOP_CFRAME(hcl);
} }
else else
@ -4910,20 +4921,39 @@ static HCL_INLINE int emit_set (hcl_t* hcl)
return 0; return 0;
} }
static HCL_INLINE int emit_class_mstore (hcl_t* hcl) static HCL_INLINE int emit_class_cmstore (hcl_t* hcl)
{ {
hcl_cframe_t* cf; hcl_cframe_t* cf;
hcl_oop_t lit; hcl_oop_t lit;
hcl_oow_t index; hcl_oow_t index;
cf = GET_TOP_CFRAME(hcl); cf = GET_TOP_CFRAME(hcl);
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_CLASS_MSTORE); HCL_ASSERT (hcl, cf->opcode == COP_EMIT_CLASS_CMSTORE);
lit = hcl_makesymbol(hcl, HCL_CNODE_GET_TOKPTR(cf->operand), HCL_CNODE_GET_TOKLEN(cf->operand)); lit = hcl_makesymbol(hcl, HCL_CNODE_GET_TOKPTR(cf->operand), HCL_CNODE_GET_TOKLEN(cf->operand));
if (HCL_UNLIKELY(!lit)) return -1; if (HCL_UNLIKELY(!lit)) return -1;
if (add_literal(hcl, lit, &index) <= -1) return -1; if (add_literal(hcl, lit, &index) <= -1) return -1;
if (emit_single_param_instruction(hcl, HCL_CODE_CLASS_MSTORE, index, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1; if (emit_single_param_instruction(hcl, HCL_CODE_CLASS_CMSTORE, index, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1;
POP_CFRAME (hcl);
return 0;
}
static HCL_INLINE int emit_class_imstore (hcl_t* hcl)
{
hcl_cframe_t* cf;
hcl_oop_t lit;
hcl_oow_t index;
cf = GET_TOP_CFRAME(hcl);
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_CLASS_IMSTORE);
lit = hcl_makesymbol(hcl, HCL_CNODE_GET_TOKPTR(cf->operand), HCL_CNODE_GET_TOKLEN(cf->operand));
if (HCL_UNLIKELY(!lit)) return -1;
if (add_literal(hcl, lit, &index) <= -1) return -1;
if (emit_single_param_instruction(hcl, HCL_CODE_CLASS_IMSTORE, index, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1;
POP_CFRAME (hcl); POP_CFRAME (hcl);
return 0; return 0;
@ -5176,8 +5206,12 @@ int hcl_compile (hcl_t* hcl, hcl_cnode_t* obj, int flags)
if (emit_set(hcl) <= -1) goto oops; if (emit_set(hcl) <= -1) goto oops;
break; break;
case COP_EMIT_CLASS_MSTORE: case COP_EMIT_CLASS_CMSTORE:
if (emit_class_mstore(hcl) <= -1) goto oops; if (emit_class_cmstore(hcl) <= -1) goto oops;
break;
case COP_EMIT_CLASS_IMSTORE:
if (emit_class_imstore(hcl) <= -1) goto oops;
break; break;
case COP_EMIT_THROW: case COP_EMIT_THROW:

View File

@ -386,9 +386,14 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
LOG_INST_0 (hcl, "class_pexit"); LOG_INST_0 (hcl, "class_pexit");
break; break;
case HCL_CODE_CLASS_MSTORE: case HCL_CODE_CLASS_CMSTORE:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_mstore %zu", b1); LOG_INST_1 (hcl, "class_cmstore %zu", b1);
break;
case HCL_CODE_CLASS_IMSTORE:
FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_imstore %zu", b1);
break; break;
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */

View File

@ -3594,13 +3594,44 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
break; break;
} }
case HCL_CODE_CLASS_MSTORE: case HCL_CODE_CLASS_CMSTORE:
{
/* TODO: change this part */
hcl_oop_t class_;
hcl_oop_t dic;
FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_cmstore %zu", b1);
/* store the stack top in the member dictionary of the currect class with the key indicated by 'b1' */
HCL_ASSERT (hcl, !HCL_CLSTACK_IS_EMPTY(hcl));
HCL_CLSTACK_FETCH_TOP_TO (hcl, class_);
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, class_));
dic = ((hcl_oop_class_t)class_)->memdic;
HCL_ASSERT (hcl, HCL_IS_NIL(hcl, dic) || HCL_IS_DIC(hcl, dic));
if (HCL_IS_NIL(hcl, dic))
{
hcl_pushvolat (hcl, (hcl_oop_t*)&class_);
dic = hcl_makedic(hcl, 16); /* TODO: configurable initial size? */
hcl_popvolat (hcl);
if (HCL_UNLIKELY(!dic)) goto oops_with_errmsg_supplement;
((hcl_oop_class_t)class_)->memdic = dic;
}
if (!hcl_putatdic(hcl, (hcl_oop_dic_t)dic, hcl->active_function->literal_frame[b1], HCL_STACK_GETTOP(hcl))) goto oops_with_errmsg_supplement;
break;
}
case HCL_CODE_CLASS_IMSTORE:
{ {
hcl_oop_t class_; hcl_oop_t class_;
hcl_oop_t dic; hcl_oop_t dic;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_mstore %zu", b1); LOG_INST_1 (hcl, "class_imstore %zu", b1);
/* store the stack top in the member dictionary of the currect class with the key indicated by 'b1' */ /* store the stack top in the member dictionary of the currect class with the key indicated by 'b1' */

View File

@ -930,8 +930,9 @@ enum hcl_bcode_t
HCL_CODE_CLASS_PEXIT = 0xE3, /* 227 */ HCL_CODE_CLASS_PEXIT = 0xE3, /* 227 */
HCL_CODE_PUSH_OBJVAR_X = 0xE4, /* 228 ## */ HCL_CODE_PUSH_OBJVAR_X = 0xE4, /* 228 ## */
HCL_CODE_CLASS_MSTORE = 0xE5, /* 229 */ HCL_CODE_CLASS_CMSTORE = 0xE5, /* 229 */
/* UNUSED - 0xE6 - 0xE7 */ HCL_CODE_CLASS_IMSTORE = 0xE6, /* 230 */
/* UNUSED - 0xE7 */
HCL_CODE_STORE_INTO_OBJVAR_X = 0xE8, /* 232 ## */ HCL_CODE_STORE_INTO_OBJVAR_X = 0xE8, /* 232 ## */
HCL_CODE_MAKE_ARRAY = 0xE9, /* 233 ## */ HCL_CODE_MAKE_ARRAY = 0xE9, /* 233 ## */