mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
cleaup platform-switching Rust platform
This commit is contained in:
parent
157c0d2aad
commit
bc60d623f2
2 changed files with 65 additions and 6 deletions
|
@ -2,20 +2,24 @@
|
|||
|
||||
use core::ffi::c_void;
|
||||
use roc_std::RocStr;
|
||||
use std::ffi::CStr;
|
||||
use std::io::Write;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "roc__mainForHost_1_exposed_generic"]
|
||||
fn roc_main(_: &mut RocStr);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||
return libc::malloc(size);
|
||||
libc::malloc(size)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_realloc(
|
||||
c_ptr: *mut c_void,
|
||||
|
@ -23,14 +27,20 @@ pub unsafe extern "C" fn roc_realloc(
|
|||
_old_size: usize,
|
||||
_alignment: u32,
|
||||
) -> *mut c_void {
|
||||
return libc::realloc(c_ptr, new_size);
|
||||
libc::realloc(c_ptr, new_size)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||
return libc::free(c_ptr);
|
||||
libc::free(c_ptr);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_panic(msg: *mut RocStr, tag_id: u32) {
|
||||
match tag_id {
|
||||
|
@ -45,22 +55,34 @@ pub unsafe extern "C" fn roc_panic(msg: *mut RocStr, tag_id: u32) {
|
|||
std::process::exit(1);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_dbg(loc: *mut RocStr, msg: *mut RocStr, src: *mut RocStr) {
|
||||
eprintln!("[{}] {} = {}", &*loc, &*src, &*msg);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut c_void {
|
||||
libc::memset(dst, c, n)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[cfg(unix)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_getppid() -> libc::pid_t {
|
||||
libc::getppid()
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[cfg(unix)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_mmap(
|
||||
|
@ -74,6 +96,9 @@ pub unsafe extern "C" fn roc_mmap(
|
|||
libc::mmap(addr, len, prot, flags, fd, offset)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[cfg(unix)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn roc_shm_open(
|
||||
|
@ -84,6 +109,9 @@ pub unsafe extern "C" fn roc_shm_open(
|
|||
libc::shm_open(name, oflag, mode as libc::c_uint)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// TODO
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main() -> i32 {
|
||||
let mut roc_str = RocStr::default();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue