rusty_jvm/lib.rs
1//! # Rusty JVM
2//!
3//! A Java Virtual Machine (JVM) interpreter written in Rust from scratch — with 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//! It currently supports a broad set of language features up to Java 23, with garbage collection and multithreading planned for future releases.
7//!
8//! ## Features
9//! See the [README.md](https://github.com/hextriclosan/rusty-jvm/blob/rusty_jvm-v0.4.0/README.md#implemented-key-features) for the full list of implemented features.
10//!
11//! ## Usage
12//!
13//! ### Step 1: Create a simple Java program
14//! Create a file named `Hello.java` with the following content:
15//! ```java
16//! public class Hello {
17//! public static void main(String[] args) {
18//! System.out.println("Hello, world!");
19//! }
20//! }
21//! ```
22//!
23//! #### Shortcut (one-liner)
24//! On Windows (cmd):
25//! ```shell
26//! echo public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } } > Hello.java
27//! ```
28//! On Unix-like systems:
29//! ```bash
30//! echo 'public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } }' > Hello.java
31//! ```
32//!
33//! ### Step 2: Compile the Java program (currently tested with Java 23)
34//! ```bash
35//! javac Hello.java
36//! ```
37//!
38//! ### Step 3: Run the compiled Java program with Rusty JVM
39//! ```bash
40//! rusty-jvm Hello
41//! ```
42mod vm;
43use derive_new::new;
44use getset::Getters;
45use indexmap::IndexMap;
46pub use vm::run;
47
48#[derive(PartialEq, Debug, new, Getters, Default)]
49#[get = "pub"]
50/// Represents the command-line arguments for the Java program.
51pub struct Arguments {
52 /// The entry point for the Java program.
53 /// This may be empty when running in install or purge mode.
54 entry_point: String,
55 /// The arguments passed to the Java program.
56 program_args: Vec<String>,
57 /// The standard Java options (e.g., `-version`, `-help`).
58 java_standard_options: Vec<String>,
59 /// The options passed to the Java launcher (e.g., `--dry-run`).
60 java_launcher_options: Vec<String>,
61 /// System properties set for the Java program (e.g., `-Dproperty=value`).
62 system_properties: IndexMap<String, String>,
63 /// JVM options (e.g., `-Xmx1024m`).
64 jvm_options: Vec<String>,
65 /// Advanced JVM options (e.g., `-XX:+UseG1GC`).
66 advanced_jvm_options: Vec<String>,
67}
68
69impl Arguments {
70 /// Creates a new `Arguments` instance with the specified entry point.
71 /// # Arguments
72 /// * `entry_point` - The entry point for the Java program.
73 /// # Returns
74 /// A new `Arguments` instance with the specified entry point and default values for other fields.
75 pub fn new_with_entry_point(entry_point: String) -> Self {
76 Self {
77 entry_point,
78 ..Default::default()
79 }
80 }
81}