Skip to main content

Compiler

Struct Compiler 

Source
pub struct Compiler<'a> { /* private fields */ }
Expand description

Compiles Do source to bytecode.

Implementations§

Source§

impl<'a> Compiler<'a>

Source

pub fn new(path: &'a Path, content: &'a [u8]) -> Self

Create new compiler instance

§Arguments
  • path: The path of the source file; used in backtraces
  • content: The source as a byte slice
Source

pub fn mode(&mut self, mode: Mode<'a>) -> &mut Self

Change compilation mode

Default: Mode::Script

Source

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.

Source

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.
Source

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

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> 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.