Skip to content
Open
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
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "inst"
version = "0.1.0"
edition = "2024"

[dependencies]
value = { path = "../value", version = "0.1.0" }
thiserror = "2.0.17"
18 changes: 18 additions & 0 deletions bjvm-wasm/crates/inst/src/ctrl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Control {
Continue,
JumpAbsolute(usize),
JumpRelative(isize),
}

#[derive(Debug, Clone, Copy, thiserror::Error)]
pub enum Trap {
#[error("division by zero")]
DivisionByZero,
#[error("invalid operation")]
InvalidOperation,
#[error("stack overflow")]
StackOverflow,
#[error("stack underflow")]
StackUnderflow,
}
21 changes: 21 additions & 0 deletions bjvm-wasm/crates/inst/src/def.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mod nop; pub use nop::*;
mod a_const_null; pub use a_const_null::*;
mod i_const_m1; pub use i_const_m1::*;
mod i_const_0; pub use i_const_0::*;
mod i_const_1; pub use i_const_1::*;
mod i_const_2; pub use i_const_2::*;
mod i_const_3; pub use i_const_3::*;
mod i_const_4; pub use i_const_4::*;
mod i_const_5; pub use i_const_5::*;
mod l_const_0; pub use l_const_0::*;
mod l_const_1; pub use l_const_1::*;
mod f_const_0; pub use f_const_0::*;
mod f_const_1; pub use f_const_1::*;
mod f_const_2; pub use f_const_2::*;
mod d_const_0; pub use d_const_0::*;
mod d_const_1; pub use d_const_1::*;
mod bipush; pub use bipush::*;
mod sipush; pub use sipush::*;
mod ldc; pub use ldc::*;
mod ldc_w; pub use ldc_w::*;
mod ldc_2_w; pub use ldc_2_w::*;
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/a_const_null.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn a_const_null(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Reference(None));
Ok(Control::Continue)
}
9 changes: 9 additions & 0 deletions bjvm-wasm/crates/inst/src/def/bipush.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use value::Value;

use crate::{Control, Trap};

pub fn bipush(stack: &mut Vec<Value>, pc: &mut usize, arg1: u8) -> Result<Control, Trap> {
stack.push(Value::Int(arg1 as i8 as i32));
*pc += 1;
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/d_const_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn d_const_0(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Double(0.0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/d_const_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn d_const_1(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Double(1.0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/f_const_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn f_const_0(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Float(0.0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/f_const_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn f_const_1(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Float(1.0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/f_const_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn f_const_2(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Float(2.0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_0(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_1(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(1));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_2(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(2));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_3(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(3));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_4(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(4));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_5(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(5));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/i_const_m1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn i_const_m1(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Int(-1));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/l_const_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn l_const_0(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Long(0));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/l_const_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn l_const_1(stack: &mut Vec<Value>) -> Result<Control, Trap> {
stack.push(Value::Long(1));
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/ldc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn ldc(stack: &mut Vec<Value>, value: Value) -> Result<Control, Trap> {
stack.push(value);
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/ldc_2_w.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn ldc_2_w(stack: &mut Vec<Value>, value: Value) -> Result<Control, Trap> {
stack.push(value);
Ok(Control::Continue)
}
8 changes: 8 additions & 0 deletions bjvm-wasm/crates/inst/src/def/ldc_w.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use value::Value;

use crate::{Control, Trap};

pub fn ldc_w(stack: &mut Vec<Value>, value: Value) -> Result<Control, Trap> {
stack.push(value);
Ok(Control::Continue)
}
5 changes: 5 additions & 0 deletions bjvm-wasm/crates/inst/src/def/nop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::{Control, Trap};

pub fn nop() -> Result<Control, Trap> {
Ok(Control::Continue)
}
9 changes: 9 additions & 0 deletions bjvm-wasm/crates/inst/src/def/sipush.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use value::Value;

use crate::{Control, Trap};

pub fn sipush(stack: &mut Vec<Value>, pc: &mut usize, arg1: u8, arg2: u8) -> Result<Control, Trap> {
stack.push(Value::Int(((arg1 as i16) << 8 | (arg2 as i16)) as i32));
*pc += 2;
Ok(Control::Continue)
}
Loading