pub struct Tin { /* private fields */ }
Expand description
An instance of the Tin runtime.
Implementations
sourceimpl Tin
impl Tin
sourcepub fn load(&mut self, source: &str) -> Result<()>
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());
sourcepub fn graph(&self) -> Graph<'_>
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.
sourcepub fn compile(&mut self) -> Result<Module>
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
Auto Trait Implementations
impl !RefUnwindSafe for Tin
impl Send for Tin
impl Sync for Tin
impl Unpin for Tin
impl !UnwindSafe for Tin
Blanket Implementations
impl<T> Any for Twhere
T: Any,
impl<T> Any for Twhere
T: Any,
fn get_type_id(&self) -> TypeId
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
sourcefn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
sourcefn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.