mod ml_oracle;
mod oracle;
pub use ml_oracle::{
BaselinePredictor, BugPredictor, CodeFeatures, ComplexityPredictor, TestPrioritizer,
};
pub use oracle::{TranspilerOracle, TranspilerVerdict, TranspilerVerification, VerificationStats};
use crate::grammar::Grammar;
use crate::{Language, Result};
pub trait Transpiler: Send + Sync {
fn source_language(&self) -> Language;
fn target_language(&self) -> Language;
fn transpile(&self, source: &str) -> Result<String>;
fn grammar(&self) -> &dyn Grammar;
fn version(&self) -> &str;
}
#[derive(Debug, Clone)]
pub struct TranspilerConfig {
pub name: String,
pub source: Language,
pub target: Language,
pub strict: bool,
}
impl TranspilerConfig {
#[must_use]
pub fn depyler() -> Self {
Self {
name: "depyler".to_string(),
source: Language::Python,
target: Language::Rust,
strict: true,
}
}
#[must_use]
pub fn bashrs() -> Self {
Self {
name: "bashrs".to_string(),
source: Language::Bash,
target: Language::Rust,
strict: true,
}
}
#[must_use]
pub fn ruchy() -> Self {
Self {
name: "ruchy".to_string(),
source: Language::Ruchy,
target: Language::Rust,
strict: true,
}
}
#[must_use]
pub fn decy() -> Self {
Self {
name: "decy".to_string(),
source: Language::C,
target: Language::Rust,
strict: true,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_depyler_config() {
let config = TranspilerConfig::depyler();
assert_eq!(config.name, "depyler");
assert_eq!(config.source, Language::Python);
assert_eq!(config.target, Language::Rust);
assert!(config.strict);
}
#[test]
fn test_bashrs_config() {
let config = TranspilerConfig::bashrs();
assert_eq!(config.name, "bashrs");
assert_eq!(config.source, Language::Bash);
assert_eq!(config.target, Language::Rust);
assert!(config.strict);
}
#[test]
fn test_ruchy_config() {
let config = TranspilerConfig::ruchy();
assert_eq!(config.name, "ruchy");
assert_eq!(config.source, Language::Ruchy);
assert_eq!(config.target, Language::Rust);
assert!(config.strict);
}
#[test]
fn test_decy_config() {
let config = TranspilerConfig::decy();
assert_eq!(config.name, "decy");
assert_eq!(config.source, Language::C);
assert_eq!(config.target, Language::Rust);
assert!(config.strict);
}
#[test]
fn test_transpiler_config_debug() {
let config = TranspilerConfig::depyler();
let debug = format!("{:?}", config);
assert!(debug.contains("TranspilerConfig"));
assert!(debug.contains("depyler"));
}
#[test]
fn test_transpiler_config_clone() {
let config = TranspilerConfig::depyler();
let cloned = config.clone();
assert_eq!(cloned.name, config.name);
assert_eq!(cloned.source, config.source);
assert_eq!(cloned.target, config.target);
}
}