diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-04-12 12:16:21 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-04-12 14:31:46 -0700 |
| commit | d7e881841438cfe0797b71ff35ea96c8f2477a76 (patch) | |
| tree | 727e73ccf9138df34a1ad3585ef00559e526b2c6 /src/lib | |
| parent | 87d17c3a2cfbdaf3d860a9df171c6be220aaab5e (diff) | |
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.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/bitv.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs index 75254ce75e8..fab40ac8332 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"; } |
