BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Microsoft Presents Static TypeScript, a Fast Subset of TypeScript Targeting Embedded Devices

Microsoft Presents Static TypeScript, a Fast Subset of TypeScript Targeting Embedded Devices

This item in japanese

Microsoft recently submitted a research paper introducing Static TypeScript (STS), a subset of TypeScript targeting low-resource embedded devices, to the Managed Programming Languages and Runtimes 2019 (MPLR 2019) international conference. STS programs may run on devices with only 16 kB of RAM faster than embedded interpreters would, which would extend battery life of these devices.

STS is a syntactic subset of TypeScript, built specifically to target microcontroller units (MCUs), and compiles to machine code that runs efficiently on MCUs in the target RAM range of 16-256kB.

STS eliminates the most dynamic features of JavaScript, like with, eval, prototype-based inheritance, the arguments keyword, or the .apply method. The this pointer and the new syntax are not allowed outside classes or on non-class types. STS also does not implement recent additions to the JavaScript language, such as generators, the await and async function expressions, or file-based modules.

STS also departs from TypeScript typing conventions. Static TypeScript has nominal typing for classes, while TypeScript uses structural typing. This implies in particular that an interface cannot have the same name as a class, a non-class type cannot be casted to a class, classes cannot inherit from built-in types, this cannot be used outside of a method, and functions cannot be overloaded. STS in particular separates, at the type level, objects which act as key-values map from class instances and other special-purpose JavaScript objects, like functions and arrays.

STS language choices allow it to efficiently compile classes with Virtual Call Table techniques. As importantly, the language choices facilitate type inference, resulting in code which looks like standard JavaScript. Daryl Zuniga, software engineer on MakeCode, the primary user of STS, explained on HackerNews:

Because of the heavy use of type inference, most beginner programs have no type annotations and it looks just like Javascript.

An HackerNews user expressed his enthusiasm:

Extremely interesting idea. Sounds like many of the things they get rid of are some of the more problematic features of JS anyway. The end result is fairly Swift-y; a loosely OOP static language that has closures and really convenient hash-map syntax.

The Microsoft research paper reports that the STS compiler produces efficient and compact ARM Thumb machine code. The latter point is illustrated with a platform game written with STS, and which runs at 30 frames per second on a the 120x160 display of a $25, 120MHz, 192kB of RAM AdaFruit device. Alternative JavaScript embedded interpreters, like IoT.js, Espruino, Duktape, or MicroPython, displayed, in the tests presented by the research paper, a significantly higher memory consumption profile, and worse performance.

STS programs may be deployed on embedded devices with a web browser or manually, that is, without any app or driver installation. The research paper explains:

Compiled programs appear as downloads, which are then transferred manually by the user to the device, which appears as a USB mass storage device, via file copy (or directly through WebUSB, an upcoming standard for connecting websites to physical devices).

Zuniga emphasizes the importance of browser-based deployment and simulation for young pupils learning physical computing, an important target audience of MakeCode:

STS comes with a simulator that runs in the browser and so programs can be tested there before they run on hardware. For educational purposes, we found diagnosing issues on hardware to be really hard for students, so we try to catch and present errors as early as possible.

Going forward, Microsoft envisages STS having a significant impact on the Internet of Things (IoT):

We see statically typed languages such as STS playing an important role in the future of IoT, allowing embedded devices to run more efficiently—faster and, as a result, with reduced energy requirements—as well as providing programmers who aren’t embedded developers with an easier, higher-level alternative to the lower-level languages generally used to program these devices.

Developers may consult online the technical details of the STS language and the current draft of the Microsoft research paper.

Rate this Article

Adoption
Style

BT