}
struct sn_interpreter_kv* sn_set_variable(struct sn_interpreter* sn, const char* name, struct sn_generic* gen) {
+ if(gen != NULL) gen->reference = true;
int i;
bool replaced = false;
bool global = true;
argbufmode = SN_TYPE_STRING;
} else if(c == '(') {
gn_stack[br] = malloc(sizeof(struct sn_generic));
+ gn_stack[br]->reference = false;
gn_stack[br]->type = SN_TYPE_TREE;
gn_stack[br]->tree = malloc(sizeof(struct sn_tree));
gn_stack[br]->tree->args = malloc(sizeof(struct sn_generic*));
if(t->args != NULL) {
int i;
for(i = 0; t->args[i] != NULL; i++) {
- sn_generic_free(sn, t->args[i]);
+ if(!t->args[i]->reference) sn_generic_free(sn, t->args[i]);
}
free(t->args);
}
struct sn_tree* tree;
bool used;
void* argvalue;
+ bool reference;
struct sn_generic* (*handler)(struct sn_interpreter* sn, int, struct sn_generic**);
};
sn->local_variables = old_kv;
}
return r;
+ } else if(strcmp(op->name, "discard") == 0) {
+ r->type = SN_TYPE_VOID;
+ int i;
+ for(i = 1; gen->tree->args[i] != NULL; i++){
+ sn_generic_free(sn, _sn_run(sn, gen->tree->args[i]));
+ }
+ return r;
}
bool called = false;
int j;
sn_print_to(stdout, rgen);
printf("\n");
}
+ if(rgen->type == SN_TYPE_VOID) free(rgen);
return 0;
}