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

pub struct Compiler { /* fields omitted */ }

Compiler is a bytecode generator that walks an CST 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(ffi: FFI) -> Compiler[src]

Construct a new Compiler.

pub fn declare(&mut self, name: String)[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, and moving the FFI into the current compiler.

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

Restore the enclosing compiler, returning the nested one for data (Lambda) extraction, and moving the FFI mappings back into the enclosing compiler.

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

Walks an CST to generate bytecode. At this stage, the CST should've been verified, pruned, typechecked, etc. A malformed CST will cause a panic, as CSTs 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)[src]

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

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

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

pub fn captured(&mut self, name: &str) -> Option<Captured>[src]

Tries to resolve a variable in enclosing scopes if resolution it successful, it captures the variable in the original scope then builds a chain of upvalues to hoist that upvalue where it's needed.

pub fn captured_upvalue(&mut self, name: &str) -> Option<usize>[src]

Returns the index of a captured non-local.

pub fn symbol(&mut self, name: &str, 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<CST>>) -> 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<CST>) -> Result<(), Syntax>[src]

Generates a print expression Note that currently printing is a baked-in language feature, but the second the FFI becomes a thing it'll no longer be one.

pub fn label(
    &mut self,
    name: String,
    expression: Spanned<CST>
) -> Result<(), Syntax>
[src]

Generates a Label construction that loads the variant, then wraps some data

pub fn tuple(&mut self, tuple: Vec<Spanned<CST>>) -> Result<(), Syntax>[src]

Generates a Tuple construction that loads all fields in the tuple then rips them off the stack into a vec.

pub fn ffi(
    &mut self,
    name: String,
    expression: Spanned<CST>,
    span: Span
) -> Result<(), Syntax>
[src]

Makes a Rust function callable from Passerine, by keeping a reference to that function.

pub fn resolve_assign(&mut self, name: &str) -> bool[src]

Resolves the assignment of a variable returns true if the variable was declared.

pub fn destructure(&mut self, pattern: Spanned<CSTPattern>, redeclare: bool)[src]

Destructures a pattern into a series of unpack and assign instructions. Instructions match against the topmost stack item. Does delete the data that is matched against.

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

Assign a value to a variable.

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

Recursively compiles a lambda declaration in a new scope.

pub fn call(
    &mut self,
    fun: Spanned<CST>,
    arg: Spanned<CST>
) -> 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

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.