Tree * duplicate_tree(const Tree * src) { if (!src) return NULL; return new_tree(duplicate_tree(src->left), duplicate_tree(src->right), src->val); }
struct Value for_each(struct Tree * ast, struct Tree_map * defined, struct Map * let_map){ struct Value array = execute(ast->children[0], defined, let_map); for(int i = 0; i < array.data.array->size; i++){ struct Value * item = array.data.array->values[i]; struct Value index = { .type = 'l', .data = { .ln=(long)i } }; struct Tree * function = duplicate_tree(ast->children[3]); populate_each_function(&ast->children[1]->content, &ast->children[2]->content, function, item, &index); execute(function, defined, let_map); } return array; }
struct Value execute_defined_func(struct Tree * ast, struct Tree_map * defined, struct Map * let_map, int idx){ struct Map * arguments = make_args_map(ast, defined, let_map, idx); struct Tree * populated_ast = populate_args(arguments, duplicate_tree(get_defined_body(defined->trees[idx]))); return execute(populated_ast, defined, let_map); }