value_t assembler_push_map_scope(assembler_t *assm, map_scope_o *scope) { TRY_SET(scope->map, new_heap_id_hash_map(assm->runtime, 8)); scope->super.vtable.lookup = (scope_lookup_m) map_scope_lookup; scope->outer = assembler_set_scope(assm, (scope_o*) scope); scope->assembler = assm; return success(); }
value_t build_fragment_entry_map(binding_context_t *context, value_t modules) { runtime_t *runtime = get_ambience_runtime(context->ambience); TRY_SET(context->fragment_entry_map, new_heap_id_hash_map(runtime, 16)); TRY(build_real_fragment_entries(context, modules)); TRY(build_synthetic_fragment_entries(context)); return context->fragment_entry_map; }
// Initialize serialization state. static value_t serialize_state_init(serialize_state_t *state, runtime_t *runtime, value_mapping_t *resolver, byte_buffer_t *buf) { state->buf = buf; state->object_offset = 0; state->runtime = runtime; state->resolver = resolver; TRY_SET(state->ref_map, new_heap_id_hash_map(runtime, 16)); return success(); }
static value_t init_empty_module_fragment(runtime_t *runtime, value_t fragment) { TRY_DEF(nspace, new_heap_namespace(runtime, nothing())); TRY_DEF(methodspace, new_heap_methodspace(runtime)); TRY_DEF(imports, new_heap_id_hash_map(runtime, 16)); set_module_fragment_namespace(fragment, nspace); set_module_fragment_methodspace(fragment, methodspace); set_module_fragment_imports(fragment, imports); return success(); }
value_t assembler_init(assembler_t *assm, runtime_t *runtime, value_t fragment, scope_o *scope) { CHECK_FALSE("no scope callback", scope == NULL); CHECK_FAMILY_OPT(ofModuleFragment, fragment); TRY(assembler_init_stripped_down(assm, runtime)); TRY_SET(assm->value_pool, new_heap_id_hash_map(runtime, 16)); assm->scope = scope; assm->fragment = fragment; return success(); }
TEST(plankton, map) { CREATE_RUNTIME(); value_t map = new_heap_id_hash_map(runtime, 16); check_plankton(runtime, map); for (size_t i = 0; i < 16; i++) { set_id_hash_map_at(runtime, map, new_integer(i), new_integer(5)); check_plankton(runtime, map); } DISPOSE_RUNTIME(); }
value_t build_bound_module(value_t ambience, value_t unbound_module) { runtime_t *runtime = get_ambience_runtime(ambience); binding_context_t context; binding_context_init(&context, ambience); TRY_SET(context.bound_module_map, new_heap_id_hash_map(runtime, 16)); TRY_DEF(modules, build_transitive_module_array(runtime, unbound_module)); TRY(build_fragment_entry_map(&context, modules)); TRY_DEF(schedule, build_binding_schedule(&context)); TRY(execute_binding_schedule(&context, schedule)); value_t path = get_unbound_module_path(unbound_module); value_t result = get_id_hash_map_at(context.bound_module_map, path); CHECK_FALSE("module missing", in_condition_cause(ccNotFound, result)); return result; }
value_t get_or_create_methodspace_selector_slice(runtime_t *runtime, value_t self, value_t selector) { value_t cache_ptr = get_methodspace_cache_ptr(self); value_t cache = get_freeze_cheat_value(cache_ptr); // Create the cache if it doesn't exist. if (is_nothing(cache)) { TRY_SET(cache, new_heap_id_hash_map(runtime, 128)); set_freeze_cheat_value(cache_ptr, cache); } // Create the selector-specific cache if it doesn't exits. value_t slice = get_id_hash_map_at(cache, selector); if (in_condition_cause(ccNotFound, slice)) { TRY_SET(slice, create_methodspace_selector_slice(runtime, self, selector)); TRY(set_id_hash_map_at(runtime, cache, selector, slice)); } return slice; }
// Checks whether a fragment entry for the given stage and path already exists // and if not creates it. static value_t binding_context_ensure_fragment_entry(binding_context_t *context, value_t stage, value_t path, value_t fragment, bool *created) { CHECK_PHYLUM(tpStageOffset, stage); CHECK_FAMILY(ofPath, path); CHECK_FAMILY_OPT(ofUnboundModuleFragment, fragment); value_t path_map = context->fragment_entry_map; runtime_t *runtime = get_ambience_runtime(context->ambience); if (!has_id_hash_map_at(path_map, path)) { TRY_DEF(stage_map, new_heap_id_hash_map(runtime, 16)); TRY(set_id_hash_map_at(runtime, path_map, path, stage_map)); } value_t stage_map = get_id_hash_map_at(path_map, path); if (!has_id_hash_map_at(stage_map, stage)) { TRY_DEF(imports, new_heap_array_buffer(runtime, 4)); TRY_DEF(ident, new_heap_identifier(runtime, stage, path)); TRY_DEF(entry, new_heap_triple(runtime, fragment, imports, ident)); TRY(set_id_hash_map_at(runtime, stage_map, stage, entry)); *created = true; } return get_id_hash_map_at(stage_map, stage); }