1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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)
    }
}