cultivar/runtime/src/lib.rs

37 lines
939 B
Rust

#![feature(vec_into_raw_parts)]
#![no_std]
use core::alloc::GlobalAlloc;
use fungi_common::{prelude::*, std_bis::*};
use fungi_runtime_interface::prelude::*;
use parity_scale_codec::Decode;
//use fungi_runtime_interface::*;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
//static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
struct MyAi {}
/*impl Ai for MyAi {
fn run(_board: &mut Board) {}
}*/
/// # 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 {
let mut data = unsafe { Vec::from_raw_parts(ptr, len, len) };
let sim_id = SimId::decode(&mut &data[..]).unwrap();
run_inner(sim_id);
let (ptr, len, _) = data.into_raw_parts();
(len as u64) << 32 | ptr as u64
}
fn run_inner(sim_id: SimId) {
fungi_common::api::walk(sim_id, EntityId(0), Direction::East);
}