void world_initialize(World* world) { initialize_null(&world->modulesByName); initialize_null(&world->modulesByFilename); initialize_null(&world->everyModule); initialize_null(&world->fileSources); initialize_null(&world->moduleSearchPaths); set_hashtable(&world->modulesByName); set_hashtable(&world->modulesByFilename); set_list(&world->everyModule); set_list(&world->moduleSearchPaths); set_list(&world->fileSources); world->moduleSearchPaths.append_str("$builtins"); world->fileWatchWorld = alloc_file_watch_world(); world->builtinPatch = circa_create_native_patch(world, "builtins"); #if CIRCA_ENABLE_LIBUV world->libuvWorld = alloc_libuv_world(); #endif perlin_init(); }
void symbol_initialize_global_table() { g_runtimeSymbolMap = new Value(); set_hashtable(g_runtimeSymbolMap); g_runtimeSymbolTable = new Value(); set_list(g_runtimeSymbolTable, 0); }
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); } } }
void list_names_that_must_be_looped(Block* contents, Value* names) { // Find all names within 'contents' that must be looped. A name must be looped when // a term inside the loop binds a name that was already used outside the loop. Value namesMap; set_hashtable(&namesMap); for (BlockIteratorFlat it(contents); it; ++it) { Term* term = it.current(); if (has_empty_name(term)) continue; Value termVal; termVal.set_term(contents->owningTerm); Term* outsideName = find_name_at(&termVal, term_name(term)); // Don't look at names outside the major block. if (outsideName != NULL && !is_under_same_major_block(term, outsideName)) outsideName = NULL; if (outsideName != NULL) set_bool(hashtable_insert(&namesMap, term_name(term)), true); } hashtable_get_keys(&namesMap, names); list_sort(names, NULL, NULL); }
Value* block_insert_property(Block* block, Symbol key) { if (is_null(&block->properties)) set_hashtable(&block->properties); Value keyVal; set_symbol(&keyVal, key); return hashtable_insert(&block->properties, &keyVal); }
void Block__properties(VM* vm) { Block* block = as_block(vm->input(0)); if (block == NULL) return vm->throw_str("NULL block"); if (is_null(&block->properties)) set_hashtable(vm->output()); else copy(&block->properties, vm->output()); }
static void update_patch_function_lookup(World* world) { NativePatchWorld* nativeWorld = world->nativePatchWorld; set_hashtable(&nativeWorld->everyPatchedFunction); // For every native module. std::map<std::string, NativePatch*>::const_iterator it; for (it = nativeWorld->nativeModules.begin(); it != nativeWorld->nativeModules.end(); ++it) { NativePatch* module = it->second; update_patch_function_lookup_for_module(module); } }
static NativePatch* add_native_patch(World* world) { NativePatch* patch = new NativePatch(); set_hashtable(&patch->funcMap); patch->world = world; patch->dll = NULL; world->nativePatchCount++; world->nativePatch = (NativePatch**) realloc(world->nativePatch, sizeof(NativePatch*) * world->nativePatchCount); world->nativePatch[world->nativePatchCount-1] = patch; return patch; }
Term::Term(Block* _parent) : type(NULL), function(NULL), uniqueOrdinal(0), owningBlock(_parent), index(0), nestedContents(NULL) { id = _parent->world->nextTermID++; set_hashtable(&properties); if (id == DEBUG_BREAK_ON_TERM) ca_debugger_break(); }
void perf_stats_to_map(Value* map) { u64 frozenStats[c_numPerfStats]; for (int name = c_firstStatIndex; name < s_LastStatIndex-1; name++) { int i = name - c_firstStatIndex; frozenStats[i] = PERF_STATS[i]; } set_hashtable(map); for (int name = c_firstStatIndex; name < s_LastStatIndex-1; name++) { int i = name - c_firstStatIndex; u64 value = frozenStats[i]; set_int(hashtable_insert_symbol_key(map, name), (int) value); } }
Term::Input::Input(Term* t) : term(t) { set_hashtable(&properties); }
Term::Input::Input() : term(NULL) { set_hashtable(&properties); }
NativePatchWorld* create_native_patch_world() { NativePatchWorld* world = new NativePatchWorld(); set_hashtable(&world->everyPatchedFunction); return world; }
void list_names_that_should_be_used_as_minor_block_output(Block* block, Value* names) { Value namesMap; set_hashtable(&namesMap); }
void change_event_set_blank(Value* value, int eventSpecificFields) { set_list(value, 3 + eventSpecificFields); set_symbol(change_event_type(value), s_none); set_hashtable(change_event_attrs(value)); }
void circa_use_in_memory_filesystem(caWorld* world) { world_clear_file_sources(world); set_hashtable(world_append_file_source(world)); }