adding the class_set instruction

This commit is contained in:
hyung-hwan 2022-01-29 17:43:11 +00:00
parent a89b83a6fd
commit 84e53e3459
4 changed files with 49 additions and 11 deletions

View File

@ -552,6 +552,7 @@ 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_SET:
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:
@ -1278,6 +1279,7 @@ enum
COP_EMIT_POP_STACKTOP, COP_EMIT_POP_STACKTOP,
COP_EMIT_RETURN, COP_EMIT_RETURN,
COP_EMIT_SET, COP_EMIT_SET,
COP_EMIT_CLASS_SET,
COP_EMIT_THROW, COP_EMIT_THROW,
COP_POST_IF_COND, COP_POST_IF_COND,
@ -2269,7 +2271,7 @@ static HCL_INLINE int compile_class_p2 (hcl_t* hcl)
pop_clsblk (hcl); /* end of the class block */ pop_clsblk (hcl); /* end of the class block */
if (emit_byte_instruction(hcl, HCL_CODE_CLASS_PUSH_EXIT, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1; if (emit_byte_instruction(hcl, HCL_CODE_CLASS_PEXIT, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1;
// if (cf->operand) // if (cf->operand)
{ {
@ -4793,8 +4795,9 @@ static HCL_INLINE int post_lambda (hcl_t* hcl)
if (x <= -1) return -1; if (x <= -1) return -1;
if (x == 0) if (x == 0)
{ {
/* save to the method slot */ /* arrange to save to the method slot */
printf ("this is a method defintion...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.\n"); SWITCH_TOP_CFRAME (hcl, COP_EMIT_CLASS_SET, defun_name);
cf = GET_TOP_CFRAME(hcl);
} }
else else
{ {
@ -4802,7 +4805,6 @@ printf ("this is a method defintion...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.\n");
hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAMEDUP, HCL_CNODE_GET_LOC(defun_name), HCL_CNODE_GET_TOK(defun_name), "duplicate name"); hcl_setsynerrbfmt (hcl, HCL_SYNERR_VARNAMEDUP, HCL_CNODE_GET_LOC(defun_name), HCL_CNODE_GET_TOK(defun_name), "duplicate name");
return -1; return -1;
} }
cf->u.set.mode = VAR_ACCESS_STORE;
} }
else else
{ {
@ -4902,6 +4904,26 @@ static HCL_INLINE int emit_set (hcl_t* hcl)
return 0; return 0;
} }
static HCL_INLINE int emit_class_set (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_SET);
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_SET, index, HCL_CNODE_GET_LOC(cf->operand)) <= -1) return -1;
POP_CFRAME (hcl);
return 0;
}
static HCL_INLINE int emit_throw (hcl_t* hcl) static HCL_INLINE int emit_throw (hcl_t* hcl)
{ {
hcl_cframe_t* cf; hcl_cframe_t* cf;
@ -5149,6 +5171,10 @@ 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_SET:
if (emit_class_set(hcl) <= -1) goto oops;
break;
case COP_EMIT_THROW: case COP_EMIT_THROW:
if (emit_throw(hcl) <= -1) goto oops; if (emit_throw(hcl) <= -1) goto oops;
break; break;

View File

@ -382,8 +382,13 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
LOG_INST_0 (hcl, "class_exit"); LOG_INST_0 (hcl, "class_exit");
break; break;
case HCL_CODE_CLASS_PUSH_EXIT: case HCL_CODE_CLASS_PEXIT:
LOG_INST_0 (hcl, "class_push_exit"); LOG_INST_0 (hcl, "class_pexit");
break;
case HCL_CODE_CLASS_SET:
FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_set %zu", b1);
break; break;
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */

View File

@ -3534,11 +3534,11 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
break; break;
} }
case HCL_CODE_CLASS_PUSH_EXIT: case HCL_CODE_CLASS_PEXIT:
{ {
hcl_oop_t c; hcl_oop_t c;
LOG_INST_0 (hcl, "class_push_exit"); LOG_INST_0 (hcl, "class_pexit");
if (HCL_CLSTACK_IS_EMPTY(hcl)) if (HCL_CLSTACK_IS_EMPTY(hcl))
{ {
@ -3551,6 +3551,12 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
break; break;
} }
case HCL_CODE_CLASS_SET:
{
FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "class_set %zu", b1);
}
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
case HCL_CODE_PUSH_CTXTEMPVAR_X: case HCL_CODE_PUSH_CTXTEMPVAR_X:

View File

@ -925,10 +925,11 @@ enum hcl_bcode_t
HCL_CODE_PUSH_CTXTEMPVAR_X = 0xE0, /* 224 ## */ HCL_CODE_PUSH_CTXTEMPVAR_X = 0xE0, /* 224 ## */
HCL_CODE_CLASS_ENTER = 0xE1, /* 225 ## */ HCL_CODE_CLASS_ENTER = 0xE1, /* 225 ## */
HCL_CODE_CLASS_EXIT = 0xE2, /* 226 */ HCL_CODE_CLASS_EXIT = 0xE2, /* 226 */
HCL_CODE_CLASS_PUSH_EXIT = 0xE3, /* 227 */ HCL_CODE_CLASS_PEXIT = 0xE3, /* 227 */
HCL_CODE_PUSH_OBJVAR_X = 0xE4, /* 228 ## */ HCL_CODE_PUSH_OBJVAR_X = 0xE4, /* 228 ## */
/* UNUSED - 0xE5 - 0xE7 */ HCL_CODE_CLASS_SET = 0xE5, /* 229 */
/* UNUSED - 0xE6 - 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 ## */