7 releases (breaking)

Uses new Rust 2024

new 0.6.0 Apr 19, 2025
0.5.0 Apr 13, 2025
0.4.1 Apr 3, 2025
0.3.0 Mar 25, 2025
0.1.0 Mar 10, 2025

#285 in Programming languages

Download history 104/week @ 2025-03-10 37/week @ 2025-03-17 198/week @ 2025-03-24 255/week @ 2025-03-31 87/week @ 2025-04-07 110/week @ 2025-04-14

676 downloads per month

MIT license

51KB
1K SLoC

Project Status: Beta License: MIT crates.io tests docs crates

ByteVM

ByteVM is a bytecode virtual machine written in Rust. It is designed to execute programs written in a custom bytecode format. The VM is designed to be fast, efficient, and easy to use. It is intended to be used as a platform for implementing programming languages, interpreters, and compilers.

Status

ByteVM is currently in the early stages of development. The VM is not yet feature complete, and the API is subject to change. The VM is not yet suitable for production use.

Examples


let mut program  = ProgramBuilder::default();

program.add_function(FunctionBuilder::default()
    .name("main")
    .arity(0)
    .body(BlockEncoder::default()
        // Declare a local variable to hold the input
        .declare_local("n")
        .push_integer(input)
        .set_local("n")
        
        // Call the fib function
        .get_local("n")
        .call_function_by_name("fib")
        
        // Return the result
        .return_value()
    )
    .build()
);

program.add_function(FunctionBuilder::default()
    .name("fib")
    .arity(1)
    .body(BlockEncoder::default()
        // Declare local variables for the Fibonacci function
        .declare_local("n")
        
        // if n <= 1 then return n
        .get_local("n")
        .push_integer(1)
        .less_than_or_equal()
        .jump_if_false("end")
        .get_local("n")
        .return_value()
        .add_label("end")
        
        // fib(n - 1)
        .get_local("n")
        .push_integer(1)
        .sub()
        .call_function_by_name("fib")
        
        // fib(n - 2)
        .get_local("n")
        .push_integer(2)
        .sub()
        .call_function_by_name("fib")
        
        // add the results of fib(n-1) and fib(n-2)
        .add()
        
        // return the result
        .return_value())
    .build()
);

let mut vm = Vm::default();
vm.load_program(program.build());
vm.run(None);

Use of AI

Parts of this project were generated using AI tools.

License

ByteVM is distributed under the terms of the MIT license. See LICENSE for details.

Dependencies

~90KB