Skip to content

Instantly share code, notes, and snippets.

@oakes
Last active February 20, 2021 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oakes/bb0f90fdc25dc5a9946e663ba564c32c to your computer and use it in GitHub Desktop.
Save oakes/bb0f90fdc25dc5a9946e663ba564c32c to your computer and use it in GitHub Desktop.
# to build this with emscripten, you need emsdk on your PATH.
# first, clone https://github.com/emscripten-core/emsdk
# then in that repo run:
# ./emsdk install latest
# ./emsdk activate latest
# and then add the directories it prints out to your PATH
#
# then in this repo run:
# nim c -d:emscripten bug.nim
#
# finally, run an http server:
# python -m http.server
#
# in your browser console, you'll see:
# Error: unhandled exception: key not found: (-1, -1) [KeyError]
import tables
type
DirectionName = enum
West, NorthWest, North, NorthEast,
East, SouthEast, South, SouthWest,
const
velocities = {(-1, 0): West, (-1, -1): NorthWest,
(0, -1): North, (1, -1): NorthEast,
(1, 0): East, (1, 1): SouthEast,
(0, 1): South, (-1, 1): SouthWest}.toTable
echo velocities[(-1, -1)]
when defined(emscripten):
# This path will only run if -d:emscripten is passed to nim.
--nimcache:tmp # Store intermediate files close by in the ./tmp dir.
--os:linux # Emscripten pretends to be linux.
--cpu:wasm32 # Emscripten is 32bits.
--cc:clang # Emscripten is very close to clang, so we ill replace it.
when defined(windows):
--clang.exe:emcc.bat # Replace C
--clang.linkerexe:emcc.bat # Replace C linker
--clang.cpp.exe:emcc.bat # Replace C++
--clang.cpp.linkerexe:emcc.bat # Replace C++ linker.
else:
--clang.exe:emcc # Replace C
--clang.linkerexe:emcc # Replace C linker
--clang.cpp.exe:emcc # Replace C++
--clang.cpp.linkerexe:emcc # Replace C++ linker.
--listCmd # List what commands we are running so that we can debug them.
--gc:arc # GC:arc is friendlier with crazy platforms.
--exceptions:goto # Goto exceptions are friendlier with crazy platforms.
--define:useMalloc
# Pass this to Emscripten linker to generate html file scaffold for us.
switch("passL", "-o index.html -s INITIAL_MEMORY=64MB -s SAFE_HEAP=1 -s WARN_UNALIGNED=1 -s USE_WEBGL2=1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment