pub struct Compiler<'a> { /* private fields */ }Expand description
Compiles Do source to bytecode.
Implementations§
Source§impl<'a> Compiler<'a>
impl<'a> Compiler<'a>
Sourcepub fn new(path: &'a Path, content: &'a [u8]) -> Self
pub fn new(path: &'a Path, content: &'a [u8]) -> Self
Create new compiler instance
§Arguments
path: The path of the source file; used in backtracescontent: The source as a byte slice
Sourcepub fn mode(&mut self, mode: Mode<'a>) -> &mut Self
pub fn mode(&mut self, mode: Mode<'a>) -> &mut Self
Change compilation mode
Default: Mode::Script
Sourcepub fn prelude(&mut self) -> Prelude<'a, '_>
pub fn prelude(&mut self) -> Prelude<'a, '_>
Configure a prelude, a collection of standard imports which are injected into the code.
Note that prelude imports which are not referenced by the code are omitted from compilation, even if importing them would have side effects.
Sourcepub fn analyze<D: EmitDiag, T: EmitToken<Break = D::Break>>(
self,
diags: &mut D,
tokens: &mut T,
) -> Result<(), Error<D::Break>>
pub fn analyze<D: EmitDiag, T: EmitToken<Break = D::Break>>( self, diags: &mut D, tokens: &mut T, ) -> Result<(), Error<D::Break>>
Analyze source code, generating diagnostics and semantic tokens.
Ignores errors to the greatest extent possible, other than a request
by either emitter to stop analysis. The two emitters must share a common
Break type.
The precise order of emitted tokens is not specified, but will be approximately in textual order. The precise interleaving of diagnostics and tokens is not specified.
§Arguments
diags: Where to send generated diagnostics.tokens: Where to send semantic tokens.
§Errors
ErrorKind::Fail: Compilation failed due to at least one fatal error. This should nearly never occur unless the source code is too severely malformed to process.ErrorKind::Break: Compilation was stopped by the diagnostic emitter.
Sourcepub fn compile<E: EmitDiag>(
self,
write: &mut impl Write,
diags: &mut E,
) -> Result<(), Error<E::Break>>
pub fn compile<E: EmitDiag>( self, write: &mut impl Write, diags: &mut E, ) -> Result<(), Error<E::Break>>
Compile the source
§Arguments
write: Where to write bytecode.diags: Where to send generated diagnostics.
§Errors
ErrorKind::Fail: Compilation failed due to at least one fatal error.ErrorKind::Break: Compilation was stopped by the diagnostic emitter.ErrorKind::Io: Writing bytecode failed with anio::Error.
Auto Trait Implementations§
impl<'a> !Freeze for Compiler<'a>
impl<'a> !RefUnwindSafe for Compiler<'a>
impl<'a> !Send for Compiler<'a>
impl<'a> !Sync for Compiler<'a>
impl<'a> Unpin for Compiler<'a>
impl<'a> UnsafeUnpin for Compiler<'a>
impl<'a> UnwindSafe for Compiler<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more