1
0
Fork 0
libfringe/src/main.rs

37 lines
781 B
Rust
Raw Normal View History

2014-12-23 11:24:40 +08:00
extern crate lwkt;
extern crate fn_box;
use std::ptr::null_mut;
use std::intrinsics::abort;
use lwkt::Context;
use fn_box::FnBox;
fn main() {
2015-01-13 15:38:52 +08:00
let f = Box::new(move |:| {
2014-12-23 11:24:40 +08:00
println!("Hello, world!")
2015-01-13 15:38:52 +08:00
});
2014-12-23 11:24:40 +08:00
let mut native = unsafe { Context::native() };
2015-01-10 05:45:39 +08:00
fn init(ctx: *mut (*mut Context, *mut Context), f: Box<FnBox<(), ()>>) -> ! {
2014-12-23 11:24:40 +08:00
unsafe {
let (native, green) = *ctx;
f();
Context::swap(&mut *green, &mut *native);
abort();
}
}
2015-01-13 15:38:52 +08:00
let mut ctx = Box::new((&mut native as *mut Context, null_mut()));
2014-12-23 11:24:40 +08:00
let mut green = Context::new(init, &mut *ctx as *mut _, f);
ctx.1 = &mut green as *mut Context;
unsafe {
Context::swap(&mut native, &mut green);
}
println!("size_of::<Context>() == {}", std::mem::size_of::<Context>());
}