gaia-assembler 0.1.1

Universal assembler framework for Gaia project
Documentation
//! Lua backend compiler

use crate::{config::GaiaConfig, program::GaiaModule, Backend, GeneratedFiles};
use gaia_types::{
    helpers::{AbiCompatible, ApiCompatible, Architecture, ArtifactType, CompilationTarget},
    Result,
};
use std::collections::HashMap;

/// Lua Backend implementation
#[derive(Default)]
pub struct LuaBackend {}

impl Backend for LuaBackend {
    fn name(&self) -> &'static str {
        "Lua"
    }

    fn primary_target(&self) -> CompilationTarget {
        CompilationTarget { build: Architecture::Unknown, host: AbiCompatible::LuaBytecode, target: ApiCompatible::Unknown }
    }

    fn artifact_type(&self) -> ArtifactType {
        ArtifactType::Bytecode
    }

    fn match_score(&self, target: &CompilationTarget) -> f32 {
        if target.host == AbiCompatible::LuaBytecode {
            return 80.0;
        }
        0.0
    }

    fn generate(&self, _program: &GaiaModule, config: &GaiaConfig) -> Result<GeneratedFiles> {
        #[cfg(feature = "lua-assembler")]
        {
            Ok(GeneratedFiles { artifact_type: self.artifact_type(), files: HashMap::new(), custom: None, diagnostics: vec![] })
        }
        #[cfg(not(feature = "lua-assembler"))]
        {
            Err(gaia_types::GaiaError::custom_error("Lua feature is not enabled"))
        }
    }
}