Skip to content

Instantly share code, notes, and snippets.

SDK = ~/.emsdk_portable
EMSCRIPTEN_PATH = $(shell $(SDK)/emsdk active_path emscripten-1.7.8)
CLANG_PATH = $(shell dirname $(shell PATH=$(shell $(SDK)/emsdk active_path clang-3.2-64bit):$(PATH) which clang))
EMCC = LLVM=$(CLANG_PATH) python $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc)
default: build
build:
$(EMCC) main.cpp
@evanw
evanw / build.sh
Created April 6, 2014 17:17
Google Closure Compiler ignores input source maps
java \
-jar compiler.jar \
--js main.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--js_output_file main.min.js \
--create_source_map main.min.js.map \
--source_map_format V3
import os
import re
import json
import base64
path = 'compiled.js.mem'
data = open('compiled.js.mem', 'rb').read()
print 'data length:', len(data)
def tinystr(s):
build:
emcc -O1 -fno-rtti -fno-exceptions temp.c -o temp.js
@evanw
evanw / Makefile
Created July 2, 2015 21:01
Test case for flatbuffers issue #226
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
@evanw
evanw / Main.hx
Last active November 25, 2015 17:41
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 / gl.cpp
Created November 11, 2013 01:04
The mandelbulb fractal shader from https://www.shadertoy.com/view/MdfGRr ported to C++ with GLUT. Uses W/A/S/D to rotate and up/down/left/right to move. Compiles on OS X with: g++ main.cpp gl.cpp -framework GLUT -framework OpenGL -Wno-deprecated-declarations
#include "gl.h"
mat4 &mat4::transpose() {
std::swap(m01, m10); std::swap(m02, m20); std::swap(m03, m30);
std::swap(m12, m21); std::swap(m13, m31); std::swap(m23, m32);
return *this;
}
mat4 &mat4::rotateX(float degrees) {
float radians = degrees * (M_PI / 180);
@evanw
evanw / main.rs
Created December 29, 2013 05:36
Rust language: Use after free? (rustc 0.8)
struct Foo {
x: int
}
impl Drop for Foo {
fn drop(&mut self) {
println!("drop {}", self.x);
}
}
@evanw
evanw / Makefile
Created January 4, 2014 18:20
C++ memory test compiled using emscripten with 512mb heap
SOURCES = \
main.cpp
CPP_FLAGS = \
-fno-exceptions \
-fno-rtti \
-Wall \
-Wextra
JS_FLAGS = \
@evanw
evanw / Makefile
Created January 28, 2014 20:20
Code generated by emlink is incorrect
SDK = ~/.emsdk_portable
JS_FLAGS = -s ASM_JS=1 -O1
CPP_FLAGS = -std=c++11 -fno-rtti -fno-exceptions
EMSCRIPTEN_PATH = $(shell $(SDK)/emsdk active_path emscripten-1.7.8)
CLANG_PATH = $(shell dirname $(shell PATH=$(shell $(SDK)/emsdk active_path clang-3.2-64bit):$(PATH) which clang))
EMCC = LLVM=$(CLANG_PATH) python $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc)
EMLINK = LLVM=$(CLANG_PATH) python $(shell dirname $(shell PATH=$(EMSCRIPTEN_PATH):$(PATH) which emcc))/emlink.py
default: cpp_simple cpp_modules js_simple js_modules