MiniScript Ports
Tags: miniscript, programming, languages
Published: 2024-02-07 15:27:52

Since its introduction in 2017, [MiniScript](https://miniscript.org)'s community has been steadily growing.  And a delightful community it is — it spans the gamut from brand-new, never-coded-before beginners to experienced software engineers.

Some of those experienced community members have gone so far as to port or reimplement MiniScript in other languages and environments.  Because of its minimal nature (see its [one-page quick reference](https://miniscript.org/files/MiniScript-QuickRef.pdf)!), implementing an interpreter or bytecode compiler for MiniScript is a much more accessible task than for most other languages.  Let's take a look at some of the ports currently available.

## Official Reference Implementations

There are two official reference implementations of MiniScript: one in C#, and one in C++.  Both are actively maintained, and available [on GitHub](https://github.com/JoeStrout/miniscript).

## Java and Kotlin

There are two MiniScript ports that run on the JVM (Java Virtual Machine).  The first one was actually written for Kotlin, and is available [here](https://github.com/Arcnor/miniscript-kt).  It was last updated over 4 years ago, so it's probably a little out of date now, but would be an excellent starting point and probably wouldn't take much effort to refresh.

The other one is for standard Java, available [here](https://github.com/heatseeker0/JavaMiniScript).  It was last updated 2 years ago, so it's a bit newer but still not completely current.  This might be an excellent launching point to adding MiniScript support to a Java-based game or app.  ([Minecraft mods](https://mcreator.net/) leap to mind!)

## MiniScript in MiniScript

Active community member Marc Gurevitx has recently published a project called [ms.ms](https://github.com/marcgurevitx/ms-ms), a MiniScript interpreter _written in MiniScript_.

![MiniScript in MiniScript?!?](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExeGx2NGN0d3diYjc1YWQ2d2JxMWtpc3czaHZuamo3b2xsajR5eDZ3ayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/xThuWu82QD3pj4wvEQ/giphy.gif)

While Marc is quick to warn you that the result runs slowly, in cases where you need something like this, that's not the point.  Among other tricks, gives MiniScript an "eval" function — a way to evaluate an arbitrary snippet of MiniScript code stored in a string, from within your own MiniScript program.

(ms-ms is based on another of Marc's projects, [peg-ms](https://github.com/marcgurevitx/peg-ms/tree/aa191eccec3d8414ddd5746b46e892a3123bf67a), which implements [Parsing Expression Grammars](https://en.wikipedia.org/wiki/Parsing_expression_grammar).  That's a topic that's dear to me as well — see my [2011 blog post](https://luminaryapps.com/blog/better-text-searching-with-peg/) extolling the virtues of PEG over regular expressions!)

## MiniScript in TypeScript

Finally (for now!), another active community member Sebastian Nozzi (@sebnozzi) has been developing a MiniScript implementation in JavaScript — or more specifically, TypeScript (strongly-typed JavaScript).  This enables MiniScript to run directly in a web browser!  It's fast, too; on some code, the speed is comparable to command-line MiniScript or Mini Micro running on your local machine.

He's currently divided his work into two projects on GitHub: [MiniScript.TS](https://github.com/sebnozzi/miniscript.ts) is the language core, while [MiniScript-NodeJS](https://github.com/sebnozzi/miniscript-nodejs) adds Node.js support and a script-runner.  The latter includes support for `print` and `input`, the [`import`](https://miniscript.org/wiki/Import) command, and a subset of the Mini Micro [/sys disk](https://github.com/JoeStrout/minimicro-sysdisk).

The importance of this work cannot be overstated.  Until now, the only way to run MiniScript code in a web browser was to send it to a back-end server running a command-line build (like our current [Try-It! page](https://miniscript.org/tryit/), or to use the web version of [Mini Micro](https://miniscript.org/MiniMicro/), which is built in Unity and does not work well on mobile browsers.  All that has changed!  Now we can run MiniScript code directly in the browser, no need for a backend server.  And Seb has already ported several of his old Mini Micro games, like [Sliding Puzzle](https://sebnozzi.itch.io/sliding-puzzle) and [Foggy Window](https://sebnozzi.itch.io/foggy-window), to use his MiniScript.TS engine rather than Mini Micro, enabling them to work fine even on mobile devices.

I'm already planning to work with Seb to reimplement the official MiniScript Try-It! page using his port, as well as the [Robo-Reindeer Rumble](https://miniscript.org/RoboReindeer/) game.  Eventually, I expect to see an explosion of web-based apps and game development environments based on MiniScript and running happily within the browser.  All thanks to the hard work @sebnozzi's been putting in on MiniScript.TS and related code!

## Future Work

The official [MiniScript discord server](https://discord.gg/7s6zajx) has a #ports channel, where anybody interested in porting MiniScript (or working with existing ports) can discuss.  Projects that have been kicked around there include porting MiniScript to:

• Go
• Rust
• Lua
• pure C (sans C++)
• 6502 assembly
• WebAssembly
• compiler backends, like [LLVM](https://llvm.org/) or [Cranelift](https://cranelift.dev/)

It's exciting to see all this work going on!  And remember, if you've ever wanted to find out what it's like to implement a language, MiniScript is a great choice — tiny enough to be relatively easy to implement, but powerful enough to be useful for real programs.  And you'll have an entire community of enthusiastic users cheering you on!