Fix #1651.
/* clone the bignums so we can modify them in-place */
size_a = BIGNUM_LENGTH(a);
data_root<bignum> c(allot_bignum(size_a, 0), this);
- // c = allot_bignum(size_a, 0);
+ /* c = allot_bignum(size_a, 0); */
scan_a = BIGNUM_START_PTR(a);
a_end = scan_a + size_a;
scan_c = BIGNUM_START_PTR(c);
return c.untagged();
}
- // copy 'b' to 'a'
+ /* copy 'b' to 'a' */
scan_a = BIGNUM_START_PTR(a);
scan_b = BIGNUM_START_PTR(b);
a_end = scan_a + size_a;
*(scan_a++) = 0;
size_a = size_b;
- // copy 'c' to 'b'
+ /* copy 'c' to 'b' */
scan_b = BIGNUM_START_PTR(b);
scan_c = BIGNUM_START_PTR(c);
size_c = BIGNUM_LENGTH(c);
s -= (B * *scan_a);
t += (D * *scan_a++);
*scan_c++ = (bignum_digit_type)(s & BIGNUM_DIGIT_MASK);
- //*scan_d++ = (bignum_digit_type) (t & BIGNUM_DIGIT_MASK);
+ /* *scan_d++ = (bignum_digit_type) (t & BIGNUM_DIGIT_MASK); */
s >>= BIGNUM_DIGIT_LENGTH;
t >>= BIGNUM_DIGIT_LENGTH;
}
s += (A * *scan_a);
t -= (C * *scan_a++);
*scan_c++ = (bignum_digit_type)(s & BIGNUM_DIGIT_MASK);
- //*scan_d++ = (bignum_digit_type) (t & BIGNUM_DIGIT_MASK);
+ /* *scan_d++ = (bignum_digit_type) (t & BIGNUM_DIGIT_MASK); */
s >>= BIGNUM_DIGIT_LENGTH;
t >>= BIGNUM_DIGIT_LENGTH;
}
BIGNUM_ASSERT(s == 0);
BIGNUM_ASSERT(t == 0);
- // update size_a and size_b to remove any zeros at end
+ /* update size_a and size_b to remove any zeroes at end */
while (size_a > 0 && *(--scan_a) == 0)
size_a--;
while (size_b > 0 && *(--scan_b) == 0)
cell ks = 24;
#endif
- x = x - ((x >> 1) & k1); // put count of each 2 bits into those 2 bits
- x = (x & k2) + ((x >> 2) & k2); // put count of each 4 bits into those 4 bits
- x = (x + (x >> 4)) & k4; // put count of each 8 bits into those 8 bits
- x = (x * kf) >> ks; // returns 8 most significant bits of x + (x<<8) +
- // (x<<16) + (x<<24) + ...
+ x = x - ((x >> 1) & k1); /* put count of each 2 bits into those 2 bits */
+ x = (x & k2) + ((x >> 2) & k2); /* put count of each 4 bits into those 4 bits */
+ x = (x + (x >> 4)) & k4; /* put count of each 8 bits into those 8 bits */
+ x = (x * kf) >> ks; /* returns 8 most significant bits of x + (x<<8) + */
+ (x<<16) + (x<<24) + ... */
return x;
#endif
/* The compiled code heap is structured into blocks. */
struct code_block {
- // header format (bits indexed with least significant as zero):
- // bit 0 : free?
- // bits 1-2: type (as a code_block_type)
- // if not free:
- // bits 3-23: code size / 8
- // bits 24-31: stack frame size / 16
- // if free:
- // bits 3-end: code size / 8
+ /* header format (bits indexed with least significant as zero):
+ bit 0 : free?
+ bits 1-2: type (as a code_block_type)
+ if not free:
+ bits 3-23: code size / 8
+ bits 24-31: stack frame size / 16
+ if free:
+ bits 3-end: code size / 8 */
cell header;
cell owner; /* tagged pointer to word, quotation or f */
cell parameters; /* tagged pointer to array or f */
/* Allocates memory (init_context()) */
VM_C_API void reset_context(factor_vm* parent) {
- // The function is used by (start-context-and-delete) which expects
- // the top two datastack items to be preserved after the context has
- // been resetted.
+ /* The function is used by (start-context-and-delete) which expects
+ the top two datastack items to be preserved after the context has
+ been reset. */
context* ctx = parent->ctx;
cell arg1 = ctx->pop();
inline static void check_call_site(cell return_address) {
unsigned char opcode = call_site_opcode(return_address);
FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode);
- (void)opcode; // suppress warning when compiling without assertions
+ (void)opcode; /* suppress warning when compiling without assertions */
}
inline static void* get_call_target(cell return_address) {
aging = new aging_space(aging_size, tenured->end);
aging_semispace = new aging_space(aging_size, aging->end);
- // Initialize vm nursery
+ /* Initialize vm nursery */
vm_nursery->here = aging_semispace->end;
vm_nursery->start = aging_semispace->end;
vm_nursery->end = vm_nursery->start + young_size;
cout << "Starting low level debugger..." << endl;
- // Even though we've stopped the VM, the stdin_loop thread (see os-*.cpp)
- // that pumps the console is still running concurrently. We lock a mutex so
- // the thread will take a break and give us exclusive access to stdin.
+ /* Even though we've stopped the VM, the stdin_loop thread (see os-*.cpp)
+ that pumps the console is still running concurrently. We lock a mutex so
+ the thread will take a break and give us exclusive access to stdin. */
lock_console();
ignore_ctrl_c();
namespace factor {
-// Runtime errors must be kept in sync with:
-// basis/debugger/debugger.factor
-// core/kernel/kernel.factor
+/* Runtime errors must be kept in sync with:
+ basis/debugger/debugger.factor
+ core/kernel/kernel.factor */
#define KERNEL_ERROR 0xfac7
enum vm_error_type {
void factor_vm::prepare_boot_image() {
std::cout << "*** Stage 2 early init... " << std::flush;
- // Compile all words.
+ /* Compile all words. */
data_root<array> words(instances(WORD_TYPE), this);
cell n_words = array_capacity(words.untagged());
}
update_code_heap_words(true);
- // Initialize all quotations
+ /* Initialize all quotations */
data_root<array> quotations(instances(QUOTATION_TYPE), this);
cell n_quots = array_capacity(quotations.untagged());
factor_vm* new_factor_vm();
VM_C_API void start_standalone_factor(int argc, vm_char** argv);
-// image
+/* image */
bool factor_arg(const vm_char* str, const vm_char* arg, cell* value);
-// objects
+/* objects */
cell object_size(cell tagged);
-// os-*
+/* os-* */
void open_console();
void close_console();
void lock_console();
namespace factor {
-// gc_info should be kept in sync with:
-// basis/compiler/codegen/gc-maps/gc-maps.factor
-// basis/vm/vm.factor
+/* gc_info should be kept in sync with:
+ basis/compiler/codegen/gc-maps/gc-maps.factor
+ basis/vm/vm.factor */
struct gc_info {
uint32_t scrub_d_count;
uint32_t scrub_r_count;
return items_read;
}
-// Call fclose() once only. Issues #1335, #908.
+/* Call fclose() once only. Issues #1335, #908. */
int raw_fclose(FILE* stream) {
if (fclose(stream) == EOF && errno != EINTR)
return -1;
struct object {
NO_TYPE_CHECK;
- // header format (bits indexed with least significant as zero):
- // bit 0 : free?
- // if not forwarding:
- // bit 1 : forwarding pointer?
- // bit 2-5 : tag
- // bit 7-end : hashcode
- // if forwarding:
- // bit 2-end : forwarding pointer
+ /* header format (bits indexed with least significant as zero):
+ bit 0 : free?
+ if not forwarding:
+ bit 1 : forwarding pointer?
+ bit 2-5 : tag
+ bit 7-end : hashcode
+ if forwarding:
+ bit 2-end : forwarding pointer */
cell header;
template <typename Fixup> cell base_size(Fixup fixup) const;
abort();
}
}
- return NULL; // quiet warning
+ return NULL; /* quiet warning */
}
/* Initialize the Mach exception handler thread. */
vm_char** argv;
};
-// arg must be new'ed because we're going to delete it!
+/* arg must be new'ed because we're going to delete it! */
void* start_standalone_factor_thread(void* arg) {
factor_vm* newvm = new_factor_vm();
startargs* args = (startargs*)arg;
namespace factor {
-// Special object count and identifiers must be kept in sync with:
-// core/kernel/kernel.factor
-// basis/bootstrap/image/image.factor
+/* Special object count and identifiers must be kept in sync with:
+ core/kernel/kernel.factor
+ basis/bootstrap/image/image.factor */
static const cell special_object_count = 85;
namespace factor {
-// glibc lies about the contents of the fpstate the kernel provides, hiding the
-// FXSR
-// environment
+/* glibc lies about the contents of the fpstate the kernel provides, hiding the
+ FXSR environment */
struct _fpstate {
/* Regular FPU environment */
unsigned long cw;
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (h == INVALID_HANDLE_VALUE) {
- // FindFirstFile is the only call that can stat c:\pagefile.sys
+ /* FindFirstFile is the only call that can stat c:\pagefile.sys */
WIN32_FIND_DATA st;
HANDLE h;
static uint32_t hi = 0;
static uint32_t lo = 0;
- // Note: on older systems QueryPerformanceCounter may be unreliable
- // until you add /usepmtimer to Boot.ini. I had an issue where two
- // nano_count calls would show a difference of about 1 second,
- // while actually about 80 seconds have passed. The /usepmtimer
- // switch cured the issue on that PC (WinXP Pro SP3 32-bit).
- // See also http://www.virtualdub.org/blog/pivot/entry.php?id=106
+ /* Note: on older systems QueryPerformanceCounter may be unreliable
+ until you add /usepmtimer to Boot.ini. I had an issue where two
+ nano_count calls would show a difference of about 1 second,
+ while actually about 80 seconds have passed. The /usepmtimer
+ switch cured the issue on that PC (WinXP Pro SP3 32-bit).
+ See also http://www.virtualdub.org/blog/pivot/entry.php?id=106 */
LARGE_INTEGER count;
BOOL ret = QueryPerformanceCounter(&count);
if (ret == 0)
cancellation requests to unblock the thread. */
VOID CALLBACK dummy_cb (ULONG_PTR dwParam) { }
-// CancelSynchronousIo is not in Windows XP
+/* CancelSynchronousIo is not in Windows XP */
#if _WIN32_WINNT >= 0x0600
static void wake_up_thread(HANDLE thread) {
if (!CancelSynchronousIo(thread)) {
#if _WIN32_WINNT != 0x0600
#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501 // For AddVectoredExceptionHandler, WinXP support
-//#define _WIN32_WINNT 0x0600 // For CancelSynchronousIo
+#define _WIN32_WINNT 0x0501 /* For AddVectoredExceptionHandler, WinXP support */
+/*#define _WIN32_WINNT 0x0600 /* For CancelSynchronousIo */
#endif
#ifndef UNICODE
#define FACTOR_OS_STRING "windows"
-// SSE traps raise these exception codes, which are defined in internal NT
-// headers
-// but not winbase.h
+/* SSE traps raise these exception codes, which are defined in internal NT
+headers, but not winbase.h */
#ifndef STATUS_FLOAT_MULTIPLE_FAULTS
#define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
#endif
void factor_vm::start_sampling_profiler(fixnum rate) {
samples_per_second = rate;
safepoint.sample_counts.clear();
- // Release the memory consumed by collecting samples.
+ /* Release the memory consumed by collecting samples. */
samples.clear();
samples.shrink_to_fit();
sample_callstacks.clear();
namespace factor {
struct profiling_sample_count {
- // Number of samples taken before the safepoint that recorded the sample
+ /* Number of samples taken before the safepoint that recorded the sample */
fixnum sample_count;
- // Number of samples taken during GC
+ /* Number of samples taken during GC */
fixnum gc_sample_count;
- // Number of samples taken during unoptimized compiler
+ /* Number of samples taken during unoptimized compiler */
fixnum jit_sample_count;
- // Number of samples taken during foreign code execution
+ /* Number of samples taken during foreign code execution */
fixnum foreign_sample_count;
- // Number of samples taken during code execution in non-Factor threads
+ /* Number of samples taken during code execution in non-Factor threads */
fixnum foreign_thread_sample_count;
profiling_sample_count()
};
struct profiling_sample {
- // Sample counts
+ /* Sample counts */
profiling_sample_count counts;
- // Active thread during sample
+ /* Active thread during sample */
cell thread;
/* The callstack at safepoint time. Indexes to the beginning and ending
code_block entries in the vm sample_callstacks array. */
namespace factor {
-// Poor mans range-based for loops.
+/* Poor man's range-based for-loops. */
#define FACTOR_FOR_EACH(iterable) \
for (auto iter = (iterable).begin(), \
_end = (iterable).end(); \
struct code_root;
struct factor_vm {
- //
- // vvvvvv
- // THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR. See:
- // basis/vm/vm.factor
- // basis/compiler/constants/constants.factor
+ /*
+ vvvvvv
+ THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR. See:
+ basis/vm/vm.factor
+ basis/compiler/constants/constants.factor */
/* Current context */
context* ctx;
set-special-object primitives */
cell special_objects[special_object_count];
- // THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR.
- // ^^^^^^
- //
+ /* THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR.
+ ^^^^^^
+ */
/* Handle to the main thread we run in */
THREADHANDLE thread;
/* Safepoint state */
volatile safepoint_state safepoint;
- // contexts
+ /* contexts */
context* new_context();
void init_context(context* ctx);
void delete_context();
void primitive_check_datastack();
void primitive_load_locals();
- // run
+ /* run */
void primitive_exit();
void primitive_nano_count();
void primitive_sleep();
void primitive_set_slot();
- // objects
+ /* objects */
void primitive_special_object();
void primitive_set_special_object();
void primitive_identity_hashcode();
void primitive_clone();
void primitive_become();
- // sampling_profiler
+ /* sampling_profiler */
void record_sample(bool prolog_p);
void record_callstack_sample(cell* begin, cell* end, bool prolog_p);
void start_sampling_profiler(fixnum rate);
void primitive_sampling_profiler();
void primitive_get_samples();
- // errors
+ /* errors */
void general_error(vm_error_type error, cell arg1, cell arg2);
void type_error(cell type, cell tagged);
void not_implemented_error();
void divide_by_zero_error();
void primitive_unimplemented();
- // bignum
+ /* bignum */
int bignum_equal_p(bignum* x, bignum* y);
enum bignum_comparison bignum_compare(bignum* x, bignum* y);
bignum* bignum_add(bignum* x, bignum* y);
int bignum_unsigned_logbitp(int shift, bignum* bn);
bignum* bignum_gcd(bignum* a_, bignum* b_);
- //data heap
+ /* data heap */
void set_data_heap(data_heap* data_);
void init_data_heap(cell young_size, cell aging_size, cell tenured_size);
void primitive_size();
write_barrier((cell*)offset);
}
- // data heap checker
+ /* data heap checker */
void check_data_heap();
- // gc
+ /* gc */
void end_gc();
void set_current_gc_op(gc_op op);
void start_gc_again();
return (Type*)allot_object(Type::type_number, size);
}
- // generic arrays
+ /* generic arrays */
template <typename Array> Array* allot_uninitialized_array(cell capacity);
template <typename Array>
bool reallot_array_in_place_p(Array* array, cell capacity);
template <typename Array> Array* reallot_array(Array* array_, cell capacity);
- // debug
+ /* debug */
void print_chars(ostream& out, string* str);
void print_word(ostream& out, word* word, cell nesting);
void print_factor_string(ostream& out, string* str);
void factorbug();
void primitive_die();
- // arrays
+ /* arrays */
inline void set_array_nth(array* array, cell slot, cell value);
array* allot_array(cell capacity, cell fill_);
void primitive_array();
void primitive_resize_array();
cell std_vector_to_array(std::vector<cell>& elements);
- // strings
+ /* strings */
string* allot_string_internal(cell capacity);
void fill_string(string* str_, cell start, cell capacity, cell fill);
string* allot_string(cell capacity, cell fill);
void primitive_resize_string();
void primitive_set_string_nth_fast();
- // booleans
+ /* booleans */
cell tag_boolean(cell untagged) {
return untagged ? special_objects[OBJ_CANONICAL_TRUE] : false_object;
}
- // byte arrays
+ /* byte arrays */
byte_array* allot_byte_array(cell size);
void primitive_byte_array();
void primitive_uninitialized_byte_array();
template <typename Type> byte_array* byte_array_from_value(Type* value);
- // tuples
+ /* tuples */
void primitive_tuple();
void primitive_tuple_boa();
- // words
+ /* words */
word* allot_word(cell name_, cell vocab_, cell hashcode_);
void primitive_word();
void primitive_word_code();
void primitive_wrapper();
void jit_compile_word(cell word_, cell def_, bool relocating);
- // math
+ /* math */
void primitive_bignum_to_fixnum();
void primitive_bignum_to_fixnum_strict();
void primitive_float_to_fixnum();
inline fixnum float_to_fixnum(cell tagged);
inline double fixnum_to_float(cell tagged);
- // tagged
+ /* tagged */
template <typename Type> void check_tagged(tagged<Type> t) {
if (!t.type_p())
type_error(Type::type_number, t.value_);
return t.untagged();
}
- // io
+ /* io */
void init_c_io();
void io_error_if_not_EINTR();
FILE* safe_fopen(char* filename, const char* mode);
void primitive_fflush();
void primitive_fclose();
- // code_block
+ /* code_block */
cell compute_entry_point_pic_address(word* w, cell tagged_quot);
cell compute_entry_point_pic_address(cell w_);
cell compute_entry_point_pic_tail_address(cell w_);
cell owner_, cell relocation_, cell parameters_,
cell literals_, cell frame_size_untagged);
- //code heap
+ /* code heap */
template <typename Iterator> void each_code_block(Iterator& iter) {
code->allocator->iterate(iter);
}
void primitive_strip_stack_traces();
void primitive_code_blocks();
- // callbacks
+ /* callbacks */
void primitive_free_callback();
void primitive_callback();
void primitive_callback_room();
- // image
+ /* image */
void load_data_heap(FILE* file, image_header* h, vm_parameters* p);
void load_code_heap(FILE* file, image_header* h, vm_parameters* p);
bool save_image(const vm_char* saving_filename, const vm_char* filename);
template <typename Iterator>
void iterate_callstack(context* ctx, Iterator& iterator);
- // cpu-*
+ /* cpu-* */
void dispatch_signal_handler(cell* sp, cell* pc, cell newpc);
#if defined(FACTOR_X86) || defined(FACTOR_64)
void dispatch_non_resumable_signal(cell* sp, cell* pc,
void dispatch_resumable_signal(cell* sp, cell* pc, cell handler);
#endif
- // alien
+ /* alien */
char* pinned_alien_offset(cell obj);
cell allot_alien(cell delegate_, cell displacement);
cell allot_alien(cell address);
void primitive_dll_validp();
char* alien_offset(cell obj);
- // quotations
+ /* quotations */
void primitive_jit_compile();
cell lazy_jit_compile_entry_point();
void primitive_array_to_quotation();
bool quotation_compiled_p(quotation* quot);
void primitive_quotation_compiled_p();
- // dispatch
+ /* dispatch */
cell lookup_tuple_method(cell obj, cell methods);
cell lookup_method(cell obj, cell methods);
void primitive_lookup_method();
void primitive_reset_dispatch_stats();
void primitive_dispatch_stats();
- // inline cache
+ /* inline cache */
void init_inline_caching(int max_size);
void deallocate_inline_cache(cell return_address);
void update_pic_count(cell type);
void update_pic_transitions(cell pic_size);
cell inline_cache_miss(cell return_address);
- // entry points
+ /* entry points */
void c_to_factor(cell quot);
void unwind_native_frames(cell quot, cell to);
cell get_fpu_state();
void set_fpu_state(cell state);
- // factor
+ /* factor */
void prepare_boot_image();
void init_factor(vm_parameters* p);
void pass_args_to_factor(int argc, vm_char** argv);
void factor_yield();
void factor_sleep(long us);
- // os-*
+ /* os-* */
void primitive_existsp();
void init_ffi();
void ffi_dlopen(dll* dll);
void start_sampling_profiler_timer();
void end_sampling_profiler_timer();
-// os-windows
+/* os-windows */
#if defined(WINDOWS)
HANDLE sampler_thread;
void sampler_thread_loop();
LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
void* dispatch);
-#else // UNIX
+#else /* UNIX */
void dispatch_signal(void* uap, void(handler)());
void unix_init_signals();
#endif