Esempio n. 1
0
void compile_iter_loop(compiler_wrapper *cw, ast_node *root)
{
    ast_loop_node *node = (ast_loop_node *)root;

    compile(cw, node->onloop);
    append_op(cw, LI_MAKE_ITER, node->lineno);

    int tagOut = next_if_tag(cw);
    int tagLoop = next_if_tag(cw);

    int start = (int)cw->rops.count;

    append_op(cw, LI_NEXT_ITER_OR_JUMP, node->lineno);
    append_op(cw, tagOut, node->lineno);
    append_op(cw, -1, node->lineno);
    append_op(cw, -1, node->lineno);
    append_op(cw, -1, node->lineno);

    append_var_info(cw, ((ast_value_node *)(node->init))->value.s, 0, node->lineno);
    append_op(cw, LI_POP, node->lineno);

    if(node->condition)
    {
        append_op(cw, LI_ITER_INDEX, node->lineno);
        append_var_info(cw, ((ast_value_node *)(node->condition))->value.s, 0, node->lineno);
        append_op(cw, LI_POP, node->lineno);
    }

    lky_object *wrapLoop = lobjb_build_int(tagLoop);    
    lky_object *wrapOut = lobjb_build_int(tagOut);
    pool_add(&ast_memory_pool, wrapLoop);
    pool_add(&ast_memory_pool, wrapOut);

    arr_append(&cw->loop_start_stack, wrapLoop);
    arr_append(&cw->loop_end_stack, wrapOut);

    compile_compound(cw, node->payload->next);

    arr_remove(&cw->loop_start_stack, NULL, cw->loop_start_stack.count - 1);
    arr_remove(&cw->loop_end_stack, NULL, cw->loop_end_stack.count - 1);

    append_op(cw, tagLoop, node->lineno);

    append_op(cw, LI_JUMP, node->lineno); // Add the jump to the start location
    unsigned char buf[4];
    int_to_byte_array(buf, start);
    append_op(cw, buf[0], node->lineno);
    append_op(cw, buf[1], node->lineno);
    append_op(cw, buf[2], node->lineno);
    append_op(cw, buf[3], node->lineno);

    append_op(cw, tagOut, node->lineno);
    append_op(cw, LI_POP, node->lineno);

    cw->save_val = 1;
}
Esempio n. 2
0
/*!
** Parse the command line arguments and fill @a dg accordingly.
**
** @param[out] dg The main data structure to be filled.
** @param[in] argc The arguments count.
** @param[in] argv The arguments array.
*/
void dgopts(depgraph_t *dg, int argc, char **argv)
{
    int opt_idx;
    int c;
    int stop_loop = 0;

    while (!stop_loop && -1 != (c = getopt_long(argc, argv,
                                    dgoptstring, dglongopts,
                                    &opt_idx)))
    {
        switch (c)
        {
        case 'h':
            print_help(help, ERROR_NO);
            break;
        case 'o':
            dg->out = pool_add(strdup(optarg));
            break;
        case 'r':
            dg->root = pool_add(strdup(optarg));
            break;
        case 't':
            dg->outfunc = which_output(optarg);
            break;
        case 'u':
            print_help(usage, ERROR_NO);
            break;
        case 'v':
            dg->verbose = 1;
            break;
        case 'V':
            print_help(version, ERROR_NO);
            break;
        case '?':
            print_help(help, ERROR_CMD);
            break;
        default:
            exit(ERROR_CMD);
            break;
        }
    }
    if (optind >= argc)
    {
        print_help(usage, ERROR_CMD);
    }
    dg->atom = pool_add(strdup(argv[optind]));
    if (NULL == dg->outfunc)
        dg->outfunc = output_txt;
}
Esempio n. 3
0
EagleComplexType *ett_copy(EagleComplexType *type)
{
    EagleComplexType *output = malloc(ty_size_of_type(type));
    pool_add(&type_mempool, output);
    memcpy(output, type, ty_size_of_type(type));

    if(output->type == ETFunction)
    {
        EagleFunctionType *ft = (EagleFunctionType *)output;
        ft->params = malloc(ft->pct * sizeof(EagleComplexType *));
        pool_add(&type_mempool, ft->params);
    }

    return output;
}
Esempio n. 4
0
int main(void)
{
	pool p;
	pthread_t t1, t2;
	size_t i;

	if( (p = pool_new(NELEM)) == NULL)
		return 77;

	/* Add some items to the pool */
	for(i = 0; i < NELEM; i++) {
		void* dummy = (void*)(i + 1);
		pool_add(p, dummy);
	}

	/* Start the threads */
	pthread_create(&t1, NULL, tfn, p);
	pthread_create(&t2, NULL, tfn, p);

	/* Wait for the threads to finish */
	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	pool_free(p, NULL);
	return 0;
}
Esempio n. 5
0
EagleComplexType *ett_interface_type(char *name)
{
    EagleComplexType *et = hst_get(&type_named_table, name, NULL, NULL);
    if(et)
        return et;

    EagleInterfaceType *ett = malloc(sizeof(EagleInterfaceType));
    ett->names = arr_create(3);
    arr_append(&ett->names, name);
    ett->type = ETInterface;

    pool_add(&list_mempool, &ett->names);
    pool_add(&type_mempool, ett);

    return (EagleComplexType *)ett;
}
Esempio n. 6
0
EagleComplexType *ett_function_type(EagleComplexType *retVal, EagleComplexType **params, int pct)
{
    EagleFunctionType *ett = malloc(sizeof(EagleFunctionType));
    ett->type = ETFunction;
    ett->retType = retVal;
    ett->params = malloc(sizeof(EagleComplexType *) * pct);
    memcpy(ett->params, params, sizeof(EagleComplexType *) * pct);
    ett->pct = pct;
    ett->variadic = 0;
    ett->closure = NO_CLOSURE;
    ett->gen = 0;

    pool_add(&type_mempool, ett);
    pool_add(&type_mempool, ett->params);

    return (EagleComplexType *)ett;
}
Esempio n. 7
0
// Helper function to add an instruction/tag to
// the running operations list. This should be
// the only function that appends to that list.
void append_op(compiler_wrapper *cw, long ins, long lineno)
{
    lky_object *obj = lobjb_build_int(ins);
    lky_object *idx = lobjb_build_int(lineno);
    pool_add(&ast_memory_pool, obj);
    arr_append(&cw->rops, obj);
    arr_append(&cw->rindices, idx);
}
Esempio n. 8
0
void correct_bases(bwa_seq_t *seqs, bwa_seq_t *ori_read, alignarray *aligns,
		const int tid) {
	pool *p = NULL;
	int j = 0, cursor = 0, i = 0, index = 0, has_hit = 0;
	alg *a = NULL;
	bwa_seq_t *s = NULL;
	int *counter = NULL;

	//p_query("ORI", ori_read);
	p = new_pool();
	ori_read->cursor = 0;
	for (i = 0; i < aligns->len; i++) {
		a = g_ptr_array_index(aligns, i);
		index = a->r_id;
		s = &seqs[index];
		if (s->is_in_c_pool > 0 && s->is_in_c_pool != tid)
			continue;
		if (s->status == USED || strcmp(s->name, ori_read->name) == 0)
			continue;
		s->rev_com = a->rev_comp;
		if (s->rev_com)
			s->cursor = s->len - ori_read->len - a->pos;
		else
			s->cursor = a->pos;
		if (s->is_in_c_pool == 0)
			pool_add(p, s, tid);
	}
	if (p->n >= 4) {
		//p_pool(__func__, p, NULL);
		counter = (int*) calloc(5, sizeof(int));
		for (j = 0; j < ori_read->len; j++) {
			reset_c(counter, NULL);
			has_hit = 0;
			for (i = 0; i < p->n; i++) {
				s = g_ptr_array_index(p->reads, i);
				cursor = s->cursor + j;
				if (cursor >= 0 || cursor < s->len) {
					has_hit = 1;
					if (s->rev_com) {
						counter[s->rseq[cursor]]++;
					} else {
						counter[s->seq[cursor]]++;
					}
				}
			}
			//show_debug_msg(__func__, "Correcting %d: %d:%d:%d:%d\n", j, counter[0],
			//		counter[1], counter[2], counter[3]);
			if (has_hit) {
				ori_read->seq[j] = get_pure_most(counter);
				ori_read->rseq[ori_read->len - 1 - j] = 3 - ori_read->seq[j];
			}
		}
		free(counter);
	}
	free_pool(p);
	//p_query("AFT", ori_read);
}
Esempio n. 9
0
EagleComplexType *ett_gen_type(EagleComplexType *ytype)
{
    EagleGenType *ett = malloc(sizeof(EagleGenType));
    ett->type = ETGenerator;
    ett->ytype = ytype;

    pool_add(&type_mempool, ett);

    return (EagleComplexType *)ett;
}
Esempio n. 10
0
VarBundle *vs_put(VarScopeStack *vs, char *ident, LLVMValueRef val, EagleComplexType *type, int lineno)
{
    VarBundle *vb = vs_create(ident, NULL, type, val, lineno);
    VarScope *s = vs->scope;

    hst_put(&s->table, ident, vb, NULL, NULL);
    pool_add(&vs->pool, vb);

    return vb;
}
Esempio n. 11
0
EagleComplexType *ett_class_type(char *name)
{
    EagleComplexType *et = hst_get(&type_named_table, name, NULL, NULL);
    if(et)
        return et;

    EagleStructType *ett = malloc(sizeof(EagleStructType));
    ett->type = ETClass;
    ett->types = arr_create(10);
    ett->names = arr_create(10);
    ett->name = name;

    hst_put(&type_named_table, name, ett, NULL, NULL);
    pool_add(&type_mempool, ett);
    pool_add(&list_mempool, &ett->types);
    pool_add(&list_mempool, &ett->names);

    return (EagleComplexType *)ett;
}
int balanceador_AgregaURL (char *URL){

    int PoolstructOptimo = PoolstructMasVacia ();
    struct Poolstruct *ps;
    ps  =   listaPools_getPoolstruct(PoolstructOptimo);
    pool_add(ps, URL);
    printf("(B)***** %s en el pool del hilo %d \n", URL, PoolstructOptimo);
    int x = 3;

}
Esempio n. 13
0
EagleComplexType *ett_array_type(EagleComplexType *of, int ct)
{
    EagleArrayType *ett = malloc(sizeof(EagleArrayType));
    ett->type = ETArray;
    ett->of = of;
    ett->ct = ct;

    pool_add(&type_mempool, ett);

    return (EagleComplexType *)ett;
}
Esempio n. 14
0
EagleComplexType *ett_pointer_type(EagleComplexType *to)
{
    EaglePointerType *ett = malloc(sizeof(EaglePointerType));
    ett->type = ETPointer;
    ett->to = to;
    ett->counted = 0;
    ett->weak = 0;
    ett->closed = 0;

    pool_add(&type_mempool, ett);

    return (EagleComplexType *)ett;
}
Esempio n. 15
0
File: main.c Progetto: 91he/Test
int main(){
	srand(time(NULL));
	struct thread_pool *pool = pool_init(4);
	int i;
	int num[10];
	for(i = 0; i < 10; ++i)
		num[i] = i;
	for(i = 0; i < 10; ++i){
		pool_add(pool, handle, num+i);
	}
	sleep(5);
	pool_destroy(pool);

	return 0;
}
Esempio n. 16
0
EagleComplexType *ett_generic_type(char *ident)
{
    EagleComplexType *ty = hst_get(&generic_ident_table, ident, NULL, NULL);
    if(ty)
        return ty;

    ty = calloc(ty_type_max_size(), 1);
    ty->type = ETGeneric;
    ((EagleGenericType *)ty)->ident = ident;
    hst_put(&generic_ident_table, ident, ty, NULL, NULL);

    pool_add(&type_mempool, ty);

    return ty;
}
Esempio n. 17
0
VarBundle *vs_put_in_module(VarScopeStack *vs, char *ident, char *module, LLVMValueRef val, EagleComplexType *type)
{
    VarBundle *vb = vs_create(ident, module, type, val, -1);

    Hashtable *mod = hst_get(&vs->modules, module, NULL, NULL);
    if(!mod)
    {
        mod = malloc(sizeof(Hashtable));
        *mod = hst_create();
        mod->duplicate_keys = 1;

        hst_put(&vs->modules, module, mod, NULL, NULL);
    }

    hst_put(mod, ident, vb, NULL, NULL);
    pool_add(&vs->pool, vb);
    
    return vb;
}
Esempio n. 18
0
EagleComplexType *ett_enum_type(char *name)
{
    EagleComplexType *et = hst_get(&enum_named_table, name, NULL, NULL);
    if(et)
        return et;

    char *anam = hst_retrieve_duped_key(&enum_table, name);
    if(!anam)
        die(__LINE__, "Internal compiler error: no such enum %s", name);

    EagleEnumType *en = malloc(sizeof(*en));
    en->type = ETEnum;
    en->name = anam;

    pool_add(&type_mempool, en);

    hst_put(&enum_named_table, name, en, NULL, NULL);

    return (EagleComplexType *)en;
}
Esempio n. 19
0
NPError My_NPN_PostURLNotify(NPP instance, const char* url,
                             const char* target, uint32_t len,
                             const char* buf, NPBool file,
                             void* notifyData){
    fprintf(stderr, "%s-%d: %s\n", __func__, __LINE__, url);
    if(target) return NPERR_NO_ERROR;

    url_data *data = malloc(sizeof(url_data));

    data->httpType = CURL_HTTP_POST;
    data->instance = instance;
    data->url = strdup(url);
    data->notifyData = notifyData;
    data->postData = (char*)malloc(len);

    memcpy(data->postData, buf, len);

    pool_add(g_FRManager.pool, url_worker, data);

	return NPERR_NO_ERROR;
}
Esempio n. 20
0
void queue_get(queue_t *q, msg_t *msg)
{
	msg_list_t *first;

	assert(q); assert(msg);
	pthread_mutex_lock(&q->mutex);
	while (q->msg_nr == 0)
		pthread_cond_wait(&q->cond, &q->mutex);

	first = q->first;
	q->first = first->next;
	q->msg_nr--;

	msg->data = first->msg.data;
	msg->type = first->msg.type;
	msg->len = first->msg.len;

	pool_add(q, first);
	pthread_mutex_unlock(&q->mutex);
	return;
}
Esempio n. 21
0
static void server_read_callback(struct bufferevent *bev, void *ctx)
{
    struct range_stream *cs = (struct range_stream *) ctx;
    struct io *io = cs->io;
    debug_print(0, "read_cb bev=%p", bev);
    while (!range_stream_empty(cs)) {
        int log_size;
        struct Log *log = range_stream_get(cs, &log_size);
        if (log == NULL) {
            break;
        }
        char *data = log_get_data((struct Log *) log);
        debug_print(0, "%d %d %s", log->protocol, log->logsize, data);
        switch (log_data_protocol(log)) {
        case LOGPOOL_EVENT_READ:
            debug_print(1, "R %d %d, '%s'", log->klen, log->vlen, data);
            pool_add((struct Procedure*) log, bev, io->pool);
            break;
        case LOGPOOL_EVENT_WRITE:
#if LOGPOOL_DEBUG >= 1
            log_dump(stderr, "W ", (struct Log *) log, "\n", 0);
#endif
            pool_exec((struct Log *) log, log_size, io->pool);
            break;
        case LOGPOOL_EVENT_QUIT:
            debug_print(1, "Q %d, %d\n", log->klen, log->vlen);
            pool_delete_connection(io->pool, bev);
            bufferevent_free(bev);
            goto L_exit;
        case LOGPOOL_EVENT_NULL:
        default:
            /*TODO*/abort();
            break;
        }
    }
    L_exit:;
    return;
}
Esempio n. 22
0
File: pool.c Progetto: noelbk/bklib
char *
pool_memdup(pool_t *pool, const char *str, int len) {
    char *p=0, *q=0;
    int err=-1;
    do {
	assertb(str);
	p = (char*)malloc(len);
	assertb(p);
	memcpy(p, str, len);
	q = (char*)pool_add(pool, p, 0, 0);
	err = 0;
    } while(0);
    if( err ) {
	if( q ) {
	    pool_free(pool, q);
	}
	else if ( p ) {
	    free(p);
	}
	p = q = 0;
    }
    return q;
}
Esempio n. 23
0
NPError My_NPN_GetURLNotify(NPP instance, const char* url,
                            const char* target, void* notifyData){
    fprintf(stderr, "%s-%d: %p, %s\n", __func__, __LINE__, target, url);
    if(target && !strcmp("_blank", target)){
        My_NPP_URLNotify(instance, url, NPRES_DONE, notifyData);
    }else if(!memcmp(url, "javascript:", 11)){
        NPStream stream;
        char buf[256];

        sprintf(buf, "file:///%X.html__flashplugin_unique__", instance);

        stream.url = url;
        stream.notifyData = notifyData;
        stream.end = strlen(buf);

        My_NPP_NewStream(instance, "text/html", &stream, 0, NULL);

        My_NPP_WriteReady(instance, &stream);
        My_NPP_Write(instance, &stream, 0, stream.end, buf);

        My_NPP_URLNotify(instance, url, NPRES_DONE, notifyData);
        My_NPP_DestroyStream(instance, &stream, NPRES_DONE);
    }else if(!target){
        url_data *data = malloc(sizeof(url_data));

        data->httpType = CURL_HTTP_GET;
        data->instance = instance;
        data->url = strdup(url);
        data->notifyData = notifyData;
        data->postData = NULL;

        pool_add(g_FRManager.pool, url_worker, data);
    }

    return NPERR_NO_ERROR;
}
Esempio n. 24
0
File: pool.c Progetto: noelbk/bklib
void*
pool_realloc(pool_t *pool, void *ptr, size_t len) {
    pool_remove(pool, ptr);
    ptr = realloc(ptr, len);
    return pool_add(pool, ptr, 0, 0);
}
Esempio n. 25
0
void append_var_info(compiler_wrapper *cw, char *ch, char load, int lineno)
{
    char needs_close = cw->repl;
    char already_defined = 0;
    arraylist list = cw->used_names;
    int i;
    for(i = 0; i < list.count; i++)
    {
        name_wrapper *w = arr_get(&cw->used_names, i);
        
        if(strcmp(w->name, ch))
            continue;   

        if(w->owner != cw)
        {
            switch_to_close(w->owner, ch, w->idx);
            needs_close = 1;
        }
        else
        {
            needs_close = is_close(cw, w->idx);
            already_defined = 1;
        }
    }

    if(!needs_close && !already_defined && load)
        needs_close = 1;

    if(needs_close)
    {
        lky_instruction istr = load ? LI_LOAD_CLOSE : LI_SAVE_CLOSE;
        char *nsid = malloc(strlen(ch) + 1);
        strcpy(nsid, ch);

        int i = find_prev_name(cw, nsid);
        if(i < 0)
        {
            i = (int)cw->rnames.count;
            arr_append(&cw->rnames, nsid);
        }

        append_op(cw, istr, lineno);
        unsigned char buf[4];
        int_to_byte_array(buf, i);
        append_op(cw, buf[0], lineno);
        append_op(cw, buf[1], lineno);
        append_op(cw, buf[2], lineno);
        append_op(cw, buf[3], lineno);

        return;
    }

    lky_instruction istr = load ? LI_LOAD_LOCAL : LI_SAVE_LOCAL;
    hm_error_t err;
    
    int idx = 0;
    lky_object_builtin *o = hm_get(&cw->saved_locals, ch, &err);
    if(err == HM_KEY_NOT_FOUND)
    {
        idx = get_next_local(cw);
        lky_object *obj = lobjb_build_int(idx);
        pool_add(&ast_memory_pool, obj);
        hm_put(&cw->saved_locals, ch, obj);
    }
    else
        idx = OBJ_NUM_UNWRAP(o);

    append_op(cw, istr, lineno);
    unsigned char buf[4];
    int_to_byte_array(buf, idx);
    append_op(cw, buf[0], lineno);
    append_op(cw, buf[1], lineno);
    append_op(cw, buf[2], lineno);
    append_op(cw, buf[3], lineno);

    name_wrapper *wrap = malloc(sizeof(name_wrapper));
    pool_add(&ast_memory_pool, wrap);
    wrap->idx = cw->rops.count - 5;
    wrap->name = ch;
    wrap->owner = cw;
    arr_append(&cw->used_names, wrap);
}
Esempio n. 26
0
File: pool.c Progetto: noelbk/bklib
void*
pool_malloc(pool_t *pool, size_t len) {
    return pool_add(pool, calloc(len, 1), 0, 0);
}
Esempio n. 27
0
int rfc6791_add(struct ipv4_prefix *prefix)
{
    return pool_add(pool, prefix);
}
Esempio n. 28
0
void compile_loop(compiler_wrapper *cw, ast_node *root)
{
    ast_loop_node *node = (ast_loop_node *)root;

    // if(node->init && node->condition && !node->onloop)
    //    return compile_iter_loop(cw, root);

    int tagOut = next_if_tag(cw); // Prepare the exit tag
    int tagLoop = next_if_tag(cw); // Prepare the continue tag

    if(node->init) // If we have a for loop, compile the init
    {
        char save = cw->save_val;
        cw->save_val = 0;
        compile(cw, node->init);
        if(!cw->save_val)
            append_op(cw, LI_POP, node->lineno);
        cw->save_val = save;
    }

    int start = (int)cw->rops.count; // The start location (for loop jumps)

    compile(cw, node->condition); // Append the tag for the unknown end location
    append_op(cw, LI_JUMP_FALSE, node->lineno);
    append_op(cw, tagOut, node->lineno);
    append_op(cw, -1, node->lineno); // Note that we use for bytes to represent jump locations.
    append_op(cw, -1, node->lineno); // This allows us to index locations beyond 255 in the
    append_op(cw, -1, node->lineno); // interpreter.
    
    lky_object *wrapLoop = lobjb_build_int(tagLoop);
    lky_object *wrapOut = lobjb_build_int(tagOut);
    pool_add(&ast_memory_pool, wrapLoop);
    pool_add(&ast_memory_pool, wrapOut);
    arr_append(&cw->loop_start_stack, wrapLoop);
    arr_append(&cw->loop_end_stack, wrapOut);

    compile_compound(cw, node->payload->next);

    arr_remove(&cw->loop_start_stack, NULL, cw->loop_start_stack.count - 1);
    arr_remove(&cw->loop_end_stack, NULL, cw->loop_end_stack.count - 1);

    append_op(cw, tagLoop, node->lineno);

    if(node->onloop) // If a for loop, compile the onloop.
    {
        char save = cw->save_val;
        cw->save_val = 0;
        compile(cw, node->onloop);
        if(!cw->save_val)
            append_op(cw, LI_POP, node->lineno);
        cw->save_val = save;
    }

    append_op(cw, LI_JUMP, node->lineno); // Add the jump to the start location
    unsigned char buf[4];
    int_to_byte_array(buf, start);

    append_op(cw, buf[0], node->lineno);
    append_op(cw, buf[1], node->lineno);
    append_op(cw, buf[2], node->lineno);
    append_op(cw, buf[3], node->lineno);

    append_op(cw, tagOut, node->lineno);

    cw->save_val = 1;
}
Esempio n. 29
0
File: pool.c Progetto: noelbk/bklib
char*
pool_strdup(pool_t *pool, const char *str) {
    if( !str ) return 0;
    return (char*)pool_add(pool, strdup(str), 0, 0);
}