2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Module: util
|
|
|
|
*/
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Function: id
|
|
|
|
|
|
|
|
The identity function
|
|
|
|
*/
|
2012-01-02 08:31:58 -06:00
|
|
|
pure fn id<copy T>(x: T) -> T { x }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Function: unreachable
|
|
|
|
|
|
|
|
A standard function to use to indicate unreachable code. Because the
|
|
|
|
function is guaranteed to fail typestate will correctly identify
|
|
|
|
any code paths following the appearance of this function as unreachable.
|
|
|
|
*/
|
2011-09-15 17:24:22 -05:00
|
|
|
fn unreachable() -> ! {
|
|
|
|
fail "Internal error: entered unreachable code";
|
|
|
|
}
|
2010-06-29 01:18:51 -05:00
|
|
|
|
2010-08-03 19:52:35 -05:00
|
|
|
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment
|
|
|
|
* the constraint once fixed. */
|
2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Function: rational
|
|
|
|
|
|
|
|
A rational number
|
|
|
|
*/
|
2011-09-15 17:24:22 -05:00
|
|
|
type rational = {num: int, den: int}; // : int::positive(*.den);
|
2011-06-16 18:55:46 -05:00
|
|
|
|
2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Function: rational_leq
|
|
|
|
*/
|
2011-09-15 17:24:22 -05:00
|
|
|
pure fn rational_leq(x: rational, y: rational) -> bool {
|
2011-05-12 10:24:54 -05:00
|
|
|
// NB: Uses the fact that rationals have positive denominators WLOG:
|
2010-09-22 17:44:13 -05:00
|
|
|
|
2011-09-15 17:24:22 -05:00
|
|
|
x.num * y.den <= y.num * x.den
|
2011-04-06 19:56:44 -05:00
|
|
|
}
|
|
|
|
|
2011-10-27 16:54:18 -05:00
|
|
|
/*
|
|
|
|
Function: orb
|
|
|
|
*/
|
2011-09-15 17:24:22 -05:00
|
|
|
pure fn orb(a: bool, b: bool) -> bool { a || b }
|
2011-10-05 17:36:29 -05:00
|
|
|
|
2011-10-27 16:54:18 -05:00
|
|
|
// FIXME: Document what this is for or delete it
|
2011-10-05 17:36:29 -05:00
|
|
|
tag void {
|
|
|
|
void(@void);
|
|
|
|
}
|
|
|
|
|
2010-09-22 17:44:13 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|