1
Fork 0

Use 'resource' rather than 'res' as a keyword

Resources are now defined like...

    resource fd(int n) { close(n); }

Calling fd with an int will then produce a non-copyable value
that, when dropped, will call close on the given int.
This commit is contained in:
Marijn Haverbeke 2011-06-28 17:53:00 +02:00
parent fb14afd5eb
commit 9561def209
4 changed files with 8 additions and 8 deletions

View file

@ -139,7 +139,7 @@ fn bad_expr_word_table() -> hashmap[str, ()] {
words.insert("be", ());
words.insert("fail", ());
words.insert("type", ());
words.insert("res", ());
words.insert("resource", ());
words.insert("check", ());
words.insert("assert", ());
words.insert("claim", ());
@ -2045,7 +2045,7 @@ fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
ret got_item(parse_item_tag(p, attrs));
} else if (eat_word(p, "obj")) {
ret got_item(parse_item_obj(p, lyr, attrs));
} else if (eat_word(p, "res")) {
} else if (eat_word(p, "resource")) {
ret got_item(parse_item_res(p, lyr, attrs));
} else { ret no_item; }
}

View file

@ -1,6 +1,6 @@
// error-pattern:Copying a non-copyable type
res foo(int i) {}
resource foo(int i) {}
fn main() {
auto x <- foo(10);

View file

@ -5,13 +5,13 @@
// Tests for alt as expressions resulting in boxed types
fn test_box() {
auto rs = alt (true) { case (true) { @100 } };
assert (*rs == 100);
auto res = alt (true) { case (true) { @100 } };
assert (*res == 100);
}
fn test_str() {
auto rs = alt (true) { case (true) { "happy" } };
assert (rs == "happy");
auto res = alt (true) { case (true) { "happy" } };
assert (res == "happy");
}
fn main() { test_box(); test_str(); }

View file

@ -1,4 +1,4 @@
res shrinky_pointer(@mutable int i) {
resource shrinky_pointer(@mutable int i) {
*i -= 1;
}