[][src]Struct passerine::compiler::gen::Compiler

pub struct Compiler { /* fields omitted */ }

Compiler is a bytecode generator that walks an AST and produces (unoptimized) Bytecode. There are plans to add a bytecode optimizer in the future. Note that this struct should not be controlled manually, use the gen function instead.

Implementations

impl Compiler[src]

pub fn base() -> Compiler[src]

Construct a new Compiler.

pub fn declare(&mut self, span: Span)[src]

Declare a local variable.

pub fn enter_scope(&mut self)[src]

Replace the current compiler with a fresh one, keeping a reference to the old one in self.enclosing.

pub fn exit_scope(&mut self) -> Compiler[src]

Restore the enclosing compiler, returning the nested one for data extraction.

pub fn walk(&mut self, ast: &Spanned<AST>) -> Result<(), Syntax>[src]

Walks an AST to generate bytecode. At this stage, the AST should've been verified, pruned, typechecked, etc. A malformed AST will cause a panic, as ASTs should be correct at this stage, and for them to be incorrect is an error in the compiler itself.

pub fn data(&mut self, data: Data) -> Result<(), Syntax>[src]

Takes a Data leaf and and produces some code to load the constant

pub fn local(&self, span: Span) -> Option<usize>[src]

Returns the relative position on the stack of a declared local, if it exists in the current scope.

pub fn capture(&mut self, captured: Captured) -> usize[src]

Marks a local as captured in a closure, which essentially tells the VM to move it to the heap. Returns the index of the captured variable.

pub fn captured(&mut self, span: Span) -> Option<usize>[src]

pub fn symbol(&mut self, span: Span) -> Result<(), Syntax>[src]

Takes a symbol leaf, and produces some code to load the local

pub fn block(&mut self, children: Vec<Spanned<AST>>) -> Result<(), Syntax>[src]

A block is a series of expressions where the last is returned. Each sup-expression is walked, the last value is left on the stack.

pub fn print(&mut self, expression: Spanned<AST>) -> Result<(), Syntax>[src]

pub fn assign(
    &mut self,
    symbol: Spanned<AST>,
    expression: Spanned<AST>
) -> Result<(), Syntax>
[src]

Assign a value to a variable.

pub fn lambda(
    &mut self,
    symbol: Spanned<AST>,
    expression: Spanned<AST>
) -> Result<(), Syntax>
[src]

Recursively compiles a lambda declaration in a new scope.

pub fn call(
    &mut self,
    fun: Spanned<AST>,
    arg: Spanned<AST>
) -> Result<(), Syntax>
[src]

When a function is called, the top two items are taken off the stack, The topmost item is expected to be a function.

Auto Trait Implementations

impl !RefUnwindSafe for Compiler

impl !Send for Compiler

impl !Sync for Compiler

impl Unpin for Compiler

impl !UnwindSafe for Compiler

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.