pub mod analyzer;
pub mod host;
pub mod parser;
pub mod project;
pub mod testgen;
pub mod toml_config;
pub mod types;
pub mod native_proto;
pub mod pipeline;
pub mod cabi;
pub mod zigir;
pub(crate) mod infer;
pub(crate) mod jsdoc;
pub(crate) mod native_builtins;
#[cfg(test)]
pub(crate) mod tests;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HostType {
Void,
Bool,
I32,
I64,
F64,
Str, }
#[derive(Debug, Clone)]
pub struct HostFunction {
pub name: String,
pub params: Vec<HostType>,
pub return_type: Option<HostType>,
pub is_async: bool,
pub async_return_fields: Vec<(String, HostType)>,
}
impl HostFunction {
pub fn struct_zig_name(&self) -> String {
format!("{}Result", toml_config::pascal_case(&self.name))
}
pub fn struct_c_name(&self) -> String {
format!("Host{}", self.struct_zig_name())
}
}
impl HostType {
pub fn to_zig_field_type(self) -> &'static str {
match self {
HostType::Void => "void",
HostType::Bool => "bool",
HostType::I32 => "i32",
HostType::I64 => "i64",
HostType::F64 => "f64",
HostType::Str => "[]const u8",
}
}
pub fn to_c_field_type(self) -> &'static str {
match self {
HostType::Void => "void",
HostType::Bool => "bool",
HostType::I32 => "i32",
HostType::I64 => "i64",
HostType::F64 => "f64",
HostType::Str => "[256]u8",
}
}
}
#[derive(Debug, Clone)]
pub struct HostConfig {
pub functions: Vec<HostFunction>,
}
#[derive(Debug, Clone, Default)]
pub struct BuildConfig {
pub force_rebuild: bool,
pub run_zig_build: bool,
pub zig_optimize: Option<String>,
pub is_build_script: bool,
}
#[derive(Debug, Clone)]
pub struct ProjectConfig {
pub js_dir: PathBuf,
pub js_files: Vec<String>,
pub out_dir: PathBuf,
pub host_config: Option<HostConfig>,
pub build: BuildConfig,
}
impl Default for ProjectConfig {
fn default() -> Self {
Self {
js_dir: PathBuf::from("."),
js_files: vec!["main.js".to_string()],
out_dir: PathBuf::from("out"),
host_config: None,
build: BuildConfig::default(),
}
}
}
#[derive(Debug, Default)]
pub struct ProjectResult {
pub project_name: String,
pub is_test: bool,
pub cabi_exports_json: String,
pub diagnostics: Vec<String>,
}
pub fn transpile_project(config: &ProjectConfig) -> Result<ProjectResult, String> {
pipeline::transpile_project(config)
}
pub use cabi::write_cabi_metadata;