Superfastscript is a typesafe WebAssembly-ready variant of JavaScript. Superfastscript programs can be directly compiled to WASM, but use a syntax very similar to JavaScript.
Typed languages like TypeScript are well-suited to normal JS development, but the current WebAssembly Minimal Viable Product doesn't support many features of JavaScript people have come to know and love. Superfastscript imposes certain limitations on existing JavaScript, and adds some new syntax variants, to allow JS programmers to quickly write WASM-ready programs.
We need a subset of typed JavaScript that excludes certain features unsupported by WASM:
- The JS standard library
- JS objects
- Closures
- Exceptions /
try/catch/finally
Superfastscript adds some new language features that are missing in JavaScript.
Because WASM lacks a garbage collector, we're also going to want some new primitives
malloc- the manually allocate function allocates memoryfree- the finite resource eraser extension function undoesmalloc
Superfastscript adds pointers, a long-missing feature of JavaScript. Pointers can point to primitives or arbitrary buffers without loss of generality.
Superfastscript changes the function syntax slightly. We omit the function keyword and write the return type instead:
int main()
{
return 0;
}You can declare variables with familiar var x; syntax. Except instead of var, we'll write the type name:
int main()
{
int x = 100;
return x;
}You can use the manual allocate function, malloc, to allocate blocks memory:
int* ptr = malloc(sizeof(int) * 24);These pointers are similar to other brace-using languages. For example, you can modify an array (really just a pointer) element:
// Increment the 15th element of the manually-allocated array
ptr[14]++;Once a memory block is allocated, use the finite resource eraser extension function, free, to release it:
free(ptr);Additional reading is available: