]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: change the definition of entry_point in word and quotation from void* to cell
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 7 Jan 2015 10:51:19 +0000 (11:51 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 15 Jan 2015 09:29:13 +0000 (09:29 +0000)
this gets rid of lots of redundant casts from void* to cell

20 files changed:
vm/callbacks.cpp
vm/callbacks.hpp
vm/callstack.cpp
vm/code_blocks.cpp
vm/code_blocks.hpp
vm/code_heap.cpp
vm/compaction.cpp
vm/cpu-ppc.hpp
vm/cpu-x86.hpp
vm/debug.cpp
vm/entry_points.cpp
vm/image.cpp
vm/inline_cache.cpp
vm/inline_cache.hpp
vm/instruction_operands.cpp
vm/layouts.hpp
vm/quotations.cpp
vm/safepoints.cpp
vm/vm.hpp
vm/words.cpp

index 5dde871fbd90c1eb166c450b97125b5d8b487ca4..f8bf247f99d8dc5ab850d10a1202956663c7fd13 100644 (file)
@@ -60,7 +60,7 @@ void callback_heap::store_callback_operand(code_block* stub, cell index,
 
 void callback_heap::update(code_block* stub) {
   store_callback_operand(stub, setup_seh_p() ? 2 : 1,
-                         (cell)callback_entry_point(stub));
+                         callback_entry_point(stub));
   stub->flush_icache();
 }
 
@@ -82,7 +82,7 @@ code_block* callback_heap::add(cell owner, cell return_rewind) {
   stub->parameters = false_object;
   stub->relocation = false_object;
 
-  memcpy(stub->entry_point(), insns->data<void>(), size);
+  memcpy((void*)stub->entry_point(), insns->data<void>(), size);
 
   /* Store VM pointer */
   store_callback_operand(stub, 0, (cell)parent);
@@ -131,9 +131,9 @@ void factor_vm::primitive_callback() {
 
   w.untag_check(this);
 
-  void* func = callbacks->add(w.value(), return_rewind)->entry_point();
+  cell func = callbacks->add(w.value(), return_rewind)->entry_point();
   CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
-  ctx->push(allot_alien(func));
+  ctx->push(allot_alien((void*)func));
 }
 
 void factor_vm::primitive_free_callback() {
index d841d17f49e0183dd6567982100d10d675721a06..e712521ee3b04aa76b9c8b392c3848630cb0e3ba 100644 (file)
@@ -31,7 +31,7 @@ struct callback_heap {
   callback_heap(cell size, factor_vm* parent);
   ~callback_heap();
 
-  void* callback_entry_point(code_block* stub) {
+  cell callback_entry_point(code_block* stub) {
     word* w = (word*)UNTAG(stub->owner);
     return w->entry_point;
   }
index af7c26f9071c5a8f2d8c7240c05abf5448fb4a85..d9766aea2ca4f8d5fbe6e1a6a0dc4c8dd5e0ca36 100644 (file)
@@ -105,15 +105,15 @@ Used by the single stepper. */
 void factor_vm::primitive_innermost_stack_frame_executing() {
   callstack* stack = untag_check<callstack>(ctx->peek());
   void* frame = stack->top();
-  void* addr = *(void**)frame;
-  ctx->replace(code->code_block_for_address((cell)addr)->owner_quot());
+  cell addr = *(cell*)frame;
+  ctx->replace(code->code_block_for_address(addr)->owner_quot());
 }
 
 void factor_vm::primitive_innermost_stack_frame_scan() {
   callstack* stack = untag_check<callstack>(ctx->peek());
   void* frame = stack->top();
   cell addr = *(cell*)frame;
-  ctx->replace(code->code_block_for_address((cell)addr)->scan(this, addr));
+  ctx->replace(code->code_block_for_address(addr)->scan(this, addr));
 }
 
 /* Allocates memory (jit_compile_quot) */
@@ -130,7 +130,7 @@ void factor_vm::primitive_set_innermost_stack_frame_quot() {
   cell addr = *(cell*)inner;
   code_block* block = code->code_block_for_address(addr);
   cell offset = block->offset(addr);
-  *(void**)inner = (char*)quot->entry_point + offset;
+  *(cell*)inner = quot->entry_point + offset;
 }
 
 /* Allocates memory (allot_alien) */
index 8524cfbb381a9afdd402f92cb543c1c83111c9b7..05c9f9ae5f9715547f2e25e8b398e9a081f9bcd3 100644 (file)
@@ -29,9 +29,9 @@ cell code_block::scan(factor_vm* vm, cell addr) const {
 cell factor_vm::compute_entry_point_address(cell obj) {
   switch (tagged<object>(obj).type()) {
     case WORD_TYPE:
-      return (cell)untag<word>(obj)->entry_point;
+      return untag<word>(obj)->entry_point;
     case QUOTATION_TYPE:
-      return (cell)untag<quotation>(obj)->entry_point;
+      return untag<quotation>(obj)->entry_point;
     default:
       critical_error("Expected word or quotation", obj);
       return 0;
@@ -40,13 +40,13 @@ cell factor_vm::compute_entry_point_address(cell obj) {
 
 cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) {
   if (!to_boolean(tagged_quot) || max_pic_size == 0)
-    return (cell)w->entry_point;
+    return w->entry_point;
   else {
     quotation* quot = untag<quotation>(tagged_quot);
     if (quot_compiled_p(quot))
-      return (cell)quot->entry_point;
+      return quot->entry_point;
     else
-      return (cell)w->entry_point;
+      return w->entry_point;
   }
 }
 
@@ -241,7 +241,7 @@ void factor_vm::store_external_address(instruction_operand op) {
       op.store_value(compute_dlsym_address(parameters, index));
       break;
     case RT_THIS:
-      op.store_value((cell)compiled->entry_point());
+      op.store_value(compiled->entry_point());
       break;
     case RT_MEGAMORPHIC_CACHE_HITS:
       op.store_value((cell)&dispatch_stats.megamorphic_cache_hits);
@@ -281,9 +281,9 @@ cell factor_vm::compute_here_address(cell arg, cell offset,
                                      code_block* compiled) {
   fixnum n = untag_fixnum(arg);
   if (n >= 0)
-    return (cell)compiled->entry_point() + offset + n;
+    return compiled->entry_point() + offset + n;
   else
-    return (cell)compiled->entry_point() - n;
+    return compiled->entry_point() - n;
 }
 
 struct initial_code_block_visitor {
@@ -359,7 +359,7 @@ void factor_vm::fixup_labels(array* labels, code_block* compiled) {
     relocation_entry new_entry(RT_HERE, rel_class, offset);
 
     instruction_operand op(new_entry, compiled, 0);
-    op.store_value(target + (cell)compiled->entry_point());
+    op.store_value(target + compiled->entry_point());
   }
 }
 
index b1ceab23e1b7bb523a3bdd795cf5a5dd7924b819..a08f78eb3ab363a1d7b3799802d0f00256efcc0c 100644 (file)
@@ -52,7 +52,7 @@ struct code_block {
        and a leaf procedure code block will record a frame size of zero.
        If we're seeing a stack frame in either of these cases, it's a
        fake "leaf frame" set up by the signal handler. */
-    if (natural_frame_size == 0 || (void*)addr == entry_point())
+    if (natural_frame_size == 0 || addr == entry_point())
       return LEAF_FRAME_SIZE;
     else
       return natural_frame_size;
@@ -68,7 +68,7 @@ struct code_block {
 
   template <typename Fixup> cell size(Fixup fixup) const { return size(); }
 
-  void* entry_point() const { return (void*)(this + 1); }
+  cell entry_point() const { return (cell)(this + 1); }
 
   /* GC info is stored at the end of the block */
   gc_info* block_gc_info() const {
@@ -92,10 +92,10 @@ struct code_block {
     }
   }
 
-  cell offset(cell addr) const { return addr - (cell)entry_point(); }
+  cell offset(cell addr) const { return addr - entry_point(); }
 
   cell address_for_offset(cell offset) const {
-    return (cell)((char*)entry_point() + offset);
+    return entry_point() + offset;
   }
 
   cell scan(factor_vm* vm, cell addr) const;
@@ -105,12 +105,12 @@ struct code_block {
 VM_C_API void undefined_symbol(void);
 
 inline code_block* word::code() const {
-  FACTOR_ASSERT(entry_point != NULL);
+  FACTOR_ASSERT(entry_point != 0);
   return (code_block*)entry_point - 1;
 }
 
 inline code_block* quotation::code() const {
-  FACTOR_ASSERT(entry_point != NULL);
+  FACTOR_ASSERT(entry_point != 0);
   return (code_block*)entry_point - 1;
 }
 
index ef4c3d42df091c6fa0bc1b809fbbac40229ace62..1338226f6d6b9fccb725e751cd4bd9a01c80d5f8 100644 (file)
@@ -103,10 +103,10 @@ code_block* code_heap::code_block_for_address(cell address) {
   FACTOR_ASSERT(blocki != all_blocks.begin());
   --blocki;
   code_block* found_block = (code_block*)*blocki;
-  FACTOR_ASSERT((cell)found_block->entry_point() <=
+  FACTOR_ASSERT(found_block->entry_point() <=
                 address /* XXX this isn't valid during fixup. should store the
                                size in the map
-                              && address - (cell)found_block->entry_point() <
+                              && address - found_block->entry_point() <
                                  found_block->size()*/);
   return found_block;
 }
@@ -251,7 +251,7 @@ struct code_block_accumulator {
        from_unsigned_cell() here. It is OK, however, to add it as
        if it were a fixnum, and have library code shift it to the
        left by 4. */
-    cell entry_point = (cell)compiled->entry_point();
+    cell entry_point = compiled->entry_point();
     FACTOR_ASSERT((entry_point & (data_alignment - 1)) == 0);
     FACTOR_ASSERT((entry_point & TAG_MASK) == FIXNUM_TYPE);
     objects.push_back(entry_point);
index 3cdd0070cee00d347ee61921b571cec6989cc9f1..b5104c5eb19d5bcc469d328ff0332092b665165a 100644 (file)
@@ -88,7 +88,7 @@ template <typename Fixup> struct code_block_compaction_relocation_visitor {
       : parent(parent), old_address(old_address), fixup(fixup) {}
 
   void operator()(instruction_operand op) {
-    cell old_offset = op.rel_offset() + (cell)old_address->entry_point();
+    cell old_offset = op.rel_offset() + old_address->entry_point();
 
     switch (op.rel_type()) {
       case RT_LITERAL: {
index 1cbafe4c5fe115330abffceeddf0d6719aeca1cb..89150dac51d9abab580c55b57f375f72c4624ee4 100644 (file)
@@ -37,13 +37,13 @@ inline static void* get_call_target(cell return_address) {
   return (void*)(signed_addr + return_address);
 }
 
-inline static void set_call_target(cell return_address, void* target) {
+inline static void set_call_target(cell return_address, cell target) {
   return_address -= 4;
   check_call_site(return_address);
 
   uint32_t insn = *(uint32_t*)return_address;
 
-  fixnum relative_address = ((cell)target - return_address);
+  fixnum relative_address = target - return_address;
   insn = ((insn & ~b_mask) | (relative_address & b_mask));
   *(uint32_t*)return_address = insn;
 
index 6e3cca788019e9b81382874fe3e67021eb972ba8..2d1ae42e85e00be828ab5bf3cad9c3fbcd1fb66c 100644 (file)
@@ -33,9 +33,9 @@ inline static void* get_call_target(cell return_address) {
   return (void*)(*(int*)(return_address - 4) + return_address);
 }
 
-inline static void set_call_target(cell return_address, void* target) {
+inline static void set_call_target(cell return_address, cell target) {
   check_call_site(return_address);
-  *(int*)(return_address - 4) = (uint32_t)((cell)target - return_address);
+  *(int*)(return_address - 4) = (uint32_t)(target - return_address);
 }
 
 inline static bool tail_call_site_p(cell return_address) {
index 218f21eba3768cdd5e250af040a2fd7111a44911..7d7312231e1019310fdbeebe189a354210dd7fc4 100644 (file)
@@ -200,10 +200,10 @@ struct stack_frame_printer {
     parent->print_obj(owner->scan(parent, addr));
     std::cout << std::endl;
     std::cout << "word/quot addr: ";
-    std::cout << std::hex << (cell)owner->owner << std::dec;
+    std::cout << std::hex << owner->owner << std::dec;
     std::cout << std::endl;
     std::cout << "word/quot xt: ";
-    std::cout << std::hex << (cell)owner->entry_point() << std::dec;
+    std::cout << std::hex << owner->entry_point() << std::dec;
     std::cout << std::endl;
     std::cout << "return address: ";
     std::cout << std::hex << addr << std::dec;
index d2b59fa35ff3826d544777e5b96efb73a3cecf05..41db6cc297f38360380b6a18ccb96b1ac8e220be 100644 (file)
@@ -10,7 +10,7 @@ void factor_vm::c_to_factor(cell quot) {
   if (!c_to_factor_func) {
     tagged<word> c_to_factor_word(special_objects[C_TO_FACTOR_WORD]);
     code_block* c_to_factor_block = callbacks->add(c_to_factor_word.value(), 0);
-    void* func = c_to_factor_block->entry_point();
+    cell func = c_to_factor_block->entry_point();
     CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
     c_to_factor_func = (c_to_factor_func_type) func;
   }
@@ -24,21 +24,21 @@ template <typename Func> Func factor_vm::get_entry_point(cell n) {
 
 void factor_vm::unwind_native_frames(cell quot, cell to) {
   tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
-  void* func = entry_point_word->entry_point;
+  cell func = entry_point_word->entry_point;
   CODE_TO_FUNCTION_POINTER(func);
   ((unwind_native_frames_func_type) func)(quot, to);
 }
 
 cell factor_vm::get_fpu_state() {
   tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]);
-  void* func = entry_point_word->entry_point;
+  cell func = entry_point_word->entry_point;
   CODE_TO_FUNCTION_POINTER(func);
   return ((get_fpu_state_func_type) func)();
 }
 
 void factor_vm::set_fpu_state(cell state) {
   tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]);
-  void* func = entry_point_word->entry_point;
+  cell func = entry_point_word->entry_point;
   CODE_TO_FUNCTION_POINTER(func);
   ((set_fpu_state_func_type) func)(state);
 }
index c0f78b9608090b6c7b22c26c1da1fda9859193be..bd76915c6ff6cd188270abec510b8f065b0d5e60 100644 (file)
@@ -140,7 +140,7 @@ struct startup_code_block_relocation_visitor {
   void operator()(instruction_operand op) {
     code_block* compiled = op.compiled;
     cell old_offset =
-        op.rel_offset() + (cell)compiled->entry_point() - fixup.code_offset;
+        op.rel_offset() + compiled->entry_point() - fixup.code_offset;
 
     switch (op.rel_type()) {
       case RT_LITERAL: {
index 9c2929949869bbf0dc3ceb8606592dff941ce7eb..adf7210f564d3dc8d427f28aca0e6b82ef08aaf2 100644 (file)
@@ -164,7 +164,7 @@ void factor_vm::update_pic_transitions(cell pic_size) {
    also, the block containing the return address may now be dead. Use a
    code_root to take care of the details. */
 /* Allocates memory */
-void* factor_vm::inline_cache_miss(cell return_address_) {
+cell factor_vm::inline_cache_miss(cell return_address_) {
   code_root return_address(return_address_, this);
   bool tail_call_site = tail_call_site_p(return_address.value);
 
@@ -185,7 +185,7 @@ void* factor_vm::inline_cache_miss(cell return_address_) {
 
   update_pic_transitions(pic_size);
 
-  void* xt;
+  cell xt;
 
   if (pic_size >= max_pic_size)
     xt = generic_word->entry_point;
@@ -221,7 +221,7 @@ void* factor_vm::inline_cache_miss(cell return_address_) {
 }
 
 /* Allocates memory */
-VM_C_API void* inline_cache_miss(cell return_address, factor_vm* parent) {
+VM_C_API cell inline_cache_miss(cell return_address, factor_vm* parent) {
   return parent->inline_cache_miss(return_address);
 }
 
index fbb60d7544c99b2bf5e4efea92d9e910acca8095..836f5552c37ad327720d5ffa8186314a9b889ca7 100644 (file)
@@ -1,5 +1,5 @@
 namespace factor {
 
-VM_C_API void* inline_cache_miss(cell return_address, factor_vm* vm);
+VM_C_API cell inline_cache_miss(cell return_address, factor_vm* vm);
 
 }
index 93f190eb68e8b4949e3f5c935a62b292eba29f6f..460d1f0c3709a71b6d9ef6f52a2e146a8e23fb58 100644 (file)
@@ -7,7 +7,7 @@ instruction_operand::instruction_operand(relocation_entry rel,
     : rel(rel),
       compiled(compiled),
       index(index),
-      pointer((cell)compiled->entry_point() + rel.rel_offset()) {}
+      pointer(compiled->entry_point() + rel.rel_offset()) {}
 
 /* Load a 32-bit value from a PowerPC LIS/ORI sequence */
 fixnum instruction_operand::load_value_2_2() {
@@ -159,7 +159,7 @@ void instruction_operand::store_value(fixnum absolute_value) {
 }
 
 void instruction_operand::store_code_block(code_block* compiled) {
-  store_value((cell)compiled->entry_point());
+  store_value(compiled->entry_point());
 }
 
 }
index 3622963a789efc4b542bc21bb7cbee0d61ce9052..2bd409e11c0d7ce6ce469154714fa8e5c3bc3876 100644 (file)
@@ -228,7 +228,7 @@ struct word : public object {
   /* TAGGED machine code for sub-primitive */
   cell subprimitive;
   /* UNTAGGED entry point: jump here to execute word */
-  void* entry_point;
+  cell entry_point;
   /* UNTAGGED compiled code block */
 
   /* defined in code_blocks.hpp */
@@ -266,7 +266,7 @@ struct quotation : public object {
   /* tagged */
   cell cache_counter;
   /* UNTAGGED entry point; jump here to call quotation */
-  void* entry_point;
+  cell entry_point;
 
   /* defined in code_blocks.hpp */
   code_block* code() const;
index c5a480d05ba3cb9ad22aac9b8d03cf060b4e07d1..8deeecdeb283cd0bd79733e1ea203d5e159095b3 100644 (file)
@@ -331,7 +331,7 @@ void factor_vm::jit_compile_quot(cell quot_, bool relocating) {
 /* Allocates memory */
 void factor_vm::primitive_jit_compile() { jit_compile_quot(ctx->pop(), true); }
 
-void* factor_vm::lazy_jit_compile_entry_point() {
+cell factor_vm::lazy_jit_compile_entry_point() {
   return untag<word>(special_objects[LAZY_JIT_COMPILE_WORD])->entry_point;
 }
 
@@ -352,7 +352,7 @@ void factor_vm::primitive_array_to_quotation() {
 void factor_vm::primitive_quotation_code() {
   data_root<quotation> quot(ctx->pop(), this);
 
-  ctx->push(from_unsigned_cell((cell)quot->entry_point));
+  ctx->push(from_unsigned_cell(quot->entry_point));
   ctx->push(from_unsigned_cell((cell)quot->code() + quot->code()->size()));
 }
 
@@ -387,7 +387,7 @@ VM_C_API cell lazy_jit_compile(cell quot, factor_vm* parent) {
 }
 
 bool factor_vm::quot_compiled_p(quotation* quot) {
-  return quot->entry_point != NULL &&
+  return quot->entry_point != 0 &&
          quot->entry_point != lazy_jit_compile_entry_point();
 }
 
index 53e198db811117ffb0d836382bc88189ef3d072c..0970d60331f7411ac811a631c6302d25007cc430 100644 (file)
@@ -44,7 +44,7 @@ void safepoint_state::handle_safepoint(factor_vm* parent, cell pc) volatile {
   } else if (atomic::load(&parent->sampling_profiler_p)) {
     FACTOR_ASSERT(parent->code->seg->in_segment_p(pc));
     code_block* block = parent->code->code_block_for_address(pc);
-    bool prolog_p = (cell)block->entry_point() == pc;
+    bool prolog_p = block->entry_point() == pc;
 
     parent->record_sample(prolog_p);
   }
index 4d0f2e153b67ac82c5b5d1474451b623832c829b..15ce00b534726954bd07e6ab326467f56e9dbb62 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -673,7 +673,7 @@ struct factor_vm {
 
   // quotations
   void primitive_jit_compile();
-  void* lazy_jit_compile_entry_point();
+  cell lazy_jit_compile_entry_point();
   void primitive_array_to_quotation();
   void primitive_quotation_code();
   code_block* jit_compile_quot(cell owner_, cell quot_, bool relocating);
@@ -711,7 +711,7 @@ struct factor_vm {
   cell inline_cache_size(cell cache_entries);
   cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
   void update_pic_transitions(cell pic_size);
-  void* inline_cache_miss(cell return_address);
+  cell inline_cache_miss(cell return_address);
 
   // entry points
   void c_to_factor(cell quot);
index 7b7e4e8e052f91768b34f45025a2fbb2994abfb2..68daf0732a9c886d3fd8f52e9ec932947f5058dc 100644 (file)
@@ -55,7 +55,7 @@ word* factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) {
   new_word->pic_def = false_object;
   new_word->pic_tail_def = false_object;
   new_word->subprimitive = false_object;
-  new_word->entry_point = NULL;
+  new_word->entry_point = 0;
 
   jit_compile_word(new_word.value(), new_word->def, true);
 
@@ -77,7 +77,7 @@ void factor_vm::primitive_word_code() {
   data_root<word> w(ctx->pop(), this);
   w.untag_check(this);
 
-  ctx->push(from_unsigned_cell((cell)w->entry_point));
+  ctx->push(from_unsigned_cell(w->entry_point));
   ctx->push(from_unsigned_cell((cell)w->code() + w->code()->size()));
 }