VM: change type of callstack_top and callstack_bottom from void* to cell

cell and void* is always the same size, but now you can remove lots of
redundant type casts from void* to cell.
db4
Björn Lindqvist 2015-01-05 12:59:54 +01:00
parent a6e191a490
commit e47181e87a
11 changed files with 35 additions and 35 deletions

View File

@ -17,10 +17,10 @@ This means that if 'callstack' is called in tail position, we
will have popped a necessary frame... however this word is only will have popped a necessary frame... however this word is only
called by continuation implementation, and user code shouldn't called by continuation implementation, and user code shouldn't
be calling it at all, so we leave it as it is for now. */ be calling it at all, so we leave it as it is for now. */
void* factor_vm::second_from_top_stack_frame(context* ctx) { cell factor_vm::second_from_top_stack_frame(context* ctx) {
void* frame_top = ctx->callstack_top; cell frame_top = ctx->callstack_top;
for (cell i = 0; i < 2; ++i) { for (cell i = 0; i < 2; ++i) {
void* pred = frame_predecessor(frame_top); cell pred = frame_predecessor(frame_top);
if (pred >= ctx->callstack_bottom) if (pred >= ctx->callstack_bottom)
return frame_top; return frame_top;
frame_top = pred; frame_top = pred;
@ -30,13 +30,13 @@ void* factor_vm::second_from_top_stack_frame(context* ctx) {
/* Allocates memory (allot_callstack) */ /* Allocates memory (allot_callstack) */
cell factor_vm::capture_callstack(context* ctx) { cell factor_vm::capture_callstack(context* ctx) {
void* top = second_from_top_stack_frame(ctx); cell top = second_from_top_stack_frame(ctx);
void* bottom = ctx->callstack_bottom; cell bottom = ctx->callstack_bottom;
fixnum size = std::max((fixnum)0, (fixnum)bottom - (fixnum)top); fixnum size = std::max((cell)0, bottom - top);
callstack* stack = allot_callstack(size); callstack* stack = allot_callstack(size);
memcpy(stack->top(), top, size); memcpy(stack->top(), (void *)top, size);
return tag<callstack>(stack); return tag<callstack>(stack);
} }
@ -49,12 +49,12 @@ void factor_vm::primitive_callstack_for() {
ctx->replace(capture_callstack(other_ctx)); ctx->replace(capture_callstack(other_ctx));
} }
void* factor_vm::frame_predecessor(void* frame_top) { cell factor_vm::frame_predecessor(cell frame_top) {
void* addr = *(void**)frame_top; cell addr = *(cell*)frame_top;
FACTOR_ASSERT(addr != 0); FACTOR_ASSERT(addr != 0);
code_block* owner = code->code_block_for_address((cell)addr); code_block* owner = code->code_block_for_address(addr);
cell frame_size = owner->stack_frame_size_for_address((cell)addr); cell frame_size = owner->stack_frame_size_for_address(addr);
return (void*)((char*)frame_top + frame_size); return frame_top + frame_size;
} }
struct stack_frame_accumulator { struct stack_frame_accumulator {

View File

@ -43,9 +43,9 @@ template <typename Iterator, typename Fixup>
inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator, inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
Fixup& fixup) { Fixup& fixup) {
char* frame_top = (char*)ctx->callstack_top; cell frame_top = ctx->callstack_top;
while (frame_top < (char*)ctx->callstack_bottom) { while (frame_top < ctx->callstack_bottom) {
void* addr = *(void**)frame_top; void* addr = *(void**)frame_top;
FACTOR_ASSERT(addr != 0); FACTOR_ASSERT(addr != 0);
void* fixed_addr = Fixup::translated_code_block_map void* fixed_addr = Fixup::translated_code_block_map
@ -62,7 +62,7 @@ inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
void* fixed_addr_for_iter = void* fixed_addr_for_iter =
Fixup::translated_code_block_map ? fixed_addr : addr; Fixup::translated_code_block_map ? fixed_addr : addr;
iterator(frame_top, frame_size, owner, fixed_addr_for_iter); iterator((void*)frame_top, frame_size, owner, fixed_addr_for_iter);
frame_top += frame_size; frame_top += frame_size;
} }
} }

View File

@ -473,14 +473,13 @@ struct find_symbol_at_address_visitor {
/* References to undefined symbols are patched up to call this function on /* References to undefined symbols are patched up to call this function on
image load. It finds the symbol and library, and throws an error. */ image load. It finds the symbol and library, and throws an error. */
void factor_vm::undefined_symbol() { void factor_vm::undefined_symbol() {
void* frame = ctx->callstack_top; cell frame = ctx->callstack_top;
void* return_address = *(void**)frame; cell return_address = *(cell*)frame;
code_block* compiled = code->code_block_for_address((cell)return_address); code_block* compiled = code->code_block_for_address(return_address);
find_symbol_at_address_visitor visitor(this, (cell)return_address); find_symbol_at_address_visitor visitor(this, return_address);
compiled->each_instruction_operand(visitor); compiled->each_instruction_operand(visitor);
if (!to_boolean(visitor.symbol)) if (!to_boolean(visitor.symbol))
critical_error("Can't find RT_DLSYM at return address", critical_error("Can't find RT_DLSYM at return address", return_address);
(cell)return_address);
else else
general_error(ERROR_UNDEFINED_SYMBOL, visitor.symbol, visitor.library); general_error(ERROR_UNDEFINED_SYMBOL, visitor.symbol, visitor.library);
} }

View File

@ -4,8 +4,8 @@ namespace factor {
context::context(cell datastack_size, cell retainstack_size, context::context(cell datastack_size, cell retainstack_size,
cell callstack_size) cell callstack_size)
: callstack_top(NULL), : callstack_top(0),
callstack_bottom(NULL), callstack_bottom(0),
datastack(0), datastack(0),
retainstack(0), retainstack(0),
callstack_save(0), callstack_save(0),

View File

@ -19,8 +19,8 @@ struct context {
// First 4 fields accessed directly by compiler. See basis/vm/vm.factor // First 4 fields accessed directly by compiler. See basis/vm/vm.factor
/* Factor callstack pointers */ /* Factor callstack pointers */
void* callstack_top; cell callstack_top;
void* callstack_bottom; cell callstack_bottom;
/* current datastack top pointer */ /* current datastack top pointer */
cell datastack; cell datastack;

View File

@ -6,7 +6,7 @@ namespace factor {
#define FACTOR_CPU_STRING "ppc.32" #define FACTOR_CPU_STRING "ppc.32"
#endif #endif
#define CALLSTACK_BOTTOM(ctx) (void*)(ctx->callstack_seg->end - 32) #define CALLSTACK_BOTTOM(ctx) (ctx->callstack_seg->end - 32)
/* In the instruction sequence: /* In the instruction sequence:

View File

@ -12,14 +12,15 @@ void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {
and launch the handler without going through the resumable and launch the handler without going through the resumable
subprimitive. */ subprimitive. */
signal_resumable = false; signal_resumable = false;
void* frame_top = (void*)ctx->callstack_top;
cell frame_top = ctx->callstack_top;
while (frame_top < ctx->callstack_bottom && while (frame_top < ctx->callstack_bottom &&
(cell)frame_top < ctx->callstack_seg->start + stack_reserved) { frame_top < ctx->callstack_seg->start + stack_reserved) {
frame_top = frame_predecessor(frame_top); frame_top = frame_predecessor(frame_top);
} }
*sp = (cell)frame_top; *sp = frame_top;
ctx->callstack_top = frame_top; ctx->callstack_top = frame_top;
*pc = handler; *pc = handler;
} else { } else {

View File

@ -1,7 +1,7 @@
namespace factor { namespace factor {
#define CALLSTACK_BOTTOM(ctx) \ #define CALLSTACK_BOTTOM(ctx) \
(void*)(ctx->callstack_seg->end - sizeof(cell) * 5) (ctx->callstack_seg->end - sizeof(cell) * 5)
inline static void flush_icache(cell start, cell len) {} inline static void flush_icache(cell start, cell len) {}

View File

@ -22,7 +22,7 @@ template <typename Func> Func factor_vm::get_entry_point(cell n) {
return (Func) entry_point_word->entry_point; return (Func) entry_point_word->entry_point;
} }
void factor_vm::unwind_native_frames(cell quot, void* to) { void factor_vm::unwind_native_frames(cell quot, cell to) {
tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]); tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
void* func = entry_point_word->entry_point; void* func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func); CODE_TO_FUNCTION_POINTER(func);

View File

@ -1,7 +1,7 @@
namespace factor { namespace factor {
typedef void (*c_to_factor_func_type)(cell quot); typedef void (*c_to_factor_func_type)(cell quot);
typedef void (*unwind_native_frames_func_type)(cell quot, void* to); typedef void (*unwind_native_frames_func_type)(cell quot, cell to);
typedef cell (*get_fpu_state_func_type)(); typedef cell (*get_fpu_state_func_type)();
typedef void (*set_fpu_state_func_type)(cell state); typedef void (*set_fpu_state_func_type)(cell state);

View File

@ -638,11 +638,11 @@ struct factor_vm {
void iterate_callstack_object(callstack* stack_, Iterator& iterator); void iterate_callstack_object(callstack* stack_, Iterator& iterator);
callstack* allot_callstack(cell size); callstack* allot_callstack(cell size);
void* second_from_top_stack_frame(context* ctx); cell second_from_top_stack_frame(context* ctx);
cell capture_callstack(context* ctx); cell capture_callstack(context* ctx);
void primitive_callstack(); void primitive_callstack();
void primitive_callstack_for(); void primitive_callstack_for();
void* frame_predecessor(void* frame); cell frame_predecessor(cell frame_top);
void primitive_callstack_to_array(); void primitive_callstack_to_array();
void primitive_innermost_stack_frame_executing(); void primitive_innermost_stack_frame_executing();
void primitive_innermost_stack_frame_scan(); void primitive_innermost_stack_frame_scan();
@ -716,7 +716,7 @@ struct factor_vm {
// entry points // entry points
void c_to_factor(cell quot); void c_to_factor(cell quot);
template <typename Func> Func get_entry_point(cell n); template <typename Func> Func get_entry_point(cell n);
void unwind_native_frames(cell quot, void* to); void unwind_native_frames(cell quot, cell to);
cell get_fpu_state(); cell get_fpu_state();
void set_fpu_state(cell state); void set_fpu_state(cell state);