Entrypoint call entry methodgit add .

This commit is contained in:
VegOwOtenks 2024-09-02 11:28:00 +02:00
parent ea3666aad3
commit 2042007242
9 changed files with 573 additions and 119 deletions

View file

@ -2,7 +2,7 @@
use crate::classfile::{ JavaClassFile, AttributeData };
#[derive(Copy, Clone, Debug)]
pub enum LocalVariable {
pub enum Value {
Boolean(bool),
Byte(u8),
Char(u16),
@ -20,14 +20,14 @@ pub enum LocalVariable {
#[derive(Debug)]
pub struct OperandStack {
stack: Box<[LocalVariable]>,
stack: Box<[Value]>,
depth: u16,
}
impl OperandStack {
fn new(size: u16) -> Self {
return OperandStack {
stack: vec![LocalVariable::Empty(); size.into()].into_boxed_slice(),
stack: vec![Value::Empty(); size.into()].into_boxed_slice(),
depth: 0,
}
}
@ -35,25 +35,32 @@ impl OperandStack {
#[derive(Debug)]
pub struct StackFrame {
locals: Box<[LocalVariable]>,
operand_stack: OperandStack,
class_id: usize,
method_index: u16,
instruction_pointer: u32,
pub locals: Box<[Value]>,
pub operand_stack: OperandStack,
pub class_index: usize,
pub method_index: u16,
pub instruction_pointer: u32,
}
impl StackFrame {
pub fn new(classfile: &JavaClassFile, class_id: usize, method_index: u16) -> Self {
pub fn new(classfile: &JavaClassFile, class_index: usize, method_index: u16, arguments: &[Value]) -> Self {
let method_info = &classfile.methods[method_index as usize];
let code_data = match &method_info.attributes[method_info.code_attribute_index].data {
AttributeData::Code(data) => data,
_ => unreachable!(),
};
let mut locals = vec![Value::Empty(); code_data.max_locals.into()].into_boxed_slice();
assert!(locals.len() >= arguments.len());
for (index, v) in arguments.iter().enumerate() {
locals[index] = *v;
}
StackFrame {
locals: vec![LocalVariable::Empty(); code_data.max_locals.into()].into_boxed_slice(),
locals,
operand_stack: OperandStack::new(code_data.max_stack),
class_id,
class_index,
method_index,
instruction_pointer: 0,
}