Skip to content

Commit 0126af3

Browse files
committed
libsyntax: Remove last use of structural records in pipes compiler.
1 parent a6945f2 commit 0126af3

File tree

3 files changed

+69
-56
lines changed

3 files changed

+69
-56
lines changed

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ pub trait ext_ctxt_ast_builder {
8888
+ty_params: ~[ast::ty_param]) -> @ast::item;
8989
fn item_enum(name: ident, span: span,
9090
+enum_definition: ast::enum_def) -> @ast::item;
91+
fn item_struct_poly(name: ident, span: span,
92+
struct_def: ast::struct_def,
93+
ty_params: ~[ast::ty_param]) -> @ast::item;
94+
fn item_struct(name: ident, span: span,
95+
struct_def: ast::struct_def) -> @ast::item;
96+
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
9197
fn variant(name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
9298
fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
9399
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty;
@@ -99,9 +105,7 @@ pub trait ext_ctxt_ast_builder {
99105
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
100106
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
101107
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field;
102-
fn ty_rec(+v: ~[ast::ty_field]) -> @ast::Ty;
103108
fn field_imm(name: ident, e: @ast::expr) -> ast::field;
104-
fn rec(+v: ~[ast::field]) -> @ast::expr;
105109
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
106110
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
107111
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
@@ -147,15 +151,6 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
147151
}
148152
}
149153

150-
fn rec(+fields: ~[ast::field]) -> @ast::expr {
151-
@expr {
152-
id: self.next_id(),
153-
callee_id: self.next_id(),
154-
node: ast::expr_rec(fields, None),
155-
span: dummy_sp(),
156-
}
157-
}
158-
159154
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
160155
spanned {
161156
node: ast::ty_field_ {
@@ -166,14 +161,6 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
166161
}
167162
}
168163

169-
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
170-
@ast::Ty {
171-
id: self.next_id(),
172-
node: ast::ty_rec(fields),
173-
span: dummy_sp(),
174-
}
175-
}
176-
177164
fn ty_infer() -> @ast::Ty {
178165
@ast::Ty {
179166
id: self.next_id(),
@@ -286,6 +273,26 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
286273
self.item_enum_poly(name, span, enum_definition, ~[])
287274
}
288275

276+
fn item_struct(name: ident, span: span,
277+
struct_def: ast::struct_def) -> @ast::item {
278+
self.item_struct_poly(name, span, struct_def, ~[])
279+
}
280+
281+
fn item_struct_poly(name: ident, span: span,
282+
struct_def: ast::struct_def,
283+
ty_params: ~[ast::ty_param]) -> @ast::item {
284+
self.item(name, span, ast::item_struct(@struct_def, ty_params))
285+
}
286+
287+
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
288+
@ast::expr {
289+
id: self.next_id(),
290+
callee_id: self.next_id(),
291+
node: ast::expr_struct(path, fields, None),
292+
span: dummy_sp()
293+
}
294+
}
295+
289296
fn variant(name: ident,
290297
span: span,
291298
+tys: ~[@ast::Ty]) -> ast::variant {
@@ -300,7 +307,8 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
300307
kind: ast::tuple_variant_kind(args),
301308
id: self.next_id(),
302309
disr_expr: None,
303-
vis: ast::public},
310+
vis: ast::public
311+
},
304312
span: span,
305313
}
306314
}

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ pub impl gen_init for protocol {
345345
}
346346
347347
fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
348-
ext_cx.rec(self.states.map_to_vec(|s| {
348+
ext_cx.struct_expr(path(~[ext_cx.ident_of(~"__Buffer")],
349+
dummy_sp()),
350+
self.states.map_to_vec(|s| {
349351
let fty = s.to_ty(ext_cx);
350352
ext_cx.field_imm(ext_cx.ident_of(s.name),
351353
quote_expr!(
@@ -409,13 +411,27 @@ pub impl gen_init for protocol {
409411
let ty = s.to_ty(cx);
410412
let fty = quote_ty!( ::pipes::Packet<$ty> );
411413
412-
cx.ty_field_imm(cx.ident_of(s.name), fty)
414+
@spanned {
415+
node: ast::struct_field_ {
416+
kind: ast::named_field(
417+
cx.ident_of(s.name),
418+
ast::struct_immutable,
419+
ast::inherited),
420+
id: cx.next_id(),
421+
ty: fty
422+
},
423+
span: dummy_sp()
424+
}
413425
};
414426
415-
cx.item_ty_poly(
427+
cx.item_struct_poly(
416428
cx.ident_of(~"__Buffer"),
417429
dummy_sp(),
418-
cx.ty_rec(fields),
430+
ast::struct_def {
431+
fields: fields,
432+
dtor: None,
433+
ctor_id: None
434+
},
419435
cx.strip_bounds(params))
420436
}
421437

src/libsyntax/ext/pipes/proto.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@ use core::cmp;
1919
use core::dvec::DVec;
2020
use core::to_str::ToStr;
2121

22+
#[deriving_eq]
2223
pub enum direction { send, recv }
2324

24-
pub impl cmp::Eq for direction {
25-
pure fn eq(&self, other: &direction) -> bool {
26-
match ((*self), (*other)) {
27-
(send, send) => true,
28-
(recv, recv) => true,
29-
(send, _) => false,
30-
(recv, _) => false,
31-
}
32-
}
33-
pure fn ne(&self, other: &direction) -> bool { !(*self).eq(other) }
34-
}
35-
3625
pub impl ToStr for direction {
3726
pure fn to_str(&self) -> ~str {
3827
match *self {
@@ -82,44 +71,44 @@ pub impl message {
8271
}
8372
}
8473

85-
pub enum state {
86-
state_(@{
87-
id: uint,
88-
name: ~str,
89-
ident: ast::ident,
90-
span: span,
91-
dir: direction,
92-
ty_params: ~[ast::ty_param],
93-
messages: DVec<message>,
94-
proto: protocol,
95-
}),
74+
pub type state = @state_;
75+
76+
pub struct state_ {
77+
id: uint,
78+
name: ~str,
79+
ident: ast::ident,
80+
span: span,
81+
dir: direction,
82+
ty_params: ~[ast::ty_param],
83+
messages: DVec<message>,
84+
proto: protocol
9685
}
9786

98-
pub impl state {
99-
fn add_message(name: ~str, span: span,
87+
pub impl state_ {
88+
fn add_message(@self, name: ~str, span: span,
10089
+data: ~[@ast::Ty], next: Option<next_state>) {
10190
self.messages.push(message(name, span, data, self,
10291
next));
10392
}
10493

105-
fn filename() -> ~str {
106-
(*self).proto.filename()
94+
fn filename(&self) -> ~str {
95+
self.proto.filename()
10796
}
10897

109-
fn data_name() -> ast::ident {
98+
fn data_name(&self) -> ast::ident {
11099
self.ident
111100
}
112101

113102
/// Returns the type that is used for the messages.
114-
fn to_ty(cx: ext_ctxt) -> @ast::Ty {
103+
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty {
115104
cx.ty_path_ast_builder
116105
(path(~[cx.ident_of(self.name)],self.span).add_tys(
117106
cx.ty_vars(self.ty_params)))
118107
}
119108

120109
/// Iterate over the states that can be reached in one message
121110
/// from this state.
122-
fn reachable(f: fn(state) -> bool) {
111+
fn reachable(&self, f: fn(state) -> bool) {
123112
for self.messages.each |m| {
124113
match *m {
125114
message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
@@ -199,7 +188,7 @@ pub impl protocol {
199188
+ty_params: ~[ast::ty_param]) -> state {
200189
let messages = DVec();
201190

202-
let state = state_(@{
191+
let state = @state_ {
203192
id: self.states.len(),
204193
name: name,
205194
ident: ident,
@@ -208,7 +197,7 @@ pub impl protocol {
208197
ty_params: ty_params,
209198
messages: messages,
210199
proto: self
211-
});
200+
};
212201

213202
self.states.push(state);
214203
state

0 commit comments

Comments
 (0)