about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-02-10 19:40:02 -0800
committerGraydon Hoare <graydon@mozilla.com>2011-02-10 19:40:02 -0800
commit7446af747d83622c849ec9f29c0365aa7bf4e697 (patch)
treed3aca76bc89dc4d7f3e4d5a33b3fa770a45d2214 /src/comp
parentc9956a65b49f9cf2b1a691f2b88d61ada753d271 (diff)
downloadrust-7446af747d83622c849ec9f29c0365aa7bf4e697.tar.gz
rust-7446af747d83622c849ec9f29c0365aa7bf4e697.zip
Translate pat_lit, un-XFAIL alt-pattern-lit.rs for rustc.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 4135a6e59de..bedfad97980 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1838,6 +1838,24 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
     fail;
 }
 
+// FIXME: implement proper structural comparison.
+
+fn trans_compare(@block_ctxt cx, ast.binop op,
+                 ValueRef lhs, ValueRef rhs) -> ValueRef {
+    auto cmp = lib.llvm.LLVMIntEQ;
+    alt (op) {
+        case (ast.eq) { cmp = lib.llvm.LLVMIntEQ; }
+        case (ast.ne) { cmp = lib.llvm.LLVMIntNE; }
+
+        // FIXME (issue #57): switch by signedness.
+        case (ast.lt) { cmp = lib.llvm.LLVMIntSLT; }
+        case (ast.le) { cmp = lib.llvm.LLVMIntSLE; }
+        case (ast.ge) { cmp = lib.llvm.LLVMIntSGE; }
+        case (ast.gt) { cmp = lib.llvm.LLVMIntSGT; }
+    }
+    ret cx.build.ICmp(cmp, lhs, rhs);
+}
+
 fn trans_eager_binop(@block_ctxt cx, ast.binop op,
                      ValueRef lhs, ValueRef rhs) -> ValueRef {
 
@@ -1857,18 +1875,7 @@ fn trans_eager_binop(@block_ctxt cx, ast.binop op,
         case (ast.lsr) { ret cx.build.LShr(lhs, rhs); }
         case (ast.asr) { ret cx.build.AShr(lhs, rhs); }
         case (_) {
-            auto cmp = lib.llvm.LLVMIntEQ;
-            alt (op) {
-                case (ast.eq) { cmp = lib.llvm.LLVMIntEQ; }
-                case (ast.ne) { cmp = lib.llvm.LLVMIntNE; }
-
-                // FIXME (issue #57): switch by signedness.
-                case (ast.lt) { cmp = lib.llvm.LLVMIntSLT; }
-                case (ast.le) { cmp = lib.llvm.LLVMIntSLE; }
-                case (ast.ge) { cmp = lib.llvm.LLVMIntSGE; }
-                case (ast.gt) { cmp = lib.llvm.LLVMIntSGT; }
-            }
-            ret cx.build.ICmp(cmp, lhs, rhs);
+            ret trans_compare(cx, op, lhs, rhs);
         }
     }
     fail;
@@ -2132,6 +2139,16 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
     alt (pat.node) {
         case (ast.pat_wild(_)) { ret res(cx, llval); }
         case (ast.pat_bind(_, _, _)) { ret res(cx, llval); }
+
+        case (ast.pat_lit(?lt, ?ann)) {
+            auto lllit = trans_lit(cx.fcx.ccx, *lt, ann);
+            auto lleq = trans_compare(cx, ast.eq, llval, lllit);
+
+            auto matched_cx = new_sub_block_ctxt(cx, "matched_cx");
+            cx.build.CondBr(lleq, matched_cx.llbb, next_cx.llbb);
+            ret res(matched_cx, llval);
+        }
+
         case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) {
             auto lltagptr = cx.build.GEP(llval, vec(C_int(0), C_int(0)));
             auto lltag = cx.build.Load(lltagptr);
@@ -2184,6 +2201,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
     -> result {
     alt (pat.node) {
         case (ast.pat_wild(_)) { ret res(cx, llval); }
+        case (ast.pat_lit(_, _)) { ret res(cx, llval); }
         case (ast.pat_bind(?id, ?def_id, ?ann)) {
             auto ty = node_ann_type(cx.fcx.ccx, ann);
             auto llty = type_of(cx.fcx.ccx, ty);