Skip to content

Commit b4ea2cf

Browse files
committed
---
yaml --- r: 1374 b: refs/heads/master c: 7446af7 h: refs/heads/master v: v3
1 parent c07d9ab commit b4ea2cf

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c9956a65b49f9cf2b1a691f2b88d61ada753d271
2+
refs/heads/master: 7446af747d83622c849ec9f29c0365aa7bf4e697

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ TEST_XFAILS_BOOT := $(TASK_XFAILS) \
444444
TEST_XFAILS_RUSTC := $(filter-out \
445445
$(addprefix test/run-pass/, \
446446
alt-path.rs \
447+
alt-pattern-lit.rs \
447448
alt-pattern-simple.rs \
448449
alt-tag.rs \
449450
arith-0.rs \

trunk/src/comp/middle/trans.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,24 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
18381838
fail;
18391839
}
18401840

1841+
// FIXME: implement proper structural comparison.
1842+
1843+
fn trans_compare(@block_ctxt cx, ast.binop op,
1844+
ValueRef lhs, ValueRef rhs) -> ValueRef {
1845+
auto cmp = lib.llvm.LLVMIntEQ;
1846+
alt (op) {
1847+
case (ast.eq) { cmp = lib.llvm.LLVMIntEQ; }
1848+
case (ast.ne) { cmp = lib.llvm.LLVMIntNE; }
1849+
1850+
// FIXME (issue #57): switch by signedness.
1851+
case (ast.lt) { cmp = lib.llvm.LLVMIntSLT; }
1852+
case (ast.le) { cmp = lib.llvm.LLVMIntSLE; }
1853+
case (ast.ge) { cmp = lib.llvm.LLVMIntSGE; }
1854+
case (ast.gt) { cmp = lib.llvm.LLVMIntSGT; }
1855+
}
1856+
ret cx.build.ICmp(cmp, lhs, rhs);
1857+
}
1858+
18411859
fn trans_eager_binop(@block_ctxt cx, ast.binop op,
18421860
ValueRef lhs, ValueRef rhs) -> ValueRef {
18431861

@@ -1857,18 +1875,7 @@ fn trans_eager_binop(@block_ctxt cx, ast.binop op,
18571875
case (ast.lsr) { ret cx.build.LShr(lhs, rhs); }
18581876
case (ast.asr) { ret cx.build.AShr(lhs, rhs); }
18591877
case (_) {
1860-
auto cmp = lib.llvm.LLVMIntEQ;
1861-
alt (op) {
1862-
case (ast.eq) { cmp = lib.llvm.LLVMIntEQ; }
1863-
case (ast.ne) { cmp = lib.llvm.LLVMIntNE; }
1864-
1865-
// FIXME (issue #57): switch by signedness.
1866-
case (ast.lt) { cmp = lib.llvm.LLVMIntSLT; }
1867-
case (ast.le) { cmp = lib.llvm.LLVMIntSLE; }
1868-
case (ast.ge) { cmp = lib.llvm.LLVMIntSGE; }
1869-
case (ast.gt) { cmp = lib.llvm.LLVMIntSGT; }
1870-
}
1871-
ret cx.build.ICmp(cmp, lhs, rhs);
1878+
ret trans_compare(cx, op, lhs, rhs);
18721879
}
18731880
}
18741881
fail;
@@ -2132,6 +2139,16 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
21322139
alt (pat.node) {
21332140
case (ast.pat_wild(_)) { ret res(cx, llval); }
21342141
case (ast.pat_bind(_, _, _)) { ret res(cx, llval); }
2142+
2143+
case (ast.pat_lit(?lt, ?ann)) {
2144+
auto lllit = trans_lit(cx.fcx.ccx, *lt, ann);
2145+
auto lleq = trans_compare(cx, ast.eq, llval, lllit);
2146+
2147+
auto matched_cx = new_sub_block_ctxt(cx, "matched_cx");
2148+
cx.build.CondBr(lleq, matched_cx.llbb, next_cx.llbb);
2149+
ret res(matched_cx, llval);
2150+
}
2151+
21352152
case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) {
21362153
auto lltagptr = cx.build.GEP(llval, vec(C_int(0), C_int(0)));
21372154
auto lltag = cx.build.Load(lltagptr);
@@ -2184,6 +2201,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
21842201
-> result {
21852202
alt (pat.node) {
21862203
case (ast.pat_wild(_)) { ret res(cx, llval); }
2204+
case (ast.pat_lit(_, _)) { ret res(cx, llval); }
21872205
case (ast.pat_bind(?id, ?def_id, ?ann)) {
21882206
auto ty = node_ann_type(cx.fcx.ccx, ann);
21892207
auto llty = type_of(cx.fcx.ccx, ty);

0 commit comments

Comments
 (0)