lep/
obj.rs

1// Copyright (c) 2019 Timo Savola.
2// Use of this source code is governed by the MIT
3// license that can be found in the LICENSE file.
4
5use std::any::Any;
6use std::rc::Rc;
7
8/// Obj can be any object.
9pub type Obj = Rc<dyn Any>;
10
11#[derive(Eq, PartialEq)]
12pub struct Name(pub String);
13
14/// Pair may be a node in a singly linked list.
15pub struct Pair(pub Obj, pub Obj);
16
17/// () object.
18pub fn nil() -> Obj {
19    Rc::new(())
20}
21
22/// bool object.
23pub fn boolean(b: bool) -> Obj {
24    Rc::new(b)
25}
26
27/// i64 object.
28pub fn int(n: i64) -> Obj {
29    Rc::new(n)
30}
31
32/// String object.
33pub fn string(s: String) -> Obj {
34    Rc::new(s)
35}
36
37/// Name object.
38pub(crate) fn name(s: String) -> Obj {
39    Rc::new(Name(s))
40}
41
42/// Construct a Pair object.
43pub fn pair(car: Obj, cdr: Obj) -> Obj {
44    Rc::new(Pair(car, cdr))
45}