[−][src]Struct passerine::compiler::gen::Compiler
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() -> 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
.
pub fn exit_scope(&mut self) -> Compiler
[src]
Restore the enclosing compiler, returning the nested one for data extraction.
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]
pub fn label(
&mut self,
name: String,
expression: Spanned<CST>
) -> Result<(), Syntax>
[src]
&mut self,
name: String,
expression: Spanned<CST>
) -> Result<(), Syntax>
pub fn resolve_assign(&mut self, name: &str)
[src]
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]
&mut self,
pattern: Spanned<CSTPattern>,
expression: Spanned<CST>
) -> Result<(), Syntax>
Assign a value to a variable.
pub fn lambda(
&mut self,
pattern: Spanned<CSTPattern>,
expression: Spanned<CST>
) -> Result<(), Syntax>
[src]
&mut self,
pattern: Spanned<CSTPattern>,
expression: Spanned<CST>
) -> Result<(), Syntax>
Recursively compiles a lambda declaration in a new scope.
pub fn call(
&mut self,
fun: Spanned<CST>,
arg: Spanned<CST>
) -> Result<(), Syntax>
[src]
&mut self,
fun: Spanned<CST>,
arg: Spanned<CST>
) -> Result<(), Syntax>
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,