VM: refactoring to remove redundancy in retainstack|datastack_to_array
parent
0798928996
commit
6b29c0ea00
|
@ -174,26 +174,22 @@ void factor_vm::primitive_context_object_for() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
cell factor_vm::stack_to_array(cell bottom, cell top) {
|
cell factor_vm::stack_to_array(cell bottom, cell top, vm_error_type error) {
|
||||||
fixnum depth = (fixnum)(top - bottom + sizeof(cell));
|
fixnum depth = (fixnum)(top - bottom + sizeof(cell));
|
||||||
|
|
||||||
if (depth < 0)
|
if (depth < 0) {
|
||||||
return false_object;
|
general_error(error, false_object, false_object);
|
||||||
else {
|
|
||||||
array* a = allot_uninitialized_array<array>(depth / sizeof(cell));
|
|
||||||
memcpy(a + 1, (void*)bottom, depth);
|
|
||||||
return tag<array>(a);
|
|
||||||
}
|
}
|
||||||
|
array* a = allot_uninitialized_array<array>(depth / sizeof(cell));
|
||||||
|
memcpy(a + 1, (void*)bottom, depth);
|
||||||
|
return tag<array>(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
cell factor_vm::datastack_to_array(context* ctx) {
|
cell factor_vm::datastack_to_array(context* ctx) {
|
||||||
cell array = stack_to_array(ctx->datastack_seg->start, ctx->datastack);
|
return stack_to_array(ctx->datastack_seg->start,
|
||||||
if (array == false_object) {
|
ctx->datastack,
|
||||||
general_error(ERROR_DATASTACK_UNDERFLOW, false_object, false_object);
|
ERROR_DATASTACK_UNDERFLOW);
|
||||||
return false_object;
|
|
||||||
} else
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
|
@ -207,12 +203,9 @@ void factor_vm::primitive_datastack_for() {
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
cell factor_vm::retainstack_to_array(context* ctx) {
|
cell factor_vm::retainstack_to_array(context* ctx) {
|
||||||
cell array = stack_to_array(ctx->retainstack_seg->start, ctx->retainstack);
|
return stack_to_array(ctx->retainstack_seg->start,
|
||||||
if (array == false_object) {
|
ctx->retainstack,
|
||||||
general_error(ERROR_RETAINSTACK_UNDERFLOW, false_object, false_object);
|
ERROR_RETAINSTACK_UNDERFLOW);
|
||||||
return false_object;
|
|
||||||
} else
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
|
|
|
@ -164,7 +164,7 @@ struct factor_vm {
|
||||||
void primitive_context_object();
|
void primitive_context_object();
|
||||||
void primitive_context_object_for();
|
void primitive_context_object_for();
|
||||||
void primitive_set_context_object();
|
void primitive_set_context_object();
|
||||||
cell stack_to_array(cell bottom, cell top);
|
cell stack_to_array(cell bottom, cell top, vm_error_type error);
|
||||||
cell datastack_to_array(context* ctx);
|
cell datastack_to_array(context* ctx);
|
||||||
void primitive_datastack();
|
void primitive_datastack();
|
||||||
void primitive_datastack_for();
|
void primitive_datastack_for();
|
||||||
|
|
Loading…
Reference in New Issue