]>
Commit | Line | Data |
---|---|---|
c295e0f8 XL |
1 | // Compiler: |
2 | // | |
3 | // Run-time: | |
4 | // stdout: 2 | |
5 | // 7 8 | |
6 | // 10 | |
7 | ||
8 | #![allow(unused_attributes)] | |
9 | #![feature(auto_traits, lang_items, no_core, start, intrinsics, track_caller)] | |
10 | ||
11 | #![no_std] | |
12 | #![no_core] | |
13 | ||
14 | /* | |
15 | * Core | |
16 | */ | |
17 | ||
18 | // Because we don't have core yet. | |
19 | #[lang = "sized"] | |
20 | pub trait Sized {} | |
21 | ||
22 | #[lang = "copy"] | |
23 | trait Copy { | |
24 | } | |
25 | ||
26 | impl Copy for isize {} | |
27 | impl Copy for *mut i32 {} | |
28 | impl Copy for usize {} | |
29 | impl Copy for u8 {} | |
30 | impl Copy for i8 {} | |
31 | impl Copy for i32 {} | |
32 | ||
33 | #[lang = "receiver"] | |
34 | trait Receiver { | |
35 | } | |
36 | ||
37 | #[lang = "freeze"] | |
38 | pub(crate) unsafe auto trait Freeze {} | |
39 | ||
40 | #[lang = "panic_location"] | |
41 | struct PanicLocation { | |
42 | file: &'static str, | |
43 | line: u32, | |
44 | column: u32, | |
45 | } | |
46 | ||
47 | mod libc { | |
48 | #[link(name = "c")] | |
49 | extern "C" { | |
50 | pub fn puts(s: *const u8) -> i32; | |
51 | pub fn fflush(stream: *mut i32) -> i32; | |
52 | pub fn printf(format: *const i8, ...) -> i32; | |
53 | ||
ee023bcb | 54 | pub static stdout: *mut i32; |
c295e0f8 XL |
55 | } |
56 | } | |
57 | ||
58 | mod intrinsics { | |
59 | extern "rust-intrinsic" { | |
60 | pub fn abort() -> !; | |
61 | } | |
62 | } | |
63 | ||
64 | #[lang = "panic"] | |
65 | #[track_caller] | |
66 | #[no_mangle] | |
67 | pub fn panic(_msg: &str) -> ! { | |
68 | unsafe { | |
69 | libc::puts("Panicking\0" as *const str as *const u8); | |
ee023bcb | 70 | libc::fflush(libc::stdout); |
c295e0f8 XL |
71 | intrinsics::abort(); |
72 | } | |
73 | } | |
74 | ||
75 | #[lang = "add"] | |
76 | trait Add<RHS = Self> { | |
77 | type Output; | |
78 | ||
79 | fn add(self, rhs: RHS) -> Self::Output; | |
80 | } | |
81 | ||
82 | impl Add for u8 { | |
83 | type Output = Self; | |
84 | ||
85 | fn add(self, rhs: Self) -> Self { | |
86 | self + rhs | |
87 | } | |
88 | } | |
89 | ||
90 | impl Add for i8 { | |
91 | type Output = Self; | |
92 | ||
93 | fn add(self, rhs: Self) -> Self { | |
94 | self + rhs | |
95 | } | |
96 | } | |
97 | ||
98 | impl Add for i32 { | |
99 | type Output = Self; | |
100 | ||
101 | fn add(self, rhs: Self) -> Self { | |
102 | self + rhs | |
103 | } | |
104 | } | |
105 | ||
106 | impl Add for usize { | |
107 | type Output = Self; | |
108 | ||
109 | fn add(self, rhs: Self) -> Self { | |
110 | self + rhs | |
111 | } | |
112 | } | |
113 | ||
114 | impl Add for isize { | |
115 | type Output = Self; | |
116 | ||
117 | fn add(self, rhs: Self) -> Self { | |
118 | self + rhs | |
119 | } | |
120 | } | |
121 | ||
122 | /* | |
123 | * Code | |
124 | */ | |
125 | ||
126 | fn inc_ref(num: &mut isize) -> isize { | |
127 | *num = *num + 5; | |
128 | *num + 1 | |
129 | } | |
130 | ||
131 | fn inc(num: isize) -> isize { | |
132 | num + 1 | |
133 | } | |
134 | ||
135 | ||
136 | #[start] | |
137 | fn main(mut argc: isize, _argv: *const *const u8) -> isize { | |
138 | argc = inc(argc); | |
139 | unsafe { | |
140 | libc::printf(b"%ld\n\0" as *const u8 as *const i8, argc); | |
141 | } | |
142 | ||
143 | let b = inc_ref(&mut argc); | |
144 | unsafe { | |
145 | libc::printf(b"%ld %ld\n\0" as *const u8 as *const i8, argc, b); | |
146 | } | |
147 | ||
148 | argc = 10; | |
149 | unsafe { | |
150 | libc::printf(b"%ld\n\0" as *const u8 as *const i8, argc); | |
151 | } | |
152 | 0 | |
153 | } |