Change assignment behavior to update existing table entries.

This commit is contained in:
Danila Fedorin 2018-08-10 19:56:46 -07:00
parent d7ef8e236d
commit 20fb078ad2
1 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,18 @@
#include "value.h"
#include "libabacus.h"
libab_result _update_entry(libab_table* table, const char* name, libab_ref* value) {
libab_result result = LIBAB_SUCCESS;
libab_table_entry* value_entry = libab_table_search_entry_value(table, name);
if(value_entry) {
libab_ref_free(&value_entry->data_u.value);
libab_ref_copy(value, &value_entry->data_u.value);
} else {
result = libab_put_table_value(table, name, value);
}
return result;
}
libab_result _behavior_assign(libab* ab, libab_ref* scope,
libab_tree* left, libab_tree* right,
libab_ref* into) {
@ -12,7 +24,7 @@ libab_result _behavior_assign(libab* ab, libab_ref* scope,
if(left->variant == TREE_ID) {
result = libab_run_tree_scoped(ab, right, scope, into);
if(result == LIBAB_SUCCESS) {
result = libab_put_table_value(libab_ref_get(scope), left->string_value, into);
result = _update_entry(libab_ref_get(scope), left->string_value, into);
}
if(result != LIBAB_SUCCESS) {