Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy class loading including significant refactoring #20

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ members = ["jclass", "jdescriptor", "vm"]
clap = "4.5.16"
vm = {path = "vm"}

[dev-dependencies]
ctor = "0.2.8"
32 changes: 16 additions & 16 deletions jclass/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::extractors::{get_bitfield, get_bytes, get_int};
use bitflags::bitflags;
use std::io::ErrorKind::InvalidData;

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum Attribute {
ConstantValue {
constantvalue_index: u16,
Expand Down Expand Up @@ -92,7 +92,7 @@ pub enum Attribute {
},
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct ExceptionRecord {
start_pc: u16,
end_pc: u16,
Expand Down Expand Up @@ -123,7 +123,7 @@ impl ExceptionRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct LineNumberRecord {
start_pc: u16,
line_number: u16,
Expand All @@ -144,7 +144,7 @@ impl LineNumberRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct LocalVariableTableRecord {
start_pc: u16,
length: u16,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl LocalVariableTableRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct LocalVariableTypeTableRecord {
start_pc: u16,
length: u16,
Expand Down Expand Up @@ -229,15 +229,15 @@ impl LocalVariableTypeTableRecord {
}

bitflags! {
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct MethodParameterFlags: u16 {
const ACC_FINAL = 0x0010; // Indicates that the formal parameter was declared final.
const ACC_SYNTHETIC = 0x1000; // Indicates that the formal parameter was not explicitly or implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is an implementation artifact of the compiler which produced this class file.)
const ACC_MANDATED = 0x8000; // Indicates that the formal parameter was implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is mandated by a language specification, so all compilers for the language must emit it.)
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct MethodParameterRecord {
name_index: u16,
access_flags: MethodParameterFlags,
Expand All @@ -258,7 +258,7 @@ impl MethodParameterRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum StackMapFrame {
SameFrame {
frame_type: u8,
Expand Down Expand Up @@ -295,7 +295,7 @@ pub enum StackMapFrame {
},
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum VerificationTypeInfo {
TopVariableInfo,
IntegerVariableInfo,
Expand All @@ -308,7 +308,7 @@ pub enum VerificationTypeInfo {
UninitializedVariableInfo { offset: u16 },
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Annotation {
type_index: u16,
element_value_pairs: Vec<ElementValuePair>,
Expand All @@ -329,7 +329,7 @@ impl Annotation {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct ElementValuePair {
element_name_index: u16,
value: ElementValue,
Expand All @@ -350,7 +350,7 @@ impl ElementValuePair {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum ElementValue {
ConstValueIndex {
tag: u8,
Expand All @@ -376,7 +376,7 @@ pub enum ElementValue {
}

bitflags! {
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct NestedClassFlags: u16 {
const ACC_PUBLIC = 0x0001; // Marked or implicitly public in source.
const ACC_PRIVATE = 0x0002; // Marked private in source.
Expand All @@ -391,7 +391,7 @@ bitflags! {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct InnerClassRecord {
inner_class_info_index: u16,
outer_class_info_index: u16,
Expand Down Expand Up @@ -427,7 +427,7 @@ impl InnerClassRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BootstrapMethodRecord {
bootstrap_method_ref: u16,
bootstrap_arguments: Vec<u16>,
Expand All @@ -448,7 +448,7 @@ impl BootstrapMethodRecord {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct RecordComponentInfo {
name_index: u16,
descriptor_index: u16,
Expand Down
2 changes: 1 addition & 1 deletion jclass/src/constant_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::extractors::{get_float, get_int, get_string};
use std::io::ErrorKind::InvalidInput;

#[repr(u8)]
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum ConstantPool {
Empty = 0,
Utf8 {
Expand Down
2 changes: 1 addition & 1 deletion jdescriptor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum DescriptorError {
TooManyDimensions,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum TypeDescriptor {
Byte,
Char,
Expand Down
30 changes: 8 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{arg, Arg, ArgAction, Command};
use clap::{arg, Command};
use std::process;
use vm::vm::VM;

Expand All @@ -14,29 +14,15 @@ fn main() {
.help("Class to run")
.required(true),
)
.arg(
Arg::new("classes")
.action(ArgAction::Append)
.help("Java classes to load")
.required(true),
)
.get_matches();

let std_dir = matches.get_one::<String>("std-dir").unwrap();
let entry_point = matches.get_one::<String>("entry-point").unwrap();
let classes = matches
.get_many::<String>("classes")
.unwrap()
.into_iter()
.map(|s| s.as_str())
.collect();
let vm = match VM::new(classes, std_dir) {
Ok(vm) => vm,
Err(err) => {
eprintln!("Failed to create VM: {}", err);
process::exit(1);
}
};
let std_dir = matches
.get_one::<String>("std-dir")
.expect("Missing standard library directory");
let entry_point = matches
.get_one::<String>("entry-point")
.expect("Missing entry point");
let mut vm = VM::new(std_dir);

let result = match vm.run(entry_point) {
Ok(output) => output,
Expand Down
Loading