Skip to content

Commit

Permalink
Add flag indicating HLL init status on CodeRef
Browse files Browse the repository at this point in the history
Add a value that indicates whether the statevar in the coderef has been
assigned a value by the HLL (flag set via extop on HLL side).

This change is being made to coincide with a Rakudo development
regarding statevar initialization.

See [RT#102994](https://rt.perl.org/Public/Bug/Display.html?id=102994)
  • Loading branch information
jstuder-gh committed Feb 18, 2018
1 parent c7774e3 commit 39655fd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/6model/reprs/MVMCode.c
Expand Up @@ -69,6 +69,7 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVMCode *code_obj = (MVMCode *)obj;
MVM_free(code_obj->body.state_vars);
MVM_free(code_obj->body.state_vars_is_hll_init);
}

static const MVMStorageSpec storage_spec = {
Expand Down
1 change: 1 addition & 0 deletions src/6model/reprs/MVMCode.h
Expand Up @@ -6,6 +6,7 @@ struct MVMCodeBody {
MVMObject *code_object;
MVMString *name;
MVMRegister *state_vars;
MVMuint8 *state_vars_is_hll_init;
MVMuint16 is_static;
MVMuint16 is_compiler_stub;
};
Expand Down
8 changes: 5 additions & 3 deletions src/core/frame.c
Expand Up @@ -568,6 +568,7 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
MVMRegister *env = static_frame->body.static_env;
MVMuint8 *flags = static_frame->body.static_env_flags;
MVMint64 numlex = static_frame->body.num_lexicals;
MVMCode *cref = (MVMCode *)frame->code_ref;
MVMRegister *state = NULL;
MVMint64 state_act = 0; /* 0 = none so far, 1 = first time, 2 = later */
MVMint64 i;
Expand All @@ -577,18 +578,19 @@ void MVM_frame_invoke(MVMThreadContext *tc, MVMStaticFrame *static_frame,
redo_state:
switch (state_act) {
case 0:
if (!frame->code_ref)
if (!cref)
MVM_exception_throw_adhoc(tc,
"Frame must have code-ref to have state variables");
state = ((MVMCode *)frame->code_ref)->body.state_vars;
state = cref->body.state_vars;
if (state) {
/* Already have state vars; pull them from this. */
state_act = 2;
}
else {
/* Allocate storage for state vars. */
state = (MVMRegister *)MVM_calloc(1, frame->static_info->body.env_size);
((MVMCode *)frame->code_ref)->body.state_vars = state;
cref->body.state_vars = state;
cref->body.state_vars_is_hll_init = (MVMuint8 *)MVM_calloc(1, numlex);
state_act = 1;

/* Note that this frame should run state init code. */
Expand Down

0 comments on commit 39655fd

Please sign in to comment.