357 lines
7.5 KiB
Rust
357 lines
7.5 KiB
Rust
#![feature(no_core, lang_items, intrinsics, unboxed_closures, type_ascription)]
|
|
#![no_core]
|
|
#![allow(dead_code)]
|
|
|
|
#[lang = "sized"]
|
|
pub trait Sized {}
|
|
|
|
#[lang = "unsize"]
|
|
pub trait Unsize<T: ?Sized> {}
|
|
|
|
#[lang = "coerce_unsized"]
|
|
pub trait CoerceUnsized<T> {}
|
|
|
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
|
|
|
#[lang = "dispatch_from_dyn"]
|
|
pub trait DispatchFromDyn<T> {}
|
|
|
|
// &T -> &U
|
|
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
|
|
// &mut T -> &mut U
|
|
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
|
|
// *const T -> *const U
|
|
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
|
|
// *mut T -> *mut U
|
|
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
|
|
|
|
#[lang = "receiver"]
|
|
pub trait Receiver {}
|
|
|
|
impl<T: ?Sized> Receiver for &T {}
|
|
impl<T: ?Sized> Receiver for &mut T {}
|
|
impl<T: ?Sized> Receiver for Box<T> {}
|
|
|
|
#[lang = "copy"]
|
|
pub unsafe trait Copy {}
|
|
|
|
unsafe impl Copy for bool {}
|
|
unsafe impl Copy for u8 {}
|
|
unsafe impl Copy for u16 {}
|
|
unsafe impl Copy for u32 {}
|
|
unsafe impl Copy for u64 {}
|
|
unsafe impl Copy for usize {}
|
|
unsafe impl Copy for i8 {}
|
|
unsafe impl Copy for i16 {}
|
|
unsafe impl Copy for i32 {}
|
|
unsafe impl Copy for isize {}
|
|
unsafe impl Copy for char {}
|
|
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
|
|
unsafe impl<T: ?Sized> Copy for *const T {}
|
|
unsafe impl<T: ?Sized> Copy for *mut T {}
|
|
|
|
#[lang = "sync"]
|
|
pub unsafe trait Sync {}
|
|
|
|
unsafe impl Sync for bool {}
|
|
unsafe impl Sync for u8 {}
|
|
unsafe impl Sync for u16 {}
|
|
unsafe impl Sync for u32 {}
|
|
unsafe impl Sync for u64 {}
|
|
unsafe impl Sync for usize {}
|
|
unsafe impl Sync for i8 {}
|
|
unsafe impl Sync for i16 {}
|
|
unsafe impl Sync for i32 {}
|
|
unsafe impl Sync for isize {}
|
|
unsafe impl Sync for char {}
|
|
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
|
|
unsafe impl Sync for [u8; 16] {}
|
|
|
|
#[lang = "freeze"]
|
|
trait Freeze {}
|
|
|
|
#[lang = "not"]
|
|
pub trait Not {
|
|
type Output;
|
|
|
|
fn not(self) -> Self::Output;
|
|
}
|
|
|
|
impl Not for bool {
|
|
type Output = bool;
|
|
|
|
fn not(self) -> bool {
|
|
!self
|
|
}
|
|
}
|
|
|
|
#[lang = "mul"]
|
|
pub trait Mul<RHS = Self> {
|
|
type Output;
|
|
|
|
#[must_use]
|
|
fn mul(self, rhs: RHS) -> Self::Output;
|
|
}
|
|
|
|
impl Mul for u8 {
|
|
type Output = Self;
|
|
|
|
fn mul(self, rhs: Self) -> Self::Output {
|
|
self * rhs
|
|
}
|
|
}
|
|
|
|
#[lang = "add"]
|
|
pub trait Add<RHS = Self> {
|
|
type Output;
|
|
|
|
fn add(self, rhs: RHS) -> Self::Output;
|
|
}
|
|
|
|
impl Add for u8 {
|
|
type Output = Self;
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
self + rhs
|
|
}
|
|
}
|
|
|
|
impl Add for usize {
|
|
type Output = Self;
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
self + rhs
|
|
}
|
|
}
|
|
|
|
#[lang = "sub"]
|
|
pub trait Sub<RHS = Self> {
|
|
type Output;
|
|
|
|
fn sub(self, rhs: RHS) -> Self::Output;
|
|
}
|
|
|
|
impl Sub for usize {
|
|
type Output = Self;
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
|
self - rhs
|
|
}
|
|
}
|
|
|
|
#[lang = "bitor"]
|
|
pub trait BitOr<RHS = Self> {
|
|
type Output;
|
|
|
|
#[must_use]
|
|
fn bitor(self, rhs: RHS) -> Self::Output;
|
|
}
|
|
|
|
impl BitOr for bool {
|
|
type Output = bool;
|
|
|
|
fn bitor(self, rhs: bool) -> bool {
|
|
self | rhs
|
|
}
|
|
}
|
|
|
|
impl<'a> BitOr<bool> for &'a bool {
|
|
type Output = bool;
|
|
|
|
fn bitor(self, rhs: bool) -> bool {
|
|
*self | rhs
|
|
}
|
|
}
|
|
|
|
#[lang = "eq"]
|
|
pub trait PartialEq<Rhs: ?Sized = Self> {
|
|
fn eq(&self, other: &Rhs) -> bool;
|
|
fn ne(&self, other: &Rhs) -> bool;
|
|
}
|
|
|
|
impl PartialEq for u8 {
|
|
fn eq(&self, other: &u8) -> bool {
|
|
(*self) == (*other)
|
|
}
|
|
fn ne(&self, other: &u8) -> bool {
|
|
(*self) != (*other)
|
|
}
|
|
}
|
|
|
|
impl PartialEq for u16 {
|
|
fn eq(&self, other: &u16) -> bool {
|
|
(*self) == (*other)
|
|
}
|
|
fn ne(&self, other: &u16) -> bool {
|
|
(*self) != (*other)
|
|
}
|
|
}
|
|
|
|
impl PartialEq for u32 {
|
|
fn eq(&self, other: &u32) -> bool {
|
|
(*self) == (*other)
|
|
}
|
|
fn ne(&self, other: &u32) -> bool {
|
|
(*self) != (*other)
|
|
}
|
|
}
|
|
|
|
impl PartialEq for usize {
|
|
fn eq(&self, other: &usize) -> bool {
|
|
(*self) == (*other)
|
|
}
|
|
fn ne(&self, other: &usize) -> bool {
|
|
(*self) != (*other)
|
|
}
|
|
}
|
|
|
|
impl PartialEq for char {
|
|
fn eq(&self, other: &char) -> bool {
|
|
(*self) == (*other)
|
|
}
|
|
fn ne(&self, other: &char) -> bool {
|
|
(*self) != (*other)
|
|
}
|
|
}
|
|
|
|
impl<T: ?Sized> PartialEq for *const T {
|
|
fn eq(&self, other: &*const T) -> bool {
|
|
*self == *other
|
|
}
|
|
fn ne(&self, other: &*const T) -> bool {
|
|
*self != *other
|
|
}
|
|
}
|
|
|
|
#[lang = "neg"]
|
|
pub trait Neg {
|
|
type Output;
|
|
|
|
fn neg(self) -> Self::Output;
|
|
}
|
|
|
|
impl Neg for isize {
|
|
type Output = isize;
|
|
|
|
fn neg(self) -> isize {
|
|
-self
|
|
}
|
|
}
|
|
|
|
pub enum Option<T> {
|
|
Some(T),
|
|
None,
|
|
}
|
|
|
|
pub use Option::*;
|
|
|
|
#[lang = "phantom_data"]
|
|
pub struct PhantomData<T: ?Sized>;
|
|
|
|
#[lang = "fn_once"]
|
|
#[rustc_paren_sugar]
|
|
pub trait FnOnce<Args> {
|
|
type Output;
|
|
|
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
|
}
|
|
|
|
#[lang = "fn_mut"]
|
|
#[rustc_paren_sugar]
|
|
pub trait FnMut<Args>: FnOnce<Args> {
|
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
|
}
|
|
|
|
#[lang = "panic"]
|
|
// Make it available to jited mini_core_hello_world
|
|
// FIXME remove next line when jit supports linking rlibs
|
|
#[inline(always)]
|
|
pub fn panic(&(_msg, _file, _line, _col): &(&'static str, &'static str, u32, u32)) -> ! {
|
|
unsafe {
|
|
libc::puts("Panicking\0" as *const str as *const u8);
|
|
intrinsics::abort();
|
|
}
|
|
}
|
|
|
|
#[lang = "eh_personality"]
|
|
fn eh_personality() -> ! {
|
|
loop {}
|
|
}
|
|
|
|
#[lang = "drop_in_place"]
|
|
#[allow(unconditional_recursion)]
|
|
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|
// Code here does not matter - this is replaced by the
|
|
// real drop glue by the compiler.
|
|
drop_in_place(to_drop);
|
|
}
|
|
|
|
#[lang = "owned_box"]
|
|
pub struct Box<T: ?Sized>(*mut T);
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
|
|
|
#[lang = "exchange_malloc"]
|
|
// Make it available to jited mini_core_hello_world
|
|
// FIXME remove next line when jit supports linking rlibs
|
|
#[inline(always)]
|
|
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
|
libc::malloc(size)
|
|
}
|
|
|
|
#[lang = "drop"]
|
|
pub trait Drop {
|
|
fn drop(&mut self);
|
|
}
|
|
|
|
pub mod intrinsics {
|
|
extern "rust-intrinsic" {
|
|
pub fn abort() -> !;
|
|
pub fn size_of<T>() -> usize;
|
|
pub fn size_of_val<T: ?::Sized>(val: &T) -> usize;
|
|
pub fn min_align_of<T>() -> usize;
|
|
pub fn min_align_of_val<T: ?::Sized>(val: &T) -> usize;
|
|
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
|
pub fn transmute<T, U>(e: T) -> U;
|
|
pub fn uninit<T>() -> T;
|
|
pub fn ctlz_nonzero<T>(x: T) -> T;
|
|
pub fn needs_drop<T>() -> bool;
|
|
}
|
|
}
|
|
|
|
pub mod libc {
|
|
#[link(name = "c")]
|
|
extern "C" {
|
|
pub fn puts(s: *const u8);
|
|
pub fn malloc(size: usize) -> *mut u8;
|
|
pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
|
|
pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
|
|
pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
|
|
}
|
|
}
|
|
|
|
#[lang = "index"]
|
|
pub trait Index<Idx: ?Sized> {
|
|
type Output: ?Sized;
|
|
fn index(&self, index: Idx) -> &Self::Output;
|
|
}
|
|
|
|
impl<T> Index<usize> for [T; 3] {
|
|
type Output = T;
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
&self[index]
|
|
}
|
|
}
|
|
|
|
impl<T> Index<usize> for [T] {
|
|
type Output = T;
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
&self[index]
|
|
}
|
|
}
|