]> git.lizzy.rs Git - rust.git/blobdiff - example/mini_core.rs
Fix rotate_left and rotate_right with 128bit shift amount
[rust.git] / example / mini_core.rs
index f57f1ff635d701baa69937947d5d163975fdfe3f..c4834c804087199822e4552a19874744235992ef 100644 (file)
@@ -1,6 +1,7 @@
 #![feature(
     no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
-    untagged_unions, decl_macro, rustc_attrs
+    untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits,
+    thread_local,
 )]
 #![no_core]
 #![allow(dead_code)]
@@ -47,15 +48,18 @@ unsafe impl Copy for u8 {}
 unsafe impl Copy for u16 {}
 unsafe impl Copy for u32 {}
 unsafe impl Copy for u64 {}
+unsafe impl Copy for u128 {}
 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 f32 {}
 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 {}
+unsafe impl<T: Copy> Copy for Option<T> {}
 
 #[lang = "sync"]
 pub unsafe trait Sync {}
@@ -75,7 +79,19 @@ unsafe impl<'a, T: ?Sized> Sync for &'a T {}
 unsafe impl Sync for [u8; 16] {}
 
 #[lang = "freeze"]
-trait Freeze {}
+unsafe auto trait Freeze {}
+
+unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
+unsafe impl<T: ?Sized> Freeze for *const T {}
+unsafe impl<T: ?Sized> Freeze for *mut T {}
+unsafe impl<T: ?Sized> Freeze for &T {}
+unsafe impl<T: ?Sized> Freeze for &mut T {}
+
+#[lang = "structural_peq"]
+pub trait StructuralPartialEq {}
+
+#[lang = "structural_teq"]
+pub trait StructuralEq {}
 
 #[lang = "not"]
 pub trait Not {
@@ -268,6 +284,15 @@ fn ne(&self, other: &u64) -> bool {
     }
 }
 
+impl PartialEq for u128 {
+    fn eq(&self, other: &u128) -> bool {
+        (*self) == (*other)
+    }
+    fn ne(&self, other: &u128) -> bool {
+        (*self) != (*other)
+    }
+}
+
 impl PartialEq for usize {
     fn eq(&self, other: &usize) -> bool {
         (*self) == (*other)
@@ -277,6 +302,15 @@ fn ne(&self, other: &usize) -> bool {
     }
 }
 
+impl PartialEq for i8 {
+    fn eq(&self, other: &i8) -> bool {
+        (*self) == (*other)
+    }
+    fn ne(&self, other: &i8) -> bool {
+        (*self) != (*other)
+    }
+}
+
 impl PartialEq for i32 {
     fn eq(&self, other: &i32) -> bool {
         (*self) == (*other)
@@ -313,6 +347,40 @@ fn ne(&self, other: &*const T) -> bool {
     }
 }
 
+impl <T: PartialEq> PartialEq for Option<T> {
+    fn eq(&self, other: &Self) -> bool {
+        match (self, other) {
+            (Some(lhs), Some(rhs)) => *lhs == *rhs,
+            (None, None) => true,
+            _ => false,
+        }
+    }
+
+    fn ne(&self, other: &Self) -> bool {
+        match (self, other) {
+            (Some(lhs), Some(rhs)) => *lhs != *rhs,
+            (None, None) => false,
+            _ => true,
+        }
+    }
+}
+
+#[lang = "shl"]
+pub trait Shl<RHS = Self> {
+    type Output;
+
+    #[must_use]
+    fn shl(self, rhs: RHS) -> Self::Output;
+}
+
+impl Shl for u128 {
+    type Output = u128;
+
+    fn shl(self, rhs: u128) -> u128 {
+        self << rhs
+    }
+}
+
 #[lang = "neg"]
 pub trait Neg {
     type Output;
@@ -344,6 +412,14 @@ fn neg(self) -> isize {
     }
 }
 
+impl Neg for f32 {
+    type Output = f32;
+
+    fn neg(self) -> f32 {
+        -self
+    }
+}
+
 pub enum Option<T> {
     Some(T),
     None,
@@ -357,6 +433,7 @@ pub enum Option<T> {
 #[lang = "fn_once"]
 #[rustc_paren_sugar]
 pub trait FnOnce<Args> {
+    #[lang = "fn_once_output"]
     type Output;
 
     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
@@ -369,12 +446,19 @@ pub trait FnMut<Args>: FnOnce<Args> {
 }
 
 #[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)) -> ! {
+#[track_caller]
+pub fn panic(_msg: &str) -> ! {
+    unsafe {
+        libc::puts("Panicking\n\0" as *const str as *const i8);
+        intrinsics::abort();
+    }
+}
+
+#[lang = "panic_bounds_check"]
+#[track_caller]
+fn panic_bounds_check(index: usize, len: usize) -> ! {
     unsafe {
-        libc::puts("Panicking\0" as *const str as *const u8);
+        libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
         intrinsics::abort();
     }
 }
@@ -419,15 +503,11 @@ fn deref(&self) -> &Self::Target {
 }
 
 #[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 = "box_free"]
-#[inline(always)]
 unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
     libc::free(ptr as *mut u8);
 }
@@ -437,32 +517,41 @@ pub trait Drop {
     fn drop(&mut self);
 }
 
+#[lang = "manually_drop"]
+#[repr(transparent)]
+pub struct ManuallyDrop<T: ?Sized> {
+    pub value: T,
+}
+
+#[lang = "maybe_uninit"]
+#[repr(transparent)]
 pub union MaybeUninit<T> {
     pub uninit: (),
-    pub value: T,
+    pub value: ManuallyDrop<T>,
 }
 
 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 size_of_val<T: ?::Sized>(val: *const T) -> usize;
         pub fn min_align_of<T>() -> usize;
-        pub fn min_align_of_val<T: ?::Sized>(val: &T) -> usize;
+        pub fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
         pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
         pub fn transmute<T, U>(e: T) -> U;
-        pub fn init<T>() -> T;
         pub fn ctlz_nonzero<T>(x: T) -> T;
         pub fn needs_drop<T>() -> bool;
         pub fn bitreverse<T>(x: T) -> T;
         pub fn bswap<T>(x: T) -> T;
+        pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
     }
 }
 
 pub mod libc {
-    #[link(name = "c")]
+    #[cfg_attr(unix, link(name = "c"))]
+    #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
     extern "C" {
-        pub fn puts(s: *const u8);
+        pub fn puts(s: *const i8) -> i32;
         pub fn printf(format: *const i8, ...) -> i32;
         pub fn malloc(size: usize) -> *mut u8;
         pub fn free(ptr: *mut u8);
@@ -513,3 +602,29 @@ fn index(&self, index: usize) -> &Self::Output {
 #[rustc_builtin_macro]
 #[rustc_macro_transparency = "semitransparent"]
 pub macro line() { /* compiler built-in */ }
+
+#[rustc_builtin_macro]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro cfg() { /* compiler built-in */ }
+
+#[rustc_builtin_macro]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro global_asm() { /* compiler built-in */ }
+
+pub static A_STATIC: u8 = 42;
+
+#[lang = "panic_location"]
+struct PanicLocation {
+    file: &'static str,
+    line: u32,
+    column: u32,
+}
+
+#[no_mangle]
+#[cfg(not(windows))]
+pub fn get_tls() -> u8 {
+    #[thread_local]
+    static A: u8 = 42;
+
+    A
+}