diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 5af9950ff08..052daeaeb2a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -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 = { - header: BufferHeader, - data: T, -}; -#[doc(hidden)] #[cfg(stage1)] +type Buffer = { header: BufferHeader, data: T }; #[cfg(stage2)] -#[cfg(stage3)] pub struct Buffer { header: BufferHeader, data: T, @@ -247,7 +242,6 @@ pub fn mk_packet() -> Packet { payload: None, } } - #[doc(hidden)] #[cfg(stage0)] fn unibuffer() -> ~Buffer> { @@ -264,10 +258,23 @@ fn unibuffer() -> ~Buffer> { } move b } -#[doc(hidden)] #[cfg(stage1)] +fn unibuffer() -> ~Buffer> { + 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() -> ~Buffer> { let b = ~Buffer { header: BufferHeader(), diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 928885cf817..aaa909b3694 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -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);