Skip to content

Instantly share code, notes, and snippets.

@kripken
kripken / s2json.py
Created May 28, 2026 20:06
s-to-json
import json
import re
import sys
def tokenize(s_expr):
"""
Extracts tokens from an S-expression string.
Matches:
1. Strings enclosed in double quotes (handling escaped characters)
2. Parentheses '(' and ')'
@kripken
kripken / w.wat
Created April 13, 2026 18:21
reduced binaryen 8594
(module
(rec
(type $0 (sub (struct)))
(type $2 (sub $0 (struct)))
(type $1 (sub $0 (struct)))
(type $4 (sub final $0 (struct)))
(type $5 (sub final $2 (struct)))
(type $6 (sub final $0 (struct)))
(type $7 (sub final $1 (struct)))
(type $8 (sub final $1 (struct)))
;; $ bin/wasm-opt a.wat -all --closed-world --signature-pruning --roundtrip
;; [parse exception: incompatible continuation types in cont.bind: source type (type $cont.0 (cont $func.0)) has fewer parameters than target (type $cont.0 (cont $func.0)) (at 0:75)]
;; Fatal: error in parsing wasm binary
(module
(rec
(type $0 (sub (struct)))
(type $1 (func (param (ref null $0)) (result (ref null $0))))
(type $2 (func (param (ref null $0) (ref null $0) (ref null $0)) (result (ref null $0))))
(type $3 (cont $1))
@kripken
kripken / testcase.cpp
Last active February 28, 2026 01:08
testcase.cpp
This file has been truncated, but you can view the full file.
# 1 "//Dev/emscripten/test/other/test_std_filesystem.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 445 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "//Dev/emscripten/test/other/test_std_filesystem.cpp" 2
# 1 "//Dev/emscripten/cache/sysroot/include/c++/v1/cstdint" 1 3
# 146 "//Dev/emscripten/cache/sysroot/include/c++/v1/cstdint" 3
# 1 "//Dev/emscripten/cache/sysroot/include/c++/v1/__config" 1 3
@kripken
kripken / greeting_nn.py
Last active February 16, 2026 21:04
Greeting Neural Network
def matrix_math(matrix, offset, vector):
'''
Computes
matrix*vector + offset
Matrix is mxn, vector ix 1xn, offset is 1xn
'''
m = len(matrix)

Simple WasmBoxC Library Example

This shows how to easily sandbox a real-world library using WasmBoxC. Specifically we sandbox the zlib compression library.

To follow along with this, you can clone this gist and then do the following commands.

First, get the emsdk:

Wasm host GC integration demo

This lets code compiled to linear memory wasm (like a C++ or Rust game engine) use the host GC instead of shipping its own, with the benefits of

  • Not shipping a GC.
  • Not needing to manage a shadow stack in userspace.
  • Other host GC benefits, like existing optimzations there, integration with system memory pressure events, etc.
--- a 2025-10-08 13:06:30.544955211 -0700
+++ b 2025-10-08 13:06:48.673083467 -0700
@@ -1290924,24 +1290924,21 @@
(i32.const 36)
)
)
)
)
)
(return
//
// Branch hints benchmark: 30% faster with the right hint (LIKELY=0),
// 20% slower with the wrong one (LIKELY=1), compared to no hint.
//
#include <iostream>
#include <vector>
#ifdef LIKELY
#define hint(x) __builtin_expect((x), LIKELY)