use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_json::Value;
pub const TSX_EXTENSION: &str = "tsx";
pub const ZF_JSON_EXTENSION: &str = "zf.json";
pub const COMPILE_TARGET_PIPELINE: &str = "pipeline";
pub const COMPILE_TARGET_BACKEND: &str = "backend";
pub const COMPILE_TARGET_FRONTEND: &str = "frontend";
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum SourceKind {
Tsx,
ZfJson,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModuleSource {
pub id: String,
pub source_path: Option<PathBuf>,
pub kind: SourceKind,
pub code: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProgramIr {
pub source_id: String,
pub kind: SourceKind,
pub body: Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompileOptions {
pub target: String,
pub optimize_level: u8,
pub emit_trace_hints: bool,
}
impl Default for CompileOptions {
fn default() -> Self {
Self {
target: COMPILE_TARGET_PIPELINE.to_string(),
optimize_level: 1,
emit_trace_hints: true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CompiledProgram {
pub engine_id: String,
pub source_id: String,
pub artifact: Vec<u8>,
pub metadata: Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionContext {
pub project: String,
pub pipeline: String,
pub request_id: String,
pub metadata: Value,
#[serde(default)]
pub trigger: Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionOutput {
pub value: Value,
pub trace: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LanguageError {
pub code: &'static str,
pub message: String,
}
impl LanguageError {
pub fn new(code: &'static str, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
}
}
}
impl Display for LanguageError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.code, self.message)
}
}
impl std::error::Error for LanguageError {}