Tin

Struct Tin 

Source
pub struct Tin { /* private fields */ }
Expand description

An instance of the Tin runtime.

Implementations§

Source§

impl Tin

Source

pub fn new() -> Tin

Creates a new instance of the Tin runtime.

Source

pub fn load(&mut self, source: &str) -> Result<()>

Loads the specified source code as a module.

§Errors

This function will return an error if the source code contains a syntax error or if the resulting logical structure has semantic errors or type errors.

Calling this function several times will load source code into the same module scope, but references in code from earlier calls will not be able to refer to definitions from code from later calls. Any references will eagerly be resolved and fail early.

§Examples

Loading a very basic module:

let mut tin = tin_lang::Tin::new();
tin.load("U32 = 0u32; main = || U32 { 42u32 };")?;

Unresolved references are not allowed:

let mut tin = tin_lang::Tin::new();
let result = tin.load("U32 = 0u32; main = || U32 { a };");
assert!(result.is_err());
Source

pub fn graph(&self) -> Graph<'_>

Creates a graph representation of the current IR of this Tin instance.

This can be used to for example visualize the code using GraphViz or other tools.

Source

pub fn compile(&mut self) -> Result<Module>

Compiles the code loaded so far into a stand-alone module.

This module is detached from the runtime and can be used even after the runtime has been dropped. Once all required Tin code has been loaded, it is therefore recommended to drop this instance and only keep the compiled module around.

§Examples

Compiling a very basic module:

let mut tin = tin_lang::Tin::new();
tin.load("U32 = 0u32; main = || U32 { 42u32 };")?;

let mut module = tin.compile()?;
let main = module.function::<tin_lang::module::Function0<u32>>("main").unwrap();

let result = main();
assert_eq!(42, result);

Trait Implementations§

Source§

impl Debug for Tin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tin

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Tin

§

impl !RefUnwindSafe for Tin

§

impl Send for Tin

§

impl Sync for Tin

§

impl Unpin for Tin

§

impl !UnwindSafe for Tin

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> Any for T
where T: Any,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
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.
Source§

impl<T> Erased for T

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,