mirror of
https://github.com/Noratrieb/coldsquare.git
synced 2026-01-15 08:55:10 +01:00
moved into seperate crates
This commit is contained in:
parent
40f1cbfab6
commit
43e2c59e73
14 changed files with 53 additions and 43 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -1,5 +1,18 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "coldsquare"
|
||||
name = "file-info"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"file-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "file-parser"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "machine"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
11
Cargo.toml
11
Cargo.toml
|
|
@ -1,9 +1,2 @@
|
|||
[package]
|
||||
name = "coldsquare"
|
||||
version = "0.1.0"
|
||||
authors = ["Nilstrieb <nilstrieb@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
[workspace]
|
||||
members = ["crates/*"]
|
||||
9
crates/file-info/Cargo.toml
Normal file
9
crates/file-info/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "file-info"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
file-parser = { path = "../file-parser" }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::parse::{ClassFile, ParseErr};
|
||||
use file_parser::{ClassFile, ParseErr};
|
||||
use std::error::Error;
|
||||
use std::io::Write;
|
||||
|
||||
|
|
@ -40,13 +40,13 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
|||
}
|
||||
)?;
|
||||
|
||||
writeln!(w, " Class Attributes:")?;
|
||||
writeln!(w, " Attributes:")?;
|
||||
for attr in &class.attributes {
|
||||
writeln!(w, " {}", &attr.attribute_name_index.get(cp)?)?;
|
||||
}
|
||||
writeln!(w)?;
|
||||
|
||||
writeln!(w, " Class Fields:")?;
|
||||
writeln!(w, " Fields:")?;
|
||||
for field in &class.fields {
|
||||
writeln!(
|
||||
w,
|
||||
|
|
@ -57,7 +57,7 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
|||
}
|
||||
writeln!(w)?;
|
||||
|
||||
writeln!(w, " Class Methods:")?;
|
||||
writeln!(w, " Methods:")?;
|
||||
for method in &class.methods {
|
||||
writeln!(
|
||||
w,
|
||||
8
crates/file-parser/Cargo.toml
Normal file
8
crates/file-parser/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "file-parser"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
//! [The .class specs](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html)
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::parse::ParseErr;
|
||||
use crate::ParseErr;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// All of the Constants in the Constant Pool
|
||||
|
|
@ -37,7 +37,7 @@ fn data_u4() {
|
|||
|
||||
#[test]
|
||||
fn parse_empty_class() {
|
||||
let class = include_bytes!("../../testdata/Test.class");
|
||||
let class = include_bytes!("../../../testdata/Test.class");
|
||||
let parsed = parse_class_file(class).unwrap();
|
||||
|
||||
assert_eq!(parsed.minor_version, 0);
|
||||
|
|
@ -70,21 +70,18 @@ fn parse_empty_class() {
|
|||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 0x10,
|
||||
bytes: "java/lang/Object".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 6,
|
||||
bytes: "<init>".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 3,
|
||||
bytes: "()V".to_string()
|
||||
})
|
||||
},
|
||||
|
|
@ -97,35 +94,30 @@ fn parse_empty_class() {
|
|||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 4,
|
||||
bytes: "Test".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 4,
|
||||
bytes: "Code".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 15,
|
||||
bytes: "LineNumberTable".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 10,
|
||||
bytes: "SourceFile".to_string()
|
||||
})
|
||||
},
|
||||
CpInfo {
|
||||
tag: 1,
|
||||
inner: CpInfoInner::Utf8(cp_info::Utf8 {
|
||||
length: 9,
|
||||
bytes: "Test.java".to_string()
|
||||
})
|
||||
}
|
||||
|
|
@ -147,7 +139,7 @@ fn parse_empty_class() {
|
|||
|
||||
#[test]
|
||||
fn more_complex_file() {
|
||||
let class = include_bytes!("../../testdata/Test2.class");
|
||||
let class = include_bytes!("../../../testdata/Test2.class");
|
||||
let parsed = parse_class_file(class).unwrap();
|
||||
assert_eq!(parsed.magic, 0xCAFEBABE);
|
||||
}
|
||||
8
crates/machine/Cargo.toml
Normal file
8
crates/machine/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "machine"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -49,7 +49,7 @@ impl LocalVariables {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::execute::model::{LocalVariables, OperandStack};
|
||||
use super::{LocalVariables, OperandStack};
|
||||
|
||||
#[test]
|
||||
fn operand_stack() {
|
||||
4
file-info.sh
Normal file
4
file-info.sh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd crates/file-info
|
||||
cargo run ../../"$1"
|
||||
17
src/lib.rs
17
src/lib.rs
|
|
@ -1,17 +0,0 @@
|
|||
use crate::parse::{ClassFile, ParseErr};
|
||||
use std::error::Error;
|
||||
|
||||
mod execute;
|
||||
mod parse;
|
||||
mod ui;
|
||||
|
||||
pub fn parse_class_file(file: &[u8]) -> Result<ClassFile, ParseErr> {
|
||||
parse::parse_class_file(file)
|
||||
}
|
||||
|
||||
pub fn display_class<W>(w: W, class: &ClassFile) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
W: std::io::Write,
|
||||
{
|
||||
ui::display_class(w, class)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue