Started adding support for floating-point type, floating-point literals, and logging of floats. Other operations on float probably don't work yet.

This commit is contained in:
Tim Chevalier 2011-03-21 17:12:05 -07:00 committed by Graydon Hoare
parent 35951c92db
commit caa22c9341
9 changed files with 87 additions and 18 deletions

View file

@ -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());
}
@ -4476,6 +4486,15 @@ 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);
@ -4483,6 +4502,12 @@ fn trans_log(@block_ctxt cx, @ast.expr e) -> result {
"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) {

View file

@ -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; }

View file

@ -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; }