Microsoft yesterday unveiled Static TypeScript as an alternative to embedded interpreters. Static TypeScript (STS) is an implementation of a Static Compiler for TypeScript which runs in the web browser. It is primarily designed to aid school children in their computer science programming projects. STS is supported by a compiler that is also written in Typescript. It generates machine code that runs efficiently on Microcontrollers in the target RAM range of 16-256kB.
Microsoft’s plan behind building Static TypeScript
Microsoft therefore decided to come with STS which is a more efficient alternative to the embedded interpreter approach. It is statically typed, which makes for a less surprising programming experience.
Features of Static TypeScript
- The STS toolchain runs offline, once loaded into a web browser, without the need for a C/C++ compiler.
- The STS compiler generates efficient and compact machine code, which unlocks a range of application domains such as game programming for low resource devices .
- Deployment of STS user programs to embedded devices does not require app or device driver installation, just access to a web browser.
Differences with TypeScript
In contrast to TypeScript, where all object types are bags of properties, STS has at runtime four kinds of unrelated object types:
- A dynamic map type has named (string-indexed) properties that can hold values of any type
- A function (closure) type
- A class type describes instances of a class, which are treated nominally, via an efficient runtime subtype check on each field/method access
- An array (collection) type
STS Compiler and Runtime
The STS compiler and toolchain (linker, etc.) are written solely in TypeScript. The source TypeScript program is processed by the regular TypeScript compiler to perform syntactic and semantic analysis, including type checking. The STS device runtime is mainly written in C++ and includes a bespoke garbage collector. The regular TypeScript compiler, the STS code generators, assembler, and linker are all implemented in TypeScript and run both in the web browser and on command line. The STS toolchain, implemented in TypeScript, compiles STS to Thumb machine code and links this code against a pre-compiled C++ runtime in the browser, which is often the only available execution environment in schools.
Static TypeScript is used in all MakeCode editors
STS is the core language supported by Microsoft’s MakeCode Framework. MakeCode provides hands on computing education for students with projects. It enables the creation of custom programming experiences for MCU-based devices. Each MakeCode editor targets programming of a specific device or device class via STS. STS supports the concept of a package, a collection of STS, C++ and assembly files, that also can list other packages as dependencies. This capability has been used by third parties to extend the MakeCode editors, mainly to accommodate hardware peripherals for various boards.
STS is also used in MakeCode Arcade. With Arcade, STS lets developers of all skill levels easily write cool retro-style pixelated games. The games are designed by the user to be run either inside a virtual game console in the browser or on inexpensive microcontroller-based handhelds.
For more in-depth information, please read the research paper.
People were quite interested in this development. A comment on Hacker News reads, “This looks very interesting. If all it takes is dropping “with, eval, and prototype inheritance” to get fast and efficient JS execution, I’m all for it.”