aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Hoeppner2014-08-07 13:30:21 +0100
committerTill Hoeppner2014-08-07 13:30:21 +0100
commitce640c2c25b0e16c567553c5774d633c13cbf0ee (patch)
tree5bf8f3c73fe4933f55044d42eb431ebe6767ae1a
downloadirsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.tar.gz
irsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.tar.xz
irsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.zip
Setup
-rw-r--r--Cargo.toml5
-rw-r--r--Makefile33
-rw-r--r--src/lib.rs3
-rw-r--r--src/src/.irsc.rs.swpbin0 -> 12288 bytes
-rw-r--r--src/src/irsc.rs106
-rwxr-xr-xtarget/irscbin0 -> 1025479 bytes
-rwxr-xr-xtarget/rwmbin0 -> 1177853 bytes
7 files changed, 147 insertions, 0 deletions
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 <hoeppner.till@gmail.com>"]
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
--- /dev/null
+++ b/src/src/.irsc.rs.swp
Binary files 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<TcpStream>
+}
+
+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<TcpStream>) {
+ 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::<Vec<&str>>();
+ 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
--- /dev/null
+++ b/target/irsc
Binary files differ
diff --git a/target/rwm b/target/rwm
new file mode 100755
index 0000000..b3b0a9e
--- /dev/null
+++ b/target/rwm
Binary files differ