Generate buffer type for bounded protocols

This commit is contained in:
Eric Holk 2012-07-23 14:46:39 -07:00
parent c28af26258
commit b97fe98354
2 changed files with 31 additions and 0 deletions

View File

@ -91,9 +91,22 @@ fn item_ty_poly(name: ident,
+params: ~[ast::ty_param]) -> @ast::item; +params: ~[ast::ty_param]) -> @ast::item;
fn item_ty(name: ident, ty: @ast::ty) -> @ast::item; fn item_ty(name: ident, ty: @ast::ty) -> @ast::item;
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty]; fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty];
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field;
fn ty_rec(+~[ast::ty_field]) -> @ast::ty;
} }
impl ast_builder of ext_ctxt_ast_builder for ext_ctxt { impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field {
{node: {ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
span: empty_span()}
}
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::ty {
@{id: self.next_id(),
node: ast::ty_rec(fields),
span: empty_span()}
}
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound]) fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
-> ast::ty_param -> ast::ty_param
{ {

View File

@ -204,6 +204,7 @@ fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
impl compile of gen_init for protocol { impl compile of gen_init for protocol {
fn gen_init(cx: ext_ctxt) -> @ast::item { fn gen_init(cx: ext_ctxt) -> @ast::item {
#debug("gen_init");
let start_state = self.states[0]; let start_state = self.states[0];
let body = alt start_state.dir { let body = alt start_state.dir {
@ -237,6 +238,23 @@ fn compile(cx: ext_ctxt) -> @ast::item {
server_states += s.to_endpoint_decls(cx, recv); server_states += s.to_endpoint_decls(cx, recv);
} }
if self.is_bounded() {
vec::push(
items,
cx.item_ty(
@~"buffer",
cx.ty_rec(
(copy self.states).map_to_vec(
|s| cx.ty_field_imm(
s.name,
cx.ty_path_ast_builder(
(path(@~"pipes")
+ @~"packet")
.add_ty(
cx.ty_path_ast_builder(
path(s.name)))))))))
}
vec::push(items, vec::push(items,
cx.item_mod(@~"client", cx.item_mod(@~"client",
client_states)); client_states));