rune-rs / rune

An embeddable dynamic programming language for Rust.
https://rune-rs.github.io
Apache License 2.0
1.7k stars 85 forks source link

Rewrite Rune to use a slot-based virtual machine #733

Closed udoprog closed 1 month ago

udoprog commented 1 month ago

This branch is an attempt at a major rewrite of the internals of how the Rune compiler and runtime works.

This changes the virtual machine to handle allocated slots, rather than a stack. Every operation instead of operating on the stack takes addresses as inputs and outputs.

Furthermore, output addresses have a special mode known as discard, which will make sure that any side effects related to an operation is replicated (like if an error is raised) but a value is not produced.

The calling convention for native functions has also been improved and now involves no stack rearrangement. That is, native calls can be performed within the same stack frame.

New Features

Breaking out of blocks

Since slot assignment is massively simplified with this change, it includes one new feature. The ability to label and break out of blocks:

let cond = 1000;

let value = 'block: {
    if cond > 100 {
        break 'block true;
    }

    false
};