Skip to content

Commit

Permalink
Implement decont_[ins].
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Feb 6, 2015
1 parent db78722 commit 6b4f3fc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/6model/containers.c
Expand Up @@ -199,3 +199,37 @@ void MVM_6model_containers_setup(MVMThreadContext *tc) {
MVM_6model_add_container_config(tc,
MVM_string_ascii_decode_nt(tc, tc->instance->VMString, "code_pair"), &ContainerConfigurer);
}

/* ***************************************************************************
* Native container/reference operations
* ***************************************************************************/

/* If it's a container, do a fetch_i. Otherwise, try to unbox the received
* value as a native integer. */
void MVM_6model_container_decont_i(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res) {
const MVMContainerSpec *cs = STABLE(cont)->container_spec;
if (cs && IS_CONCRETE(cont))
cs->fetch_i(tc, cont, res);
else
res->i64 = MVM_repr_get_int(tc, cont);
}

/* If it's a container, do a fetch_n. Otherwise, try to unbox the received
* value as a native number. */
void MVM_6model_container_decont_n(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res) {
const MVMContainerSpec *cs = STABLE(cont)->container_spec;
if (cs && IS_CONCRETE(cont))
cs->fetch_n(tc, cont, res);
else
res->n64 = MVM_repr_get_num(tc, cont);
}

/* If it's a container, do a fetch_s. Otherwise, try to unbox the received
* value as a native string. */
void MVM_6model_container_decont_s(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res) {
const MVMContainerSpec *cs = STABLE(cont)->container_spec;
if (cs && IS_CONCRETE(cont))
cs->fetch_s(tc, cont, res);
else
res->s = MVM_repr_get_str(tc, cont);
}
3 changes: 3 additions & 0 deletions src/6model/containers.h
Expand Up @@ -73,3 +73,6 @@ struct MVMContainerRegistry {
MVM_PUBLIC void MVM_6model_add_container_config(MVMThreadContext *tc, MVMString *name, const MVMContainerConfigurer *configurer);
const MVMContainerConfigurer * MVM_6model_get_container_config(MVMThreadContext *tc, MVMString *name);
void MVM_6model_containers_setup(MVMThreadContext *tc);
void MVM_6model_container_decont_i(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res);
void MVM_6model_container_decont_n(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res);
void MVM_6model_container_decont_s(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res);
28 changes: 24 additions & 4 deletions src/core/interp.c
Expand Up @@ -4338,12 +4338,32 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
OP(iscont_i):
OP(iscont_n):
OP(iscont_s):
MVM_exception_throw_adhoc(tc, "Native iscont ops NYI");
OP(assign_i):
OP(assign_n):
OP(assign_s):
OP(decont_i):
OP(decont_n):
OP(decont_s):
MVM_exception_throw_adhoc(tc, "Native assign ops NYI");
OP(decont_i): {
MVMObject *obj = GET_REG(cur_op, 2).o;
MVMRegister *r = &GET_REG(cur_op, 0);
cur_op += 4;
MVM_6model_container_decont_i(tc, obj, r);
goto NEXT;
}
OP(decont_n): {
MVMObject *obj = GET_REG(cur_op, 2).o;
MVMRegister *r = &GET_REG(cur_op, 0);
cur_op += 4;
MVM_6model_container_decont_n(tc, obj, r);
goto NEXT;
}
OP(decont_s): {
MVMObject *obj = GET_REG(cur_op, 2).o;
MVMRegister *r = &GET_REG(cur_op, 0);
cur_op += 4;
MVM_6model_container_decont_s(tc, obj, r);
goto NEXT;
}
OP(getregref_i):
OP(getregref_n):
OP(getregref_s):
Expand All @@ -4362,7 +4382,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
OP(getattrsref_i):
OP(getattrsref_n):
OP(getattrsref_s):
MVM_exception_throw_adhoc(tc, "Native reference ops NYI");
MVM_exception_throw_adhoc(tc, "Native reference taking ops NYI");
OP(sp_log):
if (tc->cur_frame->spesh_log_idx >= 0) {
MVM_ASSIGN_REF(tc, &(tc->cur_frame->static_info->common.header),
Expand Down

0 comments on commit 6b4f3fc

Please sign in to comment.