summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2010-03-17 15:35:38 +0100
committerJohannes Weiner <hannes@cmpxchg.org>2010-03-17 15:35:38 +0100
commitc76df536143f1b2c7846bb335a176aaaf61f7e48 (patch)
treeac32a31ec46db8985ee3fde791cb798d33eff84f
parentb485d31f858bc8fcc64badd574c2525489c5e97b (diff)
core: evaluate (variable) value in own context
For example, (variable foo (load bar)) should not bind `bar' globally but rather local within the variable definition. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--sheep/core.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sheep/core.c b/sheep/core.c
index 2239285..407f08e 100644
--- a/sheep/core.c
+++ b/sheep/core.c
@@ -157,15 +157,21 @@ static int compile_variable(struct sheep_compile *compile,
struct sheep_function *function,
struct sheep_context *context, struct sheep_list *args)
{
+ SHEEP_DEFINE_MAP(env);
+ struct sheep_context block = {
+ .env = &env,
+ .parent = context,
+ };
unsigned int slot;
const char *name;
sheep_t value;
+ int ret = -1;
if (sheep_parse(compile, args, "se", &name, &value))
- return -1;
+ goto out;
- if (sheep_compile_object(compile, function, context, value))
- return -1;
+ if (sheep_compile_object(compile, function, &block, value))
+ goto out;
sheep_emit(&function->code, SHEEP_DUP, 0);
@@ -177,7 +183,10 @@ static int compile_variable(struct sheep_compile *compile,
sheep_emit(&function->code, SHEEP_SET_GLOBAL, slot);
}
sheep_map_set(context->env, name, (void *)(unsigned long)slot);
- return 0;
+ ret = 0;
+out:
+ sheep_map_drain(&env);
+ return ret;
}
/* (function name? (arg*) expr*) */