-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/cargo/zip-2.1
- Loading branch information
Showing
35 changed files
with
900 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ members = [ | |
"model", | ||
"loader", | ||
"parser", | ||
# "vm", | ||
"vm", | ||
"rt", | ||
"cli", | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use anyhow::{bail, Context, Result}; | ||
|
||
use crate::{class::ClassConstant, prelude::ClassConstants}; | ||
|
||
impl ClassConstant { | ||
pub fn ok_and_utf8_or(&self) -> Result<&String> { | ||
match self { | ||
&ClassConstant::Utf8(ref string) => Ok(string), | ||
it => bail!("Expected Utf8 but found {:?}", it), | ||
} | ||
} | ||
|
||
pub fn ok_and_class_or(&self) -> Result<&String> { | ||
match self { | ||
&ClassConstant::Class(ref string) => Ok(string), | ||
it => bail!("Expected Class but found {:?}", it), | ||
} | ||
} | ||
} | ||
|
||
pub trait ClassConstantAccessor { | ||
fn get_utf8_or(&self, idx: usize) -> Result<&String>; | ||
fn get_class_or(&self, idx: usize) -> Result<&String>; | ||
} | ||
|
||
impl ClassConstantAccessor for ClassConstants { | ||
fn get_utf8_or(&self, idx: usize) -> Result<&String> { | ||
self.get(idx) | ||
.context(format!("get constant with index {}", idx))? | ||
.ok_and_utf8_or() | ||
} | ||
|
||
fn get_class_or(&self, idx: usize) -> Result<&String> { | ||
self.get(idx) | ||
.context(format!("get constant with index {}", idx))? | ||
.ok_and_class_or() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
pub mod api; | ||
pub mod class; | ||
pub mod class_impl; | ||
pub mod class_constant_impl; | ||
|
||
pub mod prelude { | ||
pub use crate::class::{ClassAttribute, JvmClass}; | ||
} | ||
pub use crate::class::{*}; | ||
pub use crate::class_constant_impl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::io::Read; | ||
|
||
use anyhow::Result; | ||
use class_constant_impl::ClassConstantAccessor; | ||
use model::prelude::*; | ||
|
||
use crate::util; | ||
use crate::attributes; | ||
|
||
pub fn parse<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Code> { | ||
/*let attribute_length = */util::read_u32(reader)?; | ||
|
||
let max_stack = util::read_u16(reader)?; | ||
let max_locals = util::read_u16(reader)?; | ||
|
||
let code_length = util::read_u32(reader)? as usize; | ||
let code = util::read_raw(reader, code_length)?; | ||
|
||
let exception_table = parse_exception_table(reader, constants)?; | ||
let attributes = attributes::parse(reader, constants)?; | ||
|
||
Ok(Code { | ||
max_stack, | ||
max_locals, | ||
code, | ||
exception_table, | ||
attributes, | ||
}) | ||
} | ||
|
||
fn parse_exception_table<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Vec<ExceptionTable>> { | ||
let exception_table_length = util::read_u16(reader)? as usize; | ||
let mut entries = Vec::with_capacity(exception_table_length); | ||
|
||
for _ in 0..exception_table_length { | ||
entries.push(ExceptionTable { | ||
start_pc: util::read_u16(reader)?, | ||
end_pc: util::read_u16(reader)?, | ||
handler_pc: util::read_u16(reader)?, | ||
catch_type: parse_exception_table_catch_type(reader, constants)?, | ||
}) | ||
} | ||
|
||
Ok(entries) | ||
} | ||
|
||
fn parse_exception_table_catch_type<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Option<String>> { | ||
let class_name_index = util::read_u16(reader)? as usize; | ||
let class_name = if class_name_index == 0 { | ||
None | ||
} else { | ||
Some(constants.get_class_or(class_name_index)?.clone()) | ||
}; | ||
|
||
Ok(class_name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::io::Read; | ||
|
||
use anyhow::Context; | ||
use anyhow::Result; | ||
use model::prelude::*; | ||
|
||
use crate::util; | ||
|
||
pub fn parse<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<ClassConstant> { | ||
/*let attribute_length = */util::read_u32(reader)?; | ||
|
||
let constant_index = util::read_u16(reader)? as usize; | ||
let constant = constants.get(constant_index).context(format!("get constant with index {constant_index}"))?.clone(); | ||
|
||
Ok(constant) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::io::Read; | ||
|
||
use anyhow::Result; | ||
use class_constant_impl::ClassConstantAccessor; | ||
use model::prelude::*; | ||
|
||
use crate::util; | ||
use crate::attributes; | ||
|
||
pub fn parse<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Vec<LocalVariableTable>> { | ||
let _attribute_length = util::read_u32(reader)?; | ||
let local_variable_table_length = util::read_u16(reader)? as usize; | ||
|
||
let max_stack = util::read_u16(reader)?; | ||
let max_locals = util::read_u16(reader)?; | ||
|
||
let code_length = util::read_u32(reader)? as usize; | ||
let code = util::read_raw(reader, code_length)?; | ||
|
||
let exception_table = parse_exception_table(reader, constants)?; | ||
let attributes = attributes::parse(reader, constants)?; | ||
|
||
Ok(Code { | ||
max_stack, | ||
max_locals, | ||
code, | ||
exception_table, | ||
attributes, | ||
}) | ||
} | ||
|
||
fn parse_exception_table<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Vec<ExceptionTable>> { | ||
let exception_table_length = util::read_u16(reader)? as usize; | ||
let mut entries = Vec::with_capacity(exception_table_length); | ||
|
||
for _ in 0..exception_table_length { | ||
entries.push(ExceptionTable { | ||
start_pc: util::read_u16(reader)?, | ||
end_pc: util::read_u16(reader)?, | ||
handler_pc: util::read_u16(reader)?, | ||
catch_type: parse_exception_table_catch_type(reader, constants)?, | ||
}) | ||
} | ||
|
||
Ok(entries) | ||
} | ||
|
||
fn parse_exception_table_catch_type<T: Read>(reader: &mut T, constants: &ClassConstants) -> Result<Option<String>> { | ||
let class_name_index = util::read_u16(reader)? as usize; | ||
let class_name = if class_name_index == 0 { | ||
None | ||
} else { | ||
Some(constants.get_class_or(class_name_index)?.clone()) | ||
}; | ||
|
||
Ok(class_name) | ||
} |
Oops, something went wrong.