void migrate_value(Value* value, Migration* migration) { if (is_ref(value)) { set_term_ref(value, migrate_term_pointer(as_term_ref(value), migration)); } else if (is_block(value)) { set_block(value, migrate_block_pointer(as_block(value), migration)); } else if (is_list_based(value)) { migrate_list_value(value, migration); } else if (is_hashtable(value)) { Value oldHashtable; move(value, &oldHashtable); set_hashtable(value); Value* hashtable = value; for (int i=0; i < hashtable_slot_count(&oldHashtable); i++) { Value* oldKey = hashtable_key_by_index(&oldHashtable, i); if (oldKey == NULL || is_null(oldKey)) continue; Value* oldValue = hashtable_value_by_index(&oldHashtable, i); Value key; copy(oldKey, &key); migrate_value(&key, migration); Value* newValue = hashtable_insert(hashtable, &key); copy(oldValue, newValue); migrate_value(newValue, migration); } } }
bool value_may_need_migration(Value* value, Migration* migration) { if (is_list_based(value)) return list_value_may_need_migration(value, migration); if (is_hashtable(value)) return true; // todo if (is_leaf_value(value)) return false; return true; }
void circa_load_file_in_memory(caWorld* world, Value* filename, Value* contents) { touch(&world->fileSources); for (int i=0; i < world->fileSources.length(); i++) { Value* fileSource = world->fileSources.index(i); if (is_hashtable(fileSource)) { Value entry; set_list(&entry, 2); entry.set_element_int(0, 0); copy(contents, entry.index(1)); move(&entry, hashtable_insert(fileSource, filename)); break; } } }
static bool file_source_is_map(Value* file_source) { return is_hashtable(file_source); }