about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-02-11 23:49:13 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-11 23:49:13 -0800
commit910c6a5df8623e3fb18404dfa292dcbc8d930672 (patch)
tree91f07afa70c1127720552fafbff455d69ab526b7 /src
parent87d17be8462725c61e0104bc1fe6b5607e642065 (diff)
core: Fill out missing functions for basic types
Diffstat (limited to 'src')
-rw-r--r--src/libcore/f32.rs2
-rw-r--r--src/libcore/f64.rs2
-rw-r--r--src/libcore/float.rs2
-rw-r--r--src/libcore/i16.rs29
-rw-r--r--src/libcore/i32.rs29
-rw-r--r--src/libcore/i64.rs27
-rw-r--r--src/libcore/i8.rs29
-rw-r--r--src/libcore/int.rs20
-rw-r--r--src/libcore/u16.rs29
-rw-r--r--src/libcore/u32.rs2
-rw-r--r--src/libcore/u64.rs2
-rw-r--r--src/libcore/u8.rs14
-rw-r--r--src/libcore/uint.rs2
13 files changed, 162 insertions, 27 deletions
diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs
index 72f26958dee..d46a3bda312 100644
--- a/src/libcore/f32.rs
+++ b/src/libcore/f32.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `f32`"];
+#[doc = "Operations and constants for `f32`"];
 
 // PORT
 
diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs
index 1b17d7aaaa0..6d0f838d557 100644
--- a/src/libcore/f64.rs
+++ b/src/libcore/f64.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `f64`"];
+#[doc = "Operations and constants for `f64`"];
 
 // PORT
 
diff --git a/src/libcore/float.rs b/src/libcore/float.rs
index 1bcb084ccf5..f8a0e5ea7cf 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `float`"];
+#[doc = "Operations and constants for `float`"];
 
 /*
 Module: float
diff --git a/src/libcore/i16.rs b/src/libcore/i16.rs
index 4a4f4f3e35b..7fc0edebe6f 100644
--- a/src/libcore/i16.rs
+++ b/src/libcore/i16.rs
@@ -1 +1,28 @@
-#[doc = "Operations and constants constants for `i16`"];
+#[doc = "Operations and constants for `i16`"];
+
+const min_value: i16 = -1i16 << 15i16;
+const max_value: i16 = (-1i16 << 15i16) - 1i16;
+
+pure fn add(x: i16, y: i16) -> i16 { x + y }
+pure fn sub(x: i16, y: i16) -> i16 { x - y }
+pure fn mul(x: i16, y: i16) -> i16 { x * y }
+pure fn div(x: i16, y: i16) -> i16 { x / y }
+pure fn rem(x: i16, y: i16) -> i16 { x % y }
+
+pure fn lt(x: i16, y: i16) -> bool { x < y }
+pure fn le(x: i16, y: i16) -> bool { x <= y }
+pure fn eq(x: i16, y: i16) -> bool { x == y }
+pure fn ne(x: i16, y: i16) -> bool { x != y }
+pure fn ge(x: i16, y: i16) -> bool { x >= y }
+pure fn gt(x: i16, y: i16) -> bool { x > y }
+
+pure fn positive(x: i16) -> bool { x > 0i16 }
+pure fn negative(x: i16) -> bool { x < 0i16 }
+pure fn nonpositive(x: i16) -> bool { x <= 0i16 }
+pure fn nonnegative(x: i16) -> bool { x >= 0i16 }
+
+#[doc = "Iterate over the range [`lo`..`hi`)"]
+fn range(lo: i16, hi: i16, it: fn(i16)) {
+    let i = lo;
+    while i < hi { it(i); i += 1i16; }
+}
diff --git a/src/libcore/i32.rs b/src/libcore/i32.rs
index 03465f5e453..9d5e4e986ef 100644
--- a/src/libcore/i32.rs
+++ b/src/libcore/i32.rs
@@ -1 +1,28 @@
-#[doc = "Operations and constants constants for `i32`"];
+#[doc = "Operations and constants for `i32`"];
+
+const min_value: i32 = -1i32 << 31i32;
+const max_value: i32 = (-1i32 << 31i32) - 1i32;
+
+pure fn add(x: i32, y: i32) -> i32 { x + y }
+pure fn sub(x: i32, y: i32) -> i32 { x - y }
+pure fn mul(x: i32, y: i32) -> i32 { x * y }
+pure fn div(x: i32, y: i32) -> i32 { x / y }
+pure fn rem(x: i32, y: i32) -> i32 { x % y }
+
+pure fn lt(x: i32, y: i32) -> bool { x < y }
+pure fn le(x: i32, y: i32) -> bool { x <= y }
+pure fn eq(x: i32, y: i32) -> bool { x == y }
+pure fn ne(x: i32, y: i32) -> bool { x != y }
+pure fn ge(x: i32, y: i32) -> bool { x >= y }
+pure fn gt(x: i32, y: i32) -> bool { x > y }
+
+pure fn positive(x: i32) -> bool { x > 0i32 }
+pure fn negative(x: i32) -> bool { x < 0i32 }
+pure fn nonpositive(x: i32) -> bool { x <= 0i32 }
+pure fn nonnegative(x: i32) -> bool { x >= 0i32 }
+
+#[doc = "Iterate over the range [`lo`..`hi`)"]
+fn range(lo: i32, hi: i32, it: fn(i32)) {
+    let i = lo;
+    while i < hi { it(i); i += 1i32; }
+}
diff --git a/src/libcore/i64.rs b/src/libcore/i64.rs
index 67371137041..1cdefcb68a6 100644
--- a/src/libcore/i64.rs
+++ b/src/libcore/i64.rs
@@ -1 +1,28 @@
 #[doc = "Operations and constants constants for `i64`"];
+
+const min_value: i64 = -1i64 << 63i64;
+const max_value: i64 = (-1i64 << 63i64) - 1i64;
+
+pure fn add(x: i64, y: i64) -> i64 { x + y }
+pure fn sub(x: i64, y: i64) -> i64 { x - y }
+pure fn mul(x: i64, y: i64) -> i64 { x * y }
+pure fn div(x: i64, y: i64) -> i64 { x / y }
+pure fn rem(x: i64, y: i64) -> i64 { x % y }
+
+pure fn lt(x: i64, y: i64) -> bool { x < y }
+pure fn le(x: i64, y: i64) -> bool { x <= y }
+pure fn eq(x: i64, y: i64) -> bool { x == y }
+pure fn ne(x: i64, y: i64) -> bool { x != y }
+pure fn ge(x: i64, y: i64) -> bool { x >= y }
+pure fn gt(x: i64, y: i64) -> bool { x > y }
+
+pure fn positive(x: i64) -> bool { x > 0i64 }
+pure fn negative(x: i64) -> bool { x < 0i64 }
+pure fn nonpositive(x: i64) -> bool { x <= 0i64 }
+pure fn nonnegative(x: i64) -> bool { x >= 0i64 }
+
+#[doc = "Iterate over the range [`lo`..`hi`)"]
+fn range(lo: i64, hi: i64, it: fn(i64)) {
+    let i = lo;
+    while i < hi { it(i); i += 1i64; }
+}
diff --git a/src/libcore/i8.rs b/src/libcore/i8.rs
index 6d3331776b2..8b3650cd983 100644
--- a/src/libcore/i8.rs
+++ b/src/libcore/i8.rs
@@ -1 +1,28 @@
-#[doc = "Operations and constants constants for `i8`"];
+#[doc = "Operations and constants for `i8`"];
+
+const min_value: i8 = -1i8 << 7i8;
+const max_value: i8 = (-1i8 << 7i8) - 1i8;
+
+pure fn add(x: i8, y: i8) -> i8 { x + y }
+pure fn sub(x: i8, y: i8) -> i8 { x - y }
+pure fn mul(x: i8, y: i8) -> i8 { x * y }
+pure fn div(x: i8, y: i8) -> i8 { x / y }
+pure fn rem(x: i8, y: i8) -> i8 { x % y }
+
+pure fn lt(x: i8, y: i8) -> bool { x < y }
+pure fn le(x: i8, y: i8) -> bool { x <= y }
+pure fn eq(x: i8, y: i8) -> bool { x == y }
+pure fn ne(x: i8, y: i8) -> bool { x != y }
+pure fn ge(x: i8, y: i8) -> bool { x >= y }
+pure fn gt(x: i8, y: i8) -> bool { x > y }
+
+pure fn positive(x: i8) -> bool { x > 0i8 }
+pure fn negative(x: i8) -> bool { x < 0i8 }
+pure fn nonpositive(x: i8) -> bool { x <= 0i8 }
+pure fn nonnegative(x: i8) -> bool { x >= 0i8 }
+
+#[doc = "Iterate over the range [`lo`..`hi`)"]
+fn range(lo: i8, hi: i8, it: fn(i8)) {
+    let i = lo;
+    while i < hi { it(i); i += 1i8; }
+}
diff --git a/src/libcore/int.rs b/src/libcore/int.rs
index 62c9be56dc9..e7583b23553 100644
--- a/src/libcore/int.rs
+++ b/src/libcore/int.rs
@@ -1,31 +1,31 @@
-#[doc = "Operations and constants constants for `int`"];
+#[doc = "Operations and constants for `int`"];
 
 /*
 Module: int
 */
 
 /*
-Const: max_value
+Const: min_value
 
-The maximum value of an integer
+The minumum value of an integer
 */
-// FIXME: Find another way to access the machine word size in a const expr
 #[cfg(target_arch="x86")]
-const max_value: int = (-1 << 31)-1;
+const min_value: int = -1 << 31;
 
 #[cfg(target_arch="x86_64")]
-const max_value: int = (-1 << 63)-1;
+const min_value: int = -1 << 63;
 
 /*
-Const: min_value
+Const: max_value
 
-The minumum value of an integer
+The maximum value of an integer
 */
+// FIXME: Find another way to access the machine word size in a const expr
 #[cfg(target_arch="x86")]
-const min_value: int = -1 << 31;
+const max_value: int = (-1 << 31)-1;
 
 #[cfg(target_arch="x86_64")]
-const min_value: int = -1 << 63;
+const max_value: int = (-1 << 63)-1;
 
 /* Function: add */
 pure fn add(x: int, y: int) -> int { ret x + y; }
diff --git a/src/libcore/u16.rs b/src/libcore/u16.rs
index 39812d8bd7e..36e68ecfdd2 100644
--- a/src/libcore/u16.rs
+++ b/src/libcore/u16.rs
@@ -1 +1,28 @@
-#[doc = "Operations and constants constants for `u16`"];
+#[doc = "Operations and constants for `u16`"];
+
+const min_value: u16 = 0u16;
+const max_value: u16 = 0u16 - 1u16;
+
+pure fn add(x: u16, y: u16) -> u16 { x + y }
+pure fn sub(x: u16, y: u16) -> u16 { x - y }
+pure fn mul(x: u16, y: u16) -> u16 { x * y }
+pure fn div(x: u16, y: u16) -> u16 { x / y }
+pure fn rem(x: u16, y: u16) -> u16 { x % y }
+
+pure fn lt(x: u16, y: u16) -> bool { x < y }
+pure fn le(x: u16, y: u16) -> bool { x <= y }
+pure fn eq(x: u16, y: u16) -> bool { x == y }
+pure fn ne(x: u16, y: u16) -> bool { x != y }
+pure fn ge(x: u16, y: u16) -> bool { x >= y }
+pure fn gt(x: u16, y: u16) -> bool { x > y }
+
+pure fn positive(x: u16) -> bool { x > 0u16 }
+pure fn negative(x: u16) -> bool { x < 0u16 }
+pure fn nonpositive(x: u16) -> bool { x <= 0u16 }
+pure fn nonnegative(x: u16) -> bool { x >= 0u16 }
+
+#[doc = "Iterate over the range [`lo`..`hi`)"]
+fn range(lo: u16, hi: u16, it: fn(u16)) {
+    let i = lo;
+    while i < hi { it(i); i += 1u16; }
+}
diff --git a/src/libcore/u32.rs b/src/libcore/u32.rs
index 013c15eae7c..ed002a8c1e5 100644
--- a/src/libcore/u32.rs
+++ b/src/libcore/u32.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `u32`"];
+#[doc = "Operations and constants for `u32`"];
 
 /*
 Module: u32
diff --git a/src/libcore/u64.rs b/src/libcore/u64.rs
index ebcba1f2d51..a8cbeab9c9c 100644
--- a/src/libcore/u64.rs
+++ b/src/libcore/u64.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `u64`"];
+#[doc = "Operations and constants for `u64`"];
 
 /*
 Module: u64
diff --git a/src/libcore/u8.rs b/src/libcore/u8.rs
index c1f09b3bd32..34553c27eb3 100644
--- a/src/libcore/u8.rs
+++ b/src/libcore/u8.rs
@@ -1,22 +1,22 @@
-#[doc = "Operations and constants constants for `u8`"];
+#[doc = "Operations and constants for `u8`"];
 
 /*
 Module: u8
 */
 
 /*
-Const: max_value
+Const: min_value
 
-The maximum value of a u8.
+The minumum value of a u8.
 */
-const max_value: u8 = 255u8;
+const min_value: u8 = 0u8;
 
 /*
-Const: min_value
+Const: max_value
 
-The minumum value of a u8.
+The maximum value of a u8.
 */
-const min_value: u8 = 0u8;
+const max_value: u8 = 255u8;
 
 /* Function: add */
 pure fn add(x: u8, y: u8) -> u8 { ret x + y; }
diff --git a/src/libcore/uint.rs b/src/libcore/uint.rs
index f9ca9d92bf4..cd1bf7ea555 100644
--- a/src/libcore/uint.rs
+++ b/src/libcore/uint.rs
@@ -1,4 +1,4 @@
-#[doc = "Operations and constants constants for `uint`"];
+#[doc = "Operations and constants for `uint`"];
 
 /*
 Module: uint