pub struct GoBackend { /* private fields */ }Expand description
The Go code generation backend.
Translates LCNF declarations and expressions into Go source code.
Implementations§
Source§impl GoBackend
impl GoBackend
Sourcepub fn mangle_name(name: &str) -> String
pub fn mangle_name(name: &str) -> String
Mangle a name so that it is a valid, non-reserved Go identifier.
Rules:
- Replace
.,-,/,with_. - If empty →
ox_empty. - If starts with a digit → prefix with
ox_. - If a Go keyword or built-in → prefix with
ox_.
Sourcepub fn compile_module(&mut self, decls: &[LcnfFunDecl]) -> GoModule
pub fn compile_module(&mut self, decls: &[LcnfFunDecl]) -> GoModule
Emit a Go module with the OxiLean runtime preamble and compiled declarations.
Sourcepub fn compile_decl(&mut self, decl: &LcnfFunDecl) -> Option<GoFunc>
pub fn compile_decl(&mut self, decl: &LcnfFunDecl) -> Option<GoFunc>
Compile a single LCNF declaration into a Go function.
Sourcepub fn compile_type(&self, ty: &LcnfType) -> GoType
pub fn compile_type(&self, ty: &LcnfType) -> GoType
Compile an LCNF type to its Go equivalent.
Sourcepub fn compile_expr(&mut self, expr: &LcnfExpr) -> Vec<GoStmt>
pub fn compile_expr(&mut self, expr: &LcnfExpr) -> Vec<GoStmt>
Compile an LCNF expression to a sequence of Go statements.
The last statement should be a return carrying the final value.
Sourcepub fn compile_arg(&self, arg: &LcnfArg) -> GoExpr
pub fn compile_arg(&self, arg: &LcnfArg) -> GoExpr
Compile an LcnfArg into a Go expression.
Sourcepub fn emit_type_decl(&self, decl: &GoTypeDecl) -> String
pub fn emit_type_decl(&self, decl: &GoTypeDecl) -> String
Emit a GoTypeDecl to a string.
Sourcepub fn emit_module(&self, module: &GoModule) -> String
pub fn emit_module(&self, module: &GoModule) -> String
Emit a full GoModule to a string.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GoBackend
impl RefUnwindSafe for GoBackend
impl Send for GoBackend
impl Sync for GoBackend
impl Unpin for GoBackend
impl UnsafeUnpin for GoBackend
impl UnwindSafe for GoBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more