about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/comp/syntax/ext/fmt.rs2
-rw-r--r--src/libcore/extfmt.rs7
-rw-r--r--src/libcore/sys.rs5
-rw-r--r--src/rt/rust_shape.cpp18
-rw-r--r--src/rt/rust_util.h2
-rw-r--r--src/rt/rustrt.def.in1
-rw-r--r--src/test/run-pass/log-str.rs4
7 files changed, 38 insertions, 1 deletions
diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs
index 3b17fdb6f7c..dc613bcbaa6 100644
--- a/src/comp/syntax/ext/fmt.rs
+++ b/src/comp/syntax/ext/fmt.rs
@@ -247,6 +247,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
           ty_bits. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
           ty_octal. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
           ty_float. { ret make_conv_call(cx, arg.span, "float", cnv, arg); }
+          ty_poly. { ret make_conv_call(cx, arg.span, "poly", cnv, arg); }
           _ { cx.span_unimpl(sp, unsupported); }
         }
     }
@@ -303,6 +304,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
           }
           ty_octal. { #debug("type: octal"); }
           ty_float. { #debug("type: float"); }
+          ty_poly. { #debug("type: poly"); }
         }
     }
     let fmt_sp = args[0].span;
diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs
index 74826310066..0d364878346 100644
--- a/src/libcore/extfmt.rs
+++ b/src/libcore/extfmt.rs
@@ -50,6 +50,7 @@ mod ct {
         ty_hex(caseness);
         ty_octal;
         ty_float;
+        ty_poly;
         // FIXME: More types
     }
     tag flag {
@@ -249,6 +250,8 @@ mod ct {
                 ty_octal
             } else if str::eq(tstr, "f") {
                 ty_float
+            } else if str::eq(tstr, "?") {
+                ty_poly
             } else { error("unknown type in conversion: " + tstr) };
         ret {ty: t, next: i + 1u};
     }
@@ -346,6 +349,10 @@ mod rt {
         }
         ret pad(cv, s, pad_signed);
     }
+    fn conv_poly<T>(cv: conv, v: T) -> str {
+        let s = sys::log_str(v);
+        ret conv_str(cv, s);
+    }
 
     // Convert an int to string with minimum number of digits. If precision is
     // 0 and num is 0 then the result is the empty string.
diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs
index 9c8b0972111..21032e72122 100644
--- a/src/libcore/sys.rs
+++ b/src/libcore/sys.rs
@@ -19,6 +19,7 @@ native mod rustrt {
     fn refcount<T>(t: @T) -> uint;
     fn do_gc();
     fn unsupervise();
+    fn shape_log_str<T>(t: *sys::type_desc, data: T) -> str;
 }
 
 #[abi = "rust-intrinsic"]
@@ -87,6 +88,10 @@ fn unsupervise() -> () {
     ret rustrt::unsupervise();
 }
 
+fn log_str<T>(t: T) -> str {
+    rustrt::shape_log_str(get_type_desc::<T>(), t)
+}
+
 // Local Variables:
 // mode: rust;
 // fill-column: 78;
diff --git a/src/rt/rust_shape.cpp b/src/rt/rust_shape.cpp
index 1743aaad9dd..ee7e389dc77 100644
--- a/src/rt/rust_shape.cpp
+++ b/src/rt/rust_shape.cpp
@@ -548,6 +548,24 @@ shape_cmp_type(int8_t *result, const type_desc *tydesc,
     }
 }
 
+extern "C" rust_str *
+shape_log_str(const type_desc *tydesc, uint8_t *data) {
+    rust_task *task = rust_scheduler::get_task();
+
+    shape::arena arena;
+    shape::type_param *params =
+        shape::type_param::from_tydesc_and_data(tydesc, data, arena);
+
+    std::stringstream ss;
+    shape::log log(task, true, tydesc->shape, params, tydesc->shape_tables,
+                   data, ss);
+
+    log.walk();
+
+    int len = ss.str().length();
+    return make_str(task->kernel, ss.str().c_str(), len, "log_str");
+}
+
 extern "C" void
 shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
     rust_task *task = rust_scheduler::get_task();
diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h
index 37a1eb93e1d..9b3b4c6f45d 100644
--- a/src/rt/rust_util.h
+++ b/src/rt/rust_util.h
@@ -191,7 +191,7 @@ inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) {
 typedef rust_vec rust_str;
 
 inline rust_str *
-make_str(rust_kernel* kernel, char* c, size_t strlen, const char* name) {
+make_str(rust_kernel* kernel, const char* c, size_t strlen, const char* name) {
     size_t str_fill = strlen + 1;
     size_t str_alloc = str_fill;
     rust_str *str = (rust_str *)
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index da353e9f6a6..7e57625fac1 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -48,6 +48,7 @@ rust_task_sleep
 rust_get_task
 set_min_stack
 sched_threads
+shape_log_str
 squareroot
 start_task
 vec_reserve_shared
diff --git a/src/test/run-pass/log-str.rs b/src/test/run-pass/log-str.rs
new file mode 100644
index 00000000000..0fb989aa308
--- /dev/null
+++ b/src/test/run-pass/log-str.rs
@@ -0,0 +1,4 @@
+fn main() {
+    assert "[1, 2, 3]" == sys::log_str([1, 2, 3]);
+    assert #fmt["%?/%5?", [1, 2, 3], "hi"] == "[1, 2, 3]/ \"hi\"";
+}