use crate::{diagnostic::Result, ir::Program};
pub const PREVIEW_COMPILER_TARGET: &str = "aeri-text-ir";
pub const PREVIEW_CARDANO_DEPLOYABLE: bool = false;
pub const PREVIEW_BLUEPRINT_FILE: &str = "blueprint.preview.json";
pub const PREVIEW_SCRIPT_EXTENSION: &str = "aeri.ir";
pub const UPLC_COMPILER_TARGET: &str = "cardano-uplc-cbor";
pub const UPLC_CARDANO_DEPLOYABLE: bool = true;
pub const UPLC_BLUEPRINT_FILE: &str = "blueprint.uplc.json";
pub const UPLC_SCRIPT_EXTENSION: &str = "plutus.json";
pub const UPLC_PLUTUS_VERSION: &str = "PlutusV2";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Target {
Preview,
Uplc,
}
impl Target {
pub fn name(self) -> &'static str {
match self {
Self::Preview => "preview",
Self::Uplc => "uplc",
}
}
pub fn implemented(self) -> bool {
true
}
pub fn ensure_supported(self, label: &str) -> Result<()> {
let _ = label;
Ok(())
}
pub fn compiler_target(self) -> Option<&'static str> {
match self {
Self::Preview => Some(PREVIEW_COMPILER_TARGET),
Self::Uplc => Some(UPLC_COMPILER_TARGET),
}
}
pub fn cardano_deployable(self) -> Option<bool> {
match self {
Self::Preview => Some(PREVIEW_CARDANO_DEPLOYABLE),
Self::Uplc => Some(UPLC_CARDANO_DEPLOYABLE),
}
}
}
pub fn render_preview_program(program: &Program) -> String {
program.render()
}
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));
}
}