Roto: A Compiled Scripting Language for Rust

https://news.ycombinator.com/rss Hits: 4
Summary

By Terts Diepraam We are working on an embedded scripting language for Rust. This language, called Roto, aims to be a simple yet fast and reliable scripting language for Rust applications. The need for Roto comes from Rotonda, our BGP engine written in Rust. Mature BGP applications usually feature some way to filter incoming route announcements. The complexity of these filters often exceed the capabilities of configuration languages. With Rotonda, we want to allow our users to write more complex filters with ease. So we decided to give them the power of a full scripting language. We have some hard requirements for this language. First, we need these filters to be fast. Second, Rotonda is critical infrastructure and so runtime crashes are unacceptable. This rules out dynamically typed languages, of which there are plenty in the Rust community. We want a statically typed language which can give us more type safety and speed. Finally, we want a language that is easy to pick up; it should feel like a statically typed version of scripting languages you're used to. Roto fills this niche for us. In short, it's a statically typed, JIT compiled, hot-reloadable, embedded scripting language. To get good performance, Roto scripts are compiled to machine code at runtime with the cranelift compiler backend. Below is a small sample of a Roto script. In this script, we define a filtermap, which results in either accept or reject. In this case, we accept when the IP address is within the given range. filtermap within_range(range: AddrRange, ip: IpAddr) { if range.contains(ip) { accept ip } else { reject } } Instead of a filtermap, we could instead write a more conventional function, which can simply return a value. The filtermap is a construct that Roto supports to make writing filters easier. The Roto code there might look quite simple, but there's a twist: AddrRange is not a built-in type. Instead, it is added to Roto by the host application (e.g. Rotonda), making it available for...

First seen: 2025-05-21 13:20

Last seen: 2025-05-21 16:21