diff --git a/README.md b/README.md index 29ac41c4e..a10316e20 100644 --- a/README.md +++ b/README.md @@ -46,17 +46,28 @@ Traditional Chat OSVM AI Chat (NEW!) ### Installation (5 Minutes) +**Linux:** ```bash -# Clone the repository +# Clone and build git clone https://github.com/opensvm/osvm-cli.git cd osvm-cli - -# Build and install cargo build --release sudo cp target/release/osvm /usr/bin/osvm -# Verify installation -osvm --version # Should show 0.9.3 +# Verify +osvm --version +``` + +**macOS (via Docker):** +```bash +# Clone and run via Docker +git clone https://github.com/opensvm/osvm-cli.git +cd osvm-cli +./scripts/docker-run-macos.sh --version + +# Use any command +./scripts/docker-run-macos.sh snapshot --help +./scripts/docker-run-macos.sh ovsm eval '(+ 1 2 3)' ``` ### ๐Ÿ†• Try the AI-Powered Chat (NEW!) diff --git a/crates/ovsm/src/runtime/lisp_evaluator.rs b/crates/ovsm/src/runtime/lisp_evaluator.rs index 46d1aa56b..e6e18ff3c 100644 --- a/crates/ovsm/src/runtime/lisp_evaluator.rs +++ b/crates/ovsm/src/runtime/lisp_evaluator.rs @@ -3165,8 +3165,8 @@ impl LispEvaluator { }; // Parse JSON string into serde_json::Value - let json_value: serde_json::Value = serde_json::from_str(&json_str) - .map_err(|e| Error::ToolExecutionError { + let json_value: serde_json::Value = + serde_json::from_str(&json_str).map_err(|e| Error::ToolExecutionError { tool: "json-parse".to_string(), reason: format!("Failed to parse JSON: {}", e), })?; @@ -3240,9 +3240,9 @@ impl LispEvaluator { } } JV::String(s) => Value::String(s), - JV::Array(arr) => { - Value::Array(Arc::new(arr.into_iter().map(|v| self.json_to_value(v)).collect())) - } + JV::Array(arr) => Value::Array(Arc::new( + arr.into_iter().map(|v| self.json_to_value(v)).collect(), + )), JV::Object(map) => { let mut obj = HashMap::new(); for (k, v) in map { @@ -3260,11 +3260,9 @@ impl LispEvaluator { Value::Null => JV::Null, Value::Bool(b) => JV::Bool(b), Value::Int(i) => JV::Number(serde_json::Number::from(i)), - Value::Float(f) => { - serde_json::Number::from_f64(f) - .map(JV::Number) - .unwrap_or(JV::Null) - } + Value::Float(f) => serde_json::Number::from_f64(f) + .map(JV::Number) + .unwrap_or(JV::Null), Value::String(s) => JV::String(s.to_string()), Value::Array(arr) => { let mut json_arr = Vec::new(); @@ -3896,7 +3894,8 @@ impl LispEvaluator { for (key, values) in groups_obj.iter() { // Create scope for aggregation function self.env.enter_scope(); - self.env.define(params[0].clone(), Value::String(key.clone())); + self.env + .define(params[0].clone(), Value::String(key.clone())); self.env.define(params[1].clone(), values.clone()); // Evaluate aggregation function @@ -3921,7 +3920,8 @@ impl LispEvaluator { if args.len() < 2 || args.len() > 3 { return Err(Error::InvalidArguments { tool: "sort-by".to_string(), - reason: "Expected 2-3 arguments: collection, key-fn, and optional :desc flag".to_string(), + reason: "Expected 2-3 arguments: collection, key-fn, and optional :desc flag" + .to_string(), }); } @@ -3949,7 +3949,10 @@ impl LispEvaluator { if params.len() != 1 { return Err(Error::InvalidArguments { tool: "sort-by".to_string(), - reason: format!("Key function must take exactly 1 parameter, got {}", params.len()), + reason: format!( + "Key function must take exactly 1 parameter, got {}", + params.len() + ), }); } diff --git a/crates/ovsm/src/tools/stdlib/advanced_math.rs b/crates/ovsm/src/tools/stdlib/advanced_math.rs index f4371b5b1..ce2f0b1a5 100644 --- a/crates/ovsm/src/tools/stdlib/advanced_math.rs +++ b/crates/ovsm/src/tools/stdlib/advanced_math.rs @@ -993,11 +993,7 @@ impl Tool for AshTool { let n = args[0].as_int()?; let count = args[1].as_int()?; - let result = if count >= 0 { - n << count - } else { - n >> -count - }; + let result = if count >= 0 { n << count } else { n >> -count }; Ok(Value::Int(result)) } @@ -1062,11 +1058,23 @@ impl Tool for SignumTool { match &args[0] { Value::Int(n) => { - let sign = if *n < 0 { -1 } else if *n > 0 { 1 } else { 0 }; + let sign = if *n < 0 { + -1 + } else if *n > 0 { + 1 + } else { + 0 + }; Ok(Value::Int(sign)) } Value::Float(f) => { - let sign = if *f < 0.0 { -1.0 } else if *f > 0.0 { 1.0 } else { 0.0 }; + let sign = if *f < 0.0 { + -1.0 + } else if *f > 0.0 { + 1.0 + } else { + 0.0 + }; Ok(Value::Float(sign)) } _ => Err(Error::TypeError { diff --git a/crates/ovsm/src/tools/stdlib/arrays.rs b/crates/ovsm/src/tools/stdlib/arrays.rs index 2886da9a1..60e8ba714 100644 --- a/crates/ovsm/src/tools/stdlib/arrays.rs +++ b/crates/ovsm/src/tools/stdlib/arrays.rs @@ -155,10 +155,13 @@ impl Tool for ArefTool { let array = args[0].as_array()?; let index = args[1].as_int()? as usize; - array.get(index).cloned().ok_or_else(|| Error::IndexOutOfBounds { - index, - length: array.len(), - }) + array + .get(index) + .cloned() + .ok_or_else(|| Error::IndexOutOfBounds { + index, + length: array.len(), + }) } } @@ -545,9 +548,12 @@ impl Tool for CaadrTool { } let second = list[1].as_array()?; - second.first().cloned().ok_or_else(|| Error::EmptyCollection { - operation: "CAADR".to_string(), - }) + second + .first() + .cloned() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAADR".to_string(), + }) } } @@ -670,18 +676,30 @@ impl Tool for CaaaarTool { }); } - let l1 = args[0].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAAAAR".to_string(), - })?; - let l2 = l1.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAAAAR".to_string(), - })?; - let l3 = l2.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAAAAR".to_string(), - })?; - let l4 = l3.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAAAAR".to_string(), - })?; + let l1 = args[0] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAAAAR".to_string(), + })?; + let l2 = l1 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAAAAR".to_string(), + })?; + let l3 = l2 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAAAAR".to_string(), + })?; + let l4 = l3 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAAAAR".to_string(), + })?; Ok(l4.clone()) } @@ -707,15 +725,24 @@ impl Tool for CdaaarTool { }); } - let l1 = args[0].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CDAAAR".to_string(), - })?; - let l2 = l1.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CDAAAR".to_string(), - })?; - let l3 = l2.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CDAAAR".to_string(), - })?; + let l1 = args[0] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CDAAAR".to_string(), + })?; + let l2 = l1 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CDAAAR".to_string(), + })?; + let l3 = l2 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CDAAAR".to_string(), + })?; let l4 = l3.as_array()?; if l4.is_empty() { @@ -746,12 +773,18 @@ impl Tool for CadaarTool { }); } - let l1 = args[0].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CADAAR".to_string(), - })?; - let l2 = l1.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CADAAR".to_string(), - })?; + let l1 = args[0] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CADAAR".to_string(), + })?; + let l2 = l1 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CADAAR".to_string(), + })?; let l3 = l2.as_array()?; if l3.len() < 2 { @@ -785,12 +818,18 @@ impl Tool for CddaarTool { }); } - let l1 = args[0].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CDDAAR".to_string(), - })?; - let l2 = l1.as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CDDAAR".to_string(), - })?; + let l1 = args[0] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CDDAAR".to_string(), + })?; + let l2 = l1 + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CDDAAR".to_string(), + })?; let l3 = l2.as_array()?; if l3.len() < 2 { @@ -821,9 +860,12 @@ impl Tool for CaadarTool { }); } - let l1 = args[0].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAADAR".to_string(), - })?; + let l1 = args[0] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAADAR".to_string(), + })?; let l2 = l1.as_array()?; if l2.len() < 2 { @@ -833,9 +875,12 @@ impl Tool for CaadarTool { }); } - let l3 = l2[1].as_array()?.first().ok_or_else(|| Error::EmptyCollection { - operation: "CAADAR".to_string(), - })?; + let l3 = l2[1] + .as_array()? + .first() + .ok_or_else(|| Error::EmptyCollection { + operation: "CAADAR".to_string(), + })?; Ok(l3.clone()) } diff --git a/crates/ovsm/src/tools/stdlib/bit_operations.rs b/crates/ovsm/src/tools/stdlib/bit_operations.rs index b88ea6d59..7bc96fcfc 100644 --- a/crates/ovsm/src/tools/stdlib/bit_operations.rs +++ b/crates/ovsm/src/tools/stdlib/bit_operations.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// MAKE-BIT-ARRAY - Create bit array pub struct MakeBitArrayTool; impl Tool for MakeBitArrayTool { - fn name(&self) -> &str { "MAKE-BIT-ARRAY" } - fn description(&self) -> &str { "Create bit array of specified size" } + fn name(&self) -> &str { + "MAKE-BIT-ARRAY" + } + fn description(&self) -> &str { + "Create bit array of specified size" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -51,8 +55,12 @@ impl Tool for MakeBitArrayTool { /// BIT - Access bit in bit array pub struct BitTool; impl Tool for BitTool { - fn name(&self) -> &str { "BIT" } - fn description(&self) -> &str { "Access bit at index in bit array" } + fn name(&self) -> &str { + "BIT" + } + fn description(&self) -> &str { + "Access bit at index in bit array" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Int(0)); @@ -73,8 +81,12 @@ impl Tool for BitTool { /// SBIT - Access simple bit in simple bit array pub struct SbitTool; impl Tool for SbitTool { - fn name(&self) -> &str { "SBIT" } - fn description(&self) -> &str { "Access bit in simple bit array" } + fn name(&self) -> &str { + "SBIT" + } + fn description(&self) -> &str { + "Access bit in simple bit array" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Int(0)); @@ -95,8 +107,12 @@ impl Tool for SbitTool { /// BIT-AND - Bitwise AND on bit arrays pub struct BitAndTool; impl Tool for BitAndTool { - fn name(&self) -> &str { "BIT-AND" } - fn description(&self) -> &str { "Bitwise AND on bit arrays" } + fn name(&self) -> &str { + "BIT-AND" + } + fn description(&self) -> &str { + "Bitwise AND on bit arrays" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Array(Arc::new(vec![]))); @@ -104,12 +120,14 @@ impl Tool for BitAndTool { match (&args[0], &args[1]) { (Value::Array(arr1), Value::Array(arr2)) => { - let result: Vec = arr1.iter().zip(arr2.iter()).map(|(a, b)| { - match (a, b) { + let result: Vec = arr1 + .iter() + .zip(arr2.iter()) + .map(|(a, b)| match (a, b) { (Value::Int(x), Value::Int(y)) => Value::Int(x & y), _ => Value::Int(0), - } - }).collect(); + }) + .collect(); Ok(Value::Array(Arc::new(result))) } _ => Ok(Value::Array(Arc::new(vec![]))), @@ -120,8 +138,12 @@ impl Tool for BitAndTool { /// BIT-IOR - Bitwise OR on bit arrays pub struct BitIorTool; impl Tool for BitIorTool { - fn name(&self) -> &str { "BIT-IOR" } - fn description(&self) -> &str { "Bitwise inclusive OR on bit arrays" } + fn name(&self) -> &str { + "BIT-IOR" + } + fn description(&self) -> &str { + "Bitwise inclusive OR on bit arrays" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Array(Arc::new(vec![]))); @@ -129,12 +151,14 @@ impl Tool for BitIorTool { match (&args[0], &args[1]) { (Value::Array(arr1), Value::Array(arr2)) => { - let result: Vec = arr1.iter().zip(arr2.iter()).map(|(a, b)| { - match (a, b) { + let result: Vec = arr1 + .iter() + .zip(arr2.iter()) + .map(|(a, b)| match (a, b) { (Value::Int(x), Value::Int(y)) => Value::Int(x | y), _ => Value::Int(0), - } - }).collect(); + }) + .collect(); Ok(Value::Array(Arc::new(result))) } _ => Ok(Value::Array(Arc::new(vec![]))), @@ -145,8 +169,12 @@ impl Tool for BitIorTool { /// BIT-XOR - Bitwise XOR on bit arrays pub struct BitXorTool; impl Tool for BitXorTool { - fn name(&self) -> &str { "BIT-XOR" } - fn description(&self) -> &str { "Bitwise exclusive OR on bit arrays" } + fn name(&self) -> &str { + "BIT-XOR" + } + fn description(&self) -> &str { + "Bitwise exclusive OR on bit arrays" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Array(Arc::new(vec![]))); @@ -154,12 +182,14 @@ impl Tool for BitXorTool { match (&args[0], &args[1]) { (Value::Array(arr1), Value::Array(arr2)) => { - let result: Vec = arr1.iter().zip(arr2.iter()).map(|(a, b)| { - match (a, b) { + let result: Vec = arr1 + .iter() + .zip(arr2.iter()) + .map(|(a, b)| match (a, b) { (Value::Int(x), Value::Int(y)) => Value::Int(x ^ y), _ => Value::Int(0), - } - }).collect(); + }) + .collect(); Ok(Value::Array(Arc::new(result))) } _ => Ok(Value::Array(Arc::new(vec![]))), @@ -170,8 +200,12 @@ impl Tool for BitXorTool { /// BIT-NOT - Bitwise NOT on bit array pub struct BitNotTool; impl Tool for BitNotTool { - fn name(&self) -> &str { "BIT-NOT" } - fn description(&self) -> &str { "Bitwise NOT on bit array" } + fn name(&self) -> &str { + "BIT-NOT" + } + fn description(&self) -> &str { + "Bitwise NOT on bit array" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -179,14 +213,15 @@ impl Tool for BitNotTool { match &args[0] { Value::Array(arr) => { - let result: Vec = arr.iter().map(|v| { - match v { + let result: Vec = arr + .iter() + .map(|v| match v { Value::Int(0) => Value::Int(1), Value::Int(1) => Value::Int(0), Value::Int(n) => Value::Int(!n), _ => Value::Int(0), - } - }).collect(); + }) + .collect(); Ok(Value::Array(Arc::new(result))) } _ => Ok(Value::Array(Arc::new(vec![]))), @@ -197,14 +232,18 @@ impl Tool for BitNotTool { /// BIT-VECTOR-P - Check if bit vector pub struct BitVectorPTool; impl Tool for BitVectorPTool { - fn name(&self) -> &str { "BIT-VECTOR-P" } - fn description(&self) -> &str { "Check if object is bit vector" } + fn name(&self) -> &str { + "BIT-VECTOR-P" + } + fn description(&self) -> &str { + "Check if object is bit vector" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::Array(arr)) => { - let is_bit_vector = arr.iter().all(|v| { - matches!(v, Value::Int(0) | Value::Int(1)) - }); + let is_bit_vector = arr + .iter() + .all(|v| matches!(v, Value::Int(0) | Value::Int(1))); Ok(Value::Bool(is_bit_vector)) } _ => Ok(Value::Bool(false)), diff --git a/crates/ovsm/src/tools/stdlib/clos_advanced.rs b/crates/ovsm/src/tools/stdlib/clos_advanced.rs index 947772256..ea4d69362 100644 --- a/crates/ovsm/src/tools/stdlib/clos_advanced.rs +++ b/crates/ovsm/src/tools/stdlib/clos_advanced.rs @@ -18,8 +18,12 @@ use std::sync::Arc; /// GENERIC-FUNCTION-METHODS - Get all methods for generic function pub struct GenericFunctionMethodsTool; impl Tool for GenericFunctionMethodsTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-METHODS" } - fn description(&self) -> &str { "Get all methods of a generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-METHODS" + } + fn description(&self) -> &str { + "Get all methods of a generic function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -28,8 +32,12 @@ impl Tool for GenericFunctionMethodsTool { /// GENERIC-FUNCTION-NAME - Get name of generic function pub struct GenericFunctionNameTool; impl Tool for GenericFunctionNameTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-NAME" } - fn description(&self) -> &str { "Get name of generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-NAME" + } + fn description(&self) -> &str { + "Get name of generic function" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -44,8 +52,12 @@ impl Tool for GenericFunctionNameTool { /// GENERIC-FUNCTION-LAMBDA-LIST - Get lambda list of generic function pub struct GenericFunctionLambdaListTool; impl Tool for GenericFunctionLambdaListTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-LAMBDA-LIST" } - fn description(&self) -> &str { "Get lambda list of generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-LAMBDA-LIST" + } + fn description(&self) -> &str { + "Get lambda list of generic function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -54,8 +66,12 @@ impl Tool for GenericFunctionLambdaListTool { /// GENERIC-FUNCTION-ARGUMENT-PRECEDENCE-ORDER - Get argument precedence pub struct GenericFunctionArgumentPrecedenceOrderTool; impl Tool for GenericFunctionArgumentPrecedenceOrderTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-ARGUMENT-PRECEDENCE-ORDER" } - fn description(&self) -> &str { "Get argument precedence order" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-ARGUMENT-PRECEDENCE-ORDER" + } + fn description(&self) -> &str { + "Get argument precedence order" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -64,8 +80,12 @@ impl Tool for GenericFunctionArgumentPrecedenceOrderTool { /// GENERIC-FUNCTION-DECLARATIONS - Get declarations pub struct GenericFunctionDeclarationsTool; impl Tool for GenericFunctionDeclarationsTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-DECLARATIONS" } - fn description(&self) -> &str { "Get declarations of generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-DECLARATIONS" + } + fn description(&self) -> &str { + "Get declarations of generic function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -74,8 +94,12 @@ impl Tool for GenericFunctionDeclarationsTool { /// GENERIC-FUNCTION-METHOD-CLASS - Get method class pub struct GenericFunctionMethodClassTool; impl Tool for GenericFunctionMethodClassTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-METHOD-CLASS" } - fn description(&self) -> &str { "Get method class of generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-METHOD-CLASS" + } + fn description(&self) -> &str { + "Get method class of generic function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("STANDARD-METHOD".to_string())) } @@ -84,8 +108,12 @@ impl Tool for GenericFunctionMethodClassTool { /// GENERIC-FUNCTION-METHOD-COMBINATION - Get method combination pub struct GenericFunctionMethodCombinationTool; impl Tool for GenericFunctionMethodCombinationTool { - fn name(&self) -> &str { "GENERIC-FUNCTION-METHOD-COMBINATION" } - fn description(&self) -> &str { "Get method combination of generic function" } + fn name(&self) -> &str { + "GENERIC-FUNCTION-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "Get method combination of generic function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("STANDARD".to_string())) } @@ -98,8 +126,12 @@ impl Tool for GenericFunctionMethodCombinationTool { /// METHOD-QUALIFIERS - Get method qualifiers pub struct MethodQualifiersTool; impl Tool for MethodQualifiersTool { - fn name(&self) -> &str { "METHOD-QUALIFIERS" } - fn description(&self) -> &str { "Get qualifiers of a method" } + fn name(&self) -> &str { + "METHOD-QUALIFIERS" + } + fn description(&self) -> &str { + "Get qualifiers of a method" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -108,8 +140,12 @@ impl Tool for MethodQualifiersTool { /// METHOD-SPECIALIZERS - Get method specializers pub struct MethodSpecializersTool; impl Tool for MethodSpecializersTool { - fn name(&self) -> &str { "METHOD-SPECIALIZERS" } - fn description(&self) -> &str { "Get specializers of a method" } + fn name(&self) -> &str { + "METHOD-SPECIALIZERS" + } + fn description(&self) -> &str { + "Get specializers of a method" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -118,8 +154,12 @@ impl Tool for MethodSpecializersTool { /// METHOD-LAMBDA-LIST - Get method lambda list pub struct MethodLambdaListTool; impl Tool for MethodLambdaListTool { - fn name(&self) -> &str { "METHOD-LAMBDA-LIST" } - fn description(&self) -> &str { "Get lambda list of a method" } + fn name(&self) -> &str { + "METHOD-LAMBDA-LIST" + } + fn description(&self) -> &str { + "Get lambda list of a method" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -128,8 +168,12 @@ impl Tool for MethodLambdaListTool { /// METHOD-GENERIC-FUNCTION - Get generic function of method pub struct MethodGenericFunctionTool; impl Tool for MethodGenericFunctionTool { - fn name(&self) -> &str { "METHOD-GENERIC-FUNCTION" } - fn description(&self) -> &str { "Get generic function of a method" } + fn name(&self) -> &str { + "METHOD-GENERIC-FUNCTION" + } + fn description(&self) -> &str { + "Get generic function of a method" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -144,8 +188,12 @@ impl Tool for MethodGenericFunctionTool { /// METHOD-FUNCTION - Get function of method pub struct MethodFunctionTool; impl Tool for MethodFunctionTool { - fn name(&self) -> &str { "METHOD-FUNCTION" } - fn description(&self) -> &str { "Get function implementation of a method" } + fn name(&self) -> &str { + "METHOD-FUNCTION" + } + fn description(&self) -> &str { + "Get function implementation of a method" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -164,8 +212,12 @@ impl Tool for MethodFunctionTool { /// ADD-METHOD - Add method to generic function pub struct AddMethodTool; impl Tool for AddMethodTool { - fn name(&self) -> &str { "ADD-METHOD" } - fn description(&self) -> &str { "Add method to generic function" } + fn name(&self) -> &str { + "ADD-METHOD" + } + fn description(&self) -> &str { + "Add method to generic function" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -180,8 +232,12 @@ impl Tool for AddMethodTool { /// REMOVE-METHOD - Remove method from generic function pub struct RemoveMethodTool; impl Tool for RemoveMethodTool { - fn name(&self) -> &str { "REMOVE-METHOD" } - fn description(&self) -> &str { "Remove method from generic function" } + fn name(&self) -> &str { + "REMOVE-METHOD" + } + fn description(&self) -> &str { + "Remove method from generic function" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -196,8 +252,12 @@ impl Tool for RemoveMethodTool { /// FIND-METHOD - Find method by specializers pub struct FindMethodTool; impl Tool for FindMethodTool { - fn name(&self) -> &str { "FIND-METHOD" } - fn description(&self) -> &str { "Find method by specializers" } + fn name(&self) -> &str { + "FIND-METHOD" + } + fn description(&self) -> &str { + "Find method by specializers" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -206,8 +266,12 @@ impl Tool for FindMethodTool { /// COMPUTE-APPLICABLE-METHODS - Compute applicable methods pub struct ComputeApplicableMethodsTool; impl Tool for ComputeApplicableMethodsTool { - fn name(&self) -> &str { "COMPUTE-APPLICABLE-METHODS" } - fn description(&self) -> &str { "Compute applicable methods for arguments" } + fn name(&self) -> &str { + "COMPUTE-APPLICABLE-METHODS" + } + fn description(&self) -> &str { + "Compute applicable methods for arguments" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -216,8 +280,12 @@ impl Tool for ComputeApplicableMethodsTool { /// COMPUTE-APPLICABLE-METHODS-USING-CLASSES - Compute by classes pub struct ComputeApplicableMethodsUsingClassesTool; impl Tool for ComputeApplicableMethodsUsingClassesTool { - fn name(&self) -> &str { "COMPUTE-APPLICABLE-METHODS-USING-CLASSES" } - fn description(&self) -> &str { "Compute applicable methods using classes" } + fn name(&self) -> &str { + "COMPUTE-APPLICABLE-METHODS-USING-CLASSES" + } + fn description(&self) -> &str { + "Compute applicable methods using classes" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -230,8 +298,12 @@ impl Tool for ComputeApplicableMethodsUsingClassesTool { /// CLASS-DIRECT-SUPERCLASSES - Get direct superclasses pub struct ClassDirectSuperclassesTool; impl Tool for ClassDirectSuperclassesTool { - fn name(&self) -> &str { "CLASS-DIRECT-SUPERCLASSES" } - fn description(&self) -> &str { "Get direct superclasses of a class" } + fn name(&self) -> &str { + "CLASS-DIRECT-SUPERCLASSES" + } + fn description(&self) -> &str { + "Get direct superclasses of a class" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -240,8 +312,12 @@ impl Tool for ClassDirectSuperclassesTool { /// CLASS-DIRECT-SUBCLASSES - Get direct subclasses pub struct ClassDirectSubclassesTool; impl Tool for ClassDirectSubclassesTool { - fn name(&self) -> &str { "CLASS-DIRECT-SUBCLASSES" } - fn description(&self) -> &str { "Get direct subclasses of a class" } + fn name(&self) -> &str { + "CLASS-DIRECT-SUBCLASSES" + } + fn description(&self) -> &str { + "Get direct subclasses of a class" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -250,8 +326,12 @@ impl Tool for ClassDirectSubclassesTool { /// CLASS-DIRECT-SLOTS - Get direct slots pub struct ClassDirectSlotsTool; impl Tool for ClassDirectSlotsTool { - fn name(&self) -> &str { "CLASS-DIRECT-SLOTS" } - fn description(&self) -> &str { "Get direct slots of a class" } + fn name(&self) -> &str { + "CLASS-DIRECT-SLOTS" + } + fn description(&self) -> &str { + "Get direct slots of a class" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -260,8 +340,12 @@ impl Tool for ClassDirectSlotsTool { /// CLASS-DEFAULT-INITARGS - Get default initargs pub struct ClassDefaultInitargsTool; impl Tool for ClassDefaultInitargsTool { - fn name(&self) -> &str { "CLASS-DEFAULT-INITARGS" } - fn description(&self) -> &str { "Get default initialization arguments" } + fn name(&self) -> &str { + "CLASS-DEFAULT-INITARGS" + } + fn description(&self) -> &str { + "Get default initialization arguments" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -270,8 +354,12 @@ impl Tool for ClassDefaultInitargsTool { /// CLASS-DIRECT-DEFAULT-INITARGS - Get direct default initargs pub struct ClassDirectDefaultInitargsTool; impl Tool for ClassDirectDefaultInitargsTool { - fn name(&self) -> &str { "CLASS-DIRECT-DEFAULT-INITARGS" } - fn description(&self) -> &str { "Get direct default initargs" } + fn name(&self) -> &str { + "CLASS-DIRECT-DEFAULT-INITARGS" + } + fn description(&self) -> &str { + "Get direct default initargs" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -280,8 +368,12 @@ impl Tool for ClassDirectDefaultInitargsTool { /// CLASS-PROTOTYPE - Get class prototype pub struct ClassPrototypeTool; impl Tool for ClassPrototypeTool { - fn name(&self) -> &str { "CLASS-PROTOTYPE" } - fn description(&self) -> &str { "Get prototype instance of a class" } + fn name(&self) -> &str { + "CLASS-PROTOTYPE" + } + fn description(&self) -> &str { + "Get prototype instance of a class" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Object(Arc::new(HashMap::new()))) } @@ -290,8 +382,12 @@ impl Tool for ClassPrototypeTool { /// CLASS-FINALIZED-P - Check if class is finalized pub struct ClassFinalizedPTool; impl Tool for ClassFinalizedPTool { - fn name(&self) -> &str { "CLASS-FINALIZED-P" } - fn description(&self) -> &str { "Check if class is finalized" } + fn name(&self) -> &str { + "CLASS-FINALIZED-P" + } + fn description(&self) -> &str { + "Check if class is finalized" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Bool(true)) } @@ -300,10 +396,18 @@ impl Tool for ClassFinalizedPTool { /// FINALIZE-INHERITANCE - Finalize class inheritance pub struct FinalizeInheritanceTool; impl Tool for FinalizeInheritanceTool { - fn name(&self) -> &str { "FINALIZE-INHERITANCE" } - fn description(&self) -> &str { "Finalize class inheritance" } + fn name(&self) -> &str { + "FINALIZE-INHERITANCE" + } + fn description(&self) -> &str { + "Finalize class inheritance" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -314,8 +418,12 @@ impl Tool for FinalizeInheritanceTool { /// SLOT-DEFINITION-NAME - Get slot name pub struct SlotDefinitionNameTool; impl Tool for SlotDefinitionNameTool { - fn name(&self) -> &str { "SLOT-DEFINITION-NAME" } - fn description(&self) -> &str { "Get name of slot definition" } + fn name(&self) -> &str { + "SLOT-DEFINITION-NAME" + } + fn description(&self) -> &str { + "Get name of slot definition" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -330,8 +438,12 @@ impl Tool for SlotDefinitionNameTool { /// SLOT-DEFINITION-INITARGS - Get slot initargs pub struct SlotDefinitionInitargsTool; impl Tool for SlotDefinitionInitargsTool { - fn name(&self) -> &str { "SLOT-DEFINITION-INITARGS" } - fn description(&self) -> &str { "Get initialization arguments of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-INITARGS" + } + fn description(&self) -> &str { + "Get initialization arguments of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -340,8 +452,12 @@ impl Tool for SlotDefinitionInitargsTool { /// SLOT-DEFINITION-INITFORM - Get slot initform pub struct SlotDefinitionInitformTool; impl Tool for SlotDefinitionInitformTool { - fn name(&self) -> &str { "SLOT-DEFINITION-INITFORM" } - fn description(&self) -> &str { "Get initialization form of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-INITFORM" + } + fn description(&self) -> &str { + "Get initialization form of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -350,8 +466,12 @@ impl Tool for SlotDefinitionInitformTool { /// SLOT-DEFINITION-INITFUNCTION - Get slot init function pub struct SlotDefinitionInitfunctionTool; impl Tool for SlotDefinitionInitfunctionTool { - fn name(&self) -> &str { "SLOT-DEFINITION-INITFUNCTION" } - fn description(&self) -> &str { "Get initialization function of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-INITFUNCTION" + } + fn description(&self) -> &str { + "Get initialization function of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -360,8 +480,12 @@ impl Tool for SlotDefinitionInitfunctionTool { /// SLOT-DEFINITION-TYPE - Get slot type pub struct SlotDefinitionTypeTool; impl Tool for SlotDefinitionTypeTool { - fn name(&self) -> &str { "SLOT-DEFINITION-TYPE" } - fn description(&self) -> &str { "Get type of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-TYPE" + } + fn description(&self) -> &str { + "Get type of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("T".to_string())) } @@ -370,8 +494,12 @@ impl Tool for SlotDefinitionTypeTool { /// SLOT-DEFINITION-ALLOCATION - Get slot allocation pub struct SlotDefinitionAllocationTool; impl Tool for SlotDefinitionAllocationTool { - fn name(&self) -> &str { "SLOT-DEFINITION-ALLOCATION" } - fn description(&self) -> &str { "Get allocation type of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-ALLOCATION" + } + fn description(&self) -> &str { + "Get allocation type of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("INSTANCE".to_string())) } @@ -380,8 +508,12 @@ impl Tool for SlotDefinitionAllocationTool { /// SLOT-DEFINITION-READERS - Get slot readers pub struct SlotDefinitionReadersTool; impl Tool for SlotDefinitionReadersTool { - fn name(&self) -> &str { "SLOT-DEFINITION-READERS" } - fn description(&self) -> &str { "Get reader methods of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-READERS" + } + fn description(&self) -> &str { + "Get reader methods of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -390,8 +522,12 @@ impl Tool for SlotDefinitionReadersTool { /// SLOT-DEFINITION-WRITERS - Get slot writers pub struct SlotDefinitionWritersTool; impl Tool for SlotDefinitionWritersTool { - fn name(&self) -> &str { "SLOT-DEFINITION-WRITERS" } - fn description(&self) -> &str { "Get writer methods of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-WRITERS" + } + fn description(&self) -> &str { + "Get writer methods of slot" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -400,8 +536,12 @@ impl Tool for SlotDefinitionWritersTool { /// SLOT-DEFINITION-LOCATION - Get slot storage location pub struct SlotDefinitionLocationTool; impl Tool for SlotDefinitionLocationTool { - fn name(&self) -> &str { "SLOT-DEFINITION-LOCATION" } - fn description(&self) -> &str { "Get storage location of slot" } + fn name(&self) -> &str { + "SLOT-DEFINITION-LOCATION" + } + fn description(&self) -> &str { + "Get storage location of slot" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::Int(0)) @@ -415,28 +555,48 @@ impl Tool for SlotDefinitionLocationTool { /// EQL-SPECIALIZER - Create EQL specializer pub struct EqlSpecializerTool; impl Tool for EqlSpecializerTool { - fn name(&self) -> &str { "EQL-SPECIALIZER" } - fn description(&self) -> &str { "Create EQL specializer" } + fn name(&self) -> &str { + "EQL-SPECIALIZER" + } + fn description(&self) -> &str { + "Create EQL specializer" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// EQL-SPECIALIZER-OBJECT - Get object from EQL specializer pub struct EqlSpecializerObjectTool; impl Tool for EqlSpecializerObjectTool { - fn name(&self) -> &str { "EQL-SPECIALIZER-OBJECT" } - fn description(&self) -> &str { "Get object from EQL specializer" } + fn name(&self) -> &str { + "EQL-SPECIALIZER-OBJECT" + } + fn description(&self) -> &str { + "Get object from EQL specializer" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// SPECIALIZER-DIRECT-GENERIC-FUNCTIONS - Get generic functions pub struct SpecializerDirectGenericFunctionsTool; impl Tool for SpecializerDirectGenericFunctionsTool { - fn name(&self) -> &str { "SPECIALIZER-DIRECT-GENERIC-FUNCTIONS" } - fn description(&self) -> &str { "Get generic functions using specializer" } + fn name(&self) -> &str { + "SPECIALIZER-DIRECT-GENERIC-FUNCTIONS" + } + fn description(&self) -> &str { + "Get generic functions using specializer" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -445,8 +605,12 @@ impl Tool for SpecializerDirectGenericFunctionsTool { /// SPECIALIZER-DIRECT-METHODS - Get methods using specializer pub struct SpecializerDirectMethodsTool; impl Tool for SpecializerDirectMethodsTool { - fn name(&self) -> &str { "SPECIALIZER-DIRECT-METHODS" } - fn description(&self) -> &str { "Get methods using specializer" } + fn name(&self) -> &str { + "SPECIALIZER-DIRECT-METHODS" + } + fn description(&self) -> &str { + "Get methods using specializer" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -459,28 +623,48 @@ impl Tool for SpecializerDirectMethodsTool { /// ENSURE-GENERIC-FUNCTION - Ensure generic function exists pub struct EnsureGenericFunctionTool; impl Tool for EnsureGenericFunctionTool { - fn name(&self) -> &str { "ENSURE-GENERIC-FUNCTION" } - fn description(&self) -> &str { "Ensure generic function exists" } + fn name(&self) -> &str { + "ENSURE-GENERIC-FUNCTION" + } + fn description(&self) -> &str { + "Ensure generic function exists" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// ENSURE-CLASS - Ensure class exists pub struct EnsureClassTool; impl Tool for EnsureClassTool { - fn name(&self) -> &str { "ENSURE-CLASS" } - fn description(&self) -> &str { "Ensure class exists" } + fn name(&self) -> &str { + "ENSURE-CLASS" + } + fn description(&self) -> &str { + "Ensure class exists" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// ALLOCATE-INSTANCE - Allocate instance without initialization pub struct AllocateInstanceTool; impl Tool for AllocateInstanceTool { - fn name(&self) -> &str { "ALLOCATE-INSTANCE" } - fn description(&self) -> &str { "Allocate instance without initialization" } + fn name(&self) -> &str { + "ALLOCATE-INSTANCE" + } + fn description(&self) -> &str { + "Allocate instance without initialization" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Object(Arc::new(HashMap::new()))) } @@ -489,8 +673,12 @@ impl Tool for AllocateInstanceTool { /// MAKE-INSTANCE-STANDARD - Standard instance creation pub struct MakeInstanceStandardTool; impl Tool for MakeInstanceStandardTool { - fn name(&self) -> &str { "MAKE-INSTANCE-STANDARD" } - fn description(&self) -> &str { "Create standard instance" } + fn name(&self) -> &str { + "MAKE-INSTANCE-STANDARD" + } + fn description(&self) -> &str { + "Create standard instance" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Object(Arc::new(HashMap::new()))) } @@ -499,28 +687,48 @@ impl Tool for MakeInstanceStandardTool { /// MAKE-INSTANCES-OBSOLETE - Mark instances obsolete pub struct MakeInstancesObsoleteTool; impl Tool for MakeInstancesObsoleteTool { - fn name(&self) -> &str { "MAKE-INSTANCES-OBSOLETE" } - fn description(&self) -> &str { "Mark class instances obsolete" } + fn name(&self) -> &str { + "MAKE-INSTANCES-OBSOLETE" + } + fn description(&self) -> &str { + "Mark class instances obsolete" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// UPDATE-INSTANCE-FOR-REDEFINED-CLASS - Update after redefine pub struct UpdateInstanceForRedefinedClassTool; impl Tool for UpdateInstanceForRedefinedClassTool { - fn name(&self) -> &str { "UPDATE-INSTANCE-FOR-REDEFINED-CLASS" } - fn description(&self) -> &str { "Update instance after class redefinition" } + fn name(&self) -> &str { + "UPDATE-INSTANCE-FOR-REDEFINED-CLASS" + } + fn description(&self) -> &str { + "Update instance after class redefinition" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// SET-FUNCALLABLE-INSTANCE-FUNCTION - Set funcallable function pub struct SetFuncallableInstanceFunctionTool; impl Tool for SetFuncallableInstanceFunctionTool { - fn name(&self) -> &str { "SET-FUNCALLABLE-INSTANCE-FUNCTION" } - fn description(&self) -> &str { "Set function of funcallable instance" } + fn name(&self) -> &str { + "SET-FUNCALLABLE-INSTANCE-FUNCTION" + } + fn description(&self) -> &str { + "Set function of funcallable instance" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -535,8 +743,12 @@ impl Tool for SetFuncallableInstanceFunctionTool { /// FUNCALLABLE-STANDARD-CLASS - Funcallable standard class pub struct FuncallableStandardClassTool; impl Tool for FuncallableStandardClassTool { - fn name(&self) -> &str { "FUNCALLABLE-STANDARD-CLASS" } - fn description(&self) -> &str { "Funcallable standard class type" } + fn name(&self) -> &str { + "FUNCALLABLE-STANDARD-CLASS" + } + fn description(&self) -> &str { + "Funcallable standard class type" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("FUNCALLABLE-STANDARD-CLASS".to_string())) } @@ -545,8 +757,12 @@ impl Tool for FuncallableStandardClassTool { /// FUNCALLABLE-STANDARD-OBJECT - Funcallable standard object pub struct FuncallableStandardObjectTool; impl Tool for FuncallableStandardObjectTool { - fn name(&self) -> &str { "FUNCALLABLE-STANDARD-OBJECT" } - fn description(&self) -> &str { "Funcallable standard object type" } + fn name(&self) -> &str { + "FUNCALLABLE-STANDARD-OBJECT" + } + fn description(&self) -> &str { + "Funcallable standard object type" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("FUNCALLABLE-STANDARD-OBJECT".to_string())) } diff --git a/crates/ovsm/src/tools/stdlib/clos_basic.rs b/crates/ovsm/src/tools/stdlib/clos_basic.rs index ab8f86692..3a622c61f 100644 --- a/crates/ovsm/src/tools/stdlib/clos_basic.rs +++ b/crates/ovsm/src/tools/stdlib/clos_basic.rs @@ -14,8 +14,12 @@ use std::sync::Arc; /// DEFCLASS - Define class (returns class name) pub struct DefclassTool; impl Tool for DefclassTool { - fn name(&self) -> &str { "DEFCLASS" } - fn description(&self) -> &str { "Define a class" } + fn name(&self) -> &str { + "DEFCLASS" + } + fn description(&self) -> &str { + "Define a class" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -37,8 +41,12 @@ impl Tool for DefclassTool { /// MAKE-INSTANCE - Create instance pub struct MakeInstanceTool; impl Tool for MakeInstanceTool { - fn name(&self) -> &str { "MAKE-INSTANCE" } - fn description(&self) -> &str { "Create class instance" } + fn name(&self) -> &str { + "MAKE-INSTANCE" + } + fn description(&self) -> &str { + "Create class instance" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -53,8 +61,12 @@ impl Tool for MakeInstanceTool { /// CLASS-OF - Get class of object pub struct ClassOfTool; impl Tool for ClassOfTool { - fn name(&self) -> &str { "CLASS-OF" } - fn description(&self) -> &str { "Get class of object" } + fn name(&self) -> &str { + "CLASS-OF" + } + fn description(&self) -> &str { + "Get class of object" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -81,8 +93,12 @@ macro_rules! simple_clos_tool { #[doc = $desc] pub struct $name; impl Tool for $name { - fn name(&self) -> &str { $str } - fn description(&self) -> &str { $desc } + fn name(&self) -> &str { + $str + } + fn description(&self) -> &str { + $desc + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -101,8 +117,12 @@ macro_rules! simple_clos_tool_2args { #[doc = $desc] pub struct $name; impl Tool for $name { - fn name(&self) -> &str { $str } - fn description(&self) -> &str { $desc } + fn name(&self) -> &str { + $str + } + fn description(&self) -> &str { + $desc + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -127,10 +147,18 @@ simple_clos_tool_2args!(SlotExistsPTool, "SLOT-EXISTS-P", "Check if slot exists" simple_clos_tool!(DefgenericTool, "DEFGENERIC", "Define generic function"); simple_clos_tool!(DefmethodTool, "DEFMETHOD", "Define method"); simple_clos_tool!(CallNextMethodTool, "CALL-NEXT-METHOD", "Call next method"); -simple_clos_tool!(NextMethodPTool, "NEXT-METHOD-P", "Check if next method exists"); +simple_clos_tool!( + NextMethodPTool, + "NEXT-METHOD-P", + "Check if next method exists" +); // Method combination -simple_clos_tool!(MethodCombinationTool, "METHOD-COMBINATION", "Define method combination"); +simple_clos_tool!( + MethodCombinationTool, + "METHOD-COMBINATION", + "Define method combination" +); simple_clos_tool!(CallMethodTool, "CALL-METHOD", "Call specific method"); // Class hierarchy @@ -144,20 +172,48 @@ simple_clos_tool!(SubclasspTool, "SUBCLASSP", "Check subclass relation"); simple_clos_tool!(SubtypepTool, "SUBTYPEP", "Check subtype relation"); // Initialization -simple_clos_tool!(InitializeInstanceTool, "INITIALIZE-INSTANCE", "Initialize new instance"); -simple_clos_tool!(ReinitializeInstanceTool, "REINITIALIZE-INSTANCE", "Reinitialize instance"); -simple_clos_tool!(SharedInitializeTool, "SHARED-INITIALIZE", "Shared initialization"); +simple_clos_tool!( + InitializeInstanceTool, + "INITIALIZE-INSTANCE", + "Initialize new instance" +); +simple_clos_tool!( + ReinitializeInstanceTool, + "REINITIALIZE-INSTANCE", + "Reinitialize instance" +); +simple_clos_tool!( + SharedInitializeTool, + "SHARED-INITIALIZE", + "Shared initialization" +); // Change class simple_clos_tool!(ChangeClassTool, "CHANGE-CLASS", "Change object's class"); -simple_clos_tool!(UpdateInstanceForDifferentClassTool, "UPDATE-INSTANCE-FOR-DIFFERENT-CLASS", "Update after class change"); +simple_clos_tool!( + UpdateInstanceForDifferentClassTool, + "UPDATE-INSTANCE-FOR-DIFFERENT-CLASS", + "Update after class change" +); // Additional CLOS utilities simple_clos_tool!(StandardClassTool, "STANDARD-CLASS", "Standard class type"); -simple_clos_tool!(StandardObjectTool, "STANDARD-OBJECT", "Standard object type"); -simple_clos_tool!(StandardGenericFunctionTool, "STANDARD-GENERIC-FUNCTION", "Standard generic function"); +simple_clos_tool!( + StandardObjectTool, + "STANDARD-OBJECT", + "Standard object type" +); +simple_clos_tool!( + StandardGenericFunctionTool, + "STANDARD-GENERIC-FUNCTION", + "Standard generic function" +); simple_clos_tool!(StandardMethodTool, "STANDARD-METHOD", "Standard method"); -simple_clos_tool!(SlotDefinitionTool, "SLOT-DEFINITION", "Slot definition object"); +simple_clos_tool!( + SlotDefinitionTool, + "SLOT-DEFINITION", + "Slot definition object" +); /// Registers all CLOS (Common Lisp Object System) tools with the tool registry. /// diff --git a/crates/ovsm/src/tools/stdlib/compiler_eval.rs b/crates/ovsm/src/tools/stdlib/compiler_eval.rs index aae98d9f3..a3bb12e43 100644 --- a/crates/ovsm/src/tools/stdlib/compiler_eval.rs +++ b/crates/ovsm/src/tools/stdlib/compiler_eval.rs @@ -18,22 +18,37 @@ use std::sync::Arc; /// COMPILE - Compile function pub struct CompileTool; impl Tool for CompileTool { - fn name(&self) -> &str { "COMPILE" } - fn description(&self) -> &str { "Compile function definition" } + fn name(&self) -> &str { + "COMPILE" + } + fn description(&self) -> &str { + "Compile function definition" + } fn execute(&self, args: &[Value]) -> Result { // Simplified: return the function name - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// COMPILE-FILE - Compile file pub struct CompileFileTool; impl Tool for CompileFileTool { - fn name(&self) -> &str { "COMPILE-FILE" } - fn description(&self) -> &str { "Compile Lisp source file" } + fn name(&self) -> &str { + "COMPILE-FILE" + } + fn description(&self) -> &str { + "Compile Lisp source file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "COMPILE-FILE requires filename".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "COMPILE-FILE requires filename".to_string(), + }); } // Return compilation results as an object @@ -50,7 +65,10 @@ impl Tool for CompileFileTool { Ok(Value::Object(Arc::new(compile_result))) } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -58,18 +76,28 @@ impl Tool for CompileFileTool { /// COMPILE-FILE-PATHNAME - Get compiled file pathname pub struct CompileFilePathnameTool; impl Tool for CompileFilePathnameTool { - fn name(&self) -> &str { "COMPILE-FILE-PATHNAME" } - fn description(&self) -> &str { "Get pathname for compiled file" } + fn name(&self) -> &str { + "COMPILE-FILE-PATHNAME" + } + fn description(&self) -> &str { + "Get pathname for compiled file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "COMPILE-FILE-PATHNAME requires filename".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "COMPILE-FILE-PATHNAME requires filename".to_string(), + }); } match &args[0] { Value::String(path) => { let output = path.replace(".lisp", ".fasl"); Ok(Value::String(output)) } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -77,8 +105,12 @@ impl Tool for CompileFilePathnameTool { /// COMPILED-FUNCTION-P - Check if function is compiled pub struct CompiledFunctionPTool; impl Tool for CompiledFunctionPTool { - fn name(&self) -> &str { "COMPILED-FUNCTION-P" } - fn description(&self) -> &str { "Check if function is compiled" } + fn name(&self) -> &str { + "COMPILED-FUNCTION-P" + } + fn description(&self) -> &str { + "Check if function is compiled" + } fn execute(&self, _args: &[Value]) -> Result { // Simplified: always return true Ok(Value::Bool(true)) @@ -88,8 +120,12 @@ impl Tool for CompiledFunctionPTool { /// DISASSEMBLE - Disassemble function pub struct DisassembleTool; impl Tool for DisassembleTool { - fn name(&self) -> &str { "DISASSEMBLE" } - fn description(&self) -> &str { "Disassemble compiled function" } + fn name(&self) -> &str { + "DISASSEMBLE" + } + fn description(&self) -> &str { + "Disassemble compiled function" + } fn execute(&self, args: &[Value]) -> Result { // Validate argument count if args.is_empty() { @@ -106,13 +142,19 @@ impl Tool for DisassembleTool { let mut disasm_info = HashMap::new(); disasm_info.insert("function".to_string(), Value::String(func_name.clone())); - disasm_info.insert("instructions".to_string(), Value::Array(Arc::new(vec![ - Value::String("PUSH".to_string()), - Value::String("CALL".to_string()), - Value::String("RET".to_string()), - ]))); + disasm_info.insert( + "instructions".to_string(), + Value::Array(Arc::new(vec![ + Value::String("PUSH".to_string()), + Value::String("CALL".to_string()), + Value::String("RET".to_string()), + ])), + ); disasm_info.insert("available".to_string(), Value::Bool(false)); - disasm_info.insert("message".to_string(), Value::String(format!("Disassembly not available for {}", func_name))); + disasm_info.insert( + "message".to_string(), + Value::String(format!("Disassembly not available for {}", func_name)), + ); Ok(Value::Object(Arc::new(disasm_info))) } @@ -125,11 +167,18 @@ impl Tool for DisassembleTool { /// LOAD - Load Lisp file pub struct LoadTool; impl Tool for LoadTool { - fn name(&self) -> &str { "LOAD" } - fn description(&self) -> &str { "Load and execute Lisp file" } + fn name(&self) -> &str { + "LOAD" + } + fn description(&self) -> &str { + "Load and execute Lisp file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "LOAD requires filename".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "LOAD requires filename".to_string(), + }); } // Simplified: return true Ok(Value::Bool(true)) @@ -139,21 +188,37 @@ impl Tool for LoadTool { /// REQUIRE - Require module pub struct RequireTool; impl Tool for RequireTool { - fn name(&self) -> &str { "REQUIRE" } - fn description(&self) -> &str { "Require and load module" } + fn name(&self) -> &str { + "REQUIRE" + } + fn description(&self) -> &str { + "Require and load module" + } fn execute(&self, args: &[Value]) -> Result { // Simplified: return module name - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PROVIDE - Provide module pub struct ProvideTool; impl Tool for ProvideTool { - fn name(&self) -> &str { "PROVIDE" } - fn description(&self) -> &str { "Mark module as provided" } + fn name(&self) -> &str { + "PROVIDE" + } + fn description(&self) -> &str { + "Mark module as provided" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -164,30 +229,50 @@ impl Tool for ProvideTool { /// EVAL - Evaluate expression pub struct EvalTool; impl Tool for EvalTool { - fn name(&self) -> &str { "EVAL" } - fn description(&self) -> &str { "Evaluate Lisp expression" } + fn name(&self) -> &str { + "EVAL" + } + fn description(&self) -> &str { + "Evaluate Lisp expression" + } fn execute(&self, args: &[Value]) -> Result { // Simplified: return the argument - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// EVAL-WHEN - Conditional evaluation pub struct EvalWhenTool; impl Tool for EvalWhenTool { - fn name(&self) -> &str { "EVAL-WHEN" } - fn description(&self) -> &str { "Conditionally evaluate at compile/load/execute time" } + fn name(&self) -> &str { + "EVAL-WHEN" + } + fn description(&self) -> &str { + "Conditionally evaluate at compile/load/execute time" + } fn execute(&self, args: &[Value]) -> Result { // Simplified: evaluate all forms - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// CONSTANTP - Check if expression is constant pub struct ConstantpTool; impl Tool for ConstantpTool { - fn name(&self) -> &str { "CONSTANTP" } - fn description(&self) -> &str { "Check if expression is constant" } + fn name(&self) -> &str { + "CONSTANTP" + } + fn description(&self) -> &str { + "Check if expression is constant" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Bool(false)); @@ -208,18 +293,30 @@ impl Tool for ConstantpTool { /// DEFINE-COMPILER-MACRO - Define compiler macro pub struct DefineCompilerMacroTool; impl Tool for DefineCompilerMacroTool { - fn name(&self) -> &str { "DEFINE-COMPILER-MACRO" } - fn description(&self) -> &str { "Define compiler macro" } + fn name(&self) -> &str { + "DEFINE-COMPILER-MACRO" + } + fn description(&self) -> &str { + "Define compiler macro" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// COMPILER-MACRO-FUNCTION - Get compiler macro function pub struct CompilerMacroFunctionTool; impl Tool for CompilerMacroFunctionTool { - fn name(&self) -> &str { "COMPILER-MACRO-FUNCTION" } - fn description(&self) -> &str { "Get compiler macro function" } + fn name(&self) -> &str { + "COMPILER-MACRO-FUNCTION" + } + fn description(&self) -> &str { + "Get compiler macro function" + } fn execute(&self, args: &[Value]) -> Result { // Validate argument count if args.is_empty() { @@ -238,7 +335,10 @@ impl Tool for CompilerMacroFunctionTool { let mut macro_info = HashMap::new(); macro_info.insert("name".to_string(), Value::String(func_name)); macro_info.insert("defined".to_string(), Value::Bool(false)); - macro_info.insert("type".to_string(), Value::String("compiler-macro".to_string())); + macro_info.insert( + "type".to_string(), + Value::String("compiler-macro".to_string()), + ); macro_info.insert("parameters".to_string(), Value::Array(Arc::new(vec![]))); Ok(Value::Object(Arc::new(macro_info))) @@ -252,79 +352,139 @@ impl Tool for CompilerMacroFunctionTool { /// PROCLAIM - Proclaim declaration globally pub struct ProclaimTool; impl Tool for ProclaimTool { - fn name(&self) -> &str { "PROCLAIM" } - fn description(&self) -> &str { "Make global declaration" } + fn name(&self) -> &str { + "PROCLAIM" + } + fn description(&self) -> &str { + "Make global declaration" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DECLAIM - Declare at compile time pub struct DeclaimTool; impl Tool for DeclaimTool { - fn name(&self) -> &str { "DECLAIM" } - fn description(&self) -> &str { "Make compile-time declaration" } + fn name(&self) -> &str { + "DECLAIM" + } + fn description(&self) -> &str { + "Make compile-time declaration" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DECLARE - Local declaration pub struct DeclareTool; impl Tool for DeclareTool { - fn name(&self) -> &str { "DECLARE" } - fn description(&self) -> &str { "Make local declaration" } + fn name(&self) -> &str { + "DECLARE" + } + fn description(&self) -> &str { + "Make local declaration" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// THE - Type assertion pub struct TheTool; impl Tool for TheTool { - fn name(&self) -> &str { "THE" } - fn description(&self) -> &str { "Assert value type" } + fn name(&self) -> &str { + "THE" + } + fn description(&self) -> &str { + "Assert value type" + } fn execute(&self, args: &[Value]) -> Result { // Return the value (2nd argument) - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// SPECIAL - Special variable declaration pub struct SpecialTool; impl Tool for SpecialTool { - fn name(&self) -> &str { "SPECIAL" } - fn description(&self) -> &str { "Declare special variable" } + fn name(&self) -> &str { + "SPECIAL" + } + fn description(&self) -> &str { + "Declare special variable" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// INLINE - Inline function declaration pub struct InlineTool; impl Tool for InlineTool { - fn name(&self) -> &str { "INLINE" } - fn description(&self) -> &str { "Declare function for inlining" } + fn name(&self) -> &str { + "INLINE" + } + fn description(&self) -> &str { + "Declare function for inlining" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// NOTINLINE - Not-inline function declaration pub struct NotinlineTool; impl Tool for NotinlineTool { - fn name(&self) -> &str { "NOTINLINE" } - fn description(&self) -> &str { "Declare function not for inlining" } + fn name(&self) -> &str { + "NOTINLINE" + } + fn description(&self) -> &str { + "Declare function not for inlining" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// OPTIMIZE - Optimization declaration pub struct OptimizeTool; impl Tool for OptimizeTool { - fn name(&self) -> &str { "OPTIMIZE" } - fn description(&self) -> &str { "Declare optimization settings" } + fn name(&self) -> &str { + "OPTIMIZE" + } + fn description(&self) -> &str { + "Declare optimization settings" + } fn execute(&self, args: &[Value]) -> Result { // Return optimization settings as an object let mut optimize_settings = HashMap::new(); @@ -350,50 +510,90 @@ impl Tool for OptimizeTool { /// SPEED - Speed optimization level pub struct SpeedTool; impl Tool for SpeedTool { - fn name(&self) -> &str { "SPEED" } - fn description(&self) -> &str { "Speed optimization level" } + fn name(&self) -> &str { + "SPEED" + } + fn description(&self) -> &str { + "Speed optimization level" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } /// SAFETY - Safety optimization level pub struct SafetyTool; impl Tool for SafetyTool { - fn name(&self) -> &str { "SAFETY" } - fn description(&self) -> &str { "Safety optimization level" } + fn name(&self) -> &str { + "SAFETY" + } + fn description(&self) -> &str { + "Safety optimization level" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } /// DEBUG - Debug optimization level pub struct DebugTool; impl Tool for DebugTool { - fn name(&self) -> &str { "DEBUG" } - fn description(&self) -> &str { "Debug optimization level" } + fn name(&self) -> &str { + "DEBUG" + } + fn description(&self) -> &str { + "Debug optimization level" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } /// SPACE - Space optimization level pub struct SpaceTool; impl Tool for SpaceTool { - fn name(&self) -> &str { "SPACE" } - fn description(&self) -> &str { "Space optimization level" } + fn name(&self) -> &str { + "SPACE" + } + fn description(&self) -> &str { + "Space optimization level" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } /// COMPILATION-SPEED - Compilation speed level pub struct CompilationSpeedTool; impl Tool for CompilationSpeedTool { - fn name(&self) -> &str { "COMPILATION-SPEED" } - fn description(&self) -> &str { "Compilation speed level" } + fn name(&self) -> &str { + "COMPILATION-SPEED" + } + fn description(&self) -> &str { + "Compilation speed level" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } @@ -404,18 +604,30 @@ impl Tool for CompilationSpeedTool { /// SYMBOL-FUNCTION - Get function bound to symbol pub struct SymbolFunctionTool; impl Tool for SymbolFunctionTool { - fn name(&self) -> &str { "SYMBOL-FUNCTION" } - fn description(&self) -> &str { "Get function bound to symbol" } + fn name(&self) -> &str { + "SYMBOL-FUNCTION" + } + fn description(&self) -> &str { + "Get function bound to symbol" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// FBOUNDP - Check if function bound pub struct FboundpTool; impl Tool for FboundpTool { - fn name(&self) -> &str { "FBOUNDP" } - fn description(&self) -> &str { "Check if symbol has function binding" } + fn name(&self) -> &str { + "FBOUNDP" + } + fn description(&self) -> &str { + "Check if symbol has function binding" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(!args.is_empty())) } @@ -424,18 +636,30 @@ impl Tool for FboundpTool { /// FMAKUNBOUND - Unbind function pub struct FmakunboundTool; impl Tool for FmakunboundTool { - fn name(&self) -> &str { "FMAKUNBOUND" } - fn description(&self) -> &str { "Remove function binding from symbol" } + fn name(&self) -> &str { + "FMAKUNBOUND" + } + fn description(&self) -> &str { + "Remove function binding from symbol" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// MACRO-FUNCTION - Get macro function pub struct MacroFunctionTool; impl Tool for MacroFunctionTool { - fn name(&self) -> &str { "MACRO-FUNCTION" } - fn description(&self) -> &str { "Get macro function bound to symbol" } + fn name(&self) -> &str { + "MACRO-FUNCTION" + } + fn description(&self) -> &str { + "Get macro function bound to symbol" + } fn execute(&self, args: &[Value]) -> Result { // Validate argument count if args.is_empty() { diff --git a/crates/ovsm/src/tools/stdlib/conditions.rs b/crates/ovsm/src/tools/stdlib/conditions.rs index 6941aaeaf..a3005c997 100644 --- a/crates/ovsm/src/tools/stdlib/conditions.rs +++ b/crates/ovsm/src/tools/stdlib/conditions.rs @@ -13,10 +13,18 @@ use std::sync::Arc; /// ERROR - Signal error pub struct ErrorTool; impl Tool for ErrorTool { - fn name(&self) -> &str { "ERROR" } - fn description(&self) -> &str { "Signal an error condition" } + fn name(&self) -> &str { + "ERROR" + } + fn description(&self) -> &str { + "Signal an error condition" + } fn execute(&self, args: &[Value]) -> Result { - let msg = if args.is_empty() { "Error" } else { args[0].as_string()? }; + let msg = if args.is_empty() { + "Error" + } else { + args[0].as_string()? + }; Err(Error::ToolExecutionError { tool: "ERROR".to_string(), reason: msg.to_string(), @@ -27,10 +35,18 @@ impl Tool for ErrorTool { /// CERROR - Continuable error pub struct CerrorTool; impl Tool for CerrorTool { - fn name(&self) -> &str { "CERROR" } - fn description(&self) -> &str { "Signal continuable error" } + fn name(&self) -> &str { + "CERROR" + } + fn description(&self) -> &str { + "Signal continuable error" + } fn execute(&self, args: &[Value]) -> Result { - let msg = if args.is_empty() { "Continuable error" } else { args[0].as_string()? }; + let msg = if args.is_empty() { + "Continuable error" + } else { + args[0].as_string()? + }; Ok(Value::String(format!("CERROR: {}", msg))) } } @@ -38,10 +54,18 @@ impl Tool for CerrorTool { /// WARN - Signal warning pub struct WarnTool; impl Tool for WarnTool { - fn name(&self) -> &str { "WARN" } - fn description(&self) -> &str { "Signal warning" } + fn name(&self) -> &str { + "WARN" + } + fn description(&self) -> &str { + "Signal warning" + } fn execute(&self, args: &[Value]) -> Result { - let msg = if args.is_empty() { "Warning" } else { args[0].as_string()? }; + let msg = if args.is_empty() { + "Warning" + } else { + args[0].as_string()? + }; eprintln!("WARNING: {}", msg); Ok(Value::Null) } @@ -50,8 +74,12 @@ impl Tool for WarnTool { /// SIGNAL - Signal condition pub struct SignalTool; impl Tool for SignalTool { - fn name(&self) -> &str { "SIGNAL" } - fn description(&self) -> &str { "Signal condition" } + fn name(&self) -> &str { + "SIGNAL" + } + fn description(&self) -> &str { + "Signal condition" + } fn execute(&self, args: &[Value]) -> Result { if !args.is_empty() { eprintln!("SIGNAL: {}", args[0]); @@ -66,28 +94,52 @@ macro_rules! simple_condition_tool { #[doc = $desc] pub struct $name; impl Tool for $name { - fn name(&self) -> &str { $str } - fn description(&self) -> &str { $desc } + fn name(&self) -> &str { + $str + } + fn description(&self) -> &str { + $desc + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } }; } simple_condition_tool!(HandlerBindTool, "HANDLER-BIND", "Bind condition handlers"); -simple_condition_tool!(HandlerCaseTool, "HANDLER-CASE", "Handle conditions with cases"); +simple_condition_tool!( + HandlerCaseTool, + "HANDLER-CASE", + "Handle conditions with cases" +); simple_condition_tool!(IgnoreErrorsTool, "IGNORE-ERRORS", "Suppress errors"); -simple_condition_tool!(WithSimpleRestartTool, "WITH-SIMPLE-RESTART", "Provide simple restart"); +simple_condition_tool!( + WithSimpleRestartTool, + "WITH-SIMPLE-RESTART", + "Provide simple restart" +); simple_condition_tool!(RestartCaseTool, "RESTART-CASE", "Define restarts"); simple_condition_tool!(RestartBindTool, "RESTART-BIND", "Bind restarts"); simple_condition_tool!(InvokeRestartTool, "INVOKE-RESTART", "Invoke named restart"); simple_condition_tool!(FindRestartTool, "FIND-RESTART", "Find restart by name"); // Replaced with manual implementation below for Arc usage // simple_condition_tool!(ComputeRestartsTool, "COMPUTE-RESTARTS", "List available restarts"); -simple_condition_tool!(MakeConditionTool, "MAKE-CONDITION", "Create condition object"); +simple_condition_tool!( + MakeConditionTool, + "MAKE-CONDITION", + "Create condition object" +); simple_condition_tool!(ConditionTypeTool, "CONDITION-TYPE", "Get condition type"); -simple_condition_tool!(SimpleConditionFormatControlTool, "SIMPLE-CONDITION-FORMAT-CONTROL", "Get format string"); +simple_condition_tool!( + SimpleConditionFormatControlTool, + "SIMPLE-CONDITION-FORMAT-CONTROL", + "Get format string" +); // Replaced with manual implementation below for Arc usage // simple_condition_tool!(SimpleConditionFormatArgumentsTool, "SIMPLE-CONDITION-FORMAT-ARGUMENTS", "Get format args"); @@ -101,8 +153,16 @@ simple_condition_tool!(StreamErrorTool, "STREAM-ERROR", "Stream operation error" simple_condition_tool!(FileErrorTool, "FILE-ERROR", "File operation error"); simple_condition_tool!(ArithmeticErrorTool, "ARITHMETIC-ERROR", "Math error"); simple_condition_tool!(DivisionByZeroTool, "DIVISION-BY-ZERO", "Division by zero"); -simple_condition_tool!(FloatingPointOverflowTool, "FLOATING-POINT-OVERFLOW", "Float overflow"); -simple_condition_tool!(FloatingPointUnderflowTool, "FLOATING-POINT-UNDERFLOW", "Float underflow"); +simple_condition_tool!( + FloatingPointOverflowTool, + "FLOATING-POINT-OVERFLOW", + "Float overflow" +); +simple_condition_tool!( + FloatingPointUnderflowTool, + "FLOATING-POINT-UNDERFLOW", + "Float underflow" +); // Condition predicates simple_condition_tool!(ConditionPTool, "CONDITION-P", "Check if condition"); @@ -111,7 +171,11 @@ simple_condition_tool!(WarningPTool, "WARNING-P", "Check if warning"); // Restart utilities simple_condition_tool!(RestartNameTool, "RESTART-NAME", "Get restart name"); -simple_condition_tool!(InvokeRestartInteractivelyTool, "INVOKE-RESTART-INTERACTIVELY", "Invoke restart interactively"); +simple_condition_tool!( + InvokeRestartInteractivelyTool, + "INVOKE-RESTART-INTERACTIVELY", + "Invoke restart interactively" +); simple_condition_tool!(AbortTool, "ABORT", "Abort to toplevel"); simple_condition_tool!(ContinueTool, "CONTINUE", "Continue from error"); simple_condition_tool!(StorValueTool, "STORE-VALUE", "Store value restart"); @@ -121,8 +185,12 @@ simple_condition_tool!(UseValueTool, "USE-VALUE", "Use value restart"); /// COMPUTE-RESTARTS - List available restarts pub struct ComputeRestartsTool; impl Tool for ComputeRestartsTool { - fn name(&self) -> &str { "COMPUTE-RESTARTS" } - fn description(&self) -> &str { "List available restarts" } + fn name(&self) -> &str { + "COMPUTE-RESTARTS" + } + fn description(&self) -> &str { + "List available restarts" + } fn execute(&self, args: &[Value]) -> Result { // Return array of available restart names let restarts = vec![ @@ -142,8 +210,12 @@ impl Tool for ComputeRestartsTool { /// SIMPLE-CONDITION-FORMAT-ARGUMENTS - Get format args pub struct SimpleConditionFormatArgumentsTool; impl Tool for SimpleConditionFormatArgumentsTool { - fn name(&self) -> &str { "SIMPLE-CONDITION-FORMAT-ARGUMENTS" } - fn description(&self) -> &str { "Get format args" } + fn name(&self) -> &str { + "SIMPLE-CONDITION-FORMAT-ARGUMENTS" + } + fn description(&self) -> &str { + "Get format args" + } fn execute(&self, args: &[Value]) -> Result { // Extract format arguments from condition // Return as array if multiple arguments, single value otherwise @@ -164,8 +236,12 @@ impl Tool for SimpleConditionFormatArgumentsTool { /// MUFFLE-WARNING - Suppress warning signal pub struct MuffleWarningTool; impl Tool for MuffleWarningTool { - fn name(&self) -> &str { "MUFFLE-WARNING" } - fn description(&self) -> &str { "Suppress warning from being displayed" } + fn name(&self) -> &str { + "MUFFLE-WARNING" + } + fn description(&self) -> &str { + "Suppress warning from being displayed" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -174,8 +250,12 @@ impl Tool for MuffleWarningTool { /// BREAK - Enter debugger pub struct BreakTool; impl Tool for BreakTool { - fn name(&self) -> &str { "BREAK" } - fn description(&self) -> &str { "Enter interactive debugger" } + fn name(&self) -> &str { + "BREAK" + } + fn description(&self) -> &str { + "Enter interactive debugger" + } fn execute(&self, args: &[Value]) -> Result { let msg = if args.is_empty() { "Break" @@ -193,8 +273,12 @@ impl Tool for BreakTool { /// ASSERT - Runtime assertion pub struct AssertTool; impl Tool for AssertTool { - fn name(&self) -> &str { "ASSERT" } - fn description(&self) -> &str { "Runtime assertion with correctable error" } + fn name(&self) -> &str { + "ASSERT" + } + fn description(&self) -> &str { + "Runtime assertion with correctable error" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::ToolExecutionError { @@ -222,8 +306,12 @@ impl Tool for AssertTool { /// CHECK-TYPE - Type checking with restart pub struct CheckTypeTool; impl Tool for CheckTypeTool { - fn name(&self) -> &str { "CHECK-TYPE" } - fn description(&self) -> &str { "Check type with correctable error" } + fn name(&self) -> &str { + "CHECK-TYPE" + } + fn description(&self) -> &str { + "Check type with correctable error" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::ToolExecutionError { @@ -241,38 +329,66 @@ impl Tool for CheckTypeTool { /// DEFINE-CONDITION - Define condition type pub struct DefineConditionTool; impl Tool for DefineConditionTool { - fn name(&self) -> &str { "DEFINE-CONDITION" } - fn description(&self) -> &str { "Define new condition type" } + fn name(&self) -> &str { + "DEFINE-CONDITION" + } + fn description(&self) -> &str { + "Define new condition type" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// WITH-CONDITION-RESTARTS - Associate restarts with condition pub struct WithConditionRestartsTool; impl Tool for WithConditionRestartsTool { - fn name(&self) -> &str { "WITH-CONDITION-RESTARTS" } - fn description(&self) -> &str { "Associate restarts with condition" } + fn name(&self) -> &str { + "WITH-CONDITION-RESTARTS" + } + fn description(&self) -> &str { + "Associate restarts with condition" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 2 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 2 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// RESTART-CASE-ASSOCIATE - Associate restart with condition pub struct RestartCaseAssociateTool; impl Tool for RestartCaseAssociateTool { - fn name(&self) -> &str { "RESTART-CASE-ASSOCIATE" } - fn description(&self) -> &str { "Associate restart with condition in RESTART-CASE" } + fn name(&self) -> &str { + "RESTART-CASE-ASSOCIATE" + } + fn description(&self) -> &str { + "Associate restart with condition in RESTART-CASE" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// SIGNAL-CONDITION - Signal pre-constructed condition pub struct SignalConditionTool; impl Tool for SignalConditionTool { - fn name(&self) -> &str { "SIGNAL-CONDITION" } - fn description(&self) -> &str { "Signal already-constructed condition object" } + fn name(&self) -> &str { + "SIGNAL-CONDITION" + } + fn description(&self) -> &str { + "Signal already-constructed condition object" + } fn execute(&self, args: &[Value]) -> Result { if !args.is_empty() { eprintln!("CONDITION: {}", args[0]); @@ -284,8 +400,12 @@ impl Tool for SignalConditionTool { /// INVOKE-DEBUGGER - Invoke debugger explicitly pub struct InvokeDebuggerTool; impl Tool for InvokeDebuggerTool { - fn name(&self) -> &str { "INVOKE-DEBUGGER" } - fn description(&self) -> &str { "Explicitly invoke debugger with condition" } + fn name(&self) -> &str { + "INVOKE-DEBUGGER" + } + fn description(&self) -> &str { + "Explicitly invoke debugger with condition" + } fn execute(&self, args: &[Value]) -> Result { let msg = if args.is_empty() { "Debugger invoked" @@ -303,8 +423,12 @@ impl Tool for InvokeDebuggerTool { /// SIMPLE-CONDITION-P - Check if simple condition pub struct SimpleConditionPTool; impl Tool for SimpleConditionPTool { - fn name(&self) -> &str { "SIMPLE-CONDITION-P" } - fn description(&self) -> &str { "Check if condition is simple condition" } + fn name(&self) -> &str { + "SIMPLE-CONDITION-P" + } + fn description(&self) -> &str { + "Check if condition is simple condition" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(!args.is_empty())) } @@ -313,8 +437,12 @@ impl Tool for SimpleConditionPTool { /// SERIOUS-CONDITION-P - Check if serious condition pub struct SeriousConditionPTool; impl Tool for SeriousConditionPTool { - fn name(&self) -> &str { "SERIOUS-CONDITION-P" } - fn description(&self) -> &str { "Check if condition is serious" } + fn name(&self) -> &str { + "SERIOUS-CONDITION-P" + } + fn description(&self) -> &str { + "Check if condition is serious" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(!args.is_empty())) } @@ -323,18 +451,30 @@ impl Tool for SeriousConditionPTool { /// CELL-ERROR-NAME - Get unbound variable name pub struct CellErrorNameTool; impl Tool for CellErrorNameTool { - fn name(&self) -> &str { "CELL-ERROR-NAME" } - fn description(&self) -> &str { "Get name from cell-error condition" } + fn name(&self) -> &str { + "CELL-ERROR-NAME" + } + fn description(&self) -> &str { + "Get name from cell-error condition" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// UNBOUND-VARIABLE - Signal unbound variable error pub struct UnboundVariableTool; impl Tool for UnboundVariableTool { - fn name(&self) -> &str { "UNBOUND-VARIABLE" } - fn description(&self) -> &str { "Unbound variable error type" } + fn name(&self) -> &str { + "UNBOUND-VARIABLE" + } + fn description(&self) -> &str { + "Unbound variable error type" + } fn execute(&self, args: &[Value]) -> Result { let name = if args.is_empty() { "UNKNOWN" @@ -354,8 +494,12 @@ impl Tool for UnboundVariableTool { /// UNDEFINED-FUNCTION - Signal undefined function error pub struct UndefinedFunctionTool; impl Tool for UndefinedFunctionTool { - fn name(&self) -> &str { "UNDEFINED-FUNCTION" } - fn description(&self) -> &str { "Undefined function error type" } + fn name(&self) -> &str { + "UNDEFINED-FUNCTION" + } + fn description(&self) -> &str { + "Undefined function error type" + } fn execute(&self, args: &[Value]) -> Result { let name = if args.is_empty() { "UNKNOWN" @@ -375,8 +519,12 @@ impl Tool for UndefinedFunctionTool { /// STORAGE-CONDITION - Storage exhaustion condition pub struct StorageConditionTool; impl Tool for StorageConditionTool { - fn name(&self) -> &str { "STORAGE-CONDITION" } - fn description(&self) -> &str { "Storage exhaustion condition type" } + fn name(&self) -> &str { + "STORAGE-CONDITION" + } + fn description(&self) -> &str { + "Storage exhaustion condition type" + } fn execute(&self, _args: &[Value]) -> Result { Err(Error::ToolExecutionError { tool: "STORAGE-CONDITION".to_string(), diff --git a/crates/ovsm/src/tools/stdlib/control_flow_extended.rs b/crates/ovsm/src/tools/stdlib/control_flow_extended.rs index 37cec4ac2..3c83efb68 100644 --- a/crates/ovsm/src/tools/stdlib/control_flow_extended.rs +++ b/crates/ovsm/src/tools/stdlib/control_flow_extended.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// TAGBODY - Tagged body with GO targets pub struct TagbodyTool; impl Tool for TagbodyTool { - fn name(&self) -> &str { "TAGBODY" } - fn description(&self) -> &str { "Execute body with GO targets" } + fn name(&self) -> &str { + "TAGBODY" + } + fn description(&self) -> &str { + "Execute body with GO targets" + } fn execute(&self, args: &[Value]) -> Result { // In a full implementation, would track tags for GO jumps // For now, return results of all forms as array if multiple, or last form @@ -36,10 +40,18 @@ impl Tool for TagbodyTool { /// GO - Jump to tag in TAGBODY pub struct GoTool; impl Tool for GoTool { - fn name(&self) -> &str { "GO" } - fn description(&self) -> &str { "Jump to tag in TAGBODY" } + fn name(&self) -> &str { + "GO" + } + fn description(&self) -> &str { + "Jump to tag in TAGBODY" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -50,31 +62,55 @@ impl Tool for GoTool { /// BLOCK - Named block for RETURN-FROM pub struct BlockTool; impl Tool for BlockTool { - fn name(&self) -> &str { "BLOCK" } - fn description(&self) -> &str { "Create named block for RETURN-FROM" } + fn name(&self) -> &str { + "BLOCK" + } + fn description(&self) -> &str { + "Create named block for RETURN-FROM" + } fn execute(&self, args: &[Value]) -> Result { // Name is first arg, body follows - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// RETURN-FROM - Return from named block pub struct ReturnFromTool; impl Tool for ReturnFromTool { - fn name(&self) -> &str { "RETURN-FROM" } - fn description(&self) -> &str { "Return from named block" } + fn name(&self) -> &str { + "RETURN-FROM" + } + fn description(&self) -> &str { + "Return from named block" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// RETURN - Return from NIL block pub struct ReturnTool; impl Tool for ReturnTool { - fn name(&self) -> &str { "RETURN" } - fn description(&self) -> &str { "Return from implicit NIL block" } + fn name(&self) -> &str { + "RETURN" + } + fn description(&self) -> &str { + "Return from implicit NIL block" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -85,63 +121,108 @@ impl Tool for ReturnTool { /// PROG - PROG construct (BLOCK + LET + TAGBODY) pub struct ProgTool; impl Tool for ProgTool { - fn name(&self) -> &str { "PROG" } - fn description(&self) -> &str { "Combine BLOCK, LET, and TAGBODY" } + fn name(&self) -> &str { + "PROG" + } + fn description(&self) -> &str { + "Combine BLOCK, LET, and TAGBODY" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// PROG* - Sequential PROG (BLOCK + LET* + TAGBODY) pub struct ProgStarTool; impl Tool for ProgStarTool { - fn name(&self) -> &str { "PROG*" } - fn description(&self) -> &str { "Sequential PROG (BLOCK + LET* + TAGBODY)" } + fn name(&self) -> &str { + "PROG*" + } + fn description(&self) -> &str { + "Sequential PROG (BLOCK + LET* + TAGBODY)" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// PROG1 - Return first form value pub struct Prog1Tool; impl Tool for Prog1Tool { - fn name(&self) -> &str { "PROG1" } - fn description(&self) -> &str { "Evaluate forms, return first value" } + fn name(&self) -> &str { + "PROG1" + } + fn description(&self) -> &str { + "Evaluate forms, return first value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PROG2 - Return second form value pub struct Prog2Tool; impl Tool for Prog2Tool { - fn name(&self) -> &str { "PROG2" } - fn description(&self) -> &str { "Evaluate forms, return second value" } + fn name(&self) -> &str { + "PROG2" + } + fn description(&self) -> &str { + "Evaluate forms, return second value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// PROGN - Execute forms sequentially pub struct PrognTool; impl Tool for PrognTool { - fn name(&self) -> &str { "PROGN" } - fn description(&self) -> &str { "Execute forms sequentially, return last" } + fn name(&self) -> &str { + "PROGN" + } + fn description(&self) -> &str { + "Execute forms sequentially, return last" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// PROGV - Dynamic variable binding pub struct ProgvTool; impl Tool for ProgvTool { - fn name(&self) -> &str { "PROGV" } - fn description(&self) -> &str { "Dynamically bind variables during execution" } + fn name(&self) -> &str { + "PROGV" + } + fn description(&self) -> &str { + "Dynamically bind variables during execution" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::ToolExecutionError { tool: "PROGV".to_string(), - reason: "PROGV requires at least 2 arguments (symbols values &rest forms)".to_string(), + reason: "PROGV requires at least 2 arguments (symbols values &rest forms)" + .to_string(), }); } @@ -154,7 +235,11 @@ impl Tool for ProgvTool { } // Execute body with dynamic bindings - Ok(if args.len() > 2 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 2 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } @@ -165,11 +250,19 @@ impl Tool for ProgvTool { /// UNWIND-PROTECT - Ensure cleanup forms execute pub struct UnwindProtectTool; impl Tool for UnwindProtectTool { - fn name(&self) -> &str { "UNWIND-PROTECT" } - fn description(&self) -> &str { "Ensure cleanup forms execute" } + fn name(&self) -> &str { + "UNWIND-PROTECT" + } + fn description(&self) -> &str { + "Ensure cleanup forms execute" + } fn execute(&self, args: &[Value]) -> Result { // Return value of protected form (first arg) - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -180,21 +273,37 @@ impl Tool for UnwindProtectTool { /// CATCH - Establish catch tag pub struct CatchTool; impl Tool for CatchTool { - fn name(&self) -> &str { "CATCH" } - fn description(&self) -> &str { "Establish catch tag for THROW" } + fn name(&self) -> &str { + "CATCH" + } + fn description(&self) -> &str { + "Establish catch tag for THROW" + } fn execute(&self, args: &[Value]) -> Result { // Tag is first arg, body follows - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// THROW - Throw to catch tag pub struct ThrowTool; impl Tool for ThrowTool { - fn name(&self) -> &str { "THROW" } - fn description(&self) -> &str { "Throw value to catch tag" } + fn name(&self) -> &str { + "THROW" + } + fn description(&self) -> &str { + "Throw value to catch tag" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } @@ -205,18 +314,30 @@ impl Tool for ThrowTool { /// CASE - Case dispatch on value pub struct CaseTool; impl Tool for CaseTool { - fn name(&self) -> &str { "CASE" } - fn description(&self) -> &str { "Case dispatch on keyform value" } + fn name(&self) -> &str { + "CASE" + } + fn description(&self) -> &str { + "Case dispatch on keyform value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// CCASE - Correctable case pub struct CcaseTool; impl Tool for CcaseTool { - fn name(&self) -> &str { "CCASE" } - fn description(&self) -> &str { "Correctable case (signals error if no match)" } + fn name(&self) -> &str { + "CCASE" + } + fn description(&self) -> &str { + "Correctable case (signals error if no match)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::ToolExecutionError { @@ -232,8 +353,12 @@ impl Tool for CcaseTool { /// ECASE - Exhaustive case pub struct EcaseTool; impl Tool for EcaseTool { - fn name(&self) -> &str { "ECASE" } - fn description(&self) -> &str { "Exhaustive case (error if no match)" } + fn name(&self) -> &str { + "ECASE" + } + fn description(&self) -> &str { + "Exhaustive case (error if no match)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::ToolExecutionError { @@ -250,18 +375,30 @@ impl Tool for EcaseTool { /// TYPECASE - Type-based case dispatch pub struct TypecaseTool; impl Tool for TypecaseTool { - fn name(&self) -> &str { "TYPECASE" } - fn description(&self) -> &str { "Case dispatch on object type" } + fn name(&self) -> &str { + "TYPECASE" + } + fn description(&self) -> &str { + "Case dispatch on object type" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// CTYPECASE - Correctable typecase pub struct CtypecaseTool; impl Tool for CtypecaseTool { - fn name(&self) -> &str { "CTYPECASE" } - fn description(&self) -> &str { "Correctable typecase" } + fn name(&self) -> &str { + "CTYPECASE" + } + fn description(&self) -> &str { + "Correctable typecase" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::ToolExecutionError { @@ -277,8 +414,12 @@ impl Tool for CtypecaseTool { /// ETYPECASE - Exhaustive typecase pub struct EtypecaseTool; impl Tool for EtypecaseTool { - fn name(&self) -> &str { "ETYPECASE" } - fn description(&self) -> &str { "Exhaustive typecase (error if no match)" } + fn name(&self) -> &str { + "ETYPECASE" + } + fn description(&self) -> &str { + "Exhaustive typecase (error if no match)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::ToolExecutionError { @@ -299,15 +440,23 @@ impl Tool for EtypecaseTool { /// UNLESS - Execute unless condition is true pub struct UnlessTool; impl Tool for UnlessTool { - fn name(&self) -> &str { "UNLESS" } - fn description(&self) -> &str { "Execute body unless condition is true" } + fn name(&self) -> &str { + "UNLESS" + } + fn description(&self) -> &str { + "Execute body unless condition is true" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); } // First arg is condition, rest is body if !args[0].is_truthy() { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } else { Ok(Value::Null) } @@ -317,15 +466,23 @@ impl Tool for UnlessTool { /// WHEN - Execute when condition is true pub struct WhenTool; impl Tool for WhenTool { - fn name(&self) -> &str { "WHEN" } - fn description(&self) -> &str { "Execute body when condition is true" } + fn name(&self) -> &str { + "WHEN" + } + fn description(&self) -> &str { + "Execute body when condition is true" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); } // First arg is condition, rest is body if args[0].is_truthy() { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } else { Ok(Value::Null) } @@ -339,8 +496,12 @@ impl Tool for WhenTool { /// COND - Multi-clause conditional pub struct CondTool; impl Tool for CondTool { - fn name(&self) -> &str { "COND" } - fn description(&self) -> &str { "Multi-clause conditional" } + fn name(&self) -> &str { + "COND" + } + fn description(&self) -> &str { + "Multi-clause conditional" + } fn execute(&self, args: &[Value]) -> Result { // Each arg should be a clause (test consequent...) // In full implementation, would evaluate clauses until one's test succeeds @@ -355,7 +516,7 @@ impl Tool for CondTool { // Return last value of clause Ok(clause.last().cloned().unwrap_or(Value::Null)) } - _ => Ok(args[0].clone()) + _ => Ok(args[0].clone()), } } } @@ -363,8 +524,12 @@ impl Tool for CondTool { /// OR - Logical OR with short-circuit pub struct OrControlTool; impl Tool for OrControlTool { - fn name(&self) -> &str { "OR" } - fn description(&self) -> &str { "Logical OR with short-circuit evaluation" } + fn name(&self) -> &str { + "OR" + } + fn description(&self) -> &str { + "Logical OR with short-circuit evaluation" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if arg.is_truthy() { @@ -378,8 +543,12 @@ impl Tool for OrControlTool { /// AND - Logical AND with short-circuit pub struct AndControlTool; impl Tool for AndControlTool { - fn name(&self) -> &str { "AND" } - fn description(&self) -> &str { "Logical AND with short-circuit evaluation" } + fn name(&self) -> &str { + "AND" + } + fn description(&self) -> &str { + "Logical AND with short-circuit evaluation" + } fn execute(&self, args: &[Value]) -> Result { let mut last = Value::Bool(true); for arg in args { diff --git a/crates/ovsm/src/tools/stdlib/documentation.rs b/crates/ovsm/src/tools/stdlib/documentation.rs index 881b0ed2d..02ee410e0 100644 --- a/crates/ovsm/src/tools/stdlib/documentation.rs +++ b/crates/ovsm/src/tools/stdlib/documentation.rs @@ -16,8 +16,12 @@ use crate::tools::{Tool, ToolRegistry}; /// DOCUMENTATION - Get documentation string pub struct DocumentationTool; impl Tool for DocumentationTool { - fn name(&self) -> &str { "DOCUMENTATION" } - fn description(&self) -> &str { "Get documentation string for object" } + fn name(&self) -> &str { + "DOCUMENTATION" + } + fn description(&self) -> &str { + "Get documentation string for object" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -30,7 +34,8 @@ impl Tool for DocumentationTool { if !matches!(args[1], Value::String(_)) { return Err(Error::InvalidArguments { tool: "DOCUMENTATION".to_string(), - reason: "doc-type (arg 2) must be a string (FUNCTION, VARIABLE, TYPE, etc.)".to_string(), + reason: "doc-type (arg 2) must be a string (FUNCTION, VARIABLE, TYPE, etc.)" + .to_string(), }); } @@ -43,13 +48,18 @@ impl Tool for DocumentationTool { /// SET-DOCUMENTATION - Set documentation string pub struct SetDocumentationTool; impl Tool for SetDocumentationTool { - fn name(&self) -> &str { "SET-DOCUMENTATION" } - fn description(&self) -> &str { "Set documentation string for object" } + fn name(&self) -> &str { + "SET-DOCUMENTATION" + } + fn description(&self) -> &str { + "Set documentation string for object" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 3 { return Err(Error::InvalidArguments { tool: "SET-DOCUMENTATION".to_string(), - reason: "Expected 3 arguments: object, doc-type, and documentation string".to_string(), + reason: "Expected 3 arguments: object, doc-type, and documentation string" + .to_string(), }); } @@ -77,8 +87,12 @@ impl Tool for SetDocumentationTool { /// FUNCTION-DOCUMENTATION - Get function documentation pub struct FunctionDocumentationTool; impl Tool for FunctionDocumentationTool { - fn name(&self) -> &str { "FUNCTION-DOCUMENTATION" } - fn description(&self) -> &str { "Get function documentation" } + fn name(&self) -> &str { + "FUNCTION-DOCUMENTATION" + } + fn description(&self) -> &str { + "Get function documentation" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -102,8 +116,12 @@ impl Tool for FunctionDocumentationTool { /// VARIABLE-DOCUMENTATION - Get variable documentation pub struct VariableDocumentationTool; impl Tool for VariableDocumentationTool { - fn name(&self) -> &str { "VARIABLE-DOCUMENTATION" } - fn description(&self) -> &str { "Get variable documentation" } + fn name(&self) -> &str { + "VARIABLE-DOCUMENTATION" + } + fn description(&self) -> &str { + "Get variable documentation" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -127,8 +145,12 @@ impl Tool for VariableDocumentationTool { /// TYPE-DOCUMENTATION - Get type documentation pub struct TypeDocumentationTool; impl Tool for TypeDocumentationTool { - fn name(&self) -> &str { "TYPE-DOCUMENTATION" } - fn description(&self) -> &str { "Get type documentation" } + fn name(&self) -> &str { + "TYPE-DOCUMENTATION" + } + fn description(&self) -> &str { + "Get type documentation" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { diff --git a/crates/ovsm/src/tools/stdlib/environment.rs b/crates/ovsm/src/tools/stdlib/environment.rs index 9cc1791d5..59853e1e6 100644 --- a/crates/ovsm/src/tools/stdlib/environment.rs +++ b/crates/ovsm/src/tools/stdlib/environment.rs @@ -18,56 +18,96 @@ use std::sync::Arc; /// MACROEXPAND - Expand macro once pub struct MacroexpandTool; impl Tool for MacroexpandTool { - fn name(&self) -> &str { "MACROEXPAND" } - fn description(&self) -> &str { "Expand macro form once" } + fn name(&self) -> &str { + "MACROEXPAND" + } + fn description(&self) -> &str { + "Expand macro form once" + } fn execute(&self, args: &[Value]) -> Result { // Returns (expansion, expanded-p) if args.is_empty() { - return Ok(Value::Array(Arc::new(vec![Value::Null, Value::Bool(false)]))); + return Ok(Value::Array(Arc::new(vec![ + Value::Null, + Value::Bool(false), + ]))); } - Ok(Value::Array(Arc::new(vec![args[0].clone(), Value::Bool(false)]))) + Ok(Value::Array(Arc::new(vec![ + args[0].clone(), + Value::Bool(false), + ]))) } } /// MACROEXPAND-1 - Expand macro one step pub struct Macroexpand1Tool; impl Tool for Macroexpand1Tool { - fn name(&self) -> &str { "MACROEXPAND-1" } - fn description(&self) -> &str { "Expand macro form one step" } + fn name(&self) -> &str { + "MACROEXPAND-1" + } + fn description(&self) -> &str { + "Expand macro form one step" + } fn execute(&self, args: &[Value]) -> Result { // Returns (expansion, expanded-p) if args.is_empty() { - return Ok(Value::Array(Arc::new(vec![Value::Null, Value::Bool(false)]))); + return Ok(Value::Array(Arc::new(vec![ + Value::Null, + Value::Bool(false), + ]))); } - Ok(Value::Array(Arc::new(vec![args[0].clone(), Value::Bool(false)]))) + Ok(Value::Array(Arc::new(vec![ + args[0].clone(), + Value::Bool(false), + ]))) } } /// COMPILER-MACROEXPAND - Expand compiler macro pub struct CompilerMacroexpandTool; impl Tool for CompilerMacroexpandTool { - fn name(&self) -> &str { "COMPILER-MACROEXPAND" } - fn description(&self) -> &str { "Expand compiler macro" } + fn name(&self) -> &str { + "COMPILER-MACROEXPAND" + } + fn description(&self) -> &str { + "Expand compiler macro" + } fn execute(&self, args: &[Value]) -> Result { // Returns (expansion, expanded-p) if args.is_empty() { - return Ok(Value::Array(Arc::new(vec![Value::Null, Value::Bool(false)]))); + return Ok(Value::Array(Arc::new(vec![ + Value::Null, + Value::Bool(false), + ]))); } - Ok(Value::Array(Arc::new(vec![args[0].clone(), Value::Bool(false)]))) + Ok(Value::Array(Arc::new(vec![ + args[0].clone(), + Value::Bool(false), + ]))) } } /// COMPILER-MACROEXPAND-1 - Expand compiler macro one step pub struct CompilerMacroexpand1Tool; impl Tool for CompilerMacroexpand1Tool { - fn name(&self) -> &str { "COMPILER-MACROEXPAND-1" } - fn description(&self) -> &str { "Expand compiler macro one step" } + fn name(&self) -> &str { + "COMPILER-MACROEXPAND-1" + } + fn description(&self) -> &str { + "Expand compiler macro one step" + } fn execute(&self, args: &[Value]) -> Result { // Returns (expansion, expanded-p) if args.is_empty() { - return Ok(Value::Array(Arc::new(vec![Value::Null, Value::Bool(false)]))); + return Ok(Value::Array(Arc::new(vec![ + Value::Null, + Value::Bool(false), + ]))); } - Ok(Value::Array(Arc::new(vec![args[0].clone(), Value::Bool(false)]))) + Ok(Value::Array(Arc::new(vec![ + args[0].clone(), + Value::Bool(false), + ]))) } } @@ -78,8 +118,12 @@ impl Tool for CompilerMacroexpand1Tool { /// VARIABLE-INFORMATION - Get variable information from environment pub struct VariableInformationTool; impl Tool for VariableInformationTool { - fn name(&self) -> &str { "VARIABLE-INFORMATION" } - fn description(&self) -> &str { "Get variable binding information" } + fn name(&self) -> &str { + "VARIABLE-INFORMATION" + } + fn description(&self) -> &str { + "Get variable binding information" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -108,8 +152,12 @@ impl Tool for VariableInformationTool { /// FUNCTION-INFORMATION - Get function information from environment pub struct FunctionInformationTool; impl Tool for FunctionInformationTool { - fn name(&self) -> &str { "FUNCTION-INFORMATION" } - fn description(&self) -> &str { "Get function binding information" } + fn name(&self) -> &str { + "FUNCTION-INFORMATION" + } + fn description(&self) -> &str { + "Get function binding information" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -138,8 +186,12 @@ impl Tool for FunctionInformationTool { /// DECLARATION-INFORMATION - Get declaration information pub struct DeclarationInformationTool; impl Tool for DeclarationInformationTool { - fn name(&self) -> &str { "DECLARATION-INFORMATION" } - fn description(&self) -> &str { "Get declaration information from environment" } + fn name(&self) -> &str { + "DECLARATION-INFORMATION" + } + fn description(&self) -> &str { + "Get declaration information from environment" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -163,8 +215,12 @@ impl Tool for DeclarationInformationTool { /// AUGMENT-ENVIRONMENT - Create augmented environment pub struct AugmentEnvironmentTool; impl Tool for AugmentEnvironmentTool { - fn name(&self) -> &str { "AUGMENT-ENVIRONMENT" } - fn description(&self) -> &str { "Create environment with additional bindings" } + fn name(&self) -> &str { + "AUGMENT-ENVIRONMENT" + } + fn description(&self) -> &str { + "Create environment with additional bindings" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -189,8 +245,12 @@ impl Tool for AugmentEnvironmentTool { /// PARSE-MACRO - Parse macro lambda list pub struct ParseMacroTool; impl Tool for ParseMacroTool { - fn name(&self) -> &str { "PARSE-MACRO" } - fn description(&self) -> &str { "Parse macro lambda list" } + fn name(&self) -> &str { + "PARSE-MACRO" + } + fn description(&self) -> &str { + "Parse macro lambda list" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -207,8 +267,12 @@ impl Tool for ParseMacroTool { /// ENCLOSE - Create lexical closure pub struct EncloseTool; impl Tool for EncloseTool { - fn name(&self) -> &str { "ENCLOSE" } - fn description(&self) -> &str { "Create lexical closure in environment" } + fn name(&self) -> &str { + "ENCLOSE" + } + fn description(&self) -> &str { + "Create lexical closure in environment" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -228,8 +292,12 @@ impl Tool for EncloseTool { /// DEFINE-DECLARATION - Define new declaration pub struct DefineDeclarationTool; impl Tool for DefineDeclarationTool { - fn name(&self) -> &str { "DEFINE-DECLARATION" } - fn description(&self) -> &str { "Define new declaration type" } + fn name(&self) -> &str { + "DEFINE-DECLARATION" + } + fn description(&self) -> &str { + "Define new declaration type" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -253,8 +321,12 @@ impl Tool for DefineDeclarationTool { /// GET-ENVIRONMENT - Get current environment pub struct GetEnvironmentTool; impl Tool for GetEnvironmentTool { - fn name(&self) -> &str { "GET-ENVIRONMENT" } - fn description(&self) -> &str { "Get current lexical environment" } + fn name(&self) -> &str { + "GET-ENVIRONMENT" + } + fn description(&self) -> &str { + "Get current lexical environment" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - returns current environment Ok(Value::Object(Arc::new(HashMap::new()))) @@ -264,8 +336,12 @@ impl Tool for GetEnvironmentTool { /// ENVIRONMENT-P - Check if environment object pub struct EnvironmentPTool; impl Tool for EnvironmentPTool { - fn name(&self) -> &str { "ENVIRONMENT-P" } - fn description(&self) -> &str { "Check if object is environment" } + fn name(&self) -> &str { + "ENVIRONMENT-P" + } + fn description(&self) -> &str { + "Check if object is environment" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::Object(_)) => Ok(Value::Bool(true)), diff --git a/crates/ovsm/src/tools/stdlib/format.rs b/crates/ovsm/src/tools/stdlib/format.rs index 37c21c3cb..a14f9b614 100644 --- a/crates/ovsm/src/tools/stdlib/format.rs +++ b/crates/ovsm/src/tools/stdlib/format.rs @@ -57,11 +57,7 @@ impl Tool for FormatTool { args[1].as_string()? }; - let format_args = if args.len() > 1 { - &args[1..] - } else { - &[] - }; + let format_args = if args.len() > 1 { &args[1..] } else { &[] }; let result = parse_format(format_string, format_args)?; Ok(Value::String(result)) diff --git a/crates/ovsm/src/tools/stdlib/hash_tables.rs b/crates/ovsm/src/tools/stdlib/hash_tables.rs index b4083484e..92e0087bf 100644 --- a/crates/ovsm/src/tools/stdlib/hash_tables.rs +++ b/crates/ovsm/src/tools/stdlib/hash_tables.rs @@ -387,9 +387,7 @@ impl Tool for HashTablePairsTool { let hash_table = args[0].as_object()?; let pairs: Vec = hash_table .iter() - .map(|(k, v)| { - Value::Array(Arc::new(vec![Value::String(k.clone()), v.clone()])) - }) + .map(|(k, v)| Value::Array(Arc::new(vec![Value::String(k.clone()), v.clone()]))) .collect(); Ok(Value::Array(Arc::new(pairs))) @@ -478,9 +476,7 @@ impl Tool for HashTableToAlistTool { let hash_table = args[0].as_object()?; let alist: Vec = hash_table .iter() - .map(|(k, v)| { - Value::Array(Arc::new(vec![Value::String(k.clone()), v.clone()])) - }) + .map(|(k, v)| Value::Array(Arc::new(vec![Value::String(k.clone()), v.clone()]))) .collect(); Ok(Value::Array(Arc::new(alist))) @@ -545,7 +541,8 @@ impl Tool for CopyHashTableTool { } let hash_table = args[0].as_object()?; - let new_map = hash_table.iter() + let new_map = hash_table + .iter() .map(|(k, v)| (k.clone(), v.clone())) .collect::>(); @@ -761,7 +758,8 @@ impl Tool for HashTableUpdateTool { let key = args[1].as_string()?.to_string(); let value = &args[2]; - let mut new_map = hash_table.iter() + let mut new_map = hash_table + .iter() .map(|(k, v)| (k.clone(), v.clone())) .collect::>(); new_map.insert(key, value.clone()); diff --git a/crates/ovsm/src/tools/stdlib/introspection.rs b/crates/ovsm/src/tools/stdlib/introspection.rs index 7d01b6025..2d5560ac6 100644 --- a/crates/ovsm/src/tools/stdlib/introspection.rs +++ b/crates/ovsm/src/tools/stdlib/introspection.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// APROPOS - Find symbols matching string pub struct AproposTool; impl Tool for AproposTool { - fn name(&self) -> &str { "APROPOS" } - fn description(&self) -> &str { "Find and print symbols matching string" } + fn name(&self) -> &str { + "APROPOS" + } + fn description(&self) -> &str { + "Find and print symbols matching string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -43,8 +47,12 @@ impl Tool for AproposTool { /// APROPOS-LIST - Get list of symbols matching string pub struct AproposListTool; impl Tool for AproposListTool { - fn name(&self) -> &str { "APROPOS-LIST" } - fn description(&self) -> &str { "Get list of symbols matching string" } + fn name(&self) -> &str { + "APROPOS-LIST" + } + fn description(&self) -> &str { + "Get list of symbols matching string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -73,8 +81,12 @@ impl Tool for AproposListTool { /// DESCRIBE - Describe object pub struct DescribeTool; impl Tool for DescribeTool { - fn name(&self) -> &str { "DESCRIBE" } - fn description(&self) -> &str { "Print description of object" } + fn name(&self) -> &str { + "DESCRIBE" + } + fn description(&self) -> &str { + "Print description of object" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -103,8 +115,12 @@ impl Tool for DescribeTool { /// DESCRIBE-OBJECT - Describe object with details pub struct DescribeObjectTool; impl Tool for DescribeObjectTool { - fn name(&self) -> &str { "DESCRIBE-OBJECT" } - fn description(&self) -> &str { "Describe object with full details" } + fn name(&self) -> &str { + "DESCRIBE-OBJECT" + } + fn description(&self) -> &str { + "Describe object with full details" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -114,19 +130,22 @@ impl Tool for DescribeObjectTool { } println!("Object: {}", args[0]); - println!("Type: {}", match &args[0] { - Value::Null => "NULL", - Value::Bool(_) => "BOOLEAN", - Value::Int(_) => "INTEGER", - Value::Float(_) => "FLOAT", - Value::String(_) => "STRING", - Value::Array(_) => "ARRAY", - Value::Object(_) => "OBJECT", - Value::Range { .. } => "RANGE", - Value::Function { .. } => "FUNCTION", - Value::Multiple(_) => "MULTIPLE", - Value::Macro { .. } => "MACRO", - }); + println!( + "Type: {}", + match &args[0] { + Value::Null => "NULL", + Value::Bool(_) => "BOOLEAN", + Value::Int(_) => "INTEGER", + Value::Float(_) => "FLOAT", + Value::String(_) => "STRING", + Value::Array(_) => "ARRAY", + Value::Object(_) => "OBJECT", + Value::Range { .. } => "RANGE", + Value::Function { .. } => "FUNCTION", + Value::Multiple(_) => "MULTIPLE", + Value::Macro { .. } => "MACRO", + } + ); Ok(Value::Null) } } @@ -138,8 +157,12 @@ impl Tool for DescribeObjectTool { /// INSPECT - Interactively inspect object pub struct InspectTool; impl Tool for InspectTool { - fn name(&self) -> &str { "INSPECT" } - fn description(&self) -> &str { "Interactively inspect object" } + fn name(&self) -> &str { + "INSPECT" + } + fn description(&self) -> &str { + "Interactively inspect object" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -150,19 +173,22 @@ impl Tool for InspectTool { println!("=== INSPECT ==="); println!("Value: {}", args[0]); - println!("Type: {}", match &args[0] { - Value::Null => "NULL", - Value::Bool(_) => "BOOLEAN", - Value::Int(_) => "INTEGER", - Value::Float(_) => "FLOAT", - Value::String(_) => "STRING", - Value::Array(_) => "ARRAY", - Value::Object(_) => "OBJECT", - Value::Range { .. } => "RANGE", - Value::Function { .. } => "FUNCTION", - Value::Multiple(_) => "MULTIPLE", - Value::Macro { .. } => "MACRO", - }); + println!( + "Type: {}", + match &args[0] { + Value::Null => "NULL", + Value::Bool(_) => "BOOLEAN", + Value::Int(_) => "INTEGER", + Value::Float(_) => "FLOAT", + Value::String(_) => "STRING", + Value::Array(_) => "ARRAY", + Value::Object(_) => "OBJECT", + Value::Range { .. } => "RANGE", + Value::Function { .. } => "FUNCTION", + Value::Multiple(_) => "MULTIPLE", + Value::Macro { .. } => "MACRO", + } + ); Ok(Value::Null) } } @@ -174,8 +200,12 @@ impl Tool for InspectTool { /// CLASS-OF - Get class of object pub struct ClassOfTool; impl Tool for ClassOfTool { - fn name(&self) -> &str { "CLASS-OF" } - fn description(&self) -> &str { "Get class of object" } + fn name(&self) -> &str { + "CLASS-OF" + } + fn description(&self) -> &str { + "Get class of object" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::String("NULL".to_string())); @@ -202,8 +232,12 @@ impl Tool for ClassOfTool { /// FIND-CLASS - Find class by name pub struct FindClassTool; impl Tool for FindClassTool { - fn name(&self) -> &str { "FIND-CLASS" } - fn description(&self) -> &str { "Find class by name" } + fn name(&self) -> &str { + "FIND-CLASS" + } + fn description(&self) -> &str { + "Find class by name" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -227,8 +261,12 @@ impl Tool for FindClassTool { /// CLASS-NAME - Get name of class pub struct ClassNameTool; impl Tool for ClassNameTool { - fn name(&self) -> &str { "CLASS-NAME" } - fn description(&self) -> &str { "Get name of class" } + fn name(&self) -> &str { + "CLASS-NAME" + } + fn description(&self) -> &str { + "Get name of class" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -248,8 +286,12 @@ impl Tool for ClassNameTool { /// SLOT-VALUE - Get slot value pub struct SlotValueTool; impl Tool for SlotValueTool { - fn name(&self) -> &str { "SLOT-VALUE" } - fn description(&self) -> &str { "Get value of object slot" } + fn name(&self) -> &str { + "SLOT-VALUE" + } + fn description(&self) -> &str { + "Get value of object slot" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -281,8 +323,12 @@ impl Tool for SlotValueTool { /// SLOT-BOUNDP - Check if slot is bound pub struct SlotBoundpTool; impl Tool for SlotBoundpTool { - fn name(&self) -> &str { "SLOT-BOUNDP" } - fn description(&self) -> &str { "Check if slot is bound" } + fn name(&self) -> &str { + "SLOT-BOUNDP" + } + fn description(&self) -> &str { + "Check if slot is bound" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -314,8 +360,12 @@ impl Tool for SlotBoundpTool { /// SLOT-MAKUNBOUND - Make slot unbound pub struct SlotMakunboundTool; impl Tool for SlotMakunboundTool { - fn name(&self) -> &str { "SLOT-MAKUNBOUND" } - fn description(&self) -> &str { "Make slot unbound" } + fn name(&self) -> &str { + "SLOT-MAKUNBOUND" + } + fn description(&self) -> &str { + "Make slot unbound" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -347,8 +397,12 @@ impl Tool for SlotMakunboundTool { /// SLOT-EXISTS-P - Check if slot exists pub struct SlotExistsPTool; impl Tool for SlotExistsPTool { - fn name(&self) -> &str { "SLOT-EXISTS-P" } - fn description(&self) -> &str { "Check if slot exists in object" } + fn name(&self) -> &str { + "SLOT-EXISTS-P" + } + fn description(&self) -> &str { + "Check if slot exists in object" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -380,8 +434,12 @@ impl Tool for SlotExistsPTool { /// CLASS-SLOTS - Get list of class slots pub struct ClassSlotsTool; impl Tool for ClassSlotsTool { - fn name(&self) -> &str { "CLASS-SLOTS" } - fn description(&self) -> &str { "Get list of slots in class" } + fn name(&self) -> &str { + "CLASS-SLOTS" + } + fn description(&self) -> &str { + "Get list of slots in class" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { diff --git a/crates/ovsm/src/tools/stdlib/io_basic.rs b/crates/ovsm/src/tools/stdlib/io_basic.rs index b8022e2e4..555a4e6d3 100644 --- a/crates/ovsm/src/tools/stdlib/io_basic.rs +++ b/crates/ovsm/src/tools/stdlib/io_basic.rs @@ -354,10 +354,13 @@ impl Tool for ReadCharTool { let input = args[0].as_string()?; // Get first character - let ch = input.chars().next().ok_or_else(|| Error::InvalidArguments { - tool: "READ-CHAR".to_string(), - reason: "String is empty".to_string(), - })?; + let ch = input + .chars() + .next() + .ok_or_else(|| Error::InvalidArguments { + tool: "READ-CHAR".to_string(), + reason: "String is empty".to_string(), + })?; Ok(Value::String(ch.to_string())) } @@ -416,12 +419,11 @@ impl Tool for WithOpenFileTool { let content = match mode { "r" | "read" => { // Read mode - let content = std::fs::read_to_string(filename).map_err(|e| { - Error::InvalidArguments { + let content = + std::fs::read_to_string(filename).map_err(|e| Error::InvalidArguments { tool: "WITH-OPEN-FILE".to_string(), reason: format!("Failed to read file: {}", e), - } - })?; + })?; Ok(Value::String(content)) } "w" | "write" => { diff --git a/crates/ovsm/src/tools/stdlib/io_extended.rs b/crates/ovsm/src/tools/stdlib/io_extended.rs index 724027023..9cb7f781e 100644 --- a/crates/ovsm/src/tools/stdlib/io_extended.rs +++ b/crates/ovsm/src/tools/stdlib/io_extended.rs @@ -16,8 +16,12 @@ use crate::tools::{Tool, ToolRegistry}; /// READ-BYTE - Read byte from stream pub struct ReadByteTool; impl Tool for ReadByteTool { - fn name(&self) -> &str { "READ-BYTE" } - fn description(&self) -> &str { "Read single byte from binary stream" } + fn name(&self) -> &str { + "READ-BYTE" + } + fn description(&self) -> &str { + "Read single byte from binary stream" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -33,30 +37,54 @@ impl Tool for ReadByteTool { /// WRITE-BYTE - Write byte to stream pub struct WriteByteTool; impl Tool for WriteByteTool { - fn name(&self) -> &str { "WRITE-BYTE" } - fn description(&self) -> &str { "Write single byte to binary stream" } + fn name(&self) -> &str { + "WRITE-BYTE" + } + fn description(&self) -> &str { + "Write single byte to binary stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// READ-SEQUENCE - Read sequence from stream pub struct ReadSequenceTool; impl Tool for ReadSequenceTool { - fn name(&self) -> &str { "READ-SEQUENCE" } - fn description(&self) -> &str { "Read sequence from stream" } + fn name(&self) -> &str { + "READ-SEQUENCE" + } + fn description(&self) -> &str { + "Read sequence from stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(0) } else { Value::Int(0) }) + Ok(if args.is_empty() { + Value::Int(0) + } else { + Value::Int(0) + }) } } /// WRITE-SEQUENCE - Write sequence to stream pub struct WriteSequenceTool; impl Tool for WriteSequenceTool { - fn name(&self) -> &str { "WRITE-SEQUENCE" } - fn description(&self) -> &str { "Write sequence to stream" } + fn name(&self) -> &str { + "WRITE-SEQUENCE" + } + fn description(&self) -> &str { + "Write sequence to stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -67,8 +95,12 @@ impl Tool for WriteSequenceTool { /// FILE-POSITION - Get or set file position pub struct FilePositionTool; impl Tool for FilePositionTool { - fn name(&self) -> &str { "FILE-POSITION" } - fn description(&self) -> &str { "Get or set file position in stream" } + fn name(&self) -> &str { + "FILE-POSITION" + } + fn description(&self) -> &str { + "Get or set file position in stream" + } fn execute(&self, args: &[Value]) -> Result { if args.len() >= 2 { // Setting position @@ -83,8 +115,12 @@ impl Tool for FilePositionTool { /// FILE-LENGTH - Get file length pub struct FileLengthTool; impl Tool for FileLengthTool { - fn name(&self) -> &str { "FILE-LENGTH" } - fn description(&self) -> &str { "Get length of file" } + fn name(&self) -> &str { + "FILE-LENGTH" + } + fn description(&self) -> &str { + "Get length of file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -99,8 +135,12 @@ impl Tool for FileLengthTool { /// FILE-STRING-LENGTH - Get string length in file pub struct FileStringLengthTool; impl Tool for FileStringLengthTool { - fn name(&self) -> &str { "FILE-STRING-LENGTH" } - fn description(&self) -> &str { "Get length string would have in file" } + fn name(&self) -> &str { + "FILE-STRING-LENGTH" + } + fn description(&self) -> &str { + "Get length string would have in file" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -125,8 +165,12 @@ impl Tool for FileStringLengthTool { /// STREAM-ELEMENT-TYPE - Get stream element type pub struct StreamElementTypeTool; impl Tool for StreamElementTypeTool { - fn name(&self) -> &str { "STREAM-ELEMENT-TYPE" } - fn description(&self) -> &str { "Get element type of stream" } + fn name(&self) -> &str { + "STREAM-ELEMENT-TYPE" + } + fn description(&self) -> &str { + "Get element type of stream" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -141,8 +185,12 @@ impl Tool for StreamElementTypeTool { /// INPUT-STREAM-P - Check if input stream pub struct InputStreamPTool; impl Tool for InputStreamPTool { - fn name(&self) -> &str { "INPUT-STREAM-P" } - fn description(&self) -> &str { "Check if stream is input stream" } + fn name(&self) -> &str { + "INPUT-STREAM-P" + } + fn description(&self) -> &str { + "Check if stream is input stream" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -157,8 +205,12 @@ impl Tool for InputStreamPTool { /// OUTPUT-STREAM-P - Check if output stream pub struct OutputStreamPTool; impl Tool for OutputStreamPTool { - fn name(&self) -> &str { "OUTPUT-STREAM-P" } - fn description(&self) -> &str { "Check if stream is output stream" } + fn name(&self) -> &str { + "OUTPUT-STREAM-P" + } + fn description(&self) -> &str { + "Check if stream is output stream" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -173,8 +225,12 @@ impl Tool for OutputStreamPTool { /// INTERACTIVE-STREAM-P - Check if interactive stream pub struct InteractiveStreamPTool; impl Tool for InteractiveStreamPTool { - fn name(&self) -> &str { "INTERACTIVE-STREAM-P" } - fn description(&self) -> &str { "Check if stream is interactive" } + fn name(&self) -> &str { + "INTERACTIVE-STREAM-P" + } + fn description(&self) -> &str { + "Check if stream is interactive" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -189,8 +245,12 @@ impl Tool for InteractiveStreamPTool { /// OPEN-STREAM-P - Check if stream is open pub struct OpenStreamPTool; impl Tool for OpenStreamPTool { - fn name(&self) -> &str { "OPEN-STREAM-P" } - fn description(&self) -> &str { "Check if stream is open" } + fn name(&self) -> &str { + "OPEN-STREAM-P" + } + fn description(&self) -> &str { + "Check if stream is open" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { diff --git a/crates/ovsm/src/tools/stdlib/lists_advanced.rs b/crates/ovsm/src/tools/stdlib/lists_advanced.rs index bf8b461b2..06bf990c8 100644 --- a/crates/ovsm/src/tools/stdlib/lists_advanced.rs +++ b/crates/ovsm/src/tools/stdlib/lists_advanced.rs @@ -311,9 +311,9 @@ impl Tool for TreeEqualTool { } (Value::Object(obj1), Value::Object(obj2)) => { obj1.len() == obj2.len() - && obj1.iter().all(|(k, v1)| { - obj2.get(k).map_or(false, |v2| deep_equal(v1, v2)) - }) + && obj1 + .iter() + .all(|(k, v1)| obj2.get(k).map_or(false, |v2| deep_equal(v1, v2))) } (a, b) => a == b, } @@ -358,7 +358,10 @@ impl Tool for SublisTool { // Recursively process subtrees if let Value::Array(arr) = tree { - let result: Vec = arr.iter().map(|elem| sublis_recursive(alist, elem)).collect(); + let result: Vec = arr + .iter() + .map(|elem| sublis_recursive(alist, elem)) + .collect(); Value::Array(Arc::new(result)) } else { tree.clone() @@ -614,7 +617,10 @@ impl Tool for ListTuplePTool { } // In OVSM, all arrays are proper lists (no circular structures) - Ok(Value::Bool(matches!(&args[0], Value::Array(_) | Value::Null))) + Ok(Value::Bool(matches!( + &args[0], + Value::Array(_) | Value::Null + ))) } } @@ -645,15 +651,13 @@ impl Tool for StableSortTool { let list = args[0].as_array()?; let mut sorted = list.to_vec(); - sorted.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + sorted.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(sorted))) @@ -684,17 +688,15 @@ impl Tool for SortByTool { // Simple sort - just sort by the values themselves let mut sorted = list.to_vec(); - sorted.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + sorted.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(sorted))) } -} \ No newline at end of file +} diff --git a/crates/ovsm/src/tools/stdlib/loop_advanced.rs b/crates/ovsm/src/tools/stdlib/loop_advanced.rs index 642942ad2..7bad75067 100644 --- a/crates/ovsm/src/tools/stdlib/loop_advanced.rs +++ b/crates/ovsm/src/tools/stdlib/loop_advanced.rs @@ -17,38 +17,66 @@ use std::sync::Arc; /// LOOP-DESTRUCTURING - Destructure in LOOP iteration pub struct LoopDestructuringTool; impl Tool for LoopDestructuringTool { - fn name(&self) -> &str { "LOOP-DESTRUCTURING" } - fn description(&self) -> &str { "Destructure values in LOOP" } + fn name(&self) -> &str { + "LOOP-DESTRUCTURING" + } + fn description(&self) -> &str { + "Destructure values in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { + args[0].clone() + }) } } /// LOOP-FOR-ON - Iterate on CDR of list pub struct LoopForOnTool; impl Tool for LoopForOnTool { - fn name(&self) -> &str { "LOOP-FOR-ON" } - fn description(&self) -> &str { "Iterate on successive CDRs" } + fn name(&self) -> &str { + "LOOP-FOR-ON" + } + fn description(&self) -> &str { + "Iterate on successive CDRs" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// LOOP-FOR-EQUALS-THEN - Iterate with explicit update pub struct LoopForEqualsThenTool; impl Tool for LoopForEqualsThenTool { - fn name(&self) -> &str { "LOOP-FOR-EQUALS-THEN" } - fn description(&self) -> &str { "Iterate with = THEN update form" } + fn name(&self) -> &str { + "LOOP-FOR-EQUALS-THEN" + } + fn description(&self) -> &str { + "Iterate with = THEN update form" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// LOOP-FOR-BEING - Hash table and package iteration pub struct LoopForBeingTool; impl Tool for LoopForBeingTool { - fn name(&self) -> &str { "LOOP-FOR-BEING" } - fn description(&self) -> &str { "Iterate over hash tables or packages" } + fn name(&self) -> &str { + "LOOP-FOR-BEING" + } + fn description(&self) -> &str { + "Iterate over hash tables or packages" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -67,18 +95,30 @@ impl Tool for LoopForBeingTool { /// LOOP-INTO - Accumulate into named variable pub struct LoopIntoTool; impl Tool for LoopIntoTool { - fn name(&self) -> &str { "LOOP-INTO" } - fn description(&self) -> &str { "Accumulate into named variable" } + fn name(&self) -> &str { + "LOOP-INTO" + } + fn description(&self) -> &str { + "Accumulate into named variable" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// LOOP-MINIMIZE - Find minimum value pub struct LoopMinimizeTool; impl Tool for LoopMinimizeTool { - fn name(&self) -> &str { "LOOP-MINIMIZE" } - fn description(&self) -> &str { "Accumulate minimum value" } + fn name(&self) -> &str { + "LOOP-MINIMIZE" + } + fn description(&self) -> &str { + "Accumulate minimum value" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -95,7 +135,9 @@ impl Tool for LoopMinimizeTool { match (arg, &min) { (Value::Int(a), Value::Int(b)) if a < b => min = Value::Int(*a), (Value::Float(a), Value::Float(b)) if a < b => min = Value::Float(*a), - (Value::Int(a), Value::Float(b)) if (*a as f64) < *b => min = Value::Float(*a as f64), + (Value::Int(a), Value::Float(b)) if (*a as f64) < *b => { + min = Value::Float(*a as f64) + } (Value::Float(a), Value::Int(b)) if *a < (*b as f64) => min = Value::Float(*a), _ => {} } @@ -107,8 +149,12 @@ impl Tool for LoopMinimizeTool { /// LOOP-APPEND - Append lists pub struct LoopAppendTool; impl Tool for LoopAppendTool { - fn name(&self) -> &str { "LOOP-APPEND" } - fn description(&self) -> &str { "Append accumulated lists" } + fn name(&self) -> &str { + "LOOP-APPEND" + } + fn description(&self) -> &str { + "Append accumulated lists" + } fn execute(&self, args: &[Value]) -> Result { let mut result = vec![]; for arg in args { @@ -124,8 +170,12 @@ impl Tool for LoopAppendTool { /// LOOP-NCONC - Destructively concatenate lists pub struct LoopNconcTool; impl Tool for LoopNconcTool { - fn name(&self) -> &str { "LOOP-NCONC" } - fn description(&self) -> &str { "Destructively concatenate lists" } + fn name(&self) -> &str { + "LOOP-NCONC" + } + fn description(&self) -> &str { + "Destructively concatenate lists" + } fn execute(&self, args: &[Value]) -> Result { let mut result = vec![]; for arg in args { @@ -145,16 +195,28 @@ impl Tool for LoopNconcTool { /// LOOP-IF-IT - IF with IT binding pub struct LoopIfItTool; impl Tool for LoopIfItTool { - fn name(&self) -> &str { "LOOP-IF-IT" } - fn description(&self) -> &str { "IF clause with IT variable" } + fn name(&self) -> &str { + "LOOP-IF-IT" + } + fn description(&self) -> &str { + "IF clause with IT variable" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); } if args[0].is_truthy() { - Ok(if args.len() > 1 { args[1].clone() } else { args[0].clone() }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + args[0].clone() + }) } else { - Ok(if args.len() > 2 { args[2].clone() } else { Value::Null }) + Ok(if args.len() > 2 { + args[2].clone() + } else { + Value::Null + }) } } } @@ -162,8 +224,12 @@ impl Tool for LoopIfItTool { /// LOOP-THEREIS - Test and return pub struct LoopThereisTool; impl Tool for LoopThereisTool { - fn name(&self) -> &str { "LOOP-THEREIS" } - fn description(&self) -> &str { "Test condition and return if true" } + fn name(&self) -> &str { + "LOOP-THEREIS" + } + fn description(&self) -> &str { + "Test condition and return if true" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if arg.is_truthy() { @@ -177,8 +243,12 @@ impl Tool for LoopThereisTool { /// LOOP-ALWAYS - Test all conditions pub struct LoopAlwaysTool; impl Tool for LoopAlwaysTool { - fn name(&self) -> &str { "LOOP-ALWAYS" } - fn description(&self) -> &str { "Return true if all conditions true" } + fn name(&self) -> &str { + "LOOP-ALWAYS" + } + fn description(&self) -> &str { + "Return true if all conditions true" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if !arg.is_truthy() { @@ -192,8 +262,12 @@ impl Tool for LoopAlwaysTool { /// LOOP-NEVER - Test no conditions true pub struct LoopNeverTool; impl Tool for LoopNeverTool { - fn name(&self) -> &str { "LOOP-NEVER" } - fn description(&self) -> &str { "Return true if no conditions true" } + fn name(&self) -> &str { + "LOOP-NEVER" + } + fn description(&self) -> &str { + "Return true if no conditions true" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if arg.is_truthy() { @@ -211,28 +285,48 @@ impl Tool for LoopNeverTool { /// LOOP-NAMED - Named LOOP for RETURN-FROM pub struct LoopNamedTool; impl Tool for LoopNamedTool { - fn name(&self) -> &str { "LOOP-NAMED" } - fn description(&self) -> &str { "Name LOOP for RETURN-FROM" } + fn name(&self) -> &str { + "LOOP-NAMED" + } + fn description(&self) -> &str { + "Name LOOP for RETURN-FROM" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// LOOP-INITIALLY - Execute before LOOP body pub struct LoopInitiallyTool; impl Tool for LoopInitiallyTool { - fn name(&self) -> &str { "LOOP-INITIALLY" } - fn description(&self) -> &str { "Execute forms before loop starts" } + fn name(&self) -> &str { + "LOOP-INITIALLY" + } + fn description(&self) -> &str { + "Execute forms before loop starts" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// LOOP-REPEAT - Repeat fixed number of times pub struct LoopRepeatTool; impl Tool for LoopRepeatTool { - fn name(&self) -> &str { "LOOP-REPEAT" } - fn description(&self) -> &str { "Repeat loop N times" } + fn name(&self) -> &str { + "LOOP-REPEAT" + } + fn description(&self) -> &str { + "Repeat loop N times" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Int(0)); diff --git a/crates/ovsm/src/tools/stdlib/loop_full.rs b/crates/ovsm/src/tools/stdlib/loop_full.rs index f5e25f23d..8c7ffcfc6 100644 --- a/crates/ovsm/src/tools/stdlib/loop_full.rs +++ b/crates/ovsm/src/tools/stdlib/loop_full.rs @@ -17,90 +17,162 @@ use std::sync::Arc; /// LOOP-FOR - FOR iteration clause pub struct LoopForTool; impl Tool for LoopForTool { - fn name(&self) -> &str { "LOOP-FOR" } - fn description(&self) -> &str { "FOR iteration clause in LOOP" } + fn name(&self) -> &str { + "LOOP-FOR" + } + fn description(&self) -> &str { + "FOR iteration clause in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// LOOP-FROM - FROM starting value pub struct LoopFromTool; impl Tool for LoopFromTool { - fn name(&self) -> &str { "LOOP-FROM" } - fn description(&self) -> &str { "FROM starting value in LOOP" } + fn name(&self) -> &str { + "LOOP-FROM" + } + fn description(&self) -> &str { + "FROM starting value in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(0) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(0) + } else { + args[0].clone() + }) } } /// LOOP-TO - TO ending value pub struct LoopToTool; impl Tool for LoopToTool { - fn name(&self) -> &str { "LOOP-TO" } - fn description(&self) -> &str { "TO ending value in LOOP" } + fn name(&self) -> &str { + "LOOP-TO" + } + fn description(&self) -> &str { + "TO ending value in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(10) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(10) + } else { + args[0].clone() + }) } } /// LOOP-BELOW - BELOW upper bound pub struct LoopBelowTool; impl Tool for LoopBelowTool { - fn name(&self) -> &str { "LOOP-BELOW" } - fn description(&self) -> &str { "BELOW upper bound in LOOP" } + fn name(&self) -> &str { + "LOOP-BELOW" + } + fn description(&self) -> &str { + "BELOW upper bound in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(10) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(10) + } else { + args[0].clone() + }) } } /// LOOP-ABOVE - ABOVE lower bound pub struct LoopAboveTool; impl Tool for LoopAboveTool { - fn name(&self) -> &str { "LOOP-ABOVE" } - fn description(&self) -> &str { "ABOVE lower bound in LOOP" } + fn name(&self) -> &str { + "LOOP-ABOVE" + } + fn description(&self) -> &str { + "ABOVE lower bound in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(0) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(0) + } else { + args[0].clone() + }) } } /// LOOP-BY - BY step increment pub struct LoopByTool; impl Tool for LoopByTool { - fn name(&self) -> &str { "LOOP-BY" } - fn description(&self) -> &str { "BY step increment in LOOP" } + fn name(&self) -> &str { + "LOOP-BY" + } + fn description(&self) -> &str { + "BY step increment in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(1) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(1) + } else { + args[0].clone() + }) } } /// LOOP-IN - IN list iteration pub struct LoopInTool; impl Tool for LoopInTool { - fn name(&self) -> &str { "LOOP-IN" } - fn description(&self) -> &str { "IN list iteration in LOOP" } + fn name(&self) -> &str { + "LOOP-IN" + } + fn description(&self) -> &str { + "IN list iteration in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { + args[0].clone() + }) } } /// LOOP-ON - ON list iteration pub struct LoopOnTool; impl Tool for LoopOnTool { - fn name(&self) -> &str { "LOOP-ON" } - fn description(&self) -> &str { "ON list iteration in LOOP" } + fn name(&self) -> &str { + "LOOP-ON" + } + fn description(&self) -> &str { + "ON list iteration in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { + args[0].clone() + }) } } /// LOOP-ACROSS - ACROSS array iteration pub struct LoopAcrossTool; impl Tool for LoopAcrossTool { - fn name(&self) -> &str { "LOOP-ACROSS" } - fn description(&self) -> &str { "ACROSS array iteration in LOOP" } + fn name(&self) -> &str { + "LOOP-ACROSS" + } + fn description(&self) -> &str { + "ACROSS array iteration in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { + args[0].clone() + }) } } @@ -111,50 +183,90 @@ impl Tool for LoopAcrossTool { /// LOOP-WHEN - WHEN conditional pub struct LoopWhenTool; impl Tool for LoopWhenTool { - fn name(&self) -> &str { "LOOP-WHEN" } - fn description(&self) -> &str { "WHEN conditional in LOOP" } + fn name(&self) -> &str { + "LOOP-WHEN" + } + fn description(&self) -> &str { + "WHEN conditional in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } /// LOOP-UNLESS - UNLESS conditional pub struct LoopUnlessTool; impl Tool for LoopUnlessTool { - fn name(&self) -> &str { "LOOP-UNLESS" } - fn description(&self) -> &str { "UNLESS conditional in LOOP" } + fn name(&self) -> &str { + "LOOP-UNLESS" + } + fn description(&self) -> &str { + "UNLESS conditional in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[0].clone() + }) } } /// LOOP-IF - IF conditional pub struct LoopIfTool; impl Tool for LoopIfTool { - fn name(&self) -> &str { "LOOP-IF" } - fn description(&self) -> &str { "IF conditional in LOOP" } + fn name(&self) -> &str { + "LOOP-IF" + } + fn description(&self) -> &str { + "IF conditional in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } /// LOOP-WHILE - WHILE loop condition pub struct LoopWhileTool; impl Tool for LoopWhileTool { - fn name(&self) -> &str { "LOOP-WHILE" } - fn description(&self) -> &str { "WHILE loop condition in LOOP" } + fn name(&self) -> &str { + "LOOP-WHILE" + } + fn description(&self) -> &str { + "WHILE loop condition in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[0].clone() + }) } } /// LOOP-UNTIL - UNTIL loop condition pub struct LoopUntilTool; impl Tool for LoopUntilTool { - fn name(&self) -> &str { "LOOP-UNTIL" } - fn description(&self) -> &str { "UNTIL loop condition in LOOP" } + fn name(&self) -> &str { + "LOOP-UNTIL" + } + fn description(&self) -> &str { + "UNTIL loop condition in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } @@ -165,10 +277,16 @@ impl Tool for LoopUntilTool { /// LOOP-COLLECT - COLLECT values pub struct LoopCollectTool; impl Tool for LoopCollectTool { - fn name(&self) -> &str { "LOOP-COLLECT" } - fn description(&self) -> &str { "COLLECT values in LOOP" } + fn name(&self) -> &str { + "LOOP-COLLECT" + } + fn description(&self) -> &str { + "COLLECT values in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } else { + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { Value::Array(Arc::new(args.to_vec())) }) } @@ -177,8 +295,12 @@ impl Tool for LoopCollectTool { /// LOOP-APPEND - APPEND lists pub struct LoopAppendTool; impl Tool for LoopAppendTool { - fn name(&self) -> &str { "LOOP-APPEND" } - fn description(&self) -> &str { "APPEND lists in LOOP" } + fn name(&self) -> &str { + "LOOP-APPEND" + } + fn description(&self) -> &str { + "APPEND lists in LOOP" + } fn execute(&self, args: &[Value]) -> Result { let mut result = vec![]; for arg in args { @@ -193,8 +315,12 @@ impl Tool for LoopAppendTool { /// LOOP-NCONC - NCONC lists destructively pub struct LoopNconcTool; impl Tool for LoopNconcTool { - fn name(&self) -> &str { "LOOP-NCONC" } - fn description(&self) -> &str { "NCONC lists destructively in LOOP" } + fn name(&self) -> &str { + "LOOP-NCONC" + } + fn description(&self) -> &str { + "NCONC lists destructively in LOOP" + } fn execute(&self, args: &[Value]) -> Result { LoopAppendTool.execute(args) } @@ -203,8 +329,12 @@ impl Tool for LoopNconcTool { /// LOOP-SUM - SUM numbers pub struct LoopSumTool; impl Tool for LoopSumTool { - fn name(&self) -> &str { "LOOP-SUM" } - fn description(&self) -> &str { "SUM numbers in LOOP" } + fn name(&self) -> &str { + "LOOP-SUM" + } + fn description(&self) -> &str { + "SUM numbers in LOOP" + } fn execute(&self, args: &[Value]) -> Result { let mut sum = 0i64; for arg in args { @@ -219,8 +349,12 @@ impl Tool for LoopSumTool { /// LOOP-COUNT - COUNT matching items pub struct LoopCountTool; impl Tool for LoopCountTool { - fn name(&self) -> &str { "LOOP-COUNT" } - fn description(&self) -> &str { "COUNT matching items in LOOP" } + fn name(&self) -> &str { + "LOOP-COUNT" + } + fn description(&self) -> &str { + "COUNT matching items in LOOP" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Int(args.len() as i64)) } @@ -229,8 +363,12 @@ impl Tool for LoopCountTool { /// LOOP-MAXIMIZE - MAXIMIZE value pub struct LoopMaximizeTool; impl Tool for LoopMaximizeTool { - fn name(&self) -> &str { "LOOP-MAXIMIZE" } - fn description(&self) -> &str { "MAXIMIZE value in LOOP" } + fn name(&self) -> &str { + "LOOP-MAXIMIZE" + } + fn description(&self) -> &str { + "MAXIMIZE value in LOOP" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -251,8 +389,12 @@ impl Tool for LoopMaximizeTool { /// LOOP-MINIMIZE - MINIMIZE value pub struct LoopMinimizeTool; impl Tool for LoopMinimizeTool { - fn name(&self) -> &str { "LOOP-MINIMIZE" } - fn description(&self) -> &str { "MINIMIZE value in LOOP" } + fn name(&self) -> &str { + "LOOP-MINIMIZE" + } + fn description(&self) -> &str { + "MINIMIZE value in LOOP" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -277,50 +419,90 @@ impl Tool for LoopMinimizeTool { /// LOOP-DO - DO execute forms pub struct LoopDoTool; impl Tool for LoopDoTool { - fn name(&self) -> &str { "LOOP-DO" } - fn description(&self) -> &str { "DO execute forms in LOOP" } + fn name(&self) -> &str { + "LOOP-DO" + } + fn description(&self) -> &str { + "DO execute forms in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// LOOP-RETURN - RETURN from loop pub struct LoopReturnTool; impl Tool for LoopReturnTool { - fn name(&self) -> &str { "LOOP-RETURN" } - fn description(&self) -> &str { "RETURN from LOOP" } + fn name(&self) -> &str { + "LOOP-RETURN" + } + fn description(&self) -> &str { + "RETURN from LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// LOOP-WITH - WITH variable binding pub struct LoopWithTool; impl Tool for LoopWithTool { - fn name(&self) -> &str { "LOOP-WITH" } - fn description(&self) -> &str { "WITH variable binding in LOOP" } + fn name(&self) -> &str { + "LOOP-WITH" + } + fn description(&self) -> &str { + "WITH variable binding in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() >= 2 { args[1].clone() } else { Value::Null }) + Ok(if args.len() >= 2 { + args[1].clone() + } else { + Value::Null + }) } } /// LOOP-INITIALLY - INITIALLY execute once pub struct LoopInitiallyTool; impl Tool for LoopInitiallyTool { - fn name(&self) -> &str { "LOOP-INITIALLY" } - fn description(&self) -> &str { "INITIALLY execute once in LOOP" } + fn name(&self) -> &str { + "LOOP-INITIALLY" + } + fn description(&self) -> &str { + "INITIALLY execute once in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// LOOP-FINALLY - FINALLY execute at end pub struct LoopFinallyTool; impl Tool for LoopFinallyTool { - fn name(&self) -> &str { "LOOP-FINALLY" } - fn description(&self) -> &str { "FINALLY execute at end in LOOP" } + fn name(&self) -> &str { + "LOOP-FINALLY" + } + fn description(&self) -> &str { + "FINALLY execute at end in LOOP" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } diff --git a/crates/ovsm/src/tools/stdlib/method_combinations.rs b/crates/ovsm/src/tools/stdlib/method_combinations.rs index e4f9c51d2..63c1b2d6d 100644 --- a/crates/ovsm/src/tools/stdlib/method_combinations.rs +++ b/crates/ovsm/src/tools/stdlib/method_combinations.rs @@ -17,18 +17,30 @@ use std::sync::Arc; /// DEFINE-METHOD-COMBINATION - Define method combination type pub struct DefineMethodCombinationTool; impl Tool for DefineMethodCombinationTool { - fn name(&self) -> &str { "DEFINE-METHOD-COMBINATION" } - fn description(&self) -> &str { "Define new method combination type" } + fn name(&self) -> &str { + "DEFINE-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "Define new method combination type" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// METHOD-COMBINATION-NAME - Get method combination name pub struct MethodCombinationNameTool; impl Tool for MethodCombinationNameTool { - fn name(&self) -> &str { "METHOD-COMBINATION-NAME" } - fn description(&self) -> &str { "Get name of method combination" } + fn name(&self) -> &str { + "METHOD-COMBINATION-NAME" + } + fn description(&self) -> &str { + "Get name of method combination" + } fn execute(&self, args: &[Value]) -> Result { Ok(if args.is_empty() { Value::String("STANDARD".to_string()) @@ -41,8 +53,12 @@ impl Tool for MethodCombinationNameTool { /// METHOD-COMBINATION-TYPE - Get method combination type pub struct MethodCombinationTypeTool; impl Tool for MethodCombinationTypeTool { - fn name(&self) -> &str { "METHOD-COMBINATION-TYPE" } - fn description(&self) -> &str { "Get type of method combination" } + fn name(&self) -> &str { + "METHOD-COMBINATION-TYPE" + } + fn description(&self) -> &str { + "Get type of method combination" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method combination object Ok(Value::String("STANDARD".to_string())) @@ -52,10 +68,18 @@ impl Tool for MethodCombinationTypeTool { /// FIND-METHOD-COMBINATION - Find method combination by name pub struct FindMethodCombinationTool; impl Tool for FindMethodCombinationTool { - fn name(&self) -> &str { "FIND-METHOD-COMBINATION" } - fn description(&self) -> &str { "Find method combination by name" } + fn name(&self) -> &str { + "FIND-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "Find method combination by name" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -66,34 +90,54 @@ impl Tool for FindMethodCombinationTool { /// STANDARD-METHOD-COMBINATION - Standard combination pub struct StandardMethodCombinationTool; impl Tool for StandardMethodCombinationTool { - fn name(&self) -> &str { "STANDARD-METHOD-COMBINATION" } - fn description(&self) -> &str { "Standard method combination (before, primary, after, around)" } + fn name(&self) -> &str { + "STANDARD-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "Standard method combination (before, primary, after, around)" + } fn execute(&self, args: &[Value]) -> Result { // Returns combined result of all applicable methods - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// AND-METHOD-COMBINATION - AND combination pub struct AndMethodCombinationTool; impl Tool for AndMethodCombinationTool { - fn name(&self) -> &str { "AND-METHOD-COMBINATION" } - fn description(&self) -> &str { "AND method combination (short-circuit on NIL)" } + fn name(&self) -> &str { + "AND-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "AND method combination (short-circuit on NIL)" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if !arg.is_truthy() { return Ok(Value::Bool(false)); } } - Ok(if args.is_empty() { Value::Bool(true) } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[args.len() - 1].clone() + }) } } /// OR-METHOD-COMBINATION - OR combination pub struct OrMethodCombinationTool; impl Tool for OrMethodCombinationTool { - fn name(&self) -> &str { "OR-METHOD-COMBINATION" } - fn description(&self) -> &str { "OR method combination (short-circuit on non-NIL)" } + fn name(&self) -> &str { + "OR-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "OR method combination (short-circuit on non-NIL)" + } fn execute(&self, args: &[Value]) -> Result { for arg in args { if arg.is_truthy() { @@ -107,18 +151,30 @@ impl Tool for OrMethodCombinationTool { /// PROGN-METHOD-COMBINATION - PROGN combination pub struct PrognMethodCombinationTool; impl Tool for PrognMethodCombinationTool { - fn name(&self) -> &str { "PROGN-METHOD-COMBINATION" } - fn description(&self) -> &str { "PROGN method combination (call all, return last)" } + fn name(&self) -> &str { + "PROGN-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "PROGN method combination (call all, return last)" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// APPEND-METHOD-COMBINATION - APPEND combination pub struct AppendMethodCombinationTool; impl Tool for AppendMethodCombinationTool { - fn name(&self) -> &str { "APPEND-METHOD-COMBINATION" } - fn description(&self) -> &str { "APPEND method combination (append all results)" } + fn name(&self) -> &str { + "APPEND-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "APPEND method combination (append all results)" + } fn execute(&self, args: &[Value]) -> Result { let mut result = vec![]; for arg in args { @@ -134,8 +190,12 @@ impl Tool for AppendMethodCombinationTool { /// NCONC-METHOD-COMBINATION - NCONC combination pub struct NconcMethodCombinationTool; impl Tool for NconcMethodCombinationTool { - fn name(&self) -> &str { "NCONC-METHOD-COMBINATION" } - fn description(&self) -> &str { "NCONC method combination (destructively append results)" } + fn name(&self) -> &str { + "NCONC-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "NCONC method combination (destructively append results)" + } fn execute(&self, args: &[Value]) -> Result { let mut result = vec![]; for arg in args { @@ -151,8 +211,12 @@ impl Tool for NconcMethodCombinationTool { /// LIST-METHOD-COMBINATION - LIST combination pub struct ListMethodCombinationTool; impl Tool for ListMethodCombinationTool { - fn name(&self) -> &str { "LIST-METHOD-COMBINATION" } - fn description(&self) -> &str { "LIST method combination (collect results in list)" } + fn name(&self) -> &str { + "LIST-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "LIST method combination (collect results in list)" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Array(Arc::new(args.to_vec()))) } @@ -161,8 +225,12 @@ impl Tool for ListMethodCombinationTool { /// MAX-METHOD-COMBINATION - MAX combination pub struct MaxMethodCombinationTool; impl Tool for MaxMethodCombinationTool { - fn name(&self) -> &str { "MAX-METHOD-COMBINATION" } - fn description(&self) -> &str { "MAX method combination (return maximum result)" } + fn name(&self) -> &str { + "MAX-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "MAX method combination (return maximum result)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -175,7 +243,9 @@ impl Tool for MaxMethodCombinationTool { match (arg, &max) { (Value::Int(a), Value::Int(b)) if a > b => max = Value::Int(*a), (Value::Float(a), Value::Float(b)) if a > b => max = Value::Float(*a), - (Value::Int(a), Value::Float(b)) if (*a as f64) > *b => max = Value::Float(*a as f64), + (Value::Int(a), Value::Float(b)) if (*a as f64) > *b => { + max = Value::Float(*a as f64) + } (Value::Float(a), Value::Int(b)) if *a > (*b as f64) => max = Value::Float(*a), _ => {} } @@ -187,8 +257,12 @@ impl Tool for MaxMethodCombinationTool { /// MIN-METHOD-COMBINATION - MIN combination pub struct MinMethodCombinationTool; impl Tool for MinMethodCombinationTool { - fn name(&self) -> &str { "MIN-METHOD-COMBINATION" } - fn description(&self) -> &str { "MIN method combination (return minimum result)" } + fn name(&self) -> &str { + "MIN-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "MIN method combination (return minimum result)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -201,7 +275,9 @@ impl Tool for MinMethodCombinationTool { match (arg, &min) { (Value::Int(a), Value::Int(b)) if a < b => min = Value::Int(*a), (Value::Float(a), Value::Float(b)) if a < b => min = Value::Float(*a), - (Value::Int(a), Value::Float(b)) if (*a as f64) < *b => min = Value::Float(*a as f64), + (Value::Int(a), Value::Float(b)) if (*a as f64) < *b => { + min = Value::Float(*a as f64) + } (Value::Float(a), Value::Int(b)) if *a < (*b as f64) => min = Value::Float(*a), _ => {} } @@ -213,8 +289,12 @@ impl Tool for MinMethodCombinationTool { /// PLUS-METHOD-COMBINATION - + combination pub struct PlusMethodCombinationTool; impl Tool for PlusMethodCombinationTool { - fn name(&self) -> &str { "PLUS-METHOD-COMBINATION" } - fn description(&self) -> &str { "+ method combination (sum all results)" } + fn name(&self) -> &str { + "PLUS-METHOD-COMBINATION" + } + fn description(&self) -> &str { + "+ method combination (sum all results)" + } fn execute(&self, args: &[Value]) -> Result { let mut sum_int: i64 = 0; let mut sum_float: f64 = 0.0; @@ -249,8 +329,12 @@ impl Tool for PlusMethodCombinationTool { /// METHOD-QUALIFIERS - Get method qualifiers pub struct MethodQualifiersTool; impl Tool for MethodQualifiersTool { - fn name(&self) -> &str { "METHOD-QUALIFIERS" } - fn description(&self) -> &str { "Get qualifiers of a method" } + fn name(&self) -> &str { + "METHOD-QUALIFIERS" + } + fn description(&self) -> &str { + "Get qualifiers of a method" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method object Ok(Value::Array(Arc::new(vec![]))) @@ -260,8 +344,12 @@ impl Tool for MethodQualifiersTool { /// PRIMARY-METHOD-P - Check if primary method pub struct PrimaryMethodPTool; impl Tool for PrimaryMethodPTool { - fn name(&self) -> &str { "PRIMARY-METHOD-P" } - fn description(&self) -> &str { "Check if method is primary method" } + fn name(&self) -> &str { + "PRIMARY-METHOD-P" + } + fn description(&self) -> &str { + "Check if method is primary method" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method object Ok(Value::Bool(true)) @@ -271,8 +359,12 @@ impl Tool for PrimaryMethodPTool { /// BEFORE-METHOD-P - Check if before method pub struct BeforeMethodPTool; impl Tool for BeforeMethodPTool { - fn name(&self) -> &str { "BEFORE-METHOD-P" } - fn description(&self) -> &str { "Check if method is :before method" } + fn name(&self) -> &str { + "BEFORE-METHOD-P" + } + fn description(&self) -> &str { + "Check if method is :before method" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method object Ok(Value::Bool(false)) @@ -282,8 +374,12 @@ impl Tool for BeforeMethodPTool { /// AFTER-METHOD-P - Check if after method pub struct AfterMethodPTool; impl Tool for AfterMethodPTool { - fn name(&self) -> &str { "AFTER-METHOD-P" } - fn description(&self) -> &str { "Check if method is :after method" } + fn name(&self) -> &str { + "AFTER-METHOD-P" + } + fn description(&self) -> &str { + "Check if method is :after method" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method object Ok(Value::Bool(false)) @@ -293,8 +389,12 @@ impl Tool for AfterMethodPTool { /// AROUND-METHOD-P - Check if around method pub struct AroundMethodPTool; impl Tool for AroundMethodPTool { - fn name(&self) -> &str { "AROUND-METHOD-P" } - fn description(&self) -> &str { "Check if method is :around method" } + fn name(&self) -> &str { + "AROUND-METHOD-P" + } + fn description(&self) -> &str { + "Check if method is :around method" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept method object Ok(Value::Bool(false)) @@ -304,18 +404,30 @@ impl Tool for AroundMethodPTool { /// CALL-NEXT-METHOD - Call next most specific method pub struct CallNextMethodTool; impl Tool for CallNextMethodTool { - fn name(&self) -> &str { "CALL-NEXT-METHOD" } - fn description(&self) -> &str { "Call next most specific method" } + fn name(&self) -> &str { + "CALL-NEXT-METHOD" + } + fn description(&self) -> &str { + "Call next most specific method" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// NEXT-METHOD-P - Check if next method exists pub struct NextMethodPTool; impl Tool for NextMethodPTool { - fn name(&self) -> &str { "NEXT-METHOD-P" } - fn description(&self) -> &str { "Check if next method exists" } + fn name(&self) -> &str { + "NEXT-METHOD-P" + } + fn description(&self) -> &str { + "Check if next method exists" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::Bool(false)) diff --git a/crates/ovsm/src/tools/stdlib/multiple_values.rs b/crates/ovsm/src/tools/stdlib/multiple_values.rs index 1030f1dff..b42752c3f 100644 --- a/crates/ovsm/src/tools/stdlib/multiple_values.rs +++ b/crates/ovsm/src/tools/stdlib/multiple_values.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// VALUES - Return multiple values pub struct ValuesTool; impl Tool for ValuesTool { - fn name(&self) -> &str { "VALUES" } - fn description(&self) -> &str { "Return multiple values" } + fn name(&self) -> &str { + "VALUES" + } + fn description(&self) -> &str { + "Return multiple values" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Array(Arc::new(args.to_vec()))) } @@ -27,8 +31,12 @@ impl Tool for ValuesTool { /// VALUES-LIST - Return values from list pub struct ValuesListTool; impl Tool for ValuesListTool { - fn name(&self) -> &str { "VALUES-LIST" } - fn description(&self) -> &str { "Return multiple values from list" } + fn name(&self) -> &str { + "VALUES-LIST" + } + fn description(&self) -> &str { + "Return multiple values from list" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -47,19 +55,31 @@ impl Tool for ValuesListTool { /// MULTIPLE-VALUE-BIND - Bind multiple values pub struct MultipleValueBindTool; impl Tool for MultipleValueBindTool { - fn name(&self) -> &str { "MULTIPLE-VALUE-BIND" } - fn description(&self) -> &str { "Bind multiple values to variables" } + fn name(&self) -> &str { + "MULTIPLE-VALUE-BIND" + } + fn description(&self) -> &str { + "Bind multiple values to variables" + } fn execute(&self, args: &[Value]) -> Result { // Simplified: return last form result - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// MULTIPLE-VALUE-LIST - Capture values as list pub struct MultipleValueListTool; impl Tool for MultipleValueListTool { - fn name(&self) -> &str { "MULTIPLE-VALUE-LIST" } - fn description(&self) -> &str { "Capture multiple values as list" } + fn name(&self) -> &str { + "MULTIPLE-VALUE-LIST" + } + fn description(&self) -> &str { + "Capture multiple values as list" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Array(Arc::new(args.to_vec()))) } @@ -68,10 +88,18 @@ impl Tool for MultipleValueListTool { /// MULTIPLE-VALUE-SETQ - Set multiple variables pub struct MultipleValueSetqTool; impl Tool for MultipleValueSetqTool { - fn name(&self) -> &str { "MULTIPLE-VALUE-SETQ" } - fn description(&self) -> &str { "Set multiple variables from values" } + fn name(&self) -> &str { + "MULTIPLE-VALUE-SETQ" + } + fn description(&self) -> &str { + "Set multiple variables from values" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -82,28 +110,48 @@ impl Tool for MultipleValueSetqTool { /// MULTIPLE-VALUE-CALL - Call with multiple values as args pub struct MultipleValueCallTool; impl Tool for MultipleValueCallTool { - fn name(&self) -> &str { "MULTIPLE-VALUE-CALL" } - fn description(&self) -> &str { "Call function with multiple values as arguments" } + fn name(&self) -> &str { + "MULTIPLE-VALUE-CALL" + } + fn description(&self) -> &str { + "Call function with multiple values as arguments" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// MULTIPLE-VALUE-PROG1 - Return first value, evaluate forms pub struct MultipleValueProg1Tool; impl Tool for MultipleValueProg1Tool { - fn name(&self) -> &str { "MULTIPLE-VALUE-PROG1" } - fn description(&self) -> &str { "Return first form's values, evaluate remaining" } + fn name(&self) -> &str { + "MULTIPLE-VALUE-PROG1" + } + fn description(&self) -> &str { + "Return first form's values, evaluate remaining" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// NTH-VALUE - Get nth value pub struct NthValueTool; impl Tool for NthValueTool { - fn name(&self) -> &str { "NTH-VALUE" } - fn description(&self) -> &str { "Get nth value from multiple values" } + fn name(&self) -> &str { + "NTH-VALUE" + } + fn description(&self) -> &str { + "Get nth value from multiple values" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -113,10 +161,12 @@ impl Tool for NthValueTool { } let n = match &args[0] { Value::Int(i) => *i as usize, - _ => return Err(Error::InvalidArguments { - tool: self.name().to_string(), - reason: "First argument must be an integer index".to_string(), - }), + _ => { + return Err(Error::InvalidArguments { + tool: self.name().to_string(), + reason: "First argument must be an integer index".to_string(), + }) + } }; match &args[1] { Value::Array(arr) => Ok(arr.get(n).cloned().unwrap_or(Value::Null)), @@ -132,8 +182,12 @@ impl Tool for NthValueTool { /// VALUES-COUNT - Get number of values pub struct ValuesCountTool; impl Tool for ValuesCountTool { - fn name(&self) -> &str { "VALUES-COUNT" } - fn description(&self) -> &str { "Get number of values returned" } + fn name(&self) -> &str { + "VALUES-COUNT" + } + fn description(&self) -> &str { + "Get number of values returned" + } fn execute(&self, args: &[Value]) -> Result { let count = match args.get(0) { Some(Value::Array(arr)) => arr.len(), @@ -147,8 +201,12 @@ impl Tool for ValuesCountTool { /// EXTRACT-PRIMARY-VALUE - Get primary value only pub struct ExtractPrimaryValueTool; impl Tool for ExtractPrimaryValueTool { - fn name(&self) -> &str { "EXTRACT-PRIMARY-VALUE" } - fn description(&self) -> &str { "Extract only primary value, discard rest" } + fn name(&self) -> &str { + "EXTRACT-PRIMARY-VALUE" + } + fn description(&self) -> &str { + "Extract only primary value, discard rest" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::Array(arr)) => Ok(arr.first().cloned().unwrap_or(Value::Null)), @@ -165,10 +223,18 @@ impl Tool for ExtractPrimaryValueTool { /// DESTRUCTURING-BIND - Destructure and bind values pub struct DestructuringBindTool; impl Tool for DestructuringBindTool { - fn name(&self) -> &str { "DESTRUCTURING-BIND" } - fn description(&self) -> &str { "Destructure list and bind to pattern" } + fn name(&self) -> &str { + "DESTRUCTURING-BIND" + } + fn description(&self) -> &str { + "Destructure list and bind to pattern" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } @@ -179,8 +245,12 @@ impl Tool for DestructuringBindTool { /// GETF - Get property from plist pub struct GetfTool; impl Tool for GetfTool { - fn name(&self) -> &str { "GETF" } - fn description(&self) -> &str { "Get property value from property list" } + fn name(&self) -> &str { + "GETF" + } + fn description(&self) -> &str { + "Get property value from property list" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -210,8 +280,12 @@ impl Tool for GetfTool { /// REMF - Remove property from plist pub struct RemfTool; impl Tool for RemfTool { - fn name(&self) -> &str { "REMF" } - fn description(&self) -> &str { "Remove property from property list" } + fn name(&self) -> &str { + "REMF" + } + fn description(&self) -> &str { + "Remove property from property list" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(!args.is_empty())) } @@ -220,8 +294,12 @@ impl Tool for RemfTool { /// GET-PROPERTIES - Get first matching property pub struct GetPropertiesTool; impl Tool for GetPropertiesTool { - fn name(&self) -> &str { "GET-PROPERTIES" } - fn description(&self) -> &str { "Get first property matching indicator list" } + fn name(&self) -> &str { + "GET-PROPERTIES" + } + fn description(&self) -> &str { + "Get first property matching indicator list" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -245,16 +323,20 @@ impl Tool for GetPropertiesTool { /// GET-SETF-EXPANSION - Get setf expansion pub struct GetSetfExpansionTool; impl Tool for GetSetfExpansionTool { - fn name(&self) -> &str { "GET-SETF-EXPANSION" } - fn description(&self) -> &str { "Get setf expansion for place" } + fn name(&self) -> &str { + "GET-SETF-EXPANSION" + } + fn description(&self) -> &str { + "Get setf expansion for place" + } fn execute(&self, args: &[Value]) -> Result { // Return 5 values: vars, vals, stores, writer, reader Ok(Value::Array(Arc::new(vec![ - Value::Array(Arc::new(vec![])), // vars - Value::Array(Arc::new(vec![])), // vals - Value::Array(Arc::new(vec![])), // stores - args.get(0).cloned().unwrap_or(Value::Null), // writer - args.get(0).cloned().unwrap_or(Value::Null), // reader + Value::Array(Arc::new(vec![])), // vars + Value::Array(Arc::new(vec![])), // vals + Value::Array(Arc::new(vec![])), // stores + args.get(0).cloned().unwrap_or(Value::Null), // writer + args.get(0).cloned().unwrap_or(Value::Null), // reader ]))) } } @@ -262,20 +344,36 @@ impl Tool for GetSetfExpansionTool { /// DEFINE-SETF-EXPANDER - Define setf expander pub struct DefineSetfExpanderTool; impl Tool for DefineSetfExpanderTool { - fn name(&self) -> &str { "DEFINE-SETF-EXPANDER" } - fn description(&self) -> &str { "Define setf expander for access form" } + fn name(&self) -> &str { + "DEFINE-SETF-EXPANDER" + } + fn description(&self) -> &str { + "Define setf expander for access form" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DEFSETF - Define simple setf method pub struct DefsetfTool; impl Tool for DefsetfTool { - fn name(&self) -> &str { "DEFSETF" } - fn description(&self) -> &str { "Define simple setf method" } + fn name(&self) -> &str { + "DEFSETF" + } + fn description(&self) -> &str { + "Define simple setf method" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -286,18 +384,30 @@ impl Tool for DefsetfTool { /// SHIFTF - Shift values through places pub struct ShiftfTool; impl Tool for ShiftfTool { - fn name(&self) -> &str { "SHIFTF" } - fn description(&self) -> &str { "Shift values through places, return first" } + fn name(&self) -> &str { + "SHIFTF" + } + fn description(&self) -> &str { + "Shift values through places, return first" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// ROTATEF - Rotate values through places pub struct RotatefTool; impl Tool for RotatefTool { - fn name(&self) -> &str { "ROTATEF" } - fn description(&self) -> &str { "Rotate values through places" } + fn name(&self) -> &str { + "ROTATEF" + } + fn description(&self) -> &str { + "Rotate values through places" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -306,8 +416,12 @@ impl Tool for RotatefTool { /// PSETF - Parallel setf pub struct PsetfTool; impl Tool for PsetfTool { - fn name(&self) -> &str { "PSETF" } - fn description(&self) -> &str { "Set multiple places in parallel" } + fn name(&self) -> &str { + "PSETF" + } + fn description(&self) -> &str { + "Set multiple places in parallel" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -320,18 +434,30 @@ impl Tool for PsetfTool { /// SETF - Set place value pub struct SetfTool; impl Tool for SetfTool { - fn name(&self) -> &str { "SETF" } - fn description(&self) -> &str { "Set place to new value" } + fn name(&self) -> &str { + "SETF" + } + fn description(&self) -> &str { + "Set place to new value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// PSETQ - Parallel setq pub struct PsetqTool; impl Tool for PsetqTool { - fn name(&self) -> &str { "PSETQ" } - fn description(&self) -> &str { "Set multiple variables in parallel" } + fn name(&self) -> &str { + "PSETQ" + } + fn description(&self) -> &str { + "Set multiple variables in parallel" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -340,8 +466,12 @@ impl Tool for PsetqTool { /// INCF - Increment place pub struct IncfTool; impl Tool for IncfTool { - fn name(&self) -> &str { "INCF" } - fn description(&self) -> &str { "Increment place value" } + fn name(&self) -> &str { + "INCF" + } + fn description(&self) -> &str { + "Increment place value" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Int(0)); @@ -366,8 +496,12 @@ impl Tool for IncfTool { /// DECF - Decrement place pub struct DecfTool; impl Tool for DecfTool { - fn name(&self) -> &str { "DECF" } - fn description(&self) -> &str { "Decrement place value" } + fn name(&self) -> &str { + "DECF" + } + fn description(&self) -> &str { + "Decrement place value" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Int(0)); @@ -392,8 +526,12 @@ impl Tool for DecfTool { /// PUSH - Push onto list place pub struct PushTool; impl Tool for PushTool { - fn name(&self) -> &str { "PUSH" } - fn description(&self) -> &str { "Push item onto list place" } + fn name(&self) -> &str { + "PUSH" + } + fn description(&self) -> &str { + "Push item onto list place" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Array(Arc::new(vec![]))); @@ -412,8 +550,12 @@ impl Tool for PushTool { /// POP - Pop from list place pub struct PopTool; impl Tool for PopTool { - fn name(&self) -> &str { "POP" } - fn description(&self) -> &str { "Pop item from list place" } + fn name(&self) -> &str { + "POP" + } + fn description(&self) -> &str { + "Pop item from list place" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); @@ -428,8 +570,12 @@ impl Tool for PopTool { /// PUSHNEW - Push if not already present pub struct PushnewTool; impl Tool for PushnewTool { - fn name(&self) -> &str { "PUSHNEW" } - fn description(&self) -> &str { "Push item if not already in list" } + fn name(&self) -> &str { + "PUSHNEW" + } + fn description(&self) -> &str { + "Push item if not already in list" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Array(Arc::new(vec![]))); @@ -456,20 +602,36 @@ impl Tool for PushnewTool { /// DEFINE-MODIFY-MACRO - Define modify macro pub struct DefineModifyMacroTool; impl Tool for DefineModifyMacroTool { - fn name(&self) -> &str { "DEFINE-MODIFY-MACRO" } - fn description(&self) -> &str { "Define modify macro for place" } + fn name(&self) -> &str { + "DEFINE-MODIFY-MACRO" + } + fn description(&self) -> &str { + "Define modify macro for place" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DEFMACRO-WITH-PLACE - Define macro with place handling pub struct DefmacroWithPlaceTool; impl Tool for DefmacroWithPlaceTool { - fn name(&self) -> &str { "DEFMACRO-WITH-PLACE" } - fn description(&self) -> &str { "Define macro with generalized place handling" } + fn name(&self) -> &str { + "DEFMACRO-WITH-PLACE" + } + fn description(&self) -> &str { + "Define macro with generalized place handling" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -480,20 +642,36 @@ impl Tool for DefmacroWithPlaceTool { /// APPLY-KEY - Apply key function if provided pub struct ApplyKeyTool; impl Tool for ApplyKeyTool { - fn name(&self) -> &str { "APPLY-KEY" } - fn description(&self) -> &str { "Apply key function if provided" } + fn name(&self) -> &str { + "APPLY-KEY" + } + fn description(&self) -> &str { + "Apply key function if provided" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// IDENTITY - Return argument unchanged pub struct IdentityTool; impl Tool for IdentityTool { - fn name(&self) -> &str { "IDENTITY" } - fn description(&self) -> &str { "Return argument unchanged" } + fn name(&self) -> &str { + "IDENTITY" + } + fn description(&self) -> &str { + "Return argument unchanged" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } diff --git a/crates/ovsm/src/tools/stdlib/numeric.rs b/crates/ovsm/src/tools/stdlib/numeric.rs index ced7ec512..a7d38accc 100644 --- a/crates/ovsm/src/tools/stdlib/numeric.rs +++ b/crates/ovsm/src/tools/stdlib/numeric.rs @@ -478,10 +478,8 @@ impl Tool for CoerceTool { "LIST" | "ARRAY" => match &args[0] { Value::Array(_) => Ok(args[0].clone()), Value::String(s) => { - let chars: Vec = s - .chars() - .map(|c| Value::String(c.to_string())) - .collect(); + let chars: Vec = + s.chars().map(|c| Value::String(c.to_string())).collect(); Ok(Value::array(chars)) } _ => Err(Error::TypeError { @@ -677,11 +675,7 @@ impl Tool for IncfTool { }); } - let delta = if args.len() > 1 { - args[1].as_int()? - } else { - 1 - }; + let delta = if args.len() > 1 { args[1].as_int()? } else { 1 }; match &args[0] { Value::Int(n) => Ok(Value::Int(n + delta)), @@ -714,11 +708,7 @@ impl Tool for DecfTool { }); } - let delta = if args.len() > 1 { - args[1].as_int()? - } else { - 1 - }; + let delta = if args.len() > 1 { args[1].as_int()? } else { 1 }; match &args[0] { Value::Int(n) => Ok(Value::Int(n - delta)), diff --git a/crates/ovsm/src/tools/stdlib/packages.rs b/crates/ovsm/src/tools/stdlib/packages.rs index 3099e2692..c5acfb73b 100644 --- a/crates/ovsm/src/tools/stdlib/packages.rs +++ b/crates/ovsm/src/tools/stdlib/packages.rs @@ -13,29 +13,48 @@ use std::sync::Arc; /// MAKE-PACKAGE - Create package pub struct MakePackageTool; impl Tool for MakePackageTool { - fn name(&self) -> &str { "MAKE-PACKAGE" } - fn description(&self) -> &str { "Create new package" } + fn name(&self) -> &str { + "MAKE-PACKAGE" + } + fn description(&self) -> &str { + "Create new package" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::String("ANONYMOUS-PACKAGE".to_string()) } - else { args[0].clone() }) + Ok(if args.is_empty() { + Value::String("ANONYMOUS-PACKAGE".to_string()) + } else { + args[0].clone() + }) } } /// DEFPACKAGE - Define package pub struct DefpackageTool; impl Tool for DefpackageTool { - fn name(&self) -> &str { "DEFPACKAGE" } - fn description(&self) -> &str { "Define package" } + fn name(&self) -> &str { + "DEFPACKAGE" + } + fn description(&self) -> &str { + "Define package" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DELETE-PACKAGE - Delete package pub struct DeletePackageTool; impl Tool for DeletePackageTool { - fn name(&self) -> &str { "DELETE-PACKAGE" } - fn description(&self) -> &str { "Delete package" } + fn name(&self) -> &str { + "DELETE-PACKAGE" + } + fn description(&self) -> &str { + "Delete package" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -50,21 +69,36 @@ impl Tool for DeletePackageTool { /// FIND-PACKAGE - Find package by name pub struct FindPackageTool; impl Tool for FindPackageTool { - fn name(&self) -> &str { "FIND-PACKAGE" } - fn description(&self) -> &str { "Find package by name" } + fn name(&self) -> &str { + "FIND-PACKAGE" + } + fn description(&self) -> &str { + "Find package by name" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PACKAGE-NAME - Get package name pub struct PackageNameTool; impl Tool for PackageNameTool { - fn name(&self) -> &str { "PACKAGE-NAME" } - fn description(&self) -> &str { "Get package name" } + fn name(&self) -> &str { + "PACKAGE-NAME" + } + fn description(&self) -> &str { + "Get package name" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::String("COMMON-LISP".to_string()) } - else { args[0].clone() }) + Ok(if args.is_empty() { + Value::String("COMMON-LISP".to_string()) + } else { + args[0].clone() + }) } } @@ -73,17 +107,28 @@ macro_rules! simple_package_tool { #[doc = $desc] pub struct $name; impl Tool for $name { - fn name(&self) -> &str { $str } - fn description(&self) -> &str { $desc } + fn name(&self) -> &str { + $str + } + fn description(&self) -> &str { + $desc + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Array(Arc::new(vec![])) } - else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Array(Arc::new(vec![])) + } else { + args[0].clone() + }) } } }; } -simple_package_tool!(PackageNicknamesTo, "PACKAGE-NICKNAMES", "Get package nicknames"); +simple_package_tool!( + PackageNicknamesTo, + "PACKAGE-NICKNAMES", + "Get package nicknames" +); simple_package_tool!(RenamePackageTool, "RENAME-PACKAGE", "Rename package"); simple_package_tool!(InternTool, "INTERN", "Intern symbol in package"); simple_package_tool!(FindSymbolTool, "FIND-SYMBOL", "Find symbol in package"); @@ -91,44 +136,81 @@ simple_package_tool!(UninternTool, "UNINTERN", "Remove symbol from package"); simple_package_tool!(ExportTool, "EXPORT", "Export symbols"); simple_package_tool!(UnexportTool, "UNEXPORT", "Unexport symbols"); simple_package_tool!(ImportTool, "IMPORT", "Import symbols"); -simple_package_tool!(ShadowingImportTool, "SHADOWING-IMPORT", "Import with shadowing"); +simple_package_tool!( + ShadowingImportTool, + "SHADOWING-IMPORT", + "Import with shadowing" +); simple_package_tool!(ShadowTool, "SHADOW", "Shadow symbols"); simple_package_tool!(ListAllPackagesTool, "LIST-ALL-PACKAGES", "Get all packages"); simple_package_tool!(PackageUseListTool, "PACKAGE-USE-LIST", "Get used packages"); -simple_package_tool!(PackageUsedByListTool, "PACKAGE-USED-BY-LIST", "Get packages using this"); -simple_package_tool!(PackageShadowingSymbolsTool, "PACKAGE-SHADOWING-SYMBOLS", "Get shadowing symbols"); +simple_package_tool!( + PackageUsedByListTool, + "PACKAGE-USED-BY-LIST", + "Get packages using this" +); +simple_package_tool!( + PackageShadowingSymbolsTool, + "PACKAGE-SHADOWING-SYMBOLS", + "Get shadowing symbols" +); simple_package_tool!(UsePackageTool, "USE-PACKAGE", "Use another package"); simple_package_tool!(UnusePackageTool, "UNUSE-PACKAGE", "Stop using package"); simple_package_tool!(DoSymbolsTool, "DO-SYMBOLS", "Iterate over symbols"); -simple_package_tool!(DoExternalSymbolsTool, "DO-EXTERNAL-SYMBOLS", "Iterate over external symbols"); -simple_package_tool!(DoAllSymbolsTool, "DO-ALL-SYMBOLS", "Iterate over all symbols"); +simple_package_tool!( + DoExternalSymbolsTool, + "DO-EXTERNAL-SYMBOLS", + "Iterate over external symbols" +); +simple_package_tool!( + DoAllSymbolsTool, + "DO-ALL-SYMBOLS", + "Iterate over all symbols" +); /// PACKAGEP - Check if value is package pub struct PackagepTool; impl Tool for PackagepTool { - fn name(&self) -> &str { "PACKAGEP" } - fn description(&self) -> &str { "Check if value is package" } + fn name(&self) -> &str { + "PACKAGEP" + } + fn description(&self) -> &str { + "Check if value is package" + } fn execute(&self, args: &[Value]) -> Result { - Ok(Value::Bool(!args.is_empty() && matches!(args[0], Value::String(_)))) + Ok(Value::Bool( + !args.is_empty() && matches!(args[0], Value::String(_)), + )) } } /// IN-PACKAGE - Change current package pub struct InPackageTool; impl Tool for InPackageTool { - fn name(&self) -> &str { "IN-PACKAGE" } - fn description(&self) -> &str { "Change current package" } + fn name(&self) -> &str { + "IN-PACKAGE" + } + fn description(&self) -> &str { + "Change current package" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::String("COMMON-LISP-USER".to_string()) } - else { args[0].clone() }) + Ok(if args.is_empty() { + Value::String("COMMON-LISP-USER".to_string()) + } else { + args[0].clone() + }) } } /// SYMBOL-PACKAGE - Get symbol's home package pub struct SymbolPackageTool; impl Tool for SymbolPackageTool { - fn name(&self) -> &str { "SYMBOL-PACKAGE" } - fn description(&self) -> &str { "Get symbol's home package" } + fn name(&self) -> &str { + "SYMBOL-PACKAGE" + } + fn description(&self) -> &str { + "Get symbol's home package" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("COMMON-LISP".to_string())) } @@ -141,18 +223,30 @@ impl Tool for SymbolPackageTool { /// WITH-PACKAGE-ITERATOR - Iterate over package symbols pub struct WithPackageIteratorTool; impl Tool for WithPackageIteratorTool { - fn name(&self) -> &str { "WITH-PACKAGE-ITERATOR" } - fn description(&self) -> &str { "Create package symbol iterator" } + fn name(&self) -> &str { + "WITH-PACKAGE-ITERATOR" + } + fn description(&self) -> &str { + "Create package symbol iterator" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PACKAGE-LOCKED-P - Check if package is locked pub struct PackageLockedPTool; impl Tool for PackageLockedPTool { - fn name(&self) -> &str { "PACKAGE-LOCKED-P" } - fn description(&self) -> &str { "Check if package is locked" } + fn name(&self) -> &str { + "PACKAGE-LOCKED-P" + } + fn description(&self) -> &str { + "Check if package is locked" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -167,28 +261,48 @@ impl Tool for PackageLockedPTool { /// LOCK-PACKAGE - Lock package pub struct LockPackageTool; impl Tool for LockPackageTool { - fn name(&self) -> &str { "LOCK-PACKAGE" } - fn description(&self) -> &str { "Lock package against modifications" } + fn name(&self) -> &str { + "LOCK-PACKAGE" + } + fn description(&self) -> &str { + "Lock package against modifications" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// UNLOCK-PACKAGE - Unlock package pub struct UnlockPackageTool; impl Tool for UnlockPackageTool { - fn name(&self) -> &str { "UNLOCK-PACKAGE" } - fn description(&self) -> &str { "Unlock package" } + fn name(&self) -> &str { + "UNLOCK-PACKAGE" + } + fn description(&self) -> &str { + "Unlock package" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PACKAGE-IMPLEMENTED-BY-LIST - Get implementing packages pub struct PackageImplementedByListTool; impl Tool for PackageImplementedByListTool { - fn name(&self) -> &str { "PACKAGE-IMPLEMENTED-BY-LIST" } - fn description(&self) -> &str { "Get list of packages implementing this package" } + fn name(&self) -> &str { + "PACKAGE-IMPLEMENTED-BY-LIST" + } + fn description(&self) -> &str { + "Get list of packages implementing this package" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -203,8 +317,12 @@ impl Tool for PackageImplementedByListTool { /// PACKAGE-IMPLEMENTS-LIST - Get implemented packages pub struct PackageImplementsListTool; impl Tool for PackageImplementsListTool { - fn name(&self) -> &str { "PACKAGE-IMPLEMENTS-LIST" } - fn description(&self) -> &str { "Get list of packages this package implements" } + fn name(&self) -> &str { + "PACKAGE-IMPLEMENTS-LIST" + } + fn description(&self) -> &str { + "Get list of packages this package implements" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -219,18 +337,30 @@ impl Tool for PackageImplementsListTool { /// ADD-PACKAGE-LOCAL-NICKNAME - Add local nickname pub struct AddPackageLocalNicknameTool; impl Tool for AddPackageLocalNicknameTool { - fn name(&self) -> &str { "ADD-PACKAGE-LOCAL-NICKNAME" } - fn description(&self) -> &str { "Add package-local nickname" } + fn name(&self) -> &str { + "ADD-PACKAGE-LOCAL-NICKNAME" + } + fn description(&self) -> &str { + "Add package-local nickname" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// REMOVE-PACKAGE-LOCAL-NICKNAME - Remove local nickname pub struct RemovePackageLocalNicknameTool; impl Tool for RemovePackageLocalNicknameTool { - fn name(&self) -> &str { "REMOVE-PACKAGE-LOCAL-NICKNAME" } - fn description(&self) -> &str { "Remove package-local nickname" } + fn name(&self) -> &str { + "REMOVE-PACKAGE-LOCAL-NICKNAME" + } + fn description(&self) -> &str { + "Remove package-local nickname" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept nickname and package Ok(Value::Bool(true)) @@ -240,8 +370,12 @@ impl Tool for RemovePackageLocalNicknameTool { /// PACKAGE-LOCAL-NICKNAMES - Get local nicknames pub struct PackageLocalNicknamesTool; impl Tool for PackageLocalNicknamesTool { - fn name(&self) -> &str { "PACKAGE-LOCAL-NICKNAMES" } - fn description(&self) -> &str { "Get package-local nicknames" } + fn name(&self) -> &str { + "PACKAGE-LOCAL-NICKNAMES" + } + fn description(&self) -> &str { + "Get package-local nicknames" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -256,8 +390,12 @@ impl Tool for PackageLocalNicknamesTool { /// PACKAGE-LOCALLY-NICKNAMED-BY-LIST - Get packages using local nickname pub struct PackageLocallyNickedByListTool; impl Tool for PackageLocallyNickedByListTool { - fn name(&self) -> &str { "PACKAGE-LOCALLY-NICKNAMED-BY-LIST" } - fn description(&self) -> &str { "Get packages using this as local nickname" } + fn name(&self) -> &str { + "PACKAGE-LOCALLY-NICKNAMED-BY-LIST" + } + fn description(&self) -> &str { + "Get packages using this as local nickname" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -272,28 +410,48 @@ impl Tool for PackageLocallyNickedByListTool { /// WITH-PACKAGE-LOCK-HELD - Execute with package lock pub struct WithPackageLockHeldTool; impl Tool for WithPackageLockHeldTool { - fn name(&self) -> &str { "WITH-PACKAGE-LOCK-HELD" } - fn description(&self) -> &str { "Execute forms with package lock held" } + fn name(&self) -> &str { + "WITH-PACKAGE-LOCK-HELD" + } + fn description(&self) -> &str { + "Execute forms with package lock held" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// WITHOUT-PACKAGE-LOCKS - Execute without package locks pub struct WithoutPackageLocksTool; impl Tool for WithoutPackageLocksTool { - fn name(&self) -> &str { "WITHOUT-PACKAGE-LOCKS" } - fn description(&self) -> &str { "Execute forms without package lock checking" } + fn name(&self) -> &str { + "WITHOUT-PACKAGE-LOCKS" + } + fn description(&self) -> &str { + "Execute forms without package lock checking" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[args.len() - 1].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[args.len() - 1].clone() + }) } } /// DISABLE-PACKAGE-LOCKS - Disable package locks pub struct DisablePackageLocksTool; impl Tool for DisablePackageLocksTool { - fn name(&self) -> &str { "DISABLE-PACKAGE-LOCKS" } - fn description(&self) -> &str { "Disable package lock checking" } + fn name(&self) -> &str { + "DISABLE-PACKAGE-LOCKS" + } + fn description(&self) -> &str { + "Disable package lock checking" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -308,8 +466,12 @@ impl Tool for DisablePackageLocksTool { /// ENABLE-PACKAGE-LOCKS - Enable package locks pub struct EnablePackageLocksTool; impl Tool for EnablePackageLocksTool { - fn name(&self) -> &str { "ENABLE-PACKAGE-LOCKS" } - fn description(&self) -> &str { "Enable package lock checking" } + fn name(&self) -> &str { + "ENABLE-PACKAGE-LOCKS" + } + fn description(&self) -> &str { + "Enable package lock checking" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -324,8 +486,12 @@ impl Tool for EnablePackageLocksTool { /// PACKAGE-DOCUMENTATION - Get package documentation pub struct PackageDocumentationTool; impl Tool for PackageDocumentationTool { - fn name(&self) -> &str { "PACKAGE-DOCUMENTATION" } - fn description(&self) -> &str { "Get package documentation string" } + fn name(&self) -> &str { + "PACKAGE-DOCUMENTATION" + } + fn description(&self) -> &str { + "Get package documentation string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -340,23 +506,36 @@ impl Tool for PackageDocumentationTool { /// SET-PACKAGE-DOCUMENTATION - Set package documentation pub struct SetPackageDocumentationTool; impl Tool for SetPackageDocumentationTool { - fn name(&self) -> &str { "SET-PACKAGE-DOCUMENTATION" } - fn description(&self) -> &str { "Set package documentation string" } + fn name(&self) -> &str { + "SET-PACKAGE-DOCUMENTATION" + } + fn description(&self) -> &str { + "Set package documentation string" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// DESCRIBE-PACKAGE - Describe package pub struct DescribePackageTool; impl Tool for DescribePackageTool { - fn name(&self) -> &str { "DESCRIBE-PACKAGE" } - fn description(&self) -> &str { "Describe package structure and contents" } + fn name(&self) -> &str { + "DESCRIBE-PACKAGE" + } + fn description(&self) -> &str { + "Describe package structure and contents" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { - Some(Value::String(name)) => { - Ok(Value::String(format!("Package: {}\nNicknames: none\nUse list: (COMMON-LISP)\nUsed by: none\nSymbols: 0", name))) - } + Some(Value::String(name)) => Ok(Value::String(format!( + "Package: {}\nNicknames: none\nUse list: (COMMON-LISP)\nUsed by: none\nSymbols: 0", + name + ))), _ => Ok(Value::String("Package: UNKNOWN".to_string())), } } @@ -365,8 +544,12 @@ impl Tool for DescribePackageTool { /// PACKAGE-APROPOS - Find symbols matching string pub struct PackageAproposTool; impl Tool for PackageAproposTool { - fn name(&self) -> &str { "PACKAGE-APROPOS" } - fn description(&self) -> &str { "Find symbols in package matching string" } + fn name(&self) -> &str { + "PACKAGE-APROPOS" + } + fn description(&self) -> &str { + "Find symbols in package matching string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -381,8 +564,12 @@ impl Tool for PackageAproposTool { /// PACKAGE-APROPOS-LIST - Get list of matching symbols pub struct PackageAproposListTool; impl Tool for PackageAproposListTool { - fn name(&self) -> &str { "PACKAGE-APROPOS-LIST" } - fn description(&self) -> &str { "Get list of symbols matching string" } + fn name(&self) -> &str { + "PACKAGE-APROPOS-LIST" + } + fn description(&self) -> &str { + "Get list of symbols matching string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -397,8 +584,12 @@ impl Tool for PackageAproposListTool { /// PACKAGE-INHERITED-SYMBOLS - Get inherited symbols pub struct PackageInheritedSymbolsTool; impl Tool for PackageInheritedSymbolsTool { - fn name(&self) -> &str { "PACKAGE-INHERITED-SYMBOLS" } - fn description(&self) -> &str { "Get symbols inherited from other packages" } + fn name(&self) -> &str { + "PACKAGE-INHERITED-SYMBOLS" + } + fn description(&self) -> &str { + "Get symbols inherited from other packages" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { diff --git a/crates/ovsm/src/tools/stdlib/pathnames.rs b/crates/ovsm/src/tools/stdlib/pathnames.rs index 9ad410c99..90a5ce331 100644 --- a/crates/ovsm/src/tools/stdlib/pathnames.rs +++ b/crates/ovsm/src/tools/stdlib/pathnames.rs @@ -240,7 +240,9 @@ impl Tool for PathnameDeviceTool { if let Some(prefix) = path.components().next() { use std::path::Component; if let Component::Prefix(prefix) = prefix { - return Ok(Value::String(prefix.as_os_str().to_string_lossy().to_string())); + return Ok(Value::String( + prefix.as_os_str().to_string_lossy().to_string(), + )); } } } diff --git a/crates/ovsm/src/tools/stdlib/printer_control.rs b/crates/ovsm/src/tools/stdlib/printer_control.rs index 9ff22c193..67e668a26 100644 --- a/crates/ovsm/src/tools/stdlib/printer_control.rs +++ b/crates/ovsm/src/tools/stdlib/printer_control.rs @@ -16,8 +16,12 @@ use crate::tools::{Tool, ToolRegistry}; /// PPRINT - Pretty print object pub struct PprintTool; impl Tool for PprintTool { - fn name(&self) -> &str { "PPRINT" } - fn description(&self) -> &str { "Pretty print object" } + fn name(&self) -> &str { + "PPRINT" + } + fn description(&self) -> &str { + "Pretty print object" + } fn execute(&self, args: &[Value]) -> Result { if !args.is_empty() { println!("{}", args[0]); @@ -29,11 +33,15 @@ impl Tool for PprintTool { /// PPRINT-NEWLINE - Pretty print newline pub struct PprintNewlineTool; impl Tool for PprintNewlineTool { - fn name(&self) -> &str { "PPRINT-NEWLINE" } - fn description(&self) -> &str { "Insert conditional newline in pretty printing" } + fn name(&self) -> &str { + "PPRINT-NEWLINE" + } + fn description(&self) -> &str { + "Insert conditional newline in pretty printing" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept kind: :linear, :fill, :miser, :mandatory - // Kind: :linear, :fill, :miser, :mandatory + // Kind: :linear, :fill, :miser, :mandatory println!(); Ok(Value::Null) } @@ -42,11 +50,15 @@ impl Tool for PprintNewlineTool { /// PPRINT-INDENT - Set pretty print indentation pub struct PprintIndentTool; impl Tool for PprintIndentTool { - fn name(&self) -> &str { "PPRINT-INDENT" } - fn description(&self) -> &str { "Set indentation for pretty printing" } + fn name(&self) -> &str { + "PPRINT-INDENT" + } + fn description(&self) -> &str { + "Set indentation for pretty printing" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept kind: :block or :current, plus number - // Kind: :block or :current, plus number + // Kind: :block or :current, plus number Ok(Value::Null) } } @@ -54,8 +66,12 @@ impl Tool for PprintIndentTool { /// PPRINT-TAB - Pretty print tabulation pub struct PprintTabTool; impl Tool for PprintTabTool { - fn name(&self) -> &str { "PPRINT-TAB" } - fn description(&self) -> &str { "Tab to column in pretty printing" } + fn name(&self) -> &str { + "PPRINT-TAB" + } + fn description(&self) -> &str { + "Tab to column in pretty printing" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept column number Ok(Value::Null) @@ -65,18 +81,30 @@ impl Tool for PprintTabTool { /// PPRINT-LOGICAL-BLOCK - Pretty print logical block pub struct PprintLogicalBlockTool; impl Tool for PprintLogicalBlockTool { - fn name(&self) -> &str { "PPRINT-LOGICAL-BLOCK" } - fn description(&self) -> &str { "Create pretty printing logical block" } + fn name(&self) -> &str { + "PPRINT-LOGICAL-BLOCK" + } + fn description(&self) -> &str { + "Create pretty printing logical block" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } /// PPRINT-POP - Pop from pprint list pub struct PprintPopTool; impl Tool for PprintPopTool { - fn name(&self) -> &str { "PPRINT-POP" } - fn description(&self) -> &str { "Pop element from pretty print list" } + fn name(&self) -> &str { + "PPRINT-POP" + } + fn description(&self) -> &str { + "Pop element from pretty print list" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -94,8 +122,12 @@ impl Tool for PprintPopTool { /// PPRINT-EXIT-IF-LIST-EXHAUSTED - Exit if list empty pub struct PprintExitIfListExhaustedTool; impl Tool for PprintExitIfListExhaustedTool { - fn name(&self) -> &str { "PPRINT-EXIT-IF-LIST-EXHAUSTED" } - fn description(&self) -> &str { "Exit pretty print block if list exhausted" } + fn name(&self) -> &str { + "PPRINT-EXIT-IF-LIST-EXHAUSTED" + } + fn description(&self) -> &str { + "Exit pretty print block if list exhausted" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -117,8 +149,12 @@ impl Tool for PprintExitIfListExhaustedTool { /// SET-PPRINT-DISPATCH - Set pretty print dispatch function pub struct SetPprintDispatchTool; impl Tool for SetPprintDispatchTool { - fn name(&self) -> &str { "SET-PPRINT-DISPATCH" } - fn description(&self) -> &str { "Set pretty print dispatch for type" } + fn name(&self) -> &str { + "SET-PPRINT-DISPATCH" + } + fn description(&self) -> &str { + "Set pretty print dispatch for type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept type and dispatch function Ok(Value::Null) @@ -128,8 +164,12 @@ impl Tool for SetPprintDispatchTool { /// PPRINT-DISPATCH - Get pretty print dispatch function pub struct PprintDispatchTool; impl Tool for PprintDispatchTool { - fn name(&self) -> &str { "PPRINT-DISPATCH" } - fn description(&self) -> &str { "Get pretty print dispatch for object" } + fn name(&self) -> &str { + "PPRINT-DISPATCH" + } + fn description(&self) -> &str { + "Get pretty print dispatch for object" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept object Ok(Value::Null) @@ -139,8 +179,12 @@ impl Tool for PprintDispatchTool { /// COPY-PPRINT-DISPATCH - Copy pprint dispatch table pub struct CopyPprintDispatchTool; impl Tool for CopyPprintDispatchTool { - fn name(&self) -> &str { "COPY-PPRINT-DISPATCH" } - fn description(&self) -> &str { "Copy pretty print dispatch table" } + fn name(&self) -> &str { + "COPY-PPRINT-DISPATCH" + } + fn description(&self) -> &str { + "Copy pretty print dispatch table" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept dispatch table Ok(Value::Null) @@ -154,50 +198,90 @@ impl Tool for CopyPprintDispatchTool { /// *PRINT-PRETTY* - Enable pretty printing pub struct PrintPrettyTool; impl Tool for PrintPrettyTool { - fn name(&self) -> &str { "*PRINT-PRETTY*" } - fn description(&self) -> &str { "Control pretty printing" } + fn name(&self) -> &str { + "*PRINT-PRETTY*" + } + fn description(&self) -> &str { + "Control pretty printing" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } /// *PRINT-LEVEL* - Maximum print depth pub struct PrintLevelTool; impl Tool for PrintLevelTool { - fn name(&self) -> &str { "*PRINT-LEVEL*" } - fn description(&self) -> &str { "Maximum nesting level to print" } + fn name(&self) -> &str { + "*PRINT-LEVEL*" + } + fn description(&self) -> &str { + "Maximum nesting level to print" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// *PRINT-LENGTH* - Maximum list length to print pub struct PrintLengthTool; impl Tool for PrintLengthTool { - fn name(&self) -> &str { "*PRINT-LENGTH*" } - fn description(&self) -> &str { "Maximum list length to print" } + fn name(&self) -> &str { + "*PRINT-LENGTH*" + } + fn description(&self) -> &str { + "Maximum list length to print" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// *PRINT-CIRCLE* - Print circular structures pub struct PrintCircleTool; impl Tool for PrintCircleTool { - fn name(&self) -> &str { "*PRINT-CIRCLE*" } - fn description(&self) -> &str { "Detect and print circular structures" } + fn name(&self) -> &str { + "*PRINT-CIRCLE*" + } + fn description(&self) -> &str { + "Detect and print circular structures" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } /// *PRINT-ESCAPE* - Print escape characters pub struct PrintEscapeTool; impl Tool for PrintEscapeTool { - fn name(&self) -> &str { "*PRINT-ESCAPE*" } - fn description(&self) -> &str { "Print escape characters for readability" } + fn name(&self) -> &str { + "*PRINT-ESCAPE*" + } + fn description(&self) -> &str { + "Print escape characters for readability" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[0].clone() + }) } } diff --git a/crates/ovsm/src/tools/stdlib/random_extended.rs b/crates/ovsm/src/tools/stdlib/random_extended.rs index 22a3137f7..13d825ee3 100644 --- a/crates/ovsm/src/tools/stdlib/random_extended.rs +++ b/crates/ovsm/src/tools/stdlib/random_extended.rs @@ -17,11 +17,15 @@ use std::sync::Arc; /// MAKE-RANDOM-STATE - Create random state pub struct MakeRandomStateTool; impl Tool for MakeRandomStateTool { - fn name(&self) -> &str { "MAKE-RANDOM-STATE" } - fn description(&self) -> &str { "Create new random state" } + fn name(&self) -> &str { + "MAKE-RANDOM-STATE" + } + fn description(&self) -> &str { + "Create new random state" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept optional seed or state to copy - // Returns a new random state object + // Returns a new random state object Ok(Value::Int(42)) // Simplified: return seed value } } @@ -29,8 +33,12 @@ impl Tool for MakeRandomStateTool { /// RANDOM-STATE-P - Check if random state pub struct RandomStatePTool; impl Tool for RandomStatePTool { - fn name(&self) -> &str { "RANDOM-STATE-P" } - fn description(&self) -> &str { "Check if object is random state" } + fn name(&self) -> &str { + "RANDOM-STATE-P" + } + fn description(&self) -> &str { + "Check if object is random state" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(matches!(args.get(0), Some(Value::Int(_))))) } @@ -39,10 +47,18 @@ impl Tool for RandomStatePTool { /// *RANDOM-STATE* - Current random state pub struct RandomStateTool; impl Tool for RandomStateTool { - fn name(&self) -> &str { "*RANDOM-STATE*" } - fn description(&self) -> &str { "Current random state" } + fn name(&self) -> &str { + "*RANDOM-STATE*" + } + fn description(&self) -> &str { + "Current random state" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(0) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(0) + } else { + args[0].clone() + }) } } @@ -53,8 +69,12 @@ impl Tool for RandomStateTool { /// RANDOM-FLOAT - Generate random float in range pub struct RandomFloatTool; impl Tool for RandomFloatTool { - fn name(&self) -> &str { "RANDOM-FLOAT" } - fn description(&self) -> &str { "Generate random float between 0.0 and limit" } + fn name(&self) -> &str { + "RANDOM-FLOAT" + } + fn description(&self) -> &str { + "Generate random float between 0.0 and limit" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -65,10 +85,12 @@ impl Tool for RandomFloatTool { let limit = match &args[0] { Value::Float(f) => *f, Value::Int(n) => *n as f64, - _ => return Err(Error::InvalidArguments { - tool: self.name().to_string(), - reason: "Limit must be a number".to_string(), - }), + _ => { + return Err(Error::InvalidArguments { + tool: self.name().to_string(), + reason: "Limit must be a number".to_string(), + }) + } }; // Simplified: return pseudo-random value @@ -79,8 +101,12 @@ impl Tool for RandomFloatTool { /// RANDOM-INTEGER - Generate random integer in range pub struct RandomIntegerTool; impl Tool for RandomIntegerTool { - fn name(&self) -> &str { "RANDOM-INTEGER" } - fn description(&self) -> &str { "Generate random integer between 0 and limit" } + fn name(&self) -> &str { + "RANDOM-INTEGER" + } + fn description(&self) -> &str { + "Generate random integer between 0 and limit" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -90,10 +116,12 @@ impl Tool for RandomIntegerTool { } let limit = match &args[0] { Value::Int(n) => *n, - _ => return Err(Error::InvalidArguments { - tool: self.name().to_string(), - reason: "Limit must be an integer".to_string(), - }), + _ => { + return Err(Error::InvalidArguments { + tool: self.name().to_string(), + reason: "Limit must be an integer".to_string(), + }) + } }; // Simplified: return pseudo-random value @@ -104,8 +132,12 @@ impl Tool for RandomIntegerTool { /// RANDOM-ELEMENT - Get random element from sequence pub struct RandomElementTool; impl Tool for RandomElementTool { - fn name(&self) -> &str { "RANDOM-ELEMENT" } - fn description(&self) -> &str { "Get random element from sequence" } + fn name(&self) -> &str { + "RANDOM-ELEMENT" + } + fn description(&self) -> &str { + "Get random element from sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -134,8 +166,12 @@ impl Tool for RandomElementTool { /// SHUFFLE - Randomly permute sequence pub struct ShuffleTool; impl Tool for ShuffleTool { - fn name(&self) -> &str { "SHUFFLE" } - fn description(&self) -> &str { "Randomly permute sequence" } + fn name(&self) -> &str { + "SHUFFLE" + } + fn description(&self) -> &str { + "Randomly permute sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -162,10 +198,18 @@ impl Tool for ShuffleTool { /// SEED-RANDOM-STATE - Seed random state pub struct SeedRandomStateTool; impl Tool for SeedRandomStateTool { - fn name(&self) -> &str { "SEED-RANDOM-STATE" } - fn description(&self) -> &str { "Seed random state with value" } + fn name(&self) -> &str { + "SEED-RANDOM-STATE" + } + fn description(&self) -> &str { + "Seed random state with value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(0) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(0) + } else { + args[0].clone() + }) } } diff --git a/crates/ovsm/src/tools/stdlib/reader_control.rs b/crates/ovsm/src/tools/stdlib/reader_control.rs index 8d97855af..a087773fa 100644 --- a/crates/ovsm/src/tools/stdlib/reader_control.rs +++ b/crates/ovsm/src/tools/stdlib/reader_control.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// #. - Read-time evaluation pub struct ReadTimeEvalTool; impl Tool for ReadTimeEvalTool { - fn name(&self) -> &str { "#." } - fn description(&self) -> &str { "Evaluate form at read time" } + fn name(&self) -> &str { + "#." + } + fn description(&self) -> &str { + "Evaluate form at read time" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -33,8 +37,12 @@ impl Tool for ReadTimeEvalTool { /// #, - Load-time evaluation pub struct LoadTimeEvalTool; impl Tool for LoadTimeEvalTool { - fn name(&self) -> &str { "#," } - fn description(&self) -> &str { "Evaluate form at load time" } + fn name(&self) -> &str { + "#," + } + fn description(&self) -> &str { + "Evaluate form at load time" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -53,8 +61,12 @@ impl Tool for LoadTimeEvalTool { /// GET-DISPATCH-MACRO-CHARACTER - Get dispatch macro pub struct GetDispatchMacroCharacterTool; impl Tool for GetDispatchMacroCharacterTool { - fn name(&self) -> &str { "GET-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Get dispatch macro character function" } + fn name(&self) -> &str { + "GET-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Get dispatch macro character function" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -70,8 +82,12 @@ impl Tool for GetDispatchMacroCharacterTool { /// SET-DISPATCH-MACRO-CHARACTER - Set dispatch macro pub struct SetDispatchMacroCharacterTool; impl Tool for SetDispatchMacroCharacterTool { - fn name(&self) -> &str { "SET-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Set dispatch macro character function" } + fn name(&self) -> &str { + "SET-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Set dispatch macro character function" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 3 { return Err(Error::InvalidArguments { @@ -86,8 +102,12 @@ impl Tool for SetDispatchMacroCharacterTool { /// MAKE-DISPATCH-MACRO-CHARACTER - Create dispatch character pub struct MakeDispatchMacroCharacterTool; impl Tool for MakeDispatchMacroCharacterTool { - fn name(&self) -> &str { "MAKE-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Make character a dispatch macro character" } + fn name(&self) -> &str { + "MAKE-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Make character a dispatch macro character" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -106,18 +126,30 @@ impl Tool for MakeDispatchMacroCharacterTool { /// *READ-BASE* - Input radix pub struct ReadBaseTool; impl Tool for ReadBaseTool { - fn name(&self) -> &str { "*READ-BASE*" } - fn description(&self) -> &str { "Radix for reading integers" } + fn name(&self) -> &str { + "*READ-BASE*" + } + fn description(&self) -> &str { + "Radix for reading integers" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Int(10) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Int(10) + } else { + args[0].clone() + }) } } /// *READ-DEFAULT-FLOAT-FORMAT* - Default float format pub struct ReadDefaultFloatFormatTool; impl Tool for ReadDefaultFloatFormatTool { - fn name(&self) -> &str { "*READ-DEFAULT-FLOAT-FORMAT*" } - fn description(&self) -> &str { "Default float type for reading" } + fn name(&self) -> &str { + "*READ-DEFAULT-FLOAT-FORMAT*" + } + fn description(&self) -> &str { + "Default float type for reading" + } fn execute(&self, args: &[Value]) -> Result { Ok(if args.is_empty() { Value::String("SINGLE-FLOAT".to_string()) @@ -130,20 +162,36 @@ impl Tool for ReadDefaultFloatFormatTool { /// *READ-EVAL* - Allow #. reader macro pub struct ReadEvalTool; impl Tool for ReadEvalTool { - fn name(&self) -> &str { "*READ-EVAL*" } - fn description(&self) -> &str { "Allow read-time evaluation" } + fn name(&self) -> &str { + "*READ-EVAL*" + } + fn description(&self) -> &str { + "Allow read-time evaluation" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[0].clone() + }) } } /// *READ-SUPPRESS* - Suppress reading pub struct ReadSuppressTool; impl Tool for ReadSuppressTool { - fn name(&self) -> &str { "*READ-SUPPRESS*" } - fn description(&self) -> &str { "Suppress reading and return NIL" } + fn name(&self) -> &str { + "*READ-SUPPRESS*" + } + fn description(&self) -> &str { + "Suppress reading and return NIL" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(false) + } else { + args[0].clone() + }) } } @@ -154,11 +202,15 @@ impl Tool for ReadSuppressTool { /// COPY-READTABLE - Copy readtable pub struct CopyReadtableTool; impl Tool for CopyReadtableTool { - fn name(&self) -> &str { "COPY-READTABLE" } - fn description(&self) -> &str { "Copy readtable" } + fn name(&self) -> &str { + "COPY-READTABLE" + } + fn description(&self) -> &str { + "Copy readtable" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept optional from-readtable and to-readtable args - // Return an Arc-wrapped object representing the readtable + // Return an Arc-wrapped object representing the readtable let readtable = std::collections::HashMap::new(); Ok(Value::Object(Arc::new(readtable))) } @@ -167,8 +219,12 @@ impl Tool for CopyReadtableTool { /// READTABLEP - Check if readtable pub struct ReadtablepTool; impl Tool for ReadtablepTool { - fn name(&self) -> &str { "READTABLEP" } - fn description(&self) -> &str { "Check if object is readtable" } + fn name(&self) -> &str { + "READTABLEP" + } + fn description(&self) -> &str { + "Check if object is readtable" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -184,8 +240,12 @@ impl Tool for ReadtablepTool { /// READTABLE-CASE - Get/set readtable case pub struct ReadtableCaseTool; impl Tool for ReadtableCaseTool { - fn name(&self) -> &str { "READTABLE-CASE" } - fn description(&self) -> &str { "Get or set readtable case mode" } + fn name(&self) -> &str { + "READTABLE-CASE" + } + fn description(&self) -> &str { + "Get or set readtable case mode" + } fn execute(&self, args: &[Value]) -> Result { Ok(if args.is_empty() { Value::String(":UPCASE".to_string()) diff --git a/crates/ovsm/src/tools/stdlib/reader_printer.rs b/crates/ovsm/src/tools/stdlib/reader_printer.rs index a2597f4e1..d95c0324a 100644 --- a/crates/ovsm/src/tools/stdlib/reader_printer.rs +++ b/crates/ovsm/src/tools/stdlib/reader_printer.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// READ-FROM-STRING - Read from string pub struct ReadFromStringTool; impl Tool for ReadFromStringTool { - fn name(&self) -> &str { "READ-FROM-STRING" } - fn description(&self) -> &str { "Read Lisp expression from string" } + fn name(&self) -> &str { + "READ-FROM-STRING" + } + fn description(&self) -> &str { + "Read Lisp expression from string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -34,8 +38,12 @@ impl Tool for ReadFromStringTool { /// READ-DELIMITED-LIST - Read list until delimiter pub struct ReadDelimitedListTool; impl Tool for ReadDelimitedListTool { - fn name(&self) -> &str { "READ-DELIMITED-LIST" } - fn description(&self) -> &str { "Read list until delimiter character" } + fn name(&self) -> &str { + "READ-DELIMITED-LIST" + } + fn description(&self) -> &str { + "Read list until delimiter character" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Array(Arc::new(vec![]))) } @@ -44,18 +52,30 @@ impl Tool for ReadDelimitedListTool { /// READ-PRESERVING-WHITESPACE - Read preserving whitespace pub struct ReadPreservingWhitespaceTool; impl Tool for ReadPreservingWhitespaceTool { - fn name(&self) -> &str { "READ-PRESERVING-WHITESPACE" } - fn description(&self) -> &str { "Read without consuming trailing whitespace" } + fn name(&self) -> &str { + "READ-PRESERVING-WHITESPACE" + } + fn description(&self) -> &str { + "Read without consuming trailing whitespace" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// READ-CHAR - Read single character pub struct ReadCharTool; impl Tool for ReadCharTool { - fn name(&self) -> &str { "READ-CHAR" } - fn description(&self) -> &str { "Read single character from stream" } + fn name(&self) -> &str { + "READ-CHAR" + } + fn description(&self) -> &str { + "Read single character from stream" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(" ".to_string())) } @@ -64,8 +84,12 @@ impl Tool for ReadCharTool { /// READ-CHAR-NO-HANG - Read char without waiting pub struct ReadCharNoHangTool; impl Tool for ReadCharNoHangTool { - fn name(&self) -> &str { "READ-CHAR-NO-HANG" } - fn description(&self) -> &str { "Read character without blocking" } + fn name(&self) -> &str { + "READ-CHAR-NO-HANG" + } + fn description(&self) -> &str { + "Read character without blocking" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -74,18 +98,30 @@ impl Tool for ReadCharNoHangTool { /// UNREAD-CHAR - Push character back to stream pub struct UnreadCharTool; impl Tool for UnreadCharTool { - fn name(&self) -> &str { "UNREAD-CHAR" } - fn description(&self) -> &str { "Push character back to input stream" } + fn name(&self) -> &str { + "UNREAD-CHAR" + } + fn description(&self) -> &str { + "Push character back to input stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// PEEK-CHAR - Peek at next character pub struct PeekCharTool; impl Tool for PeekCharTool { - fn name(&self) -> &str { "PEEK-CHAR" } - fn description(&self) -> &str { "Peek at next character without consuming" } + fn name(&self) -> &str { + "PEEK-CHAR" + } + fn description(&self) -> &str { + "Peek at next character without consuming" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(" ".to_string())) } @@ -94,8 +130,12 @@ impl Tool for PeekCharTool { /// LISTEN - Check if input available pub struct ListenTool; impl Tool for ListenTool { - fn name(&self) -> &str { "LISTEN" } - fn description(&self) -> &str { "Check if input is available" } + fn name(&self) -> &str { + "LISTEN" + } + fn description(&self) -> &str { + "Check if input is available" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Bool(false)) } @@ -104,8 +144,12 @@ impl Tool for ListenTool { /// CLEAR-INPUT - Clear input buffer pub struct ClearInputTool; impl Tool for ClearInputTool { - fn name(&self) -> &str { "CLEAR-INPUT" } - fn description(&self) -> &str { "Clear input buffer" } + fn name(&self) -> &str { + "CLEAR-INPUT" + } + fn description(&self) -> &str { + "Clear input buffer" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -118,8 +162,12 @@ impl Tool for ClearInputTool { /// GET-MACRO-CHARACTER - Get reader macro function pub struct GetMacroCharacterTool; impl Tool for GetMacroCharacterTool { - fn name(&self) -> &str { "GET-MACRO-CHARACTER" } - fn description(&self) -> &str { "Get reader macro function for character" } + fn name(&self) -> &str { + "GET-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Get reader macro function for character" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -134,8 +182,12 @@ impl Tool for GetMacroCharacterTool { /// SET-MACRO-CHARACTER - Set reader macro function pub struct SetMacroCharacterTool; impl Tool for SetMacroCharacterTool { - fn name(&self) -> &str { "SET-MACRO-CHARACTER" } - fn description(&self) -> &str { "Set reader macro function for character" } + fn name(&self) -> &str { + "SET-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Set reader macro function for character" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -150,18 +202,30 @@ impl Tool for SetMacroCharacterTool { /// MAKE-DISPATCH-MACRO-CHARACTER - Create dispatch macro pub struct MakeDispatchMacroCharacterTool; impl Tool for MakeDispatchMacroCharacterTool { - fn name(&self) -> &str { "MAKE-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Make character a dispatch macro" } + fn name(&self) -> &str { + "MAKE-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Make character a dispatch macro" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// GET-DISPATCH-MACRO-CHARACTER - Get dispatch macro pub struct GetDispatchMacroCharacterTool; impl Tool for GetDispatchMacroCharacterTool { - fn name(&self) -> &str { "GET-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Get dispatch macro function" } + fn name(&self) -> &str { + "GET-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Get dispatch macro function" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -170,18 +234,30 @@ impl Tool for GetDispatchMacroCharacterTool { /// SET-DISPATCH-MACRO-CHARACTER - Set dispatch macro pub struct SetDispatchMacroCharacterTool; impl Tool for SetDispatchMacroCharacterTool { - fn name(&self) -> &str { "SET-DISPATCH-MACRO-CHARACTER" } - fn description(&self) -> &str { "Set dispatch macro function" } + fn name(&self) -> &str { + "SET-DISPATCH-MACRO-CHARACTER" + } + fn description(&self) -> &str { + "Set dispatch macro function" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() >= 3 { args[2].clone() } else { Value::Null }) + Ok(if args.len() >= 3 { + args[2].clone() + } else { + Value::Null + }) } } /// READTABLE-CASE - Get readtable case mode pub struct ReadtableCaseTool; impl Tool for ReadtableCaseTool { - fn name(&self) -> &str { "READTABLE-CASE" } - fn description(&self) -> &str { "Get or set readtable case mode" } + fn name(&self) -> &str { + "READTABLE-CASE" + } + fn description(&self) -> &str { + "Get or set readtable case mode" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("UPCASE".to_string())) } @@ -190,8 +266,12 @@ impl Tool for ReadtableCaseTool { /// COPY-READTABLE - Copy readtable pub struct CopyReadtableTool; impl Tool for CopyReadtableTool { - fn name(&self) -> &str { "COPY-READTABLE" } - fn description(&self) -> &str { "Copy readtable" } + fn name(&self) -> &str { + "COPY-READTABLE" + } + fn description(&self) -> &str { + "Copy readtable" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("READTABLE".to_string())) } @@ -204,8 +284,12 @@ impl Tool for CopyReadtableTool { /// WRITE-TO-STRING - Write to string pub struct WriteToStringTool; impl Tool for WriteToStringTool { - fn name(&self) -> &str { "WRITE-TO-STRING" } - fn description(&self) -> &str { "Write object to string" } + fn name(&self) -> &str { + "WRITE-TO-STRING" + } + fn description(&self) -> &str { + "Write object to string" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -229,8 +313,12 @@ impl Tool for WriteToStringTool { /// PRIN1-TO-STRING - Print to string (readable) pub struct Prin1ToStringTool; impl Tool for Prin1ToStringTool { - fn name(&self) -> &str { "PRIN1-TO-STRING" } - fn description(&self) -> &str { "Print object to string (readable)" } + fn name(&self) -> &str { + "PRIN1-TO-STRING" + } + fn description(&self) -> &str { + "Print object to string (readable)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -254,8 +342,12 @@ impl Tool for Prin1ToStringTool { /// PRINC-TO-STRING - Print to string (aesthetic) pub struct PrincToStringTool; impl Tool for PrincToStringTool { - fn name(&self) -> &str { "PRINC-TO-STRING" } - fn description(&self) -> &str { "Print object to string (aesthetic)" } + fn name(&self) -> &str { + "PRINC-TO-STRING" + } + fn description(&self) -> &str { + "Print object to string (aesthetic)" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -279,38 +371,66 @@ impl Tool for PrincToStringTool { /// WRITE-CHAR - Write single character pub struct WriteCharTool; impl Tool for WriteCharTool { - fn name(&self) -> &str { "WRITE-CHAR" } - fn description(&self) -> &str { "Write single character to stream" } + fn name(&self) -> &str { + "WRITE-CHAR" + } + fn description(&self) -> &str { + "Write single character to stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// WRITE-STRING - Write string pub struct WriteStringTool; impl Tool for WriteStringTool { - fn name(&self) -> &str { "WRITE-STRING" } - fn description(&self) -> &str { "Write string to stream" } + fn name(&self) -> &str { + "WRITE-STRING" + } + fn description(&self) -> &str { + "Write string to stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// WRITE-LINE - Write line pub struct WriteLineTool; impl Tool for WriteLineTool { - fn name(&self) -> &str { "WRITE-LINE" } - fn description(&self) -> &str { "Write line to stream" } + fn name(&self) -> &str { + "WRITE-LINE" + } + fn description(&self) -> &str { + "Write line to stream" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// TERPRI - Output newline pub struct TerpriTool; impl Tool for TerpriTool { - fn name(&self) -> &str { "TERPRI" } - fn description(&self) -> &str { "Output newline" } + fn name(&self) -> &str { + "TERPRI" + } + fn description(&self) -> &str { + "Output newline" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -319,8 +439,12 @@ impl Tool for TerpriTool { /// FRESH-LINE - Output newline if needed pub struct FreshLineTool; impl Tool for FreshLineTool { - fn name(&self) -> &str { "FRESH-LINE" } - fn description(&self) -> &str { "Output newline if not at line start" } + fn name(&self) -> &str { + "FRESH-LINE" + } + fn description(&self) -> &str { + "Output newline if not at line start" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Bool(true)) } @@ -329,8 +453,12 @@ impl Tool for FreshLineTool { /// FINISH-OUTPUT - Finish output operations pub struct FinishOutputTool; impl Tool for FinishOutputTool { - fn name(&self) -> &str { "FINISH-OUTPUT" } - fn description(&self) -> &str { "Finish all output operations" } + fn name(&self) -> &str { + "FINISH-OUTPUT" + } + fn description(&self) -> &str { + "Finish all output operations" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -339,8 +467,12 @@ impl Tool for FinishOutputTool { /// FORCE-OUTPUT - Force output flush pub struct ForceOutputTool; impl Tool for ForceOutputTool { - fn name(&self) -> &str { "FORCE-OUTPUT" } - fn description(&self) -> &str { "Force output to be flushed" } + fn name(&self) -> &str { + "FORCE-OUTPUT" + } + fn description(&self) -> &str { + "Force output to be flushed" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } @@ -349,8 +481,12 @@ impl Tool for ForceOutputTool { /// CLEAR-OUTPUT - Clear output buffer pub struct ClearOutputTool; impl Tool for ClearOutputTool { - fn name(&self) -> &str { "CLEAR-OUTPUT" } - fn description(&self) -> &str { "Clear output buffer" } + fn name(&self) -> &str { + "CLEAR-OUTPUT" + } + fn description(&self) -> &str { + "Clear output buffer" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Null) } diff --git a/crates/ovsm/src/tools/stdlib/sequences.rs b/crates/ovsm/src/tools/stdlib/sequences.rs index 5e7cac7ae..b71d03655 100644 --- a/crates/ovsm/src/tools/stdlib/sequences.rs +++ b/crates/ovsm/src/tools/stdlib/sequences.rs @@ -117,20 +117,22 @@ impl Tool for EltTool { let index = args[1].as_int()? as usize; match &args[0] { - Value::Array(arr) => arr.get(index).cloned().ok_or_else(|| { - Error::IndexOutOfBounds { + Value::Array(arr) => arr + .get(index) + .cloned() + .ok_or_else(|| Error::IndexOutOfBounds { index, length: arr.len(), - } - }), + }), Value::String(s) => { let chars: Vec = s.chars().collect(); - chars.get(index).map(|c| Value::String(c.to_string())).ok_or_else(|| { - Error::IndexOutOfBounds { + chars + .get(index) + .map(|c| Value::String(c.to_string())) + .ok_or_else(|| Error::IndexOutOfBounds { index, length: chars.len(), - } - }) + }) } _ => Err(Error::TypeError { expected: "sequence (array or string)".to_string(), @@ -235,10 +237,12 @@ impl Tool for AppendTool { match arg { Value::Array(arr) => result.extend(arr.iter().cloned()), Value::Null => {} - _ => return Err(Error::TypeError { - expected: "list".to_string(), - got: arg.type_name(), - }), + _ => { + return Err(Error::TypeError { + expected: "list".to_string(), + got: arg.type_name(), + }) + } } } @@ -555,10 +559,7 @@ impl Tool for RemoveTool { let item = &args[0]; let seq = args[1].as_array()?; - let result: Vec = seq.iter() - .filter(|elem| *elem != item) - .cloned() - .collect(); + let result: Vec = seq.iter().filter(|elem| *elem != item).cloned().collect(); Ok(Value::Array(Arc::new(result))) } @@ -586,7 +587,8 @@ impl Tool for RemoveIfTool { let seq = args[1].as_array()?; - let result: Vec = seq.iter() + let result: Vec = seq + .iter() .filter(|elem| !elem.is_truthy()) .cloned() .collect(); @@ -617,7 +619,8 @@ impl Tool for RemoveIfNotTool { let seq = args[1].as_array()?; - let result: Vec = seq.iter() + let result: Vec = seq + .iter() .filter(|elem| elem.is_truthy()) .cloned() .collect(); @@ -725,7 +728,8 @@ impl Tool for SubstTool { if tree == old { new.clone() } else if let Value::Array(arr) = tree { - let result: Vec = arr.iter() + let result: Vec = arr + .iter() .map(|elem| subst_recursive(new, old, elem)) .collect(); Value::Array(Arc::new(result)) @@ -765,7 +769,8 @@ impl Tool for SubstIfTool { if tree.is_truthy() { new.clone() } else if let Value::Array(arr) = tree { - let result: Vec = arr.iter() + let result: Vec = arr + .iter() .map(|elem| subst_if_recursive(new, elem)) .collect(); Value::Array(Arc::new(result)) @@ -857,7 +862,8 @@ impl Tool for IntersectionTool { let list1 = args[0].as_array()?; let list2 = args[1].as_array()?; - let result: Vec = list1.iter() + let result: Vec = list1 + .iter() .filter(|elem| list2.contains(elem)) .cloned() .collect(); @@ -889,7 +895,8 @@ impl Tool for SetDifferenceTool { let list1 = args[0].as_array()?; let list2 = args[1].as_array()?; - let result: Vec = list1.iter() + let result: Vec = list1 + .iter() .filter(|elem| !list2.contains(elem)) .cloned() .collect(); @@ -1066,7 +1073,9 @@ impl Tool for PairlisTool { let keys = args[0].as_array()?; let values = args[1].as_array()?; - let pairs: Vec = keys.iter().zip(values.iter()) + let pairs: Vec = keys + .iter() + .zip(values.iter()) .map(|(k, v)| Value::Array(Arc::new(vec![k.clone(), v.clone()]))) .collect(); @@ -1339,8 +1348,12 @@ impl Tool for MismatchTool { /// MERGE - Merge two sorted sequences pub struct MergeTool; impl Tool for MergeTool { - fn name(&self) -> &str { "MERGE" } - fn description(&self) -> &str { "Merge two sorted sequences" } + fn name(&self) -> &str { + "MERGE" + } + fn description(&self) -> &str { + "Merge two sorted sequences" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1352,11 +1365,9 @@ impl Tool for MergeTool { let seq2 = args[1].as_array()?; let mut result = seq1.to_vec(); result.extend(seq2.iter().cloned()); - result.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, - } + result.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(result))) } @@ -1365,22 +1376,24 @@ impl Tool for MergeTool { /// STABLE-SORT - Stable sort sequence pub struct StableSortTool; impl Tool for StableSortTool { - fn name(&self) -> &str { "STABLE-SORT" } - fn description(&self) -> &str { "Stable sort sequence" } + fn name(&self) -> &str { + "STABLE-SORT" + } + fn description(&self) -> &str { + "Stable sort sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); } let mut seq = args[0].as_array()?.to_vec(); - seq.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + seq.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(seq))) } @@ -1389,8 +1402,12 @@ impl Tool for StableSortTool { /// SEARCH - Search for subsequence pub struct SearchTool; impl Tool for SearchTool { - fn name(&self) -> &str { "SEARCH" } - fn description(&self) -> &str { "Search for subsequence within sequence" } + fn name(&self) -> &str { + "SEARCH" + } + fn description(&self) -> &str { + "Search for subsequence within sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1417,8 +1434,12 @@ impl Tool for SearchTool { /// SUBSTITUTE-IF - Substitute if predicate matches pub struct SubstituteIfTool; impl Tool for SubstituteIfTool { - fn name(&self) -> &str { "SUBSTITUTE-IF" } - fn description(&self) -> &str { "Substitute if predicate matches" } + fn name(&self) -> &str { + "SUBSTITUTE-IF" + } + fn description(&self) -> &str { + "Substitute if predicate matches" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1428,9 +1449,16 @@ impl Tool for SubstituteIfTool { } let new_val = &args[0]; let seq = args[1].as_array()?; - let result: Vec = seq.iter().map(|elem| { - if elem.is_truthy() { new_val.clone() } else { elem.clone() } - }).collect(); + let result: Vec = seq + .iter() + .map(|elem| { + if elem.is_truthy() { + new_val.clone() + } else { + elem.clone() + } + }) + .collect(); Ok(Value::Array(Arc::new(result))) } } @@ -1438,8 +1466,12 @@ impl Tool for SubstituteIfTool { /// SUBSTITUTE-IF-NOT - Substitute if predicate doesn't match pub struct SubstituteIfNotTool; impl Tool for SubstituteIfNotTool { - fn name(&self) -> &str { "SUBSTITUTE-IF-NOT" } - fn description(&self) -> &str { "Substitute if predicate doesn't match" } + fn name(&self) -> &str { + "SUBSTITUTE-IF-NOT" + } + fn description(&self) -> &str { + "Substitute if predicate doesn't match" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1449,9 +1481,16 @@ impl Tool for SubstituteIfNotTool { } let new_val = &args[0]; let seq = args[1].as_array()?; - let result: Vec = seq.iter().map(|elem| { - if !elem.is_truthy() { new_val.clone() } else { elem.clone() } - }).collect(); + let result: Vec = seq + .iter() + .map(|elem| { + if !elem.is_truthy() { + new_val.clone() + } else { + elem.clone() + } + }) + .collect(); Ok(Value::Array(Arc::new(result))) } } @@ -1459,8 +1498,12 @@ impl Tool for SubstituteIfNotTool { /// NSUBSTITUTE-IF - Destructively substitute if predicate matches pub struct NsubstituteIfTool; impl Tool for NsubstituteIfTool { - fn name(&self) -> &str { "NSUBSTITUTE-IF" } - fn description(&self) -> &str { "Destructively substitute if predicate matches" } + fn name(&self) -> &str { + "NSUBSTITUTE-IF" + } + fn description(&self) -> &str { + "Destructively substitute if predicate matches" + } fn execute(&self, args: &[Value]) -> Result { SubstituteIfTool.execute(args) } @@ -1469,8 +1512,12 @@ impl Tool for NsubstituteIfTool { /// NSUBSTITUTE-IF-NOT - Destructively substitute if predicate doesn't match pub struct NsubstituteIfNotTool; impl Tool for NsubstituteIfNotTool { - fn name(&self) -> &str { "NSUBSTITUTE-IF-NOT" } - fn description(&self) -> &str { "Destructively substitute if predicate doesn't match" } + fn name(&self) -> &str { + "NSUBSTITUTE-IF-NOT" + } + fn description(&self) -> &str { + "Destructively substitute if predicate doesn't match" + } fn execute(&self, args: &[Value]) -> Result { SubstituteIfNotTool.execute(args) } @@ -1479,8 +1526,12 @@ impl Tool for NsubstituteIfNotTool { /// DELETE-DUPLICATES - Remove duplicate elements pub struct DeleteDuplicatesTool; impl Tool for DeleteDuplicatesTool { - fn name(&self) -> &str { "DELETE-DUPLICATES" } - fn description(&self) -> &str { "Remove duplicate elements from sequence" } + fn name(&self) -> &str { + "DELETE-DUPLICATES" + } + fn description(&self) -> &str { + "Remove duplicate elements from sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -1501,8 +1552,12 @@ impl Tool for DeleteDuplicatesTool { /// COUNT - Count occurrences of item pub struct CountTool; impl Tool for CountTool { - fn name(&self) -> &str { "COUNT" } - fn description(&self) -> &str { "Count occurrences of item in sequence" } + fn name(&self) -> &str { + "COUNT" + } + fn description(&self) -> &str { + "Count occurrences of item in sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1520,8 +1575,12 @@ impl Tool for CountTool { /// COUNT-IF - Count items matching predicate pub struct CountIfTool; impl Tool for CountIfTool { - fn name(&self) -> &str { "COUNT-IF" } - fn description(&self) -> &str { "Count items matching predicate" } + fn name(&self) -> &str { + "COUNT-IF" + } + fn description(&self) -> &str { + "Count items matching predicate" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Int(0)); @@ -1535,8 +1594,12 @@ impl Tool for CountIfTool { /// POSITION - Find position of item pub struct PositionTool; impl Tool for PositionTool { - fn name(&self) -> &str { "POSITION" } - fn description(&self) -> &str { "Find position of item in sequence" } + fn name(&self) -> &str { + "POSITION" + } + fn description(&self) -> &str { + "Find position of item in sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1558,8 +1621,12 @@ impl Tool for PositionTool { /// FIND-IF-NOT - Find item not matching predicate pub struct FindIfNotTool; impl Tool for FindIfNotTool { - fn name(&self) -> &str { "FIND-IF-NOT" } - fn description(&self) -> &str { "Find first item not matching predicate" } + fn name(&self) -> &str { + "FIND-IF-NOT" + } + fn description(&self) -> &str { + "Find first item not matching predicate" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); @@ -1577,8 +1644,12 @@ impl Tool for FindIfNotTool { /// REPLACE - Replace subsequence pub struct ReplaceToolSeq; impl Tool for ReplaceToolSeq { - fn name(&self) -> &str { "REPLACE" } - fn description(&self) -> &str { "Replace subsequence in sequence" } + fn name(&self) -> &str { + "REPLACE" + } + fn description(&self) -> &str { + "Replace subsequence in sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1600,8 +1671,12 @@ impl Tool for ReplaceToolSeq { /// NREPLACE - Destructively replace subsequence pub struct NreplaceTool; impl Tool for NreplaceTool { - fn name(&self) -> &str { "NREPLACE" } - fn description(&self) -> &str { "Destructively replace subsequence" } + fn name(&self) -> &str { + "NREPLACE" + } + fn description(&self) -> &str { + "Destructively replace subsequence" + } fn execute(&self, args: &[Value]) -> Result { ReplaceToolSeq.execute(args) } @@ -1610,8 +1685,12 @@ impl Tool for NreplaceTool { /// CONCATENATE - Concatenate sequences pub struct ConcatenateTool; impl Tool for ConcatenateTool { - fn name(&self) -> &str { "CONCATENATE" } - fn description(&self) -> &str { "Concatenate sequences" } + fn name(&self) -> &str { + "CONCATENATE" + } + fn description(&self) -> &str { + "Concatenate sequences" + } fn execute(&self, args: &[Value]) -> Result { let mut result = Vec::new(); for arg in args { @@ -1626,8 +1705,12 @@ impl Tool for ConcatenateTool { /// LENGTH - Get sequence length pub struct LengthSeqTool; impl Tool for LengthSeqTool { - fn name(&self) -> &str { "LENGTH" } - fn description(&self) -> &str { "Get length of sequence" } + fn name(&self) -> &str { + "LENGTH" + } + fn description(&self) -> &str { + "Get length of sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Int(0)); @@ -1643,8 +1726,12 @@ impl Tool for LengthSeqTool { /// REVERSE - Reverse sequence pub struct ReverseTool; impl Tool for ReverseTool { - fn name(&self) -> &str { "REVERSE" } - fn description(&self) -> &str { "Reverse sequence" } + fn name(&self) -> &str { + "REVERSE" + } + fn description(&self) -> &str { + "Reverse sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -1658,8 +1745,12 @@ impl Tool for ReverseTool { /// SUBSEQUENCE - Extract subsequence pub struct SubsequenceTool; impl Tool for SubsequenceTool { - fn name(&self) -> &str { "SUBSEQUENCE" } - fn description(&self) -> &str { "Extract subsequence" } + fn name(&self) -> &str { + "SUBSEQUENCE" + } + fn description(&self) -> &str { + "Extract subsequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -1686,22 +1777,24 @@ impl Tool for SubsequenceTool { /// SORT - Sort sequence pub struct SortTool; impl Tool for SortTool { - fn name(&self) -> &str { "SORT" } - fn description(&self) -> &str { "Sort sequence" } + fn name(&self) -> &str { + "SORT" + } + fn description(&self) -> &str { + "Sort sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); } let mut seq = args[0].as_array()?.to_vec(); - seq.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + seq.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(seq))) } @@ -1710,8 +1803,12 @@ impl Tool for SortTool { /// MAP - Map function over sequence pub struct MapTool; impl Tool for MapTool { - fn name(&self) -> &str { "MAP" } - fn description(&self) -> &str { "Map function over sequence" } + fn name(&self) -> &str { + "MAP" + } + fn description(&self) -> &str { + "Map function over sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); diff --git a/crates/ovsm/src/tools/stdlib/sequences_advanced.rs b/crates/ovsm/src/tools/stdlib/sequences_advanced.rs index 333fa8ecd..823224660 100644 --- a/crates/ovsm/src/tools/stdlib/sequences_advanced.rs +++ b/crates/ovsm/src/tools/stdlib/sequences_advanced.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// SORT-BY-KEY - Sort with key function pub struct SortByKeyTool; impl Tool for SortByKeyTool { - fn name(&self) -> &str { "SORT-BY-KEY" } - fn description(&self) -> &str { "Sort sequence using key function" } + fn name(&self) -> &str { + "SORT-BY-KEY" + } + fn description(&self) -> &str { + "Sort sequence using key function" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -27,15 +31,13 @@ impl Tool for SortByKeyTool { match &args[0] { Value::Array(arr) => { let mut sorted = arr.to_vec(); - sorted.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + sorted.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(sorted))) } @@ -47,8 +49,12 @@ impl Tool for SortByKeyTool { /// STABLE-SORT-BY-KEY - Stable sort with key pub struct StableSortByKeyTool; impl Tool for StableSortByKeyTool { - fn name(&self) -> &str { "STABLE-SORT-BY-KEY" } - fn description(&self) -> &str { "Stable sort sequence using key function" } + fn name(&self) -> &str { + "STABLE-SORT-BY-KEY" + } + fn description(&self) -> &str { + "Stable sort sequence using key function" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); @@ -57,15 +63,13 @@ impl Tool for StableSortByKeyTool { match &args[0] { Value::Array(arr) => { let mut sorted = arr.to_vec(); - sorted.sort_by(|a, b| { - match (a, b) { - (Value::Int(x), Value::Int(y)) => x.cmp(y), - (Value::Float(x), Value::Float(y)) => { - x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) - } - (Value::String(x), Value::String(y)) => x.cmp(y), - _ => std::cmp::Ordering::Equal, + sorted.sort_by(|a, b| match (a, b) { + (Value::Int(x), Value::Int(y)) => x.cmp(y), + (Value::Float(x), Value::Float(y)) => { + x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal) } + (Value::String(x), Value::String(y)) => x.cmp(y), + _ => std::cmp::Ordering::Equal, }); Ok(Value::Array(Arc::new(sorted))) } @@ -81,8 +85,12 @@ impl Tool for StableSortByKeyTool { /// MISMATCH - Find first position where sequences differ pub struct MismatchTool; impl Tool for MismatchTool { - fn name(&self) -> &str { "MISMATCH" } - fn description(&self) -> &str { "Find first position where sequences differ" } + fn name(&self) -> &str { + "MISMATCH" + } + fn description(&self) -> &str { + "Find first position where sequences differ" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -115,8 +123,12 @@ impl Tool for MismatchTool { /// SEARCH-SUBSEQUENCE - Search for subsequence pub struct SearchSubsequenceTool; impl Tool for SearchSubsequenceTool { - fn name(&self) -> &str { "SEARCH-SUBSEQUENCE" } - fn description(&self) -> &str { "Search for subsequence in sequence" } + fn name(&self) -> &str { + "SEARCH-SUBSEQUENCE" + } + fn description(&self) -> &str { + "Search for subsequence in sequence" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -153,23 +165,34 @@ impl Tool for SearchSubsequenceTool { /// SUBSTITUTE-IF-NOT - Substitute where predicate false pub struct SubstituteIfNotTool; impl Tool for SubstituteIfNotTool { - fn name(&self) -> &str { "SUBSTITUTE-IF-NOT" } - fn description(&self) -> &str { "Substitute where predicate is false" } + fn name(&self) -> &str { + "SUBSTITUTE-IF-NOT" + } + fn description(&self) -> &str { + "Substitute where predicate is false" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Ok(if args.is_empty() { Value::Null } else { args[0].clone() }); + return Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }); } match &args[1] { Value::Array(arr) => { let new_val = &args[0]; - let result: Vec = arr.iter().map(|v| { - if !v.is_truthy() { - new_val.clone() - } else { - v.clone() - } - }).collect(); + let result: Vec = arr + .iter() + .map(|v| { + if !v.is_truthy() { + new_val.clone() + } else { + v.clone() + } + }) + .collect(); Ok(Value::Array(Arc::new(result))) } v => Ok(v.clone()), @@ -180,23 +203,34 @@ impl Tool for SubstituteIfNotTool { /// NSUBSTITUTE-IF-NOT - Destructive substitute where predicate false pub struct NsubstituteIfNotTool; impl Tool for NsubstituteIfNotTool { - fn name(&self) -> &str { "NSUBSTITUTE-IF-NOT" } - fn description(&self) -> &str { "Destructively substitute where predicate is false" } + fn name(&self) -> &str { + "NSUBSTITUTE-IF-NOT" + } + fn description(&self) -> &str { + "Destructively substitute where predicate is false" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Ok(if args.is_empty() { Value::Null } else { args[0].clone() }); + return Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }); } match &args[1] { Value::Array(arr) => { let new_val = &args[0]; - let result: Vec = arr.iter().map(|v| { - if !v.is_truthy() { - new_val.clone() - } else { - v.clone() - } - }).collect(); + let result: Vec = arr + .iter() + .map(|v| { + if !v.is_truthy() { + new_val.clone() + } else { + v.clone() + } + }) + .collect(); Ok(Value::Array(Arc::new(result))) } v => Ok(v.clone()), @@ -211,8 +245,12 @@ impl Tool for NsubstituteIfNotTool { /// FILL-POINTER - Get or set fill pointer pub struct FillPointerTool; impl Tool for FillPointerTool { - fn name(&self) -> &str { "FILL-POINTER" } - fn description(&self) -> &str { "Get or set array fill pointer" } + fn name(&self) -> &str { + "FILL-POINTER" + } + fn description(&self) -> &str { + "Get or set array fill pointer" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::Array(arr)) => Ok(Value::Int(arr.len() as i64)), @@ -224,8 +262,12 @@ impl Tool for FillPointerTool { /// VECTOR-PUSH - Push element, advance fill pointer pub struct VectorPushTool; impl Tool for VectorPushTool { - fn name(&self) -> &str { "VECTOR-PUSH" } - fn description(&self) -> &str { "Push element onto vector with fill pointer" } + fn name(&self) -> &str { + "VECTOR-PUSH" + } + fn description(&self) -> &str { + "Push element onto vector with fill pointer" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -251,8 +293,12 @@ impl Tool for VectorPushTool { /// VECTOR-POP - Pop element, decrement fill pointer pub struct VectorPopTool; impl Tool for VectorPopTool { - fn name(&self) -> &str { "VECTOR-POP" } - fn description(&self) -> &str { "Pop element from vector with fill pointer" } + fn name(&self) -> &str { + "VECTOR-POP" + } + fn description(&self) -> &str { + "Pop element from vector with fill pointer" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -283,8 +329,12 @@ impl Tool for VectorPopTool { /// VECTOR-PUSH-EXTEND - Push element, extend if needed pub struct VectorPushExtendTool; impl Tool for VectorPushExtendTool { - fn name(&self) -> &str { "VECTOR-PUSH-EXTEND" } - fn description(&self) -> &str { "Push element, extending vector if necessary" } + fn name(&self) -> &str { + "VECTOR-PUSH-EXTEND" + } + fn description(&self) -> &str { + "Push element, extending vector if necessary" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { diff --git a/crates/ovsm/src/tools/stdlib/strings.rs b/crates/ovsm/src/tools/stdlib/strings.rs index 755d75881..3be0a4967 100644 --- a/crates/ovsm/src/tools/stdlib/strings.rs +++ b/crates/ovsm/src/tools/stdlib/strings.rs @@ -790,9 +790,7 @@ impl Tool for CharUpcaseTool { reason: "Empty string".to_string(), })?; - Ok(Value::String( - ch.to_uppercase().next().unwrap().to_string(), - )) + Ok(Value::String(ch.to_uppercase().next().unwrap().to_string())) } } @@ -822,9 +820,7 @@ impl Tool for CharDowncaseTool { reason: "Empty string".to_string(), })?; - Ok(Value::String( - ch.to_lowercase().next().unwrap().to_string(), - )) + Ok(Value::String(ch.to_lowercase().next().unwrap().to_string())) } } @@ -884,10 +880,13 @@ impl Tool for PositionTool { let needle = args[0].as_string()?; let haystack = args[1].as_string()?; - let ch = needle.chars().next().ok_or_else(|| Error::InvalidArguments { - tool: "POSITION".to_string(), - reason: "Empty search string".to_string(), - })?; + let ch = needle + .chars() + .next() + .ok_or_else(|| Error::InvalidArguments { + tool: "POSITION".to_string(), + reason: "Empty search string".to_string(), + })?; match haystack.find(ch) { Some(idx) => Ok(Value::Int(idx as i64)), @@ -1382,10 +1381,7 @@ impl Tool for StringToListTool { } let s = args[0].as_string()?; - let chars: Vec = s - .chars() - .map(|c| Value::String(c.to_string())) - .collect(); + let chars: Vec = s.chars().map(|c| Value::String(c.to_string())).collect(); Ok(Value::Array(Arc::new(chars))) } diff --git a/crates/ovsm/src/tools/stdlib/symbols_extended.rs b/crates/ovsm/src/tools/stdlib/symbols_extended.rs index ad53d3e11..730029d51 100644 --- a/crates/ovsm/src/tools/stdlib/symbols_extended.rs +++ b/crates/ovsm/src/tools/stdlib/symbols_extended.rs @@ -17,8 +17,12 @@ use std::sync::Arc; /// GET - Get symbol property pub struct GetTool; impl Tool for GetTool { - fn name(&self) -> &str { "GET" } - fn description(&self) -> &str { "Get symbol property value" } + fn name(&self) -> &str { + "GET" + } + fn description(&self) -> &str { + "Get symbol property value" + } fn execute(&self, args: &[Value]) -> Result { // args: symbol, indicator, default if args.len() < 2 { @@ -34,8 +38,12 @@ impl Tool for GetTool { /// SYMBOL-PLIST - Get symbol property list pub struct SymbolPlistTool; impl Tool for SymbolPlistTool { - fn name(&self) -> &str { "SYMBOL-PLIST" } - fn description(&self) -> &str { "Get symbol property list" } + fn name(&self) -> &str { + "SYMBOL-PLIST" + } + fn description(&self) -> &str { + "Get symbol property list" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept symbol Ok(Value::Array(Arc::new(vec![]))) @@ -45,8 +53,12 @@ impl Tool for SymbolPlistTool { /// REMPROP - Remove property from symbol pub struct RempropTool; impl Tool for RempropTool { - fn name(&self) -> &str { "REMPROP" } - fn description(&self) -> &str { "Remove property from symbol" } + fn name(&self) -> &str { + "REMPROP" + } + fn description(&self) -> &str { + "Remove property from symbol" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept symbol and property indicator Ok(Value::Bool(true)) @@ -56,18 +68,30 @@ impl Tool for RempropTool { /// COPY-SYMBOL - Copy symbol pub struct CopySymbolTool; impl Tool for CopySymbolTool { - fn name(&self) -> &str { "COPY-SYMBOL" } - fn description(&self) -> &str { "Copy symbol with optional properties" } + fn name(&self) -> &str { + "COPY-SYMBOL" + } + fn description(&self) -> &str { + "Copy symbol with optional properties" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// GENSYM - Generate unique symbol pub struct GensymTool; impl Tool for GensymTool { - fn name(&self) -> &str { "GENSYM" } - fn description(&self) -> &str { "Generate unique uninterned symbol" } + fn name(&self) -> &str { + "GENSYM" + } + fn description(&self) -> &str { + "Generate unique uninterned symbol" + } fn execute(&self, args: &[Value]) -> Result { let prefix = match args.get(0) { Some(Value::String(s)) => s.clone(), @@ -84,8 +108,12 @@ impl Tool for GensymTool { /// GENTEMP - Generate interned temp symbol pub struct GentempTool; impl Tool for GentempTool { - fn name(&self) -> &str { "GENTEMP" } - fn description(&self) -> &str { "Generate unique interned symbol" } + fn name(&self) -> &str { + "GENTEMP" + } + fn description(&self) -> &str { + "Generate unique interned symbol" + } fn execute(&self, args: &[Value]) -> Result { let prefix = match args.get(0) { Some(Value::String(s)) => s.clone(), @@ -105,8 +133,12 @@ impl Tool for GentempTool { /// SYMBOL-NAME - Get symbol name string pub struct SymbolNameTool; impl Tool for SymbolNameTool { - fn name(&self) -> &str { "SYMBOL-NAME" } - fn description(&self) -> &str { "Get symbol name as string" } + fn name(&self) -> &str { + "SYMBOL-NAME" + } + fn description(&self) -> &str { + "Get symbol name as string" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => Ok(Value::String(s.clone())), @@ -118,8 +150,12 @@ impl Tool for SymbolNameTool { /// SYMBOL-PACKAGE - Get symbol's package pub struct SymbolPackageTool; impl Tool for SymbolPackageTool { - fn name(&self) -> &str { "SYMBOL-PACKAGE" } - fn description(&self) -> &str { "Get symbol's home package" } + fn name(&self) -> &str { + "SYMBOL-PACKAGE" + } + fn description(&self) -> &str { + "Get symbol's home package" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept symbol Ok(Value::String("COMMON-LISP-USER".to_string())) @@ -129,10 +165,18 @@ impl Tool for SymbolPackageTool { /// SYMBOL-VALUE - Get symbol value pub struct SymbolValueTool; impl Tool for SymbolValueTool { - fn name(&self) -> &str { "SYMBOL-VALUE" } - fn description(&self) -> &str { "Get symbol's dynamic value" } + fn name(&self) -> &str { + "SYMBOL-VALUE" + } + fn description(&self) -> &str { + "Get symbol's dynamic value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -143,8 +187,12 @@ impl Tool for SymbolValueTool { /// SYMBOLP - Check if symbol pub struct SymbolpTool; impl Tool for SymbolpTool { - fn name(&self) -> &str { "SYMBOLP" } - fn description(&self) -> &str { "Check if object is a symbol" } + fn name(&self) -> &str { + "SYMBOLP" + } + fn description(&self) -> &str { + "Check if object is a symbol" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(_)) => Ok(Value::Bool(true)), @@ -156,8 +204,12 @@ impl Tool for SymbolpTool { /// KEYWORDP - Check if keyword symbol pub struct KeywordpTool; impl Tool for KeywordpTool { - fn name(&self) -> &str { "KEYWORDP" } - fn description(&self) -> &str { "Check if symbol is a keyword" } + fn name(&self) -> &str { + "KEYWORDP" + } + fn description(&self) -> &str { + "Check if symbol is a keyword" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => Ok(Value::Bool(s.starts_with(':'))), @@ -169,8 +221,12 @@ impl Tool for KeywordpTool { /// BOUNDP - Check if symbol has value binding pub struct BoundpTool; impl Tool for BoundpTool { - fn name(&self) -> &str { "BOUNDP" } - fn description(&self) -> &str { "Check if symbol has value binding" } + fn name(&self) -> &str { + "BOUNDP" + } + fn description(&self) -> &str { + "Check if symbol has value binding" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Bool(!args.is_empty())) } @@ -179,8 +235,12 @@ impl Tool for BoundpTool { /// CONSTANT-SYMBOL-P - Check if symbol is constant pub struct ConstantSymbolPTool; impl Tool for ConstantSymbolPTool { - fn name(&self) -> &str { "CONSTANT-SYMBOL-P" } - fn description(&self) -> &str { "Check if symbol is a constant" } + fn name(&self) -> &str { + "CONSTANT-SYMBOL-P" + } + fn description(&self) -> &str { + "Check if symbol is a constant" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => { @@ -199,20 +259,36 @@ impl Tool for ConstantSymbolPTool { /// SET - Set symbol value pub struct SetTool; impl Tool for SetTool { - fn name(&self) -> &str { "SET" } - fn description(&self) -> &str { "Set symbol dynamic value" } + fn name(&self) -> &str { + "SET" + } + fn description(&self) -> &str { + "Set symbol dynamic value" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[1].clone() + } else { + Value::Null + }) } } /// MAKUNBOUND - Make symbol unbound pub struct MakunboundTool; impl Tool for MakunboundTool { - fn name(&self) -> &str { "MAKUNBOUND" } - fn description(&self) -> &str { "Remove symbol value binding" } + fn name(&self) -> &str { + "MAKUNBOUND" + } + fn description(&self) -> &str { + "Remove symbol value binding" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -223,8 +299,12 @@ impl Tool for MakunboundTool { /// MAKE-KEYWORD - Convert to keyword symbol pub struct MakeKeywordTool; impl Tool for MakeKeywordTool { - fn name(&self) -> &str { "MAKE-KEYWORD" } - fn description(&self) -> &str { "Convert symbol to keyword" } + fn name(&self) -> &str { + "MAKE-KEYWORD" + } + fn description(&self) -> &str { + "Convert symbol to keyword" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => { @@ -242,8 +322,12 @@ impl Tool for MakeKeywordTool { /// KEYWORDICATE - Ensure keyword pub struct KeywordicateTool; impl Tool for KeywordicateTool { - fn name(&self) -> &str { "KEYWORDICATE" } - fn description(&self) -> &str { "Ensure value is a keyword" } + fn name(&self) -> &str { + "KEYWORDICATE" + } + fn description(&self) -> &str { + "Ensure value is a keyword" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => { @@ -266,8 +350,12 @@ impl Tool for KeywordicateTool { /// INTERN - Intern symbol in package pub struct InternTool; impl Tool for InternTool { - fn name(&self) -> &str { "INTERN" } - fn description(&self) -> &str { "Intern symbol in package" } + fn name(&self) -> &str { + "INTERN" + } + fn description(&self) -> &str { + "Intern symbol in package" + } fn execute(&self, args: &[Value]) -> Result { match args.get(0) { Some(Value::String(s)) => Ok(Value::String(s.clone())), @@ -279,8 +367,12 @@ impl Tool for InternTool { /// UNINTERN - Remove symbol from package pub struct UninternTool; impl Tool for UninternTool { - fn name(&self) -> &str { "UNINTERN" } - fn description(&self) -> &str { "Remove symbol from package" } + fn name(&self) -> &str { + "UNINTERN" + } + fn description(&self) -> &str { + "Remove symbol from package" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept symbol and optional package Ok(Value::Bool(true)) @@ -290,17 +382,19 @@ impl Tool for UninternTool { /// FIND-SYMBOL - Find symbol in package pub struct FindSymbolTool; impl Tool for FindSymbolTool { - fn name(&self) -> &str { "FIND-SYMBOL" } - fn description(&self) -> &str { "Find symbol in package" } + fn name(&self) -> &str { + "FIND-SYMBOL" + } + fn description(&self) -> &str { + "Find symbol in package" + } fn execute(&self, args: &[Value]) -> Result { // Returns (symbol, status) match args.get(0) { - Some(s @ Value::String(_)) => { - Ok(Value::Array(Arc::new(vec![ - s.clone(), - Value::String(":INTERNAL".to_string()), - ]))) - } + Some(s @ Value::String(_)) => Ok(Value::Array(Arc::new(vec![ + s.clone(), + Value::String(":INTERNAL".to_string()), + ]))), _ => Ok(Value::Array(Arc::new(vec![Value::Null, Value::Null]))), } } @@ -313,20 +407,36 @@ impl Tool for FindSymbolTool { /// DEFINE-SYMBOL-MACRO - Define symbol macro pub struct DefineSymbolMacroTool; impl Tool for DefineSymbolMacroTool { - fn name(&self) -> &str { "DEFINE-SYMBOL-MACRO" } - fn description(&self) -> &str { "Define symbol macro" } + fn name(&self) -> &str { + "DEFINE-SYMBOL-MACRO" + } + fn description(&self) -> &str { + "Define symbol macro" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// SYMBOL-MACROLET - Local symbol macros pub struct SymbolMacroletTool; impl Tool for SymbolMacroletTool { - fn name(&self) -> &str { "SYMBOL-MACROLET" } - fn description(&self) -> &str { "Establish local symbol macros" } + fn name(&self) -> &str { + "SYMBOL-MACROLET" + } + fn description(&self) -> &str { + "Establish local symbol macros" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.len() > 1 { args[args.len() - 1].clone() } else { Value::Null }) + Ok(if args.len() > 1 { + args[args.len() - 1].clone() + } else { + Value::Null + }) } } @@ -337,30 +447,54 @@ impl Tool for SymbolMacroletTool { /// DEFVAR - Define special variable pub struct DefvarTool; impl Tool for DefvarTool { - fn name(&self) -> &str { "DEFVAR" } - fn description(&self) -> &str { "Define special variable" } + fn name(&self) -> &str { + "DEFVAR" + } + fn description(&self) -> &str { + "Define special variable" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DEFPARAMETER - Define and initialize special variable pub struct DefparameterTool; impl Tool for DefparameterTool { - fn name(&self) -> &str { "DEFPARAMETER" } - fn description(&self) -> &str { "Define and initialize special variable" } + fn name(&self) -> &str { + "DEFPARAMETER" + } + fn description(&self) -> &str { + "Define and initialize special variable" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// DEFCONSTANT - Define constant pub struct DefconstantTool; impl Tool for DefconstantTool { - fn name(&self) -> &str { "DEFCONSTANT" } - fn description(&self) -> &str { "Define constant symbol" } + fn name(&self) -> &str { + "DEFCONSTANT" + } + fn description(&self) -> &str { + "Define constant symbol" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } diff --git a/crates/ovsm/src/tools/stdlib/system.rs b/crates/ovsm/src/tools/stdlib/system.rs index 23cdd0db5..8f584eaa3 100644 --- a/crates/ovsm/src/tools/stdlib/system.rs +++ b/crates/ovsm/src/tools/stdlib/system.rs @@ -19,20 +19,28 @@ use std::sync::Arc; /// GETENV - Get environment variable pub struct GetenvTool; impl Tool for GetenvTool { - fn name(&self) -> &str { "GETENV" } - fn description(&self) -> &str { "Get environment variable value" } + fn name(&self) -> &str { + "GETENV" + } + fn description(&self) -> &str { + "Get environment variable value" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "GETENV requires variable name".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "GETENV requires variable name".to_string(), + }); } match &args[0] { - Value::String(var_name) => { - match env::var(var_name) { - Ok(value) => Ok(Value::String(value)), - Err(_) => Ok(Value::Null), - } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Value::String(var_name) => match env::var(var_name) { + Ok(value) => Ok(Value::String(value)), + Err(_) => Ok(Value::Null), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -40,18 +48,28 @@ impl Tool for GetenvTool { /// SETENV - Set environment variable pub struct SetenvTool; impl Tool for SetenvTool { - fn name(&self) -> &str { "SETENV" } - fn description(&self) -> &str { "Set environment variable" } + fn name(&self) -> &str { + "SETENV" + } + fn description(&self) -> &str { + "Set environment variable" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "SETENV requires name and value".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "SETENV requires name and value".to_string(), + }); } match (&args[0], &args[1]) { (Value::String(name), Value::String(value)) => { env::set_var(name, value); Ok(Value::Bool(true)) } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -59,18 +77,28 @@ impl Tool for SetenvTool { /// UNSETENV - Unset environment variable pub struct UnsetenvTool; impl Tool for UnsetenvTool { - fn name(&self) -> &str { "UNSETENV" } - fn description(&self) -> &str { "Unset environment variable" } + fn name(&self) -> &str { + "UNSETENV" + } + fn description(&self) -> &str { + "Unset environment variable" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "UNSETENV requires variable name".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "UNSETENV requires variable name".to_string(), + }); } match &args[0] { Value::String(name) => { env::remove_var(name); Ok(Value::Bool(true)) } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -78,8 +106,12 @@ impl Tool for UnsetenvTool { /// ENVIRONMENT - Get all environment variables pub struct EnvironmentTool; impl Tool for EnvironmentTool { - fn name(&self) -> &str { "ENVIRONMENT" } - fn description(&self) -> &str { "Get all environment variables as object" } + fn name(&self) -> &str { + "ENVIRONMENT" + } + fn description(&self) -> &str { + "Get all environment variables as object" + } fn execute(&self, _args: &[Value]) -> Result { let mut env_map = HashMap::new(); for (key, value) in env::vars() { @@ -96,8 +128,12 @@ impl Tool for EnvironmentTool { /// EXIT - Exit program pub struct ExitTool; impl Tool for ExitTool { - fn name(&self) -> &str { "EXIT" } - fn description(&self) -> &str { "Exit program with status code" } + fn name(&self) -> &str { + "EXIT" + } + fn description(&self) -> &str { + "Exit program with status code" + } fn execute(&self, args: &[Value]) -> Result { let code = if args.is_empty() { 0 @@ -116,8 +152,12 @@ impl Tool for ExitTool { /// QUIT - Quit program (alias for EXIT) pub struct QuitTool; impl Tool for QuitTool { - fn name(&self) -> &str { "QUIT" } - fn description(&self) -> &str { "Quit program (alias for EXIT)" } + fn name(&self) -> &str { + "QUIT" + } + fn description(&self) -> &str { + "Quit program (alias for EXIT)" + } fn execute(&self, args: &[Value]) -> Result { ExitTool.execute(args) } @@ -126,11 +166,18 @@ impl Tool for QuitTool { /// RUN-PROGRAM - Run external program pub struct RunProgramTool; impl Tool for RunProgramTool { - fn name(&self) -> &str { "RUN-PROGRAM" } - fn description(&self) -> &str { "Run external program with arguments" } + fn name(&self) -> &str { + "RUN-PROGRAM" + } + fn description(&self) -> &str { + "Run external program with arguments" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "RUN-PROGRAM requires program name".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "RUN-PROGRAM requires program name".to_string(), + }); } // Simplified: just return success status // Real implementation would use std::process::Command @@ -146,8 +193,12 @@ impl Tool for RunProgramTool { /// GET-PID - Get current process ID pub struct GetPidTool; impl Tool for GetPidTool { - fn name(&self) -> &str { "GET-PID" } - fn description(&self) -> &str { "Get current process ID" } + fn name(&self) -> &str { + "GET-PID" + } + fn description(&self) -> &str { + "Get current process ID" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::Int(std::process::id() as i64)) } @@ -160,8 +211,12 @@ impl Tool for GetPidTool { /// MACHINE-TYPE - Get machine type pub struct MachineTypeTool; impl Tool for MachineTypeTool { - fn name(&self) -> &str { "MACHINE-TYPE" } - fn description(&self) -> &str { "Get machine type/architecture" } + fn name(&self) -> &str { + "MACHINE-TYPE" + } + fn description(&self) -> &str { + "Get machine type/architecture" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(std::env::consts::ARCH.to_string())) } @@ -170,18 +225,30 @@ impl Tool for MachineTypeTool { /// MACHINE-VERSION - Get machine version pub struct MachineVersionTool; impl Tool for MachineVersionTool { - fn name(&self) -> &str { "MACHINE-VERSION" } - fn description(&self) -> &str { "Get machine version" } + fn name(&self) -> &str { + "MACHINE-VERSION" + } + fn description(&self) -> &str { + "Get machine version" + } fn execute(&self, _args: &[Value]) -> Result { - Ok(Value::String(format!("{}-{}", std::env::consts::ARCH, std::env::consts::OS))) + Ok(Value::String(format!( + "{}-{}", + std::env::consts::ARCH, + std::env::consts::OS + ))) } } /// SOFTWARE-TYPE - Get software/OS type pub struct SoftwareTypeTool; impl Tool for SoftwareTypeTool { - fn name(&self) -> &str { "SOFTWARE-TYPE" } - fn description(&self) -> &str { "Get operating system type" } + fn name(&self) -> &str { + "SOFTWARE-TYPE" + } + fn description(&self) -> &str { + "Get operating system type" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(std::env::consts::OS.to_string())) } @@ -190,8 +257,12 @@ impl Tool for SoftwareTypeTool { /// SOFTWARE-VERSION - Get software/OS version pub struct SoftwareVersionTool; impl Tool for SoftwareVersionTool { - fn name(&self) -> &str { "SOFTWARE-VERSION" } - fn description(&self) -> &str { "Get operating system version" } + fn name(&self) -> &str { + "SOFTWARE-VERSION" + } + fn description(&self) -> &str { + "Get operating system version" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(std::env::consts::OS.to_string())) } @@ -200,8 +271,12 @@ impl Tool for SoftwareVersionTool { /// LISP-IMPLEMENTATION-TYPE - Get Lisp implementation type pub struct LispImplementationTypeTool; impl Tool for LispImplementationTypeTool { - fn name(&self) -> &str { "LISP-IMPLEMENTATION-TYPE" } - fn description(&self) -> &str { "Get Lisp implementation type" } + fn name(&self) -> &str { + "LISP-IMPLEMENTATION-TYPE" + } + fn description(&self) -> &str { + "Get Lisp implementation type" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String("OVSM".to_string())) } @@ -210,8 +285,12 @@ impl Tool for LispImplementationTypeTool { /// LISP-IMPLEMENTATION-VERSION - Get Lisp implementation version pub struct LispImplementationVersionTool; impl Tool for LispImplementationVersionTool { - fn name(&self) -> &str { "LISP-IMPLEMENTATION-VERSION" } - fn description(&self) -> &str { "Get Lisp implementation version" } + fn name(&self) -> &str { + "LISP-IMPLEMENTATION-VERSION" + } + fn description(&self) -> &str { + "Get Lisp implementation version" + } fn execute(&self, _args: &[Value]) -> Result { Ok(Value::String(env!("CARGO_PKG_VERSION").to_string())) } @@ -220,20 +299,32 @@ impl Tool for LispImplementationVersionTool { /// SHORT-SITE-NAME - Get short site name pub struct ShortSiteNameTool; impl Tool for ShortSiteNameTool { - fn name(&self) -> &str { "SHORT-SITE-NAME" } - fn description(&self) -> &str { "Get short site name" } + fn name(&self) -> &str { + "SHORT-SITE-NAME" + } + fn description(&self) -> &str { + "Get short site name" + } fn execute(&self, _args: &[Value]) -> Result { - Ok(Value::String(env::var("HOSTNAME").unwrap_or_else(|_| "localhost".to_string()))) + Ok(Value::String( + env::var("HOSTNAME").unwrap_or_else(|_| "localhost".to_string()), + )) } } /// LONG-SITE-NAME - Get long site name pub struct LongSiteNameTool; impl Tool for LongSiteNameTool { - fn name(&self) -> &str { "LONG-SITE-NAME" } - fn description(&self) -> &str { "Get long site name" } + fn name(&self) -> &str { + "LONG-SITE-NAME" + } + fn description(&self) -> &str { + "Get long site name" + } fn execute(&self, _args: &[Value]) -> Result { - Ok(Value::String(env::var("HOSTNAME").unwrap_or_else(|_| "localhost".to_string()))) + Ok(Value::String( + env::var("HOSTNAME").unwrap_or_else(|_| "localhost".to_string()), + )) } } @@ -244,26 +335,31 @@ impl Tool for LongSiteNameTool { /// DIRECTORY - List directory contents pub struct DirectoryTool; impl Tool for DirectoryTool { - fn name(&self) -> &str { "DIRECTORY" } - fn description(&self) -> &str { "List directory contents" } + fn name(&self) -> &str { + "DIRECTORY" + } + fn description(&self) -> &str { + "List directory contents" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Array(Arc::new(vec![]))); } match &args[0] { - Value::String(path) => { - match std::fs::read_dir(path) { - Ok(entries) => { - let files: Vec = entries - .filter_map(|e| e.ok()) - .map(|e| Value::String(e.path().display().to_string())) - .collect(); - Ok(Value::Array(Arc::new(files))) - } - Err(_) => Ok(Value::Array(Arc::new(vec![]))), + Value::String(path) => match std::fs::read_dir(path) { + Ok(entries) => { + let files: Vec = entries + .filter_map(|e| e.ok()) + .map(|e| Value::String(e.path().display().to_string())) + .collect(); + Ok(Value::Array(Arc::new(files))) } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Err(_) => Ok(Value::Array(Arc::new(vec![]))), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -271,30 +367,34 @@ impl Tool for DirectoryTool { /// FILE-WRITE-DATE - Get file modification time pub struct FileWriteDateTool; impl Tool for FileWriteDateTool { - fn name(&self) -> &str { "FILE-WRITE-DATE" } - fn description(&self) -> &str { "Get file modification time" } + fn name(&self) -> &str { + "FILE-WRITE-DATE" + } + fn description(&self) -> &str { + "Get file modification time" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "FILE-WRITE-DATE requires file path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "FILE-WRITE-DATE requires file path".to_string(), + }); } match &args[0] { - Value::String(path) => { - match std::fs::metadata(path) { - Ok(metadata) => { - match metadata.modified() { - Ok(time) => { - match time.duration_since(std::time::UNIX_EPOCH) { - Ok(duration) => Ok(Value::Int(duration.as_secs() as i64)), - Err(_) => Ok(Value::Int(0)), - } - } - Err(_) => Ok(Value::Int(0)), - } - } - Err(_) => Ok(Value::Null), - } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Value::String(path) => match std::fs::metadata(path) { + Ok(metadata) => match metadata.modified() { + Ok(time) => match time.duration_since(std::time::UNIX_EPOCH) { + Ok(duration) => Ok(Value::Int(duration.as_secs() as i64)), + Err(_) => Ok(Value::Int(0)), + }, + Err(_) => Ok(Value::Int(0)), + }, + Err(_) => Ok(Value::Null), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -302,11 +402,18 @@ impl Tool for FileWriteDateTool { /// FILE-AUTHOR - Get file author pub struct FileAuthorTool; impl Tool for FileAuthorTool { - fn name(&self) -> &str { "FILE-AUTHOR" } - fn description(&self) -> &str { "Get file author/owner" } + fn name(&self) -> &str { + "FILE-AUTHOR" + } + fn description(&self) -> &str { + "Get file author/owner" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "FILE-AUTHOR requires file path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "FILE-AUTHOR requires file path".to_string(), + }); } // Simplified: return unknown Ok(Value::String("unknown".to_string())) @@ -316,20 +423,28 @@ impl Tool for FileAuthorTool { /// DELETE-FILE - Delete file pub struct DeleteFileTool; impl Tool for DeleteFileTool { - fn name(&self) -> &str { "DELETE-FILE" } - fn description(&self) -> &str { "Delete file" } + fn name(&self) -> &str { + "DELETE-FILE" + } + fn description(&self) -> &str { + "Delete file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "DELETE-FILE requires file path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "DELETE-FILE requires file path".to_string(), + }); } match &args[0] { - Value::String(path) => { - match std::fs::remove_file(path) { - Ok(_) => Ok(Value::Bool(true)), - Err(_) => Ok(Value::Bool(false)), - } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Value::String(path) => match std::fs::remove_file(path) { + Ok(_) => Ok(Value::Bool(true)), + Err(_) => Ok(Value::Bool(false)), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -337,11 +452,18 @@ impl Tool for DeleteFileTool { /// RENAME-FILE - Rename/move file pub struct RenameFileTool; impl Tool for RenameFileTool { - fn name(&self) -> &str { "RENAME-FILE" } - fn description(&self) -> &str { "Rename or move file" } + fn name(&self) -> &str { + "RENAME-FILE" + } + fn description(&self) -> &str { + "Rename or move file" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "RENAME-FILE requires old and new paths".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "RENAME-FILE requires old and new paths".to_string(), + }); } match (&args[0], &args[1]) { (Value::String(old_path), Value::String(new_path)) => { @@ -350,7 +472,10 @@ impl Tool for RenameFileTool { Err(_) => Ok(Value::Bool(false)), } } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -358,20 +483,28 @@ impl Tool for RenameFileTool { /// ENSURE-DIRECTORIES-EXIST - Create directory path pub struct EnsureDirectoriesExistTool; impl Tool for EnsureDirectoriesExistTool { - fn name(&self) -> &str { "ENSURE-DIRECTORIES-EXIST" } - fn description(&self) -> &str { "Create directory and parent directories" } + fn name(&self) -> &str { + "ENSURE-DIRECTORIES-EXIST" + } + fn description(&self) -> &str { + "Create directory and parent directories" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "ENSURE-DIRECTORIES-EXIST requires path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "ENSURE-DIRECTORIES-EXIST requires path".to_string(), + }); } match &args[0] { - Value::String(path) => { - match std::fs::create_dir_all(path) { - Ok(_) => Ok(Value::Bool(true)), - Err(_) => Ok(Value::Bool(false)), - } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Value::String(path) => match std::fs::create_dir_all(path) { + Ok(_) => Ok(Value::Bool(true)), + Err(_) => Ok(Value::Bool(false)), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -379,15 +512,25 @@ impl Tool for EnsureDirectoriesExistTool { /// FILE-EXISTS-P - Check if file exists pub struct FileExistsPTool; impl Tool for FileExistsPTool { - fn name(&self) -> &str { "FILE-EXISTS-P" } - fn description(&self) -> &str { "Check if file exists" } + fn name(&self) -> &str { + "FILE-EXISTS-P" + } + fn description(&self) -> &str { + "Check if file exists" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "FILE-EXISTS-P requires path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "FILE-EXISTS-P requires path".to_string(), + }); } match &args[0] { Value::String(path) => Ok(Value::Bool(std::path::Path::new(path).exists())), - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -395,15 +538,25 @@ impl Tool for FileExistsPTool { /// DIRECTORY-P - Check if path is directory pub struct DirectoryPTool; impl Tool for DirectoryPTool { - fn name(&self) -> &str { "DIRECTORY-P" } - fn description(&self) -> &str { "Check if path is a directory" } + fn name(&self) -> &str { + "DIRECTORY-P" + } + fn description(&self) -> &str { + "Check if path is a directory" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "DIRECTORY-P requires path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "DIRECTORY-P requires path".to_string(), + }); } match &args[0] { Value::String(path) => Ok(Value::Bool(std::path::Path::new(path).is_dir())), - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -411,15 +564,25 @@ impl Tool for DirectoryPTool { /// FILE-P - Check if path is file pub struct FilePTool; impl Tool for FilePTool { - fn name(&self) -> &str { "FILE-P" } - fn description(&self) -> &str { "Check if path is a file" } + fn name(&self) -> &str { + "FILE-P" + } + fn description(&self) -> &str { + "Check if path is a file" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "FILE-P requires path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "FILE-P requires path".to_string(), + }); } match &args[0] { Value::String(path) => Ok(Value::Bool(std::path::Path::new(path).is_file())), - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -431,8 +594,12 @@ impl Tool for FilePTool { /// GET-WORKING-DIRECTORY - Get current working directory pub struct GetWorkingDirectoryTool; impl Tool for GetWorkingDirectoryTool { - fn name(&self) -> &str { "GET-WORKING-DIRECTORY" } - fn description(&self) -> &str { "Get current working directory" } + fn name(&self) -> &str { + "GET-WORKING-DIRECTORY" + } + fn description(&self) -> &str { + "Get current working directory" + } fn execute(&self, _args: &[Value]) -> Result { match env::current_dir() { Ok(path) => Ok(Value::String(path.display().to_string())), @@ -444,20 +611,28 @@ impl Tool for GetWorkingDirectoryTool { /// SET-WORKING-DIRECTORY - Set current working directory pub struct SetWorkingDirectoryTool; impl Tool for SetWorkingDirectoryTool { - fn name(&self) -> &str { "SET-WORKING-DIRECTORY" } - fn description(&self) -> &str { "Set current working directory" } + fn name(&self) -> &str { + "SET-WORKING-DIRECTORY" + } + fn description(&self) -> &str { + "Set current working directory" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "SET-WORKING-DIRECTORY requires path".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "SET-WORKING-DIRECTORY requires path".to_string(), + }); } match &args[0] { - Value::String(path) => { - match env::set_current_dir(path) { - Ok(_) => Ok(Value::Bool(true)), - Err(_) => Ok(Value::Bool(false)), - } - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + Value::String(path) => match env::set_current_dir(path) { + Ok(_) => Ok(Value::Bool(true)), + Err(_) => Ok(Value::Bool(false)), + }, + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), } } } @@ -469,8 +644,12 @@ impl Tool for SetWorkingDirectoryTool { /// GET-UNIVERSAL-TIME - Get universal time pub struct GetUniversalTimeTool; impl Tool for GetUniversalTimeTool { - fn name(&self) -> &str { "GET-UNIVERSAL-TIME" } - fn description(&self) -> &str { "Get universal time (seconds since epoch)" } + fn name(&self) -> &str { + "GET-UNIVERSAL-TIME" + } + fn description(&self) -> &str { + "Get universal time (seconds since epoch)" + } fn execute(&self, _args: &[Value]) -> Result { match std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) { Ok(duration) => Ok(Value::Int(duration.as_secs() as i64)), @@ -482,14 +661,21 @@ impl Tool for GetUniversalTimeTool { /// GET-DECODED-TIME - Get decoded time pub struct GetDecodedTimeTool; impl Tool for GetDecodedTimeTool { - fn name(&self) -> &str { "GET-DECODED-TIME" } - fn description(&self) -> &str { "Get decoded time as object" } + fn name(&self) -> &str { + "GET-DECODED-TIME" + } + fn description(&self) -> &str { + "Get decoded time as object" + } fn execute(&self, _args: &[Value]) -> Result { // Simplified: return object with timestamp let mut time_obj = HashMap::new(); match std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) { Ok(duration) => { - time_obj.insert("timestamp".to_string(), Value::Int(duration.as_secs() as i64)); + time_obj.insert( + "timestamp".to_string(), + Value::Int(duration.as_secs() as i64), + ); } Err(_) => { time_obj.insert("timestamp".to_string(), Value::Int(0)); @@ -502,8 +688,12 @@ impl Tool for GetDecodedTimeTool { /// SLEEP - Sleep for specified seconds pub struct SleepTool; impl Tool for SleepTool { - fn name(&self) -> &str { "SLEEP" } - fn description(&self) -> &str { "Sleep for specified seconds" } + fn name(&self) -> &str { + "SLEEP" + } + fn description(&self) -> &str { + "Sleep for specified seconds" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); @@ -525,8 +715,12 @@ impl Tool for SleepTool { /// GET-INTERNAL-REAL-TIME - Get internal real time pub struct GetInternalRealTimeTool; impl Tool for GetInternalRealTimeTool { - fn name(&self) -> &str { "GET-INTERNAL-REAL-TIME" } - fn description(&self) -> &str { "Get internal real time in milliseconds" } + fn name(&self) -> &str { + "GET-INTERNAL-REAL-TIME" + } + fn description(&self) -> &str { + "Get internal real time in milliseconds" + } fn execute(&self, _args: &[Value]) -> Result { match std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) { Ok(duration) => Ok(Value::Int(duration.as_millis() as i64)), @@ -538,8 +732,12 @@ impl Tool for GetInternalRealTimeTool { /// GET-INTERNAL-RUN-TIME - Get internal run time pub struct GetInternalRunTimeTool; impl Tool for GetInternalRunTimeTool { - fn name(&self) -> &str { "GET-INTERNAL-RUN-TIME" } - fn description(&self) -> &str { "Get internal run time in milliseconds" } + fn name(&self) -> &str { + "GET-INTERNAL-RUN-TIME" + } + fn description(&self) -> &str { + "Get internal run time in milliseconds" + } fn execute(&self, _args: &[Value]) -> Result { // Simplified: same as real time GetInternalRealTimeTool.execute(_args) diff --git a/crates/ovsm/src/tools/stdlib/time_date.rs b/crates/ovsm/src/tools/stdlib/time_date.rs index 6ab237099..45a3ae042 100644 --- a/crates/ovsm/src/tools/stdlib/time_date.rs +++ b/crates/ovsm/src/tools/stdlib/time_date.rs @@ -19,8 +19,12 @@ use std::time::{SystemTime, UNIX_EPOCH}; /// GET-UNIVERSAL-TIME - Get current universal time pub struct GetUniversalTimeTool; impl Tool for GetUniversalTimeTool { - fn name(&self) -> &str { "GET-UNIVERSAL-TIME" } - fn description(&self) -> &str { "Get current time as universal time" } + fn name(&self) -> &str { + "GET-UNIVERSAL-TIME" + } + fn description(&self) -> &str { + "Get current time as universal time" + } fn execute(&self, _args: &[Value]) -> Result { // Universal time = seconds since 1900-01-01 00:00:00 // Unix epoch = 1970-01-01 00:00:00 = 2208988800 seconds after 1900 @@ -38,21 +42,25 @@ impl Tool for GetUniversalTimeTool { /// GET-DECODED-TIME - Get current time as decoded components pub struct GetDecodedTimeTool; impl Tool for GetDecodedTimeTool { - fn name(&self) -> &str { "GET-DECODED-TIME" } - fn description(&self) -> &str { "Get current time as decoded components" } + fn name(&self) -> &str { + "GET-DECODED-TIME" + } + fn description(&self) -> &str { + "Get current time as decoded components" + } fn execute(&self, _args: &[Value]) -> Result { // Returns: second, minute, hour, date, month, year, day-of-week, dst-p, timezone // Simplified implementation Ok(Value::Array(Arc::new(vec![ - Value::Int(0), // second - Value::Int(0), // minute - Value::Int(0), // hour - Value::Int(1), // date - Value::Int(1), // month - Value::Int(2025), // year - Value::Int(0), // day-of-week (Monday=0) + Value::Int(0), // second + Value::Int(0), // minute + Value::Int(0), // hour + Value::Int(1), // date + Value::Int(1), // month + Value::Int(2025), // year + Value::Int(0), // day-of-week (Monday=0) Value::Bool(false), // daylight saving time - Value::Int(0), // timezone offset + Value::Int(0), // timezone offset ]))) } } @@ -60,8 +68,12 @@ impl Tool for GetDecodedTimeTool { /// DECODE-UNIVERSAL-TIME - Decode universal time to components pub struct DecodeUniversalTimeTool; impl Tool for DecodeUniversalTimeTool { - fn name(&self) -> &str { "DECODE-UNIVERSAL-TIME" } - fn description(&self) -> &str { "Decode universal time to components" } + fn name(&self) -> &str { + "DECODE-UNIVERSAL-TIME" + } + fn description(&self) -> &str { + "Decode universal time to components" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Err(Error::InvalidArguments { @@ -72,15 +84,15 @@ impl Tool for DecodeUniversalTimeTool { // Returns: second, minute, hour, date, month, year, day-of-week, dst-p, timezone Ok(Value::Array(Arc::new(vec![ - Value::Int(0), // second - Value::Int(0), // minute - Value::Int(0), // hour - Value::Int(1), // date - Value::Int(1), // month - Value::Int(2025), // year - Value::Int(0), // day-of-week + Value::Int(0), // second + Value::Int(0), // minute + Value::Int(0), // hour + Value::Int(1), // date + Value::Int(1), // month + Value::Int(2025), // year + Value::Int(0), // day-of-week Value::Bool(false), // dst - Value::Int(0), // timezone + Value::Int(0), // timezone ]))) } } @@ -88,8 +100,12 @@ impl Tool for DecodeUniversalTimeTool { /// ENCODE-UNIVERSAL-TIME - Encode components to universal time pub struct EncodeUniversalTimeTool; impl Tool for EncodeUniversalTimeTool { - fn name(&self) -> &str { "ENCODE-UNIVERSAL-TIME" } - fn description(&self) -> &str { "Encode time components to universal time" } + fn name(&self) -> &str { + "ENCODE-UNIVERSAL-TIME" + } + fn description(&self) -> &str { + "Encode time components to universal time" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 6 { return Err(Error::InvalidArguments { @@ -111,8 +127,12 @@ impl Tool for EncodeUniversalTimeTool { /// TIME-ADD - Add duration to time pub struct TimeAddTool; impl Tool for TimeAddTool { - fn name(&self) -> &str { "TIME-ADD" } - fn description(&self) -> &str { "Add duration to universal time" } + fn name(&self) -> &str { + "TIME-ADD" + } + fn description(&self) -> &str { + "Add duration to universal time" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -134,8 +154,12 @@ impl Tool for TimeAddTool { /// TIME-SUBTRACT - Subtract times or duration pub struct TimeSubtractTool; impl Tool for TimeSubtractTool { - fn name(&self) -> &str { "TIME-SUBTRACT" } - fn description(&self) -> &str { "Subtract times or duration from time" } + fn name(&self) -> &str { + "TIME-SUBTRACT" + } + fn description(&self) -> &str { + "Subtract times or duration from time" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Err(Error::InvalidArguments { @@ -157,8 +181,12 @@ impl Tool for TimeSubtractTool { /// TIME< - Compare times (less than) pub struct TimeLessThanTool; impl Tool for TimeLessThanTool { - fn name(&self) -> &str { "TIME<" } - fn description(&self) -> &str { "Compare if time1 < time2" } + fn name(&self) -> &str { + "TIME<" + } + fn description(&self) -> &str { + "Compare if time1 < time2" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Bool(false)); @@ -174,8 +202,12 @@ impl Tool for TimeLessThanTool { /// TIME<= - Compare times (less than or equal) pub struct TimeLessEqualTool; impl Tool for TimeLessEqualTool { - fn name(&self) -> &str { "TIME<=" } - fn description(&self) -> &str { "Compare if time1 <= time2" } + fn name(&self) -> &str { + "TIME<=" + } + fn description(&self) -> &str { + "Compare if time1 <= time2" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Bool(false)); @@ -191,8 +223,12 @@ impl Tool for TimeLessEqualTool { /// TIME= - Compare times (equal) pub struct TimeEqualTool; impl Tool for TimeEqualTool { - fn name(&self) -> &str { "TIME=" } - fn description(&self) -> &str { "Compare if time1 = time2" } + fn name(&self) -> &str { + "TIME=" + } + fn description(&self) -> &str { + "Compare if time1 = time2" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Bool(false)); @@ -208,8 +244,12 @@ impl Tool for TimeEqualTool { /// SLEEP - Sleep for duration pub struct SleepTool; impl Tool for SleepTool { - fn name(&self) -> &str { "SLEEP" } - fn description(&self) -> &str { "Sleep for specified seconds" } + fn name(&self) -> &str { + "SLEEP" + } + fn description(&self) -> &str { + "Sleep for specified seconds" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::Null); diff --git a/crates/ovsm/src/tools/stdlib/type_predicates.rs b/crates/ovsm/src/tools/stdlib/type_predicates.rs index a011bb0bd..66c91a81b 100644 --- a/crates/ovsm/src/tools/stdlib/type_predicates.rs +++ b/crates/ovsm/src/tools/stdlib/type_predicates.rs @@ -632,9 +632,7 @@ impl Tool for EqualpTool { } let result = match (&args[0], &args[1]) { - (Value::String(s1), Value::String(s2)) => { - s1.to_lowercase() == s2.to_lowercase() - } + (Value::String(s1), Value::String(s2)) => s1.to_lowercase() == s2.to_lowercase(), _ => args[0] == args[1], }; diff --git a/crates/ovsm/src/tools/stdlib/types_extended.rs b/crates/ovsm/src/tools/stdlib/types_extended.rs index 279646e13..09e4692f8 100644 --- a/crates/ovsm/src/tools/stdlib/types_extended.rs +++ b/crates/ovsm/src/tools/stdlib/types_extended.rs @@ -17,18 +17,30 @@ use std::sync::Arc; /// DEFTYPE - Define new type pub struct DeftypeTool; impl Tool for DeftypeTool { - fn name(&self) -> &str { "DEFTYPE" } - fn description(&self) -> &str { "Define new type" } + fn name(&self) -> &str { + "DEFTYPE" + } + fn description(&self) -> &str { + "Define new type" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } /// TYPE-OF - Get type of value pub struct TypeOfTool; impl Tool for TypeOfTool { - fn name(&self) -> &str { "TYPE-OF" } - fn description(&self) -> &str { "Get type of value" } + fn name(&self) -> &str { + "TYPE-OF" + } + fn description(&self) -> &str { + "Get type of value" + } fn execute(&self, args: &[Value]) -> Result { if args.is_empty() { return Ok(Value::String("NULL".to_string())); @@ -50,11 +62,18 @@ impl Tool for TypeOfTool { /// TYPEP - Check if value is of type pub struct TypepTool; impl Tool for TypepTool { - fn name(&self) -> &str { "TYPEP" } - fn description(&self) -> &str { "Check if value is of specified type" } + fn name(&self) -> &str { + "TYPEP" + } + fn description(&self) -> &str { + "Check if value is of specified type" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "TYPEP requires value and type".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "TYPEP requires value and type".to_string(), + }); } let value = &args[0]; let type_spec = match &args[1] { @@ -81,8 +100,12 @@ impl Tool for TypepTool { /// SUBTYPEP - Check subtype relationship pub struct SubtypepTool; impl Tool for SubtypepTool { - fn name(&self) -> &str { "SUBTYPEP" } - fn description(&self) -> &str { "Check if type1 is subtype of type2" } + fn name(&self) -> &str { + "SUBTYPEP" + } + fn description(&self) -> &str { + "Check if type1 is subtype of type2" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { return Ok(Value::Bool(false)); @@ -95,11 +118,18 @@ impl Tool for SubtypepTool { /// COERCE - Coerce value to type pub struct CoerceTool; impl Tool for CoerceTool { - fn name(&self) -> &str { "COERCE" } - fn description(&self) -> &str { "Coerce value to specified type" } + fn name(&self) -> &str { + "COERCE" + } + fn description(&self) -> &str { + "Coerce value to specified type" + } fn execute(&self, args: &[Value]) -> Result { if args.len() < 2 { - return Err(Error::InvalidArguments { tool: "UNKNOWN".to_string(), reason: "COERCE requires value and type".to_string() }); + return Err(Error::InvalidArguments { + tool: "UNKNOWN".to_string(), + reason: "COERCE requires value and type".to_string(), + }); } let value = &args[0]; let type_spec = match &args[1] { @@ -108,40 +138,49 @@ impl Tool for CoerceTool { }; match type_spec.as_str() { - "INTEGER" | "INT" => { - match value { - Value::Int(n) => Ok(Value::Int(*n)), - Value::Float(f) => Ok(Value::Int(*f as i64)), - Value::String(s) => { - s.parse::() - .map(Value::Int) - .map_err(|_| Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }) - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + "INTEGER" | "INT" => match value { + Value::Int(n) => Ok(Value::Int(*n)), + Value::Float(f) => Ok(Value::Int(*f as i64)), + Value::String(s) => { + s.parse::() + .map(Value::Int) + .map_err(|_| Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }) } - } - "FLOAT" => { - match value { - Value::Float(f) => Ok(Value::Float(*f)), - Value::Int(n) => Ok(Value::Float(*n as f64)), - Value::String(s) => { - s.parse::() - .map(Value::Float) - .map_err(|_| Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }) - } - _ => Err(Error::TypeError { expected: "valid argument".to_string(), got: "invalid".to_string() }), + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), + }, + "FLOAT" => match value { + Value::Float(f) => Ok(Value::Float(*f)), + Value::Int(n) => Ok(Value::Float(*n as f64)), + Value::String(s) => { + s.parse::() + .map(Value::Float) + .map_err(|_| Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }) } - } - "STRING" => { - Ok(Value::String(format!("{}", match value { + _ => Err(Error::TypeError { + expected: "valid argument".to_string(), + got: "invalid".to_string(), + }), + }, + "STRING" => Ok(Value::String(format!( + "{}", + match value { Value::String(s) => s.clone(), Value::Int(n) => n.to_string(), Value::Float(f) => f.to_string(), Value::Bool(b) => b.to_string(), Value::Null => "null".to_string(), _ => "?".to_string(), - }))) - } + } + ))), _ => Ok(value.clone()), } } @@ -154,18 +193,30 @@ impl Tool for CoerceTool { /// SATISFIES - Type satisfying predicate pub struct SatisfiesTool; impl Tool for SatisfiesTool { - fn name(&self) -> &str { "SATISFIES" } - fn description(&self) -> &str { "Type satisfying predicate" } + fn name(&self) -> &str { + "SATISFIES" + } + fn description(&self) -> &str { + "Type satisfying predicate" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Bool(true) + } else { + args[0].clone() + }) } } /// MEMBER - Member type specifier pub struct MemberTypeTool; impl Tool for MemberTypeTool { - fn name(&self) -> &str { "MEMBER" } - fn description(&self) -> &str { "Member type specifier" } + fn name(&self) -> &str { + "MEMBER" + } + fn description(&self) -> &str { + "Member type specifier" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Array(Arc::new(args.to_vec()))) } @@ -174,10 +225,16 @@ impl Tool for MemberTypeTool { /// AND - Intersection type pub struct AndTypeTool; impl Tool for AndTypeTool { - fn name(&self) -> &str { "AND" } - fn description(&self) -> &str { "Intersection type specifier" } + fn name(&self) -> &str { + "AND" + } + fn description(&self) -> &str { + "Intersection type specifier" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { + Ok(if args.is_empty() { + Value::Bool(true) + } else { Value::Bool(args.iter().all(|v| v.is_truthy())) }) } @@ -186,10 +243,16 @@ impl Tool for AndTypeTool { /// OR - Union type pub struct OrTypeTool; impl Tool for OrTypeTool { - fn name(&self) -> &str { "OR" } - fn description(&self) -> &str { "Union type specifier" } + fn name(&self) -> &str { + "OR" + } + fn description(&self) -> &str { + "Union type specifier" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(false) } else { + Ok(if args.is_empty() { + Value::Bool(false) + } else { Value::Bool(args.iter().any(|v| v.is_truthy())) }) } @@ -198,10 +261,16 @@ impl Tool for OrTypeTool { /// NOT - Complement type pub struct NotTypeTool; impl Tool for NotTypeTool { - fn name(&self) -> &str { "NOT" } - fn description(&self) -> &str { "Complement type specifier" } + fn name(&self) -> &str { + "NOT" + } + fn description(&self) -> &str { + "Complement type specifier" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Bool(true) } else { + Ok(if args.is_empty() { + Value::Bool(true) + } else { Value::Bool(!args[0].is_truthy()) }) } @@ -210,8 +279,12 @@ impl Tool for NotTypeTool { /// VALUES - Multiple values type pub struct ValuesTool; impl Tool for ValuesTool { - fn name(&self) -> &str { "VALUES" } - fn description(&self) -> &str { "Multiple values type specifier" } + fn name(&self) -> &str { + "VALUES" + } + fn description(&self) -> &str { + "Multiple values type specifier" + } fn execute(&self, args: &[Value]) -> Result { Ok(Value::Array(Arc::new(args.to_vec()))) } @@ -220,10 +293,18 @@ impl Tool for ValuesTool { /// EQL - EQL type specifier pub struct EqlTypeTool; impl Tool for EqlTypeTool { - fn name(&self) -> &str { "EQL" } - fn description(&self) -> &str { "EQL type specifier" } + fn name(&self) -> &str { + "EQL" + } + fn description(&self) -> &str { + "EQL type specifier" + } fn execute(&self, args: &[Value]) -> Result { - Ok(if args.is_empty() { Value::Null } else { args[0].clone() }) + Ok(if args.is_empty() { + Value::Null + } else { + args[0].clone() + }) } } @@ -234,8 +315,12 @@ impl Tool for EqlTypeTool { /// INTEGER-TYPE - Integer type with range pub struct IntegerTypeTool; impl Tool for IntegerTypeTool { - fn name(&self) -> &str { "INTEGER-TYPE" } - fn description(&self) -> &str { "Integer type with optional range" } + fn name(&self) -> &str { + "INTEGER-TYPE" + } + fn description(&self) -> &str { + "Integer type with optional range" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept optional min and max Ok(Value::String("INTEGER".to_string())) @@ -245,8 +330,12 @@ impl Tool for IntegerTypeTool { /// FLOAT-TYPE - Float type with range pub struct FloatTypeTool; impl Tool for FloatTypeTool { - fn name(&self) -> &str { "FLOAT-TYPE" } - fn description(&self) -> &str { "Float type with optional range" } + fn name(&self) -> &str { + "FLOAT-TYPE" + } + fn description(&self) -> &str { + "Float type with optional range" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept optional min and max Ok(Value::String("FLOAT".to_string())) @@ -256,8 +345,12 @@ impl Tool for FloatTypeTool { /// RATIONAL-TYPE - Rational number type pub struct RationalTypeTool; impl Tool for RationalTypeTool { - fn name(&self) -> &str { "RATIONAL-TYPE" } - fn description(&self) -> &str { "Rational number type" } + fn name(&self) -> &str { + "RATIONAL-TYPE" + } + fn description(&self) -> &str { + "Rational number type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::String("RATIONAL".to_string())) @@ -267,8 +360,12 @@ impl Tool for RationalTypeTool { /// REAL-TYPE - Real number type pub struct RealTypeTool; impl Tool for RealTypeTool { - fn name(&self) -> &str { "REAL-TYPE" } - fn description(&self) -> &str { "Real number type" } + fn name(&self) -> &str { + "REAL-TYPE" + } + fn description(&self) -> &str { + "Real number type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::String("REAL".to_string())) @@ -278,8 +375,12 @@ impl Tool for RealTypeTool { /// COMPLEX-TYPE - Complex number type pub struct ComplexTypeTool; impl Tool for ComplexTypeTool { - fn name(&self) -> &str { "COMPLEX-TYPE" } - fn description(&self) -> &str { "Complex number type" } + fn name(&self) -> &str { + "COMPLEX-TYPE" + } + fn description(&self) -> &str { + "Complex number type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::String("COMPLEX".to_string())) @@ -293,8 +394,12 @@ impl Tool for ComplexTypeTool { /// ARRAY-TYPE - Array type with dimensions pub struct ArrayTypeTool; impl Tool for ArrayTypeTool { - fn name(&self) -> &str { "ARRAY-TYPE" } - fn description(&self) -> &str { "Array type with optional dimensions" } + fn name(&self) -> &str { + "ARRAY-TYPE" + } + fn description(&self) -> &str { + "Array type with optional dimensions" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation - should accept optional dimensions Ok(Value::String("ARRAY".to_string())) @@ -304,8 +409,12 @@ impl Tool for ArrayTypeTool { /// SIMPLE-ARRAY-TYPE - Simple array type pub struct SimpleArrayTypeTool; impl Tool for SimpleArrayTypeTool { - fn name(&self) -> &str { "SIMPLE-ARRAY-TYPE" } - fn description(&self) -> &str { "Simple array type" } + fn name(&self) -> &str { + "SIMPLE-ARRAY-TYPE" + } + fn description(&self) -> &str { + "Simple array type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::String("SIMPLE-ARRAY".to_string())) @@ -315,8 +424,12 @@ impl Tool for SimpleArrayTypeTool { /// VECTOR-TYPE - Vector type pub struct VectorTypeTool; impl Tool for VectorTypeTool { - fn name(&self) -> &str { "VECTOR-TYPE" } - fn description(&self) -> &str { "Vector type" } + fn name(&self) -> &str { + "VECTOR-TYPE" + } + fn description(&self) -> &str { + "Vector type" + } fn execute(&self, args: &[Value]) -> Result { let _ = args; // Placeholder implementation Ok(Value::String("VECTOR".to_string())) diff --git a/scripts/docker-run-macos.sh b/scripts/docker-run-macos.sh new file mode 100755 index 000000000..5cb178e7c --- /dev/null +++ b/scripts/docker-run-macos.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Helper script to run OSVM CLI in Docker on macOS +# Usage: ./scripts/docker-run-macos.sh [osvm arguments] + +# Build the image if it doesn't exist +if [[ "$(docker images -q osvm-cli:latest 2> /dev/null)" == "" ]]; then + echo "Building OSVM Docker image..." + docker build -f scripts/docker/Dockerfile-macos -t osvm-cli:latest . +fi + +# Run OSVM in Docker with volume mounts for configuration +# Use -it only if we have a TTY +if [ -t 0 ]; then + docker run --rm -it \ + -v ~/.config/solana:/home/osvm/.config/solana:ro \ + -v ~/.osvm:/home/osvm/.osvm \ + osvm-cli:latest "$@" +else + docker run --rm \ + -v ~/.config/solana:/home/osvm/.config/solana:ro \ + -v ~/.osvm:/home/osvm/.osvm \ + osvm-cli:latest "$@" +fi + diff --git a/scripts/docker/Dockerfile-macos b/scripts/docker/Dockerfile-macos new file mode 100644 index 000000000..4ac53002b --- /dev/null +++ b/scripts/docker/Dockerfile-macos @@ -0,0 +1,71 @@ +# Multi-stage build for osvm CLI (macOS-specific) +FROM rust:1.87-slim AS builder + +# Install dependencies for building +RUN apt-get update && apt-get install -y \ + pkg-config \ + libssl-dev \ + libudev-dev \ + perl \ + make \ + g++ \ + build-essential \ + clang \ + libclang-dev \ + cmake \ + && rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /app + +# Copy dependency files first for better caching +COPY Cargo.toml Cargo.lock ./ +COPY rust-toolchain.toml ./ + +# Copy vendor directory if it exists +COPY vendor/ ./vendor/ + +# Copy workspace crates (includes ovsm crate) +COPY crates/ ./crates/ + +# Copy guest directory +COPY guest/ ./guest/ + +# Copy source code +COPY src/ ./src/ + +# Copy templates directory (required by include_str! macros in audit_templates.rs) +COPY templates/ ./templates/ + +# Copy assets directory (required for fonts) +COPY assets/ ./assets/ + +# Build the application +RUN cargo build --release + +# Runtime image +FROM debian:bookworm-slim + +# Install runtime dependencies +RUN apt-get update && apt-get install -y \ + ca-certificates \ + libudev1 \ + libssl3 \ + && rm -rf /var/lib/apt/lists/* + +# Create non-root user +RUN useradd -m -u 1000 osvm + +# Copy the binary from builder stage +COPY --from=builder /app/target/release/osvm /usr/local/bin/osvm + +# Make it executable +RUN chmod +x /usr/local/bin/osvm + +# Switch to non-root user +USER osvm + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/osvm"] +CMD ["--help"] + diff --git a/src/ai_config.rs b/src/ai_config.rs index 89f7a8d21..7b9215a4c 100644 --- a/src/ai_config.rs +++ b/src/ai_config.rs @@ -124,8 +124,7 @@ impl AiConfig { .with_context(|| format!("Failed to create directory {}", parent.display()))?; } - let yaml = serde_yaml::to_string(self) - .context("Failed to serialize AI config to YAML")?; + let yaml = serde_yaml::to_string(self).context("Failed to serialize AI config to YAML")?; fs::write(path, yaml) .with_context(|| format!("Failed to write AI config to {}", path.display()))?; @@ -206,7 +205,10 @@ impl AiConfig { max_tokens: 4000, timeout_secs: 120, }), - _ => anyhow::bail!("Unknown preset: {}. Available: openai, ollama, local, anthropic", name), + _ => anyhow::bail!( + "Unknown preset: {}. Available: openai, ollama, local, anthropic", + name + ), } } } diff --git a/src/commands/settings.rs b/src/commands/settings.rs index 55e95074f..ca6e35af7 100644 --- a/src/commands/settings.rs +++ b/src/commands/settings.rs @@ -68,13 +68,21 @@ async fn show_ai_settings() -> Result<()> { let config_path = AiConfig::default_config_path(); println!("{}", "๐Ÿค– AI Configuration".cyan().bold()); - println!(" {}: {}", "Config file".bright_black(), config_path.display()); + println!( + " {}: {}", + "Config file".bright_black(), + config_path.display() + ); println!(); println!(" {}: {}", "Provider".yellow(), config.provider); println!(" {}: {}", "API URL".yellow(), config.api_url); if let Some(key) = &config.api_key { - let masked_key = format!("{}...{}", &key[..8.min(key.len())], &key[key.len().saturating_sub(4)..]); + let masked_key = format!( + "{}...{}", + &key[..8.min(key.len())], + &key[key.len().saturating_sub(4)..] + ); println!(" {}: {}", "API Key".yellow(), masked_key); } else { println!(" {}: {}", "API Key".yellow(), "Not set".bright_black()); @@ -91,18 +99,36 @@ async fn show_ai_settings() -> Result<()> { Ok(_) => println!("{}", "โœ… Configuration is valid".green()), Err(e) => { println!("{}", format!("โš ๏ธ Configuration warning: {}", e).yellow()); - println!("{}", " Some features may not work correctly.".bright_black()); + println!( + "{}", + " Some features may not work correctly.".bright_black() + ); } } println!(); println!("{}", "Available Commands:".bright_black()); - println!(" {} - Switch to preset configuration", "osvm settings ai preset ".bright_white()); - println!(" {} - Set API URL", "osvm settings ai set-url ".bright_white()); - println!(" {} - Set API key", "osvm settings ai set-key ".bright_white()); - println!(" {} - Set model name", "osvm settings ai set-model ".bright_white()); + println!( + " {} - Switch to preset configuration", + "osvm settings ai preset ".bright_white() + ); + println!( + " {} - Set API URL", + "osvm settings ai set-url ".bright_white() + ); + println!( + " {} - Set API key", + "osvm settings ai set-key ".bright_white() + ); + println!( + " {} - Set model name", + "osvm settings ai set-model ".bright_white() + ); println!(); - println!("{}", "Available Presets: openai, ollama, local, anthropic".bright_black()); + println!( + "{}", + "Available Presets: openai, ollama, local, anthropic".bright_black() + ); Ok(()) } @@ -113,13 +139,22 @@ async fn set_preset(preset_name: &str) -> Result<()> { // If it's OpenAI or Anthropic, remind user to set the key if (config.is_openai_compatible() || preset_name == "anthropic") && config.api_key.is_none() { - println!("{}", format!("โš ๏ธ {} requires an API key", preset_name.to_uppercase()).yellow()); - println!("{}", " Set it with: osvm settings ai set-key ".bright_black()); + println!( + "{}", + format!("โš ๏ธ {} requires an API key", preset_name.to_uppercase()).yellow() + ); + println!( + "{}", + " Set it with: osvm settings ai set-key ".bright_black() + ); } config.save()?; - println!("{}", format!("โœ… AI configuration set to '{}' preset", preset_name).green()); + println!( + "{}", + format!("โœ… AI configuration set to '{}' preset", preset_name).green() + ); println!(); show_ai_settings().await } @@ -152,7 +187,10 @@ async fn set_ai_key(key: &str) -> Result<()> { config.save()?; println!("{}", "โœ… AI API key set successfully".green()); - println!("{}", " The key is stored securely in ~/.config/osvm/ai_config.yaml".bright_black()); + println!( + "{}", + " The key is stored securely in ~/.config/osvm/ai_config.yaml".bright_black() + ); Ok(()) } diff --git a/src/commands/snapshot.rs b/src/commands/snapshot.rs index 2047f6db2..843f2d4ea 100644 --- a/src/commands/snapshot.rs +++ b/src/commands/snapshot.rs @@ -181,13 +181,16 @@ fn get_snapshot_dir(matches: &ArgMatches) -> Result { } fn get_output_config(matches: &ArgMatches) -> Result { + // Check both --no-color flag and NO_COLOR environment variable + let colorized = !matches.get_flag("no-color") && std::env::var("NO_COLOR").is_err(); + Ok(OutputConfig { format: if matches.get_flag("json") { crate::services::snapshot_service::OutputFormat::Json } else { crate::services::snapshot_service::OutputFormat::Text }, - colorized: !matches.get_flag("no-color"), + colorized, quiet: matches.get_flag("quiet"), show_progress: !matches.get_flag("quiet"), human_readable: !matches.get_flag("json"), diff --git a/src/main.rs b/src/main.rs index 7a481cd90..135c0f077 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,6 +315,13 @@ async fn main() -> Result<(), Box> { return commands::ovsm_handler::handle_ovsm_command(sub_matches).await; } + // Handle snapshot command early - it doesn't need keypair or Solana config + if sub_command == "snapshot" { + return commands::snapshot::execute_snapshot_command(sub_matches) + .await + .map_err(|e| e.into()); + } + // Handle RPC early - it generates its own keypairs and doesn't need default config if sub_command == "rpc" { return commands::rpc_manager::handle_rpc_manager(sub_matches) diff --git a/src/services/ai_service.rs b/src/services/ai_service.rs index f0d1cce5d..be98afa68 100644 --- a/src/services/ai_service.rs +++ b/src/services/ai_service.rs @@ -1,7 +1,7 @@ use crate::utils::circuit_breaker::{ AnalysisVector as CircuitAnalysisVector, EndpointId, GranularCircuitBreaker, }; -use crate::utils::debug_logger::{VerbosityLevel, get_verbosity}; +use crate::utils::debug_logger::{get_verbosity, VerbosityLevel}; use crate::utils::prompt_templates::{ AnalysisVector as TemplateAnalysisVector, PromptTemplateManager, TemplateCategory, }; @@ -579,7 +579,8 @@ impl AiService { } async fn query_openai(&self, question: &str, debug_mode: bool) -> Result { - self.query_openai_with_system(question, None, debug_mode).await + self.query_openai_with_system(question, None, debug_mode) + .await } async fn query_openai_with_system( @@ -677,8 +678,11 @@ impl AiService { // For OSVM AI, use ownPlan parameter to get plan directly let ai_response = if self.use_openai { // OpenAI: send system prompt in messages - debug_print!("Sending OVSM plan request to OpenAI-compatible endpoint with system prompt"); - self.query_openai_with_system(&planning_prompt, Some(&ovsm_system_prompt), true).await? + debug_print!( + "Sending OVSM plan request to OpenAI-compatible endpoint with system prompt" + ); + self.query_openai_with_system(&planning_prompt, Some(&ovsm_system_prompt), true) + .await? } else { // OSVM AI: use ownPlan=true to get structured plan debug_print!("Sending OVSM plan request with custom system prompt"); @@ -1701,20 +1705,20 @@ Continue the code now:"#, let partial_char_count = partial.chars().count(); if partial_char_count > overlap_window { // Get the last overlap_window characters (not bytes!) - let partial_end: String = partial.chars() + let partial_end: String = partial + .chars() .skip(partial_char_count - overlap_window) .collect(); // Try to find overlap by checking progressively smaller substrings // Use character-aware iteration for skip in 0..partial_end.chars().count() { - let potential_overlap: String = partial_end.chars() - .skip(skip) - .collect(); + let potential_overlap: String = partial_end.chars().skip(skip).collect(); if cleaned_continuation.starts_with(&potential_overlap) { // Found overlap, skip it in continuation - let continuation_without_overlap = &cleaned_continuation[potential_overlap.len()..]; + let continuation_without_overlap = + &cleaned_continuation[potential_overlap.len()..]; return format!("{}{}", partial, continuation_without_overlap); } } @@ -2619,8 +2623,13 @@ mod tests { assert!(!local_config.is_openai_compatible()); // Test with_api_url direct configuration - let ai_service = AiService::with_api_url(Some("http://localhost:11434/v1/chat/completions".to_string())); + let ai_service = AiService::with_api_url(Some( + "http://localhost:11434/v1/chat/completions".to_string(), + )); assert!(ai_service.use_openai); - assert_eq!(ai_service.api_url, "http://localhost:11434/v1/chat/completions"); + assert_eq!( + ai_service.api_url, + "http://localhost:11434/v1/chat/completions" + ); } } diff --git a/src/services/mcp_service.rs b/src/services/mcp_service.rs index 17946c5ac..688da1fcd 100644 --- a/src/services/mcp_service.rs +++ b/src/services/mcp_service.rs @@ -7,7 +7,7 @@ use crate::services::unikernel_runtime::{UnikernelConfig, UnikernelRuntime}; use crate::utils::circuit_breaker::{ AnalysisVector as CircuitAnalysisVector, EndpointId, GranularCircuitBreaker, }; -use crate::utils::debug_logger::{VerbosityLevel, get_verbosity}; +use crate::utils::debug_logger::{get_verbosity, VerbosityLevel}; use crate::utils::input_sanitization; use crate::utils::path_security::create_secure_socket_dir; use crate::{debug_error, debug_print, debug_success, debug_warn}; diff --git a/src/utils/mcp_bridge.rs b/src/utils/mcp_bridge.rs index dd8c9349b..cf170f24a 100644 --- a/src/utils/mcp_bridge.rs +++ b/src/utils/mcp_bridge.rs @@ -1,6 +1,6 @@ //! MCP Bridge Tool - dynamically calls any configured MCP tool use crate::services::mcp_service::{McpService, McpTool}; -use crate::utils::debug_logger::{log_ovsm_value, get_verbosity, VerbosityLevel}; +use crate::utils::debug_logger::{get_verbosity, log_ovsm_value, VerbosityLevel}; use ovsm::error::Result as OvsmResult; use ovsm::runtime::Value as OvsmValue; use ovsm::tools::Tool; diff --git a/src/utils/streaming_agent.rs b/src/utils/streaming_agent.rs index b9ed5d669..c872e4137 100644 --- a/src/utils/streaming_agent.rs +++ b/src/utils/streaming_agent.rs @@ -340,7 +340,9 @@ fn extract_ovsm_code(raw_plan: &str) -> Option { } if get_verbosity() >= VerbosityLevel::Verbose { - eprintln!("DEBUG: No code blocks found in triple-backticks, trying Main Branch extraction..."); + eprintln!( + "DEBUG: No code blocks found in triple-backticks, trying Main Branch extraction..." + ); } // Strategy 2: Extract from Main Branch: section (with or without bold markers) @@ -1158,9 +1160,7 @@ pub async fn execute_streaming_agent(query: &str, verbose: u8, plan_only: bool) 6. DO NOT suggest additional steps or actions\n\ 7. Just present the final answer clearly and concisely\n\n\ Expected outcome: {}", - query, - ovsm_res, - tool_plan.expected_outcome + query, ovsm_res, tool_plan.expected_outcome ); match ai_service diff --git a/test-scripts/test-snapshot-docker.sh b/test-scripts/test-snapshot-docker.sh new file mode 100755 index 000000000..c5083752a --- /dev/null +++ b/test-scripts/test-snapshot-docker.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Test script for snapshot feature in Docker + +set -e + +echo "๐Ÿงช Testing OSVM Snapshot Feature in Docker" +echo "===========================================" +echo "" + +# Detect OS and set appropriate docker run script +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "๐Ÿ“Ÿ Detected macOS" + DOCKER_RUN="./scripts/docker-run-macos.sh" + DOCKERFILE="scripts/docker/Dockerfile-macos" +else + echo "๐Ÿ“Ÿ Detected Linux" + DOCKER_RUN="./scripts/docker/docker-run.sh" + DOCKERFILE="scripts/docker/Dockerfile" +fi + +# Check if Docker image exists +if [[ "$(docker images -q osvm-cli:latest 2> /dev/null)" == "" ]]; then + echo "โŒ Docker image not found. Build with:" + echo " docker build -f $DOCKERFILE -t osvm-cli:latest ." + exit 1 +fi + +echo "โœ… Docker image found" +echo "๐Ÿณ Using: $DOCKER_RUN" +echo "" + +# Test all help commands +for cmd in "snapshot" "snapshot read" "snapshot stats" "snapshot export" "snapshot compare" "snapshot validate" "snapshot find"; do + echo "Testing: $cmd --help" + $DOCKER_RUN $cmd --help > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "โœ… $cmd help works" + else + echo "โŒ $cmd help failed" + exit 1 + fi +done + +echo "" +echo "Testing error handling..." +$DOCKER_RUN snapshot read --snapshot-dir /nonexistent --limit 1 2>&1 | grep -q "does not exist" +if [ $? -eq 0 ]; then + echo "โœ… Error handling works" +else + echo "โš ๏ธ Error message check skipped" +fi + +echo "" +echo "๐ŸŽ‰ All tests passed!" + diff --git a/tests/osvm_a_e2e_tests.rs b/tests/osvm_a_e2e_tests.rs index db0bcabb6..724525c0b 100644 --- a/tests/osvm_a_e2e_tests.rs +++ b/tests/osvm_a_e2e_tests.rs @@ -59,15 +59,8 @@ fn test_osvm_a_basic_wallet_balance_query() { ); // Command should either produce output or not crash - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); - assert!( - !combined.is_empty(), - "Command should produce some output" - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); + assert!(!combined.is_empty(), "Command should produce some output"); } // ============================================================================ @@ -90,11 +83,7 @@ fn test_osvm_a_transaction_history_analysis() { ]); // Should not crash - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!( !combined.is_empty() || output.status.success(), "Command should execute without crashing" @@ -150,11 +139,7 @@ fn test_osvm_a_program_interaction_analysis() { ]); // Should complete without panicking - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!( !combined.contains("thread 'main' panicked"), "Command should not panic during program analysis" @@ -203,11 +188,7 @@ fn test_osvm_a_dex_trading_volume_analysis() { ]); // Should complete successfully or with planned execution - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); // Verify no unexpected errors assert!( @@ -237,11 +218,7 @@ fn test_osvm_a_complex_multi_condition_query() { ]); // Verify command completed without crashing - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!(!combined.is_empty(), "Command should produce output"); } @@ -264,11 +241,7 @@ fn test_osvm_a_nft_collection_activity() { ]); // Should complete without crashing on NFT-specific query - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!( !combined.is_empty(), @@ -296,11 +269,7 @@ fn test_osvm_a_sorting_and_aggregation_query() { ]); // Should handle sorting/aggregation directives - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!( !combined.contains("invalid") || combined.contains("plan") || combined.contains("agent"), @@ -330,10 +299,6 @@ fn test_osvm_a_planning_mode_full_pipeline() { ]); // Verify command completed without crashing - let combined = format!( - "{}{}", - output_stdout(&output), - output_stderr(&output) - ); + let combined = format!("{}{}", output_stdout(&output), output_stderr(&output)); assert!(!combined.is_empty(), "Command should produce output"); }