Quantcast
Browsing all 41 articles
Browse latest View live

How to use inline assembly in Rust.

Rust Inline Asm.md fn main() { unsafe { do str::as_c_str(~"The answer is %d.\n") |c| { let a = 42; asm!("mov $0, %rdi\n\t\ mov $1, %rsi\n\t\ xorl %eax, %eax\n\t\ call _printf" : : "r"(c), "r"(a) :...

View Article


rqsrt.rs

rqsrt.rs fn libc_rsqrt(f: &f32) -> f32 { 1.0/f32::sqrt(*f) } fn llvm_rsqrt(f: &f32) -> f32 { 1.0/core::unstable::intrinsics::sqrtf32(*f) } fn asm_rsqrt(f: &f32) -> f32 { let mut b...

View Article


gist:5794062

gistfile1.rs struct Point { x: int, y: int } trait Positioned { fn x(&self)-> int; fn y(&self)-> int; fn setX(&mut self, int); fn setY(&mut self, int); } trait Movable:...

View Article

fail-parent-child.rs

fail-parent-child.rs struct Parent; impl Parent { fn new_child<'a>(&'a self) -> Child<'a> { Child { parent: self } } } struct Child<'self> { parent: &'self Parent }...

View Article

linux.ll

linux.ll ; ModuleID = 'rust.rc' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"...

View Article


gist:6106904

gistfile1.rs fn find_fn(ccx: @mut CrateContext, fn_id: ast::node_id) -> Option<codemap::span> { match ccx.tcx.def_map.find(&fn_id) { Some(&ast::def_fn(def_id, _)) => { if...

View Article

a-foo.rs

a-foo.rs fn main() { let b = test_nd_dr(8, 3); assert_eq!(b, 2); } fn test_nd_dr(n: i8, d: i8) -> i8 { let separate_div_rem = (n / d, n % d); let combined_div_rem = n.div_rem(&d); let (_, b) =...

View Article

server.rs

server.rs use std::cell::Cell; use std::rt::io::net::tcp::TcpListener; use std::rt::io::net::ip::Ipv4; use std::rt::io::{Listener, Writer}; fn main() { let mut listener = TcpListener::bind(Ipv4(0, 0,...

View Article


A macro to easily create and populate hash maps.

hashmap-macro.rs #![feature(macro_rules)] extern crate collections; use collections::HashMap; // A macro to easily create and populate hash maps macro_rules! hashmap( { $($key:expr =>...

View Article


gist:6248769

gistfile1.txt -> % gdb --args x86_64-unknown-linux-gnu/stage2/bin/rustc --cfg stage2 -O --cfg debug -Z no-debug-borrows --target=arm-linux-androideabi...

View Article

gist:6248789

gistfile1.txt laden@corn-syrup [06:23:13] [/scratch/laden/rust/build] [issue-3678-wrappers-be-gone-2] -> % RUST_LOG=rustc=1,rustc::middle::trans::foreign x86_64-unknown-linux-gnu/stage2/bin/rustc...

View Article

gist:6248800

gistfile1.txt ~"register_foreign_item_fn(abis=\"C\", path=[cmath, c_float_utils, ceil], foreign_item.id=153330)" ~"trans_native_call(callee_ty=extern \"C\" unsafe fn(f32) -> f32, llfn=*fn(Float)...

View Article

rj.rs

rj.rs extern mod sdl; use std::libc::{c_int, c_void}; use std::rt::comm; use std::rt::io::extensions::*; use std::rt::io::io_error; use std::rt::io::net::ip::{IpAddr, Ipv4Addr, Port, SocketAddr}; use...

View Article


simd.rs

simd.rs #[simd] struct F(f32, f32); static A: F = F(2.0, 3.5); fn main() { }

View Article

foo.c

foo.c extern int foobar __attribute__((weak)); int main(int argc, char *argv[]) { return foobar; }

View Article


build

build -> % rustc foo.rs --lib -Z extra-debug-info -> % ls foo.c foo.rs libfoo-102129e09d96658-0.0.so -> % gcc foo.c -g -L. -lfoo-102129e09d96658-0.0 -o foo -> % LD_LIBRARY_PATH=. ./foo [1]...

View Article

rotl.rs

rotl.rs #![feature(asm, macro_rules)] use std::mem; fn rotl(val: u64, shift: u8) -> u64 { let sz = mem::size_of_val(&val); (val << shift) | (val >> (sz * 8 - shift as uint)) }...

View Article


Steps.md

Steps.md Steps: Download http://luqman.ca/rust-builds/rust-0.9-pre-191cba6-i686-w64-mingw32.zip Extract to somewhere, say Desktop Download...

View Article

Ident Server in Rust

gistfile1.md Simple Ident Server in Rust This is a quick example of a simple TCP server written (mostly) in Rust which implements RFC 1413. It has a bit of networking, regex, and FFI. All code...

View Article

Entrypoints!.md

Entrypoints!.md Or what the hell do #![no_start], #![no_main], #[lang = "start"], #[start], and #[main] do? Crate Attributes: #![no_start] Disable automatically linking in the native crate and thus...

View Article
Browsing all 41 articles
Browse latest View live