VM: fixes to make some if-else statements read better
parent
e0a40e4f96
commit
10ac4da0f6
|
@ -82,7 +82,7 @@ struct code_block {
|
|||
byte_array* rels = untag<byte_array>(relocation);
|
||||
|
||||
cell index = 0;
|
||||
cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
|
||||
cell length = untag_fixnum(rels->capacity) / sizeof(relocation_entry);
|
||||
|
||||
for (cell i = 0; i < length; i++) {
|
||||
relocation_entry rel = rels->data<relocation_entry>()[i];
|
||||
|
|
|
@ -20,8 +20,7 @@ cell factor_vm::search_lookup_hash(cell table, cell klass, cell hashcode) {
|
|||
cell bucket = array_nth(buckets, hashcode & (array_capacity(buckets) - 1));
|
||||
if (TAG(bucket) == ARRAY_TYPE)
|
||||
return search_lookup_alist(bucket, klass);
|
||||
else
|
||||
return bucket;
|
||||
return bucket;
|
||||
}
|
||||
|
||||
cell factor_vm::nth_superclass(tuple_layout* layout, fixnum echelon) {
|
||||
|
@ -69,10 +68,9 @@ cell factor_vm::lookup_method(cell obj, cell methods) {
|
|||
if (tag == TUPLE_TYPE) {
|
||||
if (TAG(method) == ARRAY_TYPE)
|
||||
return lookup_tuple_method(obj, method);
|
||||
else
|
||||
return method;
|
||||
} else
|
||||
return method;
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
void factor_vm::primitive_lookup_method() {
|
||||
|
@ -85,8 +83,7 @@ cell factor_vm::object_class(cell obj) {
|
|||
cell tag = TAG(obj);
|
||||
if (tag == TUPLE_TYPE)
|
||||
return untag<tuple>(obj)->layout;
|
||||
else
|
||||
return tag_fixnum(tag);
|
||||
return tag_fixnum(tag);
|
||||
}
|
||||
|
||||
cell factor_vm::method_cache_hashcode(cell klass, array* array) {
|
||||
|
|
43
vm/image.cpp
43
vm/image.cpp
|
@ -127,24 +127,24 @@ char *threadsafe_strerror(int errnum) {
|
|||
}
|
||||
|
||||
FILE* factor_vm::open_image(vm_parameters* p) {
|
||||
if (p->embedded_image) {
|
||||
FILE* file = OPEN_READ(p->executable_path);
|
||||
if (file == NULL) {
|
||||
std::cout << "Cannot open embedded image" << std::endl;
|
||||
char *msg = threadsafe_strerror(errno);
|
||||
std::cout << "strerror:1: " << msg << std::endl;
|
||||
free(msg);
|
||||
exit(1);
|
||||
}
|
||||
embedded_image_footer footer;
|
||||
if (!read_embedded_image_footer(file, &footer)) {
|
||||
std::cout << "No embedded image" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
safe_fseek(file, (off_t)footer.image_offset, SEEK_SET);
|
||||
return file;
|
||||
} else
|
||||
if (!p->embedded_image)
|
||||
return OPEN_READ(p->image_path);
|
||||
|
||||
FILE* file = OPEN_READ(p->executable_path);
|
||||
if (file == NULL) {
|
||||
std::cout << "Cannot open embedded image" << std::endl;
|
||||
char *msg = threadsafe_strerror(errno);
|
||||
std::cout << "strerror:1: " << msg << std::endl;
|
||||
free(msg);
|
||||
exit(1);
|
||||
}
|
||||
embedded_image_footer footer;
|
||||
if (!read_embedded_image_footer(file, &footer)) {
|
||||
std::cout << "No embedded image" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
safe_fseek(file, (off_t)footer.image_offset, SEEK_SET);
|
||||
return file;
|
||||
}
|
||||
|
||||
/* Read an image file from disk, only done once during startup */
|
||||
|
@ -209,9 +209,11 @@ bool factor_vm::save_image(const vm_char* saving_filename,
|
|||
return false;
|
||||
if (safe_fwrite(&h, sizeof(image_header), 1, file) != 1)
|
||||
return false;
|
||||
if (safe_fwrite((void*)data->tenured->start, h.data_size, 1, file) != 1)
|
||||
if (h.data_size > 0 &&
|
||||
safe_fwrite((void*)data->tenured->start, h.data_size, 1, file) != 1)
|
||||
return false;
|
||||
if (safe_fwrite((void*)code->allocator->start, h.code_size, 1, file) != 1)
|
||||
if (h.code_size > 0 &&
|
||||
safe_fwrite((void*)code->allocator->start, h.code_size, 1, file) != 1)
|
||||
return false;
|
||||
if (raw_fclose(file) == -1)
|
||||
return false;
|
||||
|
@ -244,6 +246,9 @@ void factor_vm::primitive_save_image() {
|
|||
get volatile data saved in the image. */
|
||||
active_contexts.clear();
|
||||
code->uninitialized_blocks.clear();
|
||||
|
||||
/* I think clearing the callback heap should be fine too. */
|
||||
callbacks->allocator->initial_free_list(0);
|
||||
}
|
||||
|
||||
/* do a full GC to push everything remaining into tenured space */
|
||||
|
|
|
@ -9,16 +9,14 @@ static const fixnum array_size_max = ((cell)1 << (WORD_SIZE - TAG_BITS - 2));
|
|||
inline cell factor_vm::from_signed_cell(fixnum x) {
|
||||
if (x < fixnum_min || x > fixnum_max)
|
||||
return tag<bignum>(fixnum_to_bignum(x));
|
||||
else
|
||||
return tag_fixnum(x);
|
||||
return tag_fixnum(x);
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
inline cell factor_vm::from_unsigned_cell(cell x) {
|
||||
if (x > (cell)fixnum_max)
|
||||
return tag<bignum>(cell_to_bignum(x));
|
||||
else
|
||||
return tag_fixnum(x);
|
||||
return tag_fixnum(x);
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
|
|
|
@ -47,13 +47,11 @@ cell factor_vm::clone_object(cell obj_) {
|
|||
|
||||
if (immediate_p(obj.value()))
|
||||
return obj.value();
|
||||
else {
|
||||
cell size = object_size(obj.value());
|
||||
object* new_obj = allot_object(obj.type(), size);
|
||||
memcpy(new_obj, obj.untagged(), size);
|
||||
new_obj->set_hashcode(0);
|
||||
return tag_dynamic(new_obj);
|
||||
}
|
||||
cell size = object_size(obj.value());
|
||||
object* new_obj = allot_object(obj.type(), size);
|
||||
memcpy(new_obj, obj.untagged(), size);
|
||||
new_obj->set_hashcode(0);
|
||||
return tag_dynamic(new_obj);
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
|
@ -63,8 +61,7 @@ void factor_vm::primitive_clone() { ctx->replace(clone_object(ctx->peek())); }
|
|||
cell factor_vm::object_size(cell tagged) {
|
||||
if (immediate_p(tagged))
|
||||
return 0;
|
||||
else
|
||||
return untag<object>(tagged)->size();
|
||||
return untag<object>(tagged)->size();
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
|
|
|
@ -155,11 +155,10 @@ void synchronous_signal_handler(int signal, siginfo_t* siginfo, void* uap) {
|
|||
return;
|
||||
|
||||
factor_vm* vm = current_vm_p();
|
||||
if (vm) {
|
||||
vm->signal_number = signal;
|
||||
vm->dispatch_signal(uap, factor::synchronous_signal_handler_impl);
|
||||
} else
|
||||
if (!vm)
|
||||
fatal_error("Foreign thread received signal", signal);
|
||||
vm->signal_number = signal;
|
||||
vm->dispatch_signal(uap, factor::synchronous_signal_handler_impl);
|
||||
}
|
||||
|
||||
void safe_write_nonblock(int fd, void* data, ssize_t size);
|
||||
|
|
Loading…
Reference in New Issue