Crates.io | bytevm |
lib.rs | bytevm |
version | |
source | src |
created_at | 2025-03-10 21:25:00.848955+00 |
updated_at | 2025-04-19 19:39:23.501298+00 |
description | A tiny bytecode virtual machine |
homepage | |
repository | https://github.com/burdockcascade/bytevm |
max_upload_size | |
id | 1587243 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
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.
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);
Parts of this project were generated using AI tools.
ByteVM is distributed under the terms of the MIT license. See LICENSE for details.