1
Fork 0

Rewrote receive to return a value. This lets us initialize variables by receiving them.

This commit is contained in:
Eric Holk 2011-08-02 12:29:10 -07:00
parent 244efa6331
commit 200bbcf91b
4 changed files with 12 additions and 12 deletions

View file

@ -20,7 +20,10 @@ native "rust" mod rustrt {
fn new_port(unit_sz : uint) -> *rust_port;
fn del_port(po : *rust_port);
fn drop_port(po : *rust_port);
fn port_recv(dp : *void, po : *rust_port);
}
native "rust-intrinsic" mod rusti {
fn recv[T](port : *rustrt::rust_port) -> T;
}
resource chan_ptr(ch: *rustrt::rust_chan) {
@ -47,9 +50,8 @@ obj _port[T](raw_port : @port_ptr) {
_chan(@chan_ptr(rustrt::new_chan(**raw_port)))
}
fn recv_into(v : &T) {
rustrt::port_recv(unsafe::reinterpret_cast(ptr::addr_of(v)),
**raw_port);
fn recv() -> T {
ret rusti::recv(**raw_port)
}
}

View file

@ -58,5 +58,5 @@ rust_intrinsic_addr_of(rust_task *task, void **retptr, type_desc *ty,
extern "C" void
rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
rust_port *port) {
port_recv(task, (uintptr_t*)*retptr, port);
port_recv(task, (uintptr_t*)retptr, port);
}

View file

@ -133,10 +133,9 @@ entry:
ret void
}
define linkonce_odr void @rust_intrinsic_recv(%struct.rust_task* %task, i8** nocapture %retptr, %struct.type_desc* nocapture %ty, %class.rust_port* %port) {
define linkonce_odr void @rust_intrinsic_recv(%struct.rust_task* %task, i8** %retptr, %struct.type_desc* nocapture %ty, %class.rust_port* %port) {
entry:
%tmp2 = load i8** %retptr, align 4, !tbaa !3
%0 = bitcast i8* %tmp2 to i32*
%0 = bitcast i8** %retptr to i32*
tail call void @port_recv(%struct.rust_task* %task, i32* %0, %class.rust_port* %port)
ret void
}

View file

@ -13,8 +13,7 @@ fn send_recv() {
let c = p.mk_chan();
c.send(42);
let v = 0;
p.recv_into(v);
let v = p.recv();
log_err v;
assert(42 == v);
}
}