1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-16 18:29:56 +00:00

Replace map of vars with single element arrays

This commit is contained in:
Calvin Rose 2017-06-25 16:52:15 -04:00
parent 29a39c47b0
commit 1f8b671488
3 changed files with 7 additions and 11 deletions

View File

@ -529,9 +529,9 @@ static Slot compile_symbol(GstCompiler *c, FormOptions opts, GstValue sym) {
const GstValue *tup;
Gst *vm= c->vm;
GstValue *t = gst_tuple_begin(vm, 3);
t[0] = gst_string_cv(vm, "get"); /* Todo - replace with ref ro actual cfunc */
t[0] = gst_string_cv(vm, "get"); /* Todo - replace with actual cfunc or bytecode */
t[1] = quote(vm, lit);
t[2] = quote(vm, sym);
t[2] = gst_wrap_integer(0);
tup = gst_tuple_end(vm, t);
return compile_value(c, opts, gst_wrap_tuple(tup));
} else if (level > 0) {
@ -610,7 +610,7 @@ static Slot compile_assign(GstCompiler *c, FormOptions opts, GstValue left, GstV
GstValue *t = gst_tuple_begin(vm, 4);
t[0] = gst_string_cv(vm, "set!"); /* Todo - replace with ref ro actual cfunc */
t[1] = quote(vm, lit);
t[2] = quote(vm, left);
t[2] = gst_wrap_integer(0);
t[3] = right;
tup = gst_tuple_end(vm, t);
subOpts.resultUnused = 1;

View File

@ -274,10 +274,6 @@ GstTable *gst_env_meta(Gst *vm, GstTable *env) {
return gst_env_inttab(vm, env, GST_ENV_METADATA);
}
GstTable *gst_env_vars(Gst *vm, GstTable *env) {
return gst_env_inttab(vm, env, GST_ENV_VARS);
}
/* Add many global variables and bind to nil */
static void mergenils(Gst *vm, GstTable *destEnv, GstTable *nils) {
const GstValue *data = nils->data;
@ -347,9 +343,10 @@ void gst_env_putc(Gst *vm, GstTable *env, const char *key, GstValue value) {
void gst_env_putvar(Gst *vm, GstTable *env, GstValue key, GstValue value) {
GstTable *meta = gst_env_meta(vm, env);
GstTable *newmeta = gst_table(vm, 4);
GstTable *vars = gst_env_vars(vm, env);
gst_table_put(vm, vars, key, value);
gst_table_put(vm, env, key, gst_wrap_table(vars));
GstArray *ref = gst_array(vm, 1);
ref->count = 1;
ref->data[0] = value;
gst_table_put(vm, env, key, gst_wrap_array(ref));
gst_table_put(vm, newmeta, gst_string_cv(vm, "mutable"), gst_wrap_boolean(1));
gst_table_put(vm, meta, key, gst_wrap_table(newmeta));
}

View File

@ -645,7 +645,6 @@ GstInteger gst_endrange(GstInteger raw, uint32_t len);
void gst_env_merge(Gst *vm, GstTable *destEnv, GstTable *srcEnv);
GstTable *gst_env_nils(Gst *vm, GstTable *env);
GstTable *gst_env_meta(Gst *vm, GstTable *env);
GstTable *gst_env_vars(Gst *vm, GstTable *env);
void gst_env_put(Gst *vm, GstTable *env, GstValue key, GstValue value);
void gst_env_putc(Gst *vm, GstTable *env, const char *key, GstValue value);
void gst_env_putvar(Gst *vm, GstTable *env, GstValue key, GstValue value);