aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-20 23:00:52 -0800
committerGraydon Hoare <[email protected]>2010-11-20 23:00:52 -0800
commit79a3811ab81ee14810fa9b7fe86ba0f0501c7399 (patch)
tree1a4fa2067dc2a9534c88c37f2ed5d5fd5e6f3c65 /src
parentFix bug in llvm type signature of function items; enable three more tests. (diff)
downloadrust-79a3811ab81ee14810fa9b7fe86ba0f0501c7399.tar.xz
rust-79a3811ab81ee14810fa9b7fe86ba0f0501c7399.zip
Typecheck binary, unary and name expressions. Re-enable 3 more tests.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile3
-rw-r--r--src/comp/middle/typeck.rs57
2 files changed, 55 insertions, 5 deletions
diff --git a/src/Makefile b/src/Makefile
index 9c4a746a..8afe0d45 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -517,7 +517,10 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
TEST_XFAILS_SELF := $(filter-out \
$(addprefix test/run-pass/, \
+ arith-0.rs \
+ arith-2.rs \
bool-not.rs \
+ char.rs \
dead-code-one-arm-if.rs \
hello.rs \
int.rs \
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 0809d9f1..73f6fa85 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -189,9 +189,7 @@ fn ty_to_str(@ty typ) -> str {
}
case (ty_var(?v)) {
- // FIXME: wrap around in the case of many variables
- auto ch = ('T' as u8) + (v as u8);
- s = _str.from_bytes(vec(ch));
+ s = "<T" + util.common.istr(v) + ">";
}
}
@@ -392,7 +390,7 @@ fn ann_to_type(&ast.ann ann) -> @ty {
alt (ann) {
case (ast.ann_none) {
// shouldn't happen, but can until the typechecker is complete
- ret plain_ty(ty_var(0)); // FIXME: broken, broken, broken
+ ret plain_ty(ty_var(-1)); // FIXME: broken, broken, broken
}
case (ast.ann_type(?ty)) {
ret ty;
@@ -463,7 +461,7 @@ fn unify(@ty expected, @ty actual) -> unify_result {
alt (result) {
case (ures_ok(?result_sub)) {
ret ures_ok(plain_ty(ty_box(result_sub)));
- }
+ }
case (_) {
ret result;
}
@@ -720,6 +718,55 @@ fn check_expr(&@env e, &@ty_table locals, @ast.expr expr) -> @ast.expr {
ast.expr_lit(lit, ast.ann_type(ty)));
}
+
+ case (ast.expr_binary(?binop, ?lhs, ?rhs, _)) {
+ auto lhs_1 = check_expr(e, locals, lhs);
+ auto rhs_1 = check_expr(e, locals, rhs);
+ auto lhs_t = type_of(lhs_1);
+ auto rhs_t = type_of(rhs_1);
+ // FIXME: Binops have a bit more subtlety than this.
+ demand(e, expr.span, lhs_t, rhs_t);
+ auto t = lhs_t;
+ alt (binop) {
+ case (ast.eq) { t = plain_ty(ty_bool); }
+ case (ast.lt) { t = plain_ty(ty_bool); }
+ case (ast.le) { t = plain_ty(ty_bool); }
+ case (ast.ne) { t = plain_ty(ty_bool); }
+ case (ast.ge) { t = plain_ty(ty_bool); }
+ case (ast.gt) { t = plain_ty(ty_bool); }
+ }
+ ret @fold.respan[ast.expr_](expr.span,
+ ast.expr_binary(binop, lhs_1, rhs_1,
+ ast.ann_type(t)));
+ }
+
+
+ case (ast.expr_unary(?unop, ?oper, _)) {
+ auto oper_1 = check_expr(e, locals, oper);
+ auto oper_t = type_of(oper_1);
+ // FIXME: Unops have a bit more subtlety than this.
+ ret @fold.respan[ast.expr_](expr.span,
+ ast.expr_unary(unop, oper_1,
+ ast.ann_type(oper_t)));
+ }
+
+ case (ast.expr_name(?name, ?defopt, _)) {
+ auto ty = @rec(struct=ty_nil, cname=none[str]);
+ alt (option.get[ast.def](defopt)) {
+ case (ast.def_arg(?id)) { ty = locals.get(id); }
+ case (ast.def_local(?id)) { ty = locals.get(id); }
+ case (_) {
+ // FIXME: handle other names.
+ e.sess.unimpl("definition variant for: "
+ + name.node.ident);
+ fail;
+ }
+ }
+ ret @fold.respan[ast.expr_](expr.span,
+ ast.expr_name(name, defopt,
+ ast.ann_type(ty)));
+ }
+
case (_) {
// TODO
ret expr;