]> git.lizzy.rs Git - nothing.git/blob - src/script/expr.h
cc317f05d76799871c2e490f7bde04fd91e43c6c
[nothing.git] / src / script / expr.h
1 #ifndef ATOM_H_
2 #define ATOM_H_
3
4 struct Cons;
5 struct Atom;
6
7 enum ExprType
8 {
9     EXPR_ATOM = 0,
10     EXPR_CONS
11 };
12
13 // TODO(#285): there is no way to execute struct Expr
14 struct Expr
15 {
16     enum ExprType type;
17     union {
18         struct Cons *cons;
19         struct Atom *atom;
20     };
21 };
22
23 struct Expr atom_as_expr(struct Atom *atom);
24 struct Expr cons_as_expr(struct Cons *cons);
25 struct Expr create_expr_from_str(const char *str);
26 void destroy_expr(struct Expr expr);
27 void print_expr_as_sexpr(struct Expr expr);
28
29 enum AtomType
30 {
31     ATOM_SYMBOL = 0,
32     ATOM_NUMBER,
33     ATOM_STRING,
34 };
35
36 struct Atom
37 {
38     enum AtomType type;
39     union
40     {
41         int number;             // ATOM_NUMBER
42         char *name;             // ATOM_SYMBOL
43         char *text;             // ATOM_STRING
44     };
45 };
46
47 struct Atom *create_atom(enum AtomType type, ...);
48 void destroy_atom(struct Atom *atom);
49
50 struct Cons
51 {
52     struct Expr car;
53     struct Expr cdr;
54 };
55
56 struct Cons *create_cons(struct Expr car, struct Expr cdr);
57 void destroy_cons(struct Cons *cons);
58
59 #endif  // ATOM_H_