parent
							
								
									49bcbaee7a
								
							
						
					
					
						commit
						c675694619
					
				| 
						 | 
				
			
			@ -124,7 +124,7 @@ void callback_heap::update() {
 | 
			
		|||
  allocator->iterate(updater);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (add(), allot_alien())*/
 | 
			
		||||
void factor_vm::primitive_callback() {
 | 
			
		||||
  cell return_rewind = to_cell(ctx->pop());
 | 
			
		||||
  tagged<word> w(ctx->pop());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,6 +83,7 @@ struct stack_frame_in_array {
 | 
			
		|||
  cell cells[3];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (frames.trim()), iterate_callstack_object() */
 | 
			
		||||
void factor_vm::primitive_callstack_to_array() {
 | 
			
		||||
  data_root<callstack> callstack(ctx->peek(), this);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,6 +56,7 @@ context::~context() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/* 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_;
 | 
			
		||||
| 
						 | 
				
			
			@ -98,7 +99,7 @@ void factor_vm::init_context(context* ctx) {
 | 
			
		|||
  ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (init_context(), but not parent->new_context() */
 | 
			
		||||
context* new_context(factor_vm* parent) {
 | 
			
		||||
  context* new_context = parent->new_context();
 | 
			
		||||
  parent->init_context(new_context);
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +121,7 @@ VM_C_API void delete_context(factor_vm* parent, context* old_context) {
 | 
			
		|||
  parent->delete_context(old_context);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (init_context()) */
 | 
			
		||||
VM_C_API void reset_context(factor_vm* parent, context* ctx) {
 | 
			
		||||
  ctx->reset();
 | 
			
		||||
  parent->init_context(ctx);
 | 
			
		||||
| 
						 | 
				
			
			@ -139,6 +140,7 @@ cell factor_vm::begin_callback(cell quot_) {
 | 
			
		|||
  return quot.value();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
cell begin_callback(factor_vm* parent, cell quot) {
 | 
			
		||||
  return parent->begin_callback(quot);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -184,6 +186,7 @@ cell factor_vm::stack_to_array(cell bottom, cell top) {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
cell factor_vm::datastack_to_array(context* ctx) {
 | 
			
		||||
  cell array = stack_to_array(ctx->datastack_seg->start, ctx->datastack);
 | 
			
		||||
  if (array == false_object) {
 | 
			
		||||
| 
						 | 
				
			
			@ -193,13 +196,16 @@ cell factor_vm::datastack_to_array(context* ctx) {
 | 
			
		|||
    return array;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_datastack() { ctx->push(datastack_to_array(ctx)); }
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_datastack_for() {
 | 
			
		||||
  context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
 | 
			
		||||
  ctx->replace(datastack_to_array(other_ctx));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
cell factor_vm::retainstack_to_array(context* ctx) {
 | 
			
		||||
  cell array = stack_to_array(ctx->retainstack_seg->start, ctx->retainstack);
 | 
			
		||||
  if (array == false_object) {
 | 
			
		||||
| 
						 | 
				
			
			@ -209,10 +215,12 @@ cell factor_vm::retainstack_to_array(context* ctx) {
 | 
			
		|||
    return array;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_retainstack() {
 | 
			
		||||
  ctx->push(retainstack_to_array(ctx));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_retainstack_for() {
 | 
			
		||||
  context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
 | 
			
		||||
  ctx->replace(retainstack_to_array(other_ctx));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,7 +39,6 @@ void out_of_memory(const char *msg) {
 | 
			
		|||
/* Allocates memory */
 | 
			
		||||
void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  data_root<object> arg1(arg1_, this);
 | 
			
		||||
  data_root<object> arg2(arg2_, this);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -91,10 +90,12 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::type_error(cell type, cell tagged) {
 | 
			
		||||
  general_error(ERROR_TYPE, tag_fixnum(type), tagged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::not_implemented_error() {
 | 
			
		||||
  general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -137,17 +138,21 @@ void factor_vm::signal_error(cell signal) {
 | 
			
		|||
  general_error(ERROR_SIGNAL, from_unsigned_cell(signal), false_object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::divide_by_zero_error() {
 | 
			
		||||
  general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::fp_trap_error(unsigned int fpu_status) {
 | 
			
		||||
  general_error(ERROR_FP_TRAP, tag_fixnum(fpu_status), false_object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* For testing purposes */
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_unimplemented() { not_implemented_error(); }
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::memory_signal_handler_impl() {
 | 
			
		||||
  memory_protection_error(signal_fault_pc, signal_fault_addr);
 | 
			
		||||
  if (!signal_resumable) {
 | 
			
		||||
| 
						 | 
				
			
			@ -157,18 +162,22 @@ void factor_vm::memory_signal_handler_impl() {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void memory_signal_handler_impl() {
 | 
			
		||||
  current_vm()->memory_signal_handler_impl();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::synchronous_signal_handler_impl() {
 | 
			
		||||
  signal_error(signal_number);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void synchronous_signal_handler_impl() {
 | 
			
		||||
  current_vm()->synchronous_signal_handler_impl();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (fp_trap_error())*/
 | 
			
		||||
void factor_vm::fp_signal_handler_impl() {
 | 
			
		||||
  /* Clear pending exceptions to avoid getting stuck in a loop */
 | 
			
		||||
  set_fpu_state(get_fpu_state());
 | 
			
		||||
| 
						 | 
				
			
			@ -176,5 +185,6 @@ void factor_vm::fp_signal_handler_impl() {
 | 
			
		|||
  fp_trap_error(signal_fpu_status);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void fp_signal_handler_impl() { current_vm()->fp_signal_handler_impl(); }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -235,6 +235,7 @@ void factor_vm::primitive_enable_gc_events() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (byte_array_from_value, result.add) */
 | 
			
		||||
/* XXX: Remember that growable_array has a data_root already */
 | 
			
		||||
void factor_vm::primitive_disable_gc_events() {
 | 
			
		||||
  if (gc_events) {
 | 
			
		||||
    growable_array result(this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -334,6 +334,7 @@ void factor_vm::primitive_save_image() {
 | 
			
		|||
             (vm_char*)(path2.untagged() + 1));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_save_image_and_exit() {
 | 
			
		||||
  /* We unbox this before doing anything else. This is the only point
 | 
			
		||||
     where we might throw an error, so we have to throw an error here since
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,7 @@ void factor_vm::init_c_io() {
 | 
			
		|||
  special_objects[OBJ_STDERR] = allot_alien(false_object, (cell)stderr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::io_error() {
 | 
			
		||||
  if (errno == EINTR)
 | 
			
		||||
    return;
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +177,7 @@ void factor_vm::primitive_fgetc() {
 | 
			
		|||
    ctx->replace(tag_fixnum(c));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (from_unsigned_cell())*/
 | 
			
		||||
void factor_vm::primitive_fread() {
 | 
			
		||||
  FILE* file = pop_file_handle();
 | 
			
		||||
  void* buf = (void*)alien_offset(ctx->pop());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,7 +113,7 @@ void jit::compute_position(cell offset_) {
 | 
			
		|||
  offset = offset_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (trim(), add_code_block) */
 | 
			
		||||
code_block* jit::to_code_block(cell frame_size) {
 | 
			
		||||
  /* Emit dummy GC info */
 | 
			
		||||
  code.grow_bytes(alignment_for(code.count + 4, data_alignment));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,17 +22,20 @@ struct jit {
 | 
			
		|||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void parameter(cell parameter) { parameters.add(parameter); }
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void emit_with_parameter(cell code_template_, cell parameter_);
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void literal(cell literal) { literals.add(literal); }
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void emit_with_literal(cell code_template_, cell literal_);
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void push(cell literal) {
 | 
			
		||||
    emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE], literal);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  /* Allocates memory (literal(), emit())*/
 | 
			
		||||
  void word_jump(cell word_) {
 | 
			
		||||
    data_root<word> word(word_, parent);
 | 
			
		||||
#ifndef FACTOR_AMD64
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,6 +60,7 @@ inline fixnum factor_vm::branchless_abs(fixnum x) {
 | 
			
		|||
  return (x ^ sign_mask(x)) - sign_mask(x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_fixnum_shift() {
 | 
			
		||||
  fixnum y = untag_fixnum(ctx->pop());
 | 
			
		||||
  fixnum x = untag_fixnum(ctx->peek());
 | 
			
		||||
| 
						 | 
				
			
			@ -81,10 +82,12 @@ void factor_vm::primitive_fixnum_shift() {
 | 
			
		|||
  ctx->replace(tag<bignum>(bignum_arithmetic_shift(fixnum_to_bignum(x), y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_fixnum_to_bignum() {
 | 
			
		||||
  ctx->replace(tag<bignum>(fixnum_to_bignum(untag_fixnum(ctx->peek()))));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_float_to_bignum() {
 | 
			
		||||
  ctx->replace(tag<bignum>(float_to_bignum(ctx->peek())));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -98,26 +101,31 @@ void factor_vm::primitive_bignum_eq() {
 | 
			
		|||
  ctx->replace(tag_boolean(bignum_equal_p(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_add() {
 | 
			
		||||
  POP_BIGNUMS(x, y);
 | 
			
		||||
  ctx->replace(tag<bignum>(bignum_add(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_subtract() {
 | 
			
		||||
  POP_BIGNUMS(x, y);
 | 
			
		||||
  ctx->replace(tag<bignum>(bignum_subtract(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_multiply() {
 | 
			
		||||
  POP_BIGNUMS(x, y);
 | 
			
		||||
  ctx->replace(tag<bignum>(bignum_multiply(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_divint() {
 | 
			
		||||
  POP_BIGNUMS(x, y);
 | 
			
		||||
  ctx->replace(tag<bignum>(bignum_quotient(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_divmod() {
 | 
			
		||||
  cell* s0 = (cell*)(ctx->datastack);
 | 
			
		||||
  cell* s1 = (cell*)(ctx->datastack - sizeof(cell));
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +162,7 @@ void factor_vm::primitive_bignum_xor() {
 | 
			
		|||
  ctx->replace(tag<bignum>(bignum_bitwise_xor(x, y)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void factor_vm::primitive_bignum_shift() {
 | 
			
		||||
  fixnum y = untag_fixnum(ctx->pop());
 | 
			
		||||
  bignum* x = untag<bignum>(ctx->peek());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -121,6 +121,7 @@ struct code_block_write_barrier_visitor {
 | 
			
		|||
 | 
			
		||||
/* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this
 | 
			
		||||
   to coalesce equal but distinct quotations and wrappers. */
 | 
			
		||||
/* Calls gc */
 | 
			
		||||
void factor_vm::primitive_become() {
 | 
			
		||||
  primitive_minor_gc();
 | 
			
		||||
  array* new_objects = untag_check<array>(ctx->pop());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -197,7 +197,7 @@ void quotation_jit::iterate_quotation() {
 | 
			
		|||
                                        i == length - 1, /* tail_call_p */
 | 
			
		||||
                                        stack_frame);    /* stack_frame_p */
 | 
			
		||||
        }                                                /* Everything else */
 | 
			
		||||
            else if (i == length - 1) {
 | 
			
		||||
        else if (i == length - 1) {
 | 
			
		||||
          emit_epilog(safepoint, stack_frame);
 | 
			
		||||
          tail_call = true;
 | 
			
		||||
          word_jump(obj.value());
 | 
			
		||||
| 
						 | 
				
			
			@ -241,17 +241,17 @@ void quotation_jit::iterate_quotation() {
 | 
			
		|||
 | 
			
		||||
          i += 2;
 | 
			
		||||
        } /* dip */
 | 
			
		||||
            else if (fast_dip_p(i, length)) {
 | 
			
		||||
        else if (fast_dip_p(i, length)) {
 | 
			
		||||
          emit_quot(obj.value());
 | 
			
		||||
          emit(parent->special_objects[JIT_DIP]);
 | 
			
		||||
          i++;
 | 
			
		||||
        } /* 2dip */
 | 
			
		||||
            else if (fast_2dip_p(i, length)) {
 | 
			
		||||
        else if (fast_2dip_p(i, length)) {
 | 
			
		||||
          emit_quot(obj.value());
 | 
			
		||||
          emit(parent->special_objects[JIT_2DIP]);
 | 
			
		||||
          i++;
 | 
			
		||||
        } /* 3dip */
 | 
			
		||||
            else if (fast_3dip_p(i, length)) {
 | 
			
		||||
        else if (fast_3dip_p(i, length)) {
 | 
			
		||||
          emit_quot(obj.value());
 | 
			
		||||
          emit(parent->special_objects[JIT_3DIP]);
 | 
			
		||||
          i++;
 | 
			
		||||
| 
						 | 
				
			
			@ -272,7 +272,7 @@ void quotation_jit::iterate_quotation() {
 | 
			
		|||
                                 array_nth(elements.untagged(), i + 2));
 | 
			
		||||
          i += 3;
 | 
			
		||||
        } /* Non-optimizing compiler ignores declarations */
 | 
			
		||||
            else if (declare_p(i, length))
 | 
			
		||||
        else if (declare_p(i, length))
 | 
			
		||||
          i++;
 | 
			
		||||
        else
 | 
			
		||||
          push(obj.value());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue