mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
proof of concept
This commit is contained in:
parent
6741d93517
commit
d8e38ef2ac
3 changed files with 62 additions and 5 deletions
|
@ -2,7 +2,9 @@
|
|||
|
||||
use core::ffi::c_void;
|
||||
use core::mem::MaybeUninit;
|
||||
use libc::c_char;
|
||||
use roc_std::{RocCallResult, RocStr};
|
||||
use std::ffi::CStr;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "roc__mainForHost_1_exposed"]
|
||||
|
@ -29,6 +31,19 @@ pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
|||
return libc::free(c_ptr);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
|
||||
match tag_id {
|
||||
0 => {
|
||||
let slice = CStr::from_ptr(c_ptr as *const c_char);
|
||||
let string = slice.to_str().unwrap();
|
||||
eprintln!("Roc hit a panic: {}", string);
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> isize {
|
||||
let mut call_result: MaybeUninit<RocCallResult<RocStr>> = MaybeUninit::uninit();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue