1use std::collections::HashMap;
2
3use std::rc::Rc;
4
5use environment::Environment;
6
7#[derive(Debug, PartialEq)]
8pub struct RispError(String);
9
10pub type RispResult = Result<RispType, RispError>;
11
12
13#[derive(Debug, PartialEq, Clone)]
14pub enum RispType {
15 Nil,
16 Bool(bool),
17 Int(i64),
18 Str(String),
19 List(Vec<RispType>),
20 Vector(Vec<RispType>),
21 Map(HashMap<String, RispType>),
22 Keyword(String),
23 Symbol(String),
24 Function(fn(Vec<RispType>) -> RispResult),
25 RispFunction(RispFunc),
26}
27
28#[derive(Debug, PartialEq, Clone)]
29pub struct RispFunc {
30 pub args: Vec<RispType>,
31 pub variadic_arg: Option<String>,
32 pub body: Rc<RispType>,
33 pub env: Environment
34}
35
36
37pub fn error<S: Into<String>>(message: S) -> RispError {
38 RispError(message.into())
39}
40
41pub fn error_result<S: Into<String>>(message: S) -> RispResult {
42 Err(error(message))
43}
44
45pub fn symbol<S: Into<String>>(s: S) -> RispType {
46 RispType::Symbol(s.into())
47}
48
49pub fn keyword<S: Into<String>>(s: S) -> RispType {
50 RispType::Keyword(s.into())
51}
52
53pub fn string<S: Into<String>>(s: S) -> RispType {
54 RispType::Str(s.into())
55}
56
57#[allow(dead_code)]
58pub fn map<S: Into<String>>(pairs: Vec<(S, RispType)>) -> RispType {
59 let result: HashMap<String, RispType> = pairs.into_iter()
60 .map(|(s, r)| (s.into(), r))
61 .collect();
62 RispType::Map(result)
63}