Skip to content

Commit 0b63512

Browse files
lkupergraydon
authored andcommitted
Support for 'float' in type signatures.
1 parent 865a281 commit 0b63512

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ docsnap: doc/rust.pdf
528528
# Float doesn't work in boot
529529

530530
FLOAT_XFAILS := $(S)src/test/run-pass/float.rs \
531-
$(S)src/test/run-pass/float2.rs
531+
$(S)src/test/run-pass/float2.rs \
532+
$(S)src/test/run-pass/float-signature.rs
532533

533534
# Temporarily xfail tests broken by the nominal-tags change.
534535

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ self: $(CFG_RUSTC)
420420
# Float doesn't work in boot
421421

422422
FLOAT_XFAILS := test/run-pass/float.rs \
423-
test/run-pass/float2.rs
423+
test/run-pass/float2.rs \
424+
test/run-pass/float-signature.rs
424425

425426
# Temporarily xfail tests broken by the nominal-tags change.
426427

src/comp/front/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
349349
case (token.BOOL) { p.bump(); t = ast.ty_bool; }
350350
case (token.INT) { p.bump(); t = ast.ty_int; }
351351
case (token.UINT) { p.bump(); t = ast.ty_uint; }
352+
case (token.FLOAT) { p.bump(); t = ast.ty_float; }
352353
case (token.STR) { p.bump(); t = ast.ty_str; }
353354
case (token.CHAR) { p.bump(); t = ast.ty_char; }
354355
case (token.MACH(?tm)) { p.bump(); t = ast.ty_machine(tm); }

src/comp/middle/fold.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import std.map.hashmap;
2-
import std.option;
2+
import std.option;
33
import std.option.some;
44
import std.option.none;
55

@@ -44,6 +44,7 @@ type ast_fold[ENV] =
4444
(fn(&ENV e, &span sp) -> @ty) fold_ty_bool,
4545
(fn(&ENV e, &span sp) -> @ty) fold_ty_int,
4646
(fn(&ENV e, &span sp) -> @ty) fold_ty_uint,
47+
(fn(&ENV e, &span sp) -> @ty) fold_ty_float,
4748
(fn(&ENV e, &span sp, ty_mach tm) -> @ty) fold_ty_machine,
4849
(fn(&ENV e, &span sp) -> @ty) fold_ty_char,
4950
(fn(&ENV e, &span sp) -> @ty) fold_ty_str,
@@ -337,6 +338,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
337338
case (ast.ty_bool) { ret fld.fold_ty_bool(env_, t.span); }
338339
case (ast.ty_int) { ret fld.fold_ty_int(env_, t.span); }
339340
case (ast.ty_uint) { ret fld.fold_ty_uint(env_, t.span); }
341+
case (ast.ty_float) { ret fld.fold_ty_float(env_, t.span); }
340342

341343
case (ast.ty_machine(?m)) {
342344
ret fld.fold_ty_machine(env_, t.span, m);
@@ -1064,6 +1066,10 @@ fn identity_fold_ty_uint[ENV](&ENV env, &span sp) -> @ty {
10641066
ret @respan(sp, ast.ty_uint);
10651067
}
10661068

1069+
fn identity_fold_ty_float[ENV](&ENV env, &span sp) -> @ty {
1070+
ret @respan(sp, ast.ty_float);
1071+
}
1072+
10671073
fn identity_fold_ty_machine[ENV](&ENV env, &span sp,
10681074
ty_mach tm) -> @ty {
10691075
ret @respan(sp, ast.ty_machine(tm));
@@ -1515,6 +1521,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
15151521
fold_ty_bool = bind identity_fold_ty_bool[ENV](_,_),
15161522
fold_ty_int = bind identity_fold_ty_int[ENV](_,_),
15171523
fold_ty_uint = bind identity_fold_ty_uint[ENV](_,_),
1524+
fold_ty_float = bind identity_fold_ty_float[ENV](_,_),
15181525
fold_ty_machine = bind identity_fold_ty_machine[ENV](_,_,_),
15191526
fold_ty_char = bind identity_fold_ty_char[ENV](_,_),
15201527
fold_ty_str = bind identity_fold_ty_str[ENV](_,_),

src/comp/middle/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn sty_str(ty.sty st, def_str ds) -> str {
6161
case (ty.ty_bool) {ret "b";}
6262
case (ty.ty_int) {ret "i";}
6363
case (ty.ty_uint) {ret "u";}
64+
case (ty.ty_float) {ret "l";}
6465
case (ty.ty_machine(?mach)) {
6566
alt (mach) {
6667
case (common.ty_u8) {ret "Mb";}

src/comp/middle/typeck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
306306
case (ast.ty_bool) { sty = ty.ty_bool; }
307307
case (ast.ty_int) { sty = ty.ty_int; }
308308
case (ast.ty_uint) { sty = ty.ty_uint; }
309+
case (ast.ty_float) { sty = ty.ty_float; }
309310
case (ast.ty_machine(?tm)) { sty = ty.ty_machine(tm); }
310311
case (ast.ty_char) { sty = ty.ty_char; }
311312
case (ast.ty_str) { sty = ty.ty_str; }

src/test/run-pass/float-signature.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
fn foo(float n) -> float {
3+
ret n + 0.12345;
4+
}
5+
6+
let float n = 0.1;
7+
let float m = foo(n);
8+
9+
log m;
10+
}

0 commit comments

Comments
 (0)