Skip to content

Instantly share code, notes, and snippets.

@huonw
huonw / test.rs
Last active August 29, 2015 13:56 — forked from thehydroimpulse/test.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn modes_(&mut self, reg: u8, modecode: u8) -> AddressingMode {
match (reg, modecode) {
(2,0b00) => Direct,
(2,0b01) => Absolute(self.next_inst()),
(2,0b10) => Const(4),
(2,0b11) => Const(8),
(3,0b00) => Const(0),
(3,0b01) => Const(1),
(3,0b10) => Const(2),
(3,0b11) => Const(-1),
@huonw
huonw / gist:8366072
Created January 11, 2014 02:06 — forked from brson/gist:8366039
macro_rules! report_diag (
($f: tt, $name: tt, $msg: tt, $(arg: tt)*) => { {
reg_diag_msg!($name, $msg);
let msg = format!($msg, $($arg)*);
let msg = format!("{}: {}", stringify!($name), msg);
$f(msg);
} };
($f: tt, $name: tt, $msg: tt) => { {
reg_diag_msg!($name, $msg);
let msg = format!("{}: {}", stringify!($name), $msg);
@huonw
huonw / gist:7351219
Created November 7, 2013 08:41 — forked from cnd/gist:7351205
fn ifV<'a, T>(rc : &str, star: &'a T) -> Option<&'a T> {
if (Path::new( rc )).exists() {
Some(star)
} else {
None
}
}
trait A {}
fn foo<T: A>(_: &T) {}
struct B;
impl A for B {}
impl<'self> A for &'self A {}
fn main() {
let a = B;
@huonw
huonw / gist:6239071
Last active December 21, 2015 02:59 — forked from alexcrichton/gist:6239056
use std::rt::io;
struct HttpResponse<'self> {
out: &'self mut io::Writer,
}
fn write_http_header(_: &mut &mut io::Writer) {}
// fn write_http_header<W: io::Writer>(_: &mut W) {}
impl<'self> HttpResponse<'self> {
@huonw
huonw / t1.rs
Last active December 20, 2015 15:39 — forked from dovreshef/t1.rs
use t2::t3::fun;
mod t2;
fn main() {
t2::fun();
fun(); // calling t3::fun
}
@huonw
huonw / oops.rs
Last active December 20, 2015 06:39 — forked from kemurphy/oops.rs
let mut f = None;
match *e {
expr_call(f, ref args, _) => match f.node {
expr_path(path) => match dm.find(&f.id) {
Some(&v) => match v {
ast::def_variant(*) |ast::def_struct(*) => {
f = Some(expr_struct(
fld.fold_path(&path),
args.map(|x| fold_unnamed_field(*x)),
None
@huonw
huonw / gist:6034302
Last active December 19, 2015 23:19 — forked from bblum/gist:3885017
trait Nat { }
struct Zero;
struct Suc<N>(N);
impl Nat for Zero { }
impl<N: Nat> Nat for Suc<N> { }
@huonw
huonw / main.rs
Last active December 18, 2015 01:39 — forked from anonymous/main.rs
pub mod other;
fn main() {
other::hello();
}