Skip to content

Commit

Permalink
vm: Tweak Factor VM to compile with Microsoft Visual Studio on Window…
Browse files Browse the repository at this point in the history
…s, in addition to Mingw. Add an Nmakefile which can be used for this purpose. Rename Makefile to GNUmakefile.
  • Loading branch information
Slava Pestov committed Jan 16, 2010
1 parent b34f660 commit edb1346
Show file tree
Hide file tree
Showing 29 changed files with 318 additions and 217 deletions.
File renamed without changes.
65 changes: 65 additions & 0 deletions Nmakefile
@@ -0,0 +1,65 @@
LINK_CLFAGS =
CL_FLAGS = /O2 /W3

OBJS = vm\main-windows-nt.obj \
vm\os-windows-nt.obj \
vm\os-windows.obj \
vm\aging_collector.obj \
vm\alien.obj \
vm\arrays.obj \
vm\bignum.obj \
vm\booleans.obj \
vm\byte_arrays.obj \
vm\callbacks.obj \
vm\callstack.obj \
vm\code_blocks.obj \
vm\code_heap.obj \
vm\compaction.obj \
vm\contexts.obj \
vm\data_heap.obj \
vm\data_heap_checker.obj \
vm\debug.obj \
vm\dispatch.obj \
vm\entry_points.obj \
vm\errors.obj \
vm\factor.obj \
vm\free_list.obj \
vm\full_collector.obj \
vm\gc.obj \
vm\image.obj \
vm\inline_cache.obj \
vm\instruction_operands.obj \
vm\io.obj \
vm\jit.obj \
vm\math.obj \
vm\nursery_collector.obj \
vm\object_start_map.obj \
vm\objects.obj \
vm\primitives.obj \
vm\profiler.obj \
vm\quotations.obj \
vm\run.obj \
vm\strings.obj \
vm\to_tenured_collector.obj \
vm\tuples.obj \
vm\utilities.obj \
vm\vm.obj \
vm\words.obj

.cpp.obj:
cl /nologo /EHsc $(CL_FLAGS) /Fo$@ /c $<

all: factor.com factor.exe

factor.com: $(OBJS)
link $(LINK_FLAGS) /nologo /out:factor.com /SUBSYSTEM:console $(OBJS)

factor.exe: $(OBJS)
link $(LINK_FLAGS) /nologo /out:factor.exe /SUBSYSTEM:windows $(OBJS)

clean:
del vm\*.obj
del factor.com
del factor.exe

.PHONY: clean
3 changes: 2 additions & 1 deletion build-support/cleanup
Expand Up @@ -3,6 +3,7 @@ temp
logs
.git
.gitignore
Makefile
GNUmakefile
Nmakefile
unmaintained
build-support
4 changes: 2 additions & 2 deletions build-support/factor.sh
Expand Up @@ -406,9 +406,9 @@ backup_factor() {
}

check_makefile_exists() {
if [[ ! -e "Makefile" ]] ; then
if [[ ! -e "GNUmakefile" ]] ; then
echo ""
echo "***Makefile not found***"
echo "***GNUmakefile not found***"
echo "You are likely in the wrong directory."
echo "Run this script from your factor directory:"
echo " ./build-support/factor.sh"
Expand Down
8 changes: 4 additions & 4 deletions vm/alien.cpp
Expand Up @@ -109,7 +109,7 @@ void *factor_vm::alien_pointer()
PRIMITIVE(set_alien_##name) \
{ \
type *ptr = (type *)parent->alien_pointer(); \
type value = to(parent->ctx->pop(),parent); \
type value = (type)to(parent->ctx->pop(),parent); \
*ptr = value; \
}

Expand Down Expand Up @@ -151,7 +151,7 @@ void factor_vm::primitive_dlsym()
{
dll *d = untag_check<dll>(library.value());

if(d->dll == NULL)
if(d->handle == NULL)
ctx->push(false_object);
else
ctx->push(allot_alien(ffi_dlsym(d,sym)));
Expand All @@ -164,15 +164,15 @@ void factor_vm::primitive_dlsym()
void factor_vm::primitive_dlclose()
{
dll *d = untag_check<dll>(ctx->pop());
if(d->dll != NULL)
if(d->handle != NULL)
ffi_dlclose(d);
}

void factor_vm::primitive_dll_validp()
{
cell library = ctx->pop();
if(to_boolean(library))
ctx->push(tag_boolean(untag_check<dll>(library)->dll != NULL));
ctx->push(tag_boolean(untag_check<dll>(library)->handle != NULL));
else
ctx->push(true_object);
}
Expand Down
16 changes: 13 additions & 3 deletions vm/bitwise_hacks.hpp 100644 → 100755
Expand Up @@ -4,8 +4,18 @@ namespace factor
inline cell log2(cell x)
{
cell n;
#if defined(FACTOR_X86) || defined(FACTOR_AMD64)
asm ("bsr %1, %0;":"=r"(n):"r"(x));
#if defined(FACTOR_X86)
#if defined(_MSC_VER)
_BitScanReverse(&n,x);
#else
asm ("bsr %1, %0;":"=r"(n):"r"(x));
#endif
#elif defined(FACTOR_AMD64)
#if defined(_MSC_VER)
_BitScanReverse64(&n,x);
#else
asm ("bsr %1, %0;":"=r"(n):"r"(x));
#endif
#elif defined(FACTOR_PPC)
asm ("cntlzw %1, %0;":"=r"(n):"r"(x));
n = (31 - n);
Expand All @@ -22,7 +32,7 @@ inline cell rightmost_clear_bit(cell x)

inline cell rightmost_set_bit(cell x)
{
return log2(x & -x);
return log2(x & (~x + 1));
}

inline cell popcount(cell x)
Expand Down
2 changes: 1 addition & 1 deletion vm/code_blocks.cpp
Expand Up @@ -159,7 +159,7 @@ cell factor_vm::compute_dlsym_address(array *literals, cell index)

dll *d = (to_boolean(library) ? untag<dll>(library) : NULL);

if(d != NULL && !d->dll)
if(d != NULL && !d->handle)
return (cell)factor::undefined_symbol;

switch(tagged<object>(symbol).type())
Expand Down
2 changes: 1 addition & 1 deletion vm/compaction.cpp
Expand Up @@ -168,7 +168,7 @@ void factor_vm::update_code_roots_for_compaction()
for(; iter < end; iter++)
{
code_root *root = *iter;
code_block *block = (code_block *)(root->value & -data_alignment);
code_block *block = (code_block *)(root->value & (~data_alignment + 1));

/* Offset of return address within 16-byte allocation line */
cell offset = root->value - (cell)block;
Expand Down
12 changes: 3 additions & 9 deletions vm/factor.cpp
Expand Up @@ -3,7 +3,6 @@
namespace factor
{

factor_vm *vm;
std::map<THREADHANDLE, factor_vm*> thread_vms;

void init_globals()
Expand Down Expand Up @@ -31,11 +30,7 @@ void factor_vm::default_parameters(vm_parameters *p)
#ifdef WINDOWS
p->console = false;
#else
if (this == vm)
p->console = true;
else
p->console = false;

p->console = true;
#endif

p->callback_size = 256;
Expand Down Expand Up @@ -120,7 +115,7 @@ void factor_vm::init_factor(vm_parameters *p)
if(p->image_path == NULL)
p->image_path = default_image_path();

srand(system_micros());
srand((unsigned int)system_micros());
init_ffi();
init_stacks(p->ds_size,p->rs_size);
init_callbacks(p->callback_size);
Expand Down Expand Up @@ -225,7 +220,7 @@ factor_vm *new_factor_vm()
}

// arg must be new'ed because we're going to delete it!
void* start_standalone_factor_thread(void *arg)
void *start_standalone_factor_thread(void *arg)
{
factor_vm *newvm = new_factor_vm();
startargs *args = (startargs*) arg;
Expand All @@ -238,7 +233,6 @@ void* start_standalone_factor_thread(void *arg)
VM_C_API void start_standalone_factor(int argc, vm_char **argv)
{
factor_vm *newvm = new_factor_vm();
vm = newvm;
return newvm->start_standalone_factor(argc,argv);
}

Expand Down
2 changes: 1 addition & 1 deletion vm/factor.hpp 100644 → 100755
Expand Up @@ -2,7 +2,7 @@ namespace factor
{

VM_C_API void init_globals();

VM_C_API void start_standalone_factor(int argc, vm_char **argv);
VM_C_API THREADHANDLE start_standalone_factor_in_new_thread(int argc, vm_char **argv);

}
2 changes: 1 addition & 1 deletion vm/free_list.hpp 100644 → 100755
Expand Up @@ -32,7 +32,7 @@ struct free_heap_block
};

struct block_size_compare {
bool operator()(free_heap_block *a, free_heap_block *b)
bool operator()(free_heap_block *a, free_heap_block *b) const
{
return a->size() < b->size();
}
Expand Down
12 changes: 6 additions & 6 deletions vm/gc.cpp
Expand Up @@ -29,7 +29,7 @@ void gc_event::ended_card_scan(cell cards_scanned_, cell decks_scanned_)
{
cards_scanned += cards_scanned_;
decks_scanned += decks_scanned_;
card_scan_time = (nano_count() - temp_time);
card_scan_time = (cell)(nano_count() - temp_time);
}

void gc_event::started_code_scan()
Expand All @@ -40,7 +40,7 @@ void gc_event::started_code_scan()
void gc_event::ended_code_scan(cell code_blocks_scanned_)
{
code_blocks_scanned += code_blocks_scanned_;
code_scan_time = (nano_count() - temp_time);
code_scan_time = (cell)(nano_count() - temp_time);
}

void gc_event::started_data_sweep()
Expand All @@ -50,7 +50,7 @@ void gc_event::started_data_sweep()

void gc_event::ended_data_sweep()
{
data_sweep_time = (nano_count() - temp_time);
data_sweep_time = (cell)(nano_count() - temp_time);
}

void gc_event::started_code_sweep()
Expand All @@ -60,7 +60,7 @@ void gc_event::started_code_sweep()

void gc_event::ended_code_sweep()
{
code_sweep_time = (nano_count() - temp_time);
code_sweep_time = (cell)(nano_count() - temp_time);
}

void gc_event::started_compaction()
Expand All @@ -70,14 +70,14 @@ void gc_event::started_compaction()

void gc_event::ended_compaction()
{
compaction_time = (nano_count() - temp_time);
compaction_time = (cell)(nano_count() - temp_time);
}

void gc_event::ended_gc(factor_vm *parent)
{
data_heap_after = parent->data_room();
code_heap_after = parent->code_room();
total_time = nano_count() - start_time;
total_time = (cell)(nano_count() - start_time);
}

gc_state::gc_state(gc_op op_, factor_vm *parent) : op(op_), start_time(nano_count())
Expand Down
2 changes: 1 addition & 1 deletion vm/instruction_operands.cpp
Expand Up @@ -122,7 +122,7 @@ void instruction_operand::store_value(fixnum absolute_value)
store_value_masked(relative_value - sizeof(cell),rel_indirect_arm_mask,0);
break;
case RC_ABSOLUTE_2:
*(u16 *)(pointer - sizeof(u16)) = absolute_value;
*(u16 *)(pointer - sizeof(u16)) = (u16)absolute_value;
break;
default:
critical_error("Bad rel class",rel.rel_class());
Expand Down
2 changes: 1 addition & 1 deletion vm/layouts.hpp
Expand Up @@ -298,7 +298,7 @@ struct dll : public object {
/* tagged byte array holding a C string */
cell path;
/* OS-specific handle */
void *dll;
void *handle;
};

struct stack_frame {
Expand Down

0 comments on commit edb1346

Please sign in to comment.