From d7e881841438cfe0797b71ff35ea96c8f2477a76 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 12 Apr 2011 12:16:21 -0700 Subject: Further work on typestate. Handles expr_rec and expr_assign now. Also changed the ts_ann field on statements to be an ann instead, which explains most of the changes. As well, got rid of the "warning: no type for expression" error by filling in annotations for local decls in typeck (not sure whether this was my fault or not). Finally, in bitv, added a clone() function to copy a bit vector, and fixed is_true, is_false, and to_str to not be nonsense. --- src/lib/bitv.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs index 75254ce7..fab40ac8 100644 --- a/src/lib/bitv.rs +++ b/src/lib/bitv.rs @@ -74,6 +74,15 @@ impure fn copy(&t v0, t v1) -> bool { ret process(sub, v0, v1); } +fn clone(t v) -> t { + auto storage = _vec.init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u); + auto len = _vec.len[mutable uint](v.storage); + for each (uint i in _uint.range(0u, len)) { + storage.(i) = v.storage.(i); + } + ret rec(storage = storage, nbits = v.nbits); +} + fn get(&t v, uint i) -> bool { check (i < v.nbits); @@ -137,7 +146,7 @@ impure fn set(&t v, uint i, bool x) { /* true if all bits are 1 */ fn is_true(&t v) -> bool { - for(uint i in v.storage) { + for (uint i in to_vec(v)) { if (i != 1u) { ret false; } @@ -148,7 +157,7 @@ fn is_true(&t v) -> bool { /* true if all bits are non-1 */ fn is_false(&t v) -> bool { - for(uint i in v.storage) { + for (uint i in to_vec(v)) { if (i == 1u) { ret false; } @@ -173,7 +182,7 @@ fn to_vec(&t v) -> vec[uint] { fn to_str(&t v) -> str { auto res = ""; - for(uint i in v.storage) { + for (uint i in bitv.to_vec(v)) { if (i == 1u) { res += "1"; } -- cgit v1.2.3