oftlisp_anf/
errors.rs

1use std::io::Error as IoError;
2
3use gc::Gc;
4use oftlisp::{Symbol, Value};
5use oftlisp::ast::ArgsBindingError;
6
7use types::Context;
8
9/// A compile error.
10#[derive(Debug)]
11pub enum CompileError {
12    /// A bytes is too long to serialize.
13    BytesTooLong(Gc<Vec<u8>>),
14
15    /// A literal value was encountered that cannot be serialized.
16    CannotSerialize(Value<Context>),
17
18    /// An imported module is missing from the list of `ExportedModule`s. This
19    /// should be impossible.
20    MissingModule(Symbol),
21
22    /// A string is too long to serialize.
23    StringTooLong(Gc<String>),
24
25    /// A symbol is too long to serialize.
26    SymbolTooLong(Symbol),
27
28    /// An unsupported number of arguments in a function definition was
29    /// attempted to be serialized.
30    TooManyArgsInDefn,
31
32    /// An unsupported number of arguments in a function call was attempted to
33    /// be serialized.
34    TooManyArgsInCall,
35
36    /// An unsupported number of decls was attempted to be serialized.
37    TooManyDecls(Symbol),
38
39    /// An unsupported number of exports was attempted to be serialized.
40    TooManyExports(Symbol),
41
42    /// An unsupported number of imports was attempted to be serialized.
43    TooManyImports(Symbol),
44
45    /// An unsupported number of symbols was attempted to be imported from a
46    /// module.
47    TooManyImportedSymbols(Symbol, Symbol),
48
49    /// An unsupported number of modules was attempted to be serialized.
50    TooManyModules,
51
52    /// A vector is too long to serialize.
53    VectorTooLong(Vec<Gc<Value<Context>>>),
54}
55
56/// A runtime error.
57#[derive(Debug)]
58pub enum RuntimeError {
59    /// An error binding arguments.
60    ArgsBindingError(ArgsBindingError<Context>),
61
62    /// Exits with the given exit code.
63    Exit(u8),
64
65    /// An I/O error.
66    Io(IoError),
67
68    /// An attempt was made to access a non-existent data member on an object.
69    InvalidVTable(Gc<Value<Context>>),
70
71    /// A variable was used that was not defined.
72    NonexistentVar(Symbol),
73
74    /// A value that was not a function was called.
75    NotAFunction(Gc<Value<Context>>),
76
77    /// An attempt was made to access a non-existent data member on an object.
78    ObjectDataOutOfBounds(isize, Gc<Value<Context>>),
79
80    /// An attempt was made to access a non-existent function on an object.
81    ObjectNoSuchFunc(Symbol, Gc<Value<Context>>),
82
83    /// A runtime panic.
84    Panic(Vec<Gc<Value<Context>>>),
85}
86
87impl From<ArgsBindingError<Context>> for RuntimeError {
88    fn from(err: ArgsBindingError<Context>) -> RuntimeError {
89        RuntimeError::ArgsBindingError(err)
90    }
91}
92
93impl From<IoError> for RuntimeError {
94    fn from(err: IoError) -> RuntimeError {
95        RuntimeError::Io(err)
96    }
97}