Revert "Move the option type to its own module"

This commit is contained in:
Patrick Walton 2010-11-05 10:41:23 -07:00
parent a58016d43e
commit 2fcf81cc4b
11 changed files with 46 additions and 68 deletions

View File

@ -5,9 +5,9 @@ import front.token;
import middle.trans;
import middle.resolve;
import std.option;
import std.option.some;
import std.option.none;
import std.util.option;
import std.util.some;
import std.util.none;
import std._str;
import std._vec;
@ -39,8 +39,8 @@ fn usage(session.session sess, str argv0) {
impure fn main(vec[str] args) {
auto sess = session.session();
let option.t[str] input_file = none[str];
let option.t[str] output_file = none[str];
let option[str] input_file = none[str];
let option[str] output_file = none[str];
let bool do_warn = true;
auto i = 1u;

View File

@ -1,4 +1,5 @@
import util.common.option;
import std.map.hashmap;
import std.util.option;
import util.common.span;

View File

@ -1,8 +1,8 @@
import std._io;
import std.option.some;
import std.option.none;
import std.map.hashmap;
import std.util.option;
import std.util.some;
import std.util.none;
import std.map.hashmap;
import driver.session;
import util.common;

View File

@ -1,7 +1,7 @@
import std.map.hashmap;
import std.option.some;
import std.option.none;
import std.util.option;
import std.util.some;
import std.util.none;
import util.common.new_str_hash;
import util.common.spanned;

View File

@ -8,9 +8,9 @@ import std.map.hashmap;
import std.list.list;
import std.list.nil;
import std.list.cons;
import std.option.some;
import std.option.none;
import std.util.option;
import std.util.some;
import std.util.none;
import std._str;
tag scope {

View File

@ -3,9 +3,9 @@ import std._vec;
import std._str.rustrt.sbuf;
import std._vec.rustrt.vbuf;
import std.map.hashmap;
import std.option.some;
import std.option.none;
import std.util.option;
import std.util.some;
import std.util.none;
import front.ast;
import driver.session;

View File

@ -2,7 +2,7 @@
* A deque, for fun. Untested as of yet. Likely buggy.
*/
import std.option;
import std.util;
import std._vec;
import std._int;
@ -23,7 +23,7 @@ type t[T] = obj {
fn create[T]() -> t[T] {
type cell[T] = mutable option.t[T];
type cell[T] = mutable util.option[T];
let uint initial_capacity = 32u; // 2^5
@ -39,7 +39,7 @@ fn create[T]() -> t[T] {
if (i < nelts) {
ret old.((lo + i) % nelts);
} else {
ret option.none;
ret util.none[T];
}
}
@ -50,7 +50,7 @@ fn create[T]() -> t[T] {
fn get[T](vec[cell[T]] elts, uint i) -> T {
alt (elts.(i)) {
case (option.some[T](?t)) { ret t; }
case (util.some[T](?t)) { ret t; }
case (_) { fail; }
}
}
@ -77,7 +77,7 @@ fn create[T]() -> t[T] {
hi = nelts;
}
elts.(lo) = option.some[T](t);
elts.(lo) = util.some[T](t);
nelts += 1u;
}
@ -88,7 +88,7 @@ fn create[T]() -> t[T] {
hi = nelts;
}
elts.(hi) = option.some[T](t);
elts.(hi) = util.some[T](t);
hi = (hi + 1u) % _vec.len[cell[T]](elts);
nelts += 1u;
}
@ -99,7 +99,7 @@ fn create[T]() -> t[T] {
*/
fn pop_front() -> T {
let T t = get[T](elts, lo);
elts.(lo) = option.none[T];
elts.(lo) = util.none[T];
lo = (lo + 1u) % _vec.len[cell[T]](elts);
nelts -= 1u;
ret t;
@ -113,7 +113,7 @@ fn create[T]() -> t[T] {
}
let T t = get[T](elts, hi);
elts.(hi) = option.none[T];
elts.(hi) = util.none[T];
nelts -= 1u;
ret t;
}
@ -132,7 +132,7 @@ fn create[T]() -> t[T] {
}
}
let vec[cell[T]] v = _vec.init_elt[cell[T]](option.none[T],
let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T],
initial_capacity);
ret deque[T](0u, 0u, 0u, v);

View File

@ -1,7 +1,7 @@
import option;
import option.some;
import option.none;
import util.option;
import util.some;
import util.none;
// FIXME: It would probably be more appealing to define this as
// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
}
fn find[T,U](&list[T] ls,
(fn(&T) -> option.t[U]) f) -> option.t[U] {
(fn(&T) -> option[U]) f) -> option[U] {
alt(ls) {
case (cons[T](?hd, ?tl)) {
alt (f(hd)) {

View File

@ -1,40 +0,0 @@
// lib/option.rs
tag t[T] {
none;
some(T);
}
type operator[T, U] = fn(&T) -> U;
fn get[T](&t[T] opt) -> T {
alt (opt) {
case (some[T](?x)) {
ret x;
}
case (none[T]) {
fail;
}
}
}
fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
alt (opt) {
case (some[T](?x)) {
ret some[U](f(x));
}
case (none[T]) {
ret none[U];
}
}
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

View File

@ -20,7 +20,6 @@ mod _task;
// Utility modules.
mod option;
mod util;
// Authorize various rule-bendings.

View File

@ -1,3 +1,21 @@
tag option[T] {
none;
some(T);
}
type operator[T, U] = fn(&T) -> U;
fn option_map[T, U](&operator[T, U] f, &option[T] opt) -> option[U] {
alt (opt) {
case (some[T](?x)) {
ret some[U](f(x));
}
case (none[T]) {
ret none[U];
}
}
}
fn id[T](&T x) -> T {
ret x;
}