cultivar/runtime/src/lib.rs

32 lines
834 B
Rust
Raw Permalink Normal View History

2023-04-01 05:52:41 +00:00
#![feature(vec_into_raw_parts)]
#![no_std]
2023-04-01 14:02:42 +00:00
use cultivar_common::{prelude::*, std_bis::*};
//use cultivar_runtime_interface::prelude::*;
2023-04-01 05:52:41 +00:00
use parity_scale_codec::Decode;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
//static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
/// # Safety
/// The pointer given in argument must be valid, or undefined data will be read.
#[export_name = "run"]
pub unsafe fn run(ptr: *mut u8, len: usize) -> u64 {
2023-04-01 14:02:42 +00:00
let data = unsafe { Vec::from_raw_parts(ptr, len, len) };
2023-04-01 05:52:41 +00:00
2023-07-17 22:58:44 +00:00
let sim_token = SimToken::decode(&mut &data[..]).unwrap();
2023-04-01 14:02:42 +00:00
2023-07-17 22:58:44 +00:00
run_inner(sim_token);
2023-04-01 05:52:41 +00:00
let (ptr, len, _) = data.into_raw_parts();
(len as u64) << 32 | ptr as u64
}
2023-07-17 22:58:44 +00:00
fn run_inner(sim_token: SimToken) {
say(&format!(
"{:?}",
walk(sim_token, EntityId(0), Direction::East)
));
2023-04-01 05:52:41 +00:00
}