Skip to content

Commit

Permalink
Create snek_globals in snek_pick_frame instead of snek_frame_lookup
Browse files Browse the repository at this point in the history
This seems cleaner as it creates the global frame precisely where it
is referenced.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed May 26, 2019
1 parent f5a02e5 commit 51d262a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions snek-frame.c
Expand Up @@ -19,8 +19,14 @@ snek_frame_t *snek_frame;

static snek_frame_t *snek_pick_frame(bool globals)
{
if (globals)
if (globals) {
if (!snek_globals) {
snek_globals = snek_alloc(sizeof (snek_frame_t));
snek_globals->prev = SNEK_OFFSET_NONE;
snek_globals->code = SNEK_OFFSET_NONE;
}
return snek_globals;
}
return snek_frame;
}

Expand Down Expand Up @@ -116,14 +122,7 @@ snek_frame_lookup(snek_id_t id, bool insert)
if (!snek_is_global(v->value))
return v;
}
if (insert && !snek_globals) {
snek_globals = snek_alloc(sizeof (snek_frame_t));
snek_globals->prev = SNEK_OFFSET_NONE;
snek_globals->code = SNEK_OFFSET_NONE;
}
if ((v = snek_variable_lookup(true, id, insert)))
return v;
return v;
return snek_variable_lookup(true, id, insert);
}

void
Expand Down

0 comments on commit 51d262a

Please sign in to comment.