1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! External definitions for allocating values in the OCaml runtime

use crate::{
    mlvalues::{Size, Value},
    tag::Tag,
    Char,
};

extern "C" {
    pub fn caml_alloc(size: Size, tag: Tag) -> Value;
    pub fn caml_alloc_small(size: Size, tag: Tag) -> Value;
    pub fn caml_alloc_tuple(size: Size) -> Value;
    pub fn caml_alloc_string(size: Size) -> Value; // size in bytes
    pub fn caml_alloc_initialized_string(size: Size, string: *const Char) -> Value;
    pub fn caml_copy_string(string: *const Char) -> Value;
    pub fn caml_copy_string_array(arr: *const *const Char) -> Value;
    pub fn caml_is_double_array(v: Value) -> i32;
    pub fn caml_copy_double(double: f64) -> Value;
    pub fn caml_copy_int32(int: i32) -> Value; // defined in [ints.c]
    pub fn caml_copy_int64(int: i64) -> Value; // defined in [ints.c]
    pub fn caml_copy_nativeint(int: isize) -> Value; // defined in [ints.c]
    pub fn caml_alloc_float_array(size: Size) -> Value;
    pub fn caml_alloc_array(
        value: unsafe extern "C" fn(*const Char) -> Value,
        array: *const *const Char,
    ) -> Value;

    pub fn caml_alloc_final(
        size: Size,
        final_fn: extern "C" fn(Value),
        consumed: Size,
        max: Size,
    ) -> Value;
}