当前位置: 首页>>代码示例>>C++>>正文


C++ Int_val函数代码示例

本文整理汇总了C++中Int_val函数的典型用法代码示例。如果您正苦于以下问题:C++ Int_val函数的具体用法?C++ Int_val怎么用?C++ Int_val使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Int_val函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setRightLife

value setRightLife(val)
{
	fi.rightLife = Int_val(val);
	return Val_unit;
}
开发者ID:hassenc,项目名称:Game,代码行数:5,代码来源:fightInterface.c

示例2: caml_sys_close

CAMLprim value caml_sys_close(value fd)
{
  close(Int_val(fd));
  return Val_unit;
}
开发者ID:jessicah,项目名称:snowflake-jocaml,代码行数:5,代码来源:sys.c

示例3: caml_ba_map_file

CAMLprim value caml_ba_map_file(value vfd, value vkind, value vlayout,
                                value vshared, value vdim, value vstart)
{
  HANDLE fd, fmap;
  int flags, major_dim, mode, perm;
  intnat num_dims, i;
  intnat dim[CAML_BA_MAX_NUM_DIMS];
  __int64 currpos, startpos, file_size, data_size;
  uintnat array_size, page, delta;
  char c;
  void * addr;
  LARGE_INTEGER li;
  SYSTEM_INFO sysinfo;

  fd = Handle_val(vfd);
  flags = Int_val(vkind) | Int_val(vlayout);
  startpos = Int64_val(vstart);
  num_dims = Wosize_val(vdim);
  major_dim = flags & CAML_BA_FORTRAN_LAYOUT ? num_dims - 1 : 0;
  /* Extract dimensions from OCaml array */
  num_dims = Wosize_val(vdim);
  if (num_dims < 1 || num_dims > CAML_BA_MAX_NUM_DIMS)
    caml_invalid_argument("Bigarray.mmap: bad number of dimensions");
  for (i = 0; i < num_dims; i++) {
    dim[i] = Long_val(Field(vdim, i));
    if (dim[i] == -1 && i == major_dim) continue;
    if (dim[i] < 0)
      caml_invalid_argument("Bigarray.create: negative dimension");
  }
  /* Determine file size */
  currpos = caml_ba_set_file_pointer(fd, 0, FILE_CURRENT);
  if (currpos == -1) caml_ba_sys_error();
  file_size = caml_ba_set_file_pointer(fd, 0, FILE_END);
  if (file_size == -1) caml_ba_sys_error();
  /* Determine array size in bytes (or size of array without the major
     dimension if that dimension wasn't specified) */
  array_size = caml_ba_element_size[flags & CAML_BA_KIND_MASK];
  for (i = 0; i < num_dims; i++)
    if (dim[i] != -1) array_size *= dim[i];
  /* Check if the first/last dimension is unknown */
  if (dim[major_dim] == -1) {
    /* Determine first/last dimension from file size */
    if (file_size < startpos)
      caml_failwith("Bigarray.mmap: file position exceeds file size");
    data_size = file_size - startpos;
    dim[major_dim] = (uintnat) (data_size / array_size);
    array_size = dim[major_dim] * array_size;
    if (array_size != data_size)
      caml_failwith("Bigarray.mmap: file size doesn't match array dimensions");
  }
  /* Restore original file position */
  caml_ba_set_file_pointer(fd, currpos, FILE_BEGIN);
  /* Create the file mapping */
  if (Bool_val(vshared)) {
    perm = PAGE_READWRITE;
    mode = FILE_MAP_WRITE;
  } else {
    perm = PAGE_READONLY;       /* doesn't work under Win98 */
    mode = FILE_MAP_COPY;
  }
  li.QuadPart = startpos + array_size;
  fmap = CreateFileMapping(fd, NULL, perm, li.HighPart, li.LowPart, NULL);
  if (fmap == NULL) caml_ba_sys_error();
  /* Determine offset so that the mapping starts at the given file pos */
  GetSystemInfo(&sysinfo);
  delta = (uintnat) (startpos % sysinfo.dwAllocationGranularity);
  /* Map the mapping in memory */
  li.QuadPart = startpos - delta;
  addr =
    MapViewOfFile(fmap, mode, li.HighPart, li.LowPart, array_size + delta);
  if (addr == NULL) caml_ba_sys_error();
  addr = (void *) ((uintnat) addr + delta);
  /* Close the file mapping */
  CloseHandle(fmap);
  /* Build and return the OCaml bigarray */
  return caml_ba_alloc(flags | CAML_BA_MAPPED_FILE, num_dims, addr, dim);
}
开发者ID:MassD,项目名称:ocaml,代码行数:77,代码来源:mmap_win32.c

示例4: uint128_of_int

CAMLprim value
uint128_of_int(value v)
{
  CAMLparam1(v);
  CAMLreturn (copy_uint128((__uint128_t)Int_val(v)));
}
开发者ID:mwweissmann,项目名称:ocaml-uint,代码行数:6,代码来源:uint128_conv.c

示例5: translate_return_value

/* given a return value in OCaml land, translate it to 
   the return_val_t C structure
*/ 
return_val_t translate_return_value(value ocaml_result) {
  CAMLparam1(ocaml_result);
  CAMLlocal5(ocaml_shape, ocaml_strides, ocaml_data, ocaml_cur, ocaml_type);
  CAMLlocal1(v);
  
  return_val_t ret;
  
  if (Is_long(ocaml_result)) {
    // In this case, we know that the return code must have been Pass,
    // since the other two return codes have data.
    ret.return_code = RET_PASS;
    ret.results_len = 0;
  } else if (Tag_val(ocaml_result) == RET_FAIL) {
    ret.return_code = RET_FAIL;
    ret.results_len = caml_string_length(Field(ocaml_result, 0));
    ret.error_msg = malloc(ret.results_len + 1);
    strcpy(ret.error_msg, String_val(Field(ocaml_result, 0)));
  } else if (Tag_val(ocaml_result) == RET_SUCCESS) {
    
    ocaml_cur = Field(ocaml_result, 0);
    ret.return_code = RET_SUCCESS;
    ret.results_len = ocaml_list_length(ocaml_cur);
    ret.results = (ret_t*)malloc(sizeof(ret_t) * ret.results_len);
    
    int i, j;
    host_val h; 
    for (i = 0; i < ret.results_len; ++i) {
      v = Field(ocaml_cur, 0);
      h = create_host_val(v);  
      ocaml_cur = Field(ocaml_cur, 1);
      // returning a scalar
      if (value_is_scalar(h)) {

        ret.results[i].is_scalar = 1;
        ocaml_type = (scalar_type)value_type_of(h);
        ret.results[i].data.scalar.ret_type =
            get_scalar_element_type(ocaml_type);

        // WARNING:
        // Tiny Memory Leak Ahead
        // -----------------------
        // When scalar data is returned to the host language
        // on the heap, it should be manually deleted by the
        // host frontend

        if (type_is_bool(ocaml_type)) {
          ret.results[i].data.scalar.ret_scalar_value.boolean = get_bool(h);
        } else if (type_is_int32(ocaml_type)) {
          ret.results[i].data.scalar.ret_scalar_value.int32 = get_int32(h);
        } else if (type_is_int64(ocaml_type)) {
          ret.results[i].data.scalar.ret_scalar_value.int64 = get_int64(h);
        } else if (type_is_float32(ocaml_type)) { 
          ret.results[i].data.scalar.ret_scalar_value.float32 = get_float64(h);
        } else if (type_is_float64(ocaml_type)) {
          ret.results[i].data.scalar.ret_scalar_value.float64 = get_float64(h);
        } else {
          caml_failwith("Unable to return scalar of this type\n");
        }
      } else {
        // Pass the type
        ret.results[i].is_scalar = 0;
        ret.results[i].data.array.ret_type = array_type_of(h);

        // Pass the data
        ret.results[i].data.array.data = get_array_data(h);

        // Build the shape array
        ocaml_shape = value_get_shape(h);
        int shape_len = Wosize_val(ocaml_shape);

        ret.results[i].data.array.shape =
            (int*)malloc(shape_len * sizeof(int));
        ret.results[i].data.array.shape_len = shape_len;
        for (j = 0; j < shape_len; ++j) {
          ret.results[i].data.array.shape[j] = Int_val(Field(ocaml_shape, j));
        }

        // Build the strides array
        ocaml_strides = value_get_strides(h);
        int strides_len = Wosize_val(ocaml_strides);

        ret.results[i].data.array.strides_len = strides_len;
        ret.results[i].data.array.strides =
            (int*)malloc(strides_len * sizeof(int));
        for (j = 0; j < strides_len; ++j) {
          ret.results[i].data.array.strides[j] =
              Int_val(Field(ocaml_strides, j));
        }
      }
    }
  }
  CAMLreturnT(return_val_t, ret);
	
}
开发者ID:iskandr,项目名称:parakeet-retired,代码行数:97,代码来源:front_end_stubs.c

示例6: sys_dlmemcpy

CAMLprim value sys_dlmemcpy( value dst, value src, value len ) {
	memcpy((char*)dst,(char*)src,Int_val(len));
	return Val_unit;
}
开发者ID:MarcWeber,项目名称:ocamllibs,代码行数:4,代码来源:extc_stubs.c

示例7: caml_nc_xor_into

CAMLprim value
caml_nc_xor_into (value b1, value off1, value b2, value off2, value n) {
  xor_into (_ba_uint8_off (b1, off1), _ba_uint8_off (b2, off2), Int_val (n));
  return Val_unit;
}
开发者ID:rgrinberg,项目名称:ocaml-nocrypto,代码行数:5,代码来源:misc.c

示例8: t_major_is_valid

static int t_major_is_valid(value t)
{
  return (Int_val(Field(t, 3)) == caml_stat_compactions);
}
开发者ID:fxfactorial,项目名称:grenier,代码行数:4,代码来源:ml_physh_map.c

示例9: t_major_fill

static size_t t_major_fill(value t)
{
  return Int_val(Field(t, 4));
}
开发者ID:fxfactorial,项目名称:grenier,代码行数:4,代码来源:ml_physh_map.c

示例10: caml_page_safe_get

/* Read an OCaml character out of a raw page, mods offset with PAGE_SIZE  */
CAMLprim value
caml_page_safe_get(value v_page, value v_off)
{
    int off = Int_val(v_off) % PAGE_SIZE;
    return Int_val(*((char *)v_page + off));
}
开发者ID:matthiasgoergens,项目名称:mirage,代码行数:7,代码来源:page_stubs.c

示例11: t_minor_fill

static size_t t_minor_fill(value t)
{
  return Int_val(Field(t, 1));
}
开发者ID:fxfactorial,项目名称:grenier,代码行数:4,代码来源:ml_physh_map.c

示例12: setRightCreatureLevel

value setRightCreatureLevel(lvl)
{
	fi.rightLevel = Int_val(lvl);
	return Val_unit;
}
开发者ID:hassenc,项目名称:Game,代码行数:5,代码来源:fightInterface.c

示例13: setLeftCreatureLevel

value setLeftCreatureLevel(lvl)
{
	fi.leftLevel = Int_val(lvl);
	return Val_unit;
}
开发者ID:hassenc,项目名称:Game,代码行数:5,代码来源:fightInterface.c

示例14: setRightManaMax

value setRightManaMax(val)
{
	fi.rightManaMax = Int_val(val);
	return Val_unit;
}
开发者ID:hassenc,项目名称:Game,代码行数:5,代码来源:fightInterface.c

示例15: sys_dlint

CAMLprim value sys_dlint( value i ) {
	return Int_val(i);
}
开发者ID:MarcWeber,项目名称:ocamllibs,代码行数:3,代码来源:extc_stubs.c


注:本文中的Int_val函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。