Skip to content

Instantly share code, notes, and snippets.

View eira-fransham's full-sized avatar

Eira Fransham eira-fransham

  • Berlin
View GitHub Profile
@eira-fransham
eira-fransham / pollock.rs
Created September 26, 2018 15:05
Example of using pollock.rs to make some simple sketches
#![feature(nll)]
#[macro_use]
extern crate pollock;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use pollock::*;
#![feature(nll)]
extern crate pollock;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use pollock::*;
#[derive(Serialize, Deserialize)]
This file has been truncated, but you can view the full file.
# callgrind format
version: 1
creator: callgrind-3.13.0
pid: 6359
cmd: target/release/rustfest-5c3dd55c20998644 --bench
part: 1
desc: I1 cache: 32768 B, 64 B, 8-way associative
desc: D1 cache: 32768 B, 64 B, 8-way associative
@eira-fransham
eira-fransham / unsound-insert.rs
Last active November 27, 2019 03:35
Explanation of unsoundness in `SmallVec::insert_many`
extern crate smallvec;
use smallvec::SmallVec;
struct Printer(usize);
impl Drop for Printer {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
@eira-fransham
eira-fransham / bigint-native.s
Created May 14, 2018 14:44
Disassembly of `U256::full_mul` when using `-C target-cpu=native`
libbigint.so`disassemble:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq 0x10(%rbp), %r14
use std::{str, mem, ptr, slice};
use std::ops::Deref;
pub struct CowStr<'a>(CowVec<'a, u8>);
impl<'a> CowStr<'a> {
#[inline]
pub fn borrowed(b: &'a str) -> Self {
CowStr(CowVec::borrowed(b.as_bytes()))
}
pub struct VecBuilder<'a, T: 'a> {
inner: *mut Vec<T>,
_marker: std::marker::PhantomData<&'a mut Vec<T>>,
}
impl<'a, T> VecBuilder<'a, T> {
pub fn new(v: &'a mut Vec<T>) -> Self {
VecBuilder {
inner: v,
_marker: Default::default(),
#[macro_use]
extern crate combine;
use std::collections::HashMap;
#[derive(Debug, Clone)]
enum Ast {
Lit(Value),
Variable(String),
Call(Box<Ast>, Vec<Ast>),
@eira-fransham
eira-fransham / __use.rs
Last active May 7, 2018 11:45
Comparison of assembly for a simple case
pub fn disassemble() {
let smallvec: SmallVec<[_; 16]> = smallvec![10; 100];
test::black_box(smallvec);
}
// Low-level interface, we can implement a higher-level interface as a library
mod pwasm {
use std::marker::PhantomData;
pub struct ContractDef<State> {
state: State,
iterate: for<'a> fn(&'a EthEnv, State, MessageData) -> (State, ReturnData),
}
// Will it ever be possible to get arbitrary blocks?