about summary refs log tree commit diff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2011-03-21 17:12:05 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-03-21 18:10:34 -0700
commitcaa22c93415bb106bced82bbabc3d9ffbef7e69c (patch)
tree2a77dc7cfb33c82dcdc83a69a423ebc4340e576e /src/comp/middle
parent35951c92dbc1bb2eeb94f7951b6186ce8239fc41 (diff)
downloadrust-caa22c93415bb106bced82bbabc3d9ffbef7e69c.tar.gz
rust-caa22c93415bb106bced82bbabc3d9ffbef7e69c.zip
Started adding support for floating-point type, floating-point literals, and logging of floats. Other operations on float probably don't work yet.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/trans.rs34
-rw-r--r--src/comp/middle/ty.rs3
-rw-r--r--src/comp/middle/typeck.rs1
3 files changed, 33 insertions, 5 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index e7102413788..7be12f910be 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -211,6 +211,11 @@ fn T_int() -> TypeRef {
     ret T_i32();
 }
 
+fn T_float() -> TypeRef {
+    // FIXME: switch on target type.
+    ret T_f64();
+}
+
 fn T_char() -> TypeRef {
     ret T_i32();
 }
@@ -360,10 +365,6 @@ fn T_crate(type_names tn) -> TypeRef {
     ret t;
 }
 
-fn T_double() -> TypeRef {
-    ret llvm.LLVMDoubleType();
-}
-
 fn T_taskptr(type_names tn) -> TypeRef {
     ret T_ptr(T_task(tn));
 }
@@ -590,6 +591,7 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef {
         case (ty.ty_nil) { llty = T_nil(); }
         case (ty.ty_bool) { llty = T_bool(); }
         case (ty.ty_int) { llty = T_int(); }
+        case (ty.ty_float) { llty = T_float(); }
         case (ty.ty_uint) { llty = T_int(); }
         case (ty.ty_machine(?tm)) {
             alt (tm) {
@@ -743,6 +745,10 @@ fn C_integral(int i, TypeRef t) -> ValueRef {
     ret llvm.LLVMConstIntOfString(t, _str.buf(istr(i)), 10);
 }
 
+fn C_float(str s) -> ValueRef {
+    ret llvm.LLVMConstRealOfString(T_float(), _str.buf(s));
+}
+
 fn C_nil() -> ValueRef {
     // NB: See comment above in T_void().
     ret C_integral(0, T_i1());
@@ -879,6 +885,7 @@ fn trans_upcall2(builder b, @glue_fns glues, ValueRef lltaskptr,
         llglue = glues.upcall_glues_cdecl.(n);
     }
     let vec[ValueRef] call_args = vec(llupcall);
+
     if (!pass_task) {
         call_args += vec(lltaskptr);
     }
@@ -2290,6 +2297,9 @@ fn trans_lit(@crate_ctxt cx, &ast.lit lit, &ast.ann ann) -> ValueRef {
             }
             ret C_integral(i, t);
         }
+        case(ast.lit_float(?fs)) {
+            ret C_float(fs);
+        }
         case (ast.lit_char(?c)) {
             ret C_integral(c as int, T_char());
         }
@@ -4477,12 +4487,27 @@ fn trans_log(@block_ctxt cx, @ast.expr e) -> result {
     auto sub = trans_expr(cx, e);
     auto e_ty = ty.expr_ty(e);
     alt (e_ty.struct) {
+        case(ty.ty_float) {
+            auto tmp = sub.bcx.build.Alloca(T_float());
+            sub.bcx.build.Store(sub.val, tmp);
+            sub = res(sub.bcx, tmp);
+        }
+        case(_) { }
+    }
+
+    alt (e_ty.struct) {
         case (ty.ty_str) {
             auto v = vp2i(sub.bcx, sub.val);
             ret trans_upcall(sub.bcx,
                              "upcall_log_str",
                              vec(v));
         }
+        case (ty.ty_float) {
+            auto v = vp2i(sub.bcx, sub.val);
+            ret trans_upcall(sub.bcx,
+                             "upcall_log_float",
+                             vec(v));
+        }
         case (_) {
             ret trans_upcall(sub.bcx,
                              "upcall_log_int",
@@ -6247,7 +6272,6 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
     collect_items(cx, crate);
     collect_tag_ctors(cx, crate);
     trans_constants(cx, crate);
-
     trans_mod(cx, crate.node.module);
     trans_vec_append_glue(cx);
     if (!shared) {
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index c6fbb5bf14d..bf525679e2b 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -32,6 +32,7 @@ tag sty {
     ty_nil;
     ty_bool;
     ty_int;
+    ty_float;
     ty_uint;
     ty_machine(util.common.ty_mach);
     ty_char;
@@ -162,6 +163,7 @@ fn ty_to_str(&@t typ) -> str {
         case (ty_nil)          { s += "()";                         }
         case (ty_bool)         { s += "bool";                       }
         case (ty_int)          { s += "int";                        }
+        case (ty_float)        { s += "float";                      }
         case (ty_uint)         { s += "uint";                       }
         case (ty_machine(?tm)) { s += common.ty_mach_to_str(tm);    }
         case (ty_char)         { s += "char";                       }
@@ -418,6 +420,7 @@ fn type_is_scalar(@t ty) -> bool {
         case (ty_nil) { ret true; }
         case (ty_bool) { ret true; }
         case (ty_int) { ret true; }
+        case (ty_float) { ret true; }
         case (ty_uint) { ret true; }
         case (ty_machine(_)) { ret true; }
         case (ty_char) { ret true; }
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index e4eaf2fb97a..c849483e8ad 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -1493,6 +1493,7 @@ fn check_lit(@ast.lit lit) -> @ty.t {
         case (ast.lit_str(_))           { sty = ty.ty_str;  }
         case (ast.lit_char(_))          { sty = ty.ty_char; }
         case (ast.lit_int(_))           { sty = ty.ty_int;  }
+        case (ast.lit_float(_))           { sty = ty.ty_float;  }
         case (ast.lit_uint(_))          { sty = ty.ty_uint; }
         case (ast.lit_mach_int(?tm, _)) { sty = ty.ty_machine(tm); }
         case (ast.lit_nil)              { sty = ty.ty_nil;  }