aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-04-21 16:44:17 -0700
committerPatrick Walton <[email protected]>2011-04-21 16:44:17 -0700
commit735435bf964dcafdfc09d01ea644bbfbe725abd8 (patch)
tree0689fd29766063d7cb853c31989ba983c5a9d587 /src
parentrustc: Pass a type store around, which does nothing yet (diff)
downloadrust-735435bf964dcafdfc09d01ea644bbfbe725abd8.tar.xz
rust-735435bf964dcafdfc09d01ea644bbfbe725abd8.zip
stdlib: Add a pointer equality function to the standard library and a test case
Diffstat (limited to 'src')
-rw-r--r--src/lib/Box.rs8
-rw-r--r--src/lib/std.rc1
-rw-r--r--src/rt/rust_builtin.cpp5
-rw-r--r--src/rt/rustrt.def.in1
-rw-r--r--src/test/run-pass/lib-box.rs12
5 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/Box.rs b/src/lib/Box.rs
new file mode 100644
index 00000000..2d94c680
--- /dev/null
+++ b/src/lib/Box.rs
@@ -0,0 +1,8 @@
+export rustrt;
+
+native "rust" mod rustrt {
+ fn rust_ptr_eq[T](@T a, @T b) -> int;
+}
+
+fn ptr_eq[T](@T a, @T b) -> bool { ret rustrt.rust_ptr_eq[T](a, b) != 0; }
+
diff --git a/src/lib/std.rc b/src/lib/std.rc
index 7e9e06c2..1056f375 100644
--- a/src/lib/std.rc
+++ b/src/lib/std.rc
@@ -69,6 +69,7 @@ mod sha1;
mod ebml;
mod UFind;
mod ExtFmt;
+mod Box;
// Local Variables:
// mode: rust;
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index c1aa5b59..30e2eb3d 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -468,6 +468,11 @@ rust_file_is_dir(rust_task *task, rust_str *path) {
extern "C" CDECL FILE* rust_get_stdin() {return stdin;}
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
+extern "C" CDECL int
+rust_ptr_eq(rust_task *task, type_desc *t, rust_box *a, rust_box *b) {
+ return a == b;
+}
+
//
// Local Variables:
// mode: C++
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 9ea6bee4..d724dd71 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -19,6 +19,7 @@ rust_get_stdin
rust_get_stdout
rust_list_files
rust_process_wait
+rust_ptr_eq
rust_run_program
rust_start
size_of
diff --git a/src/test/run-pass/lib-box.rs b/src/test/run-pass/lib-box.rs
new file mode 100644
index 00000000..10f5e727
--- /dev/null
+++ b/src/test/run-pass/lib-box.rs
@@ -0,0 +1,12 @@
+use std;
+import std.Box;
+
+fn main() {
+ auto x = @3;
+ auto y = @3;
+ check (Box.ptr_eq[int](x, x));
+ check (Box.ptr_eq[int](y, y));
+ check (!Box.ptr_eq[int](x, y));
+ check (!Box.ptr_eq[int](y, x));
+}
+