From ce640c2c25b0e16c567553c5774d633c13cbf0ee Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 7 Aug 2014 13:30:21 +0100 Subject: Setup --- Cargo.toml | 5 +++ Makefile | 33 ++++++++++++++++ src/lib.rs | 3 ++ src/src/.irsc.rs.swp | Bin 0 -> 12288 bytes src/src/irsc.rs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ target/irsc | Bin 0 -> 1025479 bytes target/rwm | Bin 0 -> 1177853 bytes 7 files changed, 147 insertions(+) create mode 100644 Cargo.toml create mode 100644 Makefile create mode 100644 src/lib.rs create mode 100644 src/src/.irsc.rs.swp create mode 100644 src/src/irsc.rs create mode 100755 target/irsc create mode 100755 target/rwm diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b15999b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[package] + +name = "irsc" +version = "0.0.1" +authors = ["Till Hoeppner "] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..58dec28 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +RUSTC ?= rustc +RUSTC_FLAGS ?= +NAME ?= irsc + +SRC = $(shell find src -name '*.rs') + +all: $(NAME) + +$(NAME): $(SRC) + mkdir -p target + $(RUSTC) --out-dir target $(RUSTC_FLAGS) src/$(NAME).rs + +opt: RUSTC_FLAGS += --opt-level=3 -Z lto +opt: $(NAME) + +small: opt + upx -9 ./target/$(NAME) + +debug: RUSTC_FLAGS += -g +debug: $(NAME) + +run: $(NAME) + ./target/$(NAME) + +test: $(SRC) + mkdir -p target + $(RUSTC) --test --out-dir target src/$(NAME).rs + ./target/$(NAME) + +clean: + @rm -rf target + +.PHONY: clean diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a93251b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +#[test] +fn it_works() { +} diff --git a/src/src/.irsc.rs.swp b/src/src/.irsc.rs.swp new file mode 100644 index 0000000..da65aeb Binary files /dev/null and b/src/src/.irsc.rs.swp differ diff --git a/src/src/irsc.rs b/src/src/irsc.rs new file mode 100644 index 0000000..704a0f7 --- /dev/null +++ b/src/src/irsc.rs @@ -0,0 +1,106 @@ +use std::io::{ + BufferedReader, + TcpStream, + IoResult +}; +use std::str; +use std::ascii::StrAsciiExt; +use std::simd::f32x4; + +struct Server { + host: String, + port: u16, + stream: Option +} + +impl Server { + + fn new(host: &str, port: u16) -> Server { + Server { + host: String::from_str(host), + port: port, + stream: None + } + } + + fn connect(&mut self) { + self.stream = Some(TcpStream::connect(self.host.as_slice(), self.port).unwrap()); + + let cs = self.stream.clone(); + spawn(proc() { + Server::listen(cs); + }); + } + + #[inline] + fn sendraw(stream: &mut TcpStream, s: &str) { + stream.write_str(s); + stream.flush(); + } + + #[inline] + fn sendrawln(stream: &mut TcpStream, s: &str) { + Server::sendraw(stream, String::with_capacity(s.len() + 2).append(s).append("\r\n").as_slice()); + } + + fn join(self, channel: &str) { + self.stream.map(|mut st| Server::sendrawln(&mut st, format!("JOIN {}", channel).as_slice())); + } + + fn listen(stream: Option) { + let mut abort = false; + let mut stream = match stream { + Some(s) => s, + None => return + }; + if abort {return;} + let mut reader = BufferedReader::new(stream.clone()); + loop { + let line = reader.read_line().unwrap(); + //println!("{}", line); + let mut parts = line.as_slice().split(' ').collect::>(); + println!("{}", parts); + + if parts.len() == 0 { + continue; + } + + // if message has a prefix + let prefix = if parts.get(0).chars().next().unwrap() == ':' { + parts.shift().unwrap() + } else { "" }; + + match (*parts.get(0)).to_ascii_upper().as_slice() { + "PING" => { + Server::sendrawln(&mut stream, format!("PONG {}", parts.get(1)).as_slice()); + continue; + } + _ => {} + } + + } + } + + +} + +fn main() { + let mut furnet = Server::new("irc.furnet.org", 6667); + furnet.connect(); + + std::io::timer::sleep(5000u64); + + furnet.join("#teenagefurs"); + + // create simd vectors + let x = f32x4(1.0, 2.0, 3.0, 4.0); + let y = f32x4(4.0, 3.0, 2.0, 1.0); + + // simd product + let z = x * y; + + // like any struct, the simd vector can be destructured using `let` + let f32x4(a, b, c, d) = z; + + println!("{}", (a, b, c, d)); +} diff --git a/target/irsc b/target/irsc new file mode 100755 index 0000000..49a26f5 Binary files /dev/null and b/target/irsc differ diff --git a/target/rwm b/target/rwm new file mode 100755 index 0000000..b3b0a9e Binary files /dev/null and b/target/rwm differ -- cgit v1.2.3