messing around with pipes and stages

This commit is contained in:
Tim Chevalier 2013-01-29 15:06:05 -08:00
parent e0281d991c
commit 845b06542e
2 changed files with 44 additions and 9 deletions

View File

@ -143,14 +143,9 @@ pub fn BufferHeader() -> BufferHeader {
// This is for protocols to associate extra data to thread around.
#[doc(hidden)]
#[cfg(stage0)]
type Buffer<T: Owned> = {
header: BufferHeader,
data: T,
};
#[doc(hidden)]
#[cfg(stage1)]
type Buffer<T> = { header: BufferHeader, data: T };
#[cfg(stage2)]
#[cfg(stage3)]
pub struct Buffer<T> {
header: BufferHeader,
data: T,
@ -247,7 +242,6 @@ pub fn mk_packet<T: Owned>() -> Packet<T> {
payload: None,
}
}
#[doc(hidden)]
#[cfg(stage0)]
fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
@ -264,10 +258,23 @@ fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
}
move b
}
#[doc(hidden)]
#[cfg(stage1)]
fn unibuffer<T>() -> ~Buffer<Packet<T>> {
let b = ~{
header: BufferHeader(),
data: Packet {
header: PacketHeader(),
payload: None,
}
};
unsafe {
b.data.header.buffer = reinterpret_cast(&b);
}
move b
}
#[doc(hidden)]
#[cfg(stage2)]
#[cfg(stage3)]
fn unibuffer<T>() -> ~Buffer<Packet<T>> {
let b = ~Buffer {
header: BufferHeader(),

View File

@ -355,6 +355,34 @@ fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
}))
}
#[cfg(stage0)]
fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr {
debug!("gen_init_bounded");
let buffer_fields = self.gen_buffer_init(ext_cx);
let buffer = quote_expr!(~{
header: ::pipes::BufferHeader(),
data: $buffer_fields,
});
let entangle_body = ext_cx.block_expr(
ext_cx.block(
self.states.map_to_vec(
|s| ext_cx.parse_stmt(
fmt!("data.%s.set_buffer_(buffer)",
s.name))),
ext_cx.parse_expr(
fmt!("::ptr::addr_of(&(data.%s))",
self.states[0].name))));
quote_expr!({
let buffer = $buffer;
do ::pipes::entangle_buffer(move buffer) |buffer, data| {
$entangle_body
}
})
}
#[cfg(stage1)]
#[cfg(stage2)]
fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr {
debug!("gen_init_bounded");
let buffer_fields = self.gen_buffer_init(ext_cx);