(index<- ) ./libgreen/macros.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri Apr 25 22:40:04 2014
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // FIXME: this file probably shouldn't exist
12
13 #![macro_escape]
14
15 use std::fmt;
16
17 // Indicates whether we should perform expensive sanity checks, including rtassert!
18 // FIXME: Once the runtime matures remove the `true` below to turn off rtassert, etc.
19 pub static ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert);
20
21 macro_rules! rterrln (
22 ($($arg:tt)*) => ( {
23 format_args!(::macros::dumb_println, $($arg)*)
24 } )
25 )
26
27 // Some basic logging. Enabled by passing `--cfg rtdebug` to the libstd build.
28 macro_rules! rtdebug (
29 ($($arg:tt)*) => ( {
30 if cfg!(rtdebug) {
31 rterrln!($($arg)*)
32 }
33 })
34 )
35
36 macro_rules! rtassert (
37 ( $arg:expr ) => ( {
38 if ::macros::ENFORCE_SANITY {
39 if !$arg {
40 rtabort!(" assertion failed: {}", stringify!($arg));
41 }
42 }
43 } )
44 )
45
46
47 macro_rules! rtabort (
48 ($($arg:tt)*) => ( {
49 ::macros::abort(format!($($arg)*));
50 } )
51 )
52
53 pub fn dumb_println(args: &fmt::Arguments) {
54 use std::io;
55 use std::rt;
56
57 let mut w = rt::Stderr;
58 let _ = fmt::writeln(&mut w as &mut io::Writer, args);
59 }
60
61 pub fn abort(msg: &str) -> ! {
62 let msg = if !msg.is_empty() { msg } else { "aborted" };
63 let hash = msg.chars().fold(0, |accum, val| accum + (val as uint) );
64 let quote = match hash % 10 {
65 0 => "
66 It was from the artists and poets that the pertinent answers came, and I
67 know that panic would have broken loose had they been able to compare notes.
68 As it was, lacking their original letters, I half suspected the compiler of
69 having asked leading questions, or of having edited the correspondence in
70 corroboration of what he had latently resolved to see.",
71 1 => "
72 There are not many persons who know what wonders are opened to them in the
73 stories and visions of their youth; for when as children we listen and dream,
74 we think but half-formed thoughts, and when as men we try to remember, we are
75 dulled and prosaic with the poison of life. But some of us awake in the night
76 with strange phantasms of enchanted hills and gardens, of fountains that sing
77 in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch
78 down to sleeping cities of bronze and stone, and of shadowy companies of heroes
79 that ride caparisoned white horses along the edges of thick forests; and then
80 we know that we have looked back through the ivory gates into that world of
81 wonder which was ours before we were wise and unhappy.",
82 2 => "
83 Instead of the poems I had hoped for, there came only a shuddering blackness
84 and ineffable loneliness; and I saw at last a fearful truth which no one had
85 ever dared to breathe before â the unwhisperable secret of secrets â The fact
86 that this city of stone and stridor is not a sentient perpetuation of Old New
87 York as London is of Old London and Paris of Old Paris, but that it is in fact
88 quite dead, its sprawling body imperfectly embalmed and infested with queer
89 animate things which have nothing to do with it as it was in life.",
90 3 => "
91 The ocean ate the last of the land and poured into the smoking gulf, thereby
92 giving up all it had ever conquered. From the new-flooded lands it flowed
93 again, uncovering death and decay; and from its ancient and immemorial bed it
94 trickled loathsomely, uncovering nighted secrets of the years when Time was
95 young and the gods unborn. Above the waves rose weedy remembered spires. The
96 moon laid pale lilies of light on dead London, and Paris stood up from its damp
97 grave to be sanctified with star-dust. Then rose spires and monoliths that were
98 weedy but not remembered; terrible spires and monoliths of lands that men never
99 knew were lands...",
100 4 => "
101 There was a night when winds from unknown spaces whirled us irresistibly into
102 limitless vacuum beyond all thought and entity. Perceptions of the most
103 maddeningly untransmissible sort thronged upon us; perceptions of infinity
104 which at the time convulsed us with joy, yet which are now partly lost to my
105 memory and partly incapable of presentation to others.",
106 _ => "You've met with a terrible fate, haven't you?"
107 };
108 rterrln!("{}", "");
109 rterrln!("{}", quote);
110 rterrln!("{}", "");
111 rterrln!("fatal runtime error: {}", msg);
112
113 abort();
114
115 fn abort() -> ! {
116 use std::intrinsics;
117 unsafe { intrinsics::abort() }
118 }
119 }