gpu

module std::ffisource

Values C holds for Alloy (LANGUAGE_SPEC.md section 6.3): a C library that calls back through an extern (...) -> R function often passes along a void * its caller gave it. c_pointer is that pointer: made from a reference, read back as one by the callback, which names the type it was made from.

type c_pointersource

exp type c_pointer = if (wasm32()) u32 else u64;

Functions

type c_sizesource

exp type c_size : Number = if (wasm32()) u32 else u64;

C's integer types whose width follows the target (section 6.3), for externs to write as the C header does: size_t and uintptr_t are 32 bits on wasm32 and 64 elsewhere, ssize_t and ptrdiff_t likewise signed, and long is 32 bits on Windows and wasm32, 64 on Linux and macOS (unsigned long alike).

type c_ssizesource

exp type c_ssize : Number = if (wasm32()) i32 else i64;

type c_longsource

exp type c_long : Number = if (wasm32() || target() == "windows-x86_64") i32 else i64;

type c_ulongsource

exp type c_ulong : Number = if (wasm32() || target() == "windows-x86_64") u32 else u64;

fn c_pointer::fromsource

exp fn c_pointer::from<T>(target: &T) -> c_pointer

The address of the value, for C to pass back.

fn as_refsource

exp fn as_ref<T>(self p: &c_pointer) -> &T

The value the pointer was made from, which must be a T still alive.

fn as_varsource

exp fn as_var<T>(self p: &c_pointer) -> &var T

The value the pointer was made from, to change; it must be a T still alive, made from a &var reference.

fn c_pointer::keepsource

exp fn c_pointer::keep<T>(value: *var T) -> c_pointer

Hands the heap value to C, which holds it until take gives it back: its address, for callbacks to reach it through as_var and as_ref. Nothing frees it meanwhile, so state a browser calls back after main returns stays alive (std::web).

fn takesource

exp fn take<T>(self p: &c_pointer) -> *var T

The heap value c_pointer::keep handed to C, owned again.

fn viewsource

exp fn view<T>(self p: &c_pointer, length: u64) -> &[T]

The length values of type T from the address, memory C gave and keeps alive while they are used: an array a callback receives, a mapped file.

fn view_varsource

exp fn view_var<T>(self p: &c_pointer, length: u64) -> &var [T]

The length values of type T from the address, to change: a buffer C gave to fill.

fn c_textsource

exp fn c_text(self p: &c_pointer) -> &[u8]

The C string at the address, up to its NUL.

fn c_pointer::ofsource

exp fn c_pointer::of<T>(elements: &[T]) -> c_pointer

The address of the elements' first, for C to read or fill them; 0 when there are none.

interface CFunctionsource

exp interface CFunction

What every C function type, extern (T) -> R, and every type named over one satisfy with no marker, and nothing else (a lang item): the types a library's symbols are read as.

type Librarysource

exp type Library = struct

A shared library loaded while the program runs (section 6.3): a .so on Linux and Android, a .dylib or framework on Apple systems, a DLL on Windows. It stays loaded until the program ends. On Linux a program that loads one links against glibc dynamically, since a static program cannot load libraries; WebAssembly has none to load.

Functions

fn Library::opensource

exp fn Library::open(path: &[u8]) -> Option<Library>

The library at the path, or found by the system's search for a bare name (libvulkan.so.1, vulkan-1.dll); None when it cannot be loaded.

fn symbolsource

exp fn symbol<F: CFunction>(self library: &Library, name: &[u8]) -> Option<F>

The library's function of that name, called through the C function type F, which must be its C prototype; None when the library has no such symbol. One symbol may be read as several types, as Objective-C's objc_msgSend is, a prototype per message.