Skip to main content

SwiftBackend

Struct SwiftBackend 

Source
pub struct SwiftBackend {
    pub emit_public: bool,
    pub emit_comments: bool,
    /* private fields */
}
Expand description

Swift code generation backend.

Compiles LCNF declarations/expressions to valid Swift source code. Entry points:

Fields§

§emit_public: bool

Whether to emit public declarations

§emit_comments: bool

Whether to emit inline comments

Implementations§

Source§

impl SwiftBackend

Source

pub fn new() -> Self

Create a new backend with default settings.

Source

pub fn fresh_var(&mut self) -> String

Allocate a fresh temporary variable name.

Source

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

Mangle an OxiLean name into a valid Swift identifier.

Rules:

  1. Empty input → "ox_empty"
  2. Swift keywords → prefixed with ox_
  3. Leading digit → prefixed with ox_
  4. Non-alphanumeric / non-underscore characters → replaced with _
Source

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

Compile an LCNF argument to a Swift expression.

Source

pub fn compile_lit(&self, lit: &LcnfLit) -> SwiftExpr

Compile an LCNF literal to a Swift expression.

Source

pub fn compile_expr(&self, expr: &LcnfExpr) -> Vec<SwiftStmt>

Compile an LCNF expression to a list of Swift statements.

The final statement is always a return.

Source

pub fn compile_let_value(&self, value: &LcnfLetValue) -> SwiftExpr

Compile a let-value to a Swift expression.

Source

pub fn compile_decl(&self, decl: &LcnfFunDecl) -> SwiftFunc

Compile a single LCNF function declaration to a SwiftFunc.

Source

pub fn compile_lcnf_type(&self, ty: &LcnfType) -> SwiftType

Map an LCNF type to the closest Swift type.

Source

pub fn compile_module(&self, name: &str, decls: &[LcnfFunDecl]) -> SwiftModule

Compile a collection of LCNF declarations into a SwiftModule.

Source

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

Emit a SwiftModule to a Swift source string.

Source

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

Emit a single SwiftFunc to a Swift source string.

Source

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

Emit a single SwiftTypeDecl to a Swift source string.

Trait Implementations§

Source§

impl Default for SwiftBackend

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.