]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: replace assert with FACTOR_ASSERT
authorJoe Groff <arcata@gmail.com>
Fri, 18 Nov 2011 04:42:30 +0000 (20:42 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 23 Nov 2011 19:11:26 +0000 (11:11 -0800)
Factor is finally a real C++ project and has a custom assert macro. Assertion failures were still getting caught as exceptions and causing failure loops. Write our own macro that calls factor::abort on failure.

39 files changed:
GNUmakefile
vm/allot.hpp
vm/arrays.hpp
vm/assert.hpp [new file with mode: 0644]
vm/callstack.cpp
vm/code_blocks.cpp
vm/code_blocks.hpp
vm/code_heap.cpp
vm/code_roots.hpp
vm/contexts.cpp
vm/cpu-ppc.hpp
vm/cpu-x86.cpp
vm/cpu-x86.hpp
vm/data_heap.cpp
vm/data_roots.hpp
vm/debug.cpp
vm/free_list.hpp
vm/free_list_allocator.hpp
vm/gc.cpp
vm/generic_arrays.hpp
vm/jit.cpp
vm/layouts.hpp
vm/mach_signal.cpp
vm/mark_bits.hpp
vm/master.hpp
vm/mvm-none.cpp
vm/mvm.hpp
vm/object_start_map.cpp
vm/os-unix.cpp
vm/os-windows.cpp
vm/os-windows.hpp
vm/quotations.cpp
vm/run.cpp
vm/run.hpp
vm/safepoints.cpp
vm/sampling_profiler.cpp
vm/slot_visitor.hpp
vm/tagged.hpp
vm/vm.hpp

index 955a310e126b2b8d770abddebad7fb4cc3011323..6e7bcc69dce50c242f3479ab265af70f96e656ef 100755 (executable)
@@ -68,6 +68,7 @@ ifdef CONFIG
                vm/words.o
 
        MASTER_HEADERS = $(PLAF_MASTER_HEADERS) \
+               vm/assert.hpp \
                vm/layouts.hpp \
                vm/platform.hpp \
                vm/primitives.hpp \
index 9a7c898efa09689b08058aaee6554679e3cec503..3a4e2dc2f86c422ff2c477aa9568444c226c0cf3 100644 (file)
@@ -8,7 +8,7 @@ namespace factor
 inline object *factor_vm::allot_object(cell type, cell size)
 {
 #ifdef FACTOR_DEBUG
-       assert(!current_gc);
+       FACTOR_ASSERT(!current_gc);
 #endif
 
        /* If the object is smaller than the nursery, allocate it in the nursery,
index 5d6a0445fdd285b7d127e599cbbcf6ffb68ad765..e374b97659dde9bce5bb03208c372f81183d747d 100755 (executable)
@@ -4,8 +4,8 @@ namespace factor
 inline cell array_nth(array *array, cell slot)
 {
 #ifdef FACTOR_DEBUG
-       assert(slot < array_capacity(array));
-       assert(array->type() == ARRAY_TYPE);
+       FACTOR_ASSERT(slot < array_capacity(array));
+       FACTOR_ASSERT(array->type() == ARRAY_TYPE);
 #endif
        return array->data()[slot];
 }
@@ -13,8 +13,8 @@ inline cell array_nth(array *array, cell slot)
 inline void factor_vm::set_array_nth(array *array, cell slot, cell value)
 {
 #ifdef FACTOR_DEBUG
-       assert(slot < array_capacity(array));
-       assert(array->type() == ARRAY_TYPE);
+       FACTOR_ASSERT(slot < array_capacity(array));
+       FACTOR_ASSERT(array->type() == ARRAY_TYPE);
 #endif
        cell *slot_ptr = &array->data()[slot];
        *slot_ptr = value;
diff --git a/vm/assert.hpp b/vm/assert.hpp
new file mode 100644 (file)
index 0000000..e45fdda
--- /dev/null
@@ -0,0 +1,16 @@
+namespace factor
+{
+    void abort();
+}
+
+#ifndef NDEBUG
+#define FACTOR_ASSERT(condition) ((condition) \
+    ? (void)0 \
+    : ( \
+        ::fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d\n", \
+            #condition, __FILE__, __LINE__), \
+        ::factor::abort() \
+    ))
+#else
+#define FACTOR_ASSERT(condition) ((void)0)
+#endif
index 0be681d41c80d44c83dcbdfeffb6385fce3f65f0..58e1a364d748d47d2ce48d2e39765f0706e86c01 100755 (executable)
@@ -7,7 +7,7 @@ void factor_vm::check_frame(stack_frame *frame)
 {
 #ifdef FACTOR_DEBUG
        check_code_pointer((cell)frame->entry_point);
-       assert(frame->size != 0);
+       FACTOR_ASSERT(frame->size != 0);
 #endif
 }
 
index b636777a672b4f7540878d4a9fa7fcea2d6eaf74..00bfac513396826db49909ecbf731309d07a7c1f 100755 (executable)
@@ -54,8 +54,8 @@ cell factor_vm::code_block_owner(code_block *compiled)
                tagged<quotation> quot(owner.as<quotation>());
                tagged<array> elements(quot->array);
 #ifdef FACTOR_DEBUG
-               assert(array_capacity(elements.untagged()) == 5);
-               assert(array_nth(elements.untagged(),4) == special_objects[PIC_MISS_WORD]
+               FACTOR_ASSERT(array_capacity(elements.untagged()) == 5);
+               FACTOR_ASSERT(array_nth(elements.untagged(),4) == special_objects[PIC_MISS_WORD]
                        || array_nth(elements.untagged(),4) == special_objects[PIC_MISS_TAIL_WORD]);
 #endif
                tagged<wrapper> word_wrapper(array_nth(elements.untagged(),0));
index c0f076836bbb406f132054f4fc3ed75fde959c29..8c3a6c1c8001abe4d89450668c7db5906ef83452 100644 (file)
@@ -38,7 +38,7 @@ struct code_block
        {
                cell size = header & ~7;
 #ifdef FACTOR_DEBUG
-               assert(size > 0);
+               FACTOR_ASSERT(size > 0);
 #endif
                return size;
        }
@@ -86,12 +86,12 @@ struct code_block
 VM_C_API void undefined_symbol(void);
 
 inline code_block *word::code() const {
-       assert(entry_point != NULL);
+       FACTOR_ASSERT(entry_point != NULL);
        return (code_block*)entry_point - 1;
 }
 
 inline code_block *quotation::code() const {
-       assert(entry_point != NULL);
+       FACTOR_ASSERT(entry_point != NULL);
        return (code_block*)entry_point - 1;
 }
 
index 737f3cc837caf52881786413f54dba582d62c062..f98ebb5fd9fefd1243dd7369edcc34d268b309b8 100755 (executable)
@@ -60,7 +60,7 @@ void code_heap::clear_mark_bits()
 
 void code_heap::free(code_block *compiled)
 {
-       assert(!uninitialized_p(compiled));
+       FACTOR_ASSERT(!uninitialized_p(compiled));
        points_to_nursery.erase(compiled);
        points_to_aging.erase(compiled);
        all_blocks.erase(compiled);
@@ -76,10 +76,10 @@ code_block *code_heap::code_block_for_address(cell address)
 {
        std::set<code_block*>::const_iterator blocki =
                all_blocks.upper_bound((code_block*)address);
-       assert(blocki != all_blocks.begin());
+       FACTOR_ASSERT(blocki != all_blocks.begin());
        --blocki;
        code_block* found_block = *blocki;
-       assert((cell)found_block->entry_point() <= address
+       FACTOR_ASSERT((cell)found_block->entry_point() <= address
                && address - (cell)found_block->entry_point() < found_block->size());
        return found_block;
 }
@@ -265,8 +265,8 @@ struct code_block_accumulator {
                if it were a fixnum, and have library code shift it to the
                left by 4. */
                cell entry_point = (cell)compiled->entry_point();
-               assert((entry_point & (data_alignment - 1)) == 0);
-               assert((entry_point & TAG_MASK) == FIXNUM_TYPE);
+               FACTOR_ASSERT((entry_point & (data_alignment - 1)) == 0);
+               FACTOR_ASSERT((entry_point & TAG_MASK) == FIXNUM_TYPE);
                objects.push_back(entry_point);
        }
 };
index 64f2b0c0ed9eff1df50b07dd9e6e2d7db56fe81c..9b3075270841cbdb74df882dd1c6ba88d1e984b8 100644 (file)
@@ -20,7 +20,7 @@ struct code_root {
        ~code_root()
        {
 #ifdef FACTOR_DEBUG
-               assert(parent->code_roots.back() == this);
+               FACTOR_ASSERT(parent->code_roots.back() == this);
 #endif
                parent->code_roots.pop_back();
        }
index b31c42f0f487717966003aca6d41bd2353cde7dd..fc10e3d8c82638453bd563ba2e9f6e5fcb47cb34 100644 (file)
@@ -110,7 +110,7 @@ void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_, cell
 
 void factor_vm::delete_contexts()
 {
-       assert(!ctx);
+       FACTOR_ASSERT(!ctx);
        std::list<context *>::const_iterator iter = unused_contexts.begin();
        std::list<context *>::const_iterator end = unused_contexts.end();
        while(iter != end)
index 80eb7fb1d843e6dbbb32e7207101ec021bc6e30b..abaa965065cdc2bc494ce36633c05d0156dbacbf 100644 (file)
@@ -22,9 +22,9 @@ inline static void check_call_site(cell return_address)
 {
        u32 insn = *(u32 *)return_address;
        /* Check that absolute bit is 0 */
-       assert((insn & 0x2) == 0x0);
+       FACTOR_ASSERT((insn & 0x2) == 0x0);
        /* Check that instruction is branch */
-       assert((insn >> 26) == 0x12);
+       FACTOR_ASSERT((insn >> 26) == 0x12);
 }
 
 static const u32 b_mask = 0x3fffffc;
index 003d8e198071119c8df5e9d09b096cfc575b0d68..28b289e34c91502d7305b58702b34e185feabda6 100644 (file)
@@ -51,7 +51,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
                {
                        // Make a fake frame for the leaf procedure
                        code_block *leaf_block = code->code_block_for_address(*pc);
-                       assert(leaf_block != NULL);
+                       FACTOR_ASSERT(leaf_block != NULL);
 
                        cell newsp = *sp - 4*sizeof(cell);
                        *(cell*)(newsp + 3*sizeof(cell)) = 4*sizeof(cell);
@@ -61,7 +61,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
                        handler_word = tagged<word>(special_objects[LEAF_SIGNAL_HANDLER_WORD]);
                }
                else
-                       assert(false);
+                       FACTOR_ASSERT(false);
 
                *pc = (cell)handler_word->entry_point;
        }
index 89d7fb792afd7eb435f592e3af93a465453412bf..e30aeab6e6e913d41af3c1d955b014185543a649 100755 (executable)
@@ -1,5 +1,3 @@
-#include <assert.h>
-
 namespace factor
 {
 
@@ -30,7 +28,7 @@ inline static unsigned char call_site_opcode(cell return_address)
 inline static void check_call_site(cell return_address)
 {
        unsigned char opcode = call_site_opcode(return_address);
-       assert(opcode == call_opcode || opcode == jmp_opcode);
+       FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode);
 }
 
 inline static void *get_call_target(cell return_address)
index 08f3e929cad25f7b3bc96a52d21de225b4df6020..ddd39d221aa1b32cdb83058b111abdc707193851 100755 (executable)
@@ -43,7 +43,7 @@ data_heap::data_heap(cell young_size_,
 
        nursery = new nursery_space(young_size,aging_semispace->end);
 
-       assert(seg->end - nursery->end <= deck_size);
+       FACTOR_ASSERT(seg->end - nursery->end <= deck_size);
 }
 
 data_heap::~data_heap()
index 8e366a7cfd7c514af73718feb9d2fa57a9ec10bd..35b83cf7e7412ffa980b7f65567190620f2f96e8 100644 (file)
@@ -45,7 +45,7 @@ struct gc_bignum {
        ~gc_bignum()
        {
 #ifdef FACTOR_DEBUG
-               assert(parent->bignum_roots.back() == (cell)addr);
+               FACTOR_ASSERT(parent->bignum_roots.back() == (cell)addr);
 #endif
                parent->bignum_roots.pop_back();
        }
index ca00580158a88b3645a47e4a8db536f5c680e70b..9ca7691e9e0f840339b2c2c53207ee0ad0af5413 100755 (executable)
@@ -586,7 +586,7 @@ void factor_vm::factorbug()
                {
                        exit_fep(this);
                        general_error(ERROR_INTERRUPT,false_object,false_object);
-                       assert(false);
+                       FACTOR_ASSERT(false);
                }
                else if(strcmp(cmd,"data") == 0)
                        dump_objects(TYPE_COUNT);
index 3fb06babc9a8c7c6f7bbee0533a2e101fc80872f..e8def2f4c28e4568be2c26a0096dae14b1c081a5 100755 (executable)
@@ -17,7 +17,7 @@ struct free_heap_block
        {
                cell size = header & ~7;
 #ifdef FACTOR_DEBUG
-               assert(size > 0);
+               FACTOR_ASSERT(size > 0);
 #endif
                return size;
        }
@@ -25,7 +25,7 @@ struct free_heap_block
        void make_free(cell size)
        {
 #ifdef FACTOR_DEBUG
-               assert(size > 0);
+               FACTOR_ASSERT(size > 0);
 #endif
                header = size | 1;
        }
index 8c63bd487d482def2295958e80ab0e695e0c5091..ea7b5b1a5d1ded29660bc836a82a61c1a39de693 100644 (file)
@@ -140,7 +140,7 @@ void free_list_allocator<Block>::sweep()
                {
                        /* find size */
                        cell size = state.unmarked_block_size(start);
-                       assert(size > 0);
+                       FACTOR_ASSERT(size > 0);
 
                        free_heap_block *free_block = (free_heap_block *)start;
                        free_block->make_free(size);
index 5ea23dce3bb96dd647e652c4bb8a18b4e1aaae32..177bb970afa91fad80393cc668fa71b13236187a 100755 (executable)
--- a/vm/gc.cpp
+++ b/vm/gc.cpp
@@ -145,14 +145,14 @@ void factor_vm::set_current_gc_op(gc_op op)
 
 void factor_vm::gc(gc_op op, cell requested_size, bool trace_contexts_p)
 {
-       assert(!gc_off);
-       assert(!current_gc);
+       FACTOR_ASSERT(!gc_off);
+       FACTOR_ASSERT(!current_gc);
 
        /* Important invariant: tenured space must have enough contiguous free
        space to fit the entire contents of the aging space and nursery. This is
        because when doing a full collection, objects from younger generations
        are promoted before any unreachable tenured objects are freed. */
-       assert(!data->high_fragmentation_p());
+       FACTOR_ASSERT(!data->high_fragmentation_p());
 
        current_gc = new gc_state(op,this);
        atomic::store(&current_gc_p, true);
@@ -223,7 +223,7 @@ void factor_vm::gc(gc_op op, cell requested_size, bool trace_contexts_p)
        current_gc = NULL;
 
        /* Check the invariant again, just in case. */
-       assert(!data->high_fragmentation_p());
+       FACTOR_ASSERT(!data->high_fragmentation_p());
 }
 
 /* primitive_minor_gc() is invoked by inline GC checks, and it needs to fill in
@@ -246,7 +246,7 @@ struct call_frame_scrubber {
                code_block *compiled = parent->frame_code(frame);
                gc_info *info = compiled->block_gc_info();
 
-               assert(return_address < compiled->size());
+               FACTOR_ASSERT(return_address < compiled->size());
                cell index = info->return_address_index(return_address);
                if(index != (cell)-1)
                        ctx->scrub_stacks(info,index);
index 0113791fbdfe7ef0a151dae25c0ce96e53e4023e..777d23d2c0b9323d5671c70c921cfe8e833b00bc 100755 (executable)
@@ -4,7 +4,7 @@ namespace factor
 template<typename Array> cell array_capacity(const Array *array)
 {
 #ifdef FACTOR_DEBUG
-       assert(array->type() == Array::type_number);
+       FACTOR_ASSERT(array->type() == Array::type_number);
 #endif
        return array->capacity >> TAG_BITS;
 }
index a84856ec6fe79b28543f7becd1a0e7a59dd22760..775e0487fcbaf2fc41059afa7305584cbf343faf 100644 (file)
@@ -22,13 +22,13 @@ jit::jit(code_block_type type_, cell owner_, factor_vm *vm)
          parent(vm)
 {
        fixnum old_count = atomic::fetch_add(&parent->current_jit_count, 1);
-       assert(old_count >= 0);
+       FACTOR_ASSERT(old_count >= 0);
 }
 
 jit::~jit()
 {
        fixnum old_count = atomic::fetch_subtract(&parent->current_jit_count, 1);
-       assert(old_count >= 1);
+       FACTOR_ASSERT(old_count >= 1);
 }
 
 void jit::emit_relocation(cell relocation_template_)
index 4431e73b9675b2104fd3e78b9d8cc572d591b443..9c6e2e7e3b7842762f3c3353a1236a69992662fd 100644 (file)
@@ -89,7 +89,7 @@ static inline const char *type_name(cell type)
        case DLL_TYPE:
                return "dll";
        default:
-               assert(false);
+               FACTOR_ASSERT(false);
                return "";
        }
 }
@@ -123,7 +123,7 @@ inline static bool immediate_p(cell obj)
 inline static fixnum untag_fixnum(cell tagged)
 {
 #ifdef FACTOR_DEBUG
-       assert(TAG(tagged) == FIXNUM_TYPE);
+       FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
 #endif
        return ((fixnum)tagged) >> TAG_BITS;
 }
index 718937577cb0c9bda0ede0beebd88f959c9f6e55..a4fe269b3d495c202634d099f781dfd13df2381c 100755 (executable)
@@ -62,7 +62,7 @@ void factor_vm::call_fault_handler(
                handler = (cell)factor::synchronous_signal_handler_impl;
        }
 
-       assert(handler != 0);
+       FACTOR_ASSERT(handler != 0);
 
        dispatch_signal_handler(
                (cell*)&MACH_STACK_POINTER(thread_state),
@@ -81,7 +81,7 @@ static void call_fault_handler(
 {
        /* Look up the VM instance involved */
        THREADHANDLE thread_id = pthread_from_mach_thread_np(thread);
-       assert(thread_id);
+       FACTOR_ASSERT(thread_id);
        std::map<THREADHANDLE, factor_vm*>::const_iterator vm = thread_vms.find(thread_id);
 
        /* Handle the exception */
@@ -211,6 +211,7 @@ mach_exception_thread (void *arg)
                        abort ();
                }
        }
+       return NULL; // quiet warning
 }
 
 /* Initialize the Mach exception handler thread. */
index b3b73ba1ea86aba00d6123d8ea77e44f0a264e1a..0cce3fd1343574d6703aae51455f18059dcbdffc 100644 (file)
@@ -82,7 +82,7 @@ template<typename Block> struct mark_bits {
                else
                {
 #ifdef FACTOR_DEBUG
-                       assert(start.first < bits_size);
+                       FACTOR_ASSERT(start.first < bits_size);
 #endif
                        bits[start.first] |= ~start_mask;
 
@@ -92,7 +92,7 @@ template<typename Block> struct mark_bits {
                        if(end_mask != 0)
                        {
 #ifdef FACTOR_DEBUG
-                               assert(end.first < bits_size);
+                               FACTOR_ASSERT(end.first < bits_size);
 #endif
                                bits[end.first] |= end_mask;
                        }
@@ -126,7 +126,7 @@ template<typename Block> struct mark_bits {
        Block *forward_block(const Block *original)
        {
 #ifdef FACTOR_DEBUG
-               assert(marked_p(original));
+               FACTOR_ASSERT(marked_p(original));
 #endif
                std::pair<cell,cell> position = bitmap_deref(original);
 
@@ -136,7 +136,7 @@ template<typename Block> struct mark_bits {
                cell new_line_number = approx_popcount + popcount(marked[position.first] & mask);
                Block *new_block = line_block(new_line_number);
 #ifdef FACTOR_DEBUG
-               assert(new_block <= original);
+               FACTOR_ASSERT(new_block <= original);
 #endif
                return new_block;
        }
index 5b0604fe33233ff82a1c94cf63f4dd0a6a9ad4dd..5131892352a96b5cbbd1a6af76fa9efeb4325fbb 100755 (executable)
 #include <errno.h>
 #endif
 
-#ifdef FACTOR_DEBUG
-#include <assert.h>
-#endif
-
 /* C headers */
 #include <fcntl.h>
 #include <limits.h>
@@ -26,7 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include <wchar.h>
-#include <assert.h>
 
 /* C++ headers */
 #include <algorithm>
@@ -88,6 +83,7 @@ namespace factor
 }
 
 /* Factor headers */
+#include "assert.hpp"
 #include "layouts.hpp"
 #include "platform.hpp"
 #include "primitives.hpp"
index 56692d16de4e6250b4d7ff6284746da96e6e7362..596e2527e8775026feab3875473512dd11d9094d 100644 (file)
@@ -12,7 +12,7 @@ void init_mvm()
 
 void register_vm_with_thread(factor_vm *vm)
 {
-       assert(!global_vm);
+       FACTOR_ASSERT(!global_vm);
        global_vm = vm;
 }
 
index 4fbc9b74677dec0ac88cf647559a3d9052044262..3a17cabe51ca3240ec046e50c2f71e6a4c46d67b 100644 (file)
@@ -8,7 +8,7 @@ factor_vm *current_vm_p();
 inline factor_vm *current_vm()
 {
        factor_vm *vm = current_vm_p();
-       assert(vm != NULL);
+       FACTOR_ASSERT(vm != NULL);
        return vm;
 }
 
index 6b5b5139b9082ee4e3d86707037d13c1dd1b0112..72152aceedc9cd269db74a3f4e7574d99e53daa9 100644 (file)
@@ -33,7 +33,7 @@ cell object_start_map::find_object_containing_card(cell card_index)
                {
 #ifdef FACTOR_DEBUG
                        /* First card should start with an object */
-                       assert(card_index > 0);
+                       FACTOR_ASSERT(card_index > 0);
 #endif
                        card_index--;
                }
index cc53edea251bbbcac573b276d5380b1b37bc03ec..90c524ee2f18aaba21a91865692214b4fe57c45c 100755 (executable)
@@ -493,7 +493,7 @@ void *stdin_loop(void *arg)
 
 void factor_vm::open_console()
 {
-       assert(!stdin_thread_initialized_p);
+       FACTOR_ASSERT(!stdin_thread_initialized_p);
        safe_pipe(&control_read,&control_write);
        safe_pipe(&size_read,&size_write);
        safe_pipe(&stdin_read,&stdin_write);
@@ -513,7 +513,7 @@ void factor_vm::close_console()
 
 void factor_vm::lock_console()
 {
-       assert(stdin_thread_initialized_p);
+       FACTOR_ASSERT(stdin_thread_initialized_p);
        /* Lock the stdin_mutex and send the stdin_loop thread a signal to interrupt
        any read() it has in progress. When the stdin loop iterates again, it will
        try to lock the same mutex and wait until unlock_console() is called. */
@@ -523,7 +523,7 @@ void factor_vm::lock_console()
 
 void factor_vm::unlock_console()
 {
-       assert(stdin_thread_initialized_p);
+       FACTOR_ASSERT(stdin_thread_initialized_p);
        pthread_mutex_unlock(&stdin_mutex);
 }
 
@@ -544,7 +544,7 @@ void factor_vm::handle_ctrl_c()
        sigaction_safe(SIGINT,&fep_sigaction,NULL);
 }
 
-void factor_vm::abort()
+void abort()
 {
        sig_t ret;
        do
@@ -553,7 +553,7 @@ void factor_vm::abort()
        }
        while(ret == SIG_ERR && errno == EINTR);
        
-       close_console();
+       factor_vm::close_console();
        ::abort();
 }
 
index fc9b8c381669a1badb9f2f16ebc69c23f5d2cc9d..e48bdca8c0370a042195d2983943cb494273cda5 100755 (executable)
@@ -294,7 +294,7 @@ static BOOL WINAPI ctrl_handler(DWORD dwCtrlType)
                        Since in practice nobody uses the multi-VM stuff yet, we just grab the first
                        VM we can get. This will not be a good idea when we actually support native
                        threads. */
-                       assert(thread_vms.size() == 1);
+                       FACTOR_ASSERT(thread_vms.size() == 1);
                        factor_vm *vm = thread_vms.begin()->second;
                        vm->safepoint.enqueue_fep(vm);
                        return TRUE;
@@ -337,17 +337,17 @@ void factor_vm::sampler_thread_loop()
        DWORD ok;
 
        ok = QueryPerformanceFrequency(&units_per_second);
-       assert(ok);
+       FACTOR_ASSERT(ok);
 
        ok = QueryPerformanceCounter(&counter);
-       assert(ok);
+       FACTOR_ASSERT(ok);
 
        counter.QuadPart *= samples_per_second;
        while (atomic::load(&sampling_profiler_p))
        {
                SwitchToThread();
                ok = QueryPerformanceCounter(&new_counter);
-               assert(ok);
+               FACTOR_ASSERT(ok);
                new_counter.QuadPart *= samples_per_second;
                cell samples = 0;
                while (new_counter.QuadPart - counter.QuadPart > units_per_second.QuadPart)
@@ -359,16 +359,16 @@ void factor_vm::sampler_thread_loop()
                if (samples > 0)
                {
                        DWORD suscount = SuspendThread(thread);
-                       assert(suscount == 0);
+                       FACTOR_ASSERT(suscount == 0);
 
                        CONTEXT context;
                        memset((void*)&context, 0, sizeof(CONTEXT));
                        context.ContextFlags = CONTEXT_CONTROL;
                        BOOL context_ok = GetThreadContext(thread, &context);
-                       assert(context_ok);
+                       FACTOR_ASSERT(context_ok);
 
                        suscount = ResumeThread(thread);
-                       assert(suscount == 1);
+                       FACTOR_ASSERT(suscount == 1);
 
                        safepoint.enqueue_samples(this, samples, context.EIP, false);
                }
@@ -403,7 +403,7 @@ void factor_vm::end_sampling_profiler_timer()
        sampler_thread = NULL;
 }
 
-void factor_vm::abort()
+void abort()
 {
        ::abort();
 }
index ac0b2b6d534c786e1d38d911bab2ec6814d2793d..30352c13c2fc975455be7797adcde4e0077ea05e 100755 (executable)
@@ -82,7 +82,7 @@ inline static THREADHANDLE thread_id()
                FALSE,
                id
        );
-       assert(threadHandle != NULL);
+       FACTOR_ASSERT(threadHandle != NULL);
        return threadHandle;
 }
 
index 3caaa3fdde511cb1ebacef0aafde373d1b1a0814..c1691128f4cd4989b65a1cb5cd9f42aea224ad69 100755 (executable)
@@ -392,7 +392,7 @@ cell factor_vm::lazy_jit_compile(cell quot_)
 {
        data_root<quotation> quot(quot_,this);
 
-       assert(!quot_compiled_p(quot.untagged()));
+       FACTOR_ASSERT(!quot_compiled_p(quot.untagged()));
 
        code_block *compiled = jit_compile_quot(quot.value(),quot.value(),true);
        quot.untagged()->entry_point = compiled->entry_point();
index b16754036db7a4907e425cc728f63fa28045f3f0..f26e99bcdaf40948cf423aadf89a74a04f00874e 100755 (executable)
@@ -8,9 +8,9 @@ void factor_vm::primitive_exit()
        exit((int)to_fixnum(ctx->pop()));
 }
 
-void factor_vm::exit(int status)
+void exit(int status)
 {
-       close_console();
+       factor_vm::close_console();
        ::exit(status);
 }
 
index 412ef35bb4403ee39e5aa0ef975114ad79a07a9b..d3d8e3f94945e2e6b821f2dac8ddf5f6075089fe 100755 (executable)
@@ -1,4 +1,7 @@
 namespace factor
 {
 
+void abort();
+void exit(int status);
+
 }
index 12c63bffb325a616631d08125998ed3597ddb302..880f5a6bd09f4c06312b0d7fc343e80bdb42b9c0 100644 (file)
@@ -50,7 +50,7 @@ void safepoint_state::handle_safepoint(factor_vm *parent, cell pc) volatile
        }
        else if (atomic::load(&parent->sampling_profiler_p))
        {
-               assert(parent->code->seg->in_segment_p(pc));
+               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;
 
index 8b567408aeb0aae000ae0ee8defe32a00e7edec8..c1c720634bfc4e08e96f571a44fcdd3994914e82 100644 (file)
@@ -55,7 +55,7 @@ void factor_vm::record_callstack_sample(cell *begin, cell *end, bool prolog_p)
        stack_frame *frame = ctx->bottom_frame();
        if (prolog_p)
        {
-               assert(frame >= ctx->callstack_top);
+               FACTOR_ASSERT(frame >= ctx->callstack_top);
                stack_frame *next_frame = frame_successor(frame);
                while (next_frame >= ctx->callstack_top)
                {
index bd2b8483982ef9eaf4040805653d9ffcfe39d39e..5e8cbe10d055d1356b3c9a9a9530738627a29629 100755 (executable)
@@ -317,7 +317,7 @@ struct call_frame_slot_visitor {
                code_block *compiled = visitor->fixup.translate_code(parent->frame_code(frame));
                gc_info *info = compiled->block_gc_info();
 
-               assert(return_address < compiled->size());
+               FACTOR_ASSERT(return_address < compiled->size());
                cell callsite = info->return_address_index(return_address);
                if(callsite == (cell)-1)
                        return;
index e9f89528bc3b0f68c6bd18240b9ae8e59590e32f..12f649669cebafe06f711b919a653d697a01373b 100755 (executable)
@@ -37,7 +37,7 @@ struct tagged
        cell value() const
        {
 #ifdef FACTOR_DEBUG
-               assert(type_p());
+               FACTOR_ASSERT(type_p());
 #endif
                return value_;
        }
@@ -45,7 +45,7 @@ struct tagged
        Type *untagged() const
        {
 #ifdef FACTOR_DEBUG
-               assert(type_p());
+               FACTOR_ASSERT(type_p());
 #endif
                return (Type *)(UNTAG(value_));
        }
index 0889a254f654e3505fe2d3a6133f0cb35f2a871d..7193d50e2f9ef9427e03e61b0e7b94f339d3f0e7 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -190,7 +190,6 @@ struct factor_vm
        void primitive_nano_count();
        void primitive_sleep();
        void primitive_set_slot();
-       static void exit(int status);
 
        // objects
        void primitive_special_object();
@@ -380,7 +379,7 @@ struct factor_vm
        {
        #ifdef FACTOR_DEBUG
                if(!(current_gc && current_gc->op == collect_growing_heap_op))
-                       assert(data->seg->in_segment_p((cell)pointer));
+                       FACTOR_ASSERT(data->seg->in_segment_p((cell)pointer));
        #endif
        }
 
@@ -739,8 +738,6 @@ struct factor_vm
        static void unlock_console();
        static void ignore_ctrl_c();
        static void handle_ctrl_c();
-       static void abort();
-       static void exit();
 
        // os-windows
   #if defined(WINDOWS)