]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/contexts.cpp
webapps.wiki: adding search bar
[factor.git] / vm / contexts.cpp
index 8480ee7bf79e458e3c6f6fa1d582128711aa03c4..48afadaa279556b99e9a1ecced1151e89474d5f9 100644 (file)
@@ -2,16 +2,15 @@
 
 namespace factor {
 
-context::context(cell datastack_size, cell retainstack_size,
-                 cell callstack_size)
+context::context(cell ds_size, cell rs_size, cell cs_size)
     : callstack_top(0),
       callstack_bottom(0),
       datastack(0),
       retainstack(0),
       callstack_save(0),
-      datastack_seg(new segment(datastack_size, false)),
-      retainstack_seg(new segment(retainstack_size, false)),
-      callstack_seg(new segment(callstack_size, false)) {
+      datastack_seg(new segment(ds_size, false)),
+      retainstack_seg(new segment(rs_size, false)),
+      callstack_seg(new segment(cs_size, false)) {
   reset();
 }
 
@@ -39,6 +38,10 @@ void context::fill_stack_seg(cell top_ptr, segment* seg, cell pattern) {
   cell clear_start = top_ptr + sizeof(cell);
   cell clear_size = seg->end - clear_start;
   memset_cell((void*)clear_start, pattern, clear_size);
+#else
+  (void)top_ptr;
+  (void)seg;
+  (void)pattern;
 #endif
 }
 
@@ -51,7 +54,7 @@ vm_error_type context::address_to_error(cell addr) {
     return ERROR_RETAINSTACK_UNDERFLOW;
   if (retainstack_seg->overflow_p(addr))
     return ERROR_RETAINSTACK_OVERFLOW;
-  /* These are flipped because the callstack grows downwards. */
+  // These are flipped because the callstack grows downwards.
   if (callstack_seg->underflow_p(addr))
     return ERROR_CALLSTACK_OVERFLOW;
   if (callstack_seg->overflow_p(addr))
@@ -82,26 +85,6 @@ context::~context() {
   delete callstack_seg;
 }
 
-/* called on startup */
-/* Allocates memory (new_context()) */
-void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_,
-                              cell callstack_size_) {
-  datastack_size = datastack_size_;
-  retainstack_size = retainstack_size_;
-  callstack_size = callstack_size_;
-
-  ctx = NULL;
-  spare_ctx = new_context();
-}
-
-void factor_vm::delete_contexts() {
-  FACTOR_ASSERT(!ctx);
-  FACTOR_FOR_EACH(unused_contexts) {
-    delete *iter;
-    iter++;
-  }
-}
-
 context* factor_vm::new_context() {
   context* new_context;
 
@@ -119,12 +102,12 @@ context* factor_vm::new_context() {
   return new_context;
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::init_context(context* ctx) {
   ctx->context_objects[OBJ_CONTEXT] = allot_alien((cell)ctx);
 }
 
-/* Allocates memory (init_context(), but not parent->new_context() */
+// Allocates memory (init_context(), but not parent->new_context()
 VM_C_API context* new_context(factor_vm* parent) {
   context* new_context = parent->new_context();
   parent->init_context(new_context);
@@ -146,7 +129,7 @@ VM_C_API void delete_context(factor_vm* parent) {
   parent->delete_context();
 }
 
-/* Allocates memory (init_context()) */
+// Allocates memory (init_context())
 VM_C_API void reset_context(factor_vm* parent) {
 
   // The function is used by (start-context-and-delete) which expects
@@ -162,7 +145,7 @@ VM_C_API void reset_context(factor_vm* parent) {
   parent->init_context(ctx);
 }
 
-/* Allocates memory */
+// Allocates memory
 cell factor_vm::begin_callback(cell quot_) {
   data_root<object> quot(quot_, this);
 
@@ -175,7 +158,7 @@ cell factor_vm::begin_callback(cell quot_) {
   return quot.value();
 }
 
-/* Allocates memory */
+// Allocates memory
 cell begin_callback(factor_vm* parent, cell quot) {
   return parent->begin_callback(quot);
 }
@@ -208,7 +191,7 @@ void factor_vm::primitive_context_object_for() {
   ctx->replace(other_ctx->context_objects[n]);
 }
 
-/* Allocates memory */
+// Allocates memory
 cell factor_vm::stack_to_array(cell bottom, cell top, vm_error_type error) {
   fixnum depth = (fixnum)(top - bottom + sizeof(cell));
 
@@ -220,14 +203,14 @@ cell factor_vm::stack_to_array(cell bottom, cell top, vm_error_type error) {
   return tag<array>(a);
 }
 
-/* Allocates memory */
+// Allocates memory
 cell factor_vm::datastack_to_array(context* ctx) {
   return stack_to_array(ctx->datastack_seg->start,
                         ctx->datastack,
                         ERROR_DATASTACK_UNDERFLOW);
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::primitive_datastack_for() {
   data_root<alien> alien_ctx(ctx->pop(), this);
   context* other_ctx = (context*)pinned_alien_offset(alien_ctx.value());
@@ -235,43 +218,37 @@ void factor_vm::primitive_datastack_for() {
   ctx->push(array);
 }
 
-/* Allocates memory */
+// Allocates memory
 cell factor_vm::retainstack_to_array(context* ctx) {
   return stack_to_array(ctx->retainstack_seg->start,
                         ctx->retainstack,
                         ERROR_RETAINSTACK_UNDERFLOW);
 }
 
-/* Allocates memory */
+// Allocates memory
 void factor_vm::primitive_retainstack_for() {
   context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
   ctx->replace(retainstack_to_array(other_ctx));
 }
 
-/* returns pointer to top of stack */
-cell factor_vm::array_to_stack(array* array, cell bottom) {
+// returns pointer to top of stack
+static cell array_to_stack(array* array, cell bottom) {
   cell depth = array_capacity(array) * sizeof(cell);
   memcpy((void*)bottom, array + 1, depth);
   return bottom + depth - sizeof(cell);
 }
 
-void factor_vm::set_datastack(context* ctx, array* array) {
-  ctx->datastack = array_to_stack(array, ctx->datastack_seg->start);
-}
-
 void factor_vm::primitive_set_datastack() {
-  set_datastack(ctx, untag_check<array>(ctx->pop()));
-}
-
-void factor_vm::set_retainstack(context* ctx, array* array) {
-  ctx->retainstack = array_to_stack(array, ctx->retainstack_seg->start);
+  array* arr = untag_check<array>(ctx->pop());
+  ctx->datastack = array_to_stack(arr, ctx->datastack_seg->start);
 }
 
 void factor_vm::primitive_set_retainstack() {
-  set_retainstack(ctx, untag_check<array>(ctx->pop()));
+  array* arr = untag_check<array>(ctx->pop());
+  ctx->retainstack = array_to_stack(arr, ctx->retainstack_seg->start);
 }
 
-/* Used to implement call( */
+// Used to implement call(
 void factor_vm::primitive_check_datastack() {
   fixnum out = to_fixnum(ctx->pop());
   fixnum in = to_fixnum(ctx->pop());