VM: simplifies the dispatch_resumable_signal() method

db4
Björn Lindqvist 2015-08-15 00:08:42 +02:00 committed by John Benediktsson
parent b8aef640f9
commit 1b1b275a1a
1 changed files with 13 additions and 16 deletions

View File

@ -13,8 +13,9 @@ void factor_vm::dispatch_non_resumable_signal(cell* sp, cell* pc,
signal_resumable = false; signal_resumable = false;
cell frame_top = ctx->callstack_top; cell frame_top = ctx->callstack_top;
cell seg_start = ctx->callstack_seg->start;
if (frame_top < ctx->callstack_seg->start) { if (frame_top < seg_start) {
/* The saved callstack pointer is outside the callstack /* The saved callstack pointer is outside the callstack
segment. That means that we need to carefully cut off one frame segment. That means that we need to carefully cut off one frame
first which hopefully should put the pointer within the first which hopefully should put the pointer within the
@ -28,7 +29,7 @@ void factor_vm::dispatch_non_resumable_signal(cell* sp, cell* pc,
frame that leaves room for the signal handler to do its thing, frame that leaves room for the signal handler to do its thing,
and launch the handler without going through the resumable and launch the handler without going through the resumable
subprimitive. */ subprimitive. */
FACTOR_ASSERT(ctx->callstack_seg->start <= frame_top); FACTOR_ASSERT(seg_start <= frame_top);
while (frame_top < ctx->callstack_bottom && frame_top < limit) { while (frame_top < ctx->callstack_bottom && frame_top < limit) {
frame_top = code->frame_predecessor(frame_top); frame_top = code->frame_predecessor(frame_top);
} }
@ -56,27 +57,23 @@ void factor_vm::dispatch_resumable_signal(cell* sp, cell* pc, cell handler) {
leafness by matching the PC to a word. We should also use leafness by matching the PC to a word. We should also use
FRAME_RETURN_ADDRESS instead of assuming the stack pointer is the FRAME_RETURN_ADDRESS instead of assuming the stack pointer is the
right place to put the resume address. */ right place to put the resume address. */
cell word_idx = 0; cell index = 0;
cell delta = 0;
if (offset == 0) { if (offset == 0) {
word_idx = SIGNAL_HANDLER_WORD; delta = sizeof(cell);
index = SIGNAL_HANDLER_WORD;
cell newsp = *sp - sizeof(cell);
*sp = newsp;
*(cell*)newsp = *pc;
} else if (offset == 16 - sizeof(cell)) { } else if (offset == 16 - sizeof(cell)) {
word_idx = LEAF_SIGNAL_HANDLER_WORD;
/* Make a fake frame for the leaf procedure */ /* Make a fake frame for the leaf procedure */
FACTOR_ASSERT(code->code_block_for_address(*pc) != NULL); FACTOR_ASSERT(code->code_block_for_address(*pc) != NULL);
delta = LEAF_FRAME_SIZE;
cell newsp = *sp - LEAF_FRAME_SIZE; index = LEAF_SIGNAL_HANDLER_WORD;
*sp = newsp;
*(cell*)newsp = *pc;
} else { } else {
FACTOR_ASSERT(false); FACTOR_ASSERT(false);
} }
tagged<word> handler_word = tagged<word>(special_objects[word_idx]); cell new_sp = *sp - delta;
*sp = new_sp;
*(cell*)new_sp = *pc;
tagged<word> handler_word = tagged<word>(special_objects[index]);
*pc = (cell)handler_word->entry_point; *pc = (cell)handler_word->entry_point;
} }