rusty_jvm/
lib.rs

1//! # Rusty JVM
2//!
3//! A JVM interpreter written in Rust from scratch — no dependency on existing JVMs.
4//!
5//! `rusty-jvm` executes Java bytecode in interpreted mode and aims to support as much of the Java language as possible.
6//! Currently supports a range of Java language features up to Java 23 (excluding GC and lambdas for now).
7//!
8//! ## Features
9//! Refer to the [README.md](https://github.com/hextriclosan/rusty-jvm/blob/main/README.md#implemented-key-features)
10//!
11//! ## Usage
12//!
13//! ### Creating a simple Java program
14//! ###### Windows
15//! ```bash
16//! echo public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } } > Hello.java
17//! ```
18//! ###### Unix-like systems
19//! ```bash
20//! echo 'public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } }' > Hello.java
21//! ```
22//! ### Compiling the Java program (current supported version is Java 23)
23//! ```bash
24//! javac Hello.java
25//! ```
26//! ### Running the compiled Java program with Rusty JVM
27//! ```bash
28//! rusty-jvm Hello
29//! ```
30mod vm;
31use derive_new::new;
32use getset::Getters;
33use indexmap::IndexMap;
34pub use vm::run;
35
36#[derive(PartialEq, Debug, new, Getters, Default)]
37#[get = "pub"]
38/// Represents the command-line arguments for the Java program.
39pub struct Arguments {
40    /// The entry point for the Java program.  
41    /// This may be empty when running in install or purge mode.
42    entry_point: String,
43    /// The arguments passed to the Java program.
44    program_args: Vec<String>,
45    /// The standard Java options (e.g., `-version`, `-help`).
46    java_standard_options: Vec<String>,
47    /// The options passed to the Java launcher (e.g., `--install`, `--purge`).
48    java_launcher_options: Vec<String>,
49    /// System properties set for the Java program (e.g., `-Dproperty=value`).
50    system_properties: IndexMap<String, String>,
51    /// JVM options (e.g., `-Xmx1024m`).
52    jvm_options: Vec<String>,
53    /// Advanced JVM options (e.g., `-XX:+UseG1GC`).
54    advanced_jvm_options: Vec<String>,
55}
56
57impl Arguments {
58    /// Creates a new `Arguments` instance with the specified entry point.
59    /// # Arguments
60    /// * `entry_point` - The entry point for the Java program.
61    /// # Returns
62    /// A new `Arguments` instance with the specified entry point and default values for other fields.
63    pub fn new_with_entry_point(entry_point: String) -> Self {
64        Self {
65            entry_point,
66            ..Default::default()
67        }
68    }
69}