Try to specify roc_alloc etc in example Rust hosts

...but they're all broken for other reasons, so who knows
if it actually worked?
This commit is contained in:
Richard Feldman 2021-05-22 23:24:40 -04:00
parent 175115ee4e
commit bfd8187d97
5 changed files with 125 additions and 1 deletions

View file

@ -4,6 +4,7 @@ use roc_std::alloca;
use roc_std::RocCallResult;
use roc_std::RocStr;
use std::alloc::Layout;
use std::ffi::c_void;
use std::time::SystemTime;
extern "C" {
@ -18,6 +19,30 @@ extern "C" {
#[link_name = "roc__rocMain_1_Fx_size"]
fn size_Fx() -> i64;
fn malloc(size: usize) -> *mut c_void;
fn realloc(c_ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(c_ptr: *mut c_void);
}
#[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void {
return malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
_alignment: usize,
c_ptr: *mut c_void,
_old_size: usize,
new_size: usize,
) -> *mut c_void {
return realloc(c_ptr, new_size);
}
#[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) {
return free(c_ptr);
}
#[no_mangle]

View file

@ -1,5 +1,6 @@
#![allow(non_snake_case)]
use core::ffi::c_void;
use roc_std::{alloca, RocCallResult, RocResult, RocStr};
use std::alloc::Layout;
@ -24,6 +25,30 @@ extern "C" {
#[link_name = "roc__mainForHost_1_Fx_result_size"]
fn size_Fx_result() -> i64;
fn malloc(size: usize) -> *mut c_void;
fn realloc(c_ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(c_ptr: *mut c_void);
}
#[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void {
return malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
_alignment: usize,
c_ptr: *mut c_void,
_old_size: usize,
new_size: usize,
) -> *mut c_void {
return realloc(c_ptr, new_size);
}
#[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) {
return free(c_ptr);
}
#[no_mangle]

View file

@ -4,6 +4,7 @@ use roc_std::alloca;
use roc_std::RocCallResult;
use roc_std::RocStr;
use std::alloc::Layout;
use std::ffi::c_void;
use std::time::SystemTime;
extern "C" {
@ -26,6 +27,30 @@ extern "C" {
#[link_name = "roc__mainForHost_1_Fx_result_size"]
fn size_Fx_result() -> i64;
fn malloc(size: usize) -> *mut c_void;
fn realloc(c_ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(c_ptr: *mut c_void);
}
#[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void {
return malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
_alignment: usize,
c_ptr: *mut c_void,
_old_size: usize,
new_size: usize,
) -> *mut c_void {
return realloc(c_ptr, new_size);
}
#[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) {
return free(c_ptr);
}
#[no_mangle]

View file

@ -2,11 +2,36 @@
use roc_std::RocCallResult;
use roc_std::RocList;
use std::ffi::c_void;
use std::time::SystemTime;
extern "C" {
#[link_name = "roc__mainForHost_1_exposed"]
fn quicksort(list: RocList<i64>, output: &mut RocCallResult<RocList<i64>>) -> ();
fn malloc(size: usize) -> *mut c_void;
fn realloc(c_ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(c_ptr: *mut c_void);
}
#[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void {
return malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
_alignment: usize,
c_ptr: *mut c_void,
_old_size: usize,
new_size: usize,
) -> *mut c_void {
return realloc(c_ptr, new_size);
}
#[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) {
return free(c_ptr);
}
const NUM_NUMS: usize = 100;

View file

@ -1,9 +1,9 @@
#![allow(non_snake_case)]
use roc_std::alloca;
use roc_std::RocCallResult;
use roc_std::RocStr;
use std::alloc::Layout;
use std::ffi::c_void;
use std::time::SystemTime;
type Model = *const u8;
@ -60,6 +60,30 @@ extern "C" {
#[link_name = "roc__mainForHost_1_Model_size"]
fn size_Model() -> i64;
fn malloc(size: usize) -> *mut c_void;
fn realloc(c_ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(c_ptr: *mut c_void);
}
#[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void {
return malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
_alignment: usize,
c_ptr: *mut c_void,
_old_size: usize,
new_size: usize,
) -> *mut c_void {
return realloc(c_ptr, new_size);
}
#[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) {
return free(c_ptr);
}
unsafe fn call_Fx(function_pointer: *const u8, closure_data: *const u8, output: *mut u8) -> () {