maximecb / uvm

Fun, portable, minimalistic virtual machine.
Apache License 2.0
539 stars 19 forks source link
bytecode bytecode-interpreter compiler containerization emulation emulator interpreter jit-compiler permacomputing rust sandboxing uvm virtual-machine

UVM

NOTE: this project is very much a work in progress. You're likely to run into bugs and missing features. I would like to find collaborators who share the vision and want to help me make it happen.

   

A simple, minimalistic virtual machine designed to run self-contained applications. UVM is intended as a platform to distribute programs that will not break and to combat code rot. It aims to be conceptually simple, easy to understand, easy to target, fun to work with and approachable to newcomers. It may also be valuable as a teaching tool or as a platform to experiment with. There is a short 4-minute overview of UVM on YouTube if you'd like to see a quick survey.

Contents:

If you think that UVM is cool, you can support my work via GitHub Sponsors :heart:

Features

Current features:

Planned future features:

Build Instructions

Dependencies:

Installing Rust and SDL2 on macOS

Install the SDL2 package:

brew install sdl2

Add this to your ~/.zprofile:

export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"

Install the Rust toolchain:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Installing Rust and SDL2 on Debian/Ubuntu

Install the SDL2 package:

sudo apt-get install libsdl2-dev

Install the Rust toolchain:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Installing Rust and SDL2 on Windows

Follow the Windows-specific instructions to install the Rust toolchain.

Get SDL2.dll from one of SDL2 Releases.

Copy SDL2.dll (unzip) to the vm/ folder.

Compiling the Project

cd vm
cargo build

To run an asm file with UVM:

cargo run examples/fizzbuzz.asm

There is also a toy C compiler in the ncc directory, along with many example C programs that run on UVM:

cd ncc
./build_and_run.sh examples/snake.c

Running the Test Suite

Run cargo test from the vm, and ncc directories.

Codebase Organization

The repository is organized into a 3 different subprojects, each of which is a Rust codebase which can be compiled with cargo:

The ncc compiler is, at the time of this writing, incomplete in that it lacks some C features and the error messages need improvement. This compiler was implemented to serve as an example of how to write a compiler that targets UVM, and to write some library code to be used by other programs. Over time, the ncc compiler will be improved. Despite its limitations, it is still usable to write small programs. Contributions to it are welcome.

The api directory contains JSON files that represent a declarative list of system calls, constants and the permission system that UVM exposes to programs running on it. This is helpful for documentation purposes, or if you want to build a compiler that targets UVM. The directory also contains code that automatically generates markdown documentation, Rust constants and C definitions for system calls.

Open Source License

The code for UVM, NCC and associated tools is shared under the Apache-2.0 license.

The examples under the vm/examples and ncc/examples directories are shared under the Creative Commons CC0 license.

Contributing

There is a lot of work to be done to get this project going and contributions are welcome.

A good first step is to look at open issues and read the available documentation. Another easy way to contribute is to create new example programs showcasing cool things you can do with UVM, or to open issues to report bugs. If you do report bugs, please provide as much context as possible, and the smallest reproduction you can come up with.

You can also search the codebase for TODO or FIXME notes:

grep -IRi "todo" .

In general, smaller pull requests are easier to review and have a much higher chance of getting merged than large pull requests. If you would like to add a new, complex feature or refactor the design of UVM, I recommend opening an issue or starting a discussion about your proposed change first.

Also please keep in mind that one of the core principles of UVM is to minimize dependencies to keep the VM easy to install and easy to port. Opening a PR that adds dependencies to multiple new packages and libraries is unlikely to get merged. Again, if you have a valid argument in favor of doing so, please open a discussion to share your point of view.