Beispiel #1
0
int *
merge(int *p, int plen, int *q, int qlen)
{
	Node *merged = NULL;
	int *pend = p + plen;
	int *qend = q + qlen;
	while (p < pend && q < qend) {
		if (*p <= *q) {
			debug("Pushing: %d\n", *p);
			merged = stack_push(merged, *p);
			p++;
		} else {
			debug("Pushing: %d\n", *q);
			merged = stack_push(merged, *q);
			q++;
		}
	}
	while (p < pend) {
		debug("Pushing: %d\n", *p);
		merged = stack_push(merged, *p);
		p++;
	}
	while (q < qend) {
		debug("Pushing: %d\n", *q);
		merged = stack_push(merged, *q);
		q++;
	}
	return stack_to_array(merged, plen + qlen, 0);
}
Beispiel #2
0
int
test_stack(int argc, char *argv[])
{
	Node *t = NULL;
	t = stack_push(stack_push(stack_push(stack_push(stack_push(t, 1), 2), 3), 4), 5);
	print_array(stack_to_array(t, 5, 0), 5);
}
Beispiel #3
0
cell factor_vm::retainstack_to_array(context* ctx) {
  cell array = stack_to_array(ctx->retainstack_seg->start, ctx->retainstack);
  if (array == false_object) {
    general_error(ERROR_RETAINSTACK_UNDERFLOW, false_object, false_object);
    return false_object;
  } else
    return array;
}
Beispiel #4
0
/* Allocates memory */
cell factor_vm::retainstack_to_array(context* ctx) {
  return stack_to_array(ctx->retainstack_seg->start,
                        ctx->retainstack,
                        ERROR_RETAINSTACK_UNDERFLOW);
}
Beispiel #5
0
/* Allocates memory */
cell factor_vm::datastack_to_array(context* ctx) {
  return stack_to_array(ctx->datastack_seg->start,
                        ctx->datastack,
                        ERROR_DATASTACK_UNDERFLOW);
}
Beispiel #6
0
void factor_vm::primitive_retainstack()
{
	if(!stack_to_array(rs_bot,rs))
		general_error(ERROR_RS_UNDERFLOW,false_object,false_object,NULL);
}
Beispiel #7
0
void factor_vm::primitive_datastack()
{
	if(!stack_to_array(ds_bot,ds))
		general_error(ERROR_DS_UNDERFLOW,false_object,false_object,NULL);
}