+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;
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;
}
}
- 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_ {
}
}
- 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(),
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 {
kind: ast::tuple_variant_kind(args),
id: self.next_id(),
disr_expr: None,
- vis: ast::public},
+ vis: ast::public
+ },
span: span,
}
}
}
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!(
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))
}
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 {
}
}
-pub enum state {
- state_(@{
- id: uint,
- name: ~str,
- ident: ast::ident,
- span: span,
- dir: direction,
- ty_params: ~[ast::ty_param],
- messages: DVec<message>,
- proto: protocol,
- }),
+pub type state = @state_;
+
+pub struct state_ {
+ id: uint,
+ name: ~str,
+ ident: ast::ident,
+ span: span,
+ dir: direction,
+ ty_params: ~[ast::ty_param],
+ messages: DVec<message>,
+ 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)))
/// 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, _ })) => {
+ty_params: ~[ast::ty_param]) -> state {
let messages = DVec();
- let state = state_(@{
+ let state = @state_ {
id: self.states.len(),
name: name,
ident: ident,
ty_params: ty_params,
messages: messages,
proto: self
- });
+ };
self.states.push(state);
state