static gboolean location_changed(GntFileSel *sel, GError **err) { GList *files, *iter; gboolean success; if (!sel->dirs) return TRUE; gnt_tree_remove_all(GNT_TREE(sel->dirs)); if (sel->files) gnt_tree_remove_all(GNT_TREE(sel->files)); gnt_entry_set_text(GNT_ENTRY(sel->location), NULL); if (sel->current == NULL) { if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(sel)); return TRUE; } /* XXX:\ * XXX: This is blocking. * XXX:/ */ files = NULL; if (sel->read_fn) success = sel->read_fn(sel->current, &files, err); else success = local_read_fn(sel->current, &files, err); if (!success || *err) { gnt_warning("error opening location %s (%s)", sel->current, *err ? (*err)->message : "reason unknown"); return FALSE; } for (iter = files; iter; iter = iter->next) { GntFile *file = iter->data; char *str = file->basename; if (file->type == GNT_FILE_DIR) { gnt_tree_add_row_after(GNT_TREE(sel->dirs), g_strdup(str), gnt_tree_create_row(GNT_TREE(sel->dirs), str), NULL, NULL); if (sel->multiselect && sel->dirsonly && is_tagged(sel, str)) gnt_tree_set_row_flags(GNT_TREE(sel->dirs), (gpointer)str, GNT_TEXT_FLAG_BOLD); } else if (!sel->dirsonly) { char size[128]; snprintf(size, sizeof(size), "%ld", file->size); gnt_tree_add_row_after(GNT_TREE(sel->files), g_strdup(str), gnt_tree_create_row(GNT_TREE(sel->files), str, size, ""), NULL, NULL); if (sel->multiselect && is_tagged(sel, str)) gnt_tree_set_row_flags(GNT_TREE(sel->files), (gpointer)str, GNT_TEXT_FLAG_BOLD); } } g_list_foreach(files, (GFunc)gnt_file_free, NULL); g_list_free(files); if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(sel)); return TRUE; }
Word::Word( const std::string& str, int string_start, int string_end, const std::vector<std::string>& strtags) : form(str), start(string_start), end(string_end), id(-1), sigid(-1), tags(), rules() { // std::cout << "word is " << form << " and position is " << string_start << std::endl; if (end == -1) { end = start + 1; } for(std::vector<std::string>::const_iterator i(strtags.begin()); i != strtags.end(); ++i) { // fix "unknown tag" bug // if tag doesn't exist, then do tagging try { tags.push_back(SymbolTable::instance_nt().get(*i)); } catch(Miss& m){ // std::cerr << "Here 1" << std::endl; std::cerr << m.what() << std::endl; } } if(is_tagged()) { try { sigid = SymbolTable::instance_word().get(wordsignature->get_unknown_mapping(form,start)); } catch(Miss& m) { // std::cerr << "Here 2" << std::endl; // std::cerr << m.what() << std::endl; sigid = -1; } } try { //look up the word in the symbol table id = SymbolTable::instance_word().get(str); } catch(Miss&) { //see what the id corresponding to the unknown token is std::string signature = wordsignature->get_unknown_mapping(form,start); try { id = SymbolTable::instance_word().get(signature); } catch(Miss& m) { std::cerr << m.what() << std::endl; // try { // id = SymbolTable::instance_word().get(signature.substr(0, signature.find_last_of("-"))); // } // catch(Miss& m) { // std::cerr << m.what() << std::endl; id = -1; // } } } }
//-------------------------------------------------------------------------- bool push_many (mpsc_node_hook& first, mpsc_node_hook& last) { last.next = nullptr; mpsc_node_hook* old_tail = m_tail->exchange (&last, mo_acq_rel); //(*) another push() here would succeed, a pop() when the queue size is > 1 would succeed too. bool was_empty = is_tagged (old_tail); untag (old_tail)->next.store (&first, mo_release); return was_empty; }
Cell eval(Cell exp, Cell env) { if (is_self_evaluating(exp)) { return exp; } else if (is_atom(exp)) { return lookup(exp, env); } else if (is_tagged(exp, atom("define"))) { return define(car(cdr(exp)), eval(car(cdr(cdr(exp))), env), env); } else if (is_tagged(exp, atom("set!"))) { return set(car(cdr(exp)), eval(car(cdr(cdr(exp))), env), env); } else if (is_tagged(exp, atom("if"))) { Cell cond = eval(car(cdr(exp)), env); if (is_atom(cond) && is_eq(cond, atom("#f"))) { exp = car(cdr(cdr(cdr(exp)))); } else { exp = car(cdr(cdr(exp))); } return eval(exp, env); } else if (is_tagged(exp, atom("vau"))) { return procedure(exp, env); } else if (is_pair(exp)) { Cell proc = eval(car(exp), env); if (is_primitive(proc)) { return (proc->primitive)(eval_operands(cdr(exp), env)); } else if (is_procedure(proc)) { Cell src = car(proc); Cell e = car(cdr(cdr(src))); Cell para = cons(e, cons(car(cdr(src)), null)); Cell args = cons(env, cons(cdr(exp), null)); Cell body = car(cdr(cdr(cdr(src)))); return eval(body, extend_env(para, args, cdr(proc))); } } fprintf(stderr, "eval illegal state\n"); return atom("#<void>"); }
/** * Main garbage collector function */ void GC_collect(void) { header_t *current_ptr = NULL, *previous_ptr = NULL, *it = NULL; if(is_empty(&usedptr)) return; // Scan the BSS and initialized data segments. mark_from_region(BBSstart, BBSend); // Scan the stack. REFRESH_STACK_TOP mark_from_region(stack_bottom, stack_top); // Scan the heap mark_from_heap(); // Collect current_ptr = usedptr; while(current_ptr != NULL) { if(!is_tagged(current_ptr)) { header_t *block_ptr; block_ptr = remove_from_list(&usedptr, previous_ptr, current_ptr); add_to_list(&freeptr, block_ptr); if(previous_ptr != NULL) current_ptr = previous_ptr; else { current_ptr = usedptr; continue; } } previous_ptr = current_ptr; current_ptr = next_block(current_ptr); } }
static struct block *object_initializer(struct block *block, struct var target) { int i, filled = target.offset; const struct typetree *type = target.type; assert(!is_tagged(type)); consume('{'); target.lvalue = 1; switch (type->type) { case T_UNION: /* C89 states that only the first element of a union can be * initialized. Zero the whole thing first if there is padding. */ if (size_of(get_member(type, 0)->type) < type->size) { target.type = (type->size % 8) ? type_init(T_ARRAY, &basic_type__char, type->size) : type_init(T_ARRAY, &basic_type__long, type->size / 8); zero_initialize(block, target); } target.type = get_member(type, 0)->type; block = initializer(block, target); if (peek().token != '}') { error("Excess elements in union initializer."); exit(1); } break; case T_STRUCT: for (i = 0; i < nmembers(type); ++i) { target.type = get_member(type, i)->type; target.offset = filled + get_member(type, i)->offset; block = initializer(block, target); if (peek().token == ',') { consume(','); } else break; if (peek().token == '}') { break; } } while (++i < nmembers(type)) { target.type = get_member(type, i)->type; target.offset = filled + get_member(type, i)->offset; zero_initialize(block, target); } break; case T_ARRAY: target.type = type->next; for (i = 0; !type->size || i < type->size / size_of(type->next); ++i) { target.offset = filled + i * size_of(type->next); block = initializer(block, target); if (peek().token == ',') { consume(','); } else break; if (peek().token == '}') { break; } } if (!type->size) { assert(!target.symbol->type.size); assert(is_array(&target.symbol->type)); /* Incomplete array type can only be in the root level of target * type tree, overwrite type directly in symbol. */ ((struct symbol *) target.symbol)->type.size = (i + 1) * size_of(type->next); } else { while (++i < type->size / size_of(type->next)) { target.offset = filled + i * size_of(type->next); zero_initialize(block, target); } } break; default: error("Block initializer only apply to aggregate or union type."); exit(1); } consume('}'); return block; }