Skip to content

Commit 93524c9

Browse files
committed
---
yaml --- r: 138937 b: refs/heads/try2 c: a95b933 h: refs/heads/master i: 138935: da0d66a v: v3
1 parent 6d840aa commit 93524c9

37 files changed

+3156
-422
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a21b43c6bbb0edcf4dfe9913a084f28eb950b364
8+
refs/heads/try2: a95b933350e1e403c8a4118977049e38505f2a90
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/RELEASES.txt

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,85 @@
1-
Version 0.6 (?)
1+
Version 0.6 (March 2013)
22
---------------------------
33

4+
* ~??? changes, numerous bugfixes
5+
6+
* TODO:
7+
* Ord/Cmp
8+
* Lifetime changes
9+
* Implicit self
10+
* Remove `static` keyword
11+
* Static method syntax
12+
* `as Trait`
13+
* `copy` removed?
14+
15+
* Syntax changes
16+
* The self type parameter in traits is now spelled `Self`
17+
* Replaced the `Durable` trait with the `'static` lifetime
18+
* The old closure type syntax with the trailing sigil has been
19+
removed in favor of the more consistent leading sigil
20+
* `super` is a keyword, and may be prefixed to paths
21+
* Trait bounds are separated with `+` instead of whitespace
22+
* Traits are implemented with `impl Trait for Type`
23+
instead of `impl Type: Trait`
24+
* The `export` keyword has finally been removed
25+
* The `move` keyword has been removed (linear types move by default)
26+
* The interior mutability qualifier on vectors, `[mut T]`, has been
27+
removed. Use `&mut [T]`, etc.
28+
* `mut` is no longer valid in `~mut T`. Use inherited mutability
29+
* `fail` is no longer a keyword. Use `fail!()`
30+
* `assert` is no longer a keyword. Use `assert!()`
31+
* `log` is no longer a keyword. use `debug!`, etc.
32+
* 1-tuples may be represented as `(T,)`
33+
* Struct fields may no longer be `mut`. Use inherited mutability,
34+
`@mut T`, `core::mut` or `core::cell`
35+
* `extern mod { ... }` is no longer valid syntax for foreign
36+
function modules. Use extern blocks: `extern { ... }`
37+
* Newtype enums removed. Used tuple-structs.
38+
* Trait implementations no longer support visibility modifiers
39+
40+
* Semantic changes
41+
* Linear types move by default, eliminating the `move` keyword
42+
* All foreign functions are considered unsafe
43+
* &mut is now unaliasable
44+
* Writes to borrowed @mut pointers are prevented dynamically
45+
* () has size 0
46+
* The name of the main function can be customized using #[main]
47+
* The default type of an inferred closure is &fn instead of @fn
48+
* Name resolution continues to be tweaked
49+
* Method visibility is inherited from the implementation declaration
50+
51+
* Other language changes
52+
* Structural records have been removed
53+
* Many more types can be used in constants, including enums
54+
`static lifetime pointers and vectors
55+
* Pattern matching over vectors improved and expanded
56+
* Typechecking of closure types has been overhauled to
57+
improve inference and eliminate unsoundness
58+
459
* Libraries
5-
* `core::send_map` renamed to `core::hashmap`
60+
* Lots of effort to organize the container API's around `core::container`
61+
* `core::send_map` renamed to `core::hashmap`
62+
* Added big integers to `std::bigint`
63+
* Removed `core::oldcomm` module
64+
* Added pipe-based `core::comm` module
65+
* Reimplemented `std::treemap`
66+
* Numeric traits have been reorganized under `core::num`
67+
* `core::dvec` removed. Use `@mut ~[T]` or other language types
68+
* `vec::slice` finally returns a slice
69+
* `debug!` and friends don't require a format string, e.g. `debug!(Foo)`
70+
71+
* Tools
72+
* Replaced the 'cargo' package manager with 'rustpkg'
73+
* Added all-purpose 'rust' tool
74+
* `rustc --test` now supports a benchmarks with the `#[bench]` attribute
75+
* rustc now attempts to offer spelling suggestions
76+
77+
* Misc
78+
* Improved support for ARM and Android
79+
* Preliminary MIPS backend
80+
* Improved foreign function ABI implementation for x86, x86_64
81+
* Various and memory usage improvements
82+
* Rust code may be embedded in foreign code under limited circumstances
683

784
Version 0.5 (December 2012)
885
---------------------------

branches/try2/src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ pub mod unicode;
243243
#[path = "num/cmath.rs"]
244244
pub mod cmath;
245245
pub mod stackwalk;
246-
246+
#[path = "rt/mod.rs"]
247+
pub mod rt;
247248

248249
// A curious inner-module that's not exported that contains the binding
249250
// 'core' so that macro-expanded references to core::error and such

branches/try2/src/libcore/option.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
143143
}
144144
}
145145
146+
pub pure fn get_mut_ref<T>(opt: &r/mut Option<T>) -> &r/mut T {
147+
/*!
148+
Gets a mutable reference to the value inside an option.
149+
150+
# Failure
151+
152+
Fails if the value equals `None`
153+
154+
# Safety note
155+
156+
In general, because this function may fail, its use is discouraged
157+
(calling `get` on `None` is akin to dereferencing a null pointer).
158+
Instead, prefer to use pattern matching and handle the `None`
159+
case explicitly.
160+
*/
161+
match *opt {
162+
Some(ref mut x) => x,
163+
None => fail!(~"option::get_mut_ref none")
164+
}
165+
}
166+
146167
#[inline(always)]
147168
pub pure fn map<T, U>(opt: &r/Option<T>, f: &fn(x: &r/T) -> U) -> Option<U> {
148169
//! Maps a `some` value by reference from one type to another
@@ -377,6 +398,23 @@ pub impl<T> Option<T> {
377398
#[inline(always)]
378399
pure fn get_ref(&self) -> &self/T { get_ref(self) }
379400
401+
/**
402+
Gets a mutable reference to the value inside an option.
403+
404+
# Failure
405+
406+
Fails if the value equals `None`
407+
408+
# Safety note
409+
410+
In general, because this function may fail, its use is discouraged
411+
(calling `get` on `None` is akin to dereferencing a null pointer).
412+
Instead, prefer to use pattern matching and handle the `None`
413+
case explicitly.
414+
*/
415+
#[inline(always)]
416+
pure fn get_mut_ref(&mut self) -> &self/mut T { get_mut_ref(self) }
417+
380418
/**
381419
* Gets the value out of an option without copying.
382420
*
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
use super::stack::StackSegment;
12+
use libc::c_void;
13+
use cast::{transmute, transmute_mut_unsafe,
14+
transmute_region, transmute_mut_region};
15+
16+
// XXX: Registers is boxed so that it is 16-byte aligned, for storing
17+
// SSE regs. It would be marginally better not to do this. In C++ we
18+
// use an attribute on a struct.
19+
pub struct Context(~Registers);
20+
21+
pub impl Context {
22+
static fn empty() -> Context {
23+
Context(new_regs())
24+
}
25+
26+
/// Create a new context that will resume execution by running ~fn()
27+
/// # Safety Note
28+
/// The `start` closure must remain valid for the life of the Task
29+
static fn new(start: &~fn(), stack: &mut StackSegment) -> Context {
30+
31+
// The C-ABI function that is the task entry point
32+
extern fn task_start_wrapper(f: &~fn()) { (*f)() }
33+
34+
let fp: *c_void = task_start_wrapper as *c_void;
35+
let argp: *c_void = unsafe { transmute::<&~fn(), *c_void>(&*start) };
36+
let sp: *uint = stack.end();
37+
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
38+
39+
// Save and then immediately load the current context,
40+
// which we will then modify to call the given function when restored
41+
let mut regs = new_regs();
42+
unsafe {
43+
swap_registers(transmute_mut_region(&mut *regs),
44+
transmute_region(&*regs))
45+
};
46+
47+
initialize_call_frame(&mut *regs, fp, argp, sp);
48+
49+
return Context(regs);
50+
}
51+
52+
static fn swap(out_context: &mut Context, in_context: &Context) {
53+
let out_regs: &mut Registers = match out_context {
54+
&Context(~ref mut r) => r
55+
};
56+
let in_regs: &Registers = match in_context {
57+
&Context(~ref r) => r
58+
};
59+
60+
unsafe { swap_registers(out_regs, in_regs) };
61+
}
62+
}
63+
64+
extern {
65+
fn swap_registers(out_regs: *mut Registers, in_regs: *Registers);
66+
}
67+
68+
// Definitions of these registers are in rt/arch/x86_64/regs.h
69+
#[cfg(target_arch = "x86_64")]
70+
type Registers = [uint * 22];
71+
72+
#[cfg(target_arch = "x86_64")]
73+
fn new_regs() -> ~Registers { ~[0, .. 22] }
74+
75+
#[cfg(target_arch = "x86_64")]
76+
fn initialize_call_frame(regs: &mut Registers,
77+
fptr: *c_void, arg: *c_void, sp: *mut uint) {
78+
79+
// Redefinitions from regs.h
80+
const RUSTRT_ARG0: uint = 3;
81+
const RUSTRT_RSP: uint = 1;
82+
const RUSTRT_IP: uint = 8;
83+
const RUSTRT_RBP: uint = 2;
84+
85+
let sp = align_down(sp);
86+
let sp = mut_offset(sp, -1);
87+
88+
// The final return address. 0 indicates the bottom of the stack
89+
unsafe { *sp = 0; }
90+
91+
rtdebug!("creating call frame");
92+
rtdebug!("fptr %x", fptr as uint);
93+
rtdebug!("arg %x", arg as uint);
94+
rtdebug!("sp %x", sp as uint);
95+
96+
regs[RUSTRT_ARG0] = arg as uint;
97+
regs[RUSTRT_RSP] = sp as uint;
98+
regs[RUSTRT_IP] = fptr as uint;
99+
100+
// Last base pointer on the stack should be 0
101+
regs[RUSTRT_RBP] = 0;
102+
}
103+
104+
#[cfg(target_arch = "x86")]
105+
struct Registers {
106+
eax: u32, ebx: u32, ecx: u32, edx: u32,
107+
ebp: u32, esi: u32, edi: u32, esp: u32,
108+
cs: u16, ds: u16, ss: u16, es: u16, fs: u16, gs: u16,
109+
eflags: u32, eip: u32
110+
}
111+
112+
#[cfg(target_arch = "x86")]
113+
fn new_regs() -> ~Registers {
114+
~Registers {
115+
eax: 0, ebx: 0, ecx: 0, edx: 0,
116+
ebp: 0, esi: 0, edi: 0, esp: 0,
117+
cs: 0, ds: 0, ss: 0, es: 0, fs: 0, gs: 0,
118+
eflags: 0, eip: 0
119+
}
120+
}
121+
122+
#[cfg(target_arch = "x86")]
123+
fn initialize_call_frame(regs: &mut Registers,
124+
fptr: *c_void, arg: *c_void, sp: *mut uint) {
125+
126+
let sp = align_down(sp);
127+
let sp = mut_offset(sp, -4); // XXX: -4 words? Needs this be done at all?
128+
129+
unsafe { *sp = arg as uint; }
130+
let sp = mut_offset(sp, -1);
131+
unsafe { *sp = 0; } // The final return address
132+
133+
regs.esp = sp as u32;
134+
regs.eip = fptr as u32;
135+
136+
// Last base pointer on the stack is 0
137+
regs.ebp = 0;
138+
}
139+
140+
fn align_down(sp: *mut uint) -> *mut uint {
141+
unsafe {
142+
let sp = transmute::<*mut uint, uint>(sp);
143+
let sp = sp & !(16 - 1);
144+
transmute::<uint, *mut uint>(sp)
145+
}
146+
}
147+
148+
// XXX: ptr::offset is positive ints only
149+
#[inline(always)]
150+
pub pure fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
151+
use core::sys::size_of;
152+
unsafe {
153+
(ptr as int + count * (size_of::<T>() as int)) as *mut T
154+
}
155+
}
156+

branches/try2/src/libcore/rt/io.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
use option::*;
12+
use result::*;
13+
14+
// XXX: ~object doesn't work currently so these are some placeholder
15+
// types to use instead
16+
pub type EventLoopObject = super::uvio::UvEventLoop;
17+
pub type IoFactoryObject = super::uvio::UvIoFactory;
18+
pub type StreamObject = super::uvio::UvStream;
19+
pub type TcpListenerObject = super::uvio::UvTcpListener;
20+
21+
pub trait EventLoop {
22+
fn run(&mut self);
23+
fn callback(&mut self, ~fn());
24+
/// The asynchronous I/O services. Not all event loops may provide one
25+
fn io(&mut self) -> Option<&self/mut IoFactoryObject>;
26+
}
27+
28+
pub trait IoFactory {
29+
fn connect(&mut self, addr: IpAddr) -> Option<~StreamObject>;
30+
fn bind(&mut self, addr: IpAddr) -> Option<~TcpListenerObject>;
31+
}
32+
33+
pub trait TcpListener {
34+
fn listen(&mut self) -> Option<~StreamObject>;
35+
}
36+
37+
pub trait Stream {
38+
fn read(&mut self, buf: &mut [u8]) -> Result<uint, ()>;
39+
fn write(&mut self, buf: &[u8]) -> Result<(), ()>;
40+
}
41+
42+
pub enum IpAddr {
43+
Ipv4(u8, u8, u8, u8, u16),
44+
Ipv6
45+
}

0 commit comments

Comments
 (0)