aeri 0.2.5

Aeri is a Cardano smart contract language by Knott Dynamics, created by Trevor Knott, with its official compiler and CLI.
Documentation
//! Backend target constants and helper methods for emission selection.
//!
//! The `Target` enum and constants here drive blueprint metadata, output file
//! naming, and deployability flags.

use crate::{diagnostic::Result, ir::Program};

/// Textual IR compiler identifier used by preview artifacts.
pub const PREVIEW_COMPILER_TARGET: &str = "aeri-text-ir";
/// Preview builds are not directly deployable to Cardano.
pub const PREVIEW_CARDANO_DEPLOYABLE: bool = false;
/// Default blueprint filename for preview builds.
pub const PREVIEW_BLUEPRINT_FILE: &str = "blueprint.preview.json";
/// Default extension for rendered preview IR files.
pub const PREVIEW_SCRIPT_EXTENSION: &str = "aeri.ir";
/// UPLC/CBOR compiler identifier used in deployable blueprints.
pub const UPLC_COMPILER_TARGET: &str = "cardano-uplc-cbor";
/// UPLC builds are deployable when successfully emitted.
pub const UPLC_CARDANO_DEPLOYABLE: bool = true;
/// Default blueprint filename for UPLC builds.
pub const UPLC_BLUEPRINT_FILE: &str = "blueprint.uplc.json";
/// Default extension for emitted UPLC script JSON files.
pub const UPLC_SCRIPT_EXTENSION: &str = "plutus.json";
/// Plutus version string used in deployed blueprints.
pub const UPLC_PLUTUS_VERSION: &str = "PlutusV2";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Emission target for compile and inspection operations.
pub enum Target {
    /// Human-readable preview target: text IR and non-deployable metadata.
    Preview,
    /// Constrained, deployable UPLC emission target.
    Uplc,
}

impl Target {
    /// Returns the CLI/config key for this target (`preview` or `uplc`).
    pub fn name(self) -> &'static str {
        match self {
            Self::Preview => "preview",
            Self::Uplc => "uplc",
        }
    }

    /// Returns whether the target is implemented in this release.
    pub fn implemented(self) -> bool {
        true
    }

    /// Returns `Ok(())` when the target can be used by the CLI.
    ///
    /// The `label` is included for consistency with future diagnostics and is
    /// currently preserved for API stability.
    pub fn ensure_supported(self, label: &str) -> Result<()> {
        let _ = label;
        Ok(())
    }

    /// Returns the backend compiler identifier string used in blueprints.
    pub fn compiler_target(self) -> Option<&'static str> {
        match self {
            Self::Preview => Some(PREVIEW_COMPILER_TARGET),
            Self::Uplc => Some(UPLC_COMPILER_TARGET),
        }
    }

    /// Returns whether this target is marked deployable in emitted metadata.
    pub fn cardano_deployable(self) -> Option<bool> {
        match self {
            Self::Preview => Some(PREVIEW_CARDANO_DEPLOYABLE),
            Self::Uplc => Some(UPLC_CARDANO_DEPLOYABLE),
        }
    }
}

/// Renders validated IR to preview textual IR format.
pub fn render_preview_program(program: &Program) -> String {
    program.render()
}

/// Standardized message describing unsupported features in the UPLC path.
pub fn unsupported_uplc_message() -> &'static str {
    "target 'uplc' only supports validators that lower to the current serializable UPLC subset. Unsupported features still report explicit blockers."
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn preview_target_declares_non_deployable_text_ir() {
        assert_eq!(Target::Preview.name(), "preview");
        assert!(Target::Preview.implemented());
        assert_eq!(Target::Preview.compiler_target(), Some("aeri-text-ir"));
        assert_eq!(Target::Preview.cardano_deployable(), Some(false));
    }

    #[test]
    fn uplc_target_has_no_fake_metadata() {
        assert_eq!(Target::Uplc.name(), "uplc");
        assert!(Target::Uplc.implemented());
        assert_eq!(Target::Uplc.compiler_target(), Some("cardano-uplc-cbor"));
        assert_eq!(Target::Uplc.cardano_deployable(), Some(true));
    }
}