Generate a header file for the interpreter API

This commit is contained in:
Olivier Goffart 2021-03-17 11:26:44 +01:00
parent c68405d4dd
commit e7cbc716ed
2 changed files with 43 additions and 1 deletions

View file

@ -31,6 +31,7 @@ pub use sixtyfps_compilerlib::diagnostics::{Diagnostic, DiagnosticLevel};
/// ```
#[derive(Clone)]
#[non_exhaustive]
#[repr(C)]
pub enum Value {
/// There is nothing in this value. That's the default.
/// For example, a function that do not return a result would return a Value::Void
@ -736,3 +737,27 @@ pub mod testing {
);
}
}
#[cfg(feature = "ffi")]
pub mod ffi {
use super::*;
/// This is casted to a Value
#[repr(C)]
pub struct ValueOpaque([usize; 7]);
/// Asserts that ValueOpaque is at least as large as Value, otherwise this would overflow
const _: usize = std::mem::size_of::<ValueOpaque>() - std::mem::size_of::<Value>();
/// Construct a new Value in the given memory location
#[no_mangle]
pub unsafe extern "C" fn sixtyfps_interpreter_value_new(val: *mut ValueOpaque) {
std::ptr::write(val as *mut Value, Value::default())
}
/// Destruct the value in that memory location
#[no_mangle]
pub unsafe extern "C" fn sixtyfps_interpreter_value_destructor(val: *mut ValueOpaque) {
drop(std::ptr::read(val as *mut Value))
}
}