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() {
|
|
|
|
let f = box move |:| {
|
|
|
|
println!("Hello, world!")
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut ctx = box { (&mut native as *mut Context, null_mut()) };
|
|
|
|
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>());
|
|
|
|
}
|