oftlisp-anf 0.1.3

An OftLisp backend using A-normal form.
Documentation
use std::io::Error as IoError;

use gc::Gc;
use oftlisp::{Symbol, Value};
use oftlisp::ast::ArgsBindingError;

use types::Context;

/// A compile error.
#[derive(Debug)]
pub enum CompileError {
    /// A bytes is too long to serialize.
    BytesTooLong(Gc<Vec<u8>>),

    /// A literal value was encountered that cannot be serialized.
    CannotSerialize(Value<Context>),

    /// An imported module is missing from the list of `ExportedModule`s. This
    /// should be impossible.
    MissingModule(Symbol),

    /// A string is too long to serialize.
    StringTooLong(Gc<String>),

    /// A symbol is too long to serialize.
    SymbolTooLong(Symbol),

    /// An unsupported number of arguments in a function definition was
    /// attempted to be serialized.
    TooManyArgsInDefn,

    /// An unsupported number of arguments in a function call was attempted to
    /// be serialized.
    TooManyArgsInCall,

    /// An unsupported number of decls was attempted to be serialized.
    TooManyDecls(Symbol),

    /// An unsupported number of exports was attempted to be serialized.
    TooManyExports(Symbol),

    /// An unsupported number of imports was attempted to be serialized.
    TooManyImports(Symbol),

    /// An unsupported number of symbols was attempted to be imported from a
    /// module.
    TooManyImportedSymbols(Symbol, Symbol),

    /// An unsupported number of modules was attempted to be serialized.
    TooManyModules,

    /// A vector is too long to serialize.
    VectorTooLong(Vec<Gc<Value<Context>>>),
}

/// A runtime error.
#[derive(Debug)]
pub enum RuntimeError {
    /// An error binding arguments.
    ArgsBindingError(ArgsBindingError<Context>),

    /// Exits with the given exit code.
    Exit(u8),

    /// An I/O error.
    Io(IoError),

    /// An attempt was made to access a non-existent data member on an object.
    InvalidVTable(Gc<Value<Context>>),

    /// A variable was used that was not defined.
    NonexistentVar(Symbol),

    /// A value that was not a function was called.
    NotAFunction(Gc<Value<Context>>),

    /// An attempt was made to access a non-existent data member on an object.
    ObjectDataOutOfBounds(isize, Gc<Value<Context>>),

    /// An attempt was made to access a non-existent function on an object.
    ObjectNoSuchFunc(Symbol, Gc<Value<Context>>),

    /// A runtime panic.
    Panic(Vec<Gc<Value<Context>>>),
}

impl From<ArgsBindingError<Context>> for RuntimeError {
    fn from(err: ArgsBindingError<Context>) -> RuntimeError {
        RuntimeError::ArgsBindingError(err)
    }
}

impl From<IoError> for RuntimeError {
    fn from(err: IoError) -> RuntimeError {
        RuntimeError::Io(err)
    }
}