From fdbf10cd89f8f7e039d21b36a6493da8218ae995 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Thu, 27 Oct 2016 14:27:43 -0600 Subject: [PATCH] libstd prelude, take 2 --- src/lib.rs | 61 ++++++++++++++++++++++----- src/services/fs.rs | 4 +- src/{ => system}/ascii.rs | 0 src/{ => system}/error.rs | 0 src/{ => system}/ffi/c_str.rs | 27 ++++++------ src/{ => system}/ffi/mod.rs | 0 src/{ => system}/ffi/os_str.rs | 23 +++++----- src/{ => system}/io/buffered.rs | 15 +++---- src/{ => system}/io/cursor.rs | 9 ++-- src/{ => system}/io/error.rs | 11 ++--- src/{ => system}/io/impls.rs | 12 ++---- src/{ => system}/io/mod.rs | 16 +++---- src/{ => system}/io/prelude.rs | 0 src/{ => system}/io/util.rs | 2 +- src/{ => system}/memchr.rs | 0 src/system/mod.rs | 9 ++++ src/{panic.rs => system/panicking.rs} | 0 src/{ => system}/path.rs | 22 +++++----- src/system/rt.rs | 9 ++++ src/{ => system}/sys/mod.rs | 0 src/{ => system}/sys/wtf8.rs | 22 +++++----- 21 files changed, 136 insertions(+), 106 deletions(-) rename src/{ => system}/ascii.rs (100%) rename src/{ => system}/error.rs (100%) rename src/{ => system}/ffi/c_str.rs (98%) rename src/{ => system}/ffi/mod.rs (100%) rename src/{ => system}/ffi/os_str.rs (98%) rename src/{ => system}/io/buffered.rs (99%) rename src/{ => system}/io/cursor.rs (99%) rename src/{ => system}/io/error.rs (98%) rename src/{ => system}/io/impls.rs (97%) rename src/{ => system}/io/mod.rs (99%) rename src/{ => system}/io/prelude.rs (100%) rename src/{ => system}/io/util.rs (99%) rename src/{ => system}/memchr.rs (100%) create mode 100644 src/system/mod.rs rename src/{panic.rs => system/panicking.rs} (100%) rename src/{ => system}/path.rs (99%) create mode 100644 src/system/rt.rs rename src/{ => system}/sys/mod.rs (100%) rename src/{ => system}/sys/wtf8.rs (99%) diff --git a/src/lib.rs b/src/lib.rs index e02b538..1f13b99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,13 @@ #![feature(alloc)] +#![feature(allow_internal_unstable)] #![feature(collections)] +#![feature(core_intrinsics)] #![feature(char_escape_debug)] #![feature(int_error_internals)] #![feature(lang_items)] +#![feature(macro_reexport)] +#![feature(prelude_import)] +#![feature(slice_concat_ext)] #![feature(slice_patterns)] #![feature(str_internals)] #![feature(try_from)] @@ -15,26 +20,60 @@ extern crate alloc; extern crate alloc_system; -#[macro_use] extern crate collections; +#[macro_reexport(format, vec)] +#[macro_use] +extern crate collections; extern crate rustc_unicode; extern crate ctru_sys as libctru; +#[prelude_import] +#[allow(unused)] +use prelude::*; + +pub mod std { + pub use core::{any, cell, clone, cmp, convert, default, hash, i16, i32, i64, i8, isize, iter, + marker, mem, ops, option, ptr, result, u16, u32, u64, u8, usize, intrinsics}; + pub use rustc_unicode::char; + pub use alloc::{arc, rc}; + pub use collections::{borrow, boxed, fmt, slice, str, string, vec}; + pub use system::{error, io, memchr, ascii, ffi, path}; + + pub mod collections { + pub use collections::{binary_heap, btree_map, btree_set, linked_list, vec_deque, + BinaryHeap, LinkedList, VecDeque, String, Vec, BTreeMap, BTreeSet}; + } +} + +pub mod prelude { + pub use std; + pub use std::marker::{Copy, Send, Sized, Sync}; + pub use std::ops::{Drop, Fn, FnMut, FnOnce}; + pub use std::mem::drop; + pub use std::boxed::Box; + pub use std::borrow::ToOwned; + pub use std::clone::Clone; + pub use std::cmp::{PartialEq, PartialOrd, Eq, Ord}; + pub use std::convert::{AsRef, AsMut, Into, From}; + pub use std::default::Default; + pub use std::iter::{Iterator, Extend, IntoIterator}; + pub use std::iter::{DoubleEndedIterator, ExactSizeIterator}; + pub use std::option::Option::{self, Some, None}; + pub use std::result::Result::{self, Ok, Err}; + pub use std::slice::SliceConcatExt; + pub use std::string::{String, ToString}; + pub use std::vec::Vec; + pub use std::fmt::Write; +} + +pub use std::{fmt, boxed, vec}; + pub mod console; pub mod srv; pub mod gfx; pub mod services; pub mod sdmc; - -pub mod ascii; -pub mod error; -pub mod ffi; -pub mod io; -pub mod memchr; -pub mod panic; -pub mod path; - -mod sys; +pub mod system; pub use srv::Srv; pub use gfx::Gfx; diff --git a/src/services/fs.rs b/src/services/fs.rs index d4aedc4..0307dc8 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -11,8 +11,8 @@ use core::mem; use alloc::arc::Arc; use collections::Vec; -use path::{Path, PathBuf}; -use ffi::OsString; +use std::path::{Path, PathBuf}; +use std::ffi::OsString; use libctru::services::fs::*; diff --git a/src/ascii.rs b/src/system/ascii.rs similarity index 100% rename from src/ascii.rs rename to src/system/ascii.rs diff --git a/src/error.rs b/src/system/error.rs similarity index 100% rename from src/error.rs rename to src/system/error.rs diff --git a/src/ffi/c_str.rs b/src/system/ffi/c_str.rs similarity index 98% rename from src/ffi/c_str.rs rename to src/system/ffi/c_str.rs index 1acc5e7..67d37d8 100644 --- a/src/ffi/c_str.rs +++ b/src/system/ffi/c_str.rs @@ -8,22 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ascii; -use collections::borrow::{Cow, Borrow, ToOwned}; -use core::cmp::Ordering; -use error::Error; -use core::fmt::{self, Write}; -use io; +use std::ascii; +use std::borrow::{Cow, Borrow}; +use std::cmp::Ordering; +use std::error::Error; +use std::fmt::{self, Write}; +use std::io; use libctru::libc::{self, c_char}; -use core::mem; -use memchr; -use core::ops; -use core::ptr; -use core::slice; -use core::str::{self, Utf8Error}; -use alloc::boxed::Box; -use collections::Vec; -use collections::String; +use std::mem; +use system::memchr; +use std::ops; +use std::ptr; +use std::slice; +use std::str::{self, Utf8Error}; /// A type representing an owned C-compatible string /// diff --git a/src/ffi/mod.rs b/src/system/ffi/mod.rs similarity index 100% rename from src/ffi/mod.rs rename to src/system/ffi/mod.rs diff --git a/src/ffi/os_str.rs b/src/system/ffi/os_str.rs similarity index 98% rename from src/ffi/os_str.rs rename to src/system/ffi/os_str.rs index d062d55..6c0ff5e 100644 --- a/src/ffi/os_str.rs +++ b/src/system/ffi/os_str.rs @@ -8,19 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use collections::borrow::{Borrow, Cow, ToOwned}; -use core::fmt::{self, Debug}; -use core::mem; -use collections::String; -use core::ops; -use core::cmp; -use core::hash::{Hash, Hasher}; -use collections::Vec; - -use sys::wtf8::{Wtf8, Wtf8Buf}; -use sys::{AsInner, IntoInner, FromInner}; - -pub use sys::wtf8::EncodeWide; +use std::borrow::{Borrow, Cow}; +use std::fmt::{self, Debug}; +use std::mem; +use std::ops; +use std::cmp; +use std::hash::{Hash, Hasher}; + +use system::sys::wtf8::{Wtf8, Wtf8Buf}; +use system::sys::{AsInner, IntoInner, FromInner}; +pub use system::sys::wtf8::EncodeWide; /// A type that can represent owned, mutable platform-native strings, but is /// cheaply inter-convertible with Rust strings. diff --git a/src/io/buffered.rs b/src/system/io/buffered.rs similarity index 99% rename from src/io/buffered.rs rename to src/system/io/buffered.rs index 13ddddb..22588fc 100644 --- a/src/io/buffered.rs +++ b/src/system/io/buffered.rs @@ -10,16 +10,13 @@ //! Buffering wrappers for I/O traits -use io::prelude::*; +use std::io::prelude::*; -use core::cmp; -use error; -use core::fmt; -use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; -use memchr; - -use collections::boxed::Box; -use collections::Vec; +use std::cmp; +use std::error; +use std::fmt; +use std::io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +use std::memchr; /// The `BufReader` struct adds buffering to any reader. /// diff --git a/src/io/cursor.rs b/src/system/io/cursor.rs similarity index 99% rename from src/io/cursor.rs rename to src/system/io/cursor.rs index 48ec47f..99d4115 100644 --- a/src/io/cursor.rs +++ b/src/system/io/cursor.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use io::prelude::*; +use std::io::prelude::*; -use core::cmp; -use io::{self, SeekFrom, Error, ErrorKind}; - -use collections::boxed::Box; -use collections::Vec; +use std::cmp; +use std::io::{self, SeekFrom, Error, ErrorKind}; /// A `Cursor` wraps another type and provides it with a /// [`Seek`](trait.Seek.html) implementation. diff --git a/src/io/error.rs b/src/system/io/error.rs similarity index 98% rename from src/io/error.rs rename to src/system/io/error.rs index edf4894..4b99e7a 100644 --- a/src/io/error.rs +++ b/src/system/io/error.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use alloc::boxed::Box; -use core::convert::Into; -use core::fmt; -use core::marker::{Send, Sync}; -use core::option::Option::{self, Some, None}; -use core::result; -use error; + +use std::error; +use std::fmt; +use std::result; /// A specialized [`Result`](../result/enum.Result.html) type for I/O /// operations. diff --git a/src/io/impls.rs b/src/system/io/impls.rs similarity index 97% rename from src/io/impls.rs rename to src/system/io/impls.rs index afa10c8..fc39a50 100644 --- a/src/io/impls.rs +++ b/src/system/io/impls.rs @@ -8,14 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::cmp; -use io::{self, SeekFrom, Read, Write, Seek, BufRead, Error, ErrorKind}; -use core::fmt; -use core::mem; - -use collections::boxed::Box; -use collections::Vec; -use collections::String; +use std::cmp; +use std::io::{self, SeekFrom, Read, Write, Seek, BufRead, Error, ErrorKind}; +use std::fmt; +use std::mem; // ============================================================================= // Forwarding implementations diff --git a/src/io/mod.rs b/src/system/io/mod.rs similarity index 99% rename from src/io/mod.rs rename to src/system/io/mod.rs index 2002fae..0551836 100644 --- a/src/io/mod.rs +++ b/src/system/io/mod.rs @@ -247,17 +247,13 @@ //! contract. The implementation of many of these functions are subject to change over //! time and may call fewer or more syscalls/library functions. - -use core::cmp; +use std::cmp; use rustc_unicode::str as core_str; -use error as std_error; -use core::fmt; -use core::result; -use core::str; -use memchr; - -use collections::Vec; -use collections::String; +use std::error as std_error; +use std::fmt; +use std::result; +use std::str; +use std::memchr; pub use self::buffered::{BufReader, BufWriter, LineWriter}; pub use self::buffered::IntoInnerError; diff --git a/src/io/prelude.rs b/src/system/io/prelude.rs similarity index 100% rename from src/io/prelude.rs rename to src/system/io/prelude.rs diff --git a/src/io/util.rs b/src/system/io/util.rs similarity index 99% rename from src/io/util.rs rename to src/system/io/util.rs index 1bcc5a6..7b24cd4 100644 --- a/src/io/util.rs +++ b/src/system/io/util.rs @@ -10,7 +10,7 @@ #![allow(missing_copy_implementations)] -use io::{self, Read, Write, ErrorKind, BufRead}; +use std::io::{self, Read, Write, ErrorKind, BufRead}; /// Copies the entire contents of a reader into a writer. /// diff --git a/src/memchr.rs b/src/system/memchr.rs similarity index 100% rename from src/memchr.rs rename to src/system/memchr.rs diff --git a/src/system/mod.rs b/src/system/mod.rs new file mode 100644 index 0000000..637a484 --- /dev/null +++ b/src/system/mod.rs @@ -0,0 +1,9 @@ +pub mod ascii; +pub mod error; +pub mod ffi; +pub mod io; +pub mod memchr; +pub mod panicking; +pub mod path; +pub mod rt; +mod sys; diff --git a/src/panic.rs b/src/system/panicking.rs similarity index 100% rename from src/panic.rs rename to src/system/panicking.rs diff --git a/src/path.rs b/src/system/path.rs similarity index 99% rename from src/path.rs rename to src/system/path.rs index c74f1d8..4894756 100644 --- a/src/path.rs +++ b/src/system/path.rs @@ -97,21 +97,19 @@ //! normalization is possible to build on top of the components APIs, //! and will be included in this library in the near future. -use ascii::*; -use collections::borrow::{Borrow, ToOwned, Cow}; -use core::cmp; +use std::ascii::*; +use std::borrow::{Borrow, ToOwned, Cow}; +use std::cmp; //use error::Error; -use core::fmt; +use std::fmt; //use fs; -use core::hash::{Hash, Hasher}; +use std::hash::{Hash, Hasher}; //use io; -use core::iter; -use core::mem; -use core::ops::{self, Deref}; -use collections::String; -use collections::Vec; +use std::mem; +use std::ops::{self, Deref}; +use std::iter; -use ffi::{OsStr, OsString}; +use std::ffi::{OsStr, OsString}; use self::platform::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix}; @@ -134,7 +132,7 @@ use self::platform::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix}; mod platform { use super::Prefix; - use ffi::OsStr; + use std::ffi::OsStr; #[inline] pub fn is_sep_byte(b: u8) -> bool { diff --git a/src/system/rt.rs b/src/system/rt.rs new file mode 100644 index 0000000..e9514f5 --- /dev/null +++ b/src/system/rt.rs @@ -0,0 +1,9 @@ +use std::mem; + +//TODO: Handle argc/argv arguments +#[lang = "start"] +#[allow(unused_variables)] +fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { + unsafe { mem::transmute::<_, fn()>(main)(); } + 0 +} diff --git a/src/sys/mod.rs b/src/system/sys/mod.rs similarity index 100% rename from src/sys/mod.rs rename to src/system/sys/mod.rs diff --git a/src/sys/wtf8.rs b/src/system/sys/wtf8.rs similarity index 99% rename from src/sys/wtf8.rs rename to src/system/sys/wtf8.rs index 12ca7a1..0bbae42 100644 --- a/src/sys/wtf8.rs +++ b/src/system/sys/wtf8.rs @@ -27,19 +27,17 @@ use core::str::next_code_point; -use ascii::*; -use collections::borrow::Cow; +use std::ascii::*; +use std::borrow::Cow; use rustc_unicode::char; -use core::fmt; -use core::hash::{Hash, Hasher}; -use core::iter::FromIterator; -use core::mem; -use core::ops; -use collections::slice; -use core::str; -use collections::String; -use sys::AsInner; -use collections::Vec; +use std::fmt; +use std::hash::{Hash, Hasher}; +use std::iter::FromIterator; +use std::mem; +use std::ops; +use std::slice; +use std::str; +use super::AsInner; const UTF8_REPLACEMENT_CHARACTER: &'static [u8] = b"\xEF\xBF\xBD";