This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// how pretty printer formats closures (I think; I'm unable to build from incoming right now to check) | |
fn main() { | |
do something |foo| | |
{ | |
something_long_enough_to_not; | |
fit_on_a_single_line; | |
} | |
let my_fn = || | |
{ | |
something_long_enough_to_not; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let bytes : ~[u8] = ~[1,1,1]; // for example | |
let len = vec::len(bytes)-1; | |
let mut out: u32 = 0; | |
do vec::iteri(bytes) |i, b| { | |
out += (b as u32) << (8*(len-i)) | |
} | |
io::println(u32::str(out)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! num_visitor( | |
($typ:ident) => ( | |
fn visit_$typ() -> bool { | |
self.align_to::<$typ>(); | |
do self.get::<$typ>() |i| { | |
self.out += $typ::to_str(i, 10u); | |
}; | |
self.bump_past::<$typ>(); | |
true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
fn visit_enter_enum_variant(_variant: uint, | |
_disr_val: int, | |
_n_fields: uint, | |
_name: &str) -> bool { | |
do self.get::<int>() |e| { | |
if e == _disr_val { | |
self.out += _name; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn visit_evec_uniq(_mtbl: uint, _inner: *tydesc) -> bool { | |
self.out += ~"~["; | |
self.align_to::<~[u8]>(); | |
self.visit_unboxed_vec(_mtbl, _inner); | |
self.bump_past::<~[u8]>(); | |
self.out += ~"]"; | |
true | |
} | |
fn visit_unboxed_vec(_mtbl: uint, _inner: *tydesc) -> bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn visit_estr_fixed(_n: uint, _sz: uint, | |
_align: uint) -> bool { | |
self.align(_align); | |
self.out += ~"\""; | |
unsafe { | |
self.out += str::unsafe::from_buf_len(self.ptr as *u8, _n); | |
} | |
self.bump(_sz); | |
self.out += ~"\""; | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import intrinsic::{tydesc, get_tydesc, visit_tydesc, ty_visitor}; | |
import libc::c_void; | |
trait MovablePtr { | |
fn move_ptr(adjustment: fn(*c_void) -> *c_void); | |
} | |
// FIXME #3262: this is a near-duplicate of code in core::vec. | |
type VecRepr = { | |
box_header: (uint, uint, uint, uint), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod std; // for tests | |
use reflect::*; | |
enum fmt_visitor = @{ | |
out: io::WriterUtil, | |
}; | |
// duplicated from syntax/ast.rs so as not to depend on it | |
enum mutability { m_mutbl, m_imm, m_const, } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let x = (~"a",~"b"); | |
io::println(x.second()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct C {mut d: ~[uint]} | |
fn main() { | |
let mut c = C {d: ~[1,2,3]}; | |
f(&c); | |
} | |
fn f(x: &C) { | |
for x.d.each |e| { | |
io::println(~"a"); |
OlderNewer