From c28af2625870b2117e73fc8bee83a1704cff7414 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 23 Jul 2012 13:50:12 -0700 Subject: Refactor the bounded pingpong example to avoid needing to generate unsafe code. Took some steps towards bounded codegen. --- src/libsyntax/ext/pipes/liveness.rs | 3 +++ src/libsyntax/ext/pipes/proto.rs | 46 ++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 19 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs index 4f803992520..d8467e36c84 100644 --- a/src/libsyntax/ext/pipes/liveness.rs +++ b/src/libsyntax/ext/pipes/liveness.rs @@ -84,8 +84,11 @@ fn analyze(proto: protocol, _cx: ext_ctxt) { // involving these states: %s", // *proto.name, // states)); + + proto.bounded = some(false); } else { #debug("protocol %s is bounded. yay!", *proto.name); + proto.bounded = some(true); } } \ No newline at end of file diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index e9070c79b55..8a535e85188 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -98,23 +98,23 @@ impl methods for state { } } -enum protocol { - protocol_(@{ - name: ident, - states: dvec, - }), -} +type protocol = @protocol_; -fn protocol(name: ident) -> protocol { - protocol_(@{name: name, states: dvec()}) -} +fn protocol(name: ident) -> protocol { @protocol_(name) } -impl methods for protocol { - fn add_state(name: ident, dir: direction) -> state { - self.add_state_poly(name, dir, ~[]) +class protocol_ { + let name: ident; + let states: dvec; + + let mut bounded: option; + + new(name: ident) { + self.name = name; + self.states = dvec(); + self.bounded = none; } - /// Get or create a state. + /// Get a state. fn get_state(name: ident) -> state { self.states.find(|i| i.name == name).get() } @@ -125,6 +125,20 @@ impl methods for protocol { self.states.find(|i| i.name == name) != none } + fn filename() -> ~str { + ~"proto://" + *self.name + } + + fn num_states() -> uint { self.states.len() } + + fn is_bounded() -> bool { self.bounded.get() } +} + +impl methods for protocol { + fn add_state(name: ident, dir: direction) -> state { + self.add_state_poly(name, dir, ~[]) + } + fn add_state_poly(name: ident, dir: direction, +ty_params: ~[ast::ty_param]) -> state { let messages = dvec(); @@ -141,12 +155,6 @@ impl methods for protocol { self.states.push(state); state } - - fn filename() -> ~str { - ~"proto://" + *self.name - } - - fn num_states() -> uint { self.states.len() } } trait visitor { -- cgit 1.4.1-3-g733a5