コード例 #1
0
ファイル: parse.c プロジェクト: going-digital/versaload
static int wasFinalPass(void)
{
    int result = 1;
    struct map_iterator i[1];
    struct map_entry *me;
    for(map_get_iterator(s->guesses, i);
        (me = (struct map_entry*)map_iterator_next(i)) != NULL;)
    {
        struct expr *guess_expr;
        struct expr *sym_expr;

        LOG(LOG_VERBOSE, ("Checking guessed symbol %s: ", me->key));
        /* Was this guessed symbol used in this pass? */
        if((sym_expr = map_get(s->sym_table, me->key)) == NULL)
        {
            /* No, skip it */
            continue;
        }
        guess_expr = me->value;
        LOG(LOG_VERBOSE, ("expected %d, actual %d\n",
             resolve_expr(guess_expr),
             resolve_expr(sym_expr)));

        if(expr_cmp_cb(me->value, sym_expr) != 0)
        {
            /* Not the same, not the last pass.
             * copy the actual value from the sym table */
            me->value = sym_expr;
            result = 0;
        }
    }
    return result;
}
コード例 #2
0
ファイル: parse.c プロジェクト: going-digital/versaload
static void dump_sym_table(int level, struct map *m)
{
    struct map_iterator i[1];
    const struct map_entry *e;

    for(map_get_iterator(m, i); (e = map_iterator_next(i)) != NULL;)
    {
        LOG(level, ("sym_table: %s ", e->key));
        expr_dump(level, e->value);
    }
}
コード例 #3
0
ファイル: router.c プロジェクト: ALPHA-60/plus-one-minus-one
static
void wildcard_router_receive(receiver_t* self,
			     bytecode_stream_t* message, context_t* context)
{
    router_t* router = (router_t*) self;
    bytecode_t* selector = message->pop(message);

    if(selector && selector->verb == route_atom) {
	bytecode_t* destination = message->pop(message);

	if(!destination) {
	    WARNING1("no destination provided.");
	    return;
	} else {
	    atom_t dest = destination->verb;

	    TRACE2("routing towards selector '%s' requested.", atom_get_cstring_value(dest));
	    if(dest == star_atom) {
		map_iterator_t i; 
		map_value_t pslot = NULL_MAP_VALUE;
		
		map_get_iterator(&router->children, &i);
		
		while (map_value_is_there (pslot = map_iterator_next(&i))) {
		    router_slot_t* slot = map_value_obtain (pslot);
		    // clone each message
		    bytecode_stream_t* message_copy = bytecode_stream_instantiate_toplevel(NULL);
		    message_copy->copy(message_copy, message);

		    TRACE2("sending event to slot: '%s'", 
			   atom_get_cstring_value(slot->name));
		    if(!router_route(slot, message_copy, context)) {
			WARNING2("route '%s' not defined.", 
				 atom_get_cstring_value(slot->name));
		    }
		}
		map_iterator_destroy (&i);
		map_iterator_retire (&i);

		bytecode_stream_retire (message);
	    } else {
		if(!router_route(get_slot(router, dest), message, context)) {
		    WARNING2("route '%s' not defined.", 
			     atom_get_cstring_value(dest));
		}
	    }
	}
    } else {
	message->push(message, selector);
	router->receive_backup(self, message, context);
    }
}
コード例 #4
0
ファイル: receiver.c プロジェクト: uucidl/plus-one-minus-one
static void receiver_eval_all_pending(receiver_t *self, context_t *context)
{
    map_iterator_t it;
    map_value_t pfifo;

    map_get_iterator(&self->fifos, &it);
    while (map_value_is_there(pfifo = map_iterator_next(&it))) {
        message_fifo_t *fifo = map_value_obtain(pfifo);
        self->eval_pending(self, fifo->atom, context);
    }
    map_iterator_destroy(&it);
    map_iterator_retire(&it);
}
コード例 #5
0
ファイル: malloc.c プロジェクト: chang-gyu/rtos
void malloc_statistics() {
	is_debug = false;
	
	printf("Caller                      Count             Size\n");
	MapIterator iter;
	map_iterator_init(&iter, statistics);
	while(map_iterator_has_next(&iter)) {
		MapEntry* entry = map_iterator_next(&iter);
		Stat* s = entry->data;
		if(s->count >= 2 || s->size > 2048)
			printf("%p %16ld %16ld\n", entry->key, s->count, s->size);
	}
	
	printf("usage: %ld/%ld\n", malloc_used(), malloc_total());
	printf("tracing: class: %ld total: %ld\n", map_size(statistics), map_size(tracing));
	printf("malloc/free count: %d - %d = %d\n", debug_malloc_count, debug_free_count, debug_malloc_count - debug_free_count);
	debug_malloc_count = debug_free_count = 0;
	
	is_debug = true;
}
コード例 #6
0
ファイル: receiver.c プロジェクト: uucidl/plus-one-minus-one
static message_node_t *receiver_peek_any_pending(receiver_t *self,
                                                 context_t *context)
{
    map_iterator_t it;
    message_node_t *head = NULL;
    map_value_t pfifo;

    /* find first occurence of next event in any fifo */
    map_get_iterator(&self->fifos, &it);
    while (map_value_is_there(pfifo = map_iterator_next(&it))) {
        message_fifo_t *fifo = map_value_obtain(pfifo);
        message_node_t *node = self->peek_pending(self, fifo->atom, context);
        if (head == NULL) {
            head = node;
        } else if (node && node->context->ms < head->context->ms) {
            head = node;
        }
    }
    map_iterator_destroy(&it);
    map_iterator_retire(&it);

    return head;
}
コード例 #7
0
ファイル: map.c プロジェクト: GNsunghokim/rtos
bool map_put(Map* map, void* key, void* data) {
	if(map->size + 1 > map->threshold) {
		// Create new map
		Map map2;
		size_t capacity = map->capacity * 2;
		map2.table = __malloc(sizeof(List*) * capacity, map->pool);
		if(!map2.table)
			return false;
		memset(map2.table, 0x0, sizeof(List*) * capacity);
		map2.capacity = capacity;
		map2.threshold = THRESHOLD(capacity);
		map2.size = 0;
		map2.hash = map->hash;
		map2.equals = map->equals;
		map2.pool = map->pool;
		
		// Copy
		MapIterator iter;
		map_iterator_init(&iter, map);
		while(map_iterator_has_next(&iter)) {
			MapEntry* entry = map_iterator_next(&iter);
			if(!map_put(&map2, entry->key, entry->data)) {
				destroy(&map2);
				return false;
			}
		}
		
		// Destory
		destroy(map);
		
		// Paste
		memcpy(map, &map2, sizeof(Map));
	}
	
	size_t index = map->hash(key) % map->capacity;
	if(!map->table[index]) {
		map->table[index] = list_create(map->pool);
		if(!map->table[index])
			return false;
	} else {
		size_t size = list_size(map->table[index]);
		for(size_t i = 0; i < size; i++) {
			MapEntry* entry = list_get(map->table[index], i);
			if(map->equals(entry->key, key))
				return false;
		}
	}
	
	MapEntry* entry = __malloc(sizeof(MapEntry), map->pool);
	if(!entry) {
		if(list_is_empty(map->table[index])) {
			list_destroy(map->table[index]);
			map->table[index] = NULL;
		}
		return false;
	}
	
	entry->key = key;
	entry->data = data;
	
	if(!list_add(map->table[index], entry)) {
		__free(entry, map->pool);
		if(list_is_empty(map->table[index])) {
			list_destroy(map->table[index]);
			map->table[index] = NULL;
		}

		return false;
	}
	map->size++;
	
	return true;
}