Tom Lauwaerts, Robbert Gurdeep Singh , Christophe Scholliers
{"title":"WARDuino:嵌入式 WebAssembly 虚拟机","authors":"Tom Lauwaerts, Robbert Gurdeep Singh , Christophe Scholliers","doi":"10.1016/j.cola.2024.101268","DOIUrl":null,"url":null,"abstract":"<div><p>Creating IoT programs for resource-constrained microcontrollers differs significantly from conventional computer programming. Microcontrollers are traditionally programmed using low-level programming languages with poor debugging facilities. By contrast, general-purpose systems can be programmed with high-level languages, which make programming easier by providing many useful tools such as advanced debuggers, strong type systems, and/or automatic memory management. Most existing solutions for programming microcontrollers with high-level languages are strongly tied to a specific microcontroller architecture, which makes porting code difficult or impossible. In addition, compiling and flashing software onto a microcontroller is time-consuming, slowing down development.</p><p>To solve these problems we present WARDuino, a WebAssembly virtual machine that runs on microcontrollers and provides WebAssembly primitives to control embedded hardware and IoT functionality. WARDuino runs programs written in a plethora of high-level languages that compile to WebAssembly. We give a general approach for language integration libraries to expose the peripherals and networking capabilities of the device following the idioms of the host language.</p><p>To ease development, we extend WebAssembly with support for remote debugging and over-the-air reprogramming. WARDuino can remotely instruct a microcontroller to pause, to step, or to dump its state, and to replace local variables, functions or even the entire running program. We use the remote debugger of the virtual machine to create a visual debugging environment in VS Code for WARDuino, that can debug WebAssembly and AssemblyScript. Aside from these important tools, we provide a novel mechanism to handle asynchronous interrupts in WebAssembly, a fundamental building block for responsive embedded applications. Our extensions are implemented in the WARDuino virtual machine and presented as formal extensions to the WebAssembly operational semantics. We use the formalization to proof observational equivalence for the core debugger semantics.</p><p>We compared the computational performance and memory size with native C code, Espruino, and WASM3 which compiles WebAssembly ahead-of-time. The comparison shows that WARDuino’s performance is acceptable. Although WARDuino is on average 425.93 times slower than native code and 37.96 times slower than WASM3, it outperforms the popular Espruino runtime by a factor of 11.66. Additionally, we show that WARDuino is fast enough to program traditional IoT applications that handle network and device interrupts with a classic smart lamp application written in AssemblyScript.</p></div>","PeriodicalId":48552,"journal":{"name":"Journal of Computer Languages","volume":"79 ","pages":"Article 101268"},"PeriodicalIF":1.7000,"publicationDate":"2024-02-13","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":"{\"title\":\"WARDuino: An embedded WebAssembly virtual machine\",\"authors\":\"Tom Lauwaerts, Robbert Gurdeep Singh , Christophe Scholliers\",\"doi\":\"10.1016/j.cola.2024.101268\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"<div><p>Creating IoT programs for resource-constrained microcontrollers differs significantly from conventional computer programming. Microcontrollers are traditionally programmed using low-level programming languages with poor debugging facilities. By contrast, general-purpose systems can be programmed with high-level languages, which make programming easier by providing many useful tools such as advanced debuggers, strong type systems, and/or automatic memory management. Most existing solutions for programming microcontrollers with high-level languages are strongly tied to a specific microcontroller architecture, which makes porting code difficult or impossible. In addition, compiling and flashing software onto a microcontroller is time-consuming, slowing down development.</p><p>To solve these problems we present WARDuino, a WebAssembly virtual machine that runs on microcontrollers and provides WebAssembly primitives to control embedded hardware and IoT functionality. WARDuino runs programs written in a plethora of high-level languages that compile to WebAssembly. We give a general approach for language integration libraries to expose the peripherals and networking capabilities of the device following the idioms of the host language.</p><p>To ease development, we extend WebAssembly with support for remote debugging and over-the-air reprogramming. WARDuino can remotely instruct a microcontroller to pause, to step, or to dump its state, and to replace local variables, functions or even the entire running program. We use the remote debugger of the virtual machine to create a visual debugging environment in VS Code for WARDuino, that can debug WebAssembly and AssemblyScript. Aside from these important tools, we provide a novel mechanism to handle asynchronous interrupts in WebAssembly, a fundamental building block for responsive embedded applications. Our extensions are implemented in the WARDuino virtual machine and presented as formal extensions to the WebAssembly operational semantics. We use the formalization to proof observational equivalence for the core debugger semantics.</p><p>We compared the computational performance and memory size with native C code, Espruino, and WASM3 which compiles WebAssembly ahead-of-time. The comparison shows that WARDuino’s performance is acceptable. Although WARDuino is on average 425.93 times slower than native code and 37.96 times slower than WASM3, it outperforms the popular Espruino runtime by a factor of 11.66. Additionally, we show that WARDuino is fast enough to program traditional IoT applications that handle network and device interrupts with a classic smart lamp application written in AssemblyScript.</p></div>\",\"PeriodicalId\":48552,\"journal\":{\"name\":\"Journal of Computer Languages\",\"volume\":\"79 \",\"pages\":\"Article 101268\"},\"PeriodicalIF\":1.7000,\"publicationDate\":\"2024-02-13\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"0\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Journal of Computer Languages\",\"FirstCategoryId\":\"94\",\"ListUrlMain\":\"https://www.sciencedirect.com/science/article/pii/S259011842400011X\",\"RegionNum\":3,\"RegionCategory\":\"计算机科学\",\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"Q3\",\"JCRName\":\"COMPUTER SCIENCE, SOFTWARE ENGINEERING\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Computer Languages","FirstCategoryId":"94","ListUrlMain":"https://www.sciencedirect.com/science/article/pii/S259011842400011X","RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q3","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
Creating IoT programs for resource-constrained microcontrollers differs significantly from conventional computer programming. Microcontrollers are traditionally programmed using low-level programming languages with poor debugging facilities. By contrast, general-purpose systems can be programmed with high-level languages, which make programming easier by providing many useful tools such as advanced debuggers, strong type systems, and/or automatic memory management. Most existing solutions for programming microcontrollers with high-level languages are strongly tied to a specific microcontroller architecture, which makes porting code difficult or impossible. In addition, compiling and flashing software onto a microcontroller is time-consuming, slowing down development.
To solve these problems we present WARDuino, a WebAssembly virtual machine that runs on microcontrollers and provides WebAssembly primitives to control embedded hardware and IoT functionality. WARDuino runs programs written in a plethora of high-level languages that compile to WebAssembly. We give a general approach for language integration libraries to expose the peripherals and networking capabilities of the device following the idioms of the host language.
To ease development, we extend WebAssembly with support for remote debugging and over-the-air reprogramming. WARDuino can remotely instruct a microcontroller to pause, to step, or to dump its state, and to replace local variables, functions or even the entire running program. We use the remote debugger of the virtual machine to create a visual debugging environment in VS Code for WARDuino, that can debug WebAssembly and AssemblyScript. Aside from these important tools, we provide a novel mechanism to handle asynchronous interrupts in WebAssembly, a fundamental building block for responsive embedded applications. Our extensions are implemented in the WARDuino virtual machine and presented as formal extensions to the WebAssembly operational semantics. We use the formalization to proof observational equivalence for the core debugger semantics.
We compared the computational performance and memory size with native C code, Espruino, and WASM3 which compiles WebAssembly ahead-of-time. The comparison shows that WARDuino’s performance is acceptable. Although WARDuino is on average 425.93 times slower than native code and 37.96 times slower than WASM3, it outperforms the popular Espruino runtime by a factor of 11.66. Additionally, we show that WARDuino is fast enough to program traditional IoT applications that handle network and device interrupts with a classic smart lamp application written in AssemblyScript.