libsyntax: Remove last use of structural records in pipes compiler.

This commit is contained in:
Luqman Aden 2013-02-17 00:55:36 -05:00
parent a6945f2a45
commit 0126af3144
3 changed files with 69 additions and 56 deletions

View File

@ -88,6 +88,12 @@ pub trait ext_ctxt_ast_builder {
+ty_params: ~[ast::ty_param]) -> @ast::item;
fn item_enum(name: ident, span: span,
+enum_definition: ast::enum_def) -> @ast::item;
fn item_struct_poly(name: ident, span: span,
struct_def: ast::struct_def,
ty_params: ~[ast::ty_param]) -> @ast::item;
fn item_struct(name: ident, span: span,
struct_def: ast::struct_def) -> @ast::item;
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
fn variant(name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty;
@ -99,9 +105,7 @@ pub trait ext_ctxt_ast_builder {
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field;
fn ty_rec(+v: ~[ast::ty_field]) -> @ast::Ty;
fn field_imm(name: ident, e: @ast::expr) -> ast::field;
fn rec(+v: ~[ast::field]) -> @ast::expr;
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
@ -147,15 +151,6 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}
fn rec(+fields: ~[ast::field]) -> @ast::expr {
@expr {
id: self.next_id(),
callee_id: self.next_id(),
node: ast::expr_rec(fields, None),
span: dummy_sp(),
}
}
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
spanned {
node: ast::ty_field_ {
@ -166,14 +161,6 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_rec(fields),
span: dummy_sp(),
}
}
fn ty_infer() -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
@ -286,6 +273,26 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
self.item_enum_poly(name, span, enum_definition, ~[])
}
fn item_struct(name: ident, span: span,
struct_def: ast::struct_def) -> @ast::item {
self.item_struct_poly(name, span, struct_def, ~[])
}
fn item_struct_poly(name: ident, span: span,
struct_def: ast::struct_def,
ty_params: ~[ast::ty_param]) -> @ast::item {
self.item(name, span, ast::item_struct(@struct_def, ty_params))
}
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
@ast::expr {
id: self.next_id(),
callee_id: self.next_id(),
node: ast::expr_struct(path, fields, None),
span: dummy_sp()
}
}
fn variant(name: ident,
span: span,
+tys: ~[@ast::Ty]) -> ast::variant {
@ -300,7 +307,8 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
kind: ast::tuple_variant_kind(args),
id: self.next_id(),
disr_expr: None,
vis: ast::public},
vis: ast::public
},
span: span,
}
}

View File

@ -345,7 +345,9 @@ pub impl gen_init for protocol {
}
fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
ext_cx.rec(self.states.map_to_vec(|s| {
ext_cx.struct_expr(path(~[ext_cx.ident_of(~"__Buffer")],
dummy_sp()),
self.states.map_to_vec(|s| {
let fty = s.to_ty(ext_cx);
ext_cx.field_imm(ext_cx.ident_of(s.name),
quote_expr!(
@ -409,13 +411,27 @@ pub impl gen_init for protocol {
let ty = s.to_ty(cx);
let fty = quote_ty!( ::pipes::Packet<$ty> );
cx.ty_field_imm(cx.ident_of(s.name), fty)
@spanned {
node: ast::struct_field_ {
kind: ast::named_field(
cx.ident_of(s.name),
ast::struct_immutable,
ast::inherited),
id: cx.next_id(),
ty: fty
},
span: dummy_sp()
}
};
cx.item_ty_poly(
cx.item_struct_poly(
cx.ident_of(~"__Buffer"),
dummy_sp(),
cx.ty_rec(fields),
ast::struct_def {
fields: fields,
dtor: None,
ctor_id: None
},
cx.strip_bounds(params))
}

View File

@ -19,20 +19,9 @@ use core::cmp;
use core::dvec::DVec;
use core::to_str::ToStr;
#[deriving_eq]
pub enum direction { send, recv }
pub impl cmp::Eq for direction {
pure fn eq(&self, other: &direction) -> bool {
match ((*self), (*other)) {
(send, send) => true,
(recv, recv) => true,
(send, _) => false,
(recv, _) => false,
}
}
pure fn ne(&self, other: &direction) -> bool { !(*self).eq(other) }
}
pub impl ToStr for direction {
pure fn to_str(&self) -> ~str {
match *self {
@ -82,8 +71,9 @@ pub impl message {
}
}
pub enum state {
state_(@{
pub type state = @state_;
pub struct state_ {
id: uint,
name: ~str,
ident: ast::ident,
@ -91,27 +81,26 @@ pub enum state {
dir: direction,
ty_params: ~[ast::ty_param],
messages: DVec<message>,
proto: protocol,
}),
proto: protocol
}
pub impl state {
fn add_message(name: ~str, span: span,
pub impl state_ {
fn add_message(@self, name: ~str, span: span,
+data: ~[@ast::Ty], next: Option<next_state>) {
self.messages.push(message(name, span, data, self,
next));
}
fn filename() -> ~str {
(*self).proto.filename()
fn filename(&self) -> ~str {
self.proto.filename()
}
fn data_name() -> ast::ident {
fn data_name(&self) -> ast::ident {
self.ident
}
/// Returns the type that is used for the messages.
fn to_ty(cx: ext_ctxt) -> @ast::Ty {
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty {
cx.ty_path_ast_builder
(path(~[cx.ident_of(self.name)],self.span).add_tys(
cx.ty_vars(self.ty_params)))
@ -119,7 +108,7 @@ pub impl state {
/// Iterate over the states that can be reached in one message
/// from this state.
fn reachable(f: fn(state) -> bool) {
fn reachable(&self, f: fn(state) -> bool) {
for self.messages.each |m| {
match *m {
message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
@ -199,7 +188,7 @@ pub impl protocol {
+ty_params: ~[ast::ty_param]) -> state {
let messages = DVec();
let state = state_(@{
let state = @state_ {
id: self.states.len(),
name: name,
ident: ident,
@ -208,7 +197,7 @@ pub impl protocol {
ty_params: ty_params,
messages: messages,
proto: self
});
};
self.states.push(state);
state