simplified the class variable access by remembering the method owner class in context objects

This commit is contained in:
hyung-hwan 2022-02-17 12:40:22 +00:00
parent fcfbec6647
commit 420d38c8be
6 changed files with 191 additions and 228 deletions

View File

@ -477,9 +477,9 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
switch (cmd) switch (cmd)
{ {
case HCL_CODE_PUSH_INSTVAR_0: case HCL_CODE_PUSH_IVAR_0:
case HCL_CODE_STORE_INTO_INSTVAR_0: case HCL_CODE_STORE_INTO_IVAR_0:
case HCL_CODE_POP_INTO_INSTVAR_0: case HCL_CODE_POP_INTO_IVAR_0:
case HCL_CODE_PUSH_TEMPVAR_0: case HCL_CODE_PUSH_TEMPVAR_0:
case HCL_CODE_STORE_INTO_TEMPVAR_0: case HCL_CODE_STORE_INTO_TEMPVAR_0:
case HCL_CODE_POP_INTO_TEMPVAR_0: case HCL_CODE_POP_INTO_TEMPVAR_0:
@ -546,12 +546,12 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
case HCL_CODE_JUMP2_BACKWARD_IF_FALSE: case HCL_CODE_JUMP2_BACKWARD_IF_FALSE:
case HCL_CODE_JUMP2_BACKWARD: case HCL_CODE_JUMP2_BACKWARD:
case HCL_CODE_PUSH_CLSVAR_I_X: case HCL_CODE_PUSH_CVAR_I_X:
case HCL_CODE_STORE_INTO_CLSVAR_I_X: case HCL_CODE_STORE_INTO_CVAR_I_X:
case HCL_CODE_POP_INTO_CLSVAR_I_X: case HCL_CODE_POP_INTO_CVAR_I_X:
case HCL_CODE_PUSH_CLSVAR_M_X: case HCL_CODE_PUSH_CVAR_M_X:
case HCL_CODE_STORE_INTO_CLSVAR_M_X: case HCL_CODE_STORE_INTO_CVAR_M_X:
case HCL_CODE_POP_INTO_CLSVAR_M_X: case HCL_CODE_POP_INTO_CVAR_M_X:
case HCL_CODE_CLASS_CMSTORE: case HCL_CODE_CLASS_CMSTORE:
case HCL_CODE_CLASS_IMSTORE: case HCL_CODE_CLASS_IMSTORE:
@ -814,9 +814,9 @@ static int emit_variable_access (hcl_t* hcl, int mode, const hcl_var_info_t* vi,
static hcl_oob_t inst_map[][3] = static hcl_oob_t inst_map[][3] =
{ {
{ HCL_CODE_PUSH_CTXTEMPVAR_0, HCL_CODE_POP_INTO_CTXTEMPVAR_0, HCL_CODE_STORE_INTO_CTXTEMPVAR_0 }, { HCL_CODE_PUSH_CTXTEMPVAR_0, HCL_CODE_POP_INTO_CTXTEMPVAR_0, HCL_CODE_STORE_INTO_CTXTEMPVAR_0 },
{ HCL_CODE_PUSH_INSTVAR_0, HCL_CODE_POP_INTO_INSTVAR_0, HCL_CODE_STORE_INTO_INSTVAR_0 }, { HCL_CODE_PUSH_IVAR_0, HCL_CODE_POP_INTO_IVAR_0, HCL_CODE_STORE_INTO_IVAR_0 },
{ HCL_CODE_PUSH_CLSVAR_I_X, HCL_CODE_POP_INTO_CLSVAR_I_X, HCL_CODE_STORE_INTO_CLSVAR_I_X }, { HCL_CODE_PUSH_CVAR_I_X, HCL_CODE_POP_INTO_CVAR_I_X, HCL_CODE_STORE_INTO_CVAR_I_X },
{ HCL_CODE_PUSH_CLSVAR_M_X, HCL_CODE_POP_INTO_CLSVAR_M_X, HCL_CODE_STORE_INTO_CLSVAR_M_X } { HCL_CODE_PUSH_CVAR_M_X, HCL_CODE_POP_INTO_CVAR_M_X, HCL_CODE_STORE_INTO_CVAR_M_X }
}; };
switch (vi->type) switch (vi->type)
@ -825,7 +825,6 @@ static int emit_variable_access (hcl_t* hcl, int mode, const hcl_var_info_t* vi,
return emit_double_param_instruction(hcl, inst_map[0][mode], vi->ctx_offset, vi->index_in_ctx, srcloc); return emit_double_param_instruction(hcl, inst_map[0][mode], vi->ctx_offset, vi->index_in_ctx, srcloc);
case VAR_INST: case VAR_INST:
case VAR_CLASS_CM: /* class variable in class method scope */
HCL_ASSERT (hcl, vi->ctx_offset == 0); HCL_ASSERT (hcl, vi->ctx_offset == 0);
return emit_single_param_instruction(hcl, inst_map[1][mode], vi->index_in_ctx, srcloc); return emit_single_param_instruction(hcl, inst_map[1][mode], vi->index_in_ctx, srcloc);
@ -833,6 +832,7 @@ static int emit_variable_access (hcl_t* hcl, int mode, const hcl_var_info_t* vi,
HCL_ASSERT (hcl, vi->ctx_offset == 0); HCL_ASSERT (hcl, vi->ctx_offset == 0);
return emit_single_param_instruction(hcl, inst_map[2][mode], vi->index_in_ctx, srcloc); return emit_single_param_instruction(hcl, inst_map[2][mode], vi->index_in_ctx, srcloc);
case VAR_CLASS_CM: /* class variable in class method scope */
case VAR_CLASS_IM: /* class variable in instance method scope */ case VAR_CLASS_IM: /* class variable in instance method scope */
HCL_ASSERT (hcl, vi->ctx_offset == 0); HCL_ASSERT (hcl, vi->ctx_offset == 0);
return emit_single_param_instruction(hcl, inst_map[3][mode], vi->index_in_ctx, srcloc); return emit_single_param_instruction(hcl, inst_map[3][mode], vi->index_in_ctx, srcloc);

View File

@ -80,54 +80,54 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
switch (bcode) switch (bcode)
{ {
case HCL_CODE_PUSH_INSTVAR_X: case HCL_CODE_PUSH_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto push_instvar; goto push_ivar;
case HCL_CODE_PUSH_INSTVAR_0: case HCL_CODE_PUSH_IVAR_0:
case HCL_CODE_PUSH_INSTVAR_1: case HCL_CODE_PUSH_IVAR_1:
case HCL_CODE_PUSH_INSTVAR_2: case HCL_CODE_PUSH_IVAR_2:
case HCL_CODE_PUSH_INSTVAR_3: case HCL_CODE_PUSH_IVAR_3:
case HCL_CODE_PUSH_INSTVAR_4: case HCL_CODE_PUSH_IVAR_4:
case HCL_CODE_PUSH_INSTVAR_5: case HCL_CODE_PUSH_IVAR_5:
case HCL_CODE_PUSH_INSTVAR_6: case HCL_CODE_PUSH_IVAR_6:
case HCL_CODE_PUSH_INSTVAR_7: case HCL_CODE_PUSH_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
push_instvar: push_ivar:
LOG_INST_1 (hcl, "push_instvar %zu", b1); LOG_INST_1 (hcl, "push_ivar %zu", b1);
break; break;
/* ------------------------------------------------- */ /* ------------------------------------------------- */
case HCL_CODE_STORE_INTO_INSTVAR_X: case HCL_CODE_STORE_INTO_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto store_instvar; goto store_into_ivar;
case HCL_CODE_STORE_INTO_INSTVAR_0: case HCL_CODE_STORE_INTO_IVAR_0:
case HCL_CODE_STORE_INTO_INSTVAR_1: case HCL_CODE_STORE_INTO_IVAR_1:
case HCL_CODE_STORE_INTO_INSTVAR_2: case HCL_CODE_STORE_INTO_IVAR_2:
case HCL_CODE_STORE_INTO_INSTVAR_3: case HCL_CODE_STORE_INTO_IVAR_3:
case HCL_CODE_STORE_INTO_INSTVAR_4: case HCL_CODE_STORE_INTO_IVAR_4:
case HCL_CODE_STORE_INTO_INSTVAR_5: case HCL_CODE_STORE_INTO_IVAR_5:
case HCL_CODE_STORE_INTO_INSTVAR_6: case HCL_CODE_STORE_INTO_IVAR_6:
case HCL_CODE_STORE_INTO_INSTVAR_7: case HCL_CODE_STORE_INTO_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
store_instvar: store_into_ivar:
LOG_INST_1 (hcl, "store_into_instvar %zu", b1); LOG_INST_1 (hcl, "store_into_ivar %zu", b1);
break; break;
case HCL_CODE_POP_INTO_INSTVAR_X: case HCL_CODE_POP_INTO_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto pop_into_instvar; goto pop_into_ivar;
case HCL_CODE_POP_INTO_INSTVAR_0: case HCL_CODE_POP_INTO_IVAR_0:
case HCL_CODE_POP_INTO_INSTVAR_1: case HCL_CODE_POP_INTO_IVAR_1:
case HCL_CODE_POP_INTO_INSTVAR_2: case HCL_CODE_POP_INTO_IVAR_2:
case HCL_CODE_POP_INTO_INSTVAR_3: case HCL_CODE_POP_INTO_IVAR_3:
case HCL_CODE_POP_INTO_INSTVAR_4: case HCL_CODE_POP_INTO_IVAR_4:
case HCL_CODE_POP_INTO_INSTVAR_5: case HCL_CODE_POP_INTO_IVAR_5:
case HCL_CODE_POP_INTO_INSTVAR_6: case HCL_CODE_POP_INTO_IVAR_6:
case HCL_CODE_POP_INTO_INSTVAR_7: case HCL_CODE_POP_INTO_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
pop_into_instvar: pop_into_ivar:
LOG_INST_1 (hcl, "pop_into_instvar %zu", b1); LOG_INST_1 (hcl, "pop_into_ivar %zu", b1);
break; break;
/* ------------------------------------------------- */ /* ------------------------------------------------- */
@ -519,36 +519,36 @@ int hcl_decode (hcl_t* hcl, hcl_oow_t start, hcl_oow_t end)
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
case HCL_CODE_PUSH_CLSVAR_I_X: case HCL_CODE_PUSH_CVAR_I_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "push_clsvar_i %zu", b1); LOG_INST_1 (hcl, "push_cvar_i %zu", b1);
break; break;
case HCL_CODE_STORE_INTO_CLSVAR_I_X: case HCL_CODE_STORE_INTO_CVAR_I_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "store_into_clsvar_i %zu", b1); LOG_INST_1 (hcl, "store_into_cvar_i %zu", b1);
break; break;
case HCL_CODE_POP_INTO_CLSVAR_I_X: case HCL_CODE_POP_INTO_CVAR_I_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "pop_into_clsvar_i %zu", b1); LOG_INST_1 (hcl, "pop_into_cvar_i %zu", b1);
break; break;
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
case HCL_CODE_PUSH_CLSVAR_M_X: case HCL_CODE_PUSH_CVAR_M_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "push_clsvar_m %zu", b1); LOG_INST_1 (hcl, "push_cvar_m %zu", b1);
break; break;
case HCL_CODE_STORE_INTO_CLSVAR_M_X: case HCL_CODE_STORE_INTO_CVAR_M_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "store_into_clsvar_m %zu", b1); LOG_INST_1 (hcl, "store_into_cvar_m %zu", b1);
break; break;
case HCL_CODE_POP_INTO_CLSVAR_M_X: case HCL_CODE_POP_INTO_CVAR_M_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "pop_into_clsvar_m %zu", b1); LOG_INST_1 (hcl, "pop_into_cvar_m %zu", b1);
break; break;
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */

View File

@ -88,19 +88,6 @@ static hcl_ooch_t oocstr_dash[] = { '-', '\0' };
#define LOAD_ACTIVE_SP(hcl) LOAD_SP(hcl, (hcl)->processor->active) #define LOAD_ACTIVE_SP(hcl) LOAD_SP(hcl, (hcl)->processor->active)
#define STORE_ACTIVE_SP(hcl) STORE_SP(hcl, (hcl)->processor->active) #define STORE_ACTIVE_SP(hcl) STORE_SP(hcl, (hcl)->processor->active)
#if 0
// THIS PART IS TO BE REMOVED
#define SWITCH_ACTIVE_CONTEXT(hcl,v_ctx) \
do \
{ \
STORE_ACTIVE_IP (hcl); \
(hcl)->active_context = (v_ctx); \
(hcl)->active_function = (hcl)->active_context->origin->base; \
(hcl)->active_code = HCL_FUNCTION_GET_CODE_BYTE((hcl)->active_function); \
LOAD_ACTIVE_IP (hcl); \
(hcl)->processor->active->current_context = (hcl)->active_context; \
} while (0)
#else
#define SWITCH_ACTIVE_CONTEXT(hcl,v_ctx) \ #define SWITCH_ACTIVE_CONTEXT(hcl,v_ctx) \
do \ do \
{ \ { \
@ -111,7 +98,6 @@ static hcl_ooch_t oocstr_dash[] = { '-', '\0' };
LOAD_ACTIVE_IP (hcl); \ LOAD_ACTIVE_IP (hcl); \
(hcl)->processor->active->current_context = (hcl)->active_context; \ (hcl)->processor->active->current_context = (hcl)->active_context; \
} while (0) } while (0)
#endif
/*#define FETCH_BYTE_CODE(hcl) ((hcl)->code.bc.arr->slot[(hcl)->ip++])*/ /*#define FETCH_BYTE_CODE(hcl) ((hcl)->code.bc.arr->slot[(hcl)->ip++])*/
#define FETCH_BYTE_CODE(hcl) ((hcl)->active_code[(hcl)->ip++]) #define FETCH_BYTE_CODE(hcl) ((hcl)->active_code[(hcl)->ip++])
@ -1955,7 +1941,6 @@ static int prepare_new_context (hcl_t* hcl, hcl_oop_block_t op_blk, hcl_ooi_t na
blkctx->req_nrets = HCL_SMOOI_TO_OOP(req_nrvars); blkctx->req_nrets = HCL_SMOOI_TO_OOP(req_nrvars);
blkctx->tmpr_mask = op_blk->tmpr_mask; blkctx->tmpr_mask = op_blk->tmpr_mask;
blkctx->base = op_blk->home->base; blkctx->base = op_blk->home->base;
blkctx->origin = op_blk->home->origin;
if (is_msgsend) if (is_msgsend)
{ {
@ -2083,7 +2068,6 @@ static int __activate_function (hcl_t* hcl, hcl_oop_function_t op_func, hcl_ooi_
functx->tmpr_mask = op_func->tmpr_mask; functx->tmpr_mask = op_func->tmpr_mask;
functx->base = op_func; functx->base = op_func;
functx->home = op_func->home; functx->home = op_func->home;
functx->origin = functx; /* the origin of the context over a function should be itself */
functx->receiver = HCL_STACK_GETRCV(hcl, nargs); functx->receiver = HCL_STACK_GETRCV(hcl, nargs);
/* copy the fixed arguments to the beginning of the variable part of the context block */ /* copy the fixed arguments to the beginning of the variable part of the context block */
@ -2147,16 +2131,16 @@ static HCL_INLINE int call_primitive (hcl_t* hcl, hcl_ooi_t nargs)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static hcl_oop_block_t find_cmethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_, hcl_oop_t op) static hcl_oop_block_t find_cmethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_, hcl_oop_t op_name, hcl_oop_class_t* owner)
{ {
hcl_oocs_t name; hcl_oocs_t name;
/* TODO: implement method cache */ /* TODO: implement method cache */
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, class_)); HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, class_));
HCL_ASSERT (hcl, HCL_IS_SYMBOL(hcl, op)); HCL_ASSERT (hcl, HCL_IS_SYMBOL(hcl, op_name));
name.ptr = HCL_OBJ_GET_CHAR_SLOT(op); name.ptr = HCL_OBJ_GET_CHAR_SLOT(op_name);
name.len = HCL_OBJ_GET_SIZE(op); name.len = HCL_OBJ_GET_SIZE(op_name);
do do
{ {
@ -2176,6 +2160,7 @@ static hcl_oop_block_t find_cmethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_
if (HCL_IS_BLOCK(hcl, val)) if (HCL_IS_BLOCK(hcl, val))
{ {
/* TODO: futher check if it's a method block? */ /* TODO: futher check if it's a method block? */
*owner = class_;
return (hcl_oop_block_t)val; return (hcl_oop_block_t)val;
} }
} }
@ -2187,7 +2172,7 @@ static hcl_oop_block_t find_cmethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_
return HCL_NULL; return HCL_NULL;
} }
static hcl_oop_block_t find_imethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_, hcl_oop_t op, hcl_ooi_t* ivaroff) static hcl_oop_block_t find_imethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_, hcl_oop_t op, hcl_ooi_t* ivaroff, hcl_oop_class_t* owner)
{ {
hcl_oocs_t name; hcl_oocs_t name;
@ -2215,6 +2200,7 @@ static hcl_oop_block_t find_imethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_
if (HCL_IS_BLOCK(hcl, val)) if (HCL_IS_BLOCK(hcl, val))
{ {
/* TODO: futher check if it's a method block? */ /* TODO: futher check if it's a method block? */
*owner = class_;
*ivaroff = HCL_OOP_TO_SMOOI(class_->nivars_super); *ivaroff = HCL_OOP_TO_SMOOI(class_->nivars_super);
return (hcl_oop_block_t)val; return (hcl_oop_block_t)val;
} }
@ -2229,33 +2215,41 @@ static hcl_oop_block_t find_imethod_noseterr (hcl_t* hcl, hcl_oop_class_t class_
static HCL_INLINE int send_message (hcl_t* hcl, hcl_oop_t rcv, hcl_oop_t msg, int to_super, hcl_ooi_t nargs) static HCL_INLINE int send_message (hcl_t* hcl, hcl_oop_t rcv, hcl_oop_t msg, int to_super, hcl_ooi_t nargs)
{ {
hcl_oop_block_t mth; hcl_oop_block_t mth_blk;
hcl_oop_context_t newctx; hcl_oop_context_t newctx;
hcl_oop_class_t class_, owner;
hcl_ooi_t ivaroff; hcl_ooi_t ivaroff;
int x; int x;
HCL_ASSERT (hcl, HCL_IS_SYMBOL(hcl, msg)); HCL_ASSERT (hcl, HCL_IS_SYMBOL(hcl, msg));
/* ============================= */
/* TODO: implement methods cache */ /* TODO: implement methods cache */
/* ============================= */
if (HCL_IS_CLASS(hcl, rcv)) if (HCL_IS_CLASS(hcl, rcv))
{ {
mth = find_cmethod_noseterr(hcl, (hcl_oop_class_t)rcv, msg); class_ = (hcl_oop_class_t)rcv;
mth_blk = find_cmethod_noseterr(hcl, class_, msg, &owner);
} }
else else
{ {
HCL_ASSERT (hcl, HCL_IS_INSTANCE(hcl, rcv)); HCL_ASSERT (hcl, HCL_IS_INSTANCE(hcl, rcv));
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, rcv->_class)); HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, rcv->_class));
mth = find_imethod_noseterr(hcl, (hcl_oop_class_t)rcv->_class, msg, &ivaroff); class_ = (hcl_oop_class_t)rcv->_class;
mth_blk = find_imethod_noseterr(hcl, class_, msg, &ivaroff, &owner);
} }
if (!mth) if (!mth_blk)
{ {
hcl_seterrbfmt (hcl, HCL_ENOENT, "'%.*js' not found in the %O", HCL_OBJ_GET_SIZE(msg), HCL_OBJ_GET_CHAR_SLOT(msg), rcv->_class); hcl_seterrbfmt (hcl, HCL_ENOENT, "'%.*js' not found in %O", HCL_OBJ_GET_SIZE(msg), HCL_OBJ_GET_CHAR_SLOT(msg), class_);
return -1; return -1;
} }
x = __activate_block(hcl, mth, nargs, 0 /* TODO: not always 0, support nrvars */, 1, ivaroff, &newctx); x = __activate_block(hcl, mth_blk, nargs, 0 /* TODO: not always 0, support nrvars */, 1, ivaroff, &newctx);
if (HCL_UNLIKELY(x <= -1)) return -1; if (HCL_UNLIKELY(x <= -1)) return -1;
/* update the method owner field of the new context created */
newctx->owner = owner;
SWITCH_ACTIVE_CONTEXT (hcl, newctx); SWITCH_ACTIVE_CONTEXT (hcl, newctx);
return 0; return 0;
} }
@ -2570,7 +2564,6 @@ static int start_initial_process_and_context (hcl_t* hcl, hcl_ooi_t initial_ip,
ctx->ip = HCL_SMOOI_TO_OOP(initial_ip); ctx->ip = HCL_SMOOI_TO_OOP(initial_ip);
ctx->req_nrets = HCL_SMOOI_TO_OOP(1); ctx->req_nrets = HCL_SMOOI_TO_OOP(1);
ctx->tmpr_mask = HCL_SMOOI_TO_OOP(tmpr_mask); ctx->tmpr_mask = HCL_SMOOI_TO_OOP(tmpr_mask);
ctx->origin = ctx; /* the origin of the initial context is itself as this is created over the initial function */
ctx->home = hcl->initial_function->home; /* this should be nil */ ctx->home = hcl->initial_function->home; /* this should be nil */
ctx->sender = (hcl_oop_context_t)hcl->_nil; ctx->sender = (hcl_oop_context_t)hcl->_nil;
ctx->base = hcl->initial_function; ctx->base = hcl->initial_function;
@ -3087,66 +3080,62 @@ static int execute (hcl_t* hcl)
{ {
/* ------------------------------------------------- */ /* ------------------------------------------------- */
case HCL_CODE_PUSH_INSTVAR_X: case HCL_CODE_PUSH_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto push_instvar; goto push_ivar;
case HCL_CODE_PUSH_INSTVAR_0: case HCL_CODE_PUSH_IVAR_0:
case HCL_CODE_PUSH_INSTVAR_1: case HCL_CODE_PUSH_IVAR_1:
case HCL_CODE_PUSH_INSTVAR_2: case HCL_CODE_PUSH_IVAR_2:
case HCL_CODE_PUSH_INSTVAR_3: case HCL_CODE_PUSH_IVAR_3:
case HCL_CODE_PUSH_INSTVAR_4: case HCL_CODE_PUSH_IVAR_4:
case HCL_CODE_PUSH_INSTVAR_5: case HCL_CODE_PUSH_IVAR_5:
case HCL_CODE_PUSH_INSTVAR_6: case HCL_CODE_PUSH_IVAR_6:
case HCL_CODE_PUSH_INSTVAR_7: case HCL_CODE_PUSH_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
push_instvar: push_ivar:
LOG_INST_2 (hcl, "push_instvar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff)); LOG_INST_2 (hcl, "push_ivar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff));
HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP); HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP);
//HCL_STACK_PUSH (hcl, ((hcl_oop_oop_t)hcl->active_context->origin->receiver)->slot[b1]);
b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff); b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff);
HCL_STACK_PUSH (hcl, ((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1]); HCL_STACK_PUSH (hcl, ((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1]);
break; break;
/* ------------------------------------------------- */ /* ------------------------------------------------- */
case HCL_CODE_STORE_INTO_INSTVAR_X: case HCL_CODE_STORE_INTO_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto store_instvar; goto store_instvar;
case HCL_CODE_STORE_INTO_INSTVAR_0: case HCL_CODE_STORE_INTO_IVAR_0:
case HCL_CODE_STORE_INTO_INSTVAR_1: case HCL_CODE_STORE_INTO_IVAR_1:
case HCL_CODE_STORE_INTO_INSTVAR_2: case HCL_CODE_STORE_INTO_IVAR_2:
case HCL_CODE_STORE_INTO_INSTVAR_3: case HCL_CODE_STORE_INTO_IVAR_3:
case HCL_CODE_STORE_INTO_INSTVAR_4: case HCL_CODE_STORE_INTO_IVAR_4:
case HCL_CODE_STORE_INTO_INSTVAR_5: case HCL_CODE_STORE_INTO_IVAR_5:
case HCL_CODE_STORE_INTO_INSTVAR_6: case HCL_CODE_STORE_INTO_IVAR_6:
case HCL_CODE_STORE_INTO_INSTVAR_7: case HCL_CODE_STORE_INTO_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
store_instvar: store_instvar:
LOG_INST_2 (hcl, "store_into_instvar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff)); LOG_INST_2 (hcl, "store_into_ivar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff));
HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP); HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP);
//((hcl_oop_oop_t)hcl->active_context->origin->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl);
b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff); b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff);
((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl); ((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl);
break; break;
/* ------------------------------------------------- */ /* ------------------------------------------------- */
case HCL_CODE_POP_INTO_INSTVAR_X: case HCL_CODE_POP_INTO_IVAR_X:
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
goto pop_into_instvar; goto pop_into_ivar;
case HCL_CODE_POP_INTO_INSTVAR_0: case HCL_CODE_POP_INTO_IVAR_0:
case HCL_CODE_POP_INTO_INSTVAR_1: case HCL_CODE_POP_INTO_IVAR_1:
case HCL_CODE_POP_INTO_INSTVAR_2: case HCL_CODE_POP_INTO_IVAR_2:
case HCL_CODE_POP_INTO_INSTVAR_3: case HCL_CODE_POP_INTO_IVAR_3:
case HCL_CODE_POP_INTO_INSTVAR_4: case HCL_CODE_POP_INTO_IVAR_4:
case HCL_CODE_POP_INTO_INSTVAR_5: case HCL_CODE_POP_INTO_IVAR_5:
case HCL_CODE_POP_INTO_INSTVAR_6: case HCL_CODE_POP_INTO_IVAR_6:
case HCL_CODE_POP_INTO_INSTVAR_7: case HCL_CODE_POP_INTO_IVAR_7:
b1 = bcode & 0x7; /* low 3 bits */ b1 = bcode & 0x7; /* low 3 bits */
pop_into_instvar: pop_into_ivar:
LOG_INST_2 (hcl, "pop_into_instvar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff)); LOG_INST_2 (hcl, "pop_into_ivar %zu ; [%zd]", b1, HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff));
HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP); HCL_ASSERT (hcl, HCL_OBJ_GET_FLAGS_TYPE(hcl->active_context->receiver) == HCL_OBJ_TYPE_OOP);
//((hcl_oop_oop_t)hcl->active_context->origin->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl);
b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff); b1 += HCL_OOP_TO_SMOOI(hcl->active_context->home->ivaroff);
((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl); ((hcl_oop_oop_t)hcl->active_context->receiver)->slot[b1] = HCL_STACK_GETTOP(hcl);
HCL_STACK_POP (hcl); HCL_STACK_POP (hcl);
@ -3890,22 +3879,22 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
/* access the class variables in the initialization context. /* access the class variables in the initialization context.
* the class object is at the class stack top */ * the class object is at the class stack top */
case HCL_CODE_PUSH_CLSVAR_I_X: case HCL_CODE_PUSH_CVAR_I_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "push_clsvar_i %zu", b1); LOG_INST_1 (hcl, "push_cvar_i %zu", b1);
HCL_CLSTACK_FETCH_TOP_TO(hcl, t); HCL_CLSTACK_FETCH_TOP_TO(hcl, t);
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, t)); HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, t));
HCL_STACK_PUSH (hcl, ((hcl_oop_class_t)t)->cvar[b1]); HCL_STACK_PUSH (hcl, ((hcl_oop_class_t)t)->cvar[b1]);
break; break;
} }
case HCL_CODE_STORE_INTO_CLSVAR_I_X: case HCL_CODE_STORE_INTO_CVAR_I_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "store_into_clsvar_i %zu", b1); LOG_INST_1 (hcl, "store_into_cvar_i %zu", b1);
if (HCL_CLSTACK_IS_EMPTY(hcl)) if (HCL_CLSTACK_IS_EMPTY(hcl))
{ {
hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "empty class stack"); hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "empty class stack");
@ -3918,11 +3907,11 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
break; break;
} }
case HCL_CODE_POP_INTO_CLSVAR_I_X: case HCL_CODE_POP_INTO_CVAR_I_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "pop_into_clsvar_i %zu", b1); LOG_INST_1 (hcl, "pop_into_cvar_i %zu", b1);
if (HCL_CLSTACK_IS_EMPTY(hcl)) if (HCL_CLSTACK_IS_EMPTY(hcl))
{ {
hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "empty class stack"); hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "empty class stack");
@ -3938,60 +3927,53 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
/* access the class variables in the instance method context.
* the receiver's class is accessed. */ /* access class variables referenced in a method context.
case HCL_CODE_PUSH_CLSVAR_M_X: * the class variables slots in the owning class of the method that triggerred the current active context */
case HCL_CODE_PUSH_CVAR_M_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "push_clsvar_m %zu", b1); LOG_INST_1 (hcl, "push_cvar_m %zu", b1);
//t = (hcl_oop_oop_t)hcl->active_context->origin->receiver; t = hcl->active_context->owner;
t = hcl->active_context->receiver; if (HCL_UNLIKELY(!HCL_IS_CLASS(hcl, t)))
if (!HCL_IS_INSTANCE(hcl, t))
{ {
hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "non-instance receiver"); /* this is an internal error or the bytecodes are compromised */
/* TODO: do throw??? instead */ hcl_seterrbfmt (hcl, HCL_EINTERN, "non-class owner in class variable access");
goto oops_with_errmsg_supplement; goto oops_with_errmsg_supplement;
} }
t = HCL_OBJ_GET_CLASS(t);
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, t));
HCL_STACK_PUSH (hcl, ((hcl_oop_class_t)t)->cvar[b1]); HCL_STACK_PUSH (hcl, ((hcl_oop_class_t)t)->cvar[b1]);
break; break;
} }
case HCL_CODE_STORE_INTO_CLSVAR_M_X: case HCL_CODE_STORE_INTO_CVAR_M_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "store_into_clsvar_m %zu", b1); LOG_INST_1 (hcl, "store_into_cvar_m %zu", b1);
//t = (hcl_oop_oop_t)hcl->active_context->origin->receiver; t = hcl->active_context->owner;
t = hcl->active_context->receiver; if (HCL_UNLIKELY(!HCL_IS_CLASS(hcl, t)))
if (!HCL_IS_INSTANCE(hcl, t))
{ {
hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "non-instance receiver"); /* this is an internal error or the bytecodes are compromised */
/* TODO: do throw??? instead */ hcl_seterrbfmt (hcl, HCL_EINTERN, "non-class owner in class variable access");
goto oops_with_errmsg_supplement; goto oops_with_errmsg_supplement;
} }
t = HCL_OBJ_GET_CLASS(t);
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, t));
((hcl_oop_class_t)t)->cvar[b1] = HCL_STACK_GETTOP(hcl); ((hcl_oop_class_t)t)->cvar[b1] = HCL_STACK_GETTOP(hcl);
break; break;
} }
case HCL_CODE_POP_INTO_CLSVAR_M_X: case HCL_CODE_POP_INTO_CVAR_M_X:
{ {
hcl_oop_t t; hcl_oop_t t;
FETCH_PARAM_CODE_TO (hcl, b1); FETCH_PARAM_CODE_TO (hcl, b1);
LOG_INST_1 (hcl, "pop_into_clsvar_m %zu", b1); LOG_INST_1 (hcl, "pop_into_cvar_m %zu", b1);
//t = (hcl_oop_oop_t)hcl->active_context->origin->receiver; t = hcl->active_context->owner;
t = hcl->active_context->receiver; if (HCL_UNLIKELY(!HCL_IS_CLASS(hcl, t)))
if (!HCL_IS_INSTANCE(hcl, t))
{ {
hcl_seterrbfmt (hcl, HCL_ESTKUNDFLW, "non-instance receiver"); /* this is an internal error or the bytecodes are compromised */
hcl_seterrbfmt (hcl, HCL_EINTERN, "non-class owner in class variable access");
goto oops_with_errmsg_supplement; goto oops_with_errmsg_supplement;
} }
t = HCL_OBJ_GET_CLASS(t);
HCL_ASSERT (hcl, HCL_IS_CLASS(hcl, t));
((hcl_oop_class_t)t)->cvar[b1] = HCL_STACK_GETTOP(hcl); ((hcl_oop_class_t)t)->cvar[b1] = HCL_STACK_GETTOP(hcl);
HCL_STACK_POP (hcl); HCL_STACK_POP (hcl);
break; break;
@ -4001,7 +3983,6 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
case HCL_CODE_PUSH_RECEIVER: /* push self or super */ case HCL_CODE_PUSH_RECEIVER: /* push self or super */
LOG_INST_0 (hcl, "push_receiver"); LOG_INST_0 (hcl, "push_receiver");
//HCL_STACK_PUSH (hcl, hcl->active_context->origin->receiver);
HCL_STACK_PUSH (hcl, hcl->active_context->receiver); HCL_STACK_PUSH (hcl, hcl->active_context->receiver);
break; break;
@ -4329,7 +4310,6 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1)
case HCL_CODE_RETURN_RECEIVER: case HCL_CODE_RETURN_RECEIVER:
LOG_INST_0 (hcl, "return_receiver"); LOG_INST_0 (hcl, "return_receiver");
//return_value = hcl->active_context->origin->receiver;
return_value = hcl->active_context->receiver; return_value = hcl->active_context->receiver;
handle_return: handle_return:

View File

@ -628,11 +628,11 @@ struct hcl_compiler_t
SHORT INSTRUCTION CODE LONG INSTRUCTION CODE SHORT INSTRUCTION CODE LONG INSTRUCTION CODE
---------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------
v v v v
0-3 0000 00XX STORE_INTO_INSTVAR 128 1000 0000 XXXXXXXX STORE_INTO_INSTVAR_X (bit 4 off, bit 3 off) 0-3 0000 00XX STORE_INTO_INSTVAR 128 1000 0000 XXXXXXXX STORE_INTO_IVAR_X (bit 4 off, bit 3 off)
4-7 0000 01XX STORE_INTO_INSTVAR 4-7 0000 01XX STORE_INTO_INSTVAR
8-11 0000 10XX POP_INTO_INSTVAR 136 1000 1000 XXXXXXXX POP_INTO_INSTVAR_X (bit 4 off, bit 3 on) 8-11 0000 10XX POP_INTO_INSTVAR 136 1000 1000 XXXXXXXX POP_INTO_IVAR_X (bit 4 off, bit 3 on)
12-15 0000 11XX POP_INTO_INSTVAR 12-15 0000 11XX POP_INTO_INSTVAR
16-19 0001 00XX PUSH_INSTVAR 144 1001 0000 XXXXXXXX PUSH_INSTVAR_X (bit 4 on) 16-19 0001 00XX PUSH_INSTVAR 144 1001 0000 XXXXXXXX PUSH_IVAR_X (bit 4 on)
20-23 0001 01XX PUSH_INSTVAR 20-23 0001 01XX PUSH_INSTVAR
v v v v
@ -683,13 +683,13 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C
116-119 0111 01XX YYYYYYYY SEND_TO_SUPER 244 1111 0100 XXXXXXXX YYYYYYYY SEND_TO_SUPER_X (bit 2 on) 116-119 0111 01XX YYYYYYYY SEND_TO_SUPER 244 1111 0100 XXXXXXXX YYYYYYYY SEND_TO_SUPER_X (bit 2 on)
# XXX args, YYYYYYYY message # XXX args, YYYYYYYY message
120 0111 1000 YYYYYYYY PUSH_CLSVAR_I_X 120 0111 1000 YYYYYYYY PUSH_CVAR_I_X
121 0111 1001 YYYYYYYY STORE_INTO_CLSVAR_I_X 121 0111 1001 YYYYYYYY STORE_INTO_CVAR_I_X
122 0111 1010 YYYYYYYY POP_INTO_CLSVAR_I_X 122 0111 1010 YYYYYYYY POP_INTO_CVAR_I_X
123 0111 1011 YYYYYYYY PUSH_CLSVAR_M_X 123 0111 1011 YYYYYYYY PUSH_CVAR_M_X
124 0111 1100 YYYYYYYY STORE_INTO_CLSVAR_M_X 124 0111 1100 YYYYYYYY STORE_INTO_CVAR_M_X
125 0111 1101 YYYYYYYY POP_INTO_CLSVAR_M_X 125 0111 1101 YYYYYYYY POP_INTO_CVAR_M_X
126 0111 1110 UNUSED 126 0111 1110 UNUSED
127 0111 1111 UNUSED 127 0111 1111 UNUSED
@ -702,35 +702,35 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C
enum hcl_bcode_t enum hcl_bcode_t
{ {
HCL_CODE_STORE_INTO_INSTVAR_0 = 0x00, HCL_CODE_STORE_INTO_IVAR_0 = 0x00,
HCL_CODE_STORE_INTO_INSTVAR_1 = 0x01, HCL_CODE_STORE_INTO_IVAR_1 = 0x01,
HCL_CODE_STORE_INTO_INSTVAR_2 = 0x02, HCL_CODE_STORE_INTO_IVAR_2 = 0x02,
HCL_CODE_STORE_INTO_INSTVAR_3 = 0x03, HCL_CODE_STORE_INTO_IVAR_3 = 0x03,
HCL_CODE_STORE_INTO_INSTVAR_4 = 0x04, HCL_CODE_STORE_INTO_IVAR_4 = 0x04,
HCL_CODE_STORE_INTO_INSTVAR_5 = 0x05, HCL_CODE_STORE_INTO_IVAR_5 = 0x05,
HCL_CODE_STORE_INTO_INSTVAR_6 = 0x06, HCL_CODE_STORE_INTO_IVAR_6 = 0x06,
HCL_CODE_STORE_INTO_INSTVAR_7 = 0x07, HCL_CODE_STORE_INTO_IVAR_7 = 0x07,
HCL_CODE_POP_INTO_INSTVAR_0 = 0x08, HCL_CODE_POP_INTO_IVAR_0 = 0x08,
HCL_CODE_POP_INTO_INSTVAR_1 = 0x09, HCL_CODE_POP_INTO_IVAR_1 = 0x09,
HCL_CODE_POP_INTO_INSTVAR_2 = 0x0A, HCL_CODE_POP_INTO_IVAR_2 = 0x0A,
HCL_CODE_POP_INTO_INSTVAR_3 = 0x0B, HCL_CODE_POP_INTO_IVAR_3 = 0x0B,
HCL_CODE_POP_INTO_INSTVAR_4 = 0x0C, HCL_CODE_POP_INTO_IVAR_4 = 0x0C,
HCL_CODE_POP_INTO_INSTVAR_5 = 0x0D, HCL_CODE_POP_INTO_IVAR_5 = 0x0D,
HCL_CODE_POP_INTO_INSTVAR_6 = 0x0E, HCL_CODE_POP_INTO_IVAR_6 = 0x0E,
HCL_CODE_POP_INTO_INSTVAR_7 = 0x0F, HCL_CODE_POP_INTO_IVAR_7 = 0x0F,
HCL_CODE_PUSH_INSTVAR_0 = 0x10, HCL_CODE_PUSH_IVAR_0 = 0x10,
HCL_CODE_PUSH_INSTVAR_1 = 0x11, HCL_CODE_PUSH_IVAR_1 = 0x11,
HCL_CODE_PUSH_INSTVAR_2 = 0x12, HCL_CODE_PUSH_IVAR_2 = 0x12,
HCL_CODE_PUSH_INSTVAR_3 = 0x13, HCL_CODE_PUSH_IVAR_3 = 0x13,
HCL_CODE_PUSH_INSTVAR_4 = 0x14, HCL_CODE_PUSH_IVAR_4 = 0x14,
HCL_CODE_PUSH_INSTVAR_5 = 0x15, HCL_CODE_PUSH_IVAR_5 = 0x15,
HCL_CODE_PUSH_INSTVAR_6 = 0x16, HCL_CODE_PUSH_IVAR_6 = 0x16,
HCL_CODE_PUSH_INSTVAR_7 = 0x17, HCL_CODE_PUSH_IVAR_7 = 0x17,
HCL_CODE_PUSH_TEMPVAR_0 = 0x18, HCL_CODE_PUSH_TEMPVAR_0 = 0x18,
HCL_CODE_PUSH_TEMPVAR_1 = 0x19, HCL_CODE_PUSH_TEMPVAR_1 = 0x19,
@ -846,16 +846,16 @@ enum hcl_bcode_t
HCL_CODE_SEND_TO_SUPER_2 = 0x76, /* 118 */ HCL_CODE_SEND_TO_SUPER_2 = 0x76, /* 118 */
HCL_CODE_SEND_TO_SUPER_3 = 0x77, /* 119 */ HCL_CODE_SEND_TO_SUPER_3 = 0x77, /* 119 */
HCL_CODE_PUSH_CLSVAR_I_X = 0x78, /* 120 */ HCL_CODE_PUSH_CVAR_I_X = 0x78, /* 120 */
HCL_CODE_STORE_INTO_CLSVAR_I_X = 0x79, /* 121 */ HCL_CODE_STORE_INTO_CVAR_I_X = 0x79, /* 121 */
HCL_CODE_POP_INTO_CLSVAR_I_X = 0x7A, /* 122 */ HCL_CODE_POP_INTO_CVAR_I_X = 0x7A, /* 122 */
HCL_CODE_PUSH_CLSVAR_M_X = 0x7B, /* 123 */ HCL_CODE_PUSH_CVAR_M_X = 0x7B, /* 123 */
HCL_CODE_STORE_INTO_CLSVAR_M_X = 0x7C, /* 124 */ HCL_CODE_STORE_INTO_CVAR_M_X = 0x7C, /* 124 */
HCL_CODE_POP_INTO_CLSVAR_M_X = 0x7D, /* 125 */ HCL_CODE_POP_INTO_CVAR_M_X = 0x7D, /* 125 */
/* UNUSED 0x7E - 0x7F */ /* UNUSED 0x7E - 0x7F */
HCL_CODE_STORE_INTO_INSTVAR_X = 0x80, /* 128 */ HCL_CODE_STORE_INTO_IVAR_X = 0x80, /* 128 */
HCL_CODE_PUSH_RECEIVER = 0x81, /* 129 */ HCL_CODE_PUSH_RECEIVER = 0x81, /* 129 */
HCL_CODE_PUSH_NIL = 0x82, /* 130 */ HCL_CODE_PUSH_NIL = 0x82, /* 130 */
@ -865,14 +865,14 @@ enum hcl_bcode_t
HCL_CODE_PUSH_PROCESS = 0x86, /* 134 */ HCL_CODE_PUSH_PROCESS = 0x86, /* 134 */
/* UNUSED 135 */ /* UNUSED 135 */
HCL_CODE_POP_INTO_INSTVAR_X = 0x88, /* 136 ## */ HCL_CODE_POP_INTO_IVAR_X = 0x88, /* 136 ## */
HCL_CODE_PUSH_NEGONE = 0x89, /* 137 */ HCL_CODE_PUSH_NEGONE = 0x89, /* 137 */
HCL_CODE_PUSH_ZERO = 0x8A, /* 138 */ HCL_CODE_PUSH_ZERO = 0x8A, /* 138 */
HCL_CODE_PUSH_ONE = 0x8B, /* 139 */ HCL_CODE_PUSH_ONE = 0x8B, /* 139 */
HCL_CODE_PUSH_TWO = 0x8C, /* 140 */ HCL_CODE_PUSH_TWO = 0x8C, /* 140 */
HCL_CODE_PUSH_INSTVAR_X = 0x90, /* 144 ## */ HCL_CODE_PUSH_IVAR_X = 0x90, /* 144 ## */
HCL_CODE_PUSH_TEMPVAR_X = 0x98, /* 152 ## */ HCL_CODE_PUSH_TEMPVAR_X = 0x98, /* 152 ## */
HCL_CODE_STORE_INTO_TEMPVAR_X = 0xA0, /* 160 ## */ HCL_CODE_STORE_INTO_TEMPVAR_X = 0xA0, /* 160 ## */
HCL_CODE_POP_INTO_TEMPVAR_X = 0xA8, /* 168 ## */ HCL_CODE_POP_INTO_TEMPVAR_X = 0xA8, /* 168 ## */

View File

@ -630,26 +630,6 @@ struct hcl_context_t
* the home context of the activating block context points to. */ * the home context of the activating block context points to. */
hcl_oop_function_t base; /* function */ hcl_oop_function_t base; /* function */
/* TODO: get rid of origin. or rename base to origin??? with the base pointing to
* the originating function object and a separate receiver pointer,
* the originating function context isn't that useful.... */
/* a function context is created with itself in this field. The function
* context creation is based on a function object(initial or lambda/defun).
*
* a block context is created over a block object. it stores
* a function context that points to itself in this field. a block context
* points to the function context where it is created. another block context
* created within the block context also points to the same function context.
*
* take note of the following points:
* ctx->origin: function context
* ctx->origin->base: actual function containing byte codes pertaining to ctx.
*
* a base of a block context is a block object but ctx->origin is guaranteed to be
* a function context. so its base is also a function object all the time.
*/
hcl_oop_context_t origin;
/* it points to the active context at the moment when /* it points to the active context at the moment when
* this context object has been activated. a new method context * this context object has been activated. a new method context
* is activated as a result of normal message sending and a block * is activated as a result of normal message sending and a block
@ -678,11 +658,14 @@ struct hcl_context_t
* at index 3. if the class of the instance has 4 instance variables in the * at index 3. if the class of the instance has 4 instance variables in the
* superclass side, the method context activated has 4 in thie field. * superclass side, the method context activated has 4 in thie field.
* therefore, the instruction accesses the instance variable slot at index 7. * therefore, the instruction accesses the instance variable slot at index 7.
* push_instvar 3 * push_ivar 3
* the debug output shows this instruction as "push_instvar 3; [4]" * the debug output shows this instruction as "push_ivar 3; [4]"
*/ */
hcl_oop_t ivaroff; hcl_oop_t ivaroff;
/* method owner if this context is created of a message send. nil otherwise */
hcl_oop_t owner; /* class(hcl_oop_class_t) or nil */
/* variable indexed part */ /* variable indexed part */
hcl_oop_t slot[1]; /* arguments, return variables, local variables, other arguments, etc */ hcl_oop_t slot[1]; /* arguments, return variables, local variables, other arguments, etc */
}; };

View File

@ -439,7 +439,7 @@ hcl_oop_t hcl_instantiate (hcl_t* hcl, hcl_oop_class_t _class, const void* vptr,
if (oop && vptr && vlen > 0) if (oop && vptr && vlen > 0)
{ {
hcl_oop_oop_t hdr = (hcl_oop_oop_t)oop; hcl_oop_oop_t hdr = (hcl_oop_oop_t)oop;
HCL_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * HCL_SIZEOF(hcl_oop_t)); HCL_MEMCPY (&hdr->slot[named_ivar], vptr, vlen * HCL_SIZEOF(hcl_oop_t));
} }
For the above code to work, it should protect the elements of For the above code to work, it should protect the elements of