libsyntax: De-mut the pipe compiler

This commit is contained in:
Patrick Walton 2013-02-21 16:13:07 -08:00
parent 1a132b3721
commit 17dcaee9d1
5 changed files with 39 additions and 37 deletions

View File

@ -158,7 +158,7 @@ pub fn mk_handler(emitter: Option<Emitter>) -> @handler {
} }
}; };
@mut HandlerT { mut err_count: 0, emit: emit } as @handler @mut HandlerT { err_count: 0, emit: emit } as @handler
} }
#[deriving_eq] #[deriving_eq]

View File

@ -73,7 +73,7 @@ pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
let rdr = tt_rdr as reader; let rdr = tt_rdr as reader;
let rust_parser = Parser(sess, cfg, rdr.dup()); let rust_parser = Parser(sess, cfg, rdr.dup());
let proto = rust_parser.parse_proto(cx.str_of(id)); let mut proto = rust_parser.parse_proto(cx.str_of(id));
// check for errors // check for errors
visit(proto, cx); visit(proto, cx);

View File

@ -27,8 +27,8 @@ use core::to_str::ToStr;
use core::vec; use core::vec;
pub trait gen_send { pub trait gen_send {
fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item; fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item;
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty; fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty;
} }
pub trait to_type_decls { pub trait to_type_decls {
@ -47,7 +47,7 @@ pub trait gen_init {
} }
pub impl gen_send for message { pub impl gen_send for message {
fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item { fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item {
debug!("pipec: gen_send"); debug!("pipec: gen_send");
match *self { match *self {
message(ref _id, span, ref tys, this, Some(ref next_state)) => { message(ref _id, span, ref tys, this, Some(ref next_state)) => {
@ -193,7 +193,7 @@ pub impl gen_send for message {
} }
} }
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty { fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty {
cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span()) cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span())
.add_tys(cx.ty_vars_global(self.get_params()))) .add_tys(cx.ty_vars_global(self.get_params())))
} }
@ -259,10 +259,14 @@ pub impl to_type_decls for state {
recv => (*self).dir.reverse() recv => (*self).dir.reverse()
}; };
let mut items = ~[]; let mut items = ~[];
for self.messages.each |m| {
if dir == send { {
items.push(m.gen_send(cx, true)); let messages = &mut *self.messages;
items.push(m.gen_send(cx, false)); for vec::each_mut(*messages) |m| {
if dir == send {
items.push(m.gen_send(cx, true));
items.push(m.gen_send(cx, false));
}
} }
} }
@ -395,7 +399,8 @@ pub impl gen_init for protocol {
} }
cx.ty_path_ast_builder(path(~[cx.ident_of(~"super"), cx.ty_path_ast_builder(path(~[cx.ident_of(~"super"),
cx.ident_of(~"__Buffer")], self.span) cx.ident_of(~"__Buffer")],
copy self.span)
.add_tys(cx.ty_vars_global(params))) .add_tys(cx.ty_vars_global(params)))
} }
@ -453,12 +458,12 @@ pub impl gen_init for protocol {
} }
items.push(cx.item_mod(cx.ident_of(~"client"), items.push(cx.item_mod(cx.ident_of(~"client"),
self.span, copy self.span,
client_states)); client_states));
items.push(cx.item_mod(cx.ident_of(~"server"), items.push(cx.item_mod(cx.ident_of(~"server"),
self.span, copy self.span,
server_states)); server_states));
cx.item_mod(cx.ident_of(self.name), self.span, items) cx.item_mod(cx.ident_of(self.name), copy self.span, items)
} }
} }

View File

@ -16,7 +16,6 @@ use ext::base::ext_ctxt;
use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path}; use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path};
use core::cmp; use core::cmp;
use core::dvec::DVec;
use core::to_str::ToStr; use core::to_str::ToStr;
#[deriving_eq] #[deriving_eq]
@ -45,26 +44,24 @@ pub struct next_state {
tys: ~[@ast::Ty], tys: ~[@ast::Ty],
} }
pub enum message { // name, span, data, current state, next state
// name, span, data, current state, next state pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>);
message(~str, span, ~[@ast::Ty], state, Option<next_state>)
}
pub impl message { pub impl message {
fn name(&self) -> ~str { fn name(&mut self) -> ~str {
match *self { match *self {
message(ref id, _, _, _, _) => (*id) message(ref id, _, _, _, _) => (*id)
} }
} }
fn span(&self) -> span { fn span(&mut self) -> span {
match *self { match *self {
message(_, span, _, _, _) => span message(_, span, _, _, _) => span
} }
} }
/// Return the type parameters actually used by this message /// Return the type parameters actually used by this message
fn get_params(&self) -> ~[ast::ty_param] { fn get_params(&mut self) -> ~[ast::ty_param] {
match *self { match *self {
message(_, _, _, this, _) => this.ty_params message(_, _, _, this, _) => this.ty_params
} }
@ -80,7 +77,7 @@ pub struct state_ {
span: span, span: span,
dir: direction, dir: direction,
ty_params: ~[ast::ty_param], ty_params: ~[ast::ty_param],
messages: DVec<message>, messages: @mut ~[message],
proto: protocol proto: protocol
} }
@ -121,17 +118,17 @@ pub impl state_ {
} }
} }
pub type protocol = @protocol_; pub type protocol = @mut protocol_;
pub fn protocol(name: ~str, +span: span) -> protocol { pub fn protocol(name: ~str, +span: span) -> protocol {
@protocol_(name, span) @mut protocol_(name, span)
} }
pub fn protocol_(name: ~str, span: span) -> protocol_ { pub fn protocol_(name: ~str, span: span) -> protocol_ {
protocol_ { protocol_ {
name: name, name: name,
span: span, span: span,
states: DVec(), states: @mut ~[],
bounded: None bounded: None
} }
} }
@ -139,30 +136,30 @@ pub fn protocol_(name: ~str, span: span) -> protocol_ {
pub struct protocol_ { pub struct protocol_ {
name: ~str, name: ~str,
span: span, span: span,
states: DVec<state>, states: @mut ~[state],
mut bounded: Option<bool>, bounded: Option<bool>,
} }
pub impl protocol_ { pub impl protocol_ {
/// Get a state. /// Get a state.
fn get_state(&self, name: ~str) -> state { fn get_state(&mut self, name: ~str) -> state {
self.states.find(|i| i.name == name).get() self.states.find(|i| i.name == name).get()
} }
fn get_state_by_id(&self, id: uint) -> state { self.states[id] } fn get_state_by_id(&mut self, id: uint) -> state { self.states[id] }
fn has_state(&self, name: ~str) -> bool { fn has_state(&mut self, name: ~str) -> bool {
self.states.find(|i| i.name == name).is_some() self.states.find(|i| i.name == name).is_some()
} }
fn filename(&self) -> ~str { fn filename(&mut self) -> ~str {
~"proto://" + self.name ~"proto://" + self.name
} }
fn num_states(&self) -> uint { self.states.len() } fn num_states(&mut self) -> uint { self.states.len() }
fn has_ty_params(&self) -> bool { fn has_ty_params(&mut self) -> bool {
for self.states.each |s| { for self.states.each |s| {
if s.ty_params.len() > 0 { if s.ty_params.len() > 0 {
return true; return true;
@ -170,7 +167,7 @@ pub impl protocol_ {
} }
false false
} }
fn is_bounded(&self) -> bool { fn is_bounded(&mut self) -> bool {
let bounded = self.bounded.get(); let bounded = self.bounded.get();
bounded bounded
} }
@ -179,7 +176,7 @@ pub impl protocol_ {
pub impl protocol { pub impl protocol {
fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction, fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction,
+ty_params: ~[ast::ty_param]) -> state { +ty_params: ~[ast::ty_param]) -> state {
let messages = DVec(); let messages = @mut ~[];
let state = @state_ { let state = @state_ {
id: self.states.len(), id: self.states.len(),

View File

@ -59,7 +59,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
let r = @mut TtReader { let r = @mut TtReader {
sp_diag: sp_diag, sp_diag: sp_diag,
interner: itr, interner: itr,
mut cur: @mut TtFrame { cur: @mut TtFrame {
readme: @mut src, readme: @mut src,
idx: 0u, idx: 0u,
dotdotdoted: false, dotdotdoted: false,