Change literal representation to not truncate
Also shuffles around the organization of numeric literals and types, separating by int/uint/float instead of machine-vs-non-machine types. This simplifies some code. Closes #974 Closes #1252
This commit is contained in:
parent
6daa233a73
commit
e3eca9174b
@ -2,7 +2,7 @@
|
||||
import syntax::{ast, codemap};
|
||||
import syntax::ast::node_id;
|
||||
import codemap::span;
|
||||
import syntax::ast::ty_mach;
|
||||
import syntax::ast::{int_ty, uint_ty, float_ty};
|
||||
import std::{option};
|
||||
import std::option::{some, none};
|
||||
import syntax::parse::parser::parse_sess;
|
||||
@ -17,9 +17,9 @@ type config =
|
||||
{os: os,
|
||||
arch: arch,
|
||||
target_strs: target_strs::t,
|
||||
int_type: ty_mach,
|
||||
uint_type: ty_mach,
|
||||
float_type: ty_mach};
|
||||
int_type: int_ty,
|
||||
uint_type: uint_ty,
|
||||
float_type: float_ty};
|
||||
|
||||
type options =
|
||||
// The crate config requested for the session, which may be combined
|
||||
|
@ -174,16 +174,16 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
|
||||
'l' { ret ty::mk_float(st.tcx); }
|
||||
'M' {
|
||||
alt next(st) as char {
|
||||
'b' { ret ty::mk_mach(st.tcx, ast::ty_u8); }
|
||||
'w' { ret ty::mk_mach(st.tcx, ast::ty_u16); }
|
||||
'l' { ret ty::mk_mach(st.tcx, ast::ty_u32); }
|
||||
'd' { ret ty::mk_mach(st.tcx, ast::ty_u64); }
|
||||
'B' { ret ty::mk_mach(st.tcx, ast::ty_i8); }
|
||||
'W' { ret ty::mk_mach(st.tcx, ast::ty_i16); }
|
||||
'L' { ret ty::mk_mach(st.tcx, ast::ty_i32); }
|
||||
'D' { ret ty::mk_mach(st.tcx, ast::ty_i64); }
|
||||
'f' { ret ty::mk_mach(st.tcx, ast::ty_f32); }
|
||||
'F' { ret ty::mk_mach(st.tcx, ast::ty_f64); }
|
||||
'b' { ret ty::mk_mach_uint(st.tcx, ast::ty_u8); }
|
||||
'w' { ret ty::mk_mach_uint(st.tcx, ast::ty_u16); }
|
||||
'l' { ret ty::mk_mach_uint(st.tcx, ast::ty_u32); }
|
||||
'd' { ret ty::mk_mach_uint(st.tcx, ast::ty_u64); }
|
||||
'B' { ret ty::mk_mach_int(st.tcx, ast::ty_i8); }
|
||||
'W' { ret ty::mk_mach_int(st.tcx, ast::ty_i16); }
|
||||
'L' { ret ty::mk_mach_int(st.tcx, ast::ty_i32); }
|
||||
'D' { ret ty::mk_mach_int(st.tcx, ast::ty_i64); }
|
||||
'f' { ret ty::mk_mach_float(st.tcx, ast::ty_f32); }
|
||||
'F' { ret ty::mk_mach_float(st.tcx, ast::ty_f64); }
|
||||
}
|
||||
}
|
||||
'c' { ret ty::mk_char(st.tcx); }
|
||||
|
@ -90,24 +90,32 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
|
||||
ty::ty_nil. { w.write_char('n'); }
|
||||
ty::ty_bot. { w.write_char('z'); }
|
||||
ty::ty_bool. { w.write_char('b'); }
|
||||
ty::ty_int. { w.write_char('i'); }
|
||||
ty::ty_uint. { w.write_char('u'); }
|
||||
ty::ty_float. { w.write_char('l'); }
|
||||
ty::ty_machine(mach) {
|
||||
alt mach {
|
||||
ty_u8. { w.write_str("Mb"); }
|
||||
ty_u16. { w.write_str("Mw"); }
|
||||
ty_u32. { w.write_str("Ml"); }
|
||||
ty_u64. { w.write_str("Md"); }
|
||||
ty::ty_int(t) {
|
||||
alt t {
|
||||
ty_i. { w.write_char('i'); }
|
||||
ty_char. { w.write_char('c'); }
|
||||
ty_i8. { w.write_str("MB"); }
|
||||
ty_i16. { w.write_str("MW"); }
|
||||
ty_i32. { w.write_str("ML"); }
|
||||
ty_i64. { w.write_str("MD"); }
|
||||
}
|
||||
}
|
||||
ty::ty_uint(t) {
|
||||
alt t {
|
||||
ty_u. { w.write_char('u'); }
|
||||
ty_u8. { w.write_str("Mb"); }
|
||||
ty_u16. { w.write_str("Mw"); }
|
||||
ty_u32. { w.write_str("Ml"); }
|
||||
ty_u64. { w.write_str("Md"); }
|
||||
}
|
||||
}
|
||||
ty::ty_float(t) {
|
||||
alt t {
|
||||
ty_f. { w.write_char('l'); }
|
||||
ty_f32. { w.write_str("Mf"); }
|
||||
ty_f64. { w.write_str("MF"); }
|
||||
}
|
||||
}
|
||||
ty::ty_char. { w.write_char('c'); }
|
||||
ty::ty_str. { w.write_char('S'); }
|
||||
ty::ty_tag(def, tys) {
|
||||
w.write_str("t[");
|
||||
|
@ -553,9 +553,8 @@ fn local_id_of_node(cx: ctx, id: node_id) -> uint {
|
||||
fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
|
||||
fn score_ty(tcx: ty::ctxt, ty: ty::t) -> uint {
|
||||
ret alt ty::struct(tcx, ty) {
|
||||
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. |
|
||||
ty::ty_uint. | ty::ty_float. | ty::ty_machine(_) |
|
||||
ty::ty_char. | ty::ty_type. | ty::ty_native(_) |
|
||||
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int(_) |
|
||||
ty::ty_uint(_) | ty::ty_float(_) | ty::ty_type. | ty::ty_native(_) |
|
||||
ty::ty_ptr(_) { 1u }
|
||||
ty::ty_box(_) { 3u }
|
||||
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }
|
||||
|
@ -102,8 +102,8 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
|
||||
|
||||
fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
|
||||
alt ty::struct(cx, ty) {
|
||||
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. | ty::ty_float. |
|
||||
ty::ty_uint. | ty::ty_machine(_) | ty::ty_char. | ty::ty_str. |
|
||||
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int(_) |
|
||||
ty::ty_float(_) | ty::ty_uint(_) | ty::ty_str. |
|
||||
ty::ty_type. | ty::ty_native(_) | ty::ty_ptr(_) | ty::ty_type. |
|
||||
ty::ty_native(_) {
|
||||
ret false;
|
||||
|
@ -299,54 +299,27 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
|
||||
let s = [];
|
||||
|
||||
alt ty::struct(ccx.tcx, t) {
|
||||
ty::ty_nil. | ty::ty_bool. | ty::ty_machine(ast::ty_u8.) | ty::ty_bot. {
|
||||
s += [shape_u8];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_int. {
|
||||
s += [s_int(ccx.tcx)];
|
||||
}
|
||||
ty::ty_float. { s += [s_float(ccx.tcx)]; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_uint. | ty::ty_ptr(_) | ty::ty_type. | ty::ty_native(_) {
|
||||
s += [s_uint(ccx.tcx)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_machine(ast::ty_i8.) {
|
||||
s += [shape_i8];
|
||||
}
|
||||
ty::ty_machine(ast::ty_u16.) { s += [shape_u16]; }
|
||||
ty::ty_machine(ast::ty_i16.) { s += [shape_i16]; }
|
||||
ty::ty_machine(ast::ty_u32.) | ty::ty_char. { s += [shape_u32]; }
|
||||
ty::ty_machine(ast::ty_i32.) { s += [shape_i32]; }
|
||||
ty::ty_machine(ast::ty_u64.) { s += [shape_u64]; }
|
||||
ty::ty_machine(ast::ty_i64.) { s += [shape_i64]; }
|
||||
|
||||
ty::ty_machine(ast::ty_f32.) { s += [shape_f32]; }
|
||||
ty::ty_machine(ast::ty_f64.) { s += [shape_f64]; }
|
||||
|
||||
ty::ty_nil. | ty::ty_bool. | ty::ty_uint(ast::ty_u8.) |
|
||||
ty::ty_bot. { s += [shape_u8]; }
|
||||
ty::ty_int(ast::ty_i.) { s += [s_int(ccx.tcx)]; }
|
||||
ty::ty_float(ast::ty_f.) { s += [s_float(ccx.tcx)]; }
|
||||
ty::ty_uint(ast::ty_u.) | ty::ty_ptr(_) | ty::ty_type. |
|
||||
ty::ty_native(_) { s += [s_uint(ccx.tcx)]; }
|
||||
ty::ty_int(ast::ty_i8.) { s += [shape_i8]; }
|
||||
ty::ty_uint(ast::ty_u16.) { s += [shape_u16]; }
|
||||
ty::ty_int(ast::ty_i16.) { s += [shape_i16]; }
|
||||
ty::ty_uint(ast::ty_u32.) { s += [shape_u32]; }
|
||||
ty::ty_int(ast::ty_i32.) | ty::ty_int(ast::ty_char.) {s += [shape_i32];}
|
||||
ty::ty_uint(ast::ty_u64.) { s += [shape_u64]; }
|
||||
ty::ty_int(ast::ty_i64.) { s += [shape_i64]; }
|
||||
ty::ty_float(ast::ty_f32.) { s += [shape_f32]; }
|
||||
ty::ty_float(ast::ty_f64.) { s += [shape_f64]; }
|
||||
ty::ty_str. {
|
||||
s += [shape_vec];
|
||||
add_bool(s, true); // type is POD
|
||||
let unit_ty = ty::mk_mach(ccx.tcx, ast::ty_u8);
|
||||
let unit_ty = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
|
||||
add_substr(s, shape_of(ccx, unit_ty, ty_param_map, is_obj_body));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_tag(did, tps) {
|
||||
alt tag_kind(ccx, did) {
|
||||
tk_unit. {
|
||||
@ -382,11 +355,6 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_box(mt) {
|
||||
s += [shape_box];
|
||||
add_substr(s, shape_of(ccx, mt.ty, ty_param_map, is_obj_body));
|
||||
@ -416,21 +384,11 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
|
||||
}
|
||||
add_substr(s, sub);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_fn(_, _, _, _, _) {
|
||||
s += [shape_fn];
|
||||
}
|
||||
ty::ty_native_fn(_, _) { s += [shape_u32]; }
|
||||
ty::ty_obj(_) { s += [shape_obj]; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_res(did, raw_subt, tps) {
|
||||
let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
|
||||
let ri = {did: did, t: subt};
|
||||
@ -445,17 +403,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
|
||||
add_substr(s, shape_of(ccx, subt, ty_param_map, is_obj_body));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_var(n) {
|
||||
fail "shape_of ty_var";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ty::ty_param(n, _) {
|
||||
if is_obj_body {
|
||||
// Just write in the parameter number.
|
||||
|
@ -130,20 +130,9 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
|
||||
T_nil() /* ...I guess? */
|
||||
}
|
||||
ty::ty_bool. { T_bool() }
|
||||
ty::ty_int. { cx.int_type }
|
||||
ty::ty_float. { cx.float_type }
|
||||
ty::ty_uint. { cx.int_type }
|
||||
ty::ty_machine(tm) {
|
||||
alt tm {
|
||||
ast::ty_i8. | ast::ty_u8. { T_i8() }
|
||||
ast::ty_i16. | ast::ty_u16. { T_i16() }
|
||||
ast::ty_i32. | ast::ty_u32. { T_i32() }
|
||||
ast::ty_i64. | ast::ty_u64. { T_i64() }
|
||||
ast::ty_f32. { T_f32() }
|
||||
ast::ty_f64. { T_f64() }
|
||||
}
|
||||
}
|
||||
ty::ty_char. { T_char() }
|
||||
ty::ty_int(t) { T_int_ty(cx, t) }
|
||||
ty::ty_uint(t) { T_uint_ty(cx, t) }
|
||||
ty::ty_float(t) { T_float_ty(cx, t) }
|
||||
ty::ty_str. { T_ptr(T_vec(cx, T_i8())) }
|
||||
ty::ty_tag(did, _) { type_of_tag(cx, sp, did, t) }
|
||||
ty::ty_box(mt) {
|
||||
@ -1516,23 +1505,10 @@ fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
|
||||
|
||||
alt ty::struct(bcx_tcx(cx), t) {
|
||||
ty::ty_nil. { ret rslt(cx, f(nil_type)); }
|
||||
ty::ty_bool. | ty::ty_uint. | ty::ty_ptr(_) | ty::ty_char. {
|
||||
ret rslt(cx, f(unsigned_int));
|
||||
}
|
||||
ty::ty_int. { ret rslt(cx, f(signed_int)); }
|
||||
ty::ty_float. { ret rslt(cx, f(floating_point)); }
|
||||
ty::ty_machine(_) {
|
||||
if ty::type_is_fp(bcx_tcx(cx), t) {
|
||||
// Floating point machine types
|
||||
ret rslt(cx, f(floating_point));
|
||||
} else if ty::type_is_signed(bcx_tcx(cx), t) {
|
||||
// Signed, integral machine types
|
||||
ret rslt(cx, f(signed_int));
|
||||
} else {
|
||||
// Unsigned, integral machine types
|
||||
ret rslt(cx, f(unsigned_int));
|
||||
}
|
||||
}
|
||||
ty::ty_bool. | ty::ty_ptr(_) { ret rslt(cx, f(unsigned_int)); }
|
||||
ty::ty_int(_) { ret rslt(cx, f(signed_int)); }
|
||||
ty::ty_uint(_) { ret rslt(cx, f(unsigned_int)); }
|
||||
ty::ty_float(_) { ret rslt(cx, f(floating_point)); }
|
||||
ty::ty_type. {
|
||||
ret rslt(trans_fail(cx, none,
|
||||
"attempt to compare values of type type"),
|
||||
@ -2120,36 +2096,11 @@ fn store_temp_expr(cx: @block_ctxt, action: copy_action, dst: ValueRef,
|
||||
|
||||
fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
|
||||
alt lit.node {
|
||||
ast::lit_int(i) { ret C_int(cx, i); }
|
||||
ast::lit_uint(u) { ret C_uint(cx, u); }
|
||||
ast::lit_mach_int(tm, i) {
|
||||
// FIXME: the entire handling of mach types falls apart
|
||||
// if target int width is larger than host, at the moment;
|
||||
// re-do the mach-int types using 'big' when that works.
|
||||
|
||||
let t = cx.int_type;
|
||||
let s = True;
|
||||
alt tm {
|
||||
ast::ty_u8. { t = T_i8(); s = False; }
|
||||
ast::ty_u16. { t = T_i16(); s = False; }
|
||||
ast::ty_u32. { t = T_i32(); s = False; }
|
||||
ast::ty_u64. { t = T_i64(); s = False; }
|
||||
ast::ty_i8. { t = T_i8(); }
|
||||
ast::ty_i16. { t = T_i16(); }
|
||||
ast::ty_i32. { t = T_i32(); }
|
||||
ast::ty_i64. { t = T_i64(); }
|
||||
}
|
||||
ret C_integral(t, i as u64, s);
|
||||
}
|
||||
ast::lit_float(fs) { ret C_float(cx, fs); }
|
||||
ast::lit_mach_float(tm, s) {
|
||||
let t = cx.float_type;
|
||||
alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } }
|
||||
ret C_floating(s, t);
|
||||
}
|
||||
ast::lit_char(c) { ret C_integral(T_char(), c as u64, False); }
|
||||
ast::lit_bool(b) { ret C_bool(b); }
|
||||
ast::lit_nil. { ret C_nil(); }
|
||||
ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) }
|
||||
ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) }
|
||||
ast::lit_float(fs, t) { C_floating(fs, T_float_ty(cx, t)) }
|
||||
ast::lit_bool(b) { C_bool(b) }
|
||||
ast::lit_nil. { C_nil() }
|
||||
ast::lit_str(s) {
|
||||
cx.sess.span_unimpl(lit.span, "unique string in this context");
|
||||
}
|
||||
@ -4359,7 +4310,7 @@ fn trans_fail_expr(bcx: @block_ctxt, sp_opt: option::t<span>,
|
||||
if ty::type_is_str(tcx, e_ty) {
|
||||
let data = tvec::get_dataptr(
|
||||
bcx, expr_res.val, type_of_or_i8(
|
||||
bcx, ty::mk_mach(tcx, ast::ty_u8)));
|
||||
bcx, ty::mk_mach_uint(tcx, ast::ty_u8)));
|
||||
ret trans_fail_value(bcx, sp_opt, data);
|
||||
} else if bcx.unreachable {
|
||||
ret bcx;
|
||||
|
@ -485,6 +485,35 @@ fn T_int(targ_cfg: @session::config) -> TypeRef {
|
||||
};
|
||||
}
|
||||
|
||||
fn T_int_ty(cx: @crate_ctxt, t: ast::int_ty) -> TypeRef {
|
||||
alt t {
|
||||
ast::ty_i. { cx.int_type }
|
||||
ast::ty_char. { T_char() }
|
||||
ast::ty_i8. { T_i8() }
|
||||
ast::ty_i16. { T_i16() }
|
||||
ast::ty_i32. { T_i32() }
|
||||
ast::ty_i64. { T_i64() }
|
||||
}
|
||||
}
|
||||
|
||||
fn T_uint_ty(cx: @crate_ctxt, t: ast::uint_ty) -> TypeRef {
|
||||
alt t {
|
||||
ast::ty_u. { cx.int_type }
|
||||
ast::ty_u8. { T_i8() }
|
||||
ast::ty_u16. { T_i16() }
|
||||
ast::ty_u32. { T_i32() }
|
||||
ast::ty_u64. { T_i64() }
|
||||
}
|
||||
}
|
||||
|
||||
fn T_float_ty(cx: @crate_ctxt, t: ast::float_ty) -> TypeRef {
|
||||
alt t {
|
||||
ast::ty_f. { cx.float_type }
|
||||
ast::ty_f32. { T_f32() }
|
||||
ast::ty_f64. { T_f64() }
|
||||
}
|
||||
}
|
||||
|
||||
fn T_float(targ_cfg: @session::config) -> TypeRef {
|
||||
ret alt targ_cfg.arch {
|
||||
session::arch_x86. { T_f64() }
|
||||
@ -734,12 +763,6 @@ fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef {
|
||||
ret llvm::LLVMRustConstInt(t, u_hi, u_lo, sign_extend);
|
||||
}
|
||||
|
||||
fn C_float(cx: @crate_ctxt, s: str) -> ValueRef {
|
||||
ret str::as_buf(s, {|buf|
|
||||
llvm::LLVMConstRealOfString(cx.float_type, buf)
|
||||
});
|
||||
}
|
||||
|
||||
fn C_floating(s: str, t: TypeRef) -> ValueRef {
|
||||
ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
|
||||
}
|
||||
|
@ -71,7 +71,9 @@ export mk_mut_ptr;
|
||||
export mk_int;
|
||||
export mk_str;
|
||||
export mk_vec;
|
||||
export mk_mach;
|
||||
export mk_mach_int;
|
||||
export mk_mach_uint;
|
||||
export mk_mach_float;
|
||||
export mk_native;
|
||||
export mk_native_fn;
|
||||
export mk_nil;
|
||||
@ -111,7 +113,6 @@ export ty_native_fn;
|
||||
export ty_bool;
|
||||
export ty_bot;
|
||||
export ty_box;
|
||||
export ty_char;
|
||||
export ty_constr;
|
||||
export ty_constr_arg;
|
||||
export ty_float;
|
||||
@ -122,7 +123,6 @@ export ty_fn_ret_style;
|
||||
export ty_int;
|
||||
export ty_str;
|
||||
export ty_vec;
|
||||
export ty_machine;
|
||||
export ty_native;
|
||||
export ty_nil;
|
||||
export ty_obj;
|
||||
@ -249,18 +249,15 @@ type raw_t =
|
||||
|
||||
type t = uint;
|
||||
|
||||
|
||||
// NB: If you change this, you'll probably want to change the corresponding
|
||||
// AST structure in front/ast::rs as well.
|
||||
tag sty {
|
||||
ty_nil;
|
||||
ty_bot;
|
||||
ty_bool;
|
||||
ty_int;
|
||||
ty_float;
|
||||
ty_uint;
|
||||
ty_machine(ast::ty_mach);
|
||||
ty_char;
|
||||
ty_int(ast::int_ty);
|
||||
ty_uint(ast::uint_ty);
|
||||
ty_float(ast::float_ty);
|
||||
ty_str;
|
||||
ty_tag(def_id, [t]);
|
||||
ty_box(mt);
|
||||
@ -361,20 +358,20 @@ type node_type_table =
|
||||
fn populate_type_store(cx: ctxt) {
|
||||
intern(cx, ty_nil, none);
|
||||
intern(cx, ty_bool, none);
|
||||
intern(cx, ty_int, none);
|
||||
intern(cx, ty_float, none);
|
||||
intern(cx, ty_uint, none);
|
||||
intern(cx, ty_machine(ast::ty_i8), none);
|
||||
intern(cx, ty_machine(ast::ty_i16), none);
|
||||
intern(cx, ty_machine(ast::ty_i32), none);
|
||||
intern(cx, ty_machine(ast::ty_i64), none);
|
||||
intern(cx, ty_machine(ast::ty_u8), none);
|
||||
intern(cx, ty_machine(ast::ty_u16), none);
|
||||
intern(cx, ty_machine(ast::ty_u32), none);
|
||||
intern(cx, ty_machine(ast::ty_u64), none);
|
||||
intern(cx, ty_machine(ast::ty_f32), none);
|
||||
intern(cx, ty_machine(ast::ty_f64), none);
|
||||
intern(cx, ty_char, none);
|
||||
intern(cx, ty_int(ast::ty_i), none);
|
||||
intern(cx, ty_float(ast::ty_f), none);
|
||||
intern(cx, ty_uint(ast::ty_u), none);
|
||||
intern(cx, ty_int(ast::ty_i8), none);
|
||||
intern(cx, ty_int(ast::ty_i16), none);
|
||||
intern(cx, ty_int(ast::ty_i32), none);
|
||||
intern(cx, ty_int(ast::ty_i64), none);
|
||||
intern(cx, ty_uint(ast::ty_u8), none);
|
||||
intern(cx, ty_uint(ast::ty_u16), none);
|
||||
intern(cx, ty_uint(ast::ty_u32), none);
|
||||
intern(cx, ty_uint(ast::ty_u64), none);
|
||||
intern(cx, ty_float(ast::ty_f32), none);
|
||||
intern(cx, ty_float(ast::ty_f64), none);
|
||||
intern(cx, ty_int(ast::ty_char), none);
|
||||
intern(cx, ty_str, none);
|
||||
intern(cx, ty_type, none);
|
||||
intern(cx, ty_bot, none);
|
||||
@ -445,17 +442,8 @@ fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t<str>) -> @raw_t {
|
||||
derive_flags_t(cx, has_params, has_vars, tt);
|
||||
}
|
||||
alt st {
|
||||
ty_nil. {/* no-op */ }
|
||||
ty_bot. {/* no-op */ }
|
||||
ty_bool. {/* no-op */ }
|
||||
ty_int. {/* no-op */ }
|
||||
ty_float. {/* no-op */ }
|
||||
ty_uint. {/* no-op */ }
|
||||
ty_machine(_) {/* no-op */ }
|
||||
ty_char. {/* no-op */ }
|
||||
ty_str. {/* no-op */ }
|
||||
ty_type. {/* no-op */ }
|
||||
ty_native(_) {/* no-op */ }
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_float(_) | ty_uint(_) |
|
||||
ty_str. | ty_type. | ty_native(_) {/* no-op */ }
|
||||
ty_param(_, _) { has_params = true; }
|
||||
ty_var(_) { has_vars = true; }
|
||||
ty_tag(_, tys) {
|
||||
@ -523,21 +511,36 @@ fn mk_float(_cx: ctxt) -> t { ret idx_float; }
|
||||
|
||||
fn mk_uint(_cx: ctxt) -> t { ret idx_uint; }
|
||||
|
||||
fn mk_mach(_cx: ctxt, tm: ast::ty_mach) -> t {
|
||||
fn mk_mach_int(_cx: ctxt, tm: ast::int_ty) -> t {
|
||||
alt tm {
|
||||
ast::ty_u8. { ret idx_u8; }
|
||||
ast::ty_u16. { ret idx_u16; }
|
||||
ast::ty_u32. { ret idx_u32; }
|
||||
ast::ty_u64. { ret idx_u64; }
|
||||
ast::ty_i. { ret idx_int; }
|
||||
ast::ty_char. { ret idx_char; }
|
||||
ast::ty_i8. { ret idx_i8; }
|
||||
ast::ty_i16. { ret idx_i16; }
|
||||
ast::ty_i32. { ret idx_i32; }
|
||||
ast::ty_i64. { ret idx_i64; }
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_mach_uint(_cx: ctxt, tm: ast::uint_ty) -> t {
|
||||
alt tm {
|
||||
ast::ty_u. { ret idx_uint; }
|
||||
ast::ty_u8. { ret idx_u8; }
|
||||
ast::ty_u16. { ret idx_u16; }
|
||||
ast::ty_u32. { ret idx_u32; }
|
||||
ast::ty_u64. { ret idx_u64; }
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_mach_float(_cx: ctxt, tm: ast::float_ty) -> t {
|
||||
alt tm {
|
||||
ast::ty_f. { ret idx_float; }
|
||||
ast::ty_f32. { ret idx_f32; }
|
||||
ast::ty_f64. { ret idx_f64; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn mk_char(_cx: ctxt) -> t { ret idx_char; }
|
||||
|
||||
fn mk_str(_cx: ctxt) -> t { ret idx_str; }
|
||||
@ -614,20 +617,9 @@ type ty_walk = fn@(t);
|
||||
|
||||
fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
|
||||
alt struct(cx, ty) {
|
||||
ty_nil. {/* no-op */ }
|
||||
ty_bot. {/* no-op */ }
|
||||
ty_bool. {/* no-op */ }
|
||||
ty_int. {/* no-op */ }
|
||||
ty_uint. {/* no-op */ }
|
||||
ty_float. {/* no-op */ }
|
||||
ty_machine(_) {/* no-op */ }
|
||||
ty_char. {/* no-op */ }
|
||||
ty_str. {/* no-op */ }
|
||||
ty_type. {/* no-op */ }
|
||||
ty_native(_) {/* no-op */ }
|
||||
ty_box(tm) { walk_ty(cx, walker, tm.ty); }
|
||||
ty_vec(tm) { walk_ty(cx, walker, tm.ty); }
|
||||
ty_ptr(tm) { walk_ty(cx, walker, tm.ty); }
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty_str. | ty_type. | ty_native(_) {/* no-op */ }
|
||||
ty_box(tm) | ty_vec(tm) | ty_ptr(tm) { walk_ty(cx, walker, tm.ty); }
|
||||
ty_tag(tid, subtys) {
|
||||
for subty: t in subtys { walk_ty(cx, walker, subty); }
|
||||
}
|
||||
@ -677,17 +669,8 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
|
||||
fm_general(_) {/* no fast path */ }
|
||||
}
|
||||
alt struct(cx, ty) {
|
||||
ty_nil. {/* no-op */ }
|
||||
ty_bot. {/* no-op */ }
|
||||
ty_bool. {/* no-op */ }
|
||||
ty_int. {/* no-op */ }
|
||||
ty_uint. {/* no-op */ }
|
||||
ty_float. {/* no-op */ }
|
||||
ty_machine(_) {/* no-op */ }
|
||||
ty_char. {/* no-op */ }
|
||||
ty_str. {/* no-op */ }
|
||||
ty_type. {/* no-op */ }
|
||||
ty_native(_) {/* no-op */ }
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty_str. | ty_type. | ty_native(_) {/* no-op */ }
|
||||
ty_box(tm) {
|
||||
ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
|
||||
}
|
||||
@ -725,10 +708,8 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
|
||||
let new_ty = fold_ty(cx, fld, a.ty);
|
||||
new_args += [{mode: a.mode, ty: new_ty}];
|
||||
}
|
||||
ty =
|
||||
copy_cname(cx,
|
||||
mk_fn(cx, proto, new_args, fold_ty(cx, fld, ret_ty),
|
||||
cf, constrs), ty);
|
||||
ty = copy_cname(cx, mk_fn(cx, proto, new_args,
|
||||
fold_ty(cx, fld, ret_ty), cf, constrs), ty);
|
||||
}
|
||||
ty_native_fn(args, ret_ty) {
|
||||
let new_args: [arg] = [];
|
||||
@ -736,10 +717,8 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
|
||||
let new_ty = fold_ty(cx, fld, a.ty);
|
||||
new_args += [{mode: a.mode, ty: new_ty}];
|
||||
}
|
||||
ty =
|
||||
copy_cname(cx,
|
||||
mk_native_fn(cx, new_args,
|
||||
fold_ty(cx, fld, ret_ty)), ty);
|
||||
ty = copy_cname(cx, mk_native_fn(cx, new_args,
|
||||
fold_ty(cx, fld, ret_ty)), ty);
|
||||
}
|
||||
ty_obj(methods) {
|
||||
let new_methods: [method] = [];
|
||||
@ -773,7 +752,6 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If this is a general type fold, then we need to run it now.
|
||||
alt fld { fm_general(folder) { ret folder(ty); } _ { ret ty; } }
|
||||
}
|
||||
@ -842,7 +820,7 @@ fn type_is_str(cx: ctxt, ty: t) -> bool {
|
||||
|
||||
fn sequence_element_type(cx: ctxt, ty: t) -> t {
|
||||
alt struct(cx, ty) {
|
||||
ty_str. { ret mk_mach(cx, ast::ty_u8); }
|
||||
ty_str. { ret mk_mach_uint(cx, ast::ty_u8); }
|
||||
ty_vec(mt) { ret mt.ty; }
|
||||
_ { cx.sess.bug("sequence_element_type called on non-sequence value"); }
|
||||
}
|
||||
@ -917,17 +895,9 @@ pure fn type_is_unique(cx: ctxt, ty: t) -> bool {
|
||||
|
||||
pure fn type_is_scalar(cx: ctxt, ty: t) -> bool {
|
||||
alt struct(cx, ty) {
|
||||
ty_nil. { ret true; }
|
||||
ty_bool. { ret true; }
|
||||
ty_int. { ret true; }
|
||||
ty_float. { ret true; }
|
||||
ty_uint. { ret true; }
|
||||
ty_machine(_) { ret true; }
|
||||
ty_char. { ret true; }
|
||||
ty_type. { ret true; }
|
||||
ty_native(_) { ret true; }
|
||||
ty_ptr(_) { ret true; }
|
||||
_ { ret false; }
|
||||
ty_nil. | ty_bool. | ty_int(_) | ty_float(_) | ty_uint(_) |
|
||||
ty_type. | ty_native(_) | ty_ptr(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
@ -946,8 +916,8 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
|
||||
let accum = false;
|
||||
let result = alt struct(cx, ty) {
|
||||
// scalar types
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_float. | ty_uint. |
|
||||
ty_machine(_) | ty_char. | ty_type. | ty_native(_) | ty_ptr(_) { false }
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_float(_) | ty_uint(_) |
|
||||
ty_type. | ty_native(_) | ty_ptr(_) { false }
|
||||
ty_rec(flds) {
|
||||
for f in flds { if type_needs_drop(cx, f.mt.ty) { accum = true; } }
|
||||
accum
|
||||
@ -998,8 +968,8 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
|
||||
|
||||
let result = alt struct(cx, ty) {
|
||||
// Scalar and unique types are sendable
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_uint. | ty_float. |
|
||||
ty_machine(_) | ty_char. | ty_native(_) | ty_ptr(_) |
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty_native(_) | ty_ptr(_) |
|
||||
ty_type. | ty_str. | ty_native_fn(_, _) { ast::kind_sendable }
|
||||
// FIXME: obj is broken for now, since we aren't asserting
|
||||
// anything about its fields.
|
||||
@ -1151,38 +1121,15 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
|
||||
|
||||
fn type_is_integral(cx: ctxt, ty: t) -> bool {
|
||||
alt struct(cx, ty) {
|
||||
ty_int. { ret true; }
|
||||
ty_uint. { ret true; }
|
||||
ty_machine(m) {
|
||||
alt m {
|
||||
ast::ty_i8. { ret true; }
|
||||
ast::ty_i16. { ret true; }
|
||||
ast::ty_i32. { ret true; }
|
||||
ast::ty_i64. { ret true; }
|
||||
ast::ty_u8. { ret true; }
|
||||
ast::ty_u16. { ret true; }
|
||||
ast::ty_u32. { ret true; }
|
||||
ast::ty_u64. { ret true; }
|
||||
_ { ret false; }
|
||||
}
|
||||
}
|
||||
ty_char. { ret true; }
|
||||
ty_bool. { ret true; }
|
||||
_ { ret false; }
|
||||
ty_int(_) | ty_uint(_) | ty_bool. { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
fn type_is_fp(cx: ctxt, ty: t) -> bool {
|
||||
alt struct(cx, ty) {
|
||||
ty_machine(tm) {
|
||||
alt tm {
|
||||
ast::ty_f32. { ret true; }
|
||||
ast::ty_f64. { ret true; }
|
||||
_ { ret false; }
|
||||
}
|
||||
}
|
||||
ty_float. { ret true; }
|
||||
_ { ret false; }
|
||||
ty_float(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1192,17 +1139,8 @@ fn type_is_numeric(cx: ctxt, ty: t) -> bool {
|
||||
|
||||
fn type_is_signed(cx: ctxt, ty: t) -> bool {
|
||||
alt struct(cx, ty) {
|
||||
ty_int. { ret true; }
|
||||
ty_machine(tm) {
|
||||
alt tm {
|
||||
ast::ty_i8. { ret true; }
|
||||
ast::ty_i16. { ret true; }
|
||||
ast::ty_i32. { ret true; }
|
||||
ast::ty_i64. { ret true; }
|
||||
_ { ret false; }
|
||||
}
|
||||
}
|
||||
_ { ret false; }
|
||||
ty_int(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1211,10 +1149,8 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
|
||||
let result = true;
|
||||
alt struct(cx, ty) {
|
||||
// Scalar types
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_float. | ty_uint. |
|
||||
ty_machine(_) | ty_char. | ty_type. | ty_native(_) | ty_ptr(_) {
|
||||
result = true;
|
||||
}
|
||||
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_float(_) | ty_uint(_) |
|
||||
ty_type. | ty_native(_) | ty_ptr(_) { result = true; }
|
||||
// Boxed types
|
||||
ty_str. | ty_box(_) | ty_uniq(_) | ty_vec(_) | ty_fn(_, _, _, _, _) |
|
||||
ty_native_fn(_, _) | ty_obj(_) {
|
||||
@ -1343,26 +1279,22 @@ fn hash_type_structure(st: sty) -> uint {
|
||||
ret h;
|
||||
}
|
||||
alt st {
|
||||
ty_nil. { ret 0u; }
|
||||
ty_bool. { ret 1u; }
|
||||
ty_int. { ret 2u; }
|
||||
ty_float. { ret 3u; }
|
||||
ty_uint. { ret 4u; }
|
||||
ty_machine(tm) {
|
||||
alt tm {
|
||||
ast::ty_i8. { ret 5u; }
|
||||
ast::ty_i16. { ret 6u; }
|
||||
ast::ty_i32. { ret 7u; }
|
||||
ast::ty_i64. { ret 8u; }
|
||||
ast::ty_u8. { ret 9u; }
|
||||
ast::ty_u16. { ret 10u; }
|
||||
ast::ty_u32. { ret 11u; }
|
||||
ast::ty_u64. { ret 12u; }
|
||||
ast::ty_f32. { ret 13u; }
|
||||
ast::ty_f64. { ret 14u; }
|
||||
ty_nil. { 0u } ty_bool. { 1u }
|
||||
ty_int(t) {
|
||||
alt t {
|
||||
ast::ty_i. { 2u } ast::ty_char. { 3u } ast::ty_i8. { 4u }
|
||||
ast::ty_i16. { 5u } ast::ty_i32. { 6u } ast::ty_i64. { 7u }
|
||||
}
|
||||
}
|
||||
ty_char. { ret 15u; }
|
||||
ty_uint(t) {
|
||||
alt t {
|
||||
ast::ty_u. { 8u } ast::ty_u8. { 9u } ast::ty_u16. { 10u }
|
||||
ast::ty_u32. { 11u } ast::ty_u64. { 12u }
|
||||
}
|
||||
}
|
||||
ty_float(t) {
|
||||
alt t { ast::ty_f. { 13u } ast::ty_f32. { 14u } ast::ty_f64. { 15u } }
|
||||
}
|
||||
ty_str. { ret 17u; }
|
||||
ty_tag(did, tys) {
|
||||
let h = hash_def(18u, did);
|
||||
@ -1505,17 +1437,17 @@ fn eq_ty(&&a: t, &&b: t) -> bool { ret a == b; }
|
||||
fn ty_to_machine_ty(cx: ctxt, ty: t) -> t {
|
||||
fn sub_fn(cx: ctxt, uint_ty: t, int_ty: t, float_ty: t, in: t) -> t {
|
||||
alt struct(cx, in) {
|
||||
ty_uint. { ret uint_ty; }
|
||||
ty_int. { ret int_ty; }
|
||||
ty_float. { ret float_ty; }
|
||||
ty_uint(ast::ty_u.) { ret uint_ty; }
|
||||
ty_int(ast::ty_i.) { ret int_ty; }
|
||||
ty_float(ast::ty_f.) { ret float_ty; }
|
||||
_ { ret in; }
|
||||
}
|
||||
}
|
||||
|
||||
let cfg = cx.sess.get_targ_cfg();
|
||||
let uint_ty = mk_mach(cx, cfg.uint_type);
|
||||
let int_ty = mk_mach(cx, cfg.int_type);
|
||||
let float_ty = mk_mach(cx, cfg.float_type);
|
||||
let uint_ty = mk_mach_uint(cx, cfg.uint_type);
|
||||
let int_ty = mk_mach_int(cx, cfg.int_type);
|
||||
let float_ty = mk_mach_float(cx, cfg.float_type);
|
||||
let fold_m = fm_general(bind sub_fn(cx, uint_ty, int_ty, float_ty, _));
|
||||
|
||||
ret fold_ty(cx, fold_m, ty);
|
||||
@ -2289,14 +2221,10 @@ mod unify {
|
||||
ty::ty_bot. {
|
||||
ret ures_ok(actual);
|
||||
}
|
||||
ty::ty_bool. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_int. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_uint. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_machine(_) { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_float. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_char. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_str. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_type. { ret struct_cmp(cx, expected, actual); }
|
||||
ty::ty_bool. | ty::ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty::ty_str. | ty::ty_type. {
|
||||
ret struct_cmp(cx, expected, actual);
|
||||
}
|
||||
ty::ty_native(ex_id) {
|
||||
alt struct(cx.tcx, actual) {
|
||||
ty_native(act_id) {
|
||||
@ -2891,20 +2819,9 @@ fn is_binopable(cx: ctxt, ty: t, op: ast::binop) -> bool {
|
||||
fn tycat(cx: ctxt, ty: t) -> int {
|
||||
alt struct(cx, ty) {
|
||||
ty_bool. { tycat_bool }
|
||||
ty_int. { tycat_int }
|
||||
ty_uint. { tycat_int }
|
||||
ty_machine(ast::ty_i8.) { tycat_int }
|
||||
ty_machine(ast::ty_i16.) { tycat_int }
|
||||
ty_machine(ast::ty_i32.) { tycat_int }
|
||||
ty_machine(ast::ty_i64.) { tycat_int }
|
||||
ty_machine(ast::ty_u8.) { tycat_int }
|
||||
ty_machine(ast::ty_u16.) { tycat_int }
|
||||
ty_machine(ast::ty_u32.) { tycat_int }
|
||||
ty_machine(ast::ty_u64.) { tycat_int }
|
||||
ty_float. { tycat_float }
|
||||
ty_machine(ast::ty_f32.) { tycat_float }
|
||||
ty_machine(ast::ty_f64.) { tycat_float }
|
||||
ty_char. { tycat_int }
|
||||
ty_int(_) { tycat_int }
|
||||
ty_uint(_) { tycat_int }
|
||||
ty_float(_) { tycat_float }
|
||||
ty_str. { tycat_str }
|
||||
ty_vec(_) { tycat_vec }
|
||||
ty_rec(_) { tycat_struct }
|
||||
|
@ -289,11 +289,9 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, &&ast_ty: @ast::ty)
|
||||
ast::ty_nil. { typ = ty::mk_nil(tcx); }
|
||||
ast::ty_bot. { typ = ty::mk_bot(tcx); }
|
||||
ast::ty_bool. { typ = ty::mk_bool(tcx); }
|
||||
ast::ty_int. { typ = ty::mk_int(tcx); }
|
||||
ast::ty_uint. { typ = ty::mk_uint(tcx); }
|
||||
ast::ty_float. { typ = ty::mk_float(tcx); }
|
||||
ast::ty_machine(tm) { typ = ty::mk_mach(tcx, tm); }
|
||||
ast::ty_char. { typ = ty::mk_char(tcx); }
|
||||
ast::ty_int(it) { typ = ty::mk_mach_int(tcx, it); }
|
||||
ast::ty_uint(uit) { typ = ty::mk_mach_uint(tcx, uit); }
|
||||
ast::ty_float(ft) { typ = ty::mk_mach_float(tcx, ft); }
|
||||
ast::ty_str. { typ = ty::mk_str(tcx); }
|
||||
ast::ty_box(mt) {
|
||||
typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
|
||||
@ -1223,32 +1221,12 @@ fn gather_locals(ccx: @crate_ctxt, f: ast::_fn, id: ast::node_id,
|
||||
// AST fragment checking
|
||||
fn check_lit(ccx: @crate_ctxt, lit: @ast::lit) -> ty::t {
|
||||
alt lit.node {
|
||||
ast::lit_str(_) { ret ty::mk_str(ccx.tcx); }
|
||||
ast::lit_char(_) { ret ty::mk_char(ccx.tcx); }
|
||||
ast::lit_int(_) { ret ty::mk_int(ccx.tcx); }
|
||||
ast::lit_float(_) { ret ty::mk_float(ccx.tcx); }
|
||||
ast::lit_mach_float(tm, _) { ret ty::mk_mach(ccx.tcx, tm); }
|
||||
ast::lit_uint(_) { ret ty::mk_uint(ccx.tcx); }
|
||||
ast::lit_mach_int(tm, _) { ret ty::mk_mach(ccx.tcx, tm); }
|
||||
ast::lit_nil. { ret ty::mk_nil(ccx.tcx); }
|
||||
ast::lit_bool(_) { ret ty::mk_bool(ccx.tcx); }
|
||||
}
|
||||
}
|
||||
|
||||
fn lit_as_uint(l: @ast::lit) -> uint {
|
||||
alt l.node {
|
||||
ast::lit_uint(u) { u }
|
||||
ast::lit_char(c) { c as uint }
|
||||
}
|
||||
}
|
||||
fn lit_as_int(l: @ast::lit) -> int {
|
||||
alt l.node {
|
||||
ast::lit_int(i) | ast::lit_mach_int(_, i) { i }
|
||||
}
|
||||
}
|
||||
fn lit_as_float(l: @ast::lit) -> str {
|
||||
alt l.node {
|
||||
ast::lit_float(f) | ast::lit_mach_float(_, f) { f }
|
||||
ast::lit_str(_) { ty::mk_str(ccx.tcx) }
|
||||
ast::lit_int(_, t) { ty::mk_mach_int(ccx.tcx, t) }
|
||||
ast::lit_uint(_, t) { ty::mk_mach_uint(ccx.tcx, t) }
|
||||
ast::lit_float(_, t) { ty::mk_mach_float(ccx.tcx, t) }
|
||||
ast::lit_nil. { ty::mk_nil(ccx.tcx) }
|
||||
ast::lit_bool(_) { ty::mk_bool(ccx.tcx) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1919,7 +1897,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
let ety = expr_ty(tcx, seq);
|
||||
alt structure_of(fcx, expr.span, ety) {
|
||||
ty::ty_vec(vec_elt_ty) { elt_ty = vec_elt_ty.ty; }
|
||||
ty::ty_str. { elt_ty = ty::mk_mach(tcx, ast::ty_u8); }
|
||||
ty::ty_str. { elt_ty = ty::mk_mach_uint(tcx, ast::ty_u8); }
|
||||
_ {
|
||||
tcx.sess.span_fatal(expr.span,
|
||||
"mismatched types: expected vector or string "
|
||||
@ -2258,7 +2236,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
alt structure_of(fcx, expr.span, base_t) {
|
||||
ty::ty_vec(mt) { write::ty_only_fixup(fcx, id, mt.ty); }
|
||||
ty::ty_str. {
|
||||
let typ = ty::mk_mach(tcx, ast::ty_u8);
|
||||
let typ = ty::mk_mach_uint(tcx, ast::ty_u8);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
_ {
|
||||
|
@ -251,12 +251,9 @@ type lit = spanned<lit_>;
|
||||
|
||||
tag lit_ {
|
||||
lit_str(str);
|
||||
lit_char(char);
|
||||
lit_int(int);
|
||||
lit_uint(uint);
|
||||
lit_mach_int(ty_mach, int);
|
||||
lit_float(str);
|
||||
lit_mach_float(ty_mach, str);
|
||||
lit_int(i64, int_ty);
|
||||
lit_uint(u64, uint_ty);
|
||||
lit_float(str, float_ty);
|
||||
lit_nil;
|
||||
lit_bool(bool);
|
||||
}
|
||||
@ -283,18 +280,11 @@ type ty_arg = spanned<ty_arg_>;
|
||||
|
||||
type ty_method = spanned<ty_method_>;
|
||||
|
||||
tag ty_mach {
|
||||
ty_i8;
|
||||
ty_i16;
|
||||
ty_i32;
|
||||
ty_i64;
|
||||
ty_u8;
|
||||
ty_u16;
|
||||
ty_u32;
|
||||
ty_u64;
|
||||
ty_f32;
|
||||
ty_f64;
|
||||
}
|
||||
tag int_ty { ty_i; ty_char; ty_i8; ty_i16; ty_i32; ty_i64; }
|
||||
|
||||
tag uint_ty { ty_u; ty_u8; ty_u16; ty_u32; ty_u64; }
|
||||
|
||||
tag float_ty { ty_f; ty_f32; ty_f64; }
|
||||
|
||||
type ty = spanned<ty_>;
|
||||
|
||||
@ -304,18 +294,13 @@ tag ty_ {
|
||||
ret/fail/break/cont. there is no syntax
|
||||
for this type. */
|
||||
|
||||
|
||||
|
||||
|
||||
/* bot represents the value of functions that don't return a value
|
||||
locally to their context. in contrast, things like log that do
|
||||
return, but don't return a meaningful value, have result type nil. */
|
||||
ty_bool;
|
||||
ty_int;
|
||||
ty_uint;
|
||||
ty_float;
|
||||
ty_machine(ty_mach);
|
||||
ty_char;
|
||||
ty_bool;
|
||||
ty_int(int_ty);
|
||||
ty_uint(uint_ty);
|
||||
ty_float(float_ty);
|
||||
ty_str;
|
||||
ty_box(mt);
|
||||
ty_uniq(mt);
|
||||
@ -332,7 +317,6 @@ tag ty_ {
|
||||
ty_type;
|
||||
ty_constr(@ty, [@ty_constr]);
|
||||
ty_mac(mac);
|
||||
|
||||
// ty_infer means the type should be inferred instead of it having been
|
||||
// specified. This should only appear at the "top level" of a type and not
|
||||
// nested in one.
|
||||
|
@ -125,21 +125,23 @@ fn is_path(e: @expr) -> bool {
|
||||
ret alt e.node { expr_path(_) { true } _ { false } };
|
||||
}
|
||||
|
||||
fn ty_mach_to_str(tm: ty_mach) -> str {
|
||||
alt tm {
|
||||
ty_u8. { ret "u8"; }
|
||||
ty_u16. { ret "u16"; }
|
||||
ty_u32. { ret "u32"; }
|
||||
ty_u64. { ret "u64"; }
|
||||
ty_i8. { ret "i8"; }
|
||||
ty_i16. { ret "i16"; }
|
||||
ty_i32. { ret "i32"; }
|
||||
ty_i64. { ret "i64"; }
|
||||
ty_f32. { ret "f32"; }
|
||||
ty_f64. { ret "f64"; }
|
||||
fn int_ty_to_str(t: int_ty) -> str {
|
||||
alt t {
|
||||
ty_i. { "" } ty_i8. { "i8" } ty_i16. { "i16" }
|
||||
ty_i32. { "i32" } ty_i64. { "i64" }
|
||||
}
|
||||
}
|
||||
|
||||
fn uint_ty_to_str(t: uint_ty) -> str {
|
||||
alt t {
|
||||
ty_u. { "" } ty_u8. { "u8" } ty_u16. { "u16" }
|
||||
ty_u32. { "u32" } ty_u64. { "u64" }
|
||||
}
|
||||
}
|
||||
|
||||
fn float_ty_to_str(t: float_ty) -> str {
|
||||
alt t { ty_f. { "" } ty_f32. { "f32" } ty_f64. { "f64" } }
|
||||
}
|
||||
|
||||
fn is_exported(i: ident, m: _mod) -> bool {
|
||||
let nonlocal = true;
|
||||
@ -245,7 +247,12 @@ fn ty_param_kind(tp: ty_param) -> kind { tp.kind }
|
||||
|
||||
// FIXME this doesn't handle big integer/float literals correctly (nor does
|
||||
// the rest of our literal handling)
|
||||
tag const_val { const_float(float); const_int(i64); const_str(str); }
|
||||
tag const_val {
|
||||
const_float(float);
|
||||
const_int(i64);
|
||||
const_uint(u64);
|
||||
const_str(str);
|
||||
}
|
||||
|
||||
fn eval_const_expr(e: @expr) -> const_val {
|
||||
fn fromb(b: bool) -> const_val { const_int(b as i64) }
|
||||
@ -254,11 +261,13 @@ fn eval_const_expr(e: @expr) -> const_val {
|
||||
alt eval_const_expr(inner) {
|
||||
const_float(f) { const_float(-f) }
|
||||
const_int(i) { const_int(-i) }
|
||||
const_uint(i) { const_uint(-i) }
|
||||
}
|
||||
}
|
||||
expr_unary(not., inner) {
|
||||
alt eval_const_expr(inner) {
|
||||
const_int(i) { const_int(!i) }
|
||||
const_uint(i) { const_uint(!i) }
|
||||
}
|
||||
}
|
||||
expr_binary(op, a, b) {
|
||||
@ -283,6 +292,17 @@ fn eval_const_expr(e: @expr) -> const_val {
|
||||
ge. { fromb(a >= b) } gt. { fromb(a > b) }
|
||||
}
|
||||
}
|
||||
(const_uint(a), const_uint(b)) {
|
||||
alt op {
|
||||
add. { const_uint(a + b) } sub. { const_uint(a - b) }
|
||||
mul. { const_uint(a * b) } div. { const_uint(a / b) }
|
||||
rem. { const_uint(a % b) } and. | bitand. { const_uint(a & b) }
|
||||
or. | bitor. { const_uint(a | b) } bitxor. { const_uint(a ^ b) }
|
||||
eq. { fromb(a == b) } lt. { fromb(a < b) }
|
||||
le. { fromb(a <= b) } ne. { fromb(a != b) }
|
||||
ge. { fromb(a >= b) } gt. { fromb(a > b) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expr_lit(lit) { lit_to_const(lit) }
|
||||
@ -292,12 +312,9 @@ fn eval_const_expr(e: @expr) -> const_val {
|
||||
fn lit_to_const(lit: @lit) -> const_val {
|
||||
alt lit.node {
|
||||
lit_str(s) { const_str(s) }
|
||||
lit_char(ch) { const_int(ch as i64) }
|
||||
lit_int(i) | lit_mach_int(_, i) { const_int(i as i64) }
|
||||
lit_uint(ui) { const_int(ui as i64) }
|
||||
lit_float(s) | lit_mach_float(_, s) {
|
||||
const_float(std::float::from_str(s))
|
||||
}
|
||||
lit_int(n, _) { const_int(n) }
|
||||
lit_uint(n, _) { const_uint(n) }
|
||||
lit_float(n, _) { const_float(std::float::from_str(n)) }
|
||||
lit_nil. { const_int(0i64) }
|
||||
lit_bool(b) { const_int(b as i64) }
|
||||
}
|
||||
@ -306,6 +323,7 @@ fn lit_to_const(lit: @lit) -> const_val {
|
||||
fn compare_const_vals(a: const_val, b: const_val) -> int {
|
||||
alt (a, b) {
|
||||
(const_int(a), const_int(b)) { a == b ? 0 : a < b ? -1 : 1 }
|
||||
(const_uint(a), const_uint(b)) { a == b ? 0 : a < b ? -1 : 1 }
|
||||
(const_float(a), const_float(b)) { a == b ? 0 : a < b ? -1 : 1 }
|
||||
(const_str(a), const_str(b)) { a == b ? 0 : a < b ? -1 : 1 }
|
||||
}
|
||||
|
@ -52,11 +52,11 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_new_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
|
||||
let lit = ast::lit_int(i);
|
||||
let lit = ast::lit_int(i as i64, ast::ty_i);
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_new_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
|
||||
let lit = ast::lit_uint(u);
|
||||
let lit = ast::lit_uint(u as u64, ast::ty_u);
|
||||
ret make_new_lit(cx, sp, lit);
|
||||
}
|
||||
fn make_add_expr(cx: ext_ctxt, sp: span, lhs: @ast::expr, rhs: @ast::expr)
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
import std::{io, vec, str, option};
|
||||
import std::{io, vec, str, option, either};
|
||||
import std::option::{some, none};
|
||||
import util::interner;
|
||||
import util::interner::intern;
|
||||
@ -161,103 +161,89 @@ fn scan_exponent(rdr: reader) -> option::t<str> {
|
||||
let c = rdr.curr();
|
||||
let rslt = "";
|
||||
if c == 'e' || c == 'E' {
|
||||
rslt += str::unsafe_from_bytes([c as u8]);
|
||||
str::push_byte(rslt, c as u8);
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
if c == '-' || c == '+' {
|
||||
rslt += str::unsafe_from_bytes([c as u8]);
|
||||
str::push_byte(rslt, c as u8);
|
||||
rdr.bump();
|
||||
}
|
||||
let exponent = scan_dec_digits(rdr);
|
||||
let exponent = scan_digits(rdr, 10u);
|
||||
if str::byte_len(exponent) > 0u {
|
||||
ret some(rslt + exponent);
|
||||
} else { rdr.err("scan_exponent: bad fp literal"); fail; }
|
||||
} else { ret none::<str>; }
|
||||
}
|
||||
|
||||
fn scan_dec_digits(rdr: reader) -> str {
|
||||
let c = rdr.curr();
|
||||
let rslt: str = "";
|
||||
while is_dec_digit(c) || c == '_' {
|
||||
if c != '_' { rslt += str::unsafe_from_bytes([c as u8]); }
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
fn scan_digits(rdr: reader, radix: uint) -> str {
|
||||
radix; // FIXME work around issue #1265
|
||||
let rslt = "";
|
||||
while true {
|
||||
let c = rdr.curr();
|
||||
if c == '_' { rdr.bump(); cont; }
|
||||
alt std::char::maybe_digit(c) {
|
||||
some(d) when (d as uint) < radix {
|
||||
str::push_byte(rslt, c as u8);
|
||||
rdr.bump();
|
||||
}
|
||||
_ { break; }
|
||||
}
|
||||
}
|
||||
ret rslt;
|
||||
}
|
||||
|
||||
fn scan_number(c: char, rdr: reader) -> token::token {
|
||||
let accum_int = 0, c = c;
|
||||
let num_str: str = "";
|
||||
let n = rdr.next();
|
||||
let num_str, base = 10u, c = c, n = rdr.next();
|
||||
if c == '0' && n == 'x' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
while is_hex_digit(c) || c == '_' {
|
||||
if c != '_' { accum_int *= 16; accum_int += hex_digit_val(c); }
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
}
|
||||
base = 16u;
|
||||
} else if c == '0' && n == 'b' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
while is_bin_digit(c) || c == '_' {
|
||||
if c != '_' { accum_int *= 2; accum_int += bin_digit_value(c); }
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
}
|
||||
} else {
|
||||
num_str = scan_dec_digits(rdr);
|
||||
accum_int = std::int::from_str(num_str);
|
||||
base = 2u;
|
||||
}
|
||||
num_str = scan_digits(rdr, base);
|
||||
c = rdr.curr();
|
||||
n = rdr.next();
|
||||
if c == 'u' || c == 'i' {
|
||||
let signed: bool = c == 'i';
|
||||
let signed = c == 'i', tp = signed ? either::left(ast::ty_i)
|
||||
: either::right(ast::ty_u);
|
||||
rdr.bump();
|
||||
c = rdr.curr();
|
||||
if c == '8' {
|
||||
rdr.bump();
|
||||
if signed {
|
||||
ret token::LIT_MACH_INT(ast::ty_i8, accum_int);
|
||||
} else { ret token::LIT_MACH_INT(ast::ty_u8, accum_int); }
|
||||
tp = signed ? either::left(ast::ty_i8)
|
||||
: either::right(ast::ty_u8);
|
||||
}
|
||||
n = rdr.next();
|
||||
if c == '1' && n == '6' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
if signed {
|
||||
ret token::LIT_MACH_INT(ast::ty_i16, accum_int);
|
||||
} else { ret token::LIT_MACH_INT(ast::ty_u16, accum_int); }
|
||||
tp = signed ? either::left(ast::ty_i16)
|
||||
: either::right(ast::ty_u16);
|
||||
} else if c == '3' && n == '2' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
tp = signed ? either::left(ast::ty_i32)
|
||||
: either::right(ast::ty_u32);
|
||||
} else if c == '6' && n == '4' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
tp = signed ? either::left(ast::ty_i64)
|
||||
: either::right(ast::ty_u64);
|
||||
}
|
||||
if c == '3' && n == '2' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
if signed {
|
||||
ret token::LIT_MACH_INT(ast::ty_i32, accum_int);
|
||||
} else { ret token::LIT_MACH_INT(ast::ty_u32, accum_int); }
|
||||
}
|
||||
if c == '6' && n == '4' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
if signed {
|
||||
ret token::LIT_MACH_INT(ast::ty_i64, accum_int);
|
||||
} else { ret token::LIT_MACH_INT(ast::ty_u64, accum_int); }
|
||||
}
|
||||
if signed {
|
||||
ret token::LIT_INT(accum_int);
|
||||
} else {
|
||||
// FIXME: should cast in the target bit-width.
|
||||
ret token::LIT_UINT(accum_int as uint);
|
||||
let parsed = std::u64::from_str(num_str, base as u64);
|
||||
alt tp {
|
||||
either::left(t) { ret token::LIT_INT(parsed as i64, t); }
|
||||
either::right(t) { ret token::LIT_UINT(parsed, t); }
|
||||
}
|
||||
}
|
||||
let is_float = false;
|
||||
if rdr.curr() == '.' {
|
||||
is_float = true;
|
||||
rdr.bump();
|
||||
let dec_part = scan_dec_digits(rdr);
|
||||
let dec_part = scan_digits(rdr, 10u);
|
||||
num_str += "." + dec_part;
|
||||
}
|
||||
alt scan_exponent(rdr) {
|
||||
@ -274,15 +260,13 @@ fn scan_number(c: char, rdr: reader) -> token::token {
|
||||
if c == '3' && n == '2' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
ret token::LIT_MACH_FLOAT(ast::ty_f32,
|
||||
intern(*rdr.get_interner(),
|
||||
num_str));
|
||||
ret token::LIT_FLOAT(intern(*rdr.get_interner(), num_str),
|
||||
ast::ty_f32);
|
||||
} else if c == '6' && n == '4' {
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
ret token::LIT_MACH_FLOAT(ast::ty_f64,
|
||||
intern(*rdr.get_interner(),
|
||||
num_str));
|
||||
ret token::LIT_FLOAT(intern(*rdr.get_interner(), num_str),
|
||||
ast::ty_f64);
|
||||
/* FIXME: if this is out of range for either a 32-bit or
|
||||
64-bit float, it won't be noticed till the back-end */
|
||||
} else {
|
||||
@ -290,10 +274,11 @@ fn scan_number(c: char, rdr: reader) -> token::token {
|
||||
}
|
||||
}
|
||||
if is_float {
|
||||
ret token::LIT_FLOAT(interner::intern::<str>(*rdr.get_interner(),
|
||||
num_str));
|
||||
ret token::LIT_FLOAT(interner::intern(*rdr.get_interner(), num_str),
|
||||
ast::ty_f);
|
||||
} else {
|
||||
ret token::LIT_INT(accum_int);
|
||||
let parsed = std::u64::from_str(num_str, base as u64);
|
||||
ret token::LIT_INT(parsed as i64, ast::ty_i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,8 +448,7 @@ fn next_token_inner(rdr: reader) -> token::token {
|
||||
fail;
|
||||
}
|
||||
rdr.bump(); // advance curr past token
|
||||
|
||||
ret token::LIT_CHAR(c2);
|
||||
ret token::LIT_INT(c2 as i64, ast::ty_char);
|
||||
}
|
||||
'"' {
|
||||
let n = rdr.get_chpos();
|
||||
@ -685,13 +669,10 @@ fn consume_comment(rdr: reader, code_to_the_left: bool, &comments: [cmnt]) {
|
||||
|
||||
fn is_lit(t: token::token) -> bool {
|
||||
ret alt t {
|
||||
token::LIT_INT(_) { true }
|
||||
token::LIT_UINT(_) { true }
|
||||
token::LIT_MACH_INT(_, _) { true }
|
||||
token::LIT_FLOAT(_) { true }
|
||||
token::LIT_MACH_FLOAT(_, _) { true }
|
||||
token::LIT_INT(_, _) { true }
|
||||
token::LIT_UINT(_, _) { true }
|
||||
token::LIT_FLOAT(_, _) { true }
|
||||
token::LIT_STR(_) { true }
|
||||
token::LIT_CHAR(_) { true }
|
||||
token::LIT_BOOL(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
|
@ -459,39 +459,35 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
|
||||
if eat_word(p, "bool") {
|
||||
t = ast::ty_bool;
|
||||
} else if eat_word(p, "int") {
|
||||
t = ast::ty_int;
|
||||
t = ast::ty_int(ast::ty_i);
|
||||
} else if eat_word(p, "uint") {
|
||||
t = ast::ty_uint;
|
||||
t = ast::ty_uint(ast::ty_u);
|
||||
} else if eat_word(p, "float") {
|
||||
t = ast::ty_float;
|
||||
t = ast::ty_float(ast::ty_f);
|
||||
} else if eat_word(p, "str") {
|
||||
t = ast::ty_str;
|
||||
} else if eat_word(p, "char") {
|
||||
t = ast::ty_char;
|
||||
/*
|
||||
} else if (eat_word(p, "task")) {
|
||||
t = ast::ty_task;
|
||||
*/
|
||||
t = ast::ty_int(ast::ty_char);
|
||||
} else if eat_word(p, "i8") {
|
||||
t = ast::ty_machine(ast::ty_i8);
|
||||
t = ast::ty_int(ast::ty_i8);
|
||||
} else if eat_word(p, "i16") {
|
||||
t = ast::ty_machine(ast::ty_i16);
|
||||
t = ast::ty_int(ast::ty_i16);
|
||||
} else if eat_word(p, "i32") {
|
||||
t = ast::ty_machine(ast::ty_i32);
|
||||
t = ast::ty_int(ast::ty_i32);
|
||||
} else if eat_word(p, "i64") {
|
||||
t = ast::ty_machine(ast::ty_i64);
|
||||
t = ast::ty_int(ast::ty_i64);
|
||||
} else if eat_word(p, "u8") {
|
||||
t = ast::ty_machine(ast::ty_u8);
|
||||
t = ast::ty_uint(ast::ty_u8);
|
||||
} else if eat_word(p, "u16") {
|
||||
t = ast::ty_machine(ast::ty_u16);
|
||||
t = ast::ty_uint(ast::ty_u16);
|
||||
} else if eat_word(p, "u32") {
|
||||
t = ast::ty_machine(ast::ty_u32);
|
||||
t = ast::ty_uint(ast::ty_u32);
|
||||
} else if eat_word(p, "u64") {
|
||||
t = ast::ty_machine(ast::ty_u64);
|
||||
t = ast::ty_uint(ast::ty_u64);
|
||||
} else if eat_word(p, "f32") {
|
||||
t = ast::ty_machine(ast::ty_f32);
|
||||
t = ast::ty_float(ast::ty_f32);
|
||||
} else if eat_word(p, "f64") {
|
||||
t = ast::ty_machine(ast::ty_f64);
|
||||
t = ast::ty_float(ast::ty_f64);
|
||||
} else if p.peek() == token::LPAREN {
|
||||
p.bump();
|
||||
if p.peek() == token::RPAREN {
|
||||
@ -662,12 +658,9 @@ fn parse_seq<copy T>(bra: token::token, ket: token::token,
|
||||
|
||||
fn lit_from_token(p: parser, tok: token::token) -> ast::lit_ {
|
||||
alt tok {
|
||||
token::LIT_INT(i) { ast::lit_int(i) }
|
||||
token::LIT_UINT(u) { ast::lit_uint(u) }
|
||||
token::LIT_FLOAT(s) { ast::lit_float(p.get_str(s)) }
|
||||
token::LIT_MACH_INT(tm, i) { ast::lit_mach_int(tm, i) }
|
||||
token::LIT_MACH_FLOAT(tm, s) { ast::lit_mach_float(tm, p.get_str(s)) }
|
||||
token::LIT_CHAR(c) { ast::lit_char(c) }
|
||||
token::LIT_INT(i, it) { ast::lit_int(i, it) }
|
||||
token::LIT_UINT(u, ut) { ast::lit_uint(u, ut) }
|
||||
token::LIT_FLOAT(s, ft) { ast::lit_float(p.get_str(s), ft) }
|
||||
token::LIT_STR(s) { ast::lit_str(p.get_str(s)) }
|
||||
token::LPAREN. { expect(p, token::RPAREN); ast::lit_nil }
|
||||
_ { unexpected(p, tok); }
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
import ast::ty_mach;
|
||||
import ast_util::ty_mach_to_str;
|
||||
import util::interner;
|
||||
import std::{int, uint, str};
|
||||
|
||||
@ -21,8 +19,6 @@ tag binop {
|
||||
}
|
||||
|
||||
tag token {
|
||||
|
||||
|
||||
/* Expression-operator symbols. */
|
||||
EQ;
|
||||
LT;
|
||||
@ -38,7 +34,6 @@ tag token {
|
||||
BINOP(binop);
|
||||
BINOPEQ(binop);
|
||||
|
||||
|
||||
/* Structural symbols */
|
||||
AT;
|
||||
DOT;
|
||||
@ -61,18 +56,13 @@ tag token {
|
||||
POUND_LBRACE;
|
||||
POUND_LT;
|
||||
|
||||
|
||||
/* Literals */
|
||||
LIT_INT(int);
|
||||
LIT_UINT(uint);
|
||||
LIT_MACH_INT(ty_mach, int);
|
||||
LIT_FLOAT(str_num);
|
||||
LIT_MACH_FLOAT(ty_mach, str_num);
|
||||
LIT_INT(i64, ast::int_ty);
|
||||
LIT_UINT(u64, ast::uint_ty);
|
||||
LIT_FLOAT(str_num, ast::float_ty);
|
||||
LIT_STR(str_num);
|
||||
LIT_CHAR(char);
|
||||
LIT_BOOL(bool);
|
||||
|
||||
|
||||
/* Name components */
|
||||
IDENT(str_num, bool);
|
||||
IDX(int);
|
||||
@ -113,10 +103,6 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
||||
BINOP(op) { ret binop_to_str(op); }
|
||||
BINOPEQ(op) { ret binop_to_str(op) + "="; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Structural symbols */
|
||||
AT. {
|
||||
ret "@";
|
||||
@ -141,39 +127,29 @@ fn to_str(r: lexer::reader, t: token) -> str {
|
||||
POUND_LBRACE. { ret "#{"; }
|
||||
POUND_LT. { ret "#<"; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Literals */
|
||||
LIT_INT(i) {
|
||||
ret int::to_str(i, 10u);
|
||||
}
|
||||
LIT_UINT(u) { ret uint::to_str(u, 10u); }
|
||||
LIT_MACH_INT(tm, i) {
|
||||
ret int::to_str(i, 10u) + "_" + ty_mach_to_str(tm);
|
||||
}
|
||||
LIT_MACH_FLOAT(tm, s) {
|
||||
ret interner::get::<str>(*r.get_interner(), s) + "_" +
|
||||
ty_mach_to_str(tm);
|
||||
}
|
||||
LIT_FLOAT(s) { ret interner::get::<str>(*r.get_interner(), s); }
|
||||
LIT_STR(s) { // FIXME: escape.
|
||||
ret "\"" + interner::get::<str>(*r.get_interner(), s) + "\"";
|
||||
}
|
||||
LIT_CHAR(c) {
|
||||
LIT_INT(c, ast::ty_char.) {
|
||||
// FIXME: escape.
|
||||
let tmp = "'";
|
||||
str::push_char(tmp, c);
|
||||
str::push_char(tmp, c as char);
|
||||
str::push_byte(tmp, '\'' as u8);
|
||||
ret tmp;
|
||||
}
|
||||
LIT_INT(i, t) {
|
||||
ret int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t);
|
||||
}
|
||||
LIT_UINT(u, t) {
|
||||
ret uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t);
|
||||
}
|
||||
LIT_FLOAT(s, t) {
|
||||
ret interner::get::<str>(*r.get_interner(), s) +
|
||||
ast_util::float_ty_to_str(t);
|
||||
}
|
||||
LIT_STR(s) { // FIXME: escape.
|
||||
ret "\"" + interner::get::<str>(*r.get_interner(), s) + "\"";
|
||||
}
|
||||
LIT_BOOL(b) { if b { ret "true"; } else { ret "false"; } }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Name components */
|
||||
IDENT(s, _) {
|
||||
ret interner::get::<str>(*r.get_interner(), s);
|
||||
@ -194,13 +170,10 @@ pure fn can_begin_expr(t: token) -> bool {
|
||||
IDENT(_, _) { true }
|
||||
UNDERSCORE. { true }
|
||||
TILDE. { true }
|
||||
LIT_INT(_) { true }
|
||||
LIT_UINT(_) { true }
|
||||
LIT_MACH_INT(_, _) { true }
|
||||
LIT_FLOAT(_) { true }
|
||||
LIT_MACH_FLOAT(_, _) { true }
|
||||
LIT_INT(_, _) { true }
|
||||
LIT_UINT(_, _) { true }
|
||||
LIT_FLOAT(_, _) { true }
|
||||
LIT_STR(_) { true }
|
||||
LIT_CHAR(_) { true }
|
||||
POUND. { true }
|
||||
AT. { true }
|
||||
NOT. { true }
|
||||
|
@ -252,11 +252,13 @@ fn print_type(s: ps, &&ty: @ast::ty) {
|
||||
ast::ty_nil. { word(s.s, "()"); }
|
||||
ast::ty_bool. { word(s.s, "bool"); }
|
||||
ast::ty_bot. { word(s.s, "!"); }
|
||||
ast::ty_int. { word(s.s, "int"); }
|
||||
ast::ty_uint. { word(s.s, "uint"); }
|
||||
ast::ty_float. { word(s.s, "float"); }
|
||||
ast::ty_machine(tm) { word(s.s, ast_util::ty_mach_to_str(tm)); }
|
||||
ast::ty_char. { word(s.s, "char"); }
|
||||
ast::ty_int(ast::ty_i.) { word(s.s, "int"); }
|
||||
ast::ty_int(ast::ty_char.) { word(s.s, "char"); }
|
||||
ast::ty_int(t) { word(s.s, ast_util::int_ty_to_str(t)); }
|
||||
ast::ty_uint(ast::ty_u.) { word(s.s, "uint"); }
|
||||
ast::ty_uint(t) { word(s.s, ast_util::uint_ty_to_str(t)); }
|
||||
ast::ty_float(ast::ty_f.) { word(s.s, "float"); }
|
||||
ast::ty_float(t) { word(s.s, ast_util::float_ty_to_str(t)); }
|
||||
ast::ty_str. { word(s.s, "str"); }
|
||||
ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
|
||||
ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); }
|
||||
@ -1385,22 +1387,17 @@ fn print_literal(s: ps, &&lit: @ast::lit) {
|
||||
}
|
||||
alt lit.node {
|
||||
ast::lit_str(st) { print_string(s, st); }
|
||||
ast::lit_char(ch) {
|
||||
word(s.s,
|
||||
"'" + escape_str(str::unsafe_from_bytes([ch as u8]), '\'') +
|
||||
"'");
|
||||
ast::lit_int(ch, ast::ty_char.) {
|
||||
word(s.s, "'" + escape_str(str::from_char(ch as char), '\'') + "'");
|
||||
}
|
||||
ast::lit_int(val) { word(s.s, int::str(val)); }
|
||||
ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); }
|
||||
ast::lit_float(fstr) { word(s.s, fstr); }
|
||||
ast::lit_mach_int(mach, val) {
|
||||
word(s.s, int::str(val as int));
|
||||
word(s.s, ast_util::ty_mach_to_str(mach));
|
||||
ast::lit_int(i, t) {
|
||||
word(s.s, int::str(i as int) + ast_util::int_ty_to_str(t));
|
||||
}
|
||||
ast::lit_mach_float(mach, val) {
|
||||
// val is already a str
|
||||
word(s.s, val);
|
||||
word(s.s, ast_util::ty_mach_to_str(mach));
|
||||
ast::lit_uint(u, t) {
|
||||
word(s.s, uint::str(u as uint) + ast_util::uint_ty_to_str(t));
|
||||
}
|
||||
ast::lit_float(f, t) {
|
||||
word(s.s, f + ast_util::float_ty_to_str(t));
|
||||
}
|
||||
ast::lit_nil. { word(s.s, "()"); }
|
||||
ast::lit_bool(val) {
|
||||
@ -1622,7 +1619,7 @@ fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str {
|
||||
|
||||
fn ends_in_lit_int(ex: @ast::expr) -> bool {
|
||||
alt ex.node {
|
||||
ast::expr_lit(@{node: ast::lit_int(_), _}) { true }
|
||||
ast::expr_lit(@{node: ast::lit_int(_, ast::ty_i.), _}) { true }
|
||||
ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) |
|
||||
ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) |
|
||||
ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) |
|
||||
|
@ -112,22 +112,10 @@ fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {}
|
||||
|
||||
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
|
||||
alt t.node {
|
||||
ty_nil. {/* no-op */ }
|
||||
ty_bot. {/* no-op */ }
|
||||
ty_bool. {/* no-op */ }
|
||||
ty_int. {/* no-op */ }
|
||||
ty_float. {/* no-op */ }
|
||||
ty_uint. {/* no-op */ }
|
||||
ty_machine(_) {/* no-op */ }
|
||||
ty_char. {/* no-op */ }
|
||||
ty_str. {/* no-op */ }
|
||||
ty_box(mt) { v.visit_ty(mt.ty, e, v); }
|
||||
ty_uniq(mt) { v.visit_ty(mt.ty, e, v); }
|
||||
ty_vec(mt) { v.visit_ty(mt.ty, e, v); }
|
||||
ty_ptr(mt) { v.visit_ty(mt.ty, e, v); }
|
||||
ty_port(t) { v.visit_ty(t, e, v); }
|
||||
ty_chan(t) { v.visit_ty(t, e, v); }
|
||||
ty_task. {/* no-op */ }
|
||||
ty_rec(flds) {
|
||||
for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); }
|
||||
}
|
||||
@ -146,14 +134,13 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
|
||||
}
|
||||
}
|
||||
ty_path(p, _) { for tp: @ty in p.node.types { v.visit_ty(tp, e, v); } }
|
||||
ty_type. {/* no-op */ }
|
||||
ty_constr(t, cs) {
|
||||
v.visit_ty(t, e, v);
|
||||
for tc: @spanned<constr_general_<@path, node_id>> in cs {
|
||||
v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v);
|
||||
}
|
||||
}
|
||||
ty_infer. {/* no-op */ }
|
||||
_ {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,7 @@ import middle::ty::*;
|
||||
import metadata::encoder;
|
||||
import syntax::print::pprust;
|
||||
import syntax::print::pprust::{path_to_str, constr_args_to_str, proto_to_str};
|
||||
import syntax::ast_util::ty_mach_to_str;
|
||||
import syntax::ast;
|
||||
import syntax::{ast, ast_util};
|
||||
import middle::ast_map;
|
||||
|
||||
fn mode_str(m: ty::mode) -> str {
|
||||
@ -86,58 +85,60 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
|
||||
}
|
||||
alt cname(cx, typ) { some(cs) { ret cs; } _ { } }
|
||||
ret alt struct(cx, typ) {
|
||||
ty_native(_) { "native" }
|
||||
ty_nil. { "()" }
|
||||
ty_bot. { "_|_" }
|
||||
ty_bool. { "bool" }
|
||||
ty_int. { "int" }
|
||||
ty_float. { "float" }
|
||||
ty_uint. { "uint" }
|
||||
ty_machine(tm) { ty_mach_to_str(tm) }
|
||||
ty_char. { "char" }
|
||||
ty_str. { "str" }
|
||||
ty_box(tm) { "@" + mt_to_str(cx, tm) }
|
||||
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
|
||||
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
|
||||
ty_type. { "type" }
|
||||
ty_rec(elems) {
|
||||
ty_native(_) { "native" }
|
||||
ty_nil. { "()" }
|
||||
ty_bot. { "_|_" }
|
||||
ty_bool. { "bool" }
|
||||
ty_int(ast::ty_i.) { "int" }
|
||||
ty_int(ast::ty_char.) { "char" }
|
||||
ty_int(t) { ast_util::int_ty_to_str(t) }
|
||||
ty_uint(ast::ty_u.) { "uint" }
|
||||
ty_uint(t) { ast_util::uint_ty_to_str(t) }
|
||||
ty_float(ast::ty_f.) { "float" }
|
||||
ty_float(t) { ast_util::float_ty_to_str(t) }
|
||||
ty_str. { "str" }
|
||||
ty_box(tm) { "@" + mt_to_str(cx, tm) }
|
||||
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
|
||||
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
|
||||
ty_type. { "type" }
|
||||
ty_rec(elems) {
|
||||
let strs: [str] = [];
|
||||
for fld: field in elems { strs += [field_to_str(cx, fld)]; }
|
||||
"{" + str::connect(strs, ",") + "}"
|
||||
}
|
||||
ty_tup(elems) {
|
||||
let strs = [];
|
||||
for elem in elems { strs += [ty_to_str(cx, elem)]; }
|
||||
"(" + str::connect(strs, ",") + ")"
|
||||
}
|
||||
ty_tag(id, tps) {
|
||||
let s = get_id_ident(cx, id);
|
||||
if vec::len::<t>(tps) > 0u {
|
||||
let strs: [str] = [];
|
||||
for fld: field in elems { strs += [field_to_str(cx, fld)]; }
|
||||
"{" + str::connect(strs, ",") + "}"
|
||||
}
|
||||
ty_tup(elems) {
|
||||
let strs = [];
|
||||
for elem in elems { strs += [ty_to_str(cx, elem)]; }
|
||||
"(" + str::connect(strs, ",") + ")"
|
||||
}
|
||||
ty_tag(id, tps) {
|
||||
let s = get_id_ident(cx, id);
|
||||
if vec::len::<t>(tps) > 0u {
|
||||
let strs: [str] = [];
|
||||
for typ: t in tps { strs += [ty_to_str(cx, typ)]; }
|
||||
s += "<" + str::connect(strs, ",") + ">";
|
||||
}
|
||||
s
|
||||
}
|
||||
ty_fn(proto, inputs, output, cf, constrs) {
|
||||
fn_to_str(cx, proto, none, inputs, output, cf, constrs)
|
||||
}
|
||||
ty_native_fn(inputs, output) {
|
||||
fn_to_str(cx, ast::proto_bare, none, inputs, output,
|
||||
ast::return_val, [])
|
||||
}
|
||||
ty_obj(meths) {
|
||||
let strs = [];
|
||||
for m: method in meths { strs += [method_to_str(cx, m)]; }
|
||||
"obj {\n\t" + str::connect(strs, "\n\t") + "\n}"
|
||||
}
|
||||
ty_res(id, _, _) { get_id_ident(cx, id) }
|
||||
ty_var(v) { "<T" + int::str(v) + ">" }
|
||||
ty_param(id, _) {
|
||||
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
|
||||
}
|
||||
_ { ty_to_short_str(cx, typ) }
|
||||
for typ: t in tps { strs += [ty_to_str(cx, typ)]; }
|
||||
s += "<" + str::connect(strs, ",") + ">";
|
||||
}
|
||||
s
|
||||
}
|
||||
ty_fn(proto, inputs, output, cf, constrs) {
|
||||
fn_to_str(cx, proto, none, inputs, output, cf, constrs)
|
||||
}
|
||||
ty_native_fn(inputs, output) {
|
||||
fn_to_str(cx, ast::proto_bare, none, inputs, output,
|
||||
ast::return_val, [])
|
||||
}
|
||||
ty_obj(meths) {
|
||||
let strs = [];
|
||||
for m: method in meths { strs += [method_to_str(cx, m)]; }
|
||||
"obj {\n\t" + str::connect(strs, "\n\t") + "\n}"
|
||||
}
|
||||
ty_res(id, _, _) { get_id_ident(cx, id) }
|
||||
ty_var(v) { "<T" + int::str(v) + ">" }
|
||||
ty_param(id, _) {
|
||||
"'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)])
|
||||
}
|
||||
_ { ty_to_short_str(cx, typ) }
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_to_short_str(cx: ctxt, typ: t) -> str {
|
||||
|
@ -109,12 +109,25 @@ pure fn is_whitespace(c: char) -> bool {
|
||||
Safety note:
|
||||
This function fails if `c` is not a valid char
|
||||
*/
|
||||
pure fn to_digit(c: char) -> u8 {
|
||||
pure fn to_digit(c: char) -> u8 unsafe {
|
||||
alt maybe_digit(c) {
|
||||
option::some(x) { x }
|
||||
option::none. { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: to_digit
|
||||
|
||||
Convert a char to the corresponding digit. Returns none when the
|
||||
character is not a valid hexadecimal digit.
|
||||
*/
|
||||
fn maybe_digit(c: char) -> option::t<u8> {
|
||||
alt c {
|
||||
'0' to '9' { c as u8 - ('0' as u8) }
|
||||
'a' to 'z' { c as u8 + 10u8 - ('a' as u8) }
|
||||
'A' to 'Z' { c as u8 + 10u8 - ('A' as u8) }
|
||||
_ { fail; }
|
||||
'0' to '9' { option::some(c as u8 - ('0' as u8)) }
|
||||
'a' to 'z' { option::some(c as u8 + 10u8 - ('a' as u8)) }
|
||||
'A' to 'Z' { option::some(c as u8 + 10u8 - ('A' as u8)) }
|
||||
_ { option::none }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,3 +63,26 @@ Function: str
|
||||
Convert to a string
|
||||
*/
|
||||
fn str(n: u64) -> str { ret to_str(n, 10u); }
|
||||
|
||||
/*
|
||||
Function: parse_buf
|
||||
|
||||
Parse a string as an unsigned integer.
|
||||
*/
|
||||
fn from_str(buf: str, radix: u64) -> u64 {
|
||||
if str::byte_len(buf) == 0u {
|
||||
log_err "parse_buf(): buf is empty";
|
||||
fail;
|
||||
}
|
||||
let i = str::byte_len(buf) - 1u;
|
||||
let power = 1u64, n = 0u64;
|
||||
while true {
|
||||
let digit = char::to_digit(buf[i] as char) as u64;
|
||||
if digit >= radix { fail; }
|
||||
n += digit * power;
|
||||
power *= radix;
|
||||
if i == 0u { ret n; }
|
||||
i -= 1u;
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
9
src/test/run-pass/big-literals.rs
Normal file
9
src/test/run-pass/big-literals.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
assert 0xffffffffu32 == (-1 as u32);
|
||||
assert 4294967295u32 == (-1 as u32);
|
||||
assert 0xffffffffffffffffu64 == (-1 as u64);
|
||||
assert 18446744073709551615u64 == (-1 as u64);
|
||||
|
||||
assert -2147483648i32 - 1i32 == 2147483647i32;
|
||||
assert -9223372036854775808i64 - 1i64 == 9223372036854775807i64;
|
||||
}
|
@ -1,82 +1,26 @@
|
||||
use std;
|
||||
import std::float;
|
||||
|
||||
import std::ctypes::*;
|
||||
|
||||
fn foo_float() -> m_float { ret 0.0 as m_float; }
|
||||
fn bar_float() -> float { be foo_float() as float; }
|
||||
|
||||
fn foo_int() -> m_int { ret 0 as m_int; }
|
||||
fn bar_int() -> int { be foo_int() as int; }
|
||||
|
||||
fn foo_uint() -> m_uint { ret 0u as m_uint; }
|
||||
fn bar_uint() -> uint { be foo_uint() as uint; }
|
||||
|
||||
fn foo_long() -> long { ret 0 as long; }
|
||||
fn bar_long() -> int { be foo_long() as int; }
|
||||
|
||||
fn foo_ulong() -> ulong { ret 0u as ulong; }
|
||||
fn bar_ulong() -> uint { be foo_uint() as uint; }
|
||||
|
||||
fn main() {
|
||||
let nan = float::NaN;
|
||||
assert(float::isNaN(nan));
|
||||
|
||||
let inf = float::infinity;
|
||||
assert(-inf == float::neg_infinity);
|
||||
|
||||
assert( nan != nan);
|
||||
assert( nan != -nan);
|
||||
assert(-nan != -nan);
|
||||
assert(-nan != nan);
|
||||
|
||||
assert( nan != 1.);
|
||||
assert( nan != 0.);
|
||||
assert( nan != inf);
|
||||
assert( nan != -inf);
|
||||
|
||||
assert( 1. != nan);
|
||||
assert( 0. != nan);
|
||||
assert( inf != nan);
|
||||
assert(-inf != nan);
|
||||
|
||||
assert(!( nan == nan));
|
||||
assert(!( nan == -nan));
|
||||
assert(!( nan == 1.));
|
||||
assert(!( nan == 0.));
|
||||
assert(!( nan == inf));
|
||||
assert(!( nan == -inf));
|
||||
assert(!( 1. == nan));
|
||||
assert(!( 0. == nan));
|
||||
assert(!( inf == nan));
|
||||
assert(!(-inf == nan));
|
||||
assert(!(-nan == nan));
|
||||
assert(!(-nan == -nan));
|
||||
|
||||
assert(!( nan > nan));
|
||||
assert(!( nan > -nan));
|
||||
assert(!( nan > 0.));
|
||||
assert(!( nan > inf));
|
||||
assert(!( nan > -inf));
|
||||
assert(!( 0. > nan));
|
||||
assert(!( inf > nan));
|
||||
assert(!(-inf > nan));
|
||||
assert(!(-nan > nan));
|
||||
|
||||
assert(!(nan < 0.));
|
||||
assert(!(nan < 1.));
|
||||
assert(!(nan < -1.));
|
||||
assert(!(nan < inf));
|
||||
assert(!(nan < -inf));
|
||||
assert(!(nan < nan));
|
||||
assert(!(nan < -nan));
|
||||
|
||||
assert(!( 0. < nan));
|
||||
assert(!( 1. < nan));
|
||||
assert(!( -1. < nan));
|
||||
assert(!( inf < nan));
|
||||
assert(!(-inf < nan));
|
||||
assert(!(-nan < nan));
|
||||
|
||||
assert(float::isNaN(nan + inf));
|
||||
assert(float::isNaN(nan + -inf));
|
||||
assert(float::isNaN(nan + 0.));
|
||||
assert(float::isNaN(nan + 1.));
|
||||
assert(float::isNaN(nan * 1.));
|
||||
assert(float::isNaN(nan / 1.));
|
||||
assert(float::isNaN(nan / 0.));
|
||||
assert(float::isNaN(0. / 0.));
|
||||
assert(float::isNaN(-inf + inf));
|
||||
assert(float::isNaN(inf - inf));
|
||||
|
||||
assert(!float::isNaN(-1.));
|
||||
assert(!float::isNaN(0.));
|
||||
assert(!float::isNaN(0.1));
|
||||
assert(!float::isNaN(1.));
|
||||
assert(!float::isNaN(inf));
|
||||
assert(!float::isNaN(-inf));
|
||||
assert(!float::isNaN(1./-inf));
|
||||
}
|
||||
assert bar_float() == 0.0;
|
||||
assert bar_int() == 0;
|
||||
assert bar_uint() == 0u;
|
||||
assert bar_long() == 0;
|
||||
assert bar_ulong() == 0u;
|
||||
}
|
@ -41,8 +41,7 @@ fn part1() {
|
||||
test(#fmt["%f", 5.82], "5.82");
|
||||
// 32-bit limits
|
||||
|
||||
// FIXME Disabled until issue 1252 is resolved.
|
||||
// test(#fmt["%i", -2147483648], "-2147483648");
|
||||
test(#fmt["%i", -2147483648], "-2147483648");
|
||||
test(#fmt["%i", 2147483647], "2147483647");
|
||||
test(#fmt["%u", 4294967295u], "4294967295");
|
||||
test(#fmt["%x", 0xffffffff_u], "ffffffff");
|
||||
|
Loading…
Reference in New Issue
Block a user