Skip to main content

GoBackend

Struct GoBackend 

Source
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

Source

pub fn new() -> Self

Create a new GoBackend.

Source

pub fn mangle_name(name: &str) -> String

Mangle a name so that it is a valid, non-reserved Go identifier.

Rules:

  1. Replace ., -, /, with _.
  2. If empty → ox_empty.
  3. If starts with a digit → prefix with ox_.
  4. If a Go keyword or built-in → prefix with ox_.
Source

pub fn compile_module(&mut self, decls: &[LcnfFunDecl]) -> GoModule

Emit a Go module with the OxiLean runtime preamble and compiled declarations.

Source

pub fn compile_decl(&mut self, decl: &LcnfFunDecl) -> Option<GoFunc>

Compile a single LCNF declaration into a Go function.

Source

pub fn compile_type(&self, ty: &LcnfType) -> GoType

Compile an LCNF type to its Go equivalent.

Source

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.

Source

pub fn compile_arg(&self, arg: &LcnfArg) -> GoExpr

Compile an LcnfArg into a Go expression.

Source

pub fn emit_func(&self, func: &GoFunc) -> String

Emit a single GoFunc to a string.

Source

pub fn emit_type_decl(&self, decl: &GoTypeDecl) -> String

Emit a GoTypeDecl to a string.

Source

pub fn emit_module(&self, module: &GoModule) -> String

Emit a full GoModule to a string.

Trait Implementations§

Source§

impl Default for GoBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.