vm: Add more comments about functions that allocate.
parent
000efd9bbb
commit
aad70160f0
|
@ -27,6 +27,7 @@ char *factor_vm::pinned_alien_offset(cell obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
/* make an alien */
|
/* make an alien */
|
||||||
cell factor_vm::allot_alien(cell delegate_, cell displacement)
|
cell factor_vm::allot_alien(cell delegate_, cell displacement)
|
||||||
{
|
{
|
||||||
|
@ -52,11 +53,13 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement)
|
||||||
return new_alien.value();
|
return new_alien.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::allot_alien(void *address)
|
cell factor_vm::allot_alien(void *address)
|
||||||
{
|
{
|
||||||
return allot_alien(false_object,(cell)address);
|
return allot_alien(false_object,(cell)address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
/* make an alien pointing at an offset of another alien */
|
/* make an alien pointing at an offset of another alien */
|
||||||
void factor_vm::primitive_displaced_alien()
|
void factor_vm::primitive_displaced_alien()
|
||||||
{
|
{
|
||||||
|
@ -117,6 +120,7 @@ void factor_vm::primitive_dlopen()
|
||||||
ctx->push(library.value());
|
ctx->push(library.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
/* look up a symbol in a native library */
|
/* look up a symbol in a native library */
|
||||||
void factor_vm::primitive_dlsym()
|
void factor_vm::primitive_dlsym()
|
||||||
{
|
{
|
||||||
|
@ -139,6 +143,7 @@ void factor_vm::primitive_dlsym()
|
||||||
ctx->push(allot_alien(ffi_dlsym(NULL,sym)));
|
ctx->push(allot_alien(ffi_dlsym(NULL,sym)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
/* look up a symbol in a native library */
|
/* look up a symbol in a native library */
|
||||||
void factor_vm::primitive_dlsym_raw()
|
void factor_vm::primitive_dlsym_raw()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace factor
|
namespace factor
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
array *factor_vm::allot_array(cell capacity, cell fill_)
|
array *factor_vm::allot_array(cell capacity, cell fill_)
|
||||||
{
|
{
|
||||||
data_root<object> fill(fill_,this);
|
data_root<object> fill(fill_,this);
|
||||||
|
@ -11,6 +12,7 @@ array *factor_vm::allot_array(cell capacity, cell fill_)
|
||||||
return new_array;
|
return new_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_array()
|
void factor_vm::primitive_array()
|
||||||
{
|
{
|
||||||
data_root<object> fill(ctx->pop(),this);
|
data_root<object> fill(ctx->pop(),this);
|
||||||
|
@ -20,6 +22,7 @@ void factor_vm::primitive_array()
|
||||||
ctx->push(tag<array>(new_array));
|
ctx->push(tag<array>(new_array));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::allot_array_1(cell obj_)
|
cell factor_vm::allot_array_1(cell obj_)
|
||||||
{
|
{
|
||||||
data_root<object> obj(obj_,this);
|
data_root<object> obj(obj_,this);
|
||||||
|
@ -28,6 +31,7 @@ cell factor_vm::allot_array_1(cell obj_)
|
||||||
return a.value();
|
return a.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::allot_array_2(cell v1_, cell v2_)
|
cell factor_vm::allot_array_2(cell v1_, cell v2_)
|
||||||
{
|
{
|
||||||
data_root<object> v1(v1_,this);
|
data_root<object> v1(v1_,this);
|
||||||
|
@ -38,6 +42,7 @@ cell factor_vm::allot_array_2(cell v1_, cell v2_)
|
||||||
return a.value();
|
return a.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_)
|
cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_)
|
||||||
{
|
{
|
||||||
data_root<object> v1(v1_,this);
|
data_root<object> v1(v1_,this);
|
||||||
|
@ -52,6 +57,7 @@ cell factor_vm::allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_)
|
||||||
return a.value();
|
return a.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_resize_array()
|
void factor_vm::primitive_resize_array()
|
||||||
{
|
{
|
||||||
data_root<array> a(ctx->pop(),this);
|
data_root<array> a(ctx->pop(),this);
|
||||||
|
@ -60,6 +66,7 @@ void factor_vm::primitive_resize_array()
|
||||||
ctx->push(tag<array>(reallot_array(a.untagged(),capacity)));
|
ctx->push(tag<array>(reallot_array(a.untagged(),capacity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::std_vector_to_array(std::vector<cell> &elements)
|
cell factor_vm::std_vector_to_array(std::vector<cell> &elements)
|
||||||
{
|
{
|
||||||
cell element_count = elements.size();
|
cell element_count = elements.size();
|
||||||
|
@ -73,6 +80,7 @@ cell factor_vm::std_vector_to_array(std::vector<cell> &elements)
|
||||||
return objects.value();
|
return objects.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_array::add(cell elt_)
|
void growable_array::add(cell elt_)
|
||||||
{
|
{
|
||||||
factor_vm *parent = elements.parent;
|
factor_vm *parent = elements.parent;
|
||||||
|
@ -83,6 +91,7 @@ void growable_array::add(cell elt_)
|
||||||
parent->set_array_nth(elements.untagged(),count++,elt.value());
|
parent->set_array_nth(elements.untagged(),count++,elt.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_array::append(array *elts_)
|
void growable_array::append(array *elts_)
|
||||||
{
|
{
|
||||||
factor_vm *parent = elements.parent;
|
factor_vm *parent = elements.parent;
|
||||||
|
@ -98,6 +107,7 @@ void growable_array::append(array *elts_)
|
||||||
parent->set_array_nth(elements.untagged(),count++,array_nth(elts.untagged(),index));
|
parent->set_array_nth(elements.untagged(),count++,array_nth(elts.untagged(),index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_array::trim()
|
void growable_array::trim()
|
||||||
{
|
{
|
||||||
factor_vm *parent = elements.parent;
|
factor_vm *parent = elements.parent;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace factor
|
namespace factor
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
byte_array *factor_vm::allot_byte_array(cell size)
|
byte_array *factor_vm::allot_byte_array(cell size)
|
||||||
{
|
{
|
||||||
byte_array *array = allot_uninitialized_array<byte_array>(size);
|
byte_array *array = allot_uninitialized_array<byte_array>(size);
|
||||||
|
@ -10,18 +11,21 @@ byte_array *factor_vm::allot_byte_array(cell size)
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_byte_array()
|
void factor_vm::primitive_byte_array()
|
||||||
{
|
{
|
||||||
cell size = unbox_array_size();
|
cell size = unbox_array_size();
|
||||||
ctx->push(tag<byte_array>(allot_byte_array(size)));
|
ctx->push(tag<byte_array>(allot_byte_array(size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_uninitialized_byte_array()
|
void factor_vm::primitive_uninitialized_byte_array()
|
||||||
{
|
{
|
||||||
cell size = unbox_array_size();
|
cell size = unbox_array_size();
|
||||||
ctx->push(tag<byte_array>(allot_uninitialized_array<byte_array>(size)));
|
ctx->push(tag<byte_array>(allot_uninitialized_array<byte_array>(size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_resize_byte_array()
|
void factor_vm::primitive_resize_byte_array()
|
||||||
{
|
{
|
||||||
data_root<byte_array> array(ctx->pop(),this);
|
data_root<byte_array> array(ctx->pop(),this);
|
||||||
|
@ -30,6 +34,7 @@ void factor_vm::primitive_resize_byte_array()
|
||||||
ctx->push(tag<byte_array>(reallot_array(array.untagged(),capacity)));
|
ctx->push(tag<byte_array>(reallot_array(array.untagged(),capacity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_byte_array::grow_bytes(cell len)
|
void growable_byte_array::grow_bytes(cell len)
|
||||||
{
|
{
|
||||||
count += len;
|
count += len;
|
||||||
|
@ -37,6 +42,7 @@ void growable_byte_array::grow_bytes(cell len)
|
||||||
elements = elements.parent->reallot_array(elements.untagged(),count * 2);
|
elements = elements.parent->reallot_array(elements.untagged(),count * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_byte_array::append_bytes(void *elts, cell len)
|
void growable_byte_array::append_bytes(void *elts, cell len)
|
||||||
{
|
{
|
||||||
cell old_count = count;
|
cell old_count = count;
|
||||||
|
@ -44,6 +50,7 @@ void growable_byte_array::append_bytes(void *elts, cell len)
|
||||||
memcpy(&elements->data<u8>()[old_count],elts,len);
|
memcpy(&elements->data<u8>()[old_count],elts,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_byte_array::append_byte_array(cell byte_array_)
|
void growable_byte_array::append_byte_array(cell byte_array_)
|
||||||
{
|
{
|
||||||
data_root<byte_array> byte_array(byte_array_,elements.parent);
|
data_root<byte_array> byte_array(byte_array_,elements.parent);
|
||||||
|
@ -59,6 +66,7 @@ void growable_byte_array::append_byte_array(cell byte_array_)
|
||||||
count += len;
|
count += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void growable_byte_array::trim()
|
void growable_byte_array::trim()
|
||||||
{
|
{
|
||||||
factor_vm *parent = elements.parent;
|
factor_vm *parent = elements.parent;
|
||||||
|
|
|
@ -125,6 +125,7 @@ void callback_heap::update()
|
||||||
each_callback(updater);
|
each_callback(updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_callback()
|
void factor_vm::primitive_callback()
|
||||||
{
|
{
|
||||||
cell return_rewind = to_cell(ctx->pop());
|
cell return_rewind = to_cell(ctx->pop());
|
||||||
|
|
|
@ -143,11 +143,13 @@ context *factor_vm::new_context()
|
||||||
return new_context;
|
return new_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::init_context(context *ctx)
|
void factor_vm::init_context(context *ctx)
|
||||||
{
|
{
|
||||||
ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
|
ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
context *new_context(factor_vm *parent)
|
context *new_context(factor_vm *parent)
|
||||||
{
|
{
|
||||||
context *new_context = parent->new_context();
|
context *new_context = parent->new_context();
|
||||||
|
@ -173,12 +175,14 @@ VM_C_API void delete_context(factor_vm *parent, context *old_context)
|
||||||
parent->delete_context(old_context);
|
parent->delete_context(old_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
VM_C_API void reset_context(factor_vm *parent, context *ctx)
|
VM_C_API void reset_context(factor_vm *parent, context *ctx)
|
||||||
{
|
{
|
||||||
ctx->reset();
|
ctx->reset();
|
||||||
parent->init_context(ctx);
|
parent->init_context(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::begin_callback(cell quot_)
|
cell factor_vm::begin_callback(cell quot_)
|
||||||
{
|
{
|
||||||
data_root<object> quot(quot_,this);
|
data_root<object> quot(quot_,this);
|
||||||
|
@ -233,6 +237,7 @@ void factor_vm::primitive_context_object_for()
|
||||||
ctx->push(other_ctx->context_objects[n]);
|
ctx->push(other_ctx->context_objects[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
cell factor_vm::stack_to_array(cell bottom, cell top)
|
cell factor_vm::stack_to_array(cell bottom, cell top)
|
||||||
{
|
{
|
||||||
fixnum depth = (fixnum)(top - bottom + sizeof(cell));
|
fixnum depth = (fixnum)(top - bottom + sizeof(cell));
|
||||||
|
|
|
@ -41,6 +41,7 @@ void out_of_memory()
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_)
|
void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_)
|
||||||
{
|
{
|
||||||
data_root<object> arg1(arg1_,this);
|
data_root<object> arg1(arg1_,this);
|
||||||
|
|
|
@ -290,6 +290,7 @@ void factor_vm::primitive_compact_gc()
|
||||||
true /* trace contexts? */);
|
true /* trace contexts? */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
/*
|
/*
|
||||||
* It is up to the caller to fill in the object's fields in a meaningful
|
* It is up to the caller to fill in the object's fields in a meaningful
|
||||||
* fashion!
|
* fashion!
|
||||||
|
|
|
@ -78,6 +78,7 @@ void jit::emit(cell code_template_)
|
||||||
code.append_byte_array(insns.value());
|
code.append_byte_array(insns.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void jit::emit_with_literal(cell code_template_, cell argument_) {
|
void jit::emit_with_literal(cell code_template_, cell argument_) {
|
||||||
data_root<array> code_template(code_template_,parent);
|
data_root<array> code_template(code_template_,parent);
|
||||||
data_root<object> argument(argument_,parent);
|
data_root<object> argument(argument_,parent);
|
||||||
|
@ -85,6 +86,7 @@ void jit::emit_with_literal(cell code_template_, cell argument_) {
|
||||||
emit(code_template.value());
|
emit(code_template.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void jit::emit_with_parameter(cell code_template_, cell argument_) {
|
void jit::emit_with_parameter(cell code_template_, cell argument_) {
|
||||||
data_root<array> code_template(code_template_,parent);
|
data_root<array> code_template(code_template_,parent);
|
||||||
data_root<object> argument(argument_,parent);
|
data_root<object> argument(argument_,parent);
|
||||||
|
@ -92,6 +94,7 @@ void jit::emit_with_parameter(cell code_template_, cell argument_) {
|
||||||
emit(code_template.value());
|
emit(code_template.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
bool jit::emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p)
|
bool jit::emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p)
|
||||||
{
|
{
|
||||||
data_root<word> word(word_,parent);
|
data_root<word> word(word_,parent);
|
||||||
|
@ -99,6 +102,7 @@ bool jit::emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p)
|
||||||
parameters.append(untag<array>(array_nth(code_template.untagged(),0)));
|
parameters.append(untag<array>(array_nth(code_template.untagged(),0)));
|
||||||
literals.append(untag<array>(array_nth(code_template.untagged(),1)));
|
literals.append(untag<array>(array_nth(code_template.untagged(),1)));
|
||||||
emit(array_nth(code_template.untagged(),2));
|
emit(array_nth(code_template.untagged(),2));
|
||||||
|
|
||||||
if(array_capacity(code_template.untagged()) == 5)
|
if(array_capacity(code_template.untagged()) == 5)
|
||||||
{
|
{
|
||||||
if(tail_call_p)
|
if(tail_call_p)
|
||||||
|
|
|
@ -122,6 +122,7 @@ void factor_vm::primitive_sampling_profiler()
|
||||||
set_sampling_profiler(to_fixnum(ctx->pop()));
|
set_sampling_profiler(to_fixnum(ctx->pop()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_get_samples()
|
void factor_vm::primitive_get_samples()
|
||||||
{
|
{
|
||||||
if (atomic::load(&sampling_profiler_p) || samples.empty()) {
|
if (atomic::load(&sampling_profiler_p) || samples.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue