Skip to content

Commit

Permalink
Merge pull request #225 from theseus-rs/rename-arguments-to-parameters
Browse files Browse the repository at this point in the history
refactor: rename Arguments struct to Parameters
  • Loading branch information
brianheineman authored Jan 20, 2025
2 parents 9799c75 + c4845f5 commit 7fccc24
Show file tree
Hide file tree
Showing 439 changed files with 7,055 additions and 6,387 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ getrandom = "0.2.15"
handlebars = "6.2.0"
home = "0.5.11"
indoc = "2.0.5"
indexmap = "2.7.0"
indexmap = "2.7.1"
os_info = "3.9.2"
rand = "0.8.4"
reqwest = { version = "0.12.12", default-features = false }
Expand Down
14 changes: 7 additions & 7 deletions ristretto_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct Cli {
#[arg(short = 'D', help = "Define a system property")]
properties: Option<Vec<String>>,

#[arg(help = "Additional arguments to pass to the main class")]
arguments: Option<Vec<String>>,
#[arg(help = "Additional parameters to pass to the main class")]
parameters: Option<Vec<String>>,

#[arg(
long = "enable-preview",
Expand Down Expand Up @@ -128,9 +128,9 @@ async fn common_main(cli: Cli) -> Result<()> {
return process_error(error);
}
};
let arguments = cli.arguments.unwrap_or_default();
let parameters = cli.parameters.unwrap_or_default();

match vm.invoke_main(arguments).await {
match vm.invoke_main(parameters).await {
Ok(_) => Ok(()),
Err(error) => process_error(error),
}
Expand Down Expand Up @@ -209,9 +209,9 @@ mod tests {
use super::*;

#[tokio::test]
async fn test_common_main_no_arguments_error() -> Result<()> {
let arguments: Vec<String> = Vec::new();
let cli = Cli::parse_from(arguments);
async fn test_common_main_no_parameters_error() -> Result<()> {
let parameters: Vec<String> = Vec::new();
let cli = Cli::parse_from(parameters);
let result = common_main(cli).await;
assert!(result.is_err());
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions ristretto_vm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;
/// Errors that can occur when loading classes
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// The arguments stack underflow
#[error("Arguments stack underflow")]
ArgumentsUnderflow,
/// An error occurred while loading a class file
#[error(transparent)]
ClassFileError(#[from] ristretto_classfile::Error),
Expand Down Expand Up @@ -51,6 +48,9 @@ pub enum Error {
/// The operand stack underflow
#[error("Operand stack underflow")]
OperandStackUnderflow,
/// The parameters stack underflow
#[error("Parameters stack underflow")]
ParametersUnderflow,
/// An error occurred while attempting to parse an integer
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
Expand Down
18 changes: 9 additions & 9 deletions ristretto_vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ pub struct Frame {
thread: Weak<Thread>,
class: Arc<Class>,
method: Arc<Method>,
arguments: Vec<Value>,
parameters: Vec<Value>,
program_counter: AtomicUsize,
}

impl Frame {
/// Create a new frame for the specified class. To invoke a method on an object reference, the
/// object reference must be the first argument in the arguments vector.
/// object reference must be the first parameter in the parameters vector.
pub fn new(
thread: &Weak<Thread>,
class: &Arc<Class>,
method: &Arc<Method>,
arguments: Vec<Value>,
parameters: Vec<Value>,
) -> Self {
Frame {
thread: thread.clone(),
class: class.clone(),
method: method.clone(),
arguments,
parameters,
program_counter: AtomicUsize::new(0),
}
}
Expand Down Expand Up @@ -110,10 +110,10 @@ impl Frame {
#[async_recursion(?Send)]
pub async fn execute(&self) -> Result<Option<Value>> {
let max_locals = self.method.max_locals();
// TODO: Implement the local variable from arguments to avoid cloning?
// TODO: Implement the local variable from parameters to avoid cloning?
let locals = &mut LocalVariables::with_max_size(max_locals);
for (index, argument) in self.arguments.iter().enumerate() {
locals.set(index, argument.clone())?;
for (index, parameter) in self.parameters.iter().enumerate() {
locals.set(index, parameter.clone())?;
}
let max_stack = self.method.max_stack();
let stack = &mut OperandStack::with_max_size(max_stack);
Expand Down Expand Up @@ -451,8 +451,8 @@ mod tests {
async fn test_execute() -> Result<()> {
let (thread, class) = get_class("Expressions").await?;
let method = class.method("add", "(II)I").expect("method not found");
let arguments = vec![Value::Int(1), Value::Int(2)];
let frame = Frame::new(&Arc::downgrade(&thread), &class, &method, arguments);
let parameters = vec![Value::Int(1), Value::Int(2)];
let frame = Frame::new(&Arc::downgrade(&thread), &class, &method, parameters);
let result = frame.execute().await?;
assert!(matches!(result, Some(Value::Int(3))));
Ok(())
Expand Down
20 changes: 10 additions & 10 deletions ristretto_vm/src/instruction/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,26 @@ async fn invoke_method(
mut method: Arc<Method>,
invocation_type: &InvocationType,
) -> Result<ExecutionResult> {
let parameters = method.parameters().len();
let mut arguments = if method.is_static() {
Vec::with_capacity(parameters)
let parameters_length = method.parameters().len();
let mut parameters = if method.is_static() {
Vec::with_capacity(parameters_length)
} else {
// Add one for the object reference
Vec::with_capacity(parameters + 1)
Vec::with_capacity(parameters_length + 1)
};
for _ in 0..parameters {
arguments.push(stack.pop()?);
for _ in 0..parameters_length {
parameters.push(stack.pop()?);
}
if !method.is_static() {
let object = stack.pop_object()?;
arguments.push(Value::Object(object));
parameters.push(Value::Object(object));
}
arguments.reverse();
parameters.reverse();

// TODO: evaluate refactoring this
match invocation_type {
InvocationType::Interface | InvocationType::Virtual => {
let Some(Value::Object(Some(reference))) = arguments.first() else {
let Some(Value::Object(Some(reference))) = parameters.first() else {
return Err(InternalError("No reference found".to_string()));
};
class = match reference {
Expand Down Expand Up @@ -273,7 +273,7 @@ async fn invoke_method(
}

// Execute the method on the current thread
let result = thread.execute(&class, &method, arguments).await?;
let result = thread.execute(&class, &method, parameters).await?;
if let Some(result) = result {
stack.push(result)?;
}
Expand Down
2 changes: 1 addition & 1 deletion ristretto_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
// #![deny(clippy::pedantic)]
#![deny(clippy::unwrap_in_result)]
#![deny(clippy::unwrap_used)]
mod arguments;
mod configuration;
mod error;
mod frame;
Expand All @@ -45,6 +44,7 @@ mod java_object;
mod local_variables;
mod native_methods;
mod operand_stack;
mod parameters;
mod rust_value;
#[cfg(test)]
pub(crate) mod test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::arguments::Arguments;
use crate::native_methods::registry::MethodRegistry;
use crate::parameters::Parameters;
use crate::thread::Thread;
use crate::Result;
use async_recursion::async_recursion;
Expand Down Expand Up @@ -39,35 +39,41 @@ pub(crate) fn register(registry: &mut MethodRegistry) {
}

#[async_recursion(?Send)]
async fn create_context_from(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn create_context_from(
_thread: Arc<Thread>,
_parameters: Parameters,
) -> Result<Option<Value>> {
todo!("apple.applescript.AppleScriptEngine.createContextFrom(Ljava/lang/Object;)J")
}

#[async_recursion(?Send)]
async fn create_object_from(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn create_object_from(
_thread: Arc<Thread>,
_parameters: Parameters,
) -> Result<Option<Value>> {
todo!("apple.applescript.AppleScriptEngine.createObjectFrom(J)Ljava/lang/Object;")
}

#[async_recursion(?Send)]
async fn dispose_context(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn dispose_context(_thread: Arc<Thread>, _parameters: Parameters) -> Result<Option<Value>> {
todo!("apple.applescript.AppleScriptEngine.disposeContext(J)V")
}

#[async_recursion(?Send)]
async fn eval_script(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn eval_script(_thread: Arc<Thread>, _parameters: Parameters) -> Result<Option<Value>> {
todo!("apple.applescript.AppleScriptEngine.evalScript(Ljava/lang/String;J)J")
}

#[async_recursion(?Send)]
async fn eval_script_from_url(
_thread: Arc<Thread>,
_arguments: Arguments,
_parameters: Parameters,
) -> Result<Option<Value>> {
todo!("apple.applescript.AppleScriptEngine.evalScriptFromURL(Ljava/lang/String;J)J")
}

#[async_recursion(?Send)]
async fn init_native(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn init_native(_thread: Arc<Thread>, _parameters: Parameters) -> Result<Option<Value>> {
Ok(None)
}

Expand All @@ -81,7 +87,7 @@ mod tests {
)]
async fn test_create_context_from() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = create_context_from(thread, Arguments::default()).await;
let _ = create_context_from(thread, Parameters::default()).await;
}

#[tokio::test]
Expand All @@ -90,7 +96,7 @@ mod tests {
)]
async fn test_create_object_from() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = create_object_from(thread, Arguments::default()).await;
let _ = create_object_from(thread, Parameters::default()).await;
}

#[tokio::test]
Expand All @@ -99,7 +105,7 @@ mod tests {
)]
async fn test_dispose_context() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = dispose_context(thread, Arguments::default()).await;
let _ = dispose_context(thread, Parameters::default()).await;
}

#[tokio::test]
Expand All @@ -108,7 +114,7 @@ mod tests {
)]
async fn test_eval_script() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = eval_script(thread, Arguments::default()).await;
let _ = eval_script(thread, Parameters::default()).await;
}

#[tokio::test]
Expand All @@ -117,13 +123,13 @@ mod tests {
)]
async fn test_eval_script_from_url() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = eval_script_from_url(thread, Arguments::default()).await;
let _ = eval_script_from_url(thread, Parameters::default()).await;
}

#[tokio::test]
async fn test_init_native() -> Result<()> {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let result = init_native(thread, Arguments::default()).await?;
let result = init_native(thread, Parameters::default()).await?;
assert_eq!(None, result);
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::arguments::Arguments;
use crate::native_methods::registry::MethodRegistry;
use crate::parameters::Parameters;
use crate::thread::Thread;
use crate::Result;
use async_recursion::async_recursion;
Expand All @@ -14,7 +14,7 @@ pub(crate) fn register(registry: &mut MethodRegistry) {
}

#[async_recursion(?Send)]
async fn init_native(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
async fn init_native(_thread: Arc<Thread>, _parameters: Parameters) -> Result<Option<Value>> {
Ok(None)
}

Expand All @@ -25,7 +25,7 @@ mod tests {
#[tokio::test]
async fn test_init_native() -> Result<()> {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let result = init_native(thread, Arguments::default()).await?;
let result = init_native(thread, Parameters::default()).await?;
assert_eq!(None, result);
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions ristretto_vm/src/native_methods/apple/laf/jrsuiconstants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::arguments::Arguments;
use crate::native_methods::registry::MethodRegistry;
use crate::parameters::Parameters;
use crate::thread::Thread;
use crate::Result;
use async_recursion::async_recursion;
Expand All @@ -21,7 +21,7 @@ pub(crate) fn register(registry: &mut MethodRegistry) {
#[async_recursion(?Send)]
async fn get_ptr_for_constant(
_thread: Arc<Thread>,
_arguments: Arguments,
_parameters: Parameters,
) -> Result<Option<Value>> {
todo!("apple.laf.JRSUIConstants.getPtrForConstant(I)J")
}
Expand All @@ -36,6 +36,6 @@ mod tests {
)]
async fn test_get_ptr_for_constant() {
let (_vm, thread) = crate::test::thread().await.expect("thread");
let _ = get_ptr_for_constant(thread, Arguments::default()).await;
let _ = get_ptr_for_constant(thread, Parameters::default()).await;
}
}
Loading

0 comments on commit 7fccc24

Please sign in to comment.