Exemplo n.º 1
0
void lookupall(NV *treep, int start, int end) {
	
	if (treep == NULL)
		return;
	
	if (treep->left && treep->left->max > start)
		lookupall(treep->left, start, end);
	if (isintersect(treep, start, end))
		printf("(%d, %d)\n", treep->start, treep->end);
	lookupall(treep->right, start, end);
}
/* Load a program into the vm and initialize its state. */
void load(struct _context* ctx, avm* vm, assembly* p )
{
	int i;
	symbol* s;
	if (!p) return;
	vm->ctx = ctx;
	vm->instructions = p->instructions;
	vm->numins = p->nextslot;
	vm->pc = p->entry;
	for (i=0; i<NUM_REGS; i++)
		seti(&vm->regs[i], 0);
	if ((vm->hs=(stack*)calloc(1, sizeof(stack))) == 0)
	{
		setvmerror(vm, ZEN_VM_OUT_OF_MEMORY);
		return;
	}
	vm->hs->size = p->stacksize;
	vm->hs->sbody = (word*)calloc(vm->hs->size, sizeof(word));
	vm->hs->fp = vm->hs->sp = 0;
	vm->cs = vm->hs;
	vm->lasterror = ZEN_NO_ERROR;
	initheap(vm, &vm->hp);
	s = lookupall(0, ctx, GLOBAL_NAME);
	vm->globalsize = s->localsize+s->tempsize;
	vm->regs[rs].entity.ival += vm->globalsize;
	vm->tot.size = ZEN_INITIALTOTSIZE;
	if (!(vm->tot.table = calloc(vm->tot.size, sizeof(pair))))
	{
		setvmerror(vm, ZEN_VM_OUT_OF_MEMORY);
		return;
	}
	vm->loaded = 1;
}
Exemplo n.º 3
0
int main() {
	int starts[] = { 7, 8, 2, 3, 6, 9};
	int ends[] = {9, 10, 3, 4, 8, 12};
	int i, n = 6;
	NV *itree = NULL, *p;
	
	for (i = 0; i < n; i++) {
		itree = insert(itree, newitem(starts[i], ends[i], NULL));
	}
	
	puts("\nlookupany");
	p = lookupany(itree, 5, 9);
	print_interval(p);
	
	puts("\nlookupall");
	lookupall(itree, 5, 9);
	
	return 0;
}