code_transpiler/
native_go.rs1use crate::{emit, go_ir};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct NativeTranspileError(pub String);
5impl std::fmt::Display for NativeTranspileError {
6 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7 f.write_str(&self.0)
8 }
9}
10impl std::error::Error for NativeTranspileError {}
11
12pub fn native_go_to_target(code: &str, target: &str) -> Result<String, NativeTranspileError> {
13 let program = go_ir::parse_go(code).map_err(|e| NativeTranspileError(e.to_string()))?;
14 emit::emit(&program, target).map_err(|e| NativeTranspileError(e.to_string()))
15}
16
17pub fn native_go_to_rust(code: &str) -> Result<String, NativeTranspileError> {
18 native_go_to_target(code, "rust")
19}