aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLindsey Kuper <[email protected]>2011-03-23 14:52:22 -0700
committerGraydon Hoare <[email protected]>2011-03-23 16:01:29 -0700
commit0b63512f4cb0aca1579b110d9104eeed4918a6eb (patch)
treebf9014f6261f2b15db81eec7e1d34aa1d3de2cd3
parentbuild: Fix minor typo in "cp" output (diff)
downloadrust-0b63512f4cb0aca1579b110d9104eeed4918a6eb.tar.xz
rust-0b63512f4cb0aca1579b110d9104eeed4918a6eb.zip
Support for 'float' in type signatures.
-rw-r--r--Makefile.in3
-rw-r--r--src/Makefile3
-rw-r--r--src/comp/front/parser.rs1
-rw-r--r--src/comp/middle/fold.rs9
-rw-r--r--src/comp/middle/metadata.rs1
-rw-r--r--src/comp/middle/typeck.rs1
-rw-r--r--src/test/run-pass/float-signature.rs10
7 files changed, 25 insertions, 3 deletions
diff --git a/Makefile.in b/Makefile.in
index 14993f14..7c036fd6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -528,7 +528,8 @@ docsnap: doc/rust.pdf
# Float doesn't work in boot
FLOAT_XFAILS := $(S)src/test/run-pass/float.rs \
- $(S)src/test/run-pass/float2.rs
+ $(S)src/test/run-pass/float2.rs \
+ $(S)src/test/run-pass/float-signature.rs
# Temporarily xfail tests broken by the nominal-tags change.
diff --git a/src/Makefile b/src/Makefile
index 66c87e9a..5079548f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -420,7 +420,8 @@ self: $(CFG_RUSTC)
# Float doesn't work in boot
FLOAT_XFAILS := test/run-pass/float.rs \
- test/run-pass/float2.rs
+ test/run-pass/float2.rs \
+ test/run-pass/float-signature.rs
# Temporarily xfail tests broken by the nominal-tags change.
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 9e13e706..063bc0e1 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -349,6 +349,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
case (token.BOOL) { p.bump(); t = ast.ty_bool; }
case (token.INT) { p.bump(); t = ast.ty_int; }
case (token.UINT) { p.bump(); t = ast.ty_uint; }
+ case (token.FLOAT) { p.bump(); t = ast.ty_float; }
case (token.STR) { p.bump(); t = ast.ty_str; }
case (token.CHAR) { p.bump(); t = ast.ty_char; }
case (token.MACH(?tm)) { p.bump(); t = ast.ty_machine(tm); }
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index 5daa7f1d..a1b77612 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -1,5 +1,5 @@
import std.map.hashmap;
-import std.option;
+ import std.option;
import std.option.some;
import std.option.none;
@@ -44,6 +44,7 @@ type ast_fold[ENV] =
(fn(&ENV e, &span sp) -> @ty) fold_ty_bool,
(fn(&ENV e, &span sp) -> @ty) fold_ty_int,
(fn(&ENV e, &span sp) -> @ty) fold_ty_uint,
+ (fn(&ENV e, &span sp) -> @ty) fold_ty_float,
(fn(&ENV e, &span sp, ty_mach tm) -> @ty) fold_ty_machine,
(fn(&ENV e, &span sp) -> @ty) fold_ty_char,
(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 {
case (ast.ty_bool) { ret fld.fold_ty_bool(env_, t.span); }
case (ast.ty_int) { ret fld.fold_ty_int(env_, t.span); }
case (ast.ty_uint) { ret fld.fold_ty_uint(env_, t.span); }
+ case (ast.ty_float) { ret fld.fold_ty_float(env_, t.span); }
case (ast.ty_machine(?m)) {
ret fld.fold_ty_machine(env_, t.span, m);
@@ -1064,6 +1066,10 @@ fn identity_fold_ty_uint[ENV](&ENV env, &span sp) -> @ty {
ret @respan(sp, ast.ty_uint);
}
+fn identity_fold_ty_float[ENV](&ENV env, &span sp) -> @ty {
+ ret @respan(sp, ast.ty_float);
+}
+
fn identity_fold_ty_machine[ENV](&ENV env, &span sp,
ty_mach tm) -> @ty {
ret @respan(sp, ast.ty_machine(tm));
@@ -1515,6 +1521,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_ty_bool = bind identity_fold_ty_bool[ENV](_,_),
fold_ty_int = bind identity_fold_ty_int[ENV](_,_),
fold_ty_uint = bind identity_fold_ty_uint[ENV](_,_),
+ fold_ty_float = bind identity_fold_ty_float[ENV](_,_),
fold_ty_machine = bind identity_fold_ty_machine[ENV](_,_,_),
fold_ty_char = bind identity_fold_ty_char[ENV](_,_),
fold_ty_str = bind identity_fold_ty_str[ENV](_,_),
diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs
index ce33658f..e384092b 100644
--- a/src/comp/middle/metadata.rs
+++ b/src/comp/middle/metadata.rs
@@ -61,6 +61,7 @@ fn sty_str(ty.sty st, def_str ds) -> str {
case (ty.ty_bool) {ret "b";}
case (ty.ty_int) {ret "i";}
case (ty.ty_uint) {ret "u";}
+ case (ty.ty_float) {ret "l";}
case (ty.ty_machine(?mach)) {
alt (mach) {
case (common.ty_u8) {ret "Mb";}
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 4175af6a..a52b39e2 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -306,6 +306,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
case (ast.ty_bool) { sty = ty.ty_bool; }
case (ast.ty_int) { sty = ty.ty_int; }
case (ast.ty_uint) { sty = ty.ty_uint; }
+ case (ast.ty_float) { sty = ty.ty_float; }
case (ast.ty_machine(?tm)) { sty = ty.ty_machine(tm); }
case (ast.ty_char) { sty = ty.ty_char; }
case (ast.ty_str) { sty = ty.ty_str; }
diff --git a/src/test/run-pass/float-signature.rs b/src/test/run-pass/float-signature.rs
new file mode 100644
index 00000000..da18390d
--- /dev/null
+++ b/src/test/run-pass/float-signature.rs
@@ -0,0 +1,10 @@
+fn main() {
+ fn foo(float n) -> float {
+ ret n + 0.12345;
+ }
+
+ let float n = 0.1;
+ let float m = foo(n);
+
+ log m;
+}