diff options
| author | Tim Chevalier <[email protected]> | 2011-03-24 12:12:04 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-01 11:27:32 -0700 |
| commit | 3130348ee177f1716488b6caca6c7852fe47754c (patch) | |
| tree | ee090db0203277e2adf4686fe26bbc3d3f024fbb /src/lib | |
| parent | rustc: Remove useless call to tag_variant_with_id() (diff) | |
| download | rust-3130348ee177f1716488b6caca6c7852fe47754c.tar.xz rust-3130348ee177f1716488b6caca6c7852fe47754c.zip | |
Started adding support for typestate checking.
I added a new field to the ast "ann" type for typestate information.
Currently, the field contains a record of a precondition bit vector and
postcondition vector, but I tried to structure things so as to make
it easy to change the representation of the typestate annotation type.
I also had to add annotations to some syntactic forms that didn't have
them before (fail, ret, be...), with all the boilerplate changes
that that would imply.
The main call to the typestate_check entry point is commented out and
the actual pre-postcondition algorithm only has a few cases
implemented, though the overall AST traversal is there. The rest of
the typestate algorithm isn't implemented yet.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/_vec.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs index c3fc7035..f2b169ef 100644 --- a/src/lib/_vec.rs +++ b/src/lib/_vec.rs @@ -207,6 +207,29 @@ fn map2[T,U,V](&operator2[T,U,V] f, &vec[mutable? T] v0, &vec[mutable? U] v1) ret u; } +fn find[T](fn (&T) -> bool f, &vec[mutable? T] v) -> option.t[T] { + for (T elt in v) { + if (f(elt)) { + ret some[T](elt); + } + } + + ret none[T]; +} + +fn foldl[T, U](fn (&U, &T) -> U p, &U z, &vec[T] v) -> U { + auto sz = len[T](v); + + if (sz == 0u) { + ret z; + } + else { + auto rest = slice[T](v, 1u, sz); + + ret (p(foldl[T,U](p, z, rest), v.(0))); + } +} + // Local Variables: // mode: rust; // fill-column: 78; |