VM: make allot_alien() and ffi_dlsym() use cell instead of void*
this way we get rid of a bunch of superfluous castsdb4
							parent
							
								
									1045f41778
								
							
						
					
					
						commit
						a53d5be683
					
				| 
						 | 
					@ -47,8 +47,8 @@ cell factor_vm::allot_alien(cell delegate_, cell displacement) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory */
 | 
					/* Allocates memory */
 | 
				
			||||||
cell factor_vm::allot_alien(void* address) {
 | 
					cell factor_vm::allot_alien(cell address) {
 | 
				
			||||||
  return allot_alien(false_object, (cell)address);
 | 
					  return allot_alien(false_object, address);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* make an alien pointing at an offset of another alien */
 | 
					/* make an alien pointing at an offset of another alien */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,7 +125,7 @@ void factor_vm::primitive_callback() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cell func = callbacks->add(w.value(), return_rewind)->entry_point();
 | 
					  cell func = callbacks->add(w.value(), return_rewind)->entry_point();
 | 
				
			||||||
  CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
 | 
					  CODE_TO_FUNCTION_POINTER_CALLBACK(this, func);
 | 
				
			||||||
  ctx->push(allot_alien((void*)func));
 | 
					  ctx->push(allot_alien(func));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void factor_vm::primitive_free_callback() {
 | 
					void factor_vm::primitive_free_callback() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,8 +114,8 @@ void factor_vm::primitive_set_innermost_stack_frame_quotation() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory (allot_alien) */
 | 
					/* Allocates memory (allot_alien) */
 | 
				
			||||||
void factor_vm::primitive_callstack_bounds() {
 | 
					void factor_vm::primitive_callstack_bounds() {
 | 
				
			||||||
  ctx->push(allot_alien((void*)ctx->callstack_seg->start));
 | 
					  ctx->push(allot_alien(ctx->callstack_seg->start));
 | 
				
			||||||
  ctx->push(allot_alien((void*)ctx->callstack_seg->end));
 | 
					  ctx->push(allot_alien(ctx->callstack_seg->end));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -149,31 +149,27 @@ cell factor_vm::compute_dlsym_address(array* parameters, cell index) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
 | 
					  dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void* undefined_symbol = (void*)factor::undefined_symbol;
 | 
					  cell undefined_symbol = (cell)factor::undefined_symbol;
 | 
				
			||||||
  undefined_symbol = FUNCTION_CODE_POINTER(undefined_symbol);
 | 
					  undefined_symbol = FUNCTION_CODE_POINTER(undefined_symbol);
 | 
				
			||||||
  if (d != NULL && !d->handle)
 | 
					  if (d != NULL && !d->handle)
 | 
				
			||||||
    return (cell)undefined_symbol;
 | 
					    return undefined_symbol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (tagged<object>(symbol).type()) {
 | 
					  switch (tagged<object>(symbol).type()) {
 | 
				
			||||||
    case BYTE_ARRAY_TYPE: {
 | 
					    case BYTE_ARRAY_TYPE: {
 | 
				
			||||||
      symbol_char* name = alien_offset(symbol);
 | 
					      symbol_char* name = alien_offset(symbol);
 | 
				
			||||||
      void* sym = ffi_dlsym(d, name);
 | 
					      cell sym = ffi_dlsym(d, name);
 | 
				
			||||||
 | 
					      return sym ? sym : undefined_symbol;
 | 
				
			||||||
      if (sym)
 | 
					 | 
				
			||||||
        return (cell)sym;
 | 
					 | 
				
			||||||
      else
 | 
					 | 
				
			||||||
        return (cell)undefined_symbol;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case ARRAY_TYPE: {
 | 
					    case ARRAY_TYPE: {
 | 
				
			||||||
      array* names = untag<array>(symbol);
 | 
					      array* names = untag<array>(symbol);
 | 
				
			||||||
      for (cell i = 0; i < array_capacity(names); i++) {
 | 
					      for (cell i = 0; i < array_capacity(names); i++) {
 | 
				
			||||||
        symbol_char* name = alien_offset(array_nth(names, i));
 | 
					        symbol_char* name = alien_offset(array_nth(names, i));
 | 
				
			||||||
        void* sym = ffi_dlsym(d, name);
 | 
					        cell sym = ffi_dlsym(d, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (sym)
 | 
					        if (sym)
 | 
				
			||||||
          return (cell)sym;
 | 
					          return sym;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      return (cell)undefined_symbol;
 | 
					      return undefined_symbol;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
      return -1;
 | 
					      return -1;
 | 
				
			||||||
| 
						 | 
					@ -187,30 +183,26 @@ cell factor_vm::compute_dlsym_toc_address(array* parameters, cell index) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
 | 
					  dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void* undefined_toc = (void*)factor::undefined_symbol;
 | 
					  cell undefined_toc = (cell)factor::undefined_symbol;
 | 
				
			||||||
  undefined_toc = FUNCTION_TOC_POINTER(undefined_toc);
 | 
					  undefined_toc = FUNCTION_TOC_POINTER(undefined_toc);
 | 
				
			||||||
  if (d != NULL && !d->handle)
 | 
					  if (d != NULL && !d->handle)
 | 
				
			||||||
    return (cell)undefined_toc;
 | 
					    return undefined_toc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (tagged<object>(symbol).type()) {
 | 
					  switch (tagged<object>(symbol).type()) {
 | 
				
			||||||
    case BYTE_ARRAY_TYPE: {
 | 
					    case BYTE_ARRAY_TYPE: {
 | 
				
			||||||
      symbol_char* name = alien_offset(symbol);
 | 
					      symbol_char* name = alien_offset(symbol);
 | 
				
			||||||
      void* toc = ffi_dlsym_toc(d, name);
 | 
					      cell toc = ffi_dlsym_toc(d, name);
 | 
				
			||||||
      if (toc)
 | 
					      return toc ? toc : undefined_toc;
 | 
				
			||||||
        return (cell)toc;
 | 
					 | 
				
			||||||
      else
 | 
					 | 
				
			||||||
        return (cell)undefined_toc;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case ARRAY_TYPE: {
 | 
					    case ARRAY_TYPE: {
 | 
				
			||||||
      array* names = untag<array>(symbol);
 | 
					      array* names = untag<array>(symbol);
 | 
				
			||||||
      for (cell i = 0; i < array_capacity(names); i++) {
 | 
					      for (cell i = 0; i < array_capacity(names); i++) {
 | 
				
			||||||
        symbol_char* name = alien_offset(array_nth(names, i));
 | 
					        symbol_char* name = alien_offset(array_nth(names, i));
 | 
				
			||||||
        void* toc = ffi_dlsym_toc(d, name);
 | 
					        cell toc = ffi_dlsym_toc(d, name);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (toc)
 | 
					        if (toc)
 | 
				
			||||||
          return (cell)toc;
 | 
					          return toc;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      return (cell)undefined_toc;
 | 
					      return undefined_toc;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
      return -1;
 | 
					      return -1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,7 +121,7 @@ context* factor_vm::new_context() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory */
 | 
					/* 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((cell)ctx);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory (init_context(), but not parent->new_context() */
 | 
					/* Allocates memory (init_context(), but not parent->new_context() */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -171,8 +171,9 @@ void factor_vm::primitive_fopen() {
 | 
				
			||||||
  path.untag_check(this);
 | 
					  path.untag_check(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  FILE* file;
 | 
					  FILE* file;
 | 
				
			||||||
  file = safe_fopen((char*)(path.untagged() + 1), (char*)(mode.untagged() + 1));
 | 
					  file = safe_fopen((char*)(path.untagged() + 1),
 | 
				
			||||||
  ctx->push(allot_alien(file));
 | 
					                    (char*)(mode.untagged() + 1));
 | 
				
			||||||
 | 
					  ctx->push(allot_alien((cell)file));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FILE* factor_vm::pop_file_handle() { return (FILE*)alien_offset(ctx->pop()); }
 | 
					FILE* factor_vm::pop_file_handle() { return (FILE*)alien_offset(ctx->pop()); }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,16 +39,16 @@ void factor_vm::ffi_dlopen(dll* dll) {
 | 
				
			||||||
  dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL);
 | 
					  dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void* factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
 | 
					cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
 | 
				
			||||||
  return dlsym(dll ? dll->handle : null_dll, symbol);
 | 
					  return (cell)dlsym(dll ? dll->handle : null_dll, symbol);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void* factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
 | 
					cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
 | 
				
			||||||
  return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
 | 
					  return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef FACTOR_PPC
 | 
					#ifdef FACTOR_PPC
 | 
				
			||||||
void* factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
 | 
					cell factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
 | 
				
			||||||
  return FUNCTION_TOC_POINTER(ffi_dlsym_raw(dll, symbol));
 | 
					  return FUNCTION_TOC_POINTER(ffi_dlsym_raw(dll, symbol));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -384,12 +384,9 @@ void safe_close(int fd) {
 | 
				
			||||||
bool check_write(int fd, void* data, ssize_t size) {
 | 
					bool check_write(int fd, void* data, ssize_t size) {
 | 
				
			||||||
  if (write(fd, data, size) == size)
 | 
					  if (write(fd, data, size) == size)
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  else {
 | 
					  if (errno == EINTR)
 | 
				
			||||||
    if (errno == EINTR)
 | 
					    return check_write(fd, data, size);
 | 
				
			||||||
      return check_write(fd, data, size);
 | 
					  return false;
 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      return false;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void safe_write(int fd, void* data, ssize_t size) {
 | 
					void safe_write(int fd, void* data, ssize_t size) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,12 +14,12 @@ void factor_vm::ffi_dlopen(dll* dll) {
 | 
				
			||||||
  dll->handle = LoadLibraryEx((WCHAR*)alien_offset(dll->path), NULL, 0);
 | 
					  dll->handle = LoadLibraryEx((WCHAR*)alien_offset(dll->path), NULL, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void* factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
 | 
					cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
 | 
				
			||||||
  return (void*)GetProcAddress(dll ? (HMODULE) dll->handle : hFactorDll,
 | 
					  return (cell)GetProcAddress(dll ? (HMODULE) dll->handle : hFactorDll,
 | 
				
			||||||
                               symbol);
 | 
					                              symbol);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void* factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
 | 
					cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
 | 
				
			||||||
  return ffi_dlsym(dll, symbol);
 | 
					  return ffi_dlsym(dll, symbol);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ namespace factor {
 | 
				
			||||||
      _(wrapper)
 | 
					      _(wrapper)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define EACH_ALIEN_PRIMITIVE(_)                               \
 | 
					#define EACH_ALIEN_PRIMITIVE(_)                               \
 | 
				
			||||||
  _(signed_cell, fixnum, from_signed_cell, to_fixnum)         \
 | 
					      _(signed_cell, fixnum, from_signed_cell, to_fixnum)     \
 | 
				
			||||||
      _(unsigned_cell, cell, from_unsigned_cell, to_cell)     \
 | 
					      _(unsigned_cell, cell, from_unsigned_cell, to_cell)     \
 | 
				
			||||||
      _(signed_8, int64_t, from_signed_8, to_signed_8)        \
 | 
					      _(signed_8, int64_t, from_signed_8, to_signed_8)        \
 | 
				
			||||||
      _(unsigned_8, uint64_t, from_unsigned_8, to_unsigned_8) \
 | 
					      _(unsigned_8, uint64_t, from_unsigned_8, to_unsigned_8) \
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ namespace factor {
 | 
				
			||||||
      _(unsigned_1, uint8_t, from_unsigned_cell, to_cell)     \
 | 
					      _(unsigned_1, uint8_t, from_unsigned_cell, to_cell)     \
 | 
				
			||||||
      _(float, float, allot_float, to_float)                  \
 | 
					      _(float, float, allot_float, to_float)                  \
 | 
				
			||||||
      _(double, double, allot_float, to_double)               \
 | 
					      _(double, double, allot_float, to_double)               \
 | 
				
			||||||
      _(cell, void*, allot_alien, pinned_alien_offset)
 | 
					      _(cell, cell, allot_alien, pinned_alien_offset)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define DECLARE_PRIMITIVE(name) \
 | 
					#define DECLARE_PRIMITIVE(name) \
 | 
				
			||||||
  VM_C_API void primitive_##name(factor_vm * parent);
 | 
					  VM_C_API void primitive_##name(factor_vm * parent);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -659,7 +659,7 @@ struct factor_vm {
 | 
				
			||||||
  // alien
 | 
					  // alien
 | 
				
			||||||
  char* pinned_alien_offset(cell obj);
 | 
					  char* pinned_alien_offset(cell obj);
 | 
				
			||||||
  cell allot_alien(cell delegate_, cell displacement);
 | 
					  cell allot_alien(cell delegate_, cell displacement);
 | 
				
			||||||
  cell allot_alien(void* address);
 | 
					  cell allot_alien(cell address);
 | 
				
			||||||
  void primitive_displaced_alien();
 | 
					  void primitive_displaced_alien();
 | 
				
			||||||
  void primitive_alien_address();
 | 
					  void primitive_alien_address();
 | 
				
			||||||
  void* alien_pointer();
 | 
					  void* alien_pointer();
 | 
				
			||||||
| 
						 | 
					@ -738,10 +738,10 @@ struct factor_vm {
 | 
				
			||||||
  void move_file(const vm_char* path1, const vm_char* path2);
 | 
					  void move_file(const vm_char* path1, const vm_char* path2);
 | 
				
			||||||
  void init_ffi();
 | 
					  void init_ffi();
 | 
				
			||||||
  void ffi_dlopen(dll* dll);
 | 
					  void ffi_dlopen(dll* dll);
 | 
				
			||||||
  void* ffi_dlsym(dll* dll, symbol_char* symbol);
 | 
					  cell ffi_dlsym(dll* dll, symbol_char* symbol);
 | 
				
			||||||
  void* ffi_dlsym_raw(dll* dll, symbol_char* symbol);
 | 
					  cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
 | 
				
			||||||
#ifdef FACTOR_PPC
 | 
					#ifdef FACTOR_PPC
 | 
				
			||||||
  void* ffi_dlsym_toc(dll* dll, symbol_char* symbol);
 | 
					  cell ffi_dlsym_toc(dll* dll, symbol_char* symbol);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  void ffi_dlclose(dll* dll);
 | 
					  void ffi_dlclose(dll* dll);
 | 
				
			||||||
  void c_to_factor_toplevel(cell quot);
 | 
					  void c_to_factor_toplevel(cell quot);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue