Struct tin_lang::Tin

source ·
pub struct Tin { /* private fields */ }
Expand description

An instance of the Tin runtime.

Implementations

Creates a new instance of the Tin runtime.

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());

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.

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

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Tries to create the default.
Calls try_default and panics on an error case.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.