Skip to content

Instantly share code, notes, and snippets.

View steveklabnik's full-sized avatar
🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
View GitHub Profile
pub fn sum_loop(nums: &[i32]) -> i32 {
let mut s = 0;
for i in nums {
s = s + i;
}
s
}
fn add_to_mutable_reference(x: &mut i32) {
*x +=1;
}
#[test]
fn mutable_reference_test() {
let mut x = 5;
let y = &mut x;
mutable_reference(y);

9:05- 9:25 1. Welcome and Introduction (20min)

  • Operational Stuff (10min) [Ashley]

    • Introduction to instructors
    • Where are all the materials
    • Explain the schedule, when are breaks
    • Code of Conduct
    • What to do if you need help
  • What is the intermezzOS project? (10min) [Steve]

extern crate rand;
extern crate byteorder;
use std::io::{ Write };
use byteorder::{LittleEndian, WriteBytesExt};
const SAMPLE_RATE: u32 = 44100;
const CHANNELS: u32 = 1;
const HEADER_SIZE: u32 = 36;
const SUBCHUNK1_SIZE: u32 = 16;

Can I compile a 32-bit .a and then link it into a 64-bit application? This is x86 specifically.

At the moment, I have a file written in assembly, with nasm, that uses BITS 32 to ensure that it's only generating x86 stuff. I then link it into my x86-64 code generated from Rust. I'd like to port that asm to Rust. (which will of course also need some inline asm but that's a distraction). I have that compiling into a .a, but when I try to link that into my x86-64 code, ld isn't happy:

note: /usr/bin/ld: skipping incompatible ./libboot.a when searching for -lboot

Any thoughts?

(This is specifically doing the "GRUB dumps you in protected mode and I need to transition to long mode" code.)

@steveklabnik
steveklabnik / playground.rs
Last active August 9, 2016 15:29 — forked from anonymous/playground.rs
Shared via Rust Playground
struct Lib {
// whatever... but it implements Drop
}
impl Lib {
fn get_widget() -> &LibWidget {
// unimportant (I think), but LibWidget implements Drop
}
use std::path::PathBuf;
fn main() {
let our_args: Vec<_> = std::env::args().collect();
let prog = PathBuf::from(&our_args[1]);
let basename = prog.parent().expect(&format!("Not a file '{:?}'", prog));
let var = String::from("0install-runenv-") + basename.to_str().unwrap();
let json_str = std::env::var(&var).expect(&format!("Environment variable '{:?}' not set", var));
//let j = json::from_str(json_str).unwrap();
digraph structs {
node [shape=record];
{
rank=same
struct1 [label="{<ptr> ptr|{len|5}|{capacity|5}}"];
struct3 [label="{{<0> 0|h}|{1|e}|{2|l}|{3|l}|{4|o}}}"];
}
struct1:ptr -> struct3:0;
}

code

Bits and pieces. gist

@steveklabnik
steveklabnik / store_champs.md
Last active February 7, 2016 14:04
NYC (and surrounding area) Meta Store Championships