]> git.lizzy.rs Git - rust.git/commitdiff
libsyntax: Remove last use of structural records in pipes compiler.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Sun, 17 Feb 2013 05:55:36 +0000 (00:55 -0500)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Sun, 17 Feb 2013 10:25:26 +0000 (05:25 -0500)
src/libsyntax/ext/pipes/ast_builder.rs
src/libsyntax/ext/pipes/pipec.rs
src/libsyntax/ext/pipes/proto.rs

index 12e5f1891aa82f6e07e213abcf579bf0b1f022bc..a8bcb9dbfc4cd2e1f6c56845308b7a5a719ef54d 100644 (file)
@@ -88,6 +88,12 @@ fn item_enum_poly(name: ident,
                       +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 @@ fn item_ty_poly(name: ident,
     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 @@ fn field_imm(name: ident, e: @ast::expr) -> ast::field {
         }
     }
 
-    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 @@ fn ty_field_imm(name: ident, ty: @ast::Ty) -> 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(),
@@ -286,6 +273,26 @@ fn item_enum(name: ident, span: span,
         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 @@ fn variant(name: ident,
                 kind: ast::tuple_variant_kind(args),
                 id: self.next_id(),
                 disr_expr: None,
-                vis: ast::public},
+                vis: ast::public
+            },
             span: span,
         }
     }
index 68d18a2937c432e39c1d3c118c3ec765f3b2b6d9..3eeb7832fdfddcacba6a379179f0ef2eb99f4e9e 100644 (file)
@@ -345,7 +345,9 @@ fn gen_init(cx: ext_ctxt) -> @ast::item {
     }
 
     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 @@ fn gen_buffer_type(cx: ext_ctxt) -> @ast::item {
             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))
     }
 
index 027375b6326bf6bffd103d3c607874575db90545..a0e0b7f06cfbea0f6edb9e4d86b4bbfdd90cc81f 100644 (file)
 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,36 +71,36 @@ fn get_params() -> ~[ast::ty_param] {
     }
 }
 
-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)))
@@ -119,7 +108,7 @@ fn to_ty(cx: ext_ctxt) -> @ast::Ty {
 
     /// 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 @@ fn add_state_poly(name: ~str, ident: ast::ident, dir: direction,
                       +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 @@ fn add_state_poly(name: ~str, ident: ast::ident, dir: direction,
             ty_params: ty_params,
             messages: messages,
             proto: self
-        });
+        };
 
         self.states.push(state);
         state