提交 6267d8a9 编写于 作者: B Brian Anderson

core: De-export at_vec and extfmt

上级 f3d6c506
......@@ -2,34 +2,24 @@
use ptr::addr_of;
export init_op;
export capacity;
export build_sized, build, build_sized_opt;
export map;
export from_fn, from_elem;
export raw;
export traits;
/// Code for dealing with @-vectors. This is pretty incomplete, and
/// contains a bunch of duplication from the code for ~-vectors.
#[abi = "cdecl"]
extern mod rustrt {
#[legacy_exports];
fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
pub fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
++v: **vec::raw::VecRepr,
++n: libc::size_t);
}
#[abi = "rust-intrinsic"]
extern mod rusti {
#[legacy_exports];
fn move_val_init<T>(&dst: T, -src: T);
pub fn move_val_init<T>(&dst: T, -src: T);
}
/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pure fn capacity<T>(&&v: @[const T]) -> uint {
pub pure fn capacity<T>(&&v: @[const T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(v));
......@@ -50,7 +40,8 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
pub pure fn build_sized<A>(size: uint,
builder: fn(push: pure fn(+A))) -> @[A] {
let mut vec = @[];
unsafe { raw::reserve(vec, size); }
builder(|+x| unsafe { raw::push(vec, move x) });
......@@ -68,7 +59,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
pub pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
build_sized(4, builder)
}
......@@ -85,7 +76,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pure fn build_sized_opt<A>(size: Option<uint>,
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: fn(push: pure fn(+A))) -> @[A] {
build_sized(size.get_default(4), builder)
}
......@@ -101,7 +92,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
/// Apply a function to each element of a vector and return the results
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
pub pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
do build_sized(v.len()) |push| {
for vec::each(v) |elem| {
push(f(*elem));
......@@ -115,7 +106,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }
......@@ -128,7 +119,7 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
pub pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(t); i += 1u; }
......@@ -137,7 +128,6 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
#[cfg(notest)]
mod traits {
#[legacy_exports];
#[cfg(stage0)]
impl<T: Copy> @[T]: Add<&[const T],@[T]> {
#[inline(always)]
......@@ -159,10 +149,9 @@ impl<T: Copy> @[T] : Add<&[const T],@[T]> {
mod traits {
#[legacy_exports];}
mod raw {
#[legacy_exports];
type VecRepr = vec::raw::VecRepr;
type SliceRepr = vec::raw::SliceRepr;
pub mod raw {
pub type VecRepr = vec::raw::VecRepr;
pub type SliceRepr = vec::raw::SliceRepr;
/**
* Sets the length of a vector
......@@ -172,13 +161,13 @@ mod raw {
* the vector is actually the specified size.
*/
#[inline(always)]
unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
pub unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}
#[inline(always)]
unsafe fn push<T>(&v: @[const T], +initval: T) {
pub unsafe fn push<T>(&v: @[const T], +initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
let fill = (**repr).unboxed.fill;
if (**repr).unboxed.alloc > fill {
......@@ -215,7 +204,7 @@ unsafe fn push_slow<T>(&v: @[const T], +initval: T) {
* * v - A vector
* * n - The number of elements to reserve space for
*/
unsafe fn reserve<T>(&v: @[const T], n: uint) {
pub unsafe fn reserve<T>(&v: @[const T], n: uint) {
// Only make the (slow) call into the runtime if we have to
if capacity(v) < n {
let ptr = addr_of(v) as **VecRepr;
......@@ -239,7 +228,7 @@ unsafe fn reserve<T>(&v: @[const T], n: uint) {
* * v - A vector
* * n - The number of elements to reserve space for
*/
unsafe fn reserve_at_least<T>(&v: @[const T], n: uint) {
pub unsafe fn reserve_at_least<T>(&v: @[const T], n: uint) {
reserve(v, uint::next_power_of_two(n));
}
......
......@@ -41,37 +41,36 @@
*/
// Functions used by the fmt extension at compile time
mod ct {
#[legacy_exports];
enum Signedness { Signed, Unsigned, }
enum Caseness { CaseUpper, CaseLower, }
enum Ty {
TyBool,
TyStr,
TyChar,
TyInt(Signedness),
TyBits,
TyHex(Caseness),
TyOctal,
TyFloat,
TyPoly,
}
enum Flag {
FlagLeftJustify,
FlagLeftZeroPad,
FlagSpaceForSign,
FlagSignAlways,
FlagAlternate,
}
enum Count {
CountIs(int),
CountIsParam(int),
CountIsNextParam,
CountImplied,
pub mod ct {
pub enum Signedness { pub Signed, pub Unsigned, }
pub enum Caseness { pub CaseUpper, pub CaseLower, }
pub enum Ty {
pub TyBool,
pub TyStr,
pub TyChar,
pub TyInt(Signedness),
pub TyBits,
pub TyHex(Caseness),
pub TyOctal,
pub TyFloat,
pub TyPoly,
}
pub enum Flag {
pub FlagLeftJustify,
pub FlagLeftZeroPad,
pub FlagSpaceForSign,
pub FlagSignAlways,
pub FlagAlternate,
}
pub enum Count {
pub CountIs(int),
pub CountIsParam(int),
pub CountIsNextParam,
pub CountImplied,
}
// A formatted conversion from an expression to a string
type Conv =
pub type Conv =
{param: Option<int>,
flags: ~[Flag],
width: Count,
......@@ -80,10 +79,10 @@ enum Count {
// A fragment of the output sequence
enum Piece { PieceString(~str), PieceConv(Conv), }
type ErrorFn = fn@(~str) -> ! ;
pub enum Piece { PieceString(~str), PieceConv(Conv), }
pub type ErrorFn = fn@(~str) -> ! ;
fn parse_fmt_string(s: ~str, error: ErrorFn) -> ~[Piece] {
pub fn parse_fmt_string(s: ~str, error: ErrorFn) -> ~[Piece] {
let mut pieces: ~[Piece] = ~[];
let lim = str::len(s);
let mut buf = ~"";
......@@ -273,21 +272,26 @@ fn parse_type(s: ~str, i: uint, lim: uint, error: ErrorFn) ->
// decisions made a runtime. If it proves worthwhile then some of these
// conditions can be evaluated at compile-time. For now though it's cleaner to
// implement it 0this way, I think.
mod rt {
#[legacy_exports];
const flag_none : u32 = 0u32;
const flag_left_justify : u32 = 0b00000000000000000000000000000001u32;
const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32;
const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32;
const flag_sign_always : u32 = 0b00000000000000000000000000001000u32;
const flag_alternate : u32 = 0b00000000000000000000000000010000u32;
enum Count { CountIs(int), CountImplied, }
enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pure fn conv_int(cv: Conv, i: int) -> ~str {
pub mod rt {
pub const flag_none: u32 = 0u32;
pub const flag_left_justify : u32 = 0b00000000000000000000000000000001u32;
pub const flag_left_zero_pad: u32 = 0b00000000000000000000000000000010u32;
pub const flag_space_for_sign:u32 = 0b00000000000000000000000000000100u32;
pub const flag_sign_always : u32 = 0b00000000000000000000000000001000u32;
pub const flag_alternate : u32 = 0b00000000000000000000000000010000u32;
pub enum Count { pub CountIs(int), pub CountImplied, }
pub enum Ty {
pub TyDefault,
pub TyBits,
pub TyHexUpper,
pub TyHexLower,
pub TyOctal
}
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
let radix = 10u;
let prec = get_int_precision(cv);
let mut s : ~str = int_to_str_prec(i, radix, prec);
......@@ -300,7 +304,7 @@ enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
}
return unsafe { pad(cv, s, PadSigned) };
}
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
let mut rs =
match cv.ty {
......@@ -312,17 +316,17 @@ enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
};
return unsafe { pad(cv, rs, PadUnsigned) };
}
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
let s = if b { ~"true" } else { ~"false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
return conv_str(cv, s);
}
pure fn conv_char(cv: Conv, c: char) -> ~str {
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
}
pure fn conv_str(cv: Conv, s: &str) -> ~str {
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = match cv.precision {
......@@ -335,7 +339,7 @@ enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
};
return unsafe { pad(cv, unpadded, PadNozero) };
}
pure fn conv_float(cv: Conv, f: float) -> ~str {
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
let (to_str, digits) = match cv.precision {
CountIs(c) => (float::to_str_exact, c as uint),
CountImplied => (float::to_str, 6u)
......@@ -350,7 +354,7 @@ enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
}
return unsafe { pad(cv, s, PadFloat) };
}
pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
pub pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
let s = sys::log_str(&v);
return conv_str(cv, s);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册