Skip to content

Instantly share code, notes, and snippets.

View .babelrc
{
"presets": [
["env", {
"targets": {
"browsers": ["chrome 85"]
}
}]
]
}
@evanw
evanw / Cargo.toml
Created Apr 24, 2018
Example crazy Rust compile error
View Cargo.toml
[package]
name = "multiplayer"
version = "0.0.1"
publish = false
[dependencies]
futures = "0.1.18"
hyper = "0.11.17"
tokio-core = "0.1.12"
tokio-signal = "0.1.4"
@evanw
evanw / rust-wtf.rs
Created Apr 1, 2018
Rust's float parser has correctness issues
View rust-wtf.rs
fn main() {
// Ok(0.000000000...0000000005)
println!("{:?}", "4.9406564584124654e-324".parse::<f64>());
// WTF???
// Err(ParseFloatError { kind: Invalid })
println!("{:?}", "4.94065645841246545e-324".parse::<f64>());
// Ok(0.000000000...0000000005)
println!("{:?}", "4.9406564584124655e-324".parse::<f64>());
@evanw
evanw / 0_stackify.ts
Last active Jun 27, 2022
Example "stackify" algorithm for turning SSA into WASM
View 0_stackify.ts
// This code demonstrates a simplified "stackification" algorithm to turn
// instructions in a basic block back into a tree. This is useful when
// generating WebAssembly code from assembly instructions in SSA form.
//
// It's the algorithm used by LLVM's WebAssembly backend, viewable here:
// https://github.com/llvm-mirror/llvm/blob/master/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
type InsKind =
'Add' |
'LocalSet' |
@evanw
evanw / FGNode.cpp
Created Jul 30, 2017
An optimizer bug with emscripten's WebAssembly backend
View FGNode.cpp
#include "FGNode.h"
#include <stdio.h>
bool Node::supportsFillPaintData() const {
return usesGeometryCache(_fields._type);
}
const PaintData& Node::fillPaintData() const {
const auto* value = _fields._fillPaintData.get();
if (!supportsFillPaintData() || !value) {
View match_stack_space.rs
/*
This demonstrates a problem I ran into when writing a parser in Rust. It
appears that adding more branches to a match expression causes the function
to consume more stack space. The stack space used in this example isn't too
extreme but in my actual parser, each function call uses around 15kb of stack
space which adds up very quickly. It only takes around 30 nested calls to
use 512kb of stack space, after which a stack overflow crash occurs.
Here's the output of this program on https://play.rust-lang.org/:
@evanw
evanw / .gitmodules
Created Mar 16, 2016
Compiler benchmark
View .gitmodules
[submodule "skew"]
path = skew
url = git@github.com:evanw/skew.git
[submodule "typescript"]
path = typescript
url = https://git01.codeplex.com/typescript
[submodule "coffeescript"]
path = coffeescript
url = git@github.com:jashkenas/coffeescript.git
View Main.hx
class Assert {
public static inline function assert(truth: Bool) {
if (!truth) {
trace('assert failed');
}
}
}
// This demonstrates using type wrapping to make an efficient color API. Colors
// are stored directly as 32-bit integers and don't cause any allocations.
@evanw
evanw / Makefile
Created Jul 2, 2015
Test case for flatbuffers issue #226
View Makefile
default: native web
native: a.out
./a.out
web: a.out.js
node a.out.js
a.out: test_generated.h
c++ -std=c++11 test.cpp
View emcc_wrapper.py
# This is a simple wrapper for the "emcc" command from the emscripten compiler.
# Unlike the emscripten SDK script, it lets you specify the compiler version
# number. Just pass the version number using the "--version" flag and put the
# flags for "emcc" after the "--":
#
# python emcc_wrapper.py --version 1.27.0 -- -O3 -s NO_EXIT_RUNTIME=1 ...
#
import os
import sys
import pipes